mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 12:03:29 +00:00
Rewrote stack allocation.
svn path=/trunk/; revision=2144
This commit is contained in:
parent
e2e13b71ce
commit
e183b6028f
14 changed files with 570 additions and 400 deletions
|
@ -1,14 +1,23 @@
|
||||||
|
#include <ntos.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
PTEB Teb;
|
||||||
|
|
||||||
printf("TEB dumpper\n");
|
printf("TEB dumpper\n");
|
||||||
__asm__("movl %%fs:0x18, %0\n\t"
|
__asm__("movl %%fs:0x18, %0\n\t"
|
||||||
: "=a" (x)
|
: "=a" (x)
|
||||||
: /* no inputs */);
|
: /* no inputs */);
|
||||||
printf("fs[0x18] %x\n", x);
|
printf("fs[0x18] %x\n", x);
|
||||||
|
|
||||||
|
Teb = (PTEB)x;
|
||||||
|
|
||||||
|
printf("StackBase: 0x%08lX\n", Teb->Tib.StackBase);
|
||||||
|
printf("StackLimit: 0x%08lX\n", Teb->Tib.StackLimit);
|
||||||
|
printf("DeallocationStack: 0x%08lX\n", Teb->DeallocationStack);
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: rtl.h,v 1.55 2001/07/04 20:40:18 chorns Exp $
|
/* $Id: rtl.h,v 1.56 2001/08/03 17:07:56 ekohl Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
typedef struct _INITIAL_TEB
|
typedef struct _INITIAL_TEB
|
||||||
{
|
{
|
||||||
PVOID StackBase;
|
ULONG StackCommit;
|
||||||
PVOID StackLimit;
|
ULONG StackReserve;
|
||||||
PVOID StackCommit;
|
PVOID StackBase;
|
||||||
PVOID StackCommitMax;
|
PVOID StackLimit;
|
||||||
PVOID StackReserve;
|
PVOID StackAllocate;
|
||||||
} INITIAL_TEB, *PINITIAL_TEB;
|
} INITIAL_TEB, *PINITIAL_TEB;
|
||||||
|
|
||||||
typedef struct _CONTROLLER_OBJECT
|
typedef struct _CONTROLLER_OBJECT
|
||||||
|
@ -161,12 +161,13 @@ typedef struct _RTL_MESSAGE_RESOURCE_DATA
|
||||||
#define RTL_QUERY_REGISTRY_DELETE (0x00000040)
|
#define RTL_QUERY_REGISTRY_DELETE (0x00000040)
|
||||||
|
|
||||||
|
|
||||||
typedef NTSTATUS (*PRTL_QUERY_REGISTRY_ROUTINE)(PWSTR ValueName,
|
typedef NTSTATUS STDCALL
|
||||||
ULONG ValueType,
|
(*PRTL_QUERY_REGISTRY_ROUTINE)(PWSTR ValueName,
|
||||||
PVOID ValueData,
|
ULONG ValueType,
|
||||||
ULONG ValueLength,
|
PVOID ValueData,
|
||||||
PVOID Context,
|
ULONG ValueLength,
|
||||||
PVOID EntryContext);
|
PVOID Context,
|
||||||
|
PVOID EntryContext);
|
||||||
|
|
||||||
typedef struct _RTL_QUERY_REGISTRY_TABLE
|
typedef struct _RTL_QUERY_REGISTRY_TABLE
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
*/
|
*/
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <ddk/ntddk.h>
|
#include <ddk/ntddk.h>
|
||||||
NT_TEB *GetTeb(VOID);
|
PTEB GetTeb(VOID);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
typedef struct _CLIENT_ID
|
typedef struct _CLIENT_ID
|
||||||
{
|
{
|
||||||
HANDLE UniqueProcess;
|
HANDLE UniqueProcess;
|
||||||
HANDLE UniqueThread;
|
HANDLE UniqueThread;
|
||||||
} CLIENT_ID, *PCLIENT_ID;
|
} CLIENT_ID, *PCLIENT_ID;
|
||||||
|
|
||||||
typedef struct _CURDIR
|
typedef struct _CURDIR
|
||||||
|
@ -154,7 +154,7 @@ typedef struct _GDI_TEB_BATCH
|
||||||
ULONG Buffer[0x136];
|
ULONG Buffer[0x136];
|
||||||
} GDI_TEB_BATCH, *PGDI_TEB_BATCH;
|
} GDI_TEB_BATCH, *PGDI_TEB_BATCH;
|
||||||
|
|
||||||
typedef struct _NT_TEB
|
typedef struct _TEB
|
||||||
{
|
{
|
||||||
NT_TIB Tib; // 00h
|
NT_TIB Tib; // 00h
|
||||||
PVOID EnvironmentPointer; // 1Ch
|
PVOID EnvironmentPointer; // 1Ch
|
||||||
|
@ -211,17 +211,12 @@ typedef struct _NT_TEB
|
||||||
ULONG Spare4; // F7Ch
|
ULONG Spare4; // F7Ch
|
||||||
PVOID ReservedForOle; // F80h
|
PVOID ReservedForOle; // F80h
|
||||||
ULONG WaitingOnLoaderLock; // F84h
|
ULONG WaitingOnLoaderLock; // F84h
|
||||||
|
} TEB, *PTEB;
|
||||||
|
|
||||||
PVOID StackCommit; // F88h
|
|
||||||
PVOID StackCommitMax; // F8Ch
|
|
||||||
PVOID StackReserve; // F90h
|
|
||||||
} NT_TEB, *PNT_TEB;
|
|
||||||
|
|
||||||
#define PEB_STARTUPINFO (0xb0003000)
|
|
||||||
|
|
||||||
#define NtCurrentPeb() (NtCurrentTeb()->Peb)
|
#define NtCurrentPeb() (NtCurrentTeb()->Peb)
|
||||||
|
|
||||||
static inline PNT_TEB NtCurrentTeb(VOID)
|
static inline PTEB NtCurrentTeb(VOID)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
|
@ -230,7 +225,7 @@ static inline PNT_TEB NtCurrentTeb(VOID)
|
||||||
: /* no inputs */
|
: /* no inputs */
|
||||||
);
|
);
|
||||||
|
|
||||||
return((PNT_TEB)x);
|
return((PTEB)x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/* $Id: create.c,v 1.39 2001/06/18 03:02:43 phreak Exp $
|
/* $Id: create.c,v 1.40 2001/08/03 17:20:06 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS system libraries
|
* PROJECT: ReactOS system libraries
|
||||||
* FILE: lib/kernel32/proc/proc.c
|
* FILE: lib/kernel32/process/create.c
|
||||||
* PURPOSE: Process functions
|
* PURPOSE: Process functions
|
||||||
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
|
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
|
||||||
* UPDATE HISTORY:
|
* UPDATE HISTORY:
|
||||||
|
@ -124,78 +124,149 @@ CreateProcessA (LPCSTR lpApplicationName,
|
||||||
HANDLE STDCALL
|
HANDLE STDCALL
|
||||||
KlCreateFirstThread(HANDLE ProcessHandle,
|
KlCreateFirstThread(HANDLE ProcessHandle,
|
||||||
LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
||||||
DWORD dwStackSize,
|
ULONG StackReserve,
|
||||||
|
ULONG StackCommit,
|
||||||
LPTHREAD_START_ROUTINE lpStartAddress,
|
LPTHREAD_START_ROUTINE lpStartAddress,
|
||||||
DWORD dwCreationFlags,
|
DWORD dwCreationFlags,
|
||||||
LPDWORD lpThreadId)
|
LPDWORD lpThreadId)
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
HANDLE ThreadHandle;
|
HANDLE ThreadHandle;
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
CLIENT_ID ClientId;
|
CLIENT_ID ClientId;
|
||||||
CONTEXT ThreadContext;
|
CONTEXT ThreadContext;
|
||||||
INITIAL_TEB InitialTeb;
|
INITIAL_TEB InitialTeb;
|
||||||
BOOLEAN CreateSuspended = FALSE;
|
BOOLEAN CreateSuspended = FALSE;
|
||||||
PVOID BaseAddress;
|
ULONG OldPageProtection;
|
||||||
|
|
||||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||||
ObjectAttributes.RootDirectory = NULL;
|
ObjectAttributes.RootDirectory = NULL;
|
||||||
ObjectAttributes.ObjectName = NULL;
|
ObjectAttributes.ObjectName = NULL;
|
||||||
ObjectAttributes.Attributes = 0;
|
ObjectAttributes.Attributes = 0;
|
||||||
if (lpThreadAttributes != NULL)
|
if (lpThreadAttributes != NULL)
|
||||||
{
|
{
|
||||||
if (lpThreadAttributes->bInheritHandle)
|
if (lpThreadAttributes->bInheritHandle)
|
||||||
ObjectAttributes.Attributes = OBJ_INHERIT;
|
ObjectAttributes.Attributes = OBJ_INHERIT;
|
||||||
ObjectAttributes.SecurityDescriptor =
|
ObjectAttributes.SecurityDescriptor =
|
||||||
lpThreadAttributes->lpSecurityDescriptor;
|
lpThreadAttributes->lpSecurityDescriptor;
|
||||||
}
|
}
|
||||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||||
|
|
||||||
if ((dwCreationFlags & CREATE_SUSPENDED) == CREATE_SUSPENDED)
|
if ((dwCreationFlags & CREATE_SUSPENDED) == CREATE_SUSPENDED)
|
||||||
CreateSuspended = TRUE;
|
CreateSuspended = TRUE;
|
||||||
else
|
else
|
||||||
CreateSuspended = FALSE;
|
CreateSuspended = FALSE;
|
||||||
|
|
||||||
/* Allocate thread stack */
|
InitialTeb.StackCommit = (StackCommit < PAGESIZE) ? PAGESIZE : StackCommit;
|
||||||
BaseAddress = NULL;
|
InitialTeb.StackReserve = (StackReserve < 0x100000) ? 0x100000 : StackReserve;
|
||||||
Status = NtAllocateVirtualMemory(ProcessHandle,
|
|
||||||
&BaseAddress,
|
|
||||||
0,
|
|
||||||
(PULONG)&dwStackSize,
|
|
||||||
MEM_COMMIT,
|
|
||||||
PAGE_READWRITE);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&ThreadContext,0,sizeof(CONTEXT));
|
/* size of guard page */
|
||||||
ThreadContext.Eip = (ULONG)lpStartAddress;
|
InitialTeb.StackCommit += PAGESIZE;
|
||||||
ThreadContext.SegGs = USER_DS;
|
|
||||||
ThreadContext.SegFs = USER_DS;
|
|
||||||
ThreadContext.SegEs = USER_DS;
|
|
||||||
ThreadContext.SegDs = USER_DS;
|
|
||||||
ThreadContext.SegCs = USER_CS;
|
|
||||||
ThreadContext.SegSs = USER_DS;
|
|
||||||
ThreadContext.Esp = (ULONG)(BaseAddress + dwStackSize - 20);
|
|
||||||
ThreadContext.EFlags = (1<<1) + (1<<9);
|
|
||||||
|
|
||||||
DPRINT("ThreadContext.Eip %x\n",ThreadContext.Eip);
|
/* Reserve stack */
|
||||||
|
InitialTeb.StackAllocate = NULL;
|
||||||
|
Status = NtAllocateVirtualMemory(ProcessHandle,
|
||||||
|
&InitialTeb.StackAllocate,
|
||||||
|
0,
|
||||||
|
&InitialTeb.StackReserve,
|
||||||
|
MEM_COMMIT, // MEM_RESERVE,
|
||||||
|
PAGE_READWRITE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT("Error reserving stack space!\n");
|
||||||
|
SetLastErrorByStatus(Status);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
Status = NtCreateThread(&ThreadHandle,
|
DPRINT("StackDeallocation: %p ReserveSize: 0x%lX\n",
|
||||||
THREAD_ALL_ACCESS,
|
InitialTeb.StackDeallocation, InitialTeb.StackReserve);
|
||||||
&ObjectAttributes,
|
|
||||||
ProcessHandle,
|
|
||||||
&ClientId,
|
|
||||||
&ThreadContext,
|
|
||||||
&InitialTeb,
|
|
||||||
CreateSuspended);
|
|
||||||
if (lpThreadId != NULL)
|
|
||||||
{
|
|
||||||
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
|
|
||||||
}
|
|
||||||
|
|
||||||
return(ThreadHandle);
|
InitialTeb.StackBase = (PVOID)((ULONG)InitialTeb.StackAllocate + InitialTeb.StackReserve);
|
||||||
|
InitialTeb.StackLimit = (PVOID)((ULONG)InitialTeb.StackBase - InitialTeb.StackCommit);
|
||||||
|
|
||||||
|
DPRINT("StackBase: %p\nStackCommit: %p\n",
|
||||||
|
InitialTeb.StackBase, InitialTeb.StackCommit);
|
||||||
|
#if 0
|
||||||
|
/* Commit stack page(s) */
|
||||||
|
Status = NtAllocateVirtualMemory(ProcessHandle,
|
||||||
|
&InitialTeb.StackLimit,
|
||||||
|
0,
|
||||||
|
&InitialTeb.StackCommit,
|
||||||
|
MEM_COMMIT,
|
||||||
|
PAGE_READWRITE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* release the stack space */
|
||||||
|
NtFreeVirtualMemory(ProcessHandle,
|
||||||
|
InitialTeb.StackAllocate,
|
||||||
|
&InitialTeb.StackReserve,
|
||||||
|
MEM_RELEASE);
|
||||||
|
|
||||||
|
DPRINT("Error comitting stack page(s)!\n");
|
||||||
|
SetLastErrorByStatus(Status);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINT("StackLimit: %p\n",
|
||||||
|
InitialTeb.StackLimit);
|
||||||
|
|
||||||
|
/* Protect guard page */
|
||||||
|
Status = NtProtectVirtualMemory(ProcessHandle,
|
||||||
|
InitialTeb.StackLimit,
|
||||||
|
PAGESIZE,
|
||||||
|
PAGE_GUARD | PAGE_READWRITE,
|
||||||
|
&OldPageProtection);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* release the stack space */
|
||||||
|
NtFreeVirtualMemory(ProcessHandle,
|
||||||
|
InitialTeb.StackAllocate,
|
||||||
|
&InitialTeb.StackReserve,
|
||||||
|
MEM_RELEASE);
|
||||||
|
|
||||||
|
DPRINT("Error comitting guard page!\n");
|
||||||
|
SetLastErrorByStatus(Status);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
memset(&ThreadContext,0,sizeof(CONTEXT));
|
||||||
|
ThreadContext.Eip = (ULONG)lpStartAddress;
|
||||||
|
ThreadContext.SegGs = USER_DS;
|
||||||
|
ThreadContext.SegFs = USER_DS;
|
||||||
|
ThreadContext.SegEs = USER_DS;
|
||||||
|
ThreadContext.SegDs = USER_DS;
|
||||||
|
ThreadContext.SegCs = USER_CS;
|
||||||
|
ThreadContext.SegSs = USER_DS;
|
||||||
|
ThreadContext.Esp = (ULONG)InitialTeb.StackBase - 20;
|
||||||
|
ThreadContext.EFlags = (1<<1) + (1<<9);
|
||||||
|
|
||||||
|
DPRINT("ThreadContext.Eip %x\n",ThreadContext.Eip);
|
||||||
|
|
||||||
|
Status = NtCreateThread(&ThreadHandle,
|
||||||
|
THREAD_ALL_ACCESS,
|
||||||
|
&ObjectAttributes,
|
||||||
|
ProcessHandle,
|
||||||
|
&ClientId,
|
||||||
|
&ThreadContext,
|
||||||
|
&InitialTeb,
|
||||||
|
CreateSuspended);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
NtFreeVirtualMemory(ProcessHandle,
|
||||||
|
InitialTeb.StackAllocate,
|
||||||
|
&InitialTeb.StackReserve,
|
||||||
|
MEM_RELEASE);
|
||||||
|
SetLastErrorByStatus(Status);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lpThreadId != NULL)
|
||||||
|
{
|
||||||
|
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
|
||||||
|
}
|
||||||
|
|
||||||
|
return(ThreadHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE
|
HANDLE
|
||||||
|
@ -328,7 +399,7 @@ KlInitPeb (HANDLE ProcessHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create the PPB */
|
/* create the PPB */
|
||||||
PpbBase = (PVOID)PEB_STARTUPINFO;
|
PpbBase = NULL;
|
||||||
PpbSize = Ppb->MaximumLength;
|
PpbSize = Ppb->MaximumLength;
|
||||||
Status = NtAllocateVirtualMemory(ProcessHandle,
|
Status = NtAllocateVirtualMemory(ProcessHandle,
|
||||||
&PpbBase,
|
&PpbBase,
|
||||||
|
@ -574,10 +645,11 @@ CreateProcessW(LPCWSTR lpApplicationName,
|
||||||
lpThreadAttributes,
|
lpThreadAttributes,
|
||||||
//Sii.StackReserve,
|
//Sii.StackReserve,
|
||||||
0x200000,
|
0x200000,
|
||||||
|
//Sii.StackCommit,
|
||||||
|
0x1000,
|
||||||
lpStartAddress,
|
lpStartAddress,
|
||||||
dwCreationFlags,
|
dwCreationFlags,
|
||||||
&lpProcessInformation->dwThreadId);
|
&lpProcessInformation->dwThreadId);
|
||||||
|
|
||||||
if (hThread == NULL)
|
if (hThread == NULL)
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: thread.c,v 1.23 2001/05/07 22:03:26 chorns Exp $
|
/* $Id: thread.c,v 1.24 2001/08/03 17:20:46 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS system libraries
|
* PROJECT: ReactOS system libraries
|
||||||
|
@ -120,7 +120,7 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
|
||||||
INITIAL_TEB InitialTeb;
|
INITIAL_TEB InitialTeb;
|
||||||
BOOLEAN CreateSuspended = FALSE;
|
BOOLEAN CreateSuspended = FALSE;
|
||||||
PVOID BaseAddress;
|
PVOID BaseAddress;
|
||||||
DWORD StackSize;
|
ULONG OldPageProtection;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||||
|
@ -141,83 +141,147 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
|
||||||
else
|
else
|
||||||
CreateSuspended = FALSE;
|
CreateSuspended = FALSE;
|
||||||
|
|
||||||
StackSize = (dwStackSize == 0) ? 4096 : dwStackSize;
|
InitialTeb.StackCommit = (dwStackSize == 0) ? PAGESIZE : dwStackSize;
|
||||||
|
InitialTeb.StackReserve = 0x100000; /* 1MByte */
|
||||||
|
|
||||||
BaseAddress = 0;
|
/* size of guard page */
|
||||||
|
InitialTeb.StackCommit += PAGESIZE;
|
||||||
|
|
||||||
Status = NtAllocateVirtualMemory(hProcess,
|
/* Reserve stack */
|
||||||
&BaseAddress,
|
InitialTeb.StackAllocate = NULL;
|
||||||
0,
|
Status = NtAllocateVirtualMemory(hProcess,
|
||||||
(PULONG)&StackSize,
|
&InitialTeb.StackAllocate,
|
||||||
MEM_COMMIT,
|
0,
|
||||||
PAGE_READWRITE);
|
&InitialTeb.StackReserve,
|
||||||
if (!NT_SUCCESS(Status))
|
MEM_COMMIT, //MEM_RESERVE,
|
||||||
{
|
PAGE_READWRITE);
|
||||||
DPRINT("Could not allocate stack space!\n");
|
if (!NT_SUCCESS(Status))
|
||||||
return NULL;
|
{
|
||||||
}
|
DPRINT("Error reserving stack space!\n");
|
||||||
|
SetLastErrorByStatus(Status);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINT("StackDeallocation: %p ReserveSize: 0x%lX\n",
|
||||||
|
InitialTeb.StackDeallocation, InitialTeb.StackReserve);
|
||||||
|
|
||||||
DPRINT("Stack base address: %p\n", BaseAddress);
|
InitialTeb.StackBase = (PVOID)((ULONG)InitialTeb.StackAllocate + InitialTeb.StackReserve);
|
||||||
|
InitialTeb.StackLimit = (PVOID)((ULONG)InitialTeb.StackBase - InitialTeb.StackCommit);
|
||||||
|
|
||||||
memset(&ThreadContext,0,sizeof(CONTEXT));
|
DPRINT("StackBase: %p\nStackCommit: 0x%lX\n",
|
||||||
ThreadContext.Eip = (LONG)ThreadStartup;
|
InitialTeb.StackBase,
|
||||||
ThreadContext.SegGs = USER_DS;
|
InitialTeb.StackCommit);
|
||||||
ThreadContext.SegFs = TEB_SELECTOR;
|
#if 0
|
||||||
ThreadContext.SegEs = USER_DS;
|
/* Commit stack pages */
|
||||||
ThreadContext.SegDs = USER_DS;
|
Status = NtAllocateVirtualMemory(hProcess,
|
||||||
ThreadContext.SegCs = USER_CS;
|
&InitialTeb.StackLimit,
|
||||||
ThreadContext.SegSs = USER_DS;
|
0,
|
||||||
ThreadContext.Esp = (ULONG)(BaseAddress + StackSize - 12);
|
&InitialTeb.StackCommit,
|
||||||
ThreadContext.EFlags = (1<<1) + (1<<9);
|
MEM_COMMIT,
|
||||||
|
PAGE_READWRITE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* release the stack space */
|
||||||
|
NtFreeVirtualMemory(hProcess,
|
||||||
|
InitialTeb.StackAllocate,
|
||||||
|
&InitialTeb.StackReserve,
|
||||||
|
MEM_RELEASE);
|
||||||
|
|
||||||
/* initialize call stack */
|
DPRINT("Error comitting stack page(s)!\n");
|
||||||
*((PULONG)(BaseAddress + StackSize - 4)) = (ULONG)lpParameter;
|
SetLastErrorByStatus(Status);
|
||||||
*((PULONG)(BaseAddress + StackSize - 8)) = (ULONG)lpStartAddress;
|
return(NULL);
|
||||||
*((PULONG)(BaseAddress + StackSize - 12)) = 0xdeadbeef;
|
}
|
||||||
|
|
||||||
DPRINT("Esp: %p\n", ThreadContext.Esp);
|
DPRINT("StackLimit: %p\n",
|
||||||
DPRINT("Eip: %p\n", ThreadContext.Eip);
|
InitialTeb.StackLimit);
|
||||||
|
|
||||||
Status = NtCreateThread(&ThreadHandle,
|
/* Protect guard page */
|
||||||
THREAD_ALL_ACCESS,
|
Status = NtProtectVirtualMemory(hProcess,
|
||||||
&ObjectAttributes,
|
InitialTeb.StackLimit,
|
||||||
hProcess,
|
PAGESIZE,
|
||||||
&ClientId,
|
PAGE_GUARD | PAGE_READWRITE,
|
||||||
&ThreadContext,
|
&OldPageProtection);
|
||||||
&InitialTeb,
|
if (!NT_SUCCESS(Status))
|
||||||
CreateSuspended);
|
{
|
||||||
|
/* release the stack space */
|
||||||
|
NtFreeVirtualMemory(hProcess,
|
||||||
|
InitialTeb.StackAllocate,
|
||||||
|
&InitialTeb.StackReserve,
|
||||||
|
MEM_RELEASE);
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
DPRINT("Error comitting guard page!\n");
|
||||||
{
|
SetLastErrorByStatus(Status);
|
||||||
DPRINT("NtCreateThread() failed!\n");
|
return(NULL);
|
||||||
return NULL;
|
}
|
||||||
}
|
#endif
|
||||||
|
|
||||||
if ( lpThreadId != NULL )
|
memset(&ThreadContext,0,sizeof(CONTEXT));
|
||||||
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
|
ThreadContext.Eip = (LONG)ThreadStartup;
|
||||||
|
ThreadContext.SegGs = USER_DS;
|
||||||
|
ThreadContext.SegFs = TEB_SELECTOR;
|
||||||
|
ThreadContext.SegEs = USER_DS;
|
||||||
|
ThreadContext.SegDs = USER_DS;
|
||||||
|
ThreadContext.SegCs = USER_CS;
|
||||||
|
ThreadContext.SegSs = USER_DS;
|
||||||
|
ThreadContext.Esp = (ULONG)InitialTeb.StackBase - 12;
|
||||||
|
ThreadContext.EFlags = (1<<1) + (1<<9);
|
||||||
|
|
||||||
return ThreadHandle;
|
/* initialize call stack */
|
||||||
|
*((PULONG)((ULONG)InitialTeb.StackBase - 4)) = (ULONG)lpParameter;
|
||||||
|
*((PULONG)((ULONG)InitialTeb.StackBase - 8)) = (ULONG)lpStartAddress;
|
||||||
|
*((PULONG)((ULONG)InitialTeb.StackBase - 12)) = 0xdeadbeef;
|
||||||
|
|
||||||
|
DPRINT("Esp: %p\n", ThreadContext.Esp);
|
||||||
|
DPRINT("Eip: %p\n", ThreadContext.Eip);
|
||||||
|
|
||||||
|
Status = NtCreateThread(&ThreadHandle,
|
||||||
|
THREAD_ALL_ACCESS,
|
||||||
|
&ObjectAttributes,
|
||||||
|
hProcess,
|
||||||
|
&ClientId,
|
||||||
|
&ThreadContext,
|
||||||
|
&InitialTeb,
|
||||||
|
CreateSuspended);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
NtFreeVirtualMemory(hProcess,
|
||||||
|
InitialTeb.StackAllocate,
|
||||||
|
&InitialTeb.StackReserve,
|
||||||
|
MEM_RELEASE);
|
||||||
|
|
||||||
|
DPRINT("NtCreateThread() failed!\n");
|
||||||
|
SetLastErrorByStatus(Status);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lpThreadId != NULL)
|
||||||
|
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
|
||||||
|
|
||||||
|
return(ThreadHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
NT_TEB *GetTeb(VOID)
|
PTEB
|
||||||
|
GetTeb(VOID)
|
||||||
{
|
{
|
||||||
return NtCurrentTeb();
|
return(NtCurrentTeb());
|
||||||
}
|
}
|
||||||
|
|
||||||
WINBOOL STDCALL SwitchToThread(VOID)
|
WINBOOL STDCALL
|
||||||
|
SwitchToThread(VOID)
|
||||||
{
|
{
|
||||||
NTSTATUS errCode;
|
NTSTATUS errCode;
|
||||||
errCode = NtYieldExecution();
|
errCode = NtYieldExecution();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD STDCALL GetCurrentThreadId()
|
DWORD STDCALL
|
||||||
|
GetCurrentThreadId()
|
||||||
{
|
{
|
||||||
return((DWORD)(NtCurrentTeb()->Cid).UniqueThread);
|
return((DWORD)(NtCurrentTeb()->Cid).UniqueThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID STDCALL ExitThread(DWORD uExitCode)
|
VOID STDCALL
|
||||||
|
ExitThread(DWORD uExitCode)
|
||||||
{
|
{
|
||||||
NTSTATUS errCode;
|
NTSTATUS errCode;
|
||||||
BOOLEAN LastThread;
|
BOOLEAN LastThread;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: debug.c,v 1.2 2000/05/25 15:50:44 ekohl Exp $
|
/* $Id: debug.c,v 1.3 2001/08/03 17:17:16 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -34,11 +34,8 @@ typedef struct _LPC_DBGSS_MESSAGE
|
||||||
|
|
||||||
/* FUNCTIONS *****************************************************************/
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
VOID
|
VOID STDCALL
|
||||||
STDCALL
|
DbgSsServerThread(PVOID Unused)
|
||||||
DbgSsServerThread (
|
|
||||||
PVOID Unused
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
LPC_DBGSS_MESSAGE Message;
|
LPC_DBGSS_MESSAGE Message;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
@ -65,26 +62,19 @@ DbgSsServerThread (
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS STDCALL
|
||||||
STDCALL
|
DbgSsHandleKmApiMsg(ULONG Unknown1,
|
||||||
DbgSsHandleKmApiMsg (
|
HANDLE EventHandle)
|
||||||
ULONG Unknown1,
|
|
||||||
HANDLE EventHandle
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS STDCALL
|
||||||
STDCALL
|
DbgSsInitialize(HANDLE ReplyPort,
|
||||||
DbgSsInitialize (
|
ULONG Unknown1,
|
||||||
HANDLE ReplyPort,
|
ULONG Unknown2,
|
||||||
ULONG Unknown1,
|
ULONG Unknown3)
|
||||||
ULONG Unknown2,
|
|
||||||
ULONG Unknown3
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
SECURITY_QUALITY_OF_SERVICE Qos;
|
SECURITY_QUALITY_OF_SERVICE Qos;
|
||||||
UNICODE_STRING PortName;
|
UNICODE_STRING PortName;
|
||||||
|
@ -129,16 +119,13 @@ DbgSsInitialize (
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS STDCALL
|
||||||
STDCALL
|
DbgUiConnectToDbg(VOID)
|
||||||
DbgUiConnectToDbg (
|
|
||||||
VOID
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
SECURITY_QUALITY_OF_SERVICE Qos;
|
SECURITY_QUALITY_OF_SERVICE Qos;
|
||||||
UNICODE_STRING PortName;
|
UNICODE_STRING PortName;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PNT_TEB Teb;
|
PTEB Teb;
|
||||||
ULONG InfoSize;
|
ULONG InfoSize;
|
||||||
|
|
||||||
Teb = NtCurrentTeb ();
|
Teb = NtCurrentTeb ();
|
||||||
|
@ -173,24 +160,19 @@ DbgUiConnectToDbg (
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS STDCALL
|
||||||
STDCALL
|
DbgUiContinue(PCLIENT_ID ClientId,
|
||||||
DbgUiContinue (
|
ULONG ContinueStatus)
|
||||||
PCLIENT_ID ClientId,
|
|
||||||
ULONG ContinueStatus
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
|
||||||
STDCALL
|
NTSTATUS STDCALL
|
||||||
DbgUiWaitStateChange (
|
DbgUiWaitStateChange(ULONG Unknown1,
|
||||||
ULONG Unknown1,
|
ULONG Unknown2)
|
||||||
ULONG Unknown2
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: error.c,v 1.7 2000/07/04 01:26:35 ekohl Exp $
|
/* $Id: error.c,v 1.8 2001/08/03 17:18:50 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -858,9 +858,8 @@ RtlAssert (
|
||||||
* REMARK
|
* REMARK
|
||||||
* RtlNtStatusToDosErrorNoTeb() does the real work.
|
* RtlNtStatusToDosErrorNoTeb() does the real work.
|
||||||
*/
|
*/
|
||||||
DWORD
|
DWORD STDCALL
|
||||||
STDCALL
|
RtlNtStatusToDosErrorNoTeb(NTSTATUS Status)
|
||||||
RtlNtStatusToDosErrorNoTeb (NTSTATUS Status)
|
|
||||||
{
|
{
|
||||||
PERROR_TABLE Table = (PERROR_TABLE)ErrorTable;
|
PERROR_TABLE Table = (PERROR_TABLE)ErrorTable;
|
||||||
|
|
||||||
|
@ -917,19 +916,16 @@ RtlNtStatusToDosErrorNoTeb (NTSTATUS Status)
|
||||||
* REMARK
|
* REMARK
|
||||||
* RtlNtStatusToDosErrorNoTeb() does the real work.
|
* RtlNtStatusToDosErrorNoTeb() does the real work.
|
||||||
*/
|
*/
|
||||||
DWORD
|
DWORD STDCALL
|
||||||
STDCALL
|
RtlNtStatusToDosError(NTSTATUS Status)
|
||||||
RtlNtStatusToDosError (
|
|
||||||
NTSTATUS Status
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
PNT_TEB Teb = NtCurrentTeb ();
|
PTEB Teb = NtCurrentTeb();
|
||||||
|
|
||||||
if (NULL != Teb)
|
if (NULL != Teb)
|
||||||
{
|
{
|
||||||
Teb->LastStatusValue = Status;
|
Teb->LastStatusValue = Status;
|
||||||
}
|
}
|
||||||
return RtlNtStatusToDosErrorNoTeb (Status);
|
return RtlNtStatusToDosErrorNoTeb(Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -954,18 +950,15 @@ RtlNtStatusToDosError (
|
||||||
* REVISIONS
|
* REVISIONS
|
||||||
* 1999-11-30 ea
|
* 1999-11-30 ea
|
||||||
*/
|
*/
|
||||||
INT
|
INT STDCALL
|
||||||
STDCALL
|
RtlNtStatusToPsxErrno(IN NTSTATUS Status)
|
||||||
RtlNtStatusToPsxErrno (
|
|
||||||
IN NTSTATUS Status
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
switch (Status)
|
switch (Status)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return -1; /* generic POSIX error */
|
return -1; /* generic POSIX error */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: process.c,v 1.25 2001/06/22 12:36:22 ekohl Exp $
|
/* $Id: process.c,v 1.26 2001/08/03 17:18:50 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS system libraries
|
* PROJECT: ReactOS system libraries
|
||||||
|
@ -22,65 +22,136 @@
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
HANDLE STDCALL KlCreateFirstThread(HANDLE ProcessHandle,
|
static NTSTATUS
|
||||||
ULONG StackSize,
|
RtlpCreateFirstThread(HANDLE ProcessHandle,
|
||||||
LPTHREAD_START_ROUTINE lpStartAddress,
|
ULONG StackReserve,
|
||||||
PCLIENT_ID ClientId)
|
ULONG StackCommit,
|
||||||
|
LPTHREAD_START_ROUTINE lpStartAddress,
|
||||||
|
PCLIENT_ID ClientId,
|
||||||
|
PHANDLE ThreadHandle)
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
HANDLE ThreadHandle;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
CONTEXT ThreadContext;
|
||||||
CONTEXT ThreadContext;
|
INITIAL_TEB InitialTeb;
|
||||||
INITIAL_TEB InitialTeb;
|
ULONG OldPageProtection;
|
||||||
PVOID BaseAddress;
|
CLIENT_ID Cid;
|
||||||
CLIENT_ID Cid;
|
|
||||||
|
|
||||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||||
ObjectAttributes.RootDirectory = NULL;
|
ObjectAttributes.RootDirectory = NULL;
|
||||||
ObjectAttributes.ObjectName = NULL;
|
ObjectAttributes.ObjectName = NULL;
|
||||||
ObjectAttributes.Attributes = 0;
|
ObjectAttributes.Attributes = 0;
|
||||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||||
|
|
||||||
BaseAddress = NULL;
|
if (StackCommit > PAGESIZE)
|
||||||
Status = NtAllocateVirtualMemory(ProcessHandle,
|
InitialTeb.StackCommit = StackCommit;
|
||||||
&BaseAddress,
|
else
|
||||||
0,
|
InitialTeb.StackCommit = PAGESIZE;
|
||||||
(PULONG)&StackSize,
|
|
||||||
MEM_COMMIT,
|
|
||||||
PAGE_READWRITE);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
DPRINT("Failed to allocate stack\n");
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&ThreadContext,0,sizeof(CONTEXT));
|
if (StackReserve > 0x100000)
|
||||||
ThreadContext.Eip = (ULONG)lpStartAddress;
|
InitialTeb.StackReserve = StackReserve;
|
||||||
ThreadContext.SegGs = USER_DS;
|
else
|
||||||
ThreadContext.SegFs = TEB_SELECTOR;
|
InitialTeb.StackReserve = 0x100000; /* 1MByte */
|
||||||
ThreadContext.SegEs = USER_DS;
|
|
||||||
ThreadContext.SegDs = USER_DS;
|
|
||||||
ThreadContext.SegCs = USER_CS;
|
|
||||||
ThreadContext.SegSs = USER_DS;
|
|
||||||
ThreadContext.Esp = (ULONG)BaseAddress + StackSize - 20;
|
|
||||||
ThreadContext.EFlags = (1<<1) + (1<<9);
|
|
||||||
|
|
||||||
DPRINT("ThreadContext.Eip %x\n",ThreadContext.Eip);
|
/* Reserve stack */
|
||||||
|
InitialTeb.StackAllocate = NULL;
|
||||||
|
Status = NtAllocateVirtualMemory(ProcessHandle,
|
||||||
|
&InitialTeb.StackAllocate,
|
||||||
|
0,
|
||||||
|
&InitialTeb.StackReserve,
|
||||||
|
MEM_COMMIT, //MEM_RESERVE,
|
||||||
|
PAGE_READWRITE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT("Error reserving stack space!\n");
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
|
||||||
Status = NtCreateThread(&ThreadHandle,
|
DPRINT("StackAllocate: %p ReserveSize: 0x%lX\n",
|
||||||
THREAD_ALL_ACCESS,
|
InitialTeb.StackAllocate, InitialTeb.StackReserve);
|
||||||
&ObjectAttributes,
|
|
||||||
ProcessHandle,
|
|
||||||
&Cid,
|
|
||||||
&ThreadContext,
|
|
||||||
&InitialTeb,
|
|
||||||
FALSE);
|
|
||||||
if (ClientId != NULL)
|
|
||||||
{
|
|
||||||
memcpy(&ClientId->UniqueThread, &Cid.UniqueThread, sizeof(ULONG));
|
|
||||||
}
|
|
||||||
|
|
||||||
return(ThreadHandle);
|
InitialTeb.StackBase = (PVOID)((ULONG)InitialTeb.StackAllocate + InitialTeb.StackReserve);
|
||||||
|
InitialTeb.StackLimit = (PVOID)((ULONG)InitialTeb.StackBase - InitialTeb.StackCommit - PAGESIZE);
|
||||||
|
InitialTeb.StackCommit += PAGESIZE;
|
||||||
|
|
||||||
|
DPRINT("StackBase: %p StackCommit: 0x%lX\n",
|
||||||
|
InitialTeb.StackBase, InitialTeb.StackCommit);
|
||||||
|
#if 0
|
||||||
|
/* Commit stack */
|
||||||
|
Status = NtAllocateVirtualMemory(ProcessHandle,
|
||||||
|
&InitialTeb.StackLimit,
|
||||||
|
0,
|
||||||
|
&InitialTeb.StackCommit,
|
||||||
|
MEM_COMMIT,
|
||||||
|
PAGE_READWRITE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* release the stack space */
|
||||||
|
NtFreeVirtualMemory(ProcessHandle,
|
||||||
|
InitialTeb.StackAllocate,
|
||||||
|
&InitialTeb.StackReserve,
|
||||||
|
MEM_RELEASE);
|
||||||
|
|
||||||
|
DPRINT("Error comitting stack page(s)!\n");
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINT("StackLimit: %p\n", InitialTeb.StackLimit);
|
||||||
|
|
||||||
|
/* Protect guard page */
|
||||||
|
Status = NtProtectVirtualMemory(ProcessHandle,
|
||||||
|
InitialTeb.StackLimit,
|
||||||
|
PAGESIZE,
|
||||||
|
PAGE_GUARD | PAGE_READWRITE,
|
||||||
|
&OldPageProtection);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* release the stack space */
|
||||||
|
NtFreeVirtualMemory(ProcessHandle,
|
||||||
|
InitialTeb.StackAllocate,
|
||||||
|
&InitialTeb.StackReserve,
|
||||||
|
MEM_RELEASE);
|
||||||
|
|
||||||
|
DPRINT("Error comitting guard page!\n");
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
memset(&ThreadContext,0,sizeof(CONTEXT));
|
||||||
|
ThreadContext.Eip = (ULONG)lpStartAddress;
|
||||||
|
ThreadContext.SegGs = USER_DS;
|
||||||
|
ThreadContext.SegFs = TEB_SELECTOR;
|
||||||
|
ThreadContext.SegEs = USER_DS;
|
||||||
|
ThreadContext.SegDs = USER_DS;
|
||||||
|
ThreadContext.SegCs = USER_CS;
|
||||||
|
ThreadContext.SegSs = USER_DS;
|
||||||
|
ThreadContext.Esp = (ULONG)InitialTeb.StackBase - 20;
|
||||||
|
ThreadContext.EFlags = (1<<1) + (1<<9);
|
||||||
|
|
||||||
|
DPRINT("ThreadContext.Eip %x\n",ThreadContext.Eip);
|
||||||
|
|
||||||
|
Status = NtCreateThread(ThreadHandle,
|
||||||
|
THREAD_ALL_ACCESS,
|
||||||
|
&ObjectAttributes,
|
||||||
|
ProcessHandle,
|
||||||
|
&Cid,
|
||||||
|
&ThreadContext,
|
||||||
|
&InitialTeb,
|
||||||
|
FALSE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
NtFreeVirtualMemory(ProcessHandle,
|
||||||
|
InitialTeb.StackAllocate,
|
||||||
|
&InitialTeb.StackReserve,
|
||||||
|
MEM_RELEASE);
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ClientId != NULL)
|
||||||
|
{
|
||||||
|
memcpy(&ClientId->UniqueThread, &Cid.UniqueThread, sizeof(ULONG));
|
||||||
|
}
|
||||||
|
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static NTSTATUS
|
static NTSTATUS
|
||||||
|
@ -184,7 +255,6 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
|
||||||
PVOID EnvPtr = NULL;
|
PVOID EnvPtr = NULL;
|
||||||
ULONG EnvSize = 0;
|
ULONG EnvSize = 0;
|
||||||
|
|
||||||
|
|
||||||
/* create the Environment */
|
/* create the Environment */
|
||||||
if (Ppb->Environment != NULL)
|
if (Ppb->Environment != NULL)
|
||||||
{
|
{
|
||||||
|
@ -227,7 +297,7 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
|
||||||
DPRINT("EnvironmentPointer %p\n", EnvPtr);
|
DPRINT("EnvironmentPointer %p\n", EnvPtr);
|
||||||
|
|
||||||
/* create the PPB */
|
/* create the PPB */
|
||||||
PpbBase = (PVOID)PEB_STARTUPINFO;
|
PpbBase = NULL;
|
||||||
PpbSize = Ppb->MaximumLength;
|
PpbSize = Ppb->MaximumLength;
|
||||||
Status = NtAllocateVirtualMemory(ProcessHandle,
|
Status = NtAllocateVirtualMemory(ProcessHandle,
|
||||||
&PpbBase,
|
&PpbBase,
|
||||||
|
@ -284,7 +354,6 @@ RtlCreateUserProcess(PUNICODE_STRING ImageFileName,
|
||||||
PRTL_PROCESS_INFO ProcessInfo)
|
PRTL_PROCESS_INFO ProcessInfo)
|
||||||
{
|
{
|
||||||
HANDLE hSection;
|
HANDLE hSection;
|
||||||
HANDLE hThread;
|
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
LPTHREAD_START_ROUTINE lpStartAddress = NULL;
|
LPTHREAD_START_ROUTINE lpStartAddress = NULL;
|
||||||
PROCESS_BASIC_INFORMATION ProcessBasicInfo;
|
PROCESS_BASIC_INFORMATION ProcessBasicInfo;
|
||||||
|
@ -317,6 +386,7 @@ RtlCreateUserProcess(PUNICODE_STRING ImageFileName,
|
||||||
ExceptionPort);
|
ExceptionPort);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
NtClose(hSection);
|
||||||
return(Status);
|
return(Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,20 +423,25 @@ RtlCreateUserProcess(PUNICODE_STRING ImageFileName,
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
|
DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
|
||||||
|
NtClose(hSection);
|
||||||
return (Status);
|
return (Status);
|
||||||
}
|
}
|
||||||
DPRINT("lpStartAddress 0x%08lx\n", (ULONG)lpStartAddress);
|
DPRINT("lpStartAddress 0x%08lx\n", (ULONG)lpStartAddress);
|
||||||
|
|
||||||
DPRINT("Creating thread for process\n");
|
DPRINT("Creating thread for process\n");
|
||||||
hThread = KlCreateFirstThread(ProcessInfo->ProcessHandle,
|
Status = RtlpCreateFirstThread(ProcessInfo->ProcessHandle,
|
||||||
// Headers.OptionalHeader.SizeOfStackReserve,
|
// Headers.OptionalHeader.SizeOfStackReserve,
|
||||||
0x200000,
|
0x200000,
|
||||||
|
// Headers.OptionalHeader.SizeOfStackCommit,
|
||||||
|
0x1000,
|
||||||
lpStartAddress,
|
lpStartAddress,
|
||||||
&(ProcessInfo->ClientId));
|
&ProcessInfo->ClientId,
|
||||||
if (hThread == NULL)
|
&ProcessInfo->ThreadHandle);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT("Failed to create thread\n");
|
DPRINT("Failed to create thread\n");
|
||||||
return(STATUS_UNSUCCESSFUL);
|
NtClose(hSection);
|
||||||
|
return(Status);
|
||||||
}
|
}
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,99 +40,87 @@ RtlCreateUserThread(HANDLE ProcessHandle,
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
INITIAL_TEB InitialTeb;
|
INITIAL_TEB InitialTeb;
|
||||||
CONTEXT ThreadContext;
|
CONTEXT ThreadContext;
|
||||||
ULONG ReserveSize;
|
ULONG OldPageProtection;
|
||||||
ULONG CommitSize;
|
|
||||||
ULONG GuardSize;
|
|
||||||
ULONG RegionSize;
|
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
/* initialize initial teb */
|
/* initialize initial teb */
|
||||||
if ((StackCommit != NULL) && (*StackCommit > PAGESIZE))
|
if ((StackCommit != NULL) && (*StackCommit > PAGESIZE))
|
||||||
CommitSize = *StackCommit;
|
InitialTeb.StackCommit = *StackCommit;
|
||||||
else
|
else
|
||||||
CommitSize = PAGESIZE;
|
InitialTeb.StackCommit = PAGESIZE;
|
||||||
|
|
||||||
if ((StackReserve != NULL) && (*StackReserve > 0x100000))
|
if ((StackReserve != NULL) && (*StackReserve > 0x100000))
|
||||||
ReserveSize = *StackReserve;
|
InitialTeb.StackReserve = *StackReserve;
|
||||||
else
|
else
|
||||||
ReserveSize = 0x100000; /* 1MByte */
|
InitialTeb.StackReserve = 0x100000; /* 1MByte */
|
||||||
|
|
||||||
GuardSize = PAGESIZE;
|
/* add size of guard page */
|
||||||
|
InitialTeb.StackCommit += PAGESIZE;
|
||||||
RegionSize = 0;
|
|
||||||
|
|
||||||
/* Reserve stack */
|
/* Reserve stack */
|
||||||
InitialTeb.StackReserve = NULL;
|
InitialTeb.StackAllocate = NULL;
|
||||||
Status = NtAllocateVirtualMemory(ProcessHandle,
|
Status = NtAllocateVirtualMemory(ProcessHandle,
|
||||||
&InitialTeb.StackReserve,
|
&InitialTeb.StackAllocate,
|
||||||
0,
|
0,
|
||||||
&ReserveSize,
|
&InitialTeb.StackReserve,
|
||||||
MEM_RESERVE,
|
MEM_COMMIT, //MEM_RESERVE,
|
||||||
PAGE_READWRITE);
|
PAGE_READWRITE);
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT("Error reserving stack space!\n");
|
DPRINT("Error reserving stack space!\n");
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINT("StackReserved: %p ReservedSize: 0x%lx\n",
|
DPRINT("StackAllocate: %p ReserveSize: 0x%lX\n",
|
||||||
InitialTeb.StackReserve, ReserveSize);
|
InitialTeb.StackAllocate, InitialTeb.StackReserve);
|
||||||
|
|
||||||
InitialTeb.StackBase = (PVOID)(InitialTeb.StackReserve + ReserveSize);
|
InitialTeb.StackBase = (PVOID)((ULONG)InitialTeb.StackAllocate + InitialTeb.StackReserve);
|
||||||
InitialTeb.StackCommit = (PVOID)(InitialTeb.StackBase - CommitSize);
|
InitialTeb.StackLimit = (PVOID)((ULONG)InitialTeb.StackBase - InitialTeb.StackCommit);
|
||||||
InitialTeb.StackLimit = (PVOID)(InitialTeb.StackCommit - PAGESIZE);
|
|
||||||
InitialTeb.StackCommitMax = (PVOID)(InitialTeb.StackReserve + PAGESIZE);
|
|
||||||
|
|
||||||
DPRINT("StackBase: %p\n",
|
DPRINT("StackBase: %p StackCommit: 0x%lX\n",
|
||||||
InitialTeb.StackBase);
|
InitialTeb.StackBase, InitialTeb.StackCommit);
|
||||||
|
#if 0
|
||||||
/* Commit stack page */
|
/* Commit stack */
|
||||||
Status = NtAllocateVirtualMemory(ProcessHandle,
|
Status = NtAllocateVirtualMemory(ProcessHandle,
|
||||||
&InitialTeb.StackCommit,
|
&InitialTeb.StackLimit,
|
||||||
0,
|
0,
|
||||||
&CommitSize,
|
&InitialTeb.StackCommit,
|
||||||
MEM_COMMIT,
|
MEM_COMMIT,
|
||||||
PAGE_READWRITE);
|
PAGE_READWRITE);
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
/* release the stack space */
|
/* release the stack space */
|
||||||
NtFreeVirtualMemory(ProcessHandle,
|
NtFreeVirtualMemory(ProcessHandle,
|
||||||
InitialTeb.StackReserve,
|
InitialTeb.StackAllocate,
|
||||||
&RegionSize,
|
&InitialTeb.StackReserve,
|
||||||
MEM_RELEASE);
|
MEM_RELEASE);
|
||||||
|
|
||||||
DPRINT("Error comitting stack page!\n");
|
DPRINT("Error comitting stack page!\n");
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINT("StackCommit: %p CommitSize: 0x%lx\n",
|
DPRINT("StackLimit: %p\nStackCommit: 0x%lX\n",
|
||||||
InitialTeb.StackCommit, CommitSize);
|
InitialTeb.StackLimit,
|
||||||
|
InitialTeb.StackCommit);
|
||||||
|
|
||||||
/* Commit guard page */
|
/* Protect guard page */
|
||||||
Status = NtAllocateVirtualMemory(ProcessHandle,
|
Status = NtProtectVirtualMemory(ProcessHandle,
|
||||||
&InitialTeb.StackLimit,
|
InitialTeb.StackLimit,
|
||||||
0,
|
PAGESIZE,
|
||||||
&GuardSize,
|
PAGE_GUARD | PAGE_READWRITE,
|
||||||
MEM_COMMIT,
|
&OldPageProtection);
|
||||||
PAGE_GUARD);
|
if (!NT_SUCCESS(Status))
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
{
|
||||||
/* release the stack space */
|
/* release the stack space */
|
||||||
NtFreeVirtualMemory(ProcessHandle,
|
NtFreeVirtualMemory(ProcessHandle,
|
||||||
InitialTeb.StackReserve,
|
InitialTeb.StackAllocate,
|
||||||
&RegionSize,
|
&InitialTeb.StackReserve,
|
||||||
MEM_RELEASE);
|
MEM_RELEASE);
|
||||||
|
|
||||||
DPRINT("Error comitting guard page!\n");
|
DPRINT("Error protecting guard page!\n");
|
||||||
return Status;
|
return(Status);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
DPRINT("StackLimit: %p GuardSize: 0x%lx\n",
|
|
||||||
InitialTeb.StackLimit, GuardSize);
|
|
||||||
|
|
||||||
/* initialize thread context */
|
/* initialize thread context */
|
||||||
RtlInitializeContext (ProcessHandle,
|
RtlInitializeContext (ProcessHandle,
|
||||||
&ThreadContext,
|
&ThreadContext,
|
||||||
|
@ -144,7 +132,6 @@ RtlCreateUserThread(HANDLE ProcessHandle,
|
||||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||||
ObjectAttributes.RootDirectory = NULL;
|
ObjectAttributes.RootDirectory = NULL;
|
||||||
ObjectAttributes.ObjectName = NULL;
|
ObjectAttributes.ObjectName = NULL;
|
||||||
// ObjectAttributes.Attributes = 0;
|
|
||||||
ObjectAttributes.Attributes = OBJ_INHERIT;
|
ObjectAttributes.Attributes = OBJ_INHERIT;
|
||||||
ObjectAttributes.SecurityDescriptor = SecurityDescriptor;
|
ObjectAttributes.SecurityDescriptor = SecurityDescriptor;
|
||||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||||
|
@ -162,8 +149,8 @@ RtlCreateUserThread(HANDLE ProcessHandle,
|
||||||
{
|
{
|
||||||
/* release the stack space */
|
/* release the stack space */
|
||||||
NtFreeVirtualMemory(ProcessHandle,
|
NtFreeVirtualMemory(ProcessHandle,
|
||||||
InitialTeb.StackReserve,
|
InitialTeb.StackAllocate,
|
||||||
&RegionSize,
|
&InitialTeb.StackReserve,
|
||||||
MEM_RELEASE);
|
MEM_RELEASE);
|
||||||
|
|
||||||
DPRINT("Error creating thread!\n");
|
DPRINT("Error creating thread!\n");
|
||||||
|
@ -172,11 +159,11 @@ RtlCreateUserThread(HANDLE ProcessHandle,
|
||||||
|
|
||||||
/* return committed stack size */
|
/* return committed stack size */
|
||||||
if (StackCommit)
|
if (StackCommit)
|
||||||
*StackCommit = CommitSize;
|
*StackCommit = InitialTeb.StackCommit;
|
||||||
|
|
||||||
/* return reserved stack size */
|
/* return reserved stack size */
|
||||||
if (StackReserve)
|
if (StackReserve)
|
||||||
*StackReserve = ReserveSize;
|
*StackReserve = InitialTeb.StackReserve;
|
||||||
|
|
||||||
/* return thread handle */
|
/* return thread handle */
|
||||||
if (ThreadHandle)
|
if (ThreadHandle)
|
||||||
|
@ -189,7 +176,7 @@ RtlCreateUserThread(HANDLE ProcessHandle,
|
||||||
ClientId->UniqueThread = LocalClientId.UniqueThread;
|
ClientId->UniqueThread = LocalClientId.UniqueThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status;
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -205,7 +192,6 @@ RtlInitializeContext(HANDLE ProcessHandle,
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
memset (Context, 0, sizeof(CONTEXT));
|
memset (Context, 0, sizeof(CONTEXT));
|
||||||
|
|
||||||
Context->Eip = (LONG)StartAddress;
|
Context->Eip = (LONG)StartAddress;
|
||||||
Context->SegGs = USER_DS;
|
Context->SegGs = USER_DS;
|
||||||
Context->SegFs = TEB_SELECTOR;
|
Context->SegFs = TEB_SELECTOR;
|
||||||
|
@ -228,7 +214,7 @@ RtlInitializeContext(HANDLE ProcessHandle,
|
||||||
Buffer[1] = 0xdeadbeef;
|
Buffer[1] = 0xdeadbeef;
|
||||||
|
|
||||||
Status = NtWriteVirtualMemory(ProcessHandle,
|
Status = NtWriteVirtualMemory(ProcessHandle,
|
||||||
(PVOID)(InitialTeb->StackBase - 4),
|
(PVOID)((ULONG)InitialTeb->StackBase - 8),
|
||||||
Buffer,
|
Buffer,
|
||||||
2 * sizeof(ULONG),
|
2 * sizeof(ULONG),
|
||||||
&BytesWritten);
|
&BytesWritten);
|
||||||
|
@ -240,45 +226,45 @@ RtlInitializeContext(HANDLE ProcessHandle,
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS STDCALL
|
NTSTATUS STDCALL
|
||||||
RtlFreeUserThreadStack (HANDLE ProcessHandle, HANDLE ThreadHandle)
|
RtlFreeUserThreadStack(HANDLE ProcessHandle,
|
||||||
|
HANDLE ThreadHandle)
|
||||||
{
|
{
|
||||||
THREAD_BASIC_INFORMATION ThreadInfo;
|
THREAD_BASIC_INFORMATION ThreadInfo;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
ULONG BytesRead;
|
ULONG BytesRead;
|
||||||
ULONG RegionSize;
|
ULONG RegionSize;
|
||||||
PVOID StackBase;
|
PVOID StackBase;
|
||||||
PNT_TEB Teb;
|
PTEB Teb;
|
||||||
|
|
||||||
Status = NtQueryInformationThread (ThreadHandle,
|
Status = NtQueryInformationThread(ThreadHandle,
|
||||||
ThreadBasicInformation,
|
ThreadBasicInformation,
|
||||||
&ThreadInfo,
|
&ThreadInfo,
|
||||||
sizeof(THREAD_BASIC_INFORMATION),
|
sizeof(THREAD_BASIC_INFORMATION),
|
||||||
NULL);
|
NULL);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
return Status;
|
return(Status);
|
||||||
|
|
||||||
if (ThreadInfo.TebBaseAddress == NULL)
|
if (ThreadInfo.TebBaseAddress == NULL)
|
||||||
return Status;
|
return(Status);
|
||||||
|
|
||||||
Teb = (PNT_TEB)ThreadInfo.TebBaseAddress;
|
Teb = (PTEB)ThreadInfo.TebBaseAddress;
|
||||||
Status = NtReadVirtualMemory (ProcessHandle,
|
Status = NtReadVirtualMemory(ProcessHandle,
|
||||||
&Teb->DeallocationStack,
|
&Teb->DeallocationStack,
|
||||||
&StackBase,
|
&StackBase,
|
||||||
sizeof(PVOID),
|
sizeof(PVOID),
|
||||||
&BytesRead);
|
&BytesRead);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
return Status;
|
return(Status);
|
||||||
|
|
||||||
if (StackBase == NULL)
|
if (StackBase == NULL)
|
||||||
return Status;
|
return(Status);
|
||||||
|
|
||||||
RegionSize = 0;
|
RegionSize = 0;
|
||||||
Status = NtFreeVirtualMemory (ProcessHandle,
|
Status = NtFreeVirtualMemory(ProcessHandle,
|
||||||
StackBase,
|
StackBase,
|
||||||
&RegionSize,
|
&RegionSize,
|
||||||
MEM_RELEASE);
|
MEM_RELEASE);
|
||||||
|
return(Status);
|
||||||
return Status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -119,7 +119,7 @@ typedef struct _KTHREAD
|
||||||
ULONG StackLimit; /* 1C */
|
ULONG StackLimit; /* 1C */
|
||||||
|
|
||||||
/* Pointer to the thread's environment block in user memory */
|
/* Pointer to the thread's environment block in user memory */
|
||||||
NT_TEB* Teb; /* 20 */
|
PTEB Teb; /* 20 */
|
||||||
|
|
||||||
/* Pointer to the thread's TLS array */
|
/* Pointer to the thread's TLS array */
|
||||||
PVOID TlsArray; /* 24 */
|
PVOID TlsArray; /* 24 */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: create.c,v 1.35 2001/07/12 17:21:05 ekohl Exp $
|
/* $Id: create.c,v 1.36 2001/08/03 17:15:00 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -292,7 +292,8 @@ PsBeginThread(PKSTART_ROUTINE StartRoutine, PVOID StartContext)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VOID PiDeleteThread(PVOID ObjectBody)
|
VOID
|
||||||
|
PiDeleteThread(PVOID ObjectBody)
|
||||||
{
|
{
|
||||||
KIRQL oldIrql;
|
KIRQL oldIrql;
|
||||||
|
|
||||||
|
@ -310,7 +311,9 @@ VOID PiDeleteThread(PVOID ObjectBody)
|
||||||
DPRINT("PiDeleteThread() finished\n");
|
DPRINT("PiDeleteThread() finished\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID PiCloseThread(PVOID ObjectBody, ULONG HandleCount)
|
VOID
|
||||||
|
PiCloseThread(PVOID ObjectBody,
|
||||||
|
ULONG HandleCount)
|
||||||
{
|
{
|
||||||
DPRINT("PiCloseThread(ObjectBody %x)\n", ObjectBody);
|
DPRINT("PiCloseThread(ObjectBody %x)\n", ObjectBody);
|
||||||
DPRINT("ObGetReferenceCount(ObjectBody) %d "
|
DPRINT("ObGetReferenceCount(ObjectBody) %d "
|
||||||
|
@ -408,7 +411,7 @@ PsInitializeThread(HANDLE ProcessHandle,
|
||||||
|
|
||||||
static NTSTATUS
|
static NTSTATUS
|
||||||
PsCreateTeb(HANDLE ProcessHandle,
|
PsCreateTeb(HANDLE ProcessHandle,
|
||||||
PNT_TEB *TebPtr,
|
PTEB *TebPtr,
|
||||||
PETHREAD Thread,
|
PETHREAD Thread,
|
||||||
PINITIAL_TEB InitialTeb)
|
PINITIAL_TEB InitialTeb)
|
||||||
{
|
{
|
||||||
|
@ -418,7 +421,7 @@ PsCreateTeb(HANDLE ProcessHandle,
|
||||||
ULONG RegionSize;
|
ULONG RegionSize;
|
||||||
ULONG TebSize;
|
ULONG TebSize;
|
||||||
PVOID TebBase;
|
PVOID TebBase;
|
||||||
NT_TEB Teb;
|
TEB Teb;
|
||||||
ULONG ResultLength;
|
ULONG ResultLength;
|
||||||
|
|
||||||
TebBase = (PVOID)0x7FFDE000;
|
TebBase = (PVOID)0x7FFDE000;
|
||||||
|
@ -471,29 +474,21 @@ PsCreateTeb(HANDLE ProcessHandle,
|
||||||
{
|
{
|
||||||
Teb.Tib.StackBase = InitialTeb->StackBase;
|
Teb.Tib.StackBase = InitialTeb->StackBase;
|
||||||
Teb.Tib.StackLimit = InitialTeb->StackLimit;
|
Teb.Tib.StackLimit = InitialTeb->StackLimit;
|
||||||
|
Teb.DeallocationStack = InitialTeb->StackAllocate;
|
||||||
/*
|
|
||||||
* I don't know if this is really stored in a WNT-TEB,
|
|
||||||
* but it's needed to free the thread stack. (Eric Kohl)
|
|
||||||
*/
|
|
||||||
Teb.StackCommit = InitialTeb->StackCommit;
|
|
||||||
Teb.StackCommitMax = InitialTeb->StackCommitMax;
|
|
||||||
Teb.StackReserve = InitialTeb->StackReserve;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* more initialization */
|
/* more initialization */
|
||||||
Teb.Cid.UniqueThread = Thread->Cid.UniqueThread;
|
Teb.Cid.UniqueThread = Thread->Cid.UniqueThread;
|
||||||
Teb.Cid.UniqueProcess = Thread->Cid.UniqueProcess;
|
Teb.Cid.UniqueProcess = Thread->Cid.UniqueProcess;
|
||||||
Teb.CurrentLocale = PsDefaultThreadLocaleId;
|
Teb.CurrentLocale = PsDefaultThreadLocaleId;
|
||||||
|
|
||||||
DPRINT("sizeof(NT_TEB) %x\n", sizeof(NT_TEB));
|
DPRINT("sizeof(TEB) %x\n", sizeof(TEB));
|
||||||
|
|
||||||
/* write TEB data into teb page */
|
/* write TEB data into teb page */
|
||||||
Status = NtWriteVirtualMemory(ProcessHandle,
|
Status = NtWriteVirtualMemory(ProcessHandle,
|
||||||
TebBase,
|
TebBase,
|
||||||
&Teb,
|
&Teb,
|
||||||
sizeof(NT_TEB),
|
sizeof(TEB),
|
||||||
&ByteCount);
|
&ByteCount);
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
|
@ -512,7 +507,7 @@ PsCreateTeb(HANDLE ProcessHandle,
|
||||||
|
|
||||||
if (TebPtr != NULL)
|
if (TebPtr != NULL)
|
||||||
{
|
{
|
||||||
*TebPtr = (PNT_TEB)TebBase;
|
*TebPtr = (PTEB)TebBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINT("TEB allocated at %p\n", TebBase);
|
DPRINT("TEB allocated at %p\n", TebBase);
|
||||||
|
@ -532,7 +527,7 @@ NtCreateThread (PHANDLE ThreadHandle,
|
||||||
BOOLEAN CreateSuspended)
|
BOOLEAN CreateSuspended)
|
||||||
{
|
{
|
||||||
PETHREAD Thread;
|
PETHREAD Thread;
|
||||||
PNT_TEB TebBase;
|
PTEB TebBase;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
DPRINT("NtCreateThread(ThreadHandle %x, PCONTEXT %x)\n",
|
DPRINT("NtCreateThread(ThreadHandle %x, PCONTEXT %x)\n",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: error.c,v 1.2 2001/06/20 13:00:53 ekohl Exp $
|
/* $Id: error.c,v 1.3 2001/08/03 17:16:30 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -918,7 +918,7 @@ RtlNtStatusToDosErrorNoTeb(IN NTSTATUS Status)
|
||||||
DWORD STDCALL
|
DWORD STDCALL
|
||||||
RtlNtStatusToDosError(IN NTSTATUS Status)
|
RtlNtStatusToDosError(IN NTSTATUS Status)
|
||||||
{
|
{
|
||||||
PNT_TEB Teb = NtCurrentTeb ();
|
PTEB Teb = NtCurrentTeb ();
|
||||||
|
|
||||||
if (NULL != Teb)
|
if (NULL != Teb)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,22 +12,20 @@
|
||||||
|
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
SetLastNtError(
|
SetLastNtError(NTSTATUS Status)
|
||||||
NTSTATUS Status)
|
|
||||||
{
|
{
|
||||||
SetLastWin32Error(RtlNtStatusToDosError(Status));
|
SetLastWin32Error(RtlNtStatusToDosError(Status));
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
SetLastWin32Error(
|
SetLastWin32Error(DWORD Status)
|
||||||
DWORD Status)
|
|
||||||
{
|
{
|
||||||
PNT_TEB Teb = NtCurrentTeb();
|
PTEB Teb = NtCurrentTeb();
|
||||||
|
|
||||||
if (NULL != Teb)
|
if (NULL != Teb)
|
||||||
{
|
{
|
||||||
Teb->LastErrorValue = Status;
|
Teb->LastErrorValue = Status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue