From 77eee7ca44da796f7a57a44780814eaf020d6fba Mon Sep 17 00:00:00 2001 From: Casper Hornstrup Date: Sun, 16 Mar 2003 14:16:54 +0000 Subject: [PATCH] 2003-03-16 Casper S. Hornstrup * include/ntos/rtltypes.h (PRTL_BASE_PROCESS_START_ROUTINE): Define. * lib/kernel32/process/create.c (RtlBaseProcessStartRoutine): Import. (KlCreateFirstThread): Support images with native subsystem ID. * lib/ntdll/def/ntdll.def (RtlBaseProcessStartRoutine): Export. * lib/ntdll/def/ntdll.edf (RtlBaseProcessStartRoutine): Ditto. * lib/ntdll/rtl/exception.c (RtlBaseProcessStart): Forward declare. (RtlBaseProcessStartRoutine, RtlBaseProcessStart): Add. svn path=/trunk/; revision=4317 --- reactos/ChangeLog | 10 +++++++ reactos/include/ntos/rtltypes.h | 6 +++- reactos/lib/kernel32/process/create.c | 41 +++++++++++++++++---------- reactos/lib/ntdll/def/ntdll.def | 3 +- reactos/lib/ntdll/def/ntdll.edf | 3 +- reactos/lib/ntdll/rtl/exception.c | 20 ++++++++++++- 6 files changed, 64 insertions(+), 19 deletions(-) diff --git a/reactos/ChangeLog b/reactos/ChangeLog index 15deb021a8b..1ae963d8cad 100644 --- a/reactos/ChangeLog +++ b/reactos/ChangeLog @@ -1,3 +1,13 @@ +2003-03-16 Casper S. Hornstrup + + * include/ntos/rtltypes.h (PRTL_BASE_PROCESS_START_ROUTINE): Define. + * lib/kernel32/process/create.c (RtlBaseProcessStartRoutine): Import. + (KlCreateFirstThread): Support images with native subsystem ID. + * lib/ntdll/def/ntdll.def (RtlBaseProcessStartRoutine): Export. + * lib/ntdll/def/ntdll.edf (RtlBaseProcessStartRoutine): Ditto. + * lib/ntdll/rtl/exception.c (RtlBaseProcessStart): Forward declare. + (RtlBaseProcessStartRoutine, RtlBaseProcessStart): Add. + 2003-03-16 Casper S. Hornstrup * include/defines.h (VS_FFI_SIGNATURE, VS_FFI_STRUCVERSION): Define. diff --git a/reactos/include/ntos/rtltypes.h b/reactos/include/ntos/rtltypes.h index be893ea6f5e..3fa93333feb 100755 --- a/reactos/include/ntos/rtltypes.h +++ b/reactos/include/ntos/rtltypes.h @@ -1,4 +1,4 @@ -/* $Id: rtltypes.h,v 1.3 2002/11/25 15:47:52 robd Exp $ +/* $Id: rtltypes.h,v 1.4 2003/03/16 14:16:54 chorns Exp $ * */ @@ -220,4 +220,8 @@ typedef struct _RTL_MESSAGE_RESOURCE_DATA RTL_MESSAGE_RESOURCE_BLOCK Blocks[1]; } RTL_MESSAGE_RESOURCE_DATA, *PRTL_MESSAGE_RESOURCE_DATA; +typedef VOID STDCALL +(*PRTL_BASE_PROCESS_START_ROUTINE)(PTHREAD_START_ROUTINE StartAddress, + PVOID Parameter); + #endif /* __DDK_RTLTYPES_H */ diff --git a/reactos/lib/kernel32/process/create.c b/reactos/lib/kernel32/process/create.c index 379e3d16f85..4941fbeeb31 100644 --- a/reactos/lib/kernel32/process/create.c +++ b/reactos/lib/kernel32/process/create.c @@ -1,4 +1,4 @@ -/* $Id: create.c,v 1.62 2003/03/09 21:38:40 hbirr Exp $ +/* $Id: create.c,v 1.63 2003/03/16 14:16:54 chorns Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -18,6 +18,9 @@ /* FUNCTIONS ****************************************************************/ +__declspec(dllimport) +PRTL_BASE_PROCESS_START_ROUTINE RtlBaseProcessStartRoutine; + WINBOOL STDCALL CreateProcessA (LPCSTR lpApplicationName, LPSTR lpCommandLine, @@ -217,9 +220,8 @@ BaseProcessStart(LPTHREAD_START_ROUTINE lpStartAddress, HANDLE STDCALL KlCreateFirstThread(HANDLE ProcessHandle, LPSECURITY_ATTRIBUTES lpThreadAttributes, - ULONG StackReserve, - ULONG StackCommit, - LPTHREAD_START_ROUTINE lpStartAddress, + PSECTION_IMAGE_INFORMATION Sii, + LPTHREAD_START_ROUTINE lpStartAddress, DWORD dwCreationFlags, LPDWORD lpThreadId) { @@ -232,6 +234,7 @@ KlCreateFirstThread(HANDLE ProcessHandle, BOOLEAN CreateSuspended = FALSE; ULONG OldPageProtection; ULONG ResultLength; + ULONG ThreadStartAddress; ULONG InitialStack[6]; ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); @@ -252,10 +255,10 @@ KlCreateFirstThread(HANDLE ProcessHandle, else CreateSuspended = FALSE; - InitialTeb.StackReserve = (StackReserve < 0x100000) ? 0x100000 : StackReserve; + InitialTeb.StackReserve = (Sii->StackReserve < 0x100000) ? 0x100000 : Sii->StackReserve; /* FIXME: use correct commit size */ #if 0 - InitialTeb.StackCommit = (StackCommit < PAGE_SIZE) ? PAGE_SIZE : StackCommit; + InitialTeb.StackCommit = (Sii->StackCommit < PAGE_SIZE) ? PAGE_SIZE : Sii->StackCommit; #endif InitialTeb.StackCommit = InitialTeb.StackReserve - PAGE_SIZE; @@ -274,7 +277,7 @@ KlCreateFirstThread(HANDLE ProcessHandle, { DPRINT("Error reserving stack space!\n"); SetLastErrorByStatus(Status); - return(NULL); + return(INVALID_HANDLE_VALUE); } DPRINT("StackAllocate: %p ReserveSize: 0x%lX\n", @@ -328,8 +331,17 @@ KlCreateFirstThread(HANDLE ProcessHandle, return(INVALID_HANDLE_VALUE); } + if (Sii->Subsystem != IMAGE_SUBSYSTEM_NATIVE) + { + ThreadStartAddress = (ULONG) BaseProcessStart; + } + else + { + ThreadStartAddress = (ULONG) RtlBaseProcessStartRoutine; + } + memset(&ThreadContext,0,sizeof(CONTEXT)); - ThreadContext.Eip = (ULONG)BaseProcessStart; + ThreadContext.Eip = ThreadStartAddress; ThreadContext.SegGs = USER_DS; ThreadContext.SegFs = USER_DS; ThreadContext.SegEs = USER_DS; @@ -738,7 +750,6 @@ CreateProcessW(LPCWSTR lpApplicationName, TempCurrentDirectoryW); } - /* * Create a section for the executable */ @@ -893,7 +904,7 @@ CreateProcessW(LPCWSTR lpApplicationName, Status = NtDuplicateObject (NtCurrentProcess(), Ppb->CurrentDirectoryHandle, hProcess, - &Ppb->CurrentDirectoryHandle, + &Ppb->CurrentDirectoryHandle, 0, TRUE, DUPLICATE_SAME_ACCESS); @@ -934,7 +945,7 @@ CreateProcessW(LPCWSTR lpApplicationName, DPRINT("ProcessBasicInfo.UniqueProcessId %d\n", ProcessBasicInfo.UniqueProcessId); lpProcessInformation->dwProcessId = ProcessBasicInfo.UniqueProcessId; - + /* * Tell the csrss server we are creating a new process */ @@ -1080,12 +1091,12 @@ CreateProcessW(LPCWSTR lpApplicationName, /* * Create the thread for the kernel */ - DPRINT("Creating thread for process\n"); + DPRINT("Creating thread for process (EntryPoint = 0x%.08x)\n", + ImageBaseAddress + (ULONG)Sii.EntryPoint); hThread = KlCreateFirstThread(hProcess, lpThreadAttributes, - Sii.StackReserve, - Sii.StackCommit, - ImageBaseAddress + (ULONG)Sii.EntryPoint, + &Sii, + ImageBaseAddress + (ULONG)Sii.EntryPoint, dwCreationFlags, &lpProcessInformation->dwThreadId); if (hThread == INVALID_HANDLE_VALUE) diff --git a/reactos/lib/ntdll/def/ntdll.def b/reactos/lib/ntdll/def/ntdll.def index 30406239e74..32080f08b2d 100644 --- a/reactos/lib/ntdll/def/ntdll.def +++ b/reactos/lib/ntdll/def/ntdll.def @@ -1,4 +1,4 @@ -; $Id: ntdll.def,v 1.92 2003/02/16 18:54:26 hbirr Exp $ +; $Id: ntdll.def,v 1.93 2003/03/16 14:16:54 chorns Exp $ ; ; ReactOS Operating System ; @@ -302,6 +302,7 @@ RtlAreAnyAccessesGranted@8 RtlAreBitsClear@12 RtlAreBitsSet@12 RtlAssert@16 +RtlBaseProcessStartRoutine DATA ;RtlCaptureStackBackTrace RtlCharToInteger@12 RtlCheckRegistryKey@8 diff --git a/reactos/lib/ntdll/def/ntdll.edf b/reactos/lib/ntdll/def/ntdll.edf index 55ad0bdf319..5d8ad4e5a35 100644 --- a/reactos/lib/ntdll/def/ntdll.edf +++ b/reactos/lib/ntdll/def/ntdll.edf @@ -1,4 +1,4 @@ -; $Id: ntdll.edf,v 1.81 2003/02/16 18:54:26 hbirr Exp $ +; $Id: ntdll.edf,v 1.82 2003/03/16 14:16:54 chorns Exp $ ; ; ReactOS Operating System ; @@ -302,6 +302,7 @@ RtlAreAnyAccessesGranted=RtlAreAnyAccessesGranted@8 RtlAreBitsClear=RtlAreBitsClear@12 RtlAreBitsSet=RtlAreBitsSet@12 RtlAssert=RtlAssert@16 +RtlBaseProcessStartRoutine DATA ;RtlCaptureStackBackTrace RtlCharToInteger=RtlCharToInteger@12 RtlCheckRegistryKey=RtlCheckRegistryKey@8 diff --git a/reactos/lib/ntdll/rtl/exception.c b/reactos/lib/ntdll/rtl/exception.c index 41f884c3d8a..441987b19c8 100644 --- a/reactos/lib/ntdll/rtl/exception.c +++ b/reactos/lib/ntdll/rtl/exception.c @@ -1,4 +1,4 @@ -/* $Id: exception.c,v 1.11 2002/10/26 00:32:18 chorns Exp $ +/* $Id: exception.c,v 1.12 2003/03/16 14:16:54 chorns Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -18,6 +18,13 @@ /* FUNCTIONS ***************************************************************/ +VOID STDCALL +RtlBaseProcessStart(PTHREAD_START_ROUTINE StartAddress, + PVOID Parameter); + +__declspec(dllexport) +PRTL_BASE_PROCESS_START_ROUTINE RtlBaseProcessStartRoutine = RtlBaseProcessStart; + ULONG RtlpDispatchException(IN PEXCEPTION_RECORD ExceptionRecord, IN PCONTEXT Context); @@ -54,4 +61,15 @@ RtlRaiseException(PEXCEPTION_RECORD ExceptionRecord) DbgPrint("RtlRaiseException()"); } +VOID STDCALL +RtlBaseProcessStart(PTHREAD_START_ROUTINE StartAddress, + PVOID Parameter) +{ + NTSTATUS ExitStatus = STATUS_SUCCESS; + + ExitStatus = (NTSTATUS) (StartAddress)(Parameter); + + NtTerminateProcess(NtCurrentProcess(), ExitStatus); + } + /* EOF */