Minor fix to teb allocation.

svn path=/trunk/; revision=690
This commit is contained in:
Eric Kohl 1999-10-11 20:43:10 +00:00
parent a77eef4a53
commit 8578ba8ac6

View file

@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.27 1999/10/07 23:38:30 ekohl Exp $ /* $Id: thread.c,v 1.28 1999/10/11 20:43:10 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -416,41 +416,6 @@ PsCreateTeb (HANDLE ProcessHandle,
while (TRUE) while (TRUE)
{ {
Status = NtQueryVirtualMemory(ProcessHandle,
TebBase,
MemoryBasicInformation,
&Info,
sizeof(MEMORY_BASIC_INFORMATION),
&ByteCount);
if (!NT_SUCCESS(Status))
{
DbgPrint ("NtQueryVirtualMemory (Status %x)\n",Status);
return Status;
}
if (Info.State == MEM_FREE)
{
DbgPrint("Virtual memory at %p is free.\n",
TebBase);
}
else
{
DbgPrint("Virtual memory at %p is allocated (BaseAddress %p RegionSize %x).\n",
TebBase, Info.BaseAddress, Info.RegionSize);
}
if (Info.State == MEM_FREE)
{
break;
}
TebBase = Info.BaseAddress - TebSize;
}
// if (Info.State != MEM_FREE)
// return STATUS_SUCCESS;
/* The TEB must reside in user space */ /* The TEB must reside in user space */
Status = NtAllocateVirtualMemory(ProcessHandle, Status = NtAllocateVirtualMemory(ProcessHandle,
&TebBase, &TebBase,
@ -458,16 +423,20 @@ PsCreateTeb (HANDLE ProcessHandle,
&TebSize, &TebSize,
MEM_COMMIT, MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (NT_SUCCESS(Status))
if (!NT_SUCCESS(Status))
{ {
DbgPrint ("TEB allocation failed!\n"); DPRINT ("TEB allocated at %x\n", TebBase);
DbgPrint ("Status %x\n",Status); break;
return Status; }
else
{
DPRINT ("TEB allocation failed! Status %x\n",Status);
} }
DbgPrint ("TebBase %p TebSize %lu\n", TebBase, TebSize); TebBase = Info.BaseAddress - TebSize;
}
DPRINT ("TebBase %p TebSize %lu\n", TebBase, TebSize);
/* set all pointers to and from the TEB */ /* set all pointers to and from the TEB */
Teb.Tib.Self = TebBase; Teb.Tib.Self = TebBase;
@ -506,7 +475,7 @@ PsCreateTeb (HANDLE ProcessHandle,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* free TEB */ /* free TEB */
DbgPrint ("Writing TEB failed!\n"); DPRINT ("Writing TEB failed!\n");
RegionSize = 0; RegionSize = 0;
NtFreeVirtualMemory(ProcessHandle, NtFreeVirtualMemory(ProcessHandle,
@ -524,7 +493,7 @@ PsCreateTeb (HANDLE ProcessHandle,
// *TebPtr = (PNT_TEB)TebBase; // *TebPtr = (PNT_TEB)TebBase;
} }
DbgPrint ("TEB allocated at %p\n", TebBase); DPRINT ("TEB allocated at %p\n", TebBase);
return Status; return Status;
} }