AllocConsole();
InputHandle = GetStdHandle(STD_INPUT_HANDLE);
OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
-
+
+ debug_printf("GetCommandLineA() %s\n",GetCommandLineA());
+ #if 0
for (i=0; i<argc; i++)
{
debug_printf("Args: '%s'\n",argv[i]);
}
+ #endif
}
#
#
#
-OBJECTS= ../common/crt0.o args.o
-LIBS= ../../lib/kernel32/kernel32.a ../../lib/ntdll/ntdll.a
+OBJECTS= args.o
all: args.exe
.phony: clean
args.exe: $(OBJECTS) $(LIBS)
- $(CC) -specs=../../specs $(OBJECTS) $(LIBS) -lgcc -o args.exe
+ $(CC) $(OBJECTS) -o args.exe
$(NM) --numeric-sort args.exe > args.sym
include ../../rules.mak
#define IDMAP_BASE (0xd0000000)
#define VIDMEM_BASE 0xb8000
+/*
+ * Return a linear address which can be used to access the physical memory
+ * starting at x
+ */
+extern inline unsigned int physical_to_linear(unsigned int x)
+{
+ return(x+IDMAP_BASE);
+}
+
+extern inline unsigned int linear_to_physical(unsigned int x)
+{
+ return(x-IDMAP_BASE);
+}
+
#define NR_ROWS 50
#define NR_COLUMNS 80
* DISCLAMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Revision: 1.4 $
- * $Author: ariadne $
- * $Date: 1999/04/03 10:41:29 $
+ * $Revision: 1.5 $
+ * $Author: dwelch $
+ * $Date: 1999/04/10 12:08:06 $
*
*/
/* Appropriated for Reactos Crtdll by Ariadne */
* The three standard file pointers provided by the run time library.
* NOTE: These will go to the bit-bucket silently in GUI applications!
*/
-extern FILE (*__imp__iob)[]; /* A pointer to an array of FILE */
-#define _iob (*__imp__iob) /* An array of FILE */
+extern FILE (*_iob)[]; /* A pointer to an array of FILE */
+//#define _iob (*__imp__iob) /* An array of FILE */
#define stdin (&_iob[0])
#define stdout (&_iob[1])
#define stderr (&_iob[2])
#define __DDK_ZW_H
-#include <windows.h>
//#ifndef WIN32_LEAN_AND_MEAN
#define PTOKEN_GROUPS PVOID
#define PTOKEN_PRIVILEGES PVOID
/*
* FUNCTION: Checks a clients access rights to a object
* ARGUMENTS:
- SecurityDescriptor = Security information against which the access is checked
+ * SecurityDescriptor = Security information against which the access is checked
* ClientToken = Represents a client
- DesiredAcces =
- GenericMapping =
- PrivilegeSet =
- ReturnLength = Bytes written
- GrantedAccess =
- AccessStatus = Indicates if the ClientToken allows the requested access
+ * DesiredAcces =
+ * GenericMapping =
+ * PrivilegeSet =
+ * ReturnLength = Bytes written
+ * GrantedAccess =
+ * AccessStatus = Indicates if the ClientToken allows the requested access
* REMARKS: The arguments map to the win32 AccessCheck
* RETURNS: Status
*/
NTSTATUS STDCALL NtCompleteConnectPort(VOID);
-NTSTATUS STDCALL NtConnectPort(VOID);
+//NTSTATUS STDCALL NtConnectPort(VOID);
+NTSTATUS STDCALL NtConnectPort(PHANDLE Handle,
+ POBJECT_ATTRIBUTES ObjectAttributes);
+
+//NTSTATUS STDCALL NtCreatePort(VOID);
+NTSTATUS STDCALL NtCreatePort(PHANDLE PortHandle,
+ ACCESS_MASK DesiredAccess,
+ POBJECT_ATTRIBUTES ObjectAttributes);
-NTSTATUS STDCALL NtCreatePort(VOID);
NTSTATUS STDCALL NtCreateToken(VOID);
NTSTATUS STDCALL NtGetPlugPlayEvent(VOID);
NTSTATUS STDCALL NtImpersonateClientOfPort(VOID);
-NTSTATUS STDCALL NtListenPort(VOID);
+//NTSTATUS STDCALL NtListenPort(VOID);
+NTSTATUS STDCALL NtListenPort(HANDLE PortHandle,
+ PLARGE_INTEGER Timeout,
+ PPORT_MSG_DATA Msg);
+
NTSTATUS STDCALL NtLoadKey2(VOID);
NTSTATUS STDCALL NtReplyPort(VOID);
NTSTATUS STDCALL NtReplyWaitReceivePort(VOID);
NTSTATUS STDCALL NtReplyWaitReplyPort(VOID);
-NTSTATUS STDCALL NtRequestPort(VOID);
+//NTSTATUS STDCALL NtRequestPort(VOID);
+NTSTATUS STDCALL NtRequestPort(HANDLE PortHandle,
+ ULONG DataLength,
+ PVOID Data,
+ ULONG Options,
+ PHANDLE ReplyPortHandle);
NTSTATUS STDCALL NtSetDefaultLocale(VOID);
//NTSTATUS STDCALL NtSetLdtEntries(VOID);
-NTSTATUS STDCALL NtSetLdtEntries(PEPROCESS Process,
+NTSTATUS STDCALL NtSetLdtEntries(PETHREAD Thread,
ULONG FirstEntry,
PULONG Entries);
#ifndef __INCLUDE_DDK_ZWTYPES_H
#define __INCLUDE_DDK_ZWTYPES_H
+/* Added by David Welch at 09/04/99 */
+typedef struct _PORT_MSG_DATA
+{
+ ULONG DataLength;
+ PVOID Data;
+ HANDLE ReplyPort;
+} PORT_MSG_DATA, *PPORT_MSG_DATA;
#define NtCurrentProcess() ( (HANDLE) 0xFFFFFFFF )
VOID NtInitializeEventImplementation(VOID);
+NTSTATUS NiInitPort(VOID);
--- /dev/null
+/* TEB/PEB parameters */
+#ifndef __INCLUDE_INTERNAL_TEB
+#define __INCLUDE_INTERNAL_TEB
+
+#include <internal/ps.h>
+
+#define PEB_BASE (0xb0001000)
+#define PEB_STARTUPINFO (0xb0003000)
+
+#define NtCurrentPeb() ((PNT_PEB)PEB_BASE)
+
+#endif /* __INCLUDE_INTERNAL_TEB */
#include <ddk/ntddk.h>
-NT_PEB *GetCurrentPeb(VOID);
-
typedef
DWORD
(*WaitForInputIdleType)(
; DISCLAMED. This includes but is not limited to warrenties of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;
-; $Revision: 1.4 $
-; $Author: ariadne $
-; $Date: 1999/04/02 21:43:45 $
+; $Revision: 1.5 $
+; $Author: dwelch $
+; $Date: 1999/04/10 12:08:09 $
;
; These three functions appear to be name mangled in some way, so GCC is
; probably not going to be able to use them in any case.
; _wtol
;
EXPORTS
-__builtin_new
-__builtin_delete
-_set_new_handler__FPFUi_i
-_CIacos
-_CIasin
-_CIatan
-_CIatan2
-_CIcos
-_CIcosh
-_CIexp
-_CIfmod
-_CIlog
-_CIlog10
-_CIpow
-_CIsin
-_CIsinh
-_CIsqrt
-_CItan
-_CItanh
-_HUGE_dll
-_XcptFilter
+;__builtin_new
+;__builtin_delete
+;_set_new_handler__FPFUi_i
+;_CIacos
+;_CIasin
+;_CIatan
+;_CIatan2
+;_CIcos
+;_CIcosh
+;_CIexp
+;_CIfmod
+;_CIlog
+;_CIlog10
+;_CIpow
+;_CIsin
+;_CIsinh
+;_CIsqrt
+;_CItan
+;_CItanh
+;_HUGE_dll
+;_XcptFilter
__GetMainArgs
-__argc_dll
-__argv_dll
-__dllonexit
-__doserrno
-__fpecode
-__isascii
-__iscsym
-__iscsymf
-__mb_cur_max_dll
-__pxcptinfoptrs
-__threadhandle
-__threadid
-__toascii
-_abnormal_termination
-_access
-_acmdln_dll
-_aexit_rtn_dll
-_amsg_exit
-_assert
-_basemajor_dll
-_baseminor_dll
-_baseversion_dll
-_beep
-_beginthread
-_c_exit
-_cabs
+;__argc_dll
+;__argv_dll
+;__dllonexit
+;__doserrno
+;__fpecode
+;__isascii
+;__iscsym
+;__iscsymf
+;__mb_cur_max_dll
+;__pxcptinfoptrs
+;__threadhandle
+;__threadid
+;__toascii
+;_abnormal_termination
+;_access
+;_acmdln_dll
+;_aexit_rtn_dll
+;_amsg_exit
+;_assert
+;_basemajor_dll
+;_baseminor_dll
+;_baseversion_dll
+;_beep
+;_beginthread
+;_c_exit
+;_cabs
_cexit
-_cgets
-_chdir
-_chdrive
-_chgsign
-_chmod
-_chsize
-_clearfp
-_close
-_commit
-_commode_dll
-_control87
-_controlfp
-_copysign
-_cprintf
-_cpumode_dll
-_cputs
-_creat
-_cscanf
-_ctype
-_cwait
-_daylight_dll
-_dup
-_dup2
-_ecvt
-_endthread
-_environ_dll
-_eof
-_errno
-_except_handler2
-_execl
-_execle
-_execlp
-_execlpe
-_execv
-_execve
-_execvp
-_execvpe
-_exit
-_expand
-_fcloseall
-_fcvt
-_fdopen
-_fgetchar
-_fgetwchar
-_filbuf
-_fileinfo_dll
-_filelength
+;_cgets
+;_chdir
+;_chdrive
+;_chgsign
+;_chmod
+;_chsize
+;_clearfp
+;_close
+;_commit
+;_commode_dll
+;_control87
+;_controlfp
+;_copysign
+;_cprintf
+;_cpumode_dll
+;_cputs
+;_creat
+;_cscanf
+;_ctype
+;_cwait
+;_daylight_dll
+;_dup
+;_dup2
+;_ecvt
+;_endthread
+;_environ_dll
+;_eof
+;_errno
+;_except_handler2
+;_execl
+;_execle
+;_execlp
+;_execlpe
+;_execv
+;_execve
+;_execvp
+;_execvpe
+;_exit
+;_expand
+;_fcloseall
+;_fcvt
+;_fdopen
+;_fgetchar
+;_fgetwchar
+;_filbuf
+;_fileinfo_dll
+;_filelength
_fileno
-_findclose
-_findfirst
-_findnext
-_finite
-_flsbuf
-_flushall
+;_findclose
+;_findfirst
+;_findnext
+;_finite
+;_flsbuf
+;_flushall
_fmode_dll
-_fpclass
-_fpieee_flt
+;_fpclass
+;_fpieee_flt
_fpreset
-_fputchar
-_fputwchar
-_fsopen
-_fstat
-_ftime
-_ftol
-_fullpath
-_futime
-_gcvt
-_get_osfhandle
-_getch
-_getche
-_getcwd
-_getdcwd
-_getdiskfree
-_getdllprocaddr
-_getdrive
-_getdrives
-_getpid
-_getsystime
-_getw
-_global_unwind2
-_heapchk
-_heapmin
-_heapset
-_heapwalk
-_hypot
-_initterm
+;_fputchar
+;_fputwchar
+;_fsopen
+;_fstat
+;_ftime
+;_ftol
+;_fullpath
+;_futime
+;_gcvt
+;_get_osfhandle
+;_getch
+;_getche
+;_getcwd
+;_getdcwd
+;_getdiskfree
+;_getdllprocaddr
+;_getdrive
+;_getdrives
+;_getpid
+;_getsystime
+;_getw
+;_global_unwind2
+;_heapchk
+;_heapmin
+;_heapset
+;_heapwalk
+;_hypot
+;_initterm
_iob
-_isatty
-_isctype
-_ismbbalnum
-_ismbbalpha
-_ismbbgraph
-_ismbbkalnum
-_ismbbkana
-_ismbbkpunct
-_ismbblead
-_ismbbprint
-_ismbbpunct
-_ismbbtrail
-_ismbcalpha
-_ismbcdigit
-_ismbchira
-_ismbckata
-_ismbcl0
-_ismbcl1
-_ismbcl2
-_ismbclegal
-_ismbclower
-_ismbcprint
-_ismbcspace
-_ismbcsymbol
-_ismbcupper
-_ismbslead
-_ismbstrail
-_isnan
-_itoa
-_j0
-_j1
-_jn
-_kbhit
-_lfind
-_loaddll
-_local_unwind2
-_locking
-_logb
-_lrotl
-_lrotr
-_lsearch
-_lseek
-_ltoa
-_makepath
-_matherr
-_mbbtombc
-_mbbtype
-_mbccpy
-_mbcjistojms
-_mbcjmstojis
-_mbclen
-_mbctohira
-_mbctokata
-_mbctolower
-_mbctombb
-_mbctoupper
-_mbctype
-_mbsbtype
-_mbscat
-_mbschr
-_mbscmp
-_mbscpy
-_mbscspn
-_mbsdec
-_mbsdup
-_mbsicmp
-_mbsinc
-_mbslen
-_mbslwr
-_mbsnbcat
-_mbsnbcmp
-_mbsnbcnt
-_mbsnbcpy
-_mbsnbicmp
-_mbsnbset
-_mbsncat
-_mbsnccnt
-_mbsncmp
-_mbsncpy
-_mbsnextc
-_mbsnicmp
-_mbsninc
-_mbsnset
-_mbspbrk
-_mbsrchr
-_mbsrev
-_mbsset
-_mbsspn
-_mbsspnp
-_mbsstr
-_mbstok
-_mbstrlen
-_mbsupr
-_memccpy
-_memicmp
-_mkdir
-_mktemp
-_msize
-_nextafter
-_onexit
-_open
-_open_osfhandle
-_osmajor_dll
-_osminor_dll
-_osmode_dll
-_osver_dll
-_osversion_dll
-_pclose
-_pctype_dll
-_pgmptr_dll
-_pipe
-_popen
-_purecall
-_putch
-_putenv
-_putw
-_pwctype_dll
-_read
-_rmdir
-_rmtmp
-_rotl
-_rotr
-_scalb
-_searchenv
-_seterrormode
-_setjmp
+;_isatty
+;_isctype
+;_ismbbalnum
+;_ismbbalpha
+;_ismbbgraph
+;_ismbbkalnum
+;_ismbbkana
+;_ismbbkpunct
+;_ismbblead
+;_ismbbprint
+;_ismbbpunct
+;_ismbbtrail
+;_ismbcalpha
+;_ismbcdigit
+;_ismbchira
+;_ismbckata
+;_ismbcl0
+;_ismbcl1
+;_ismbcl2
+;_ismbclegal
+;_ismbclower
+;_ismbcprint
+;_ismbcspace
+;_ismbcsymbol
+;_ismbcupper
+;_ismbslead
+;_ismbstrail
+;_isnan
+;_itoa
+;_j0
+;_j1
+;_jn
+;_kbhit
+;_lfind
+;_loaddll
+;_local_unwind2
+;_locking
+;_logb
+;_lrotl
+;_lrotr
+;_lsearch
+;_lseek
+;_ltoa
+;_makepath
+;_matherr
+;_mbbtombc
+;_mbbtype
+;_mbccpy
+;_mbcjistojms
+;_mbcjmstojis
+;_mbclen
+;_mbctohira
+;_mbctokata
+;_mbctolower
+;_mbctombb
+;_mbctoupper
+;_mbctype
+;_mbsbtype
+;_mbscat
+;_mbschr
+;_mbscmp
+;_mbscpy
+;_mbscspn
+;_mbsdec
+;_mbsdup
+;_mbsicmp
+;_mbsinc
+;_mbslen
+;_mbslwr
+;_mbsnbcat
+;_mbsnbcmp
+;_mbsnbcnt
+;_mbsnbcpy
+;_mbsnbicmp
+;_mbsnbset
+;_mbsncat
+;_mbsnccnt
+;_mbsncmp
+;_mbsncpy
+;_mbsnextc
+;_mbsnicmp
+;_mbsninc
+;_mbsnset
+;_mbspbrk
+;_mbsrchr
+;_mbsrev
+;_mbsset
+;_mbsspn
+;_mbsspnp
+;_mbsstr
+;_mbstok
+;_mbstrlen
+;_mbsupr
+;_memccpy
+;_memicmp
+;_mkdir
+;_mktemp
+;_msize
+;_nextafter
+;_onexit
+;_open
+;_open_osfhandle
+;_osmajor_dll
+;_osminor_dll
+;_osmode_dll
+;_osver_dll
+;_osversion_dll
+;_pclose
+;_pctype_dll
+;_pgmptr_dll
+;_pipe
+;_popen
+;_purecall
+;_putch
+;_putenv
+;_putw
+;_pwctype_dll
+;_read
+;_rmdir
+;_rmtmp
+;_rotl
+;_rotr
+;_scalb
+;_searchenv
+;_seterrormode
+;_setjmp
_setmode
-_setsystime
-_sleep
-_snprintf
-_snwprintf
-_sopen
-_spawnl
-_spawnle
-_spawnlp
-_spawnlpe
-_spawnv
-_spawnve
-_spawnvp
-_spawnvpe
-_splitpath
-_stat
-_statusfp
-_strcmpi
-_strdate
-_strdec
-_strdup
-_strerror
-_stricmp
-_stricoll
-_strinc
-_strlwr
-_strncnt
-_strnextc
-_strnicmp
-_strninc
-_strnset
-_strrev
-_strset
-_strspnp
-_strtime
-_strupr
-_swab
-_sys_errlist
-_sys_nerr_dll
-_tell
-_tempnam
-_timezone_dll
-_tolower
-_toupper
-_tzname
-_tzset
-_ultoa
-_umask
-_ungetch
-_unlink
-_unloaddll
-_utime
-_vsnprintf
-_vsnwprintf
-_wcsdup
-_wcsicmp
-_wcsicoll
-_wcslwr
-_wcsnicmp
-_wcsnset
-_wcsrev
-_wcsset
-_wcsupr
-_winmajor_dll
-_winminor_dll
-_winver_dll
-_write
-_wtoi
-_wtol
-_y0
-_y1
-_yn
+;_setsystime
+;_sleep
+;_snprintf
+;_snwprintf
+;_sopen
+;_spawnl
+;_spawnle
+;_spawnlp
+;_spawnlpe
+;_spawnv
+;_spawnve
+;_spawnvp
+;_spawnvpe
+;_splitpath
+;_stat
+;_statusfp
+;_strcmpi
+;_strdate
+;_strdec
+;_strdup
+;_strerror
+;_stricmp
+;_stricoll
+;_strinc
+;_strlwr
+;_strncnt
+;_strnextc
+;_strnicmp
+;_strninc
+;_strnset
+;_strrev
+;_strset
+;_strspnp
+;_strtime
+;_strupr
+;_swab
+;_sys_errlist
+;_sys_nerr_dll
+;_tell
+;_tempnam
+;_timezone_dll
+;_tolower
+;_toupper
+;_tzname
+;_tzset
+;_ultoa
+;_umask
+;_ungetch
+;_unlink
+;_unloaddll
+;_utime
+;_vsnprintf
+;_vsnwprintf
+;_wcsdup
+;_wcsicmp
+;_wcsicoll
+;_wcslwr
+;_wcsnicmp
+;_wcsnset
+;_wcsrev
+;_wcsset
+;_wcsupr
+;_winmajor_dll
+;_winminor_dll
+;_winver_dll
+;_write
+;_wtoi
+;_wtol
+;_y0
+;_y1
+;_yn
abort
-abs
-acos
-asctime
-asin
-atan
-atan2
+;abs
+;acos
+;asctime
+;asin
+;atan
+;atan2
atexit
-atof
-atoi
-atol
-bsearch
-calloc
-ceil
-clearerr
-clock
-cos
-cosh
-ctime
-difftime
-div
-exit
-exp
-fabs
-fclose
-feof
-ferror
-fflush
-fgetc
-fgetpos
-fgets
-fgetwc
-floor
-fmod
-fopen
-fprintf
-fputc
-fputs
-fputwc
-fread
-free
-freopen
-frexp
-fscanf
-fseek
-fsetpos
-ftell
-fwprintf
-fwrite
-fwscanf
-getc
-getchar
-getenv
-gets
-gmtime
-is_wctype
-isalnum
-isalpha
-iscntrl
-isdigit
-isgraph
-isleadbyte
-islower
-isprint
-ispunct
-isspace
-isupper
-iswalnum
-iswalpha
-iswascii
-iswcntrl
-iswctype
-iswdigit
-iswgraph
-iswlower
-iswprint
-iswpunct
-iswspace
-iswupper
-iswxdigit
-isxdigit
-labs
-ldexp
-ldiv
-localeconv
-localtime
-log
-log10
-longjmp
-malloc
-mblen
-mbstowcs
-mbtowc
-memchr
-memcmp
-memcpy
-memmove
-memset
-mktime
-modf
-perror
-pow
-printf
-putc
-putchar
-puts
-qsort
-raise
-rand
-realloc
-remove
-rename
-rewind
-scanf
-setbuf
-setlocale
-setvbuf
-signal
-sin
-sinh
-sprintf
-sqrt
-srand
-sscanf
-strcat
-strchr
-strcmp
-strcoll
-strcpy
-strcspn
-strerror
-strftime
+;atof
+;atoi
+;atol
+;bsearch
+;calloc
+;ceil
+;clearerr
+;clock
+;cos
+;cosh
+;ctime
+;difftime
+;div
+;exit
+;exp
+;fabs
+;fclose
+;feof
+;ferror
+;fflush
+;fgetc
+;fgetpos
+;fgets
+;fgetwc
+;floor
+;fmod
+;fopen
+;fprintf
+;fputc
+;fputs
+;fputwc
+;fread
+;free
+;freopen
+;frexp
+;fscanf
+;fseek
+;fsetpos
+;ftell
+;fwprintf
+;fwrite
+;fwscanf
+;getc
+;getchar
+;getenv
+;gets
+;gmtime
+;is_wctype
+;isalnum
+;isalpha
+;iscntrl
+;isdigit
+;isgraph
+;isleadbyte
+;islower
+;isprint
+;ispunct
+;isspace
+;isupper
+;iswalnum
+;iswalpha
+;iswascii
+;iswcntrl
+;iswctype
+;iswdigit
+;iswgraph
+;iswlower
+;iswprint
+;iswpunct
+;iswspace
+;iswupper
+;iswxdigit
+;isxdigit
+;labs
+;ldexp
+;ldiv
+;localeconv
+;localtime
+;log
+;log10
+;longjmp
+;malloc
+;mblen
+;mbstowcs
+;mbtowc
+;memchr
+;memcmp
+;memcpy
+;memmove
+;memset
+;mktime
+;modf
+;perror
+;pow
+;printf
+;putc
+;putchar
+;puts
+;qsort
+;raise
+;rand
+;realloc
+;remove
+;rename
+;rewind
+;scanf
+;setbuf
+;setlocale
+;setvbuf
+;signal
+;sin
+;sinh
+;sprintf
+;sqrt
+;srand
+;sscanf
+;strcat
+;strchr
+;strcmp
+;strcoll
+;strcpy
+;strcspn
+;strerror
+;strftime
strlen
-strncat
-strncmp
-strncpy
-strpbrk
-strrchr
-strspn
-strstr
-strtod
-strtok
-strtol
-strtoul
-strxfrm
-swprintf
-swscanf
-system
-tan
-tanh
-time
-tmpfile
-tmpnam
-tolower
-toupper
-towlower
-towupper
-ungetc
-ungetwc
-vfprintf
-vfwprintf
-vprintf
+;strncat
+;strncmp
+;strncpy
+;strpbrk
+;strrchr
+;strspn
+;strstr
+;strtod
+;strtok
+;strtol
+;strtoul
+;strxfrm
+;swprintf
+;swscanf
+;system
+;tan
+;tanh
+;time
+;tmpfile
+;tmpnam
+;tolower
+;toupper
+;towlower
+;towupper
+;ungetc
+;ungetwc
+;vfprintf
+;vfwprintf
+;vprintf
vsprintf
-vswprintf
-vwprintf
-wcscat
-wcschr
-wcscmp
-wcscoll
-wcscpy
-wcscspn
-wcsftime
-wcslen
-wcsncat
-wcsncmp
-wcsncpy
-wcspbrk
-wcsrchr
-wcsspn
-wcsstr
-wcstod
-wcstok
-wcstol
-wcstombs
-wcstoul
-wcsxfrm
-wctomb
-wprintf
-wscanf
-
+;vswprintf
+;vwprintf
+;wcscat
+;wcschr
+;wcscmp
+;wcscoll
+;wcscpy
+;wcscspn
+;wcsftime
+;wcslen
+;wcsncat
+;wcsncmp
+;wcsncpy
+;wcspbrk
+;wcsrchr
+;wcsspn
+;wcsstr
+;wcstod
+;wcstok
+;wcstol
+;wcstombs
+;wcstoul
+;wcsxfrm
+;wctomb
+;wprintf
+;wscanf
-HOST=mingw32-windows
ifneq ($(HOST),mingw32-windows)
ifneq ($(HOST),mingw32-linux)
DLLTARGET=crtdll.a
MALLOC_OBJECTS = malloc/expand.o malloc/heap.o
-MISC_OBJECTS = misc/GetArgs.o misc/setnew.o misc/purecall.o
+#MISC_OBJECTS = misc/GetArgs.o misc/setnew.o misc/purecall.o
+MISC_OBJECTS = misc/GetArgs.o
STRING_OBJECTS = string/memchr.o string/memcmp.o string/strcat.o \
string/strchr.o string/strcmp.o string/strcoll.o \
math/tanh.o math/stubs.o math/j0_y0.o math/j1_y1.o math/jn_yn.o
-OBJECTS = $(ASSERT_OBJECTS) $(CTYPE_OBJECTS) $(CONIO_OBJECTS) $(DIRECT_OBJECTS)\
- $(MISC_OBJECTS) $(STRING_OBJECTS) $(STDIO_OBJECTS) $(STDLIB_OBJECTS) \
- $(IO_OBJECTS) $(PROCESS_OBJECTS) $(TIME_OBJECTS) $(MALLOC_OBJECTS)\
- $(SYS_STAT_OBJECTS) $(SIGNAL_OBJECTS) $(MATH_OBJECTS) $(FLOAT_OBJECTS)\
- $(SEARCH_OBJECTS)
+#OBJECTS = $(ASSERT_OBJECTS) $(CTYPE_OBJECTS) $(CONIO_OBJECTS) $(DIRECT_OBJECTS)\
+# $(MISC_OBJECTS) $(STRING_OBJECTS) $(STDIO_OBJECTS) $(STDLIB_OBJECTS) \
+# $(IO_OBJECTS) $(PROCESS_OBJECTS) $(TIME_OBJECTS) $(MALLOC_OBJECTS)\
+# $(SYS_STAT_OBJECTS) $(SIGNAL_OBJECTS) $(MATH_OBJECTS) $(FLOAT_OBJECTS)\
+# $(SEARCH_OBJECTS)
-crtdll.a: $(OBJECTS)
+OBJECTS = $(MISC_OBJECTS) string/strdup.o stdlib/malloc.o stdlib/abort.o \
+ stdlib/_exit.o stdlib/atexit.o stdio/fileno.o io/fmode.o \
+ float/fpreset.o stdio/stdhnd.o io/setmode.o io/open.o \
+ stdio/vsprintf.o
+
+
+ crtdll.a: $(OBJECTS)
$(LD) -r $(OBJECTS) -o crtdll.a
crtdll.dll: $(DLLMAIN) $(OBJECTS) crtdll.def
$(DLLTOOL) --dllname crtdll.dll --def crtdll.def \
--output-lib crtdll.a
$(CC) -specs=crt_specs -mdll -o junk.tmp \
- -Wl,--base-file,base.tmp crtdll.o ../ntdll/ntdll.a
+ -Wl,--base-file,base.tmp crtdll.o ../kernel32/kernel32.a \
+ ../ntdll/ntdll.a
- $(RM) junk.tmp
$(DLLTOOL) --dllname crtdll.dll --base-file base.tmp \
--output-exp temp.exp --def crtdll.def
- $(RM) base.tmp
- $(CC) -specs=crt_specs -mdll -o crtdll.dll crtdll.o ../ntdll/ntdll.a\
+ $(CC) -specs=crt_specs -mdll -o crtdll.dll crtdll.o \
+ ../kernel32/kernel32.a ../ntdll/ntdll.a\
-Wl,--image-base,0x20000000 \
-Wl,--file-alignment,0x1000 \
-Wl,--section-alignment,0x1000 \
- $(RM) temp.exp
$(NM) --numeric-sort crtdll.dll > crtdll.sym
-include ../../Rules.mak
+clean:
+
+include ../../rules.mak
}
};
-FILE (*__imp__iob)[] = &_crtdll_iob;
+FILE (*_iob)[] = &_crtdll_iob;
#include <limits.h>
#include <crtdll/internal/file.h>
+#if 1
+int
+vsprintf(char *str, const char *fmt, va_list ap)
+{
+ abort();
+}
+#else
int
vsprintf(char *str, const char *fmt, va_list ap)
{
*f._ptr = 0;
return len;
}
+#endif
struct __atexit *__atexit_ptr = 0;
+#if 0
void exit(int status)
{
//int i;
_exit(status);
for(;;);
}
-
+#endif
void _exit(int _status)
static char msg[] = "Abort!\r\n";
-void
-abort()
+void abort()
{
- _write(stderr->_file, msg, sizeof(msg)-1);
- _exit(1);
+// _write(stderr->_file, msg, sizeof(msg)-1);
+// _exit(1);
}
#include <wchar.h>
#include <string.h>
-//#define NDEBUG
+#define NDEBUG
#include <kernel32/kernel32.h>
/* EXTERNS ******************************************************************/
#include <windows.h>
-//#define NDEBUG
+#define NDEBUG
#include <kernel32/kernel32.h>
/* GLOBALS *******************************************************************/
#include <kernel32/kernel32.h>
-VOID WINAPI __HeapInit(LPVOID base, ULONG minsize, ULONG maxsize);
VOID KERNEL32_Init()
{
//#include <stdlib.h>
-
+#if 0
-
+#endif
#include <ddk/ntddk.h>
#include <wchar.h>
#include <kernel32/proc.h>
+#include <internal/teb.h>
+
+#include <kernel32/kernel32.h>
WINBOOL STDCALL DllMain (HANDLE hInst,
ULONG ul_reason_for_call,
-NT_TEB *Teb;
-
-
BOOL WINAPI DllMainCRTStartup(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
{
- return(TRUE);
+ return(DllMain(hDll,dwReason,lpReserved));
}
-WINBOOL STDCALL DllMain (HANDLE hInst,
- ULONG ul_reason_for_call,
- LPVOID lpReserved)
+VOID WINAPI __HeapInit(LPVOID base, ULONG minsize, ULONG maxsize);
+
+WINBOOL STDCALL DllMain(HANDLE hInst,
+ ULONG ul_reason_for_call,
+ LPVOID lpReserved)
{
-
- switch( ul_reason_for_call ) {
- case DLL_PROCESS_ATTACH:
- {
-
- GetCurrentPeb()->ProcessHeap = HeapCreate(HEAP_GENERATE_EXCEPTIONS,
- 8192,
- 0);
- InitAtomTable(13);
- SetCurrentDirectoryW(L"C:");
- // SetSystemDirectoryW(L"C:\\Reactos\\System");
- // SetWindowsDirectoryW(L"C:\\Reactos");
-
- }
+ DPRINT("DllMain");
+ switch (ul_reason_for_call)
+ {
+ case DLL_PROCESS_ATTACH:
+ {
+ DPRINT("DLL_PROCESS_ATTACH\n");
+ }
case DLL_THREAD_ATTACH:
- {
- Teb = HeapAlloc(GetProcessHeap(),0,sizeof(NT_TEB));
- Teb->Peb = GetCurrentPeb();
- Teb->HardErrorMode = SEM_NOGPFAULTERRORBOX;
- Teb->dwTlsIndex=0;
- break;
- }
- case DLL_PROCESS_DETACH:
- {
- HeapFree(GetProcessHeap(),0,Teb);
- HeapDestroy(GetCurrentPeb()->ProcessHeap);
- break;
- }
- case DLL_THREAD_DETACH:
- {
- HeapFree(GetProcessHeap(),0,Teb);
- break;
- }
- default:
+ {
+ // Teb = HeapAlloc(GetProcessHeap(),0,sizeof(NT_TEB));
+ // Teb->Peb = GetCurrentPeb();
+ // Teb->HardErrorMode = SEM_NOGPFAULTERRORBOX;
+ // Teb->dwTlsIndex=0;
+ break;
+ }
+ case DLL_PROCESS_DETACH:
+ {
+// HeapFree(GetProcessHeap(),0,Teb);
+ HeapDestroy(NtCurrentPeb()->ProcessHeap);
+ break;
+ }
+ case DLL_THREAD_DETACH:
+ {
+ // HeapFree(GetProcessHeap(),0,Teb);
+ break;
+ }
+ default:
break;
-
+
}
- return TRUE;
-
+ return TRUE;
}
#include <kernel32/thread.h>
#include <wchar.h>
#include <string.h>
+#include <internal/teb.h>
/* GLOBALS ******************************************************************/
-static unsigned char CommandLineA[MAX_PATH];
+static CHAR CommandLineA[MAX_PATH];
/* FUNCTIONS ****************************************************************/
LPSTR STDCALL GetCommandLineA(VOID)
{
- WCHAR *CommandLineW;
- ULONG i = 0;
-
- CommandLineW = GetCommandLineW();
- while ((CommandLineW[i])!=0 && i < MAX_PATH)
- {
- CommandLineA[i] = (unsigned char)CommandLineW[i];
- i++;
- }
- CommandLineA[i] = 0;
- return CommandLineA;
+ ULONG i;
+ PWSTR CommandLineW;
+
+ CommandLineW = GetCommandLineW();
+ for (i=0; i<MAX_PATH && CommandLineW[i]!=0; i++)
+ {
+ CommandLineA[i] = (CHAR)CommandLineW[i];
+ }
+ CommandLineW[i] = 0;
+ return(CommandLineA);
}
LPWSTR STDCALL GetCommandLineW(VOID)
{
- return GetCurrentPeb()->StartupInfo->CommandLine;
+ return(NtCurrentPeb()->StartupInfo->CommandLine);
}
#include <pe.h>
#include <internal/i386/segment.h>
#include <ntdll/ldr.h>
+#include <internal/teb.h>
-//#define NDEBUG
+#define NDEBUG
#include <kernel32/kernel32.h>
/* FUNCTIONS ****************************************************************/
#define NTDLL_BASE (0x80000000)
+static NTSTATUS CreatePeb(HANDLE ProcessHandle, PWSTR CommandLine)
+{
+ NTSTATUS Status;
+ PVOID PebBase;
+ ULONG PebSize;
+ NT_PEB Peb;
+ ULONG BytesWritten;
+ PVOID StartupInfoBase;
+ ULONG StartupInfoSize;
+ PROCESSINFOW StartupInfo;
+
+ PebBase = PEB_BASE;
+ PebSize = 0x1000;
+ Status = ZwAllocateVirtualMemory(ProcessHandle,
+ &PebBase,
+ 0,
+ &PebSize,
+ MEM_COMMIT,
+ PAGE_READWRITE);
+ if (!NT_SUCCESS(Status))
+ {
+ return(Status);
+ }
+
+
+ memset(&Peb, 0, sizeof(Peb));
+ Peb.StartupInfo = PEB_STARTUPINFO;
+
+ ZwWriteVirtualMemory(ProcessHandle,
+ (PVOID)PEB_BASE,
+ &Peb,
+ sizeof(Peb),
+ &BytesWritten);
+
+ StartupInfoBase = PEB_STARTUPINFO;
+ StartupInfoSize = 0x1000;
+ Status = ZwAllocateVirtualMemory(ProcessHandle,
+ &StartupInfoBase,
+ 0,
+ &StartupInfoSize,
+ MEM_COMMIT,
+ PAGE_READWRITE);
+ if (!NT_SUCCESS(Status))
+ {
+ return(Status);
+ }
+
+
+ memset(&StartupInfo, 0, sizeof(StartupInfo));
+ wcscpy(StartupInfo.CommandLine, CommandLine);
+
+ DPRINT("StartupInfoSize %x\n",StartupInfoSize);
+ ZwWriteVirtualMemory(ProcessHandle,
+ (PVOID)PEB_STARTUPINFO,
+ &StartupInfo,
+ StartupInfoSize,
+ &BytesWritten);
+
+ return(STATUS_SUCCESS);
+}
+
+
WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
LPWSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
-
+
+ /*
+ *
+ */
+ DPRINT("Creating peb\n");
+ CreatePeb(hProcess, TempCommandLine);
+
DPRINT("Creating thread for process\n");
lpStartAddress = (LPTHREAD_START_ROUTINE)
((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))->
#include <wchar.h>
#include <string.h>
#include <internal/i386/segment.h>
+#include <internal/teb.h>
#define NDEBUG
#include <kernel32/kernel32.h>
/* GLOBALS *****************************************************************/
-static NT_PEB CurrentPeb;
-static PROCESSINFOW ProcessInfo;
-
WaitForInputIdleType lpfnGlobalRegisterWaitForInputIdle;
VOID RegisterWaitForInputIdle(WaitForInputIdleType lpfnRegisterWaitForInputIdle);
WINBOOL STDCALL GetProcessId(HANDLE hProcess, LPDWORD lpProcessId);
-VOID InitializePeb(PWSTR CommandLine)
-{
- DPRINT("InitializePeb(CommandLine %x)\n",CommandLine);
-// DPRINT("ProcessInfo.CommandLine %x\n",ProcessInfo.CommandLine);
-// wcscpy(ProcessInfo.CommandLine, CommandLine);
- CurrentPeb.StartupInfo = &ProcessInfo;
-}
-
-NT_PEB *GetCurrentPeb(VOID)
-{
- return(&CurrentPeb);
-}
-
HANDLE STDCALL GetCurrentProcess(VOID)
{
return (HANDLE)NtCurrentProcess();
-VOID
-STDCALL
-GetStartupInfoW(
- LPSTARTUPINFO lpStartupInfo
- )
+VOID STDCALL GetStartupInfoW(LPSTARTUPINFO lpStartupInfo)
{
- NT_PEB *pPeb = GetCurrentPeb();
-
- if (lpStartupInfo == NULL ) {
- SetLastError(ERROR_INVALID_PARAMETER);
- return;
- }
-
+ NT_PEB *pPeb = NtCurrentPeb();
+
+ if (lpStartupInfo == NULL)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return;
+ }
+
lpStartupInfo->cb = sizeof(STARTUPINFO);
lstrcpyW(lpStartupInfo->lpDesktop, pPeb->StartupInfo->Desktop);
lstrcpyW(lpStartupInfo->lpTitle, pPeb->StartupInfo->Title);
}
-VOID
-STDCALL
-GetStartupInfoA(
- LPSTARTUPINFO lpStartupInfo
- )
+VOID STDCALL GetStartupInfoA(LPSTARTUPINFO lpStartupInfo)
{
- NT_PEB *pPeb = GetCurrentPeb();
- ULONG i = 0;
- if (lpStartupInfo == NULL ) {
- SetLastError(ERROR_INVALID_PARAMETER);
- return;
- }
-
-
- lpStartupInfo->cb = sizeof(STARTUPINFO);
- i = 0;
-
- while ((pPeb->StartupInfo->Desktop[i])!=0 && i < MAX_PATH)
- {
- lpStartupInfo->lpDesktop[i] = (unsigned char)pPeb->StartupInfo->Desktop[i];
- i++;
- }
- lpStartupInfo->lpDesktop[i] = 0;
-
- i = 0;
- while ((pPeb->StartupInfo->Title[i])!=0 && i < MAX_PATH)
- {
- lpStartupInfo->lpTitle[i] = (unsigned char)pPeb->StartupInfo->Title[i];
- i++;
- }
- lpStartupInfo->lpTitle[i] = 0;
-
- lpStartupInfo->dwX = pPeb->StartupInfo->dwX;
- lpStartupInfo->dwY = pPeb->StartupInfo->dwY;
- lpStartupInfo->dwXSize = pPeb->StartupInfo->dwXSize;
- lpStartupInfo->dwYSize = pPeb->StartupInfo->dwYSize;
- lpStartupInfo->dwXCountChars = pPeb->StartupInfo->dwXCountChars;
- lpStartupInfo->dwYCountChars = pPeb->StartupInfo->dwYCountChars;
- lpStartupInfo->dwFillAttribute = pPeb->StartupInfo->dwFillAttribute;
- lpStartupInfo->dwFlags = pPeb->StartupInfo->dwFlags;
- lpStartupInfo->wShowWindow = pPeb->StartupInfo->wShowWindow;
- //lpStartupInfo->cbReserved2 = pPeb->StartupInfo->cbReserved;
- //lpStartupInfo->lpReserved = pPeb->StartupInfo->lpReserved1;
- //lpStartupInfo->lpReserved2 = pPeb->StartupInfo->lpReserved2;
-
- lpStartupInfo->hStdInput = pPeb->StartupInfo->hStdInput;
- lpStartupInfo->hStdOutput = pPeb->StartupInfo->hStdOutput;
- lpStartupInfo->hStdError = pPeb->StartupInfo->hStdError;
-
+ NT_PEB *pPeb = NtCurrentPeb();
+ ULONG i = 0;
+
+ if (lpStartupInfo == NULL)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
return;
+ }
+
+ lpStartupInfo->cb = sizeof(STARTUPINFO);
+ i = 0;
+
+ while ((pPeb->StartupInfo->Desktop[i])!=0 && i < MAX_PATH)
+ {
+ lpStartupInfo->lpDesktop[i] = (unsigned char)pPeb->StartupInfo->Desktop[i];
+ i++;
+ }
+ lpStartupInfo->lpDesktop[i] = 0;
+
+ i = 0;
+ while ((pPeb->StartupInfo->Title[i])!=0 && i < MAX_PATH)
+ {
+ lpStartupInfo->lpTitle[i] = (unsigned char)pPeb->StartupInfo->Title[i];
+ i++;
+ }
+ lpStartupInfo->lpTitle[i] = 0;
+
+ lpStartupInfo->dwX = pPeb->StartupInfo->dwX;
+ lpStartupInfo->dwY = pPeb->StartupInfo->dwY;
+ lpStartupInfo->dwXSize = pPeb->StartupInfo->dwXSize;
+ lpStartupInfo->dwYSize = pPeb->StartupInfo->dwYSize;
+ lpStartupInfo->dwXCountChars = pPeb->StartupInfo->dwXCountChars;
+ lpStartupInfo->dwYCountChars = pPeb->StartupInfo->dwYCountChars;
+ lpStartupInfo->dwFillAttribute = pPeb->StartupInfo->dwFillAttribute;
+ lpStartupInfo->dwFlags = pPeb->StartupInfo->dwFlags;
+ lpStartupInfo->wShowWindow = pPeb->StartupInfo->wShowWindow;
+ //lpStartupInfo->cbReserved2 = pPeb->StartupInfo->cbReserved;
+ //lpStartupInfo->lpReserved = pPeb->StartupInfo->lpReserved1;
+ //lpStartupInfo->lpReserved2 = pPeb->StartupInfo->lpReserved2;
+
+ lpStartupInfo->hStdInput = pPeb->StartupInfo->hStdInput;
+ lpStartupInfo->hStdOutput = pPeb->StartupInfo->hStdOutput;
+ lpStartupInfo->hStdError = pPeb->StartupInfo->hStdError;
+
+ return;
}
-BOOL
-STDCALL
-FlushInstructionCache(
-
-
- HANDLE hProcess,
- LPCVOID lpBaseAddress,
- DWORD dwSize
- )
+BOOL STDCALL FlushInstructionCache(HANDLE hProcess,
+ LPCVOID lpBaseAddress,
+ DWORD dwSize)
{
- NTSTATUS errCode;
- errCode = NtFlushInstructionCache(hProcess,(PVOID)lpBaseAddress,dwSize);
- if ( !NT_SUCCESS(errCode) ) {
- SetLastError(RtlNtStatusToDosError(errCode));
- return FALSE;
- }
- return TRUE;
+ NTSTATUS errCode;
+ errCode = NtFlushInstructionCache(hProcess,(PVOID)lpBaseAddress,dwSize);
+ if (!NT_SUCCESS(errCode))
+ {
+ SetLastError(RtlNtStatusToDosError(errCode));
+ return FALSE;
+ }
+ return TRUE;
}
VOID STDCALL ExitProcess(UINT uExitCode)
NtTerminateProcess(NtCurrentProcess() ,uExitCode);
}
-VOID
-STDCALL
-FatalAppExitA(
- UINT uAction,
- LPCSTR lpMessageText
- )
+VOID STDCALL FatalAppExitA(UINT uAction, LPCSTR lpMessageText)
{
- WCHAR MessageTextW[MAX_PATH];
- UINT i;
- i = 0;
- while ((*lpMessageText)!=0 && i < 35)
- {
- MessageTextW[i] = *lpMessageText;
- lpMessageText++;
- i++;
- }
- MessageTextW[i] = 0;
-
- return FatalAppExitW(uAction,MessageTextW);
+ WCHAR MessageTextW[MAX_PATH];
+ UINT i;
+ i = 0;
+ while ((*lpMessageText)!=0 && i < 35)
+ {
+ MessageTextW[i] = *lpMessageText;
+ lpMessageText++;
+ i++;
+ }
+ MessageTextW[i] = 0;
+
+ return FatalAppExitW(uAction,MessageTextW);
}
/* FUNCTIONS *****************************************************************/
+typedef WINBOOL STDCALL (*PDLLMAIN_FUNC)(HANDLE hInst,
+ ULONG ul_reason_for_call,
+ LPVOID lpReserved);
+
+
static NTSTATUS LdrLoadDll(PDLL* Dll, PCHAR Name)
{
char fqname[255] = "\\??\\C:\\reactos\\system\\";
ULONG ImageSize, InitialViewSize;
PVOID ImageBase;
HANDLE FileHandle, SectionHandle;
+ PDLLMAIN_FUNC Entrypoint;
DPRINT("LdrLoadDll(Base %x, Name %s)\n",Dll,Name);
LdrDllListHead.Next->Prev = (*Dll);
LdrDllListHead.Next = (*Dll);
- LdrPEStartup(ImageBase, SectionHandle);
+ Entrypoint = (PDLLMAIN_FUNC)LdrPEStartup(ImageBase, SectionHandle);
+ if (Entrypoint != NULL)
+ {
+ DPRINT("Calling entry point at %x\n",Entrypoint);
+ Entrypoint(ImageBase, DLL_PROCESS_ATTACH, NULL);
+ }
return(STATUS_SUCCESS);
}
# Required to run the system
#
COMPONENTS = iface_native ntoskrnl
-DLLS = ntdll kernel32
+DLLS = ntdll kernel32 crtdll
#DLLS = crtdll mingw32
#
#
# Select the device drivers and filesystems you want
#
-DEVICE_DRIVERS = blue ide keyboard mouse null parallal serial
+DEVICE_DRIVERS = blue ide keyboard mouse null parallel serial
# DEVICE_DRIVERS = beep event floppy ide_test sound test test1
FS_DRIVERS = minix vfat ext2
# FS_DRIVERS = template
-NTSTATUS STDCALL NtSetLdtEntries(PEPROCESS Process,
+NTSTATUS STDCALL NtSetLdtEntries(PETHREAD Thread,
ULONG FirstEntry,
PULONG Entries)
{
#include <internal/ke.h>
#include <internal/mm.h>
-//#define NDEBUG
+#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
--- /dev/null
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS kernel
+ * FILE: ntoskrnl/ldr/loader.c
+ * PURPOSE: Loaders for PE executables
+ * PROGRAMMERS: Jean Michault
+ * Rex Jolliff (rex@lvcablemodem.com)
+ * UPDATE HISTORY:
+ * DW 22/05/98 Created
+ * RJJ 10/12/98 Completed image loader function and added hooks for MZ/PE
+ * RJJ 10/12/98 Built driver loader function and added hooks for PE/COFF
+ * RJJ 10/12/98 Rolled in David's code to load COFF drivers
+ * JM 14/12/98 Built initial PE user module loader
+ * RJJ 06/03/99 Moved user PE loader into NTDLL
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include <windows.h>
+
+#include <internal/i386/segment.h>
+#include <internal/linkage.h>
+#include <internal/module.h>
+#include <internal/ntoskrnl.h>
+#include <internal/ob.h>
+#include <internal/ps.h>
+#include <string.h>
+#include <internal/string.h>
+#include <internal/symbol.h>
+#include <internal/teb.h>
+
+#include <ddk/ntddk.h>
+
+//#define NDEBUG
+#include <internal/debug.h>
+
+/* FUNCTIONS ****************************************************************/
+
+/* LdrLoadImage
+ * FUNCTION:
+ * Builds the initial environment for a process. Should be used
+ * to load the initial user process.
+ * ARGUMENTS:
+ * HANDLE ProcessHandle handle of the process to load the module into
+ * PUNICODE_STRING Filename name of the module to load
+ * RETURNS:
+ * NTSTATUS
+ */
+
+#define STACK_TOP (0xb0000000)
+
+static NTSTATUS LdrCreatePeb(HANDLE ProcessHandle)
+{
+ NTSTATUS Status;
+ PVOID PebBase;
+ ULONG PebSize;
+ NT_PEB Peb;
+ ULONG BytesWritten;
+
+ PebBase = PEB_BASE;
+ PebSize = 0x1000;
+ Status = ZwAllocateVirtualMemory(ProcessHandle,
+ &PebBase,
+ 0,
+ &PebSize,
+ MEM_COMMIT,
+ PAGE_READWRITE);
+ if (!NT_SUCCESS(Status))
+ {
+ return(Status);
+ }
+
+
+ memset(&Peb, 0, sizeof(Peb));
+ Peb.StartupInfo = PEB_STARTUPINFO;
+
+ ZwWriteVirtualMemory(ProcessHandle,
+ (PVOID)PEB_BASE,
+ &Peb,
+ sizeof(Peb),
+ &BytesWritten);
+
+ return(STATUS_SUCCESS);
+}
+
+NTSTATUS LdrLoadImage(HANDLE ProcessHandle, PUNICODE_STRING Filename)
+{
+ char BlockBuffer[1024];
+ DWORD ImageBase, LdrStartupAddr, StackBase;
+ ULONG ImageSize, StackSize;
+ NTSTATUS Status;
+ OBJECT_ATTRIBUTES FileObjectAttributes;
+ HANDLE FileHandle, SectionHandle, NTDllSectionHandle, ThreadHandle;
+ HANDLE DupNTDllSectionHandle;
+ CONTEXT Context;
+ UNICODE_STRING DllPathname;
+ PIMAGE_DOS_HEADER DosHeader;
+ PIMAGE_NT_HEADERS NTHeaders;
+ ULONG BytesWritten;
+ ULONG InitialViewSize;
+ ULONG i;
+ HANDLE DupSectionHandle;
+
+ /* Locate and open NTDLL to determine ImageBase and LdrStartup */
+ RtlInitUnicodeString(&DllPathname,L"\\??\\C:\\reactos\\system\\ntdll.dll");
+ InitializeObjectAttributes(&FileObjectAttributes,
+ &DllPathname,
+ 0,
+ NULL,
+ NULL);
+ DPRINT("Opening NTDLL\n");
+ Status = ZwOpenFile(&FileHandle,
+ FILE_ALL_ACCESS,
+ &FileObjectAttributes,
+ NULL,
+ 0,
+ 0);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("NTDLL open failed ");
+ DbgPrintErrorMessage(Status);
+
+ return Status;
+ }
+ Status = ZwReadFile(FileHandle, 0, 0, 0, 0, BlockBuffer, 1024, 0, 0);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("NTDLL header read failed ");
+ DbgPrintErrorMessage(Status);
+ ZwClose(FileHandle);
+
+ return Status;
+ }
+ /* FIXME: this will fail if the NT headers are more than 1024 bytes from start */
+ DosHeader = (PIMAGE_DOS_HEADER) BlockBuffer;
+ if (DosHeader->e_magic != IMAGE_DOS_MAGIC ||
+ DosHeader->e_lfanew == 0L ||
+ *(PULONG)((PUCHAR)BlockBuffer + DosHeader->e_lfanew) != IMAGE_PE_MAGIC)
+ {
+ DPRINT("NTDLL format invalid\n");
+ ZwClose(FileHandle);
+
+ return STATUS_UNSUCCESSFUL;
+ }
+ NTHeaders = (PIMAGE_NT_HEADERS)(BlockBuffer + DosHeader->e_lfanew);
+ ImageBase = NTHeaders->OptionalHeader.ImageBase;
+ ImageSize = NTHeaders->OptionalHeader.SizeOfImage;
+ /* FIXME: retrieve the offset of LdrStartup from NTDLL */
+ DPRINT("ImageBase %x\n",ImageBase);
+ LdrStartupAddr = ImageBase + NTHeaders->OptionalHeader.AddressOfEntryPoint;
+
+ /* Create a section for NTDLL */
+ Status = ZwCreateSection(&NTDllSectionHandle,
+ SECTION_ALL_ACCESS,
+ NULL,
+ NULL,
+ PAGE_READWRITE,
+ MEM_COMMIT,
+ FileHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("NTDLL create section failed ");
+ DbgPrintErrorMessage(Status);
+ ZwClose(FileHandle);
+
+ return Status;
+ }
+
+ /* Map the NTDLL into the process */
+ InitialViewSize = DosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS)
+ + sizeof(IMAGE_SECTION_HEADER) * NTHeaders->FileHeader.NumberOfSections;
+ Status = ZwMapViewOfSection(NTDllSectionHandle,
+ ProcessHandle,
+ (PVOID *)&ImageBase,
+ 0,
+ InitialViewSize,
+ NULL,
+ &InitialViewSize,
+ 0,
+ MEM_COMMIT,
+ PAGE_READWRITE);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("NTDLL map view of secion failed ");
+ DbgPrintErrorMessage(Status);
+
+ /* FIXME: destroy the section here */
+
+ ZwClose(FileHandle);
+
+ return Status;
+ }
+ for (i=0; i<NTHeaders->FileHeader.NumberOfSections; i++)
+ {
+ PIMAGE_SECTION_HEADER Sections;
+ LARGE_INTEGER Offset;
+ ULONG Base;
+
+ Sections = (PIMAGE_SECTION_HEADER)SECHDROFFSET(BlockBuffer);
+ Base = Sections[i].VirtualAddress + ImageBase;
+ SET_LARGE_INTEGER_HIGH_PART(Offset,0);
+ SET_LARGE_INTEGER_LOW_PART(Offset,Sections[i].PointerToRawData);
+ Status = ZwMapViewOfSection(NTDllSectionHandle,
+ ProcessHandle,
+ (PVOID *)&Base,
+ 0,
+ Sections[i].Misc.VirtualSize,
+ &Offset,
+ (PULONG)&Sections[i].Misc.VirtualSize,
+ 0,
+ MEM_COMMIT,
+ PAGE_READWRITE);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("NTDLL map view of secion failed ");
+ DbgPrintErrorMessage(Status);
+
+ /* FIXME: destroy the section here */
+
+ ZwClose(FileHandle);
+ return Status;
+ }
+ }
+ ZwClose(FileHandle);
+
+ /* Open process image to determine ImageBase and StackBase/Size */
+ InitializeObjectAttributes(&FileObjectAttributes,
+ Filename,
+ 0,
+ NULL,
+ NULL);
+ DPRINT("Opening image file %w\n",FileObjectAttributes.ObjectName->Buffer);
+ Status = ZwOpenFile(&FileHandle, FILE_ALL_ACCESS, &FileObjectAttributes,
+ NULL, 0, 0);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("Image open failed ");
+ DbgPrintErrorMessage(Status);
+
+ return Status;
+ }
+ Status = ZwReadFile(FileHandle, 0, 0, 0, 0, BlockBuffer, 1024, 0, 0);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("Image header read failed ");
+ DbgPrintErrorMessage(Status);
+ ZwClose(FileHandle);
+
+ return Status;
+ }
+
+ /* FIXME: this will fail if the NT headers are more than 1024 bytes from start */
+
+ DosHeader = (PIMAGE_DOS_HEADER) BlockBuffer;
+ if (DosHeader->e_magic != IMAGE_DOS_MAGIC ||
+ DosHeader->e_lfanew == 0L ||
+ *(PULONG)((PUCHAR)BlockBuffer + DosHeader->e_lfanew) != IMAGE_PE_MAGIC)
+ {
+ DPRINT("Image invalid format rc=%08lx\n", Status);
+ ZwClose(FileHandle);
+
+ return STATUS_UNSUCCESSFUL;
+ }
+ NTHeaders = (PIMAGE_NT_HEADERS)(BlockBuffer + DosHeader->e_lfanew);
+ ImageBase = NTHeaders->OptionalHeader.ImageBase;
+ ImageSize = NTHeaders->OptionalHeader.SizeOfImage;
+
+ /* Create a section for the image */
+ Status = ZwCreateSection(&SectionHandle,
+ SECTION_ALL_ACCESS,
+ NULL,
+ NULL,
+ PAGE_READWRITE,
+ MEM_COMMIT,
+ FileHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("Image create section failed ");
+ DbgPrintErrorMessage(Status);
+ ZwClose(FileHandle);
+
+ return Status;
+ }
+
+ /* Map the image into the process */
+ InitialViewSize = DosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS)
+ + sizeof(IMAGE_SECTION_HEADER) * NTHeaders->FileHeader.NumberOfSections;
+ DPRINT("InitialViewSize %x\n",InitialViewSize);
+ Status = ZwMapViewOfSection(SectionHandle,
+ ProcessHandle,
+ (PVOID *)&ImageBase,
+ 0,
+ InitialViewSize,
+ NULL,
+ &InitialViewSize,
+ 0,
+ MEM_COMMIT,
+ PAGE_READWRITE);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("Image map view of section failed ");
+ DbgPrintErrorMessage(Status);
+
+ /* FIXME: destroy the section here */
+
+ ZwClose(FileHandle);
+
+ return Status;
+ }
+ ZwClose(FileHandle);
+
+ /* Create page backed section for stack */
+ StackBase = (STACK_TOP - NTHeaders->OptionalHeader.SizeOfStackReserve);
+ StackSize = NTHeaders->OptionalHeader.SizeOfStackReserve;
+ Status = ZwAllocateVirtualMemory(ProcessHandle,
+ (PVOID *)&StackBase,
+ 0,
+ &StackSize,
+ MEM_COMMIT,
+ PAGE_READWRITE);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("Stack allocation failed ");
+ DbgPrintErrorMessage(Status);
+
+ /* FIXME: unmap the section here */
+ /* FIXME: destroy the section here */
+
+ return Status;
+ }
+
+ ZwDuplicateObject(NtCurrentProcess(),
+ &SectionHandle,
+ ProcessHandle,
+ &DupSectionHandle,
+ 0,
+ FALSE,
+ DUPLICATE_SAME_ACCESS);
+ ZwDuplicateObject(NtCurrentProcess(),
+ &NTDllSectionHandle,
+ ProcessHandle,
+ &DupNTDllSectionHandle,
+ 0,
+ FALSE,
+ DUPLICATE_SAME_ACCESS);
+
+ ZwWriteVirtualMemory(ProcessHandle,
+ (PVOID)(STACK_TOP - 4),
+ &DupNTDllSectionHandle,
+ sizeof(DupNTDllSectionHandle),
+ &BytesWritten);
+ ZwWriteVirtualMemory(ProcessHandle,
+ (PVOID)(STACK_TOP - 8),
+ &ImageBase,
+ sizeof(ImageBase),
+ &BytesWritten);
+ ZwWriteVirtualMemory(ProcessHandle,
+ (PVOID)(STACK_TOP - 12),
+ &DupSectionHandle,
+ sizeof(DupSectionHandle),
+ &BytesWritten);
+
+
+ /*
+ * Create a peb (grungy)
+ */
+ Status = LdrCreatePeb(ProcessHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ DbgPrint("LDR: Failed to create initial peb\n");
+ return(Status);
+ }
+
+ /* Initialize context to point to LdrStartup */
+ memset(&Context,0,sizeof(CONTEXT));
+ Context.SegSs = USER_DS;
+ Context.Esp = STACK_TOP - 16;
+ Context.EFlags = 0x202;
+ Context.SegCs = USER_CS;
+ Context.Eip = LdrStartupAddr;
+ Context.SegDs = USER_DS;
+ Context.SegEs = USER_DS;
+ Context.SegFs = USER_DS;
+ Context.SegGs = USER_DS;
+
+ DPRINT("LdrStartupAddr %x\n",LdrStartupAddr);
+ /* FIXME: Create process and let 'er rip */
+ Status = ZwCreateThread(&ThreadHandle,
+ THREAD_ALL_ACCESS,
+ NULL,
+ ProcessHandle,
+ NULL,
+ &Context,
+ NULL,
+ FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("Thread creation failed ");
+ DbgPrintErrorMessage(Status);
+
+ /* FIXME: destroy the stack memory block here */
+ /* FIXME: unmap the section here */
+ /* FIXME: destroy the section here */
+
+ return Status;
+ }
+
+ return STATUS_SUCCESS;
+}
+
+NTSTATUS LdrLoadInitialProcess(VOID)
+/*
+ * FIXME: The location of the initial process should be configurable,
+ * from command line or registry
+ */
+{
+ NTSTATUS Status;
+ HANDLE ProcessHandle;
+ UNICODE_STRING ProcessName;
+
+ Status = ZwCreateProcess(&ProcessHandle,
+ PROCESS_ALL_ACCESS,
+ NULL,
+ SystemProcessHandle,
+ FALSE,
+ NULL,
+ NULL,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DbgPrint("Could not create process\n");
+ return Status;
+ }
+
+ RtlInitUnicodeString(&ProcessName, L"\\??\\C:\\reactos\\system\\shell.exe");
+ Status = LdrLoadImage(ProcessHandle, &ProcessName);
+
+ return Status;
+}
return 0L;
}
-/* LdrLoadImage
- * FUNCTION:
- * Builds the initial environment for a process. Should be used
- * to load the initial user process.
- * ARGUMENTS:
- * HANDLE ProcessHandle handle of the process to load the module into
- * PUNICODE_STRING Filename name of the module to load
- * RETURNS:
- * NTSTATUS
- */
-
-#define STACK_TOP (0xb0000000)
-
-NTSTATUS LdrLoadImage(HANDLE ProcessHandle, PUNICODE_STRING Filename)
-{
- char BlockBuffer[1024];
- DWORD ImageBase, LdrStartupAddr, StackBase;
- ULONG ImageSize, StackSize;
- NTSTATUS Status;
- OBJECT_ATTRIBUTES FileObjectAttributes;
- HANDLE FileHandle, SectionHandle, NTDllSectionHandle, ThreadHandle;
- HANDLE DupNTDllSectionHandle;
- CONTEXT Context;
- UNICODE_STRING DllPathname;
- PIMAGE_DOS_HEADER DosHeader;
- PIMAGE_NT_HEADERS NTHeaders;
- ULONG BytesWritten;
- ULONG InitialViewSize;
- ULONG i;
- HANDLE DupSectionHandle;
-
- /* Locate and open NTDLL to determine ImageBase and LdrStartup */
- RtlInitUnicodeString(&DllPathname,L"\\??\\C:\\reactos\\system\\ntdll.dll");
- InitializeObjectAttributes(&FileObjectAttributes,
- &DllPathname,
- 0,
- NULL,
- NULL);
- DPRINT("Opening NTDLL\n");
- Status = ZwOpenFile(&FileHandle, FILE_ALL_ACCESS, &FileObjectAttributes, NULL, 0, 0);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("NTDLL open failed ");
- DbgPrintErrorMessage(Status);
-
- return Status;
- }
- Status = ZwReadFile(FileHandle, 0, 0, 0, 0, BlockBuffer, 1024, 0, 0);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("NTDLL header read failed ");
- DbgPrintErrorMessage(Status);
- ZwClose(FileHandle);
-
- return Status;
- }
- /* FIXME: this will fail if the NT headers are more than 1024 bytes from start */
- DosHeader = (PIMAGE_DOS_HEADER) BlockBuffer;
- if (DosHeader->e_magic != IMAGE_DOS_MAGIC ||
- DosHeader->e_lfanew == 0L ||
- *(PULONG)((PUCHAR)BlockBuffer + DosHeader->e_lfanew) != IMAGE_PE_MAGIC)
- {
- DPRINT("NTDLL format invalid\n");
- ZwClose(FileHandle);
-
- return STATUS_UNSUCCESSFUL;
- }
- NTHeaders = (PIMAGE_NT_HEADERS)(BlockBuffer + DosHeader->e_lfanew);
- ImageBase = NTHeaders->OptionalHeader.ImageBase;
- ImageSize = NTHeaders->OptionalHeader.SizeOfImage;
- /* FIXME: retrieve the offset of LdrStartup from NTDLL */
- DPRINT("ImageBase %x\n",ImageBase);
- LdrStartupAddr = ImageBase + NTHeaders->OptionalHeader.AddressOfEntryPoint;
-
- /* Create a section for NTDLL */
- Status = ZwCreateSection(&NTDllSectionHandle,
- SECTION_ALL_ACCESS,
- NULL,
- NULL,
- PAGE_READWRITE,
- MEM_COMMIT,
- FileHandle);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("NTDLL create section failed ");
- DbgPrintErrorMessage(Status);
- ZwClose(FileHandle);
-
- return Status;
- }
-
- /* Map the NTDLL into the process */
- InitialViewSize = DosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS)
- + sizeof(IMAGE_SECTION_HEADER) * NTHeaders->FileHeader.NumberOfSections;
- Status = ZwMapViewOfSection(NTDllSectionHandle,
- ProcessHandle,
- (PVOID *)&ImageBase,
- 0,
- InitialViewSize,
- NULL,
- &InitialViewSize,
- 0,
- MEM_COMMIT,
- PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("NTDLL map view of secion failed ");
- DbgPrintErrorMessage(Status);
-
- /* FIXME: destroy the section here */
-
- ZwClose(FileHandle);
-
- return Status;
- }
- for (i=0; i<NTHeaders->FileHeader.NumberOfSections; i++)
- {
- PIMAGE_SECTION_HEADER Sections;
- LARGE_INTEGER Offset;
- ULONG Base;
-
- Sections = (PIMAGE_SECTION_HEADER)SECHDROFFSET(BlockBuffer);
- Base = Sections[i].VirtualAddress + ImageBase;
- SET_LARGE_INTEGER_HIGH_PART(Offset,0);
- SET_LARGE_INTEGER_LOW_PART(Offset,Sections[i].PointerToRawData);
- Status = ZwMapViewOfSection(NTDllSectionHandle,
- ProcessHandle,
- (PVOID *)&Base,
- 0,
- Sections[i].Misc.VirtualSize,
- &Offset,
- (PULONG)&Sections[i].Misc.VirtualSize,
- 0,
- MEM_COMMIT,
- PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("NTDLL map view of secion failed ");
- DbgPrintErrorMessage(Status);
-
- /* FIXME: destroy the section here */
-
- ZwClose(FileHandle);
- return Status;
- }
- }
- ZwClose(FileHandle);
-
- /* Open process image to determine ImageBase and StackBase/Size */
- InitializeObjectAttributes(&FileObjectAttributes,
- Filename,
- 0,
- NULL,
- NULL);
- DPRINT("Opening image file %w\n",FileObjectAttributes.ObjectName->Buffer);
- Status = ZwOpenFile(&FileHandle, FILE_ALL_ACCESS, &FileObjectAttributes,
- NULL, 0, 0);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("Image open failed ");
- DbgPrintErrorMessage(Status);
-
- return Status;
- }
- Status = ZwReadFile(FileHandle, 0, 0, 0, 0, BlockBuffer, 1024, 0, 0);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("Image header read failed ");
- DbgPrintErrorMessage(Status);
- ZwClose(FileHandle);
-
- return Status;
- }
-
- /* FIXME: this will fail if the NT headers are more than 1024 bytes from start */
-
- DosHeader = (PIMAGE_DOS_HEADER) BlockBuffer;
- if (DosHeader->e_magic != IMAGE_DOS_MAGIC ||
- DosHeader->e_lfanew == 0L ||
- *(PULONG)((PUCHAR)BlockBuffer + DosHeader->e_lfanew) != IMAGE_PE_MAGIC)
- {
- DPRINT("Image invalid format rc=%08lx\n", Status);
- ZwClose(FileHandle);
-
- return STATUS_UNSUCCESSFUL;
- }
- NTHeaders = (PIMAGE_NT_HEADERS)(BlockBuffer + DosHeader->e_lfanew);
- ImageBase = NTHeaders->OptionalHeader.ImageBase;
- ImageSize = NTHeaders->OptionalHeader.SizeOfImage;
-
- /* Create a section for the image */
- Status = ZwCreateSection(&SectionHandle,
- SECTION_ALL_ACCESS,
- NULL,
- NULL,
- PAGE_READWRITE,
- MEM_COMMIT,
- FileHandle);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("Image create section failed ");
- DbgPrintErrorMessage(Status);
- ZwClose(FileHandle);
-
- return Status;
- }
-
- /* Map the image into the process */
- InitialViewSize = DosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS)
- + sizeof(IMAGE_SECTION_HEADER) * NTHeaders->FileHeader.NumberOfSections;
- DPRINT("InitialViewSize %x\n",InitialViewSize);
- Status = ZwMapViewOfSection(SectionHandle,
- ProcessHandle,
- (PVOID *)&ImageBase,
- 0,
- InitialViewSize,
- NULL,
- &InitialViewSize,
- 0,
- MEM_COMMIT,
- PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("Image map view of section failed ");
- DbgPrintErrorMessage(Status);
-
- /* FIXME: destroy the section here */
-
- ZwClose(FileHandle);
-
- return Status;
- }
- ZwClose(FileHandle);
-
- /* Create page backed section for stack */
- StackBase = (STACK_TOP - NTHeaders->OptionalHeader.SizeOfStackReserve);
- StackSize = NTHeaders->OptionalHeader.SizeOfStackReserve;
- Status = ZwAllocateVirtualMemory(ProcessHandle,
- (PVOID *)&StackBase,
- 0,
- &StackSize,
- MEM_COMMIT,
- PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("Stack allocation failed ");
- DbgPrintErrorMessage(Status);
-
- /* FIXME: unmap the section here */
- /* FIXME: destroy the section here */
-
- return Status;
- }
-
- ZwDuplicateObject(NtCurrentProcess(),
- &SectionHandle,
- ProcessHandle,
- &DupSectionHandle,
- 0,
- FALSE,
- DUPLICATE_SAME_ACCESS);
- ZwDuplicateObject(NtCurrentProcess(),
- &NTDllSectionHandle,
- ProcessHandle,
- &DupNTDllSectionHandle,
- 0,
- FALSE,
- DUPLICATE_SAME_ACCESS);
-
- ZwWriteVirtualMemory(ProcessHandle,
- (PVOID)(STACK_TOP - 4),
- &DupNTDllSectionHandle,
- sizeof(DupNTDllSectionHandle),
- &BytesWritten);
- ZwWriteVirtualMemory(ProcessHandle,
- (PVOID)(STACK_TOP - 8),
- &ImageBase,
- sizeof(ImageBase),
- &BytesWritten);
- ZwWriteVirtualMemory(ProcessHandle,
- (PVOID)(STACK_TOP - 12),
- &DupSectionHandle,
- sizeof(DupSectionHandle),
- &BytesWritten);
-
- /* Initialize context to point to LdrStartup */
- memset(&Context,0,sizeof(CONTEXT));
- Context.SegSs = USER_DS;
- Context.Esp = STACK_TOP - 16;
- Context.EFlags = 0x202;
- Context.SegCs = USER_CS;
- Context.Eip = LdrStartupAddr;
- Context.SegDs = USER_DS;
- Context.SegEs = USER_DS;
- Context.SegFs = USER_DS;
- Context.SegGs = USER_DS;
-
- DPRINT("LdrStartupAddr %x\n",LdrStartupAddr);
- /* FIXME: Create process and let 'er rip */
- Status = ZwCreateThread(&ThreadHandle,
- THREAD_ALL_ACCESS,
- NULL,
- ProcessHandle,
- NULL,
- &Context,
- NULL,
- FALSE);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("Thread creation failed ");
- DbgPrintErrorMessage(Status);
-
- /* FIXME: destroy the stack memory block here */
- /* FIXME: unmap the section here */
- /* FIXME: destroy the section here */
-
- return Status;
- }
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS LdrLoadInitialProcess(VOID)
-/*
- * FIXME: The location of the initial process should be configurable,
- * from command line or registry
- */
-{
- NTSTATUS Status;
- HANDLE ProcessHandle;
- UNICODE_STRING ProcessName;
-
- Status = ZwCreateProcess(&ProcessHandle,
- PROCESS_ALL_ACCESS,
- NULL,
- SystemProcessHandle,
- FALSE,
- NULL,
- NULL,
- NULL);
- if (!NT_SUCCESS(Status))
- {
- DbgPrint("Could not create process\n");
- return Status;
- }
-
- RtlInitUnicodeString(&ProcessName, L"\\??\\C:\\reactos\\system\\shell.exe");
- Status = LdrLoadImage(ProcessHandle, &ProcessName);
-
- return Status;
-}
DBG_OBJECTS = dbg/brkpoint.o dbg/errinfo.o
-LDR_OBJECTS = ldr/loader.o
+LDR_OBJECTS = ldr/loader.o ldr/init.o
CC_OBJECTS = cc/cacheman.o cc/block.o cc/view.o
-objects: ../ntoskrnl/objects
+objects:
mkdir objects
objects/hal.o: $(HAL_OBJECTS)
KIRQL oldIrql;
ULONG i = ((ULONG)Addr - kernel_pool_base) / PAGESIZE;
- DbgPrint("ExUnmapPage(Addr %x)\n",Addr);
- DbgPrint("i %x\n",i);
+ DPRINT("ExUnmapPage(Addr %x)\n",Addr);
+ DPRINT("i %x\n",i);
KeAcquireSpinLock(&AllocMapLock, &oldIrql);
MmSetPage(NULL, (PVOID)Addr, 0, 0);
ULONG PhysPage;
PhysPage = (ULONG)MmAllocPage();
- DbgPrint("Allocated page %x\n",PhysPage);
+ DPRINT("Allocated page %x\n",PhysPage);
if (PhysPage == 0)
{
return(NULL);
{
if (!test_bit(i%32,&alloc_map[i/32]))
{
- DbgPrint("i %x\n",i);
+ DPRINT("i %x\n",i);
set_bit(i%32,&alloc_map[i/32]);
addr = kernel_pool_base + (i*PAGESIZE);
MmSetPage(NULL, (PVOID)addr, PAGE_READWRITE, PhysPage);
VOID NtInit(VOID)
{
NtInitializeEventImplementation();
+ NiInitPort();
}
* Created 22/05/98
*/
+/* NOTES ********************************************************************
+ *
+ * This is a very rough implementation, not compatible with mach or nt
+ *
+ *
+ *
+ *
+ */
+
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
+#include <internal/ob.h>
+#include <string.h>
+#include <internal/string.h>
#include <internal/debug.h>
+/* TYPES ********************************************************************/
+
+struct _EPORT;
+
+typedef struct _PORT_MSG
+{
+ ULONG DataLength;
+ PVOID Data;
+ LIST_ENTRY ListEntry;
+ struct _EPORT* ReplyPort;
+ PMDL Mdl;
+} EPORT_MSG, *PEPORT_MSG;
+
+typedef struct _EPORT
+{
+ PEPROCESS Owner;
+ LIST_ENTRY MsgQueueHead;
+ KEVENT MsgNotify;
+ KSPIN_LOCK PortLock;
+} EPORT, *PEPORT;
+
+/* GLOBALS *******************************************************************/
+
+POBJECT_TYPE ExPortType = NULL;
+
/* FUNCTIONS *****************************************************************/
-NTSTATUS STDCALL NtAcceptConnectPort(VOID)
+NTSTATUS NiInitPort(VOID)
{
- UNIMPLEMENTED;
+ ExPortType = ExAllocatePool(NonPagedPool,sizeof(OBJECT_TYPE));
+
+ RtlInitUnicodeString(&ExPortType->TypeName,L"Event");
+
+ ExPortType->MaxObjects = ULONG_MAX;
+ ExPortType->MaxHandles = ULONG_MAX;
+ ExPortType->TotalObjects = 0;
+ ExPortType->TotalHandles = 0;
+ ExPortType->PagedPoolCharge = 0;
+ ExPortType->NonpagedPoolCharge = sizeof(EPORT);
+ ExPortType->Dump = NULL;
+ ExPortType->Open = NULL;
+ ExPortType->Close = NULL;
+ ExPortType->Delete = NULL;
+ ExPortType->Parse = NULL;
+ ExPortType->Security = NULL;
+ ExPortType->QueryName = NULL;
+ ExPortType->OkayToClose = NULL;
+
+ return(STATUS_SUCCESS);
}
-NTSTATUS STDCALL NtCompleteConnectPort(VOID)
+NTSTATUS STDCALL NtCreatePort(PHANDLE PortHandle,
+ ACCESS_MASK DesiredAccess,
+ POBJECT_ATTRIBUTES ObjectAttributes)
{
- UNIMPLEMENTED;
+ PEPORT Port;
+
+ Port = ObCreateObject(PortHandle,
+ DesiredAccess,
+ ObjectAttributes,
+ ExPortType);
+ if (Port == NULL)
+ {
+ return(STATUS_UNSUCCESSFUL);
+ }
+ InitializeListHead(&Port->MsgQueueHead);
+ KeInitializeEvent(&Port->MsgNotify, NotificationEvent, FALSE);
+ KeInitializeSpinLock(&Port->PortLock);
+ Port->Owner = PsGetCurrentProcess();
+ return(STATUS_SUCCESS);
}
-NTSTATUS STDCALL NtConnectPort(VOID)
+NTSTATUS STDCALL NtAcceptConnectPort(VOID)
{
UNIMPLEMENTED;
}
-NTSTATUS STDCALL NtCreatePort(VOID)
+NTSTATUS STDCALL NtCompleteConnectPort(VOID)
{
UNIMPLEMENTED;
}
-NTSTATUS STDCALL NtListenPort(VOID)
+NTSTATUS STDCALL NtConnectPort(PHANDLE PortHandle,
+ POBJECT_ATTRIBUTES ObjectAttributes)
{
- UNIMPLEMENTED;
+ NTSTATUS Status;
+ PEPORT Port;
+
+ Status = ObReferenceObjectByName(ObjectAttributes->ObjectName,
+ ObjectAttributes->Attributes,
+ NULL,
+ STANDARD_RIGHTS_REQUIRED,
+ ExPortType,
+ UserMode,
+ NULL,
+ (PVOID*)&Port);
+ if (Status != STATUS_SUCCESS)
+ {
+ return(Status);
+ }
+
+ Status = ObCreateHandle(PsGetCurrentProcess(),
+ Port,
+ STANDARD_RIGHTS_REQUIRED,
+ FALSE,
+ PortHandle);
+ ObDereferenceObject(Port);
+
+ return(STATUS_SUCCESS);
+
+}
+
+NTSTATUS STDCALL NtListenPort(HANDLE PortHandle,
+ PLARGE_INTEGER Timeout,
+ PPORT_MSG_DATA Msg)
+{
+ NTSTATUS Status;
+ PEPORT Port;
+ KIRQL oldIrql;
+ PEPORT_MSG KMsg;
+ PVOID Data;
+
+ Status = ObReferenceObjectByHandle(PortHandle,
+ STANDARD_RIGHTS_REQUIRED,
+ ExPortType,
+ UserMode,
+ (PVOID*)&Port,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ return(Status);
+ }
+
+ Status = KeWaitForSingleObject(&Port->MsgNotify, 0,
+ KernelMode, FALSE, Timeout);
+ if (!NT_SUCCESS(Status))
+ {
+ return(Status);
+ }
+
+ KeAcquireSpinLock(&Port->PortLock, &oldIrql);
+ KMsg = CONTAINING_RECORD(RemoveHeadList(&Port->MsgQueueHead),
+ EPORT_MSG,
+ ListEntry);
+ KeReleaseSpinLock(&Port->PortLock, oldIrql);
+
+ if (KMsg->DataLength > Msg->DataLength)
+ {
+ return(STATUS_UNSUCCESSFUL);
+ }
+ Msg->DataLength = KMsg->DataLength;
+ Data = MmGetSystemAddressForMdl(KMsg->Mdl);
+ memcpy(Msg->Data, Data, KMsg->DataLength);
+ MmUnmapLockedPages(Data, KMsg->Mdl);
+ Status = ObCreateHandle(PsGetCurrentProcess(),
+ KMsg->ReplyPort,
+ FALSE,
+ STANDARD_RIGHTS_REQUIRED,
+ &Msg->ReplyPort);
+ ObDereferenceObject(PortHandle);
+ return(Status);
}
NTSTATUS STDCALL NtReplyPort(VOID)
UNIMPLEMENTED;
}
-NTSTATUS STDCALL NtRequestPort(VOID)
+NTSTATUS STDCALL NtRequestPort(HANDLE PortHandle,
+ ULONG DataLength,
+ PVOID Data,
+ ULONG Options,
+ PHANDLE ReplyPortHandle)
+/*
+ * FUNCTION: Send a request to a port
+ * ARGUMENTS:
+ * PortHandle = Handle to the destination port
+ * DataLength = Length of the data to send
+ * Data = Data to send
+ * Option = Send options
+ * ReplyPortHandle = Optional port for reply
+ */
{
- UNIMPLEMENTED;
+ PEPORT Port;
+ NTSTATUS Status;
+ KIRQL oldIrql;
+ PEPORT_MSG Msg;
+
+ Status = ObReferenceObjectByHandle(PortHandle,
+ STANDARD_RIGHTS_REQUIRED,
+ ExPortType,
+ UserMode,
+ (PVOID*)&Port,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ return(Status);
+ }
+
+ Msg = ExAllocatePool(NonPagedPool, sizeof(EPORT_MSG));
+ Msg->DataLength = DataLength;
+ Msg->Mdl = MmCreateMdl(NULL,
+ Data,
+ Msg->DataLength);
+ MmProbeAndLockPages(Msg->Mdl,
+ UserMode,
+ IoReadAccess);
+
+ if (ReplyPortHandle != NULL)
+ {
+ NtCreatePort(ReplyPortHandle,
+ STANDARD_RIGHTS_REQUIRED,
+ NULL);
+ Status = ObReferenceObjectByHandle(*ReplyPortHandle,
+ STANDARD_RIGHTS_REQUIRED,
+ ExPortType,
+ UserMode,
+ (PVOID*)&Msg->ReplyPort,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ ExFreePool(Msg);
+ return(Status);
+ }
+ }
+
+ KeAcquireSpinLock(&Port->PortLock, &oldIrql);
+ InsertHeadList(&Port->MsgQueueHead, &Msg->ListEntry);
+ KeReleaseSpinLock(&Port->PortLock, oldIrql);
+ KeSetEvent(&Port->MsgNotify, 0, FALSE);
+
+ return(STATUS_SUCCESS);
}
NTSTATUS STDCALL NtRequestWaitReplyPort(VOID)
#include <internal/mm.h>
#include <internal/ob.h>
-//#define NDEBUG
+#define NDEBUG
#include <internal/debug.h>
-/* GLBOALS *******************************************************************/
+/* GLOBALS *******************************************************************/
extern ULONG PiNrThreads;
VOID PiDeleteProcess(PVOID ObjectBody)
{
DPRINT("PiDeleteProcess(ObjectBody %x)\n",ObjectBody);
- (VOID)MmReleaseMmInfo((PEPROCESS)ObjectBody);
+ /* FIXME: This doesn't work, why? */
+// (VOID)MmReleaseMmInfo((PEPROCESS)ObjectBody);
}
VOID PsTerminateCurrentThread(NTSTATUS ExitStatus)