Rewrote stack allocation.

svn path=/trunk/; revision=2144
This commit is contained in:
Eric Kohl 2001-08-03 17:21:38 +00:00
parent e2e13b71ce
commit e183b6028f
14 changed files with 570 additions and 400 deletions

View file

@ -1,14 +1,23 @@
#include <ntos.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
{
int x;
PTEB Teb;
printf("TEB dumpper\n");
__asm__("movl %%fs:0x18, %0\n\t"
: "=a" (x)
: /* no inputs */);
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);
}

View file

@ -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
{
PVOID StackBase;
PVOID StackLimit;
PVOID StackCommit;
PVOID StackCommitMax;
PVOID StackReserve;
ULONG StackCommit;
ULONG StackReserve;
PVOID StackBase;
PVOID StackLimit;
PVOID StackAllocate;
} INITIAL_TEB, *PINITIAL_TEB;
typedef struct _CONTROLLER_OBJECT
@ -161,12 +161,13 @@ typedef struct _RTL_MESSAGE_RESOURCE_DATA
#define RTL_QUERY_REGISTRY_DELETE (0x00000040)
typedef NTSTATUS (*PRTL_QUERY_REGISTRY_ROUTINE)(PWSTR ValueName,
ULONG ValueType,
PVOID ValueData,
ULONG ValueLength,
PVOID Context,
PVOID EntryContext);
typedef NTSTATUS STDCALL
(*PRTL_QUERY_REGISTRY_ROUTINE)(PWSTR ValueName,
ULONG ValueType,
PVOID ValueData,
ULONG ValueLength,
PVOID Context,
PVOID EntryContext);
typedef struct _RTL_QUERY_REGISTRY_TABLE
{

View file

@ -9,7 +9,7 @@
*/
#include <windows.h>
#include <ddk/ntddk.h>
NT_TEB *GetTeb(VOID);
PTEB GetTeb(VOID);

View file

@ -6,8 +6,8 @@
typedef struct _CLIENT_ID
{
HANDLE UniqueProcess;
HANDLE UniqueThread;
HANDLE UniqueProcess;
HANDLE UniqueThread;
} CLIENT_ID, *PCLIENT_ID;
typedef struct _CURDIR
@ -154,7 +154,7 @@ typedef struct _GDI_TEB_BATCH
ULONG Buffer[0x136];
} GDI_TEB_BATCH, *PGDI_TEB_BATCH;
typedef struct _NT_TEB
typedef struct _TEB
{
NT_TIB Tib; // 00h
PVOID EnvironmentPointer; // 1Ch
@ -211,17 +211,12 @@ typedef struct _NT_TEB
ULONG Spare4; // F7Ch
PVOID ReservedForOle; // F80h
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)
static inline PNT_TEB NtCurrentTeb(VOID)
static inline PTEB NtCurrentTeb(VOID)
{
int x;
@ -230,7 +225,7 @@ static inline PNT_TEB NtCurrentTeb(VOID)
: /* no inputs */
);
return((PNT_TEB)x);
return((PTEB)x);
}

View file

@ -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
* PROJECT: ReactOS system libraries
* FILE: lib/kernel32/proc/proc.c
* FILE: lib/kernel32/process/create.c
* PURPOSE: Process functions
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
* UPDATE HISTORY:
@ -124,78 +124,149 @@ CreateProcessA (LPCSTR lpApplicationName,
HANDLE STDCALL
KlCreateFirstThread(HANDLE ProcessHandle,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
DWORD dwStackSize,
ULONG StackReserve,
ULONG StackCommit,
LPTHREAD_START_ROUTINE lpStartAddress,
DWORD dwCreationFlags,
LPDWORD lpThreadId)
{
NTSTATUS Status;
HANDLE ThreadHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
CLIENT_ID ClientId;
CONTEXT ThreadContext;
INITIAL_TEB InitialTeb;
BOOLEAN CreateSuspended = FALSE;
PVOID BaseAddress;
NTSTATUS Status;
HANDLE ThreadHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
CLIENT_ID ClientId;
CONTEXT ThreadContext;
INITIAL_TEB InitialTeb;
BOOLEAN CreateSuspended = FALSE;
ULONG OldPageProtection;
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = NULL;
ObjectAttributes.Attributes = 0;
if (lpThreadAttributes != NULL)
{
if (lpThreadAttributes->bInheritHandle)
ObjectAttributes.Attributes = OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor =
lpThreadAttributes->lpSecurityDescriptor;
}
ObjectAttributes.SecurityQualityOfService = NULL;
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = NULL;
ObjectAttributes.Attributes = 0;
if (lpThreadAttributes != NULL)
{
if (lpThreadAttributes->bInheritHandle)
ObjectAttributes.Attributes = OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor =
lpThreadAttributes->lpSecurityDescriptor;
}
ObjectAttributes.SecurityQualityOfService = NULL;
if ((dwCreationFlags & CREATE_SUSPENDED) == CREATE_SUSPENDED)
CreateSuspended = TRUE;
else
CreateSuspended = FALSE;
if ((dwCreationFlags & CREATE_SUSPENDED) == CREATE_SUSPENDED)
CreateSuspended = TRUE;
else
CreateSuspended = FALSE;
/* Allocate thread stack */
BaseAddress = NULL;
Status = NtAllocateVirtualMemory(ProcessHandle,
&BaseAddress,
0,
(PULONG)&dwStackSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
return(NULL);
}
InitialTeb.StackCommit = (StackCommit < PAGESIZE) ? PAGESIZE : StackCommit;
InitialTeb.StackReserve = (StackReserve < 0x100000) ? 0x100000 : StackReserve;
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)(BaseAddress + dwStackSize - 20);
ThreadContext.EFlags = (1<<1) + (1<<9);
/* size of guard page */
InitialTeb.StackCommit += PAGESIZE;
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,
THREAD_ALL_ACCESS,
&ObjectAttributes,
ProcessHandle,
&ClientId,
&ThreadContext,
&InitialTeb,
CreateSuspended);
if (lpThreadId != NULL)
{
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
}
DPRINT("StackDeallocation: %p ReserveSize: 0x%lX\n",
InitialTeb.StackDeallocation, InitialTeb.StackReserve);
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
@ -328,7 +399,7 @@ KlInitPeb (HANDLE ProcessHandle,
}
/* create the PPB */
PpbBase = (PVOID)PEB_STARTUPINFO;
PpbBase = NULL;
PpbSize = Ppb->MaximumLength;
Status = NtAllocateVirtualMemory(ProcessHandle,
&PpbBase,
@ -574,10 +645,11 @@ CreateProcessW(LPCWSTR lpApplicationName,
lpThreadAttributes,
//Sii.StackReserve,
0x200000,
//Sii.StackCommit,
0x1000,
lpStartAddress,
dwCreationFlags,
&lpProcessInformation->dwThreadId);
if (hThread == NULL)
{
return FALSE;

View file

@ -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
* PROJECT: ReactOS system libraries
@ -112,7 +112,7 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId)
{
{
HANDLE ThreadHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
CLIENT_ID ClientId;
@ -120,7 +120,7 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
INITIAL_TEB InitialTeb;
BOOLEAN CreateSuspended = FALSE;
PVOID BaseAddress;
DWORD StackSize;
ULONG OldPageProtection;
NTSTATUS Status;
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
@ -141,83 +141,147 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
else
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,
&BaseAddress,
0,
(PULONG)&StackSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DPRINT("Could not allocate stack space!\n");
return NULL;
}
/* Reserve stack */
InitialTeb.StackAllocate = NULL;
Status = NtAllocateVirtualMemory(hProcess,
&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);
}
DPRINT("StackDeallocation: %p ReserveSize: 0x%lX\n",
InitialTeb.StackDeallocation, InitialTeb.StackReserve);
DPRINT("Stack base address: %p\n", BaseAddress);
memset(&ThreadContext,0,sizeof(CONTEXT));
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)(BaseAddress + StackSize - 12);
ThreadContext.EFlags = (1<<1) + (1<<9);
InitialTeb.StackBase = (PVOID)((ULONG)InitialTeb.StackAllocate + InitialTeb.StackReserve);
InitialTeb.StackLimit = (PVOID)((ULONG)InitialTeb.StackBase - InitialTeb.StackCommit);
/* initialize call stack */
*((PULONG)(BaseAddress + StackSize - 4)) = (ULONG)lpParameter;
*((PULONG)(BaseAddress + StackSize - 8)) = (ULONG)lpStartAddress;
*((PULONG)(BaseAddress + StackSize - 12)) = 0xdeadbeef;
DPRINT("StackBase: %p\nStackCommit: 0x%lX\n",
InitialTeb.StackBase,
InitialTeb.StackCommit);
#if 0
/* Commit stack pages */
Status = NtAllocateVirtualMemory(hProcess,
&InitialTeb.StackLimit,
0,
&InitialTeb.StackCommit,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
/* release the stack space */
NtFreeVirtualMemory(hProcess,
InitialTeb.StackAllocate,
&InitialTeb.StackReserve,
MEM_RELEASE);
DPRINT("Esp: %p\n", ThreadContext.Esp);
DPRINT("Eip: %p\n", ThreadContext.Eip);
DPRINT("Error comitting stack page(s)!\n");
SetLastErrorByStatus(Status);
return(NULL);
}
Status = NtCreateThread(&ThreadHandle,
THREAD_ALL_ACCESS,
&ObjectAttributes,
hProcess,
&ClientId,
&ThreadContext,
&InitialTeb,
CreateSuspended);
DPRINT("StackLimit: %p\n",
InitialTeb.StackLimit);
if (!NT_SUCCESS(Status))
{
DPRINT("NtCreateThread() failed!\n");
return NULL;
}
/* Protect guard page */
Status = NtProtectVirtualMemory(hProcess,
InitialTeb.StackLimit,
PAGESIZE,
PAGE_GUARD | PAGE_READWRITE,
&OldPageProtection);
if (!NT_SUCCESS(Status))
{
/* release the stack space */
NtFreeVirtualMemory(hProcess,
InitialTeb.StackAllocate,
&InitialTeb.StackReserve,
MEM_RELEASE);
if ( lpThreadId != NULL )
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
return ThreadHandle;
DPRINT("Error comitting guard page!\n");
SetLastErrorByStatus(Status);
return(NULL);
}
#endif
memset(&ThreadContext,0,sizeof(CONTEXT));
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);
/* 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;
errCode = NtYieldExecution();
return TRUE;
}
DWORD STDCALL GetCurrentThreadId()
DWORD STDCALL
GetCurrentThreadId()
{
return((DWORD)(NtCurrentTeb()->Cid).UniqueThread);
}
VOID STDCALL ExitThread(DWORD uExitCode)
VOID STDCALL
ExitThread(DWORD uExitCode)
{
NTSTATUS errCode;
BOOLEAN LastThread;

View file

@ -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
* PROJECT: ReactOS kernel
@ -34,11 +34,8 @@ typedef struct _LPC_DBGSS_MESSAGE
/* FUNCTIONS *****************************************************************/
VOID
STDCALL
DbgSsServerThread (
PVOID Unused
)
VOID STDCALL
DbgSsServerThread(PVOID Unused)
{
LPC_DBGSS_MESSAGE Message;
NTSTATUS Status;
@ -65,26 +62,19 @@ DbgSsServerThread (
}
NTSTATUS
STDCALL
DbgSsHandleKmApiMsg (
ULONG Unknown1,
HANDLE EventHandle
)
NTSTATUS STDCALL
DbgSsHandleKmApiMsg(ULONG Unknown1,
HANDLE EventHandle)
{
return STATUS_NOT_IMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}
NTSTATUS
STDCALL
DbgSsInitialize (
HANDLE ReplyPort,
ULONG Unknown1,
ULONG Unknown2,
ULONG Unknown3
)
NTSTATUS STDCALL
DbgSsInitialize(HANDLE ReplyPort,
ULONG Unknown1,
ULONG Unknown2,
ULONG Unknown3)
{
SECURITY_QUALITY_OF_SERVICE Qos;
UNICODE_STRING PortName;
@ -129,16 +119,13 @@ DbgSsInitialize (
}
NTSTATUS
STDCALL
DbgUiConnectToDbg (
VOID
)
NTSTATUS STDCALL
DbgUiConnectToDbg(VOID)
{
SECURITY_QUALITY_OF_SERVICE Qos;
UNICODE_STRING PortName;
NTSTATUS Status;
PNT_TEB Teb;
PTEB Teb;
ULONG InfoSize;
Teb = NtCurrentTeb ();
@ -173,24 +160,19 @@ DbgUiConnectToDbg (
}
NTSTATUS
STDCALL
DbgUiContinue (
PCLIENT_ID ClientId,
ULONG ContinueStatus
)
NTSTATUS STDCALL
DbgUiContinue(PCLIENT_ID ClientId,
ULONG ContinueStatus)
{
return STATUS_NOT_IMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}
NTSTATUS
STDCALL
DbgUiWaitStateChange (
ULONG Unknown1,
ULONG Unknown2
)
NTSTATUS STDCALL
DbgUiWaitStateChange(ULONG Unknown1,
ULONG Unknown2)
{
return STATUS_NOT_IMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}
/* EOF */

View file

@ -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
* PROJECT: ReactOS kernel
@ -858,9 +858,8 @@ RtlAssert (
* REMARK
* RtlNtStatusToDosErrorNoTeb() does the real work.
*/
DWORD
STDCALL
RtlNtStatusToDosErrorNoTeb (NTSTATUS Status)
DWORD STDCALL
RtlNtStatusToDosErrorNoTeb(NTSTATUS Status)
{
PERROR_TABLE Table = (PERROR_TABLE)ErrorTable;
@ -917,19 +916,16 @@ RtlNtStatusToDosErrorNoTeb (NTSTATUS Status)
* REMARK
* RtlNtStatusToDosErrorNoTeb() does the real work.
*/
DWORD
STDCALL
RtlNtStatusToDosError (
NTSTATUS Status
)
DWORD STDCALL
RtlNtStatusToDosError(NTSTATUS Status)
{
PNT_TEB Teb = NtCurrentTeb ();
PTEB Teb = NtCurrentTeb();
if (NULL != Teb)
{
Teb->LastStatusValue = Status;
}
return RtlNtStatusToDosErrorNoTeb (Status);
if (NULL != Teb)
{
Teb->LastStatusValue = Status;
}
return RtlNtStatusToDosErrorNoTeb(Status);
}
@ -954,18 +950,15 @@ RtlNtStatusToDosError (
* REVISIONS
* 1999-11-30 ea
*/
INT
STDCALL
RtlNtStatusToPsxErrno (
IN NTSTATUS Status
)
INT STDCALL
RtlNtStatusToPsxErrno(IN NTSTATUS Status)
{
#if 0
switch (Status)
{
}
switch (Status)
{
}
#endif
return -1; /* generic POSIX error */
return -1; /* generic POSIX error */
}
/* EOF */

View file

@ -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
* PROJECT: ReactOS system libraries
@ -22,65 +22,136 @@
/* FUNCTIONS ****************************************************************/
HANDLE STDCALL KlCreateFirstThread(HANDLE ProcessHandle,
ULONG StackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
PCLIENT_ID ClientId)
static NTSTATUS
RtlpCreateFirstThread(HANDLE ProcessHandle,
ULONG StackReserve,
ULONG StackCommit,
LPTHREAD_START_ROUTINE lpStartAddress,
PCLIENT_ID ClientId,
PHANDLE ThreadHandle)
{
NTSTATUS Status;
HANDLE ThreadHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
CONTEXT ThreadContext;
INITIAL_TEB InitialTeb;
PVOID BaseAddress;
CLIENT_ID Cid;
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = NULL;
ObjectAttributes.Attributes = 0;
ObjectAttributes.SecurityQualityOfService = NULL;
NTSTATUS Status;
OBJECT_ATTRIBUTES ObjectAttributes;
CONTEXT ThreadContext;
INITIAL_TEB InitialTeb;
ULONG OldPageProtection;
CLIENT_ID Cid;
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = NULL;
ObjectAttributes.Attributes = 0;
ObjectAttributes.SecurityQualityOfService = NULL;
BaseAddress = NULL;
Status = NtAllocateVirtualMemory(ProcessHandle,
&BaseAddress,
0,
(PULONG)&StackSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DPRINT("Failed to allocate stack\n");
return(NULL);
}
if (StackCommit > PAGESIZE)
InitialTeb.StackCommit = StackCommit;
else
InitialTeb.StackCommit = PAGESIZE;
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)BaseAddress + StackSize - 20;
ThreadContext.EFlags = (1<<1) + (1<<9);
if (StackReserve > 0x100000)
InitialTeb.StackReserve = StackReserve;
else
InitialTeb.StackReserve = 0x100000; /* 1MByte */
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,
THREAD_ALL_ACCESS,
&ObjectAttributes,
ProcessHandle,
&Cid,
&ThreadContext,
&InitialTeb,
FALSE);
if (ClientId != NULL)
{
memcpy(&ClientId->UniqueThread, &Cid.UniqueThread, sizeof(ULONG));
}
DPRINT("StackAllocate: %p ReserveSize: 0x%lX\n",
InitialTeb.StackAllocate, InitialTeb.StackReserve);
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
@ -184,7 +255,6 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
PVOID EnvPtr = NULL;
ULONG EnvSize = 0;
/* create the Environment */
if (Ppb->Environment != NULL)
{
@ -227,7 +297,7 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
DPRINT("EnvironmentPointer %p\n", EnvPtr);
/* create the PPB */
PpbBase = (PVOID)PEB_STARTUPINFO;
PpbBase = NULL;
PpbSize = Ppb->MaximumLength;
Status = NtAllocateVirtualMemory(ProcessHandle,
&PpbBase,
@ -284,7 +354,6 @@ RtlCreateUserProcess(PUNICODE_STRING ImageFileName,
PRTL_PROCESS_INFO ProcessInfo)
{
HANDLE hSection;
HANDLE hThread;
NTSTATUS Status;
LPTHREAD_START_ROUTINE lpStartAddress = NULL;
PROCESS_BASIC_INFORMATION ProcessBasicInfo;
@ -317,6 +386,7 @@ RtlCreateUserProcess(PUNICODE_STRING ImageFileName,
ExceptionPort);
if (!NT_SUCCESS(Status))
{
NtClose(hSection);
return(Status);
}
@ -353,20 +423,25 @@ RtlCreateUserProcess(PUNICODE_STRING ImageFileName,
if (!NT_SUCCESS(Status))
{
DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
NtClose(hSection);
return (Status);
}
DPRINT("lpStartAddress 0x%08lx\n", (ULONG)lpStartAddress);
DPRINT("Creating thread for process\n");
hThread = KlCreateFirstThread(ProcessInfo->ProcessHandle,
Status = RtlpCreateFirstThread(ProcessInfo->ProcessHandle,
// Headers.OptionalHeader.SizeOfStackReserve,
0x200000,
// Headers.OptionalHeader.SizeOfStackCommit,
0x1000,
lpStartAddress,
&(ProcessInfo->ClientId));
if (hThread == NULL)
&ProcessInfo->ClientId,
&ProcessInfo->ThreadHandle);
if (!NT_SUCCESS(Status))
{
DPRINT("Failed to create thread\n");
return(STATUS_UNSUCCESSFUL);
NtClose(hSection);
return(Status);
}
return(STATUS_SUCCESS);
}

View file

@ -40,99 +40,87 @@ RtlCreateUserThread(HANDLE ProcessHandle,
OBJECT_ATTRIBUTES ObjectAttributes;
INITIAL_TEB InitialTeb;
CONTEXT ThreadContext;
ULONG ReserveSize;
ULONG CommitSize;
ULONG GuardSize;
ULONG RegionSize;
ULONG OldPageProtection;
NTSTATUS Status;
/* initialize initial teb */
if ((StackCommit != NULL) && (*StackCommit > PAGESIZE))
CommitSize = *StackCommit;
InitialTeb.StackCommit = *StackCommit;
else
CommitSize = PAGESIZE;
InitialTeb.StackCommit = PAGESIZE;
if ((StackReserve != NULL) && (*StackReserve > 0x100000))
ReserveSize = *StackReserve;
InitialTeb.StackReserve = *StackReserve;
else
ReserveSize = 0x100000; /* 1MByte */
InitialTeb.StackReserve = 0x100000; /* 1MByte */
GuardSize = PAGESIZE;
RegionSize = 0;
/* add size of guard page */
InitialTeb.StackCommit += PAGESIZE;
/* Reserve stack */
InitialTeb.StackReserve = NULL;
InitialTeb.StackAllocate = NULL;
Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackReserve,
&InitialTeb.StackAllocate,
0,
&ReserveSize,
MEM_RESERVE,
&InitialTeb.StackReserve,
MEM_COMMIT, //MEM_RESERVE,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DPRINT("Error reserving stack space!\n");
return Status;
}
DPRINT("StackReserved: %p ReservedSize: 0x%lx\n",
InitialTeb.StackReserve, ReserveSize);
DPRINT("StackAllocate: %p ReserveSize: 0x%lX\n",
InitialTeb.StackAllocate, InitialTeb.StackReserve);
InitialTeb.StackBase = (PVOID)(InitialTeb.StackReserve + ReserveSize);
InitialTeb.StackCommit = (PVOID)(InitialTeb.StackBase - CommitSize);
InitialTeb.StackLimit = (PVOID)(InitialTeb.StackCommit - PAGESIZE);
InitialTeb.StackCommitMax = (PVOID)(InitialTeb.StackReserve + PAGESIZE);
InitialTeb.StackBase = (PVOID)((ULONG)InitialTeb.StackAllocate + InitialTeb.StackReserve);
InitialTeb.StackLimit = (PVOID)((ULONG)InitialTeb.StackBase - InitialTeb.StackCommit);
DPRINT("StackBase: %p\n",
InitialTeb.StackBase);
/* Commit stack page */
DPRINT("StackBase: %p StackCommit: 0x%lX\n",
InitialTeb.StackBase, InitialTeb.StackCommit);
#if 0
/* Commit stack */
Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackCommit,
&InitialTeb.StackLimit,
0,
&CommitSize,
&InitialTeb.StackCommit,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
/* release the stack space */
NtFreeVirtualMemory(ProcessHandle,
InitialTeb.StackReserve,
&RegionSize,
InitialTeb.StackAllocate,
&InitialTeb.StackReserve,
MEM_RELEASE);
DPRINT("Error comitting stack page!\n");
return Status;
}
DPRINT("StackCommit: %p CommitSize: 0x%lx\n",
InitialTeb.StackCommit, CommitSize);
DPRINT("StackLimit: %p\nStackCommit: 0x%lX\n",
InitialTeb.StackLimit,
InitialTeb.StackCommit);
/* Commit guard page */
Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackLimit,
0,
&GuardSize,
MEM_COMMIT,
PAGE_GUARD);
if (!NT_SUCCESS(Status))
/* 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.StackReserve,
&RegionSize,
MEM_RELEASE);
/* release the stack space */
NtFreeVirtualMemory(ProcessHandle,
InitialTeb.StackAllocate,
&InitialTeb.StackReserve,
MEM_RELEASE);
DPRINT("Error comitting guard page!\n");
return Status;
DPRINT("Error protecting guard page!\n");
return(Status);
}
DPRINT("StackLimit: %p GuardSize: 0x%lx\n",
InitialTeb.StackLimit, GuardSize);
#endif
/* initialize thread context */
RtlInitializeContext (ProcessHandle,
&ThreadContext,
@ -144,7 +132,6 @@ RtlCreateUserThread(HANDLE ProcessHandle,
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = NULL;
// ObjectAttributes.Attributes = 0;
ObjectAttributes.Attributes = OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = SecurityDescriptor;
ObjectAttributes.SecurityQualityOfService = NULL;
@ -162,8 +149,8 @@ RtlCreateUserThread(HANDLE ProcessHandle,
{
/* release the stack space */
NtFreeVirtualMemory(ProcessHandle,
InitialTeb.StackReserve,
&RegionSize,
InitialTeb.StackAllocate,
&InitialTeb.StackReserve,
MEM_RELEASE);
DPRINT("Error creating thread!\n");
@ -172,11 +159,11 @@ RtlCreateUserThread(HANDLE ProcessHandle,
/* return committed stack size */
if (StackCommit)
*StackCommit = CommitSize;
*StackCommit = InitialTeb.StackCommit;
/* return reserved stack size */
if (StackReserve)
*StackReserve = ReserveSize;
*StackReserve = InitialTeb.StackReserve;
/* return thread handle */
if (ThreadHandle)
@ -189,7 +176,7 @@ RtlCreateUserThread(HANDLE ProcessHandle,
ClientId->UniqueThread = LocalClientId.UniqueThread;
}
return Status;
return(STATUS_SUCCESS);
}
@ -205,7 +192,6 @@ RtlInitializeContext(HANDLE ProcessHandle,
NTSTATUS Status;
memset (Context, 0, sizeof(CONTEXT));
Context->Eip = (LONG)StartAddress;
Context->SegGs = USER_DS;
Context->SegFs = TEB_SELECTOR;
@ -228,7 +214,7 @@ RtlInitializeContext(HANDLE ProcessHandle,
Buffer[1] = 0xdeadbeef;
Status = NtWriteVirtualMemory(ProcessHandle,
(PVOID)(InitialTeb->StackBase - 4),
(PVOID)((ULONG)InitialTeb->StackBase - 8),
Buffer,
2 * sizeof(ULONG),
&BytesWritten);
@ -240,45 +226,45 @@ RtlInitializeContext(HANDLE ProcessHandle,
NTSTATUS STDCALL
RtlFreeUserThreadStack (HANDLE ProcessHandle, HANDLE ThreadHandle)
RtlFreeUserThreadStack(HANDLE ProcessHandle,
HANDLE ThreadHandle)
{
THREAD_BASIC_INFORMATION ThreadInfo;
NTSTATUS Status;
ULONG BytesRead;
ULONG RegionSize;
PVOID StackBase;
PNT_TEB Teb;
THREAD_BASIC_INFORMATION ThreadInfo;
NTSTATUS Status;
ULONG BytesRead;
ULONG RegionSize;
PVOID StackBase;
PTEB Teb;
Status = NtQueryInformationThread (ThreadHandle,
ThreadBasicInformation,
&ThreadInfo,
sizeof(THREAD_BASIC_INFORMATION),
NULL);
if (!NT_SUCCESS(Status))
return Status;
Status = NtQueryInformationThread(ThreadHandle,
ThreadBasicInformation,
&ThreadInfo,
sizeof(THREAD_BASIC_INFORMATION),
NULL);
if (!NT_SUCCESS(Status))
return(Status);
if (ThreadInfo.TebBaseAddress == NULL)
return Status;
if (ThreadInfo.TebBaseAddress == NULL)
return(Status);
Teb = (PNT_TEB)ThreadInfo.TebBaseAddress;
Status = NtReadVirtualMemory (ProcessHandle,
&Teb->DeallocationStack,
&StackBase,
sizeof(PVOID),
&BytesRead);
if (!NT_SUCCESS(Status))
return Status;
Teb = (PTEB)ThreadInfo.TebBaseAddress;
Status = NtReadVirtualMemory(ProcessHandle,
&Teb->DeallocationStack,
&StackBase,
sizeof(PVOID),
&BytesRead);
if (!NT_SUCCESS(Status))
return(Status);
if (StackBase == NULL)
return Status;
if (StackBase == NULL)
return(Status);
RegionSize = 0;
Status = NtFreeVirtualMemory (ProcessHandle,
StackBase,
&RegionSize,
MEM_RELEASE);
return Status;
RegionSize = 0;
Status = NtFreeVirtualMemory(ProcessHandle,
StackBase,
&RegionSize,
MEM_RELEASE);
return(Status);
}
/* EOF */

View file

@ -119,7 +119,7 @@ typedef struct _KTHREAD
ULONG StackLimit; /* 1C */
/* Pointer to the thread's environment block in user memory */
NT_TEB* Teb; /* 20 */
PTEB Teb; /* 20 */
/* Pointer to the thread's TLS array */
PVOID TlsArray; /* 24 */

View file

@ -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
* PROJECT: ReactOS kernel
@ -292,7 +292,8 @@ PsBeginThread(PKSTART_ROUTINE StartRoutine, PVOID StartContext)
}
#endif
VOID PiDeleteThread(PVOID ObjectBody)
VOID
PiDeleteThread(PVOID ObjectBody)
{
KIRQL oldIrql;
@ -310,7 +311,9 @@ VOID PiDeleteThread(PVOID ObjectBody)
DPRINT("PiDeleteThread() finished\n");
}
VOID PiCloseThread(PVOID ObjectBody, ULONG HandleCount)
VOID
PiCloseThread(PVOID ObjectBody,
ULONG HandleCount)
{
DPRINT("PiCloseThread(ObjectBody %x)\n", ObjectBody);
DPRINT("ObGetReferenceCount(ObjectBody) %d "
@ -408,7 +411,7 @@ PsInitializeThread(HANDLE ProcessHandle,
static NTSTATUS
PsCreateTeb(HANDLE ProcessHandle,
PNT_TEB *TebPtr,
PTEB *TebPtr,
PETHREAD Thread,
PINITIAL_TEB InitialTeb)
{
@ -418,7 +421,7 @@ PsCreateTeb(HANDLE ProcessHandle,
ULONG RegionSize;
ULONG TebSize;
PVOID TebBase;
NT_TEB Teb;
TEB Teb;
ULONG ResultLength;
TebBase = (PVOID)0x7FFDE000;
@ -471,29 +474,21 @@ PsCreateTeb(HANDLE ProcessHandle,
{
Teb.Tib.StackBase = InitialTeb->StackBase;
Teb.Tib.StackLimit = InitialTeb->StackLimit;
/*
* 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;
Teb.DeallocationStack = InitialTeb->StackAllocate;
}
/* more initialization */
Teb.Cid.UniqueThread = Thread->Cid.UniqueThread;
Teb.Cid.UniqueProcess = Thread->Cid.UniqueProcess;
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 */
Status = NtWriteVirtualMemory(ProcessHandle,
TebBase,
&Teb,
sizeof(NT_TEB),
sizeof(TEB),
&ByteCount);
if (!NT_SUCCESS(Status))
@ -512,7 +507,7 @@ PsCreateTeb(HANDLE ProcessHandle,
if (TebPtr != NULL)
{
*TebPtr = (PNT_TEB)TebBase;
*TebPtr = (PTEB)TebBase;
}
DPRINT("TEB allocated at %p\n", TebBase);
@ -532,7 +527,7 @@ NtCreateThread (PHANDLE ThreadHandle,
BOOLEAN CreateSuspended)
{
PETHREAD Thread;
PNT_TEB TebBase;
PTEB TebBase;
NTSTATUS Status;
DPRINT("NtCreateThread(ThreadHandle %x, PCONTEXT %x)\n",
@ -557,7 +552,7 @@ NtCreateThread (PHANDLE ThreadHandle,
KeBugCheck(0);
}
ThreadContext->Eip = LdrpGetSystemDllEntryPoint;
#endif
#endif
Status = Ke386InitThreadWithContext(&Thread->Tcb, ThreadContext);
if (!NT_SUCCESS(Status))
@ -582,7 +577,7 @@ NtCreateThread (PHANDLE ThreadHandle,
if (Client != NULL)
{
*Client=Thread->Cid;
}
}
/*
* Maybe send a message to the process's debugger
@ -653,7 +648,7 @@ PsCreateSystemThread(PHANDLE ThreadHandle,
if (ClientId!=NULL)
{
*ClientId=Thread->Cid;
}
}
PsUnblockThread(Thread, NULL);

View file

@ -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
* PROJECT: ReactOS kernel
@ -918,7 +918,7 @@ RtlNtStatusToDosErrorNoTeb(IN NTSTATUS Status)
DWORD STDCALL
RtlNtStatusToDosError(IN NTSTATUS Status)
{
PNT_TEB Teb = NtCurrentTeb ();
PTEB Teb = NtCurrentTeb ();
if (NULL != Teb)
{

View file

@ -12,22 +12,20 @@
VOID
SetLastNtError(
NTSTATUS Status)
SetLastNtError(NTSTATUS Status)
{
SetLastWin32Error(RtlNtStatusToDosError(Status));
}
VOID
SetLastWin32Error(
DWORD Status)
SetLastWin32Error(DWORD Status)
{
PNT_TEB Teb = NtCurrentTeb();
PTEB Teb = NtCurrentTeb();
if (NULL != Teb)
{
Teb->LastErrorValue = Status;
}
if (NULL != Teb)
{
Teb->LastErrorValue = Status;
}
}
/* EOF */