Changed stack allocation.

Fixed bugs in NtAllocateVirtualMemory().
Disabled NtProtectVirtualMemory().

svn path=/trunk/; revision=2162
This commit is contained in:
Eric Kohl 2001-08-07 14:13:45 +00:00
parent 2e249e1b26
commit 65d55d8863
14 changed files with 618 additions and 583 deletions

View file

@ -1,4 +1,4 @@
/* $Id: copy.c,v 1.8 2001/08/04 10:40:38 hbirr Exp $
/* $Id: copy.c,v 1.9 2001/08/07 14:12:34 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -125,7 +125,7 @@ CopyFileExW (
(PVOID *)&lpBuffer,
2,
&RegionSize,
MEM_COMMIT,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(errCode))

View file

@ -1,4 +1,4 @@
/* $Id: npipe.c,v 1.5 2001/05/10 23:37:06 ekohl Exp $
/* $Id: npipe.c,v 1.6 2001/08/07 14:12:34 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -13,11 +13,13 @@
#include <ddk/ntddk.h>
#include <ntdll/rtl.h>
#include <windows.h>
#include <kernel32/error.h>
//#include <wchar.h>
//#include <string.h>
#include <limits.h>
//#define NDEBUG
#include <kernel32/kernel32.h>
#include <kernel32/error.h>
/* FUNCTIONS ****************************************************************/
@ -52,6 +54,7 @@ CreateNamedPipeA(LPCSTR lpName,
return(NamedPipeHandle);
}
HANDLE STDCALL
CreateNamedPipeW(LPCWSTR lpName,
DWORD dwOpenMode,
@ -88,6 +91,7 @@ CreateNamedPipeW(LPCWSTR lpName,
}
DPRINT("Pipe name: %wZ\n", &NamedPipeName);
DPRINT("Pipe name: %S\n", NamedPipeName.Buffer);
InitializeObjectAttributes(&ObjectAttributes,
&NamedPipeName,
@ -110,6 +114,18 @@ CreateNamedPipeW(LPCWSTR lpName,
{
CreateOptions = CreateOptions | FILE_SYNCHRONOUS_IO_ALERT;
}
if (dwOpenMode & PIPE_ACCESS_DUPLEX)
{
CreateOptions = CreateOptions | FILE_PIPE_FULL_DUPLEX;
}
else if (dwOpenMode & PIPE_ACCESS_INBOUND)
{
CreateOptions = CreateOptions | FILE_PIPE_INBOUND;
}
else if (dwOpenMode & PIPE_ACCESS_OUTBOUND)
{
CreateOptions = CreateOptions | FILE_PIPE_OUTBOUND;
}
if (dwPipeMode & PIPE_TYPE_BYTE)
{
@ -150,6 +166,11 @@ CreateNamedPipeW(LPCWSTR lpName,
NonBlocking = FALSE;
}
if (nMaxInstances >= PIPE_UNLIMITED_INSTANCES)
{
nMaxInstances = ULONG_MAX;
}
DefaultTimeOut.QuadPart = nDefaultTimeOut * 10000;
Status = NtCreateNamedPipeFile(&PipeHandle,
@ -179,6 +200,7 @@ CreateNamedPipeW(LPCWSTR lpName,
return(PipeHandle);
}
BOOL STDCALL
WaitNamedPipeA(LPCSTR lpNamedPipeName,
DWORD nTimeOut)
@ -197,6 +219,7 @@ WaitNamedPipeA(LPCSTR lpNamedPipeName,
return(r);
}
BOOL STDCALL
WaitNamedPipeW(LPCWSTR lpNamedPipeName,
DWORD nTimeOut)
@ -260,6 +283,7 @@ WaitNamedPipeW(LPCWSTR lpNamedPipeName,
return(TRUE);
}
BOOL STDCALL
ConnectNamedPipe(HANDLE hNamedPipe,
LPOVERLAPPED lpOverlapped)
@ -311,6 +335,7 @@ ConnectNamedPipe(HANDLE hNamedPipe,
return(TRUE);
}
BOOL STDCALL
SetNamedPipeHandleState(HANDLE hNamedPipe,
LPDWORD lpMode,
@ -407,17 +432,15 @@ SetNamedPipeHandleState(HANDLE hNamedPipe,
return(TRUE);
}
WINBOOL
STDCALL
CallNamedPipeA (
LPCSTR lpNamedPipeName,
LPVOID lpInBuffer,
DWORD nInBufferSize,
LPVOID lpOutBuffer,
DWORD nOutBufferSize,
LPDWORD lpBytesRead,
DWORD nTimeOut
)
WINBOOL STDCALL
CallNamedPipeA(LPCSTR lpNamedPipeName,
LPVOID lpInBuffer,
DWORD nInBufferSize,
LPVOID lpOutBuffer,
DWORD nOutBufferSize,
LPDWORD lpBytesRead,
DWORD nTimeOut)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
@ -425,15 +448,13 @@ CallNamedPipeA (
WINBOOL STDCALL
CallNamedPipeW (
LPCWSTR lpNamedPipeName,
LPVOID lpInBuffer,
DWORD nInBufferSize,
LPVOID lpOutBuffer,
DWORD nOutBufferSize,
LPDWORD lpBytesRead,
DWORD nTimeOut
)
CallNamedPipeW(LPCWSTR lpNamedPipeName,
LPVOID lpInBuffer,
DWORD nInBufferSize,
LPVOID lpOutBuffer,
DWORD nOutBufferSize,
LPDWORD lpBytesRead,
DWORD nTimeOut)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
@ -478,15 +499,13 @@ DisconnectNamedPipe(HANDLE hNamedPipe)
WINBOOL STDCALL
GetNamedPipeHandleStateW (
HANDLE hNamedPipe,
LPDWORD lpState,
LPDWORD lpCurInstances,
LPDWORD lpMaxCollectionCount,
LPDWORD lpCollectDataTimeout,
LPWSTR lpUserName,
DWORD nMaxUserNameSize
)
GetNamedPipeHandleStateW(HANDLE hNamedPipe,
LPDWORD lpState,
LPDWORD lpCurInstances,
LPDWORD lpMaxCollectionCount,
LPDWORD lpCollectDataTimeout,
LPWSTR lpUserName,
DWORD nMaxUserNameSize)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
@ -494,15 +513,13 @@ GetNamedPipeHandleStateW (
WINBOOL STDCALL
GetNamedPipeHandleStateA (
HANDLE hNamedPipe,
LPDWORD lpState,
LPDWORD lpCurInstances,
LPDWORD lpMaxCollectionCount,
LPDWORD lpCollectDataTimeout,
LPSTR lpUserName,
DWORD nMaxUserNameSize
)
GetNamedPipeHandleStateA(HANDLE hNamedPipe,
LPDWORD lpState,
LPDWORD lpCurInstances,
LPDWORD lpMaxCollectionCount,
LPDWORD lpCollectDataTimeout,
LPSTR lpUserName,
DWORD nMaxUserNameSize)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
@ -516,8 +533,42 @@ GetNamedPipeInfo(HANDLE hNamedPipe,
LPDWORD lpInBufferSize,
LPDWORD lpMaxInstances)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
FILE_PIPE_LOCAL_INFORMATION PipeLocalInformation;
IO_STATUS_BLOCK StatusBlock;
NTSTATUS Status;
Status = NtQueryInformationFile(hNamedPipe,
&StatusBlock,
&PipeLocalInformation,
sizeof(FILE_PIPE_LOCAL_INFORMATION),
FilePipeLocalInformation);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return(FALSE);
}
if (lpFlags != NULL)
{
*lpFlags = (PipeLocalInformation.NamedPipeEnd == FILE_PIPE_SERVER_END) ? PIPE_SERVER_END : PIPE_CLIENT_END;
*lpFlags |= (PipeLocalInformation.NamedPipeType == 1) ? PIPE_TYPE_MESSAGE : PIPE_TYPE_BYTE;
}
if (lpOutBufferSize != NULL)
*lpOutBufferSize = PipeLocalInformation.OutboundQuota;
if (lpInBufferSize != NULL)
*lpInBufferSize = PipeLocalInformation.InboundQuota;
if (lpMaxInstances != NULL)
{
if (PipeLocalInformation.MaximumInstances >= 255)
*lpMaxInstances = PIPE_UNLIMITED_INSTANCES;
else
*lpMaxInstances = PipeLocalInformation.MaximumInstances;
}
return(TRUE);
}

View file

@ -1,4 +1,4 @@
/* $Id: virtual.c,v 1.6 2000/07/01 17:07:00 ea Exp $
/* $Id: virtual.c,v 1.7 2001/08/07 14:12:58 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -15,170 +15,187 @@
/* FUNCTIONS *****************************************************************/
LPVOID STDCALL VirtualAllocEx(HANDLE hProcess,
LPVOID lpAddress,
DWORD dwSize,
DWORD flAllocationType,
DWORD flProtect)
LPVOID STDCALL
VirtualAllocEx(HANDLE hProcess,
LPVOID lpAddress,
DWORD dwSize,
DWORD flAllocationType,
DWORD flProtect)
{
NTSTATUS Status;
Status = ZwAllocateVirtualMemory(hProcess,
(PVOID *)&lpAddress,
0,
(PULONG)&dwSize,
flAllocationType,
flProtect);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus (Status);
return(NULL);
}
return(lpAddress);
}
NTSTATUS Status;
LPVOID STDCALL VirtualAlloc(LPVOID lpAddress,
DWORD dwSize,
DWORD flAllocationType,
DWORD flProtect)
{
return(VirtualAllocEx(GetCurrentProcess(),lpAddress,dwSize,flAllocationType,
flProtect));
}
WINBOOL STDCALL VirtualFreeEx(HANDLE hProcess,
LPVOID lpAddress,
DWORD dwSize,
DWORD dwFreeType)
{
NTSTATUS Status;
Status = ZwFreeVirtualMemory(hProcess,
(PVOID *)&lpAddress,
(PULONG)&dwSize,
dwFreeType);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus (Status);
return(FALSE);
}
return(TRUE);
}
WINBOOL STDCALL VirtualFree(LPVOID lpAddress, DWORD dwSize, DWORD dwFreeType)
{
return(VirtualFreeEx(GetCurrentProcess(),lpAddress,dwSize,dwFreeType));
}
WINBOOL STDCALL VirtualProtect(LPVOID lpAddress,
DWORD dwSize,
DWORD flNewProtect,
PDWORD lpflOldProtect)
{
return(VirtualProtectEx(GetCurrentProcess(),
lpAddress,
dwSize,
flNewProtect,
lpflOldProtect));
Status = NtAllocateVirtualMemory(hProcess,
(PVOID *)&lpAddress,
0,
(PULONG)&dwSize,
flAllocationType,
flProtect);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return(NULL);
}
return(lpAddress);
}
WINBOOL STDCALL VirtualProtectEx(HANDLE hProcess,
LPVOID lpAddress,
DWORD dwSize,
DWORD flNewProtect,
PDWORD lpflOldProtect)
LPVOID STDCALL
VirtualAlloc(LPVOID lpAddress,
DWORD dwSize,
DWORD flAllocationType,
DWORD flProtect)
{
NTSTATUS Status;
Status = ZwProtectVirtualMemory(hProcess,
(PVOID)lpAddress,
dwSize,
flNewProtect,
(PULONG)lpflOldProtect);
if (Status != STATUS_SUCCESS)
{
SetLastErrorByStatus (Status);
return(FALSE);
}
return(TRUE);
return(VirtualAllocEx(GetCurrentProcess(),
lpAddress,
dwSize,
flAllocationType,
flProtect));
}
WINBOOL
STDCALL
VirtualLock (
LPVOID lpAddress,
DWORD dwSize
)
WINBOOL STDCALL
VirtualFreeEx(HANDLE hProcess,
LPVOID lpAddress,
DWORD dwSize,
DWORD dwFreeType)
{
ULONG BytesLocked;
NTSTATUS Status;
Status = NtLockVirtualMemory(NtCurrentProcess(),lpAddress,dwSize, &BytesLocked);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus (Status);
return FALSE;
}
return TRUE;
NTSTATUS Status;
Status = NtFreeVirtualMemory(hProcess,
(PVOID *)&lpAddress,
(PULONG)&dwSize,
dwFreeType);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return(FALSE);
}
return(TRUE);
}
DWORD
STDCALL
VirtualQuery (
LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength
)
WINBOOL STDCALL
VirtualFree(LPVOID lpAddress,
DWORD dwSize,
DWORD dwFreeType)
{
return VirtualQueryEx (NtCurrentProcess(),lpAddress, lpBuffer, dwLength );
}
#define MemoryBasicInformation 0
DWORD
STDCALL
VirtualQueryEx (
HANDLE hProcess,
LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength
)
{
NTSTATUS Status;
ULONG ResultLength;
Status = NtQueryVirtualMemory(
hProcess,(LPVOID)lpAddress,
MemoryBasicInformation, lpBuffer,
sizeof(MEMORY_BASIC_INFORMATION),
&ResultLength );
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus (Status);
return ResultLength;
}
return ResultLength;
return(VirtualFreeEx(GetCurrentProcess(),
lpAddress,
dwSize,
dwFreeType));
}
WINBOOL
STDCALL
VirtualUnlock (
LPVOID lpAddress,
DWORD dwSize
)
WINBOOL STDCALL
VirtualProtect(LPVOID lpAddress,
DWORD dwSize,
DWORD flNewProtect,
PDWORD lpflOldProtect)
{
ULONG BytesLocked;
NTSTATUS Status;
Status = NtUnlockVirtualMemory(NtCurrentProcess(),lpAddress,dwSize, &BytesLocked);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus (Status);
return FALSE;
}
return TRUE;
return(VirtualProtectEx(GetCurrentProcess(),
lpAddress,
dwSize,
flNewProtect,
lpflOldProtect));
}
WINBOOL STDCALL
VirtualProtectEx(HANDLE hProcess,
LPVOID lpAddress,
DWORD dwSize,
DWORD flNewProtect,
PDWORD lpflOldProtect)
{
NTSTATUS Status;
Status = NtProtectVirtualMemory(hProcess,
(PVOID)lpAddress,
dwSize,
flNewProtect,
(PULONG)lpflOldProtect);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return(FALSE);
}
return(TRUE);
}
WINBOOL STDCALL
VirtualLock(LPVOID lpAddress,
DWORD dwSize)
{
ULONG BytesLocked;
NTSTATUS Status;
Status = NtLockVirtualMemory(NtCurrentProcess(),
lpAddress,
dwSize,
&BytesLocked);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return(FALSE);
}
return(TRUE);
}
DWORD STDCALL
VirtualQuery(LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength)
{
return(VirtualQueryEx(NtCurrentProcess(),
lpAddress,
lpBuffer,
dwLength));
}
DWORD STDCALL
VirtualQueryEx(HANDLE hProcess,
LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength)
{
NTSTATUS Status;
ULONG ResultLength;
Status = NtQueryVirtualMemory(hProcess,
(LPVOID)lpAddress,
MemoryBasicInformation,
lpBuffer,
sizeof(MEMORY_BASIC_INFORMATION),
&ResultLength );
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return(ResultLength);
}
return(ResultLength);
}
WINBOOL STDCALL
VirtualUnlock(LPVOID lpAddress,
DWORD dwSize)
{
ULONG BytesLocked;
NTSTATUS Status;
Status = NtUnlockVirtualMemory(NtCurrentProcess(),
lpAddress,
dwSize,
&BytesLocked);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return(FALSE);
}
return(TRUE);
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.40 2001/08/03 17:20:06 ekohl Exp $
/* $Id: create.c,v 1.41 2001/08/07 14:11:41 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -157,8 +157,12 @@ KlCreateFirstThread(HANDLE ProcessHandle,
else
CreateSuspended = FALSE;
InitialTeb.StackCommit = (StackCommit < PAGESIZE) ? PAGESIZE : StackCommit;
InitialTeb.StackReserve = (StackReserve < 0x100000) ? 0x100000 : StackReserve;
/* FIXME: use correct commit size */
#if 0
InitialTeb.StackCommit = (StackCommit < PAGESIZE) ? PAGESIZE : StackCommit;
#endif
InitialTeb.StackCommit = InitialTeb.StackReserve - PAGESIZE;
/* size of guard page */
InitialTeb.StackCommit += PAGESIZE;
@ -169,7 +173,7 @@ KlCreateFirstThread(HANDLE ProcessHandle,
&InitialTeb.StackAllocate,
0,
&InitialTeb.StackReserve,
MEM_COMMIT, // MEM_RESERVE,
MEM_RESERVE,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
@ -186,7 +190,7 @@ KlCreateFirstThread(HANDLE ProcessHandle,
DPRINT("StackBase: %p\nStackCommit: %p\n",
InitialTeb.StackBase, InitialTeb.StackCommit);
#if 0
/* Commit stack page(s) */
Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackLimit,
@ -228,7 +232,6 @@ KlCreateFirstThread(HANDLE ProcessHandle,
SetLastErrorByStatus(Status);
return(NULL);
}
#endif
memset(&ThreadContext,0,sizeof(CONTEXT));
ThreadContext.Eip = (ULONG)lpStartAddress;
@ -384,7 +387,7 @@ KlInitPeb (HANDLE ProcessHandle,
&EnvPtr,
0,
&EnvSize,
MEM_COMMIT,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
@ -405,7 +408,7 @@ KlInitPeb (HANDLE ProcessHandle,
&PpbBase,
0,
&PpbSize,
MEM_COMMIT,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{

View file

@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.24 2001/08/03 17:20:46 ekohl Exp $
/* $Id: thread.c,v 1.25 2001/08/07 14:13:45 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -141,8 +141,12 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
else
CreateSuspended = FALSE;
InitialTeb.StackCommit = (dwStackSize == 0) ? PAGESIZE : dwStackSize;
InitialTeb.StackReserve = 0x100000; /* 1MByte */
/* FIXME: use correct commit size */
#if 0
InitialTeb.StackCommit = (dwStackSize == 0) ? PAGESIZE : dwStackSize;
#endif
InitialTeb.StackCommit = InitialTeb.StackReserve - PAGESIZE;
/* size of guard page */
InitialTeb.StackCommit += PAGESIZE;
@ -153,7 +157,7 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
&InitialTeb.StackAllocate,
0,
&InitialTeb.StackReserve,
MEM_COMMIT, //MEM_RESERVE,
MEM_RESERVE,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
@ -171,7 +175,7 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
DPRINT("StackBase: %p\nStackCommit: 0x%lX\n",
InitialTeb.StackBase,
InitialTeb.StackCommit);
#if 0
/* Commit stack pages */
Status = NtAllocateVirtualMemory(hProcess,
&InitialTeb.StackLimit,
@ -213,7 +217,6 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
SetLastErrorByStatus(Status);
return(NULL);
}
#endif
memset(&ThreadContext,0,sizeof(CONTEXT));
ThreadContext.Eip = (LONG)ThreadStartup;

View file

@ -1,4 +1,4 @@
/* $Id: env.c,v 1.12 2000/12/28 20:38:27 ekohl Exp $
/* $Id: env.c,v 1.13 2001/08/07 14:10:41 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -55,7 +55,7 @@ RtlCreateEnvironment(BOOLEAN Inherit,
&EnvPtr,
0,
&RegionSize,
MEM_COMMIT,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
@ -79,7 +79,7 @@ RtlCreateEnvironment(BOOLEAN Inherit,
&EnvPtr,
0,
&RegionSize,
MEM_COMMIT,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (NT_SUCCESS(Status))
{
@ -322,7 +322,7 @@ found:
(VOID**)&new_env,
0,
&new_size,
MEM_COMMIT,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{

View file

@ -1,4 +1,4 @@
/* $Id: handle.c,v 1.1 2001/05/26 16:49:51 ekohl Exp $
/* $Id: handle.c,v 1.2 2001/08/07 14:10:41 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -71,7 +71,7 @@ RtlAllocateHandle(PRTL_HANDLE_TABLE HandleTable,
(PVOID*)&ArrayPointer,
0,
&ArraySize,
MEM_COMMIT,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
return NULL;

View file

@ -95,7 +95,7 @@ typedef struct tagSUBHEAP
struct tagHEAP *heap; /* Main heap structure */
DWORD magic; /* Magic number */
WORD selector; /* Selector for HEAP_WINE_SEGPTR heaps */
} SUBHEAP;
} SUBHEAP, *PSUBHEAP;
#define SUBHEAP_MAGIC ((DWORD)('S' | ('U'<<8) | ('B'<<16) | ('H'<<24)))
@ -108,7 +108,7 @@ typedef struct tagHEAP
DWORD flags; /* Heap flags */
DWORD magic; /* Magic number */
void *private; /* Private pointer for the user of the heap */
} HEAP;
} HEAP, *PHEAP;
#define HEAP_MAGIC ((DWORD)('H' | ('E'<<8) | ('A'<<16) | ('P'<<24)))
@ -131,7 +131,8 @@ static BOOL HEAP_IsRealArena( HANDLE heap, DWORD flags, LPCVOID block, BOOL quie
/***********************************************************************
* HEAP_Dump
*/
void HEAP_Dump( HEAP *heap )
void
HEAP_Dump(PHEAP heap)
{
int i;
SUBHEAP *subheap;
@ -213,9 +214,9 @@ void HEAP_Dump( HEAP *heap )
* Pointer to the heap
* NULL: Failure
*/
static HEAP *HEAP_GetPtr(
HANDLE heap /* [in] Handle to the heap */
) {
static PHEAP
HEAP_GetPtr(HANDLE heap) /* [in] Handle to the heap */
{
HEAP *heapPtr = (HEAP *)heap;
if (!heapPtr || (heapPtr->magic != HEAP_MAGIC))
{
@ -237,7 +238,9 @@ static HEAP *HEAP_GetPtr(
*
* Insert a free block into the free list.
*/
static void HEAP_InsertFreeBlock( HEAP *heap, ARENA_FREE *pArena )
static VOID
HEAP_InsertFreeBlock(PHEAP heap,
ARENA_FREE *pArena)
{
FREE_LIST_ENTRY *pEntry = heap->freeList;
while (pEntry->size < pArena->size) pEntry++;
@ -257,10 +260,10 @@ static void HEAP_InsertFreeBlock( HEAP *heap, ARENA_FREE *pArena )
* Pointer: Success
* NULL: Failure
*/
static SUBHEAP *HEAP_FindSubHeap(
HEAP *heap, /* [in] Heap pointer */
LPCVOID ptr /* [in] Address */
) {
static PSUBHEAP
HEAP_FindSubHeap(HEAP *heap, /* [in] Heap pointer */
LPCVOID ptr) /* [in] Address */
{
SUBHEAP *sub = &heap->subheap;
while (sub)
{
@ -277,7 +280,9 @@ static SUBHEAP *HEAP_FindSubHeap(
*
* Make sure the heap storage is committed up to (not including) ptr.
*/
static inline BOOL HEAP_Commit( SUBHEAP *subheap, void *ptr )
static inline BOOL
HEAP_Commit(SUBHEAP *subheap,
void *ptr)
{
DWORD size = (DWORD)((char *)ptr - (char *)subheap);
NTSTATUS Status;
@ -291,7 +296,7 @@ static inline BOOL HEAP_Commit( SUBHEAP *subheap, void *ptr )
address = (PVOID)((char *)subheap + subheap->commitSize);
commitsize = size - subheap->commitSize;
Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
Status = NtAllocateVirtualMemory(NtCurrentProcess(),
&address,
0,
&commitsize,
@ -586,7 +591,7 @@ static SUBHEAP *HEAP_CreateSubHeap(PVOID BaseAddress,
&address,
0,
(PULONG)&totalSize,
MEM_RESERVE,
MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE);
if (!NT_SUCCESS(Status))
{
@ -1011,7 +1016,8 @@ RtlCreateHeap(ULONG flags,
* TRUE: Success
* FALSE: Failure
*/
BOOL STDCALL RtlDestroyHeap( HANDLE heap /* [in] Handle of heap */ )
BOOL STDCALL
RtlDestroyHeap(HANDLE heap) /* [in] Handle of heap */
{
HEAP *heapPtr = HEAP_GetPtr( heap );
SUBHEAP *subheap;
@ -1054,11 +1060,11 @@ BOOL STDCALL RtlDestroyHeap( HANDLE heap /* [in] Handle of heap */ )
* Pointer to allocated memory block
* NULL: Failure
*/
PVOID STDCALL RtlAllocateHeap(
HANDLE heap, /* [in] Handle of private heap block */
ULONG flags, /* [in] Heap allocation control flags */
ULONG size /* [in] Number of bytes to allocate */
) {
PVOID STDCALL
RtlAllocateHeap(HANDLE heap, /* [in] Handle of private heap block */
ULONG flags, /* [in] Heap allocation control flags */
ULONG size) /* [in] Number of bytes to allocate */
{
ARENA_FREE *pArena;
ARENA_INUSE *pInUse;
SUBHEAP *subheap;
@ -1511,76 +1517,9 @@ HW_end:
return ret;
}
/***********************************************************************
* HEAP_CreateSystemHeap
*
* Create the system heap.
*/
BOOL HEAP_CreateSystemHeap(void)
{
SYSTEM_HEAP_DESCR *descr;
HANDLE heap;
HEAP *heapPtr;
int created;
HANDLE map = CreateFileMappingA( INVALID_HANDLE_VALUE, NULL, SEC_COMMIT | PAGE_READWRITE,
0, HEAP_DEF_SIZE, "__SystemHeap" );
if (!map) return FALSE;
created = (GetLastError() != ERROR_ALREADY_EXISTS);
if (!(heapPtr = MapViewOfFileEx( map, FILE_MAP_ALL_ACCESS, 0, 0, 0, SYSTEM_HEAP_BASE )))
{
/* pre-defined address not available, use any one */
fprintf( stderr, "Warning: system heap base address %p not available\n",
SYSTEM_HEAP_BASE );
if (!(heapPtr = MapViewOfFile( map, FILE_MAP_ALL_ACCESS, 0, 0, 0 )))
{
CloseHandle( map );
return FALSE;
}
}
heap = (HANDLE)heapPtr;
if (created) /* newly created heap */
{
HEAP_InitSubHeap( heapPtr, heapPtr, HEAP_WINE_SHARED, 0, HEAP_DEF_SIZE );
HeapLock( heap );
descr = heapPtr->private = HeapAlloc( heap, HEAP_ZERO_MEMORY, sizeof(*descr) );
assert( descr );
}
else
{
/* wait for the heap to be initialized */
while (!heapPtr->private) Sleep(1);
HeapLock( heap );
/* remap it to the right address if necessary */
if (heapPtr->subheap.heap != heapPtr)
{
void *base = heapPtr->subheap.heap;
HeapUnlock( heap );
UnmapViewOfFile( heapPtr );
if (!(heapPtr = MapViewOfFileEx( map, FILE_MAP_ALL_ACCESS, 0, 0, 0, base )))
{
fprintf( stderr, "Couldn't map system heap at the correct address (%p)\n", base );
CloseHandle( map );
return FALSE;
}
heap = (HANDLE)heapPtr;
HeapLock( heap );
}
descr = heapPtr->private;
assert( descr );
}
SystemHeap = heap;
SystemHeapDescr = descr;
HeapUnlock( heap );
CloseHandle( map );
return TRUE;
}
#endif
HANDLE STDCALL
RtlGetProcessHeap(VOID)
{
@ -1664,3 +1603,5 @@ RtlValidateProcessHeaps(VOID)
return Result;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: ppb.c,v 1.9 2000/12/28 20:38:27 ekohl Exp $
/* $Id: ppb.c,v 1.10 2001/08/07 14:10:41 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -146,7 +146,7 @@ RtlCreateProcessParameters(PRTL_USER_PROCESS_PARAMETERS *ProcessParameters,
(PVOID*)&Param,
0,
&RegionSize,
MEM_COMMIT,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.26 2001/08/03 17:18:50 ekohl Exp $
/* $Id: process.c,v 1.27 2001/08/07 14:10:42 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -43,23 +43,30 @@ RtlpCreateFirstThread(HANDLE ProcessHandle,
ObjectAttributes.Attributes = 0;
ObjectAttributes.SecurityQualityOfService = NULL;
if (StackCommit > PAGESIZE)
InitialTeb.StackCommit = StackCommit;
else
InitialTeb.StackCommit = PAGESIZE;
if (StackReserve > 0x100000)
InitialTeb.StackReserve = StackReserve;
else
InitialTeb.StackReserve = 0x100000; /* 1MByte */
/* FIXME */
#if 0
if (StackCommit > PAGESIZE)
InitialTeb.StackCommit = StackCommit;
else
InitialTeb.StackCommit = PAGESIZE;
#endif
InitialTeb.StackCommit = InitialTeb.StackReserve - PAGESIZE;
/* add guard page size */
InitialTeb.StackCommit += PAGESIZE;
/* Reserve stack */
InitialTeb.StackAllocate = NULL;
Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackAllocate,
0,
&InitialTeb.StackReserve,
MEM_COMMIT, //MEM_RESERVE,
MEM_RESERVE,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
@ -71,12 +78,11 @@ RtlpCreateFirstThread(HANDLE ProcessHandle,
InitialTeb.StackAllocate, InitialTeb.StackReserve);
InitialTeb.StackBase = (PVOID)((ULONG)InitialTeb.StackAllocate + InitialTeb.StackReserve);
InitialTeb.StackLimit = (PVOID)((ULONG)InitialTeb.StackBase - InitialTeb.StackCommit - PAGESIZE);
InitialTeb.StackCommit += PAGESIZE;
InitialTeb.StackLimit = (PVOID)((ULONG)InitialTeb.StackBase - InitialTeb.StackCommit);
DPRINT("StackBase: %p StackCommit: 0x%lX\n",
InitialTeb.StackBase, InitialTeb.StackCommit);
#if 0
/* Commit stack */
Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackLimit,
@ -115,7 +121,7 @@ RtlpCreateFirstThread(HANDLE ProcessHandle,
DPRINT("Error comitting guard page!\n");
return(Status);
}
#endif
memset(&ThreadContext,0,sizeof(CONTEXT));
ThreadContext.Eip = (ULONG)lpStartAddress;
ThreadContext.SegGs = USER_DS;
@ -281,7 +287,7 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
&EnvPtr,
0,
&EnvSize,
MEM_COMMIT,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
@ -303,7 +309,7 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
&PpbBase,
0,
&PpbSize,
MEM_COMMIT,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{

View file

@ -1,4 +1,4 @@
/* $Id: sd.c,v 1.4 2000/06/29 23:35:32 dwelch Exp $
/* $Id: sd.c,v 1.5 2001/08/07 14:10:42 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -17,8 +17,9 @@
/* FUNCTIONS ***************************************************************/
NTSTATUS STDCALL RtlCreateSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
ULONG Revision)
NTSTATUS STDCALL
RtlCreateSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
ULONG Revision)
{
if (Revision != 1)
{
@ -34,7 +35,8 @@ NTSTATUS STDCALL RtlCreateSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescr
return(STATUS_SUCCESS);
}
ULONG STDCALL RtlLengthSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor)
ULONG STDCALL
RtlLengthSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor)
{
PSID Owner;
PSID Group;
@ -88,10 +90,11 @@ ULONG STDCALL RtlLengthSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescript
return(Length);
}
NTSTATUS STDCALL RtlGetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
PBOOLEAN DaclPresent,
PACL* Dacl,
PBOOLEAN DaclDefaulted)
NTSTATUS STDCALL
RtlGetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PBOOLEAN DaclPresent,
PACL* Dacl,
PBOOLEAN DaclDefaulted)
{
if (SecurityDescriptor->Revision != 1)
{
@ -130,10 +133,11 @@ NTSTATUS STDCALL RtlGetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDesc
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL RtlSetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
BOOLEAN DaclPresent,
PACL Dacl,
BOOLEAN DaclDefaulted)
NTSTATUS STDCALL
RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
BOOLEAN DaclPresent,
PACL Dacl,
BOOLEAN DaclDefaulted)
{
if (SecurityDescriptor->Revision != 1)
{
@ -158,14 +162,16 @@ NTSTATUS STDCALL RtlSetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDesc
return(STATUS_SUCCESS);
}
BOOLEAN STDCALL RtlValidSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor)
BOOLEAN STDCALL
RtlValidSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor)
{
UNIMPLEMENTED;
}
NTSTATUS STDCALL RtlSetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID Owner,
BOOLEAN OwnerDefaulted)
NTSTATUS STDCALL
RtlSetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID Owner,
BOOLEAN OwnerDefaulted)
{
if (SecurityDescriptor->Revision != 1)
{
@ -184,9 +190,10 @@ NTSTATUS STDCALL RtlSetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL RtlGetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID* Owner,
PBOOLEAN OwnerDefaulted)
NTSTATUS STDCALL
RtlGetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID* Owner,
PBOOLEAN OwnerDefaulted)
{
if (SecurityDescriptor->Revision != 1)
{
@ -219,9 +226,10 @@ NTSTATUS STDCALL RtlGetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL RtlSetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID Group,
BOOLEAN GroupDefaulted)
NTSTATUS STDCALL
RtlSetGroupSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID Group,
BOOLEAN GroupDefaulted)
{
if (SecurityDescriptor->Revision != 1)
{
@ -240,9 +248,10 @@ NTSTATUS STDCALL RtlSetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL RtlGetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID* Group,
PBOOLEAN GroupDefaulted)
NTSTATUS STDCALL
RtlGetGroupSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID* Group,
PBOOLEAN GroupDefaulted)
{
if (SecurityDescriptor->Revision != 1)
{
@ -275,58 +284,48 @@ NTSTATUS STDCALL RtlGetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS);
}
NTSTATUS
STDCALL
RtlMakeSelfRelativeSD (
PSECURITY_DESCRIPTOR AbsSD,
PSECURITY_DESCRIPTOR RelSD,
PULONG BufferLength
)
NTSTATUS STDCALL
RtlMakeSelfRelativeSD(PSECURITY_DESCRIPTOR AbsSD,
PSECURITY_DESCRIPTOR RelSD,
PULONG BufferLength)
{
UNIMPLEMENTED;
}
NTSTATUS
STDCALL
RtlAbsoluteToSelfRelativeSD (
PSECURITY_DESCRIPTOR AbsSD,
PSECURITY_DESCRIPTOR RelSD,
PULONG BufferLength
NTSTATUS STDCALL
RtlAbsoluteToSelfRelativeSD(PSECURITY_DESCRIPTOR AbsSD,
PSECURITY_DESCRIPTOR RelSD,
PULONG BufferLength
)
{
if (AbsSD->Control & SE_SELF_RELATIVE)
{
return STATUS_BAD_DESCRIPTOR_FORMAT;
}
if (AbsSD->Control & SE_SELF_RELATIVE)
{
return(STATUS_BAD_DESCRIPTOR_FORMAT);
}
return (RtlMakeSelfRelativeSD (AbsSD, RelSD, BufferLength));
return(RtlMakeSelfRelativeSD (AbsSD, RelSD, BufferLength));
}
NTSTATUS
STDCALL
RtlGetControlSecurityDescriptor (
PSECURITY_DESCRIPTOR SecurityDescriptor,
PSECURITY_DESCRIPTOR_CONTROL Control,
PULONG Revision
)
NTSTATUS STDCALL
RtlGetControlSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSECURITY_DESCRIPTOR_CONTROL Control,
PULONG Revision)
{
*Revision = SecurityDescriptor->Revision;
*Revision = SecurityDescriptor->Revision;
if (SecurityDescriptor->Revision != 1)
return STATUS_UNKNOWN_REVISION;
if (SecurityDescriptor->Revision != 1)
return(STATUS_UNKNOWN_REVISION);
*Control = SecurityDescriptor->Control;
*Control = SecurityDescriptor->Control;
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
NTSTATUS
STDCALL
RtlGetSaclSecurityDescriptor (
PSECURITY_DESCRIPTOR SecurityDescriptor,
PBOOLEAN SaclPresent,
PACL *Sacl,
PBOOLEAN SaclDefaulted)
NTSTATUS STDCALL
RtlGetSaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PBOOLEAN SaclPresent,
PACL *Sacl,
PBOOLEAN SaclDefaulted)
{
if (SecurityDescriptor->Revision != 1)
{
@ -365,14 +364,11 @@ RtlGetSaclSecurityDescriptor (
return(STATUS_SUCCESS);
}
NTSTATUS
STDCALL
RtlSetSaclSecurityDescriptor (
PSECURITY_DESCRIPTOR SecurityDescriptor,
BOOLEAN SaclPresent,
PACL Sacl,
BOOLEAN SaclDefaulted
)
NTSTATUS STDCALL
RtlSetSaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
BOOLEAN SaclPresent,
PACL Sacl,
BOOLEAN SaclDefaulted)
{
if (SecurityDescriptor->Revision != 1)
{
@ -397,21 +393,18 @@ RtlSetSaclSecurityDescriptor (
return(STATUS_SUCCESS);
}
NTSTATUS
STDCALL
RtlSelfRelativeToAbsoluteSD (
PSECURITY_DESCRIPTOR RelSD,
PSECURITY_DESCRIPTOR AbsSD,
PDWORD AbsSDSize,
PACL Dacl,
PDWORD DaclSize,
PACL Sacl,
PDWORD SaclSize,
PSID Owner,
PDWORD OwnerSize,
PSID Group,
PDWORD GroupSize
)
NTSTATUS STDCALL
RtlSelfRelativeToAbsoluteSD(PSECURITY_DESCRIPTOR RelSD,
PSECURITY_DESCRIPTOR AbsSD,
PDWORD AbsSDSize,
PACL Dacl,
PDWORD DaclSize,
PACL Sacl,
PDWORD SaclSize,
PSID Owner,
PDWORD OwnerSize,
PSID Group,
PDWORD GroupSize)
{
UNIMPLEMENTED;
}

View file

@ -35,68 +35,72 @@ RtlCreateUserThread(HANDLE ProcessHandle,
PHANDLE ThreadHandle,
PCLIENT_ID ClientId)
{
HANDLE LocalThreadHandle;
CLIENT_ID LocalClientId;
OBJECT_ATTRIBUTES ObjectAttributes;
INITIAL_TEB InitialTeb;
CONTEXT ThreadContext;
ULONG OldPageProtection;
NTSTATUS Status;
HANDLE LocalThreadHandle;
CLIENT_ID LocalClientId;
OBJECT_ATTRIBUTES ObjectAttributes;
INITIAL_TEB InitialTeb;
CONTEXT ThreadContext;
ULONG OldPageProtection;
NTSTATUS Status;
/* initialize initial teb */
if ((StackCommit != NULL) && (*StackCommit > PAGESIZE))
InitialTeb.StackCommit = *StackCommit;
else
InitialTeb.StackCommit = PAGESIZE;
/* initialize initial teb */
if ((StackReserve != NULL) && (*StackReserve > 0x100000))
InitialTeb.StackReserve = *StackReserve;
else
InitialTeb.StackReserve = 0x100000; /* 1MByte */
if ((StackReserve != NULL) && (*StackReserve > 0x100000))
InitialTeb.StackReserve = *StackReserve;
else
InitialTeb.StackReserve = 0x100000; /* 1MByte */
/* FIXME: use correct commit size */
#if 0
if ((StackCommit != NULL) && (*StackCommit > PAGESIZE))
InitialTeb.StackCommit = *StackCommit;
else
InitialTeb.StackCommit = PAGESIZE;
#endif
InitialTeb.StackCommit = InitialTeb.StackReserve - PAGESIZE;
/* add size of guard page */
InitialTeb.StackCommit += PAGESIZE;
/* add size of guard page */
InitialTeb.StackCommit += PAGESIZE;
/* Reserve stack */
InitialTeb.StackAllocate = NULL;
Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackAllocate,
0,
&InitialTeb.StackReserve,
MEM_COMMIT, //MEM_RESERVE,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
/* Reserve stack */
InitialTeb.StackAllocate = NULL;
Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackAllocate,
0,
&InitialTeb.StackReserve,
MEM_RESERVE,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DPRINT("Error reserving stack space!\n");
return Status;
DPRINT("Error reserving stack space!\n");
return(Status);
}
DPRINT("StackAllocate: %p ReserveSize: 0x%lX\n",
InitialTeb.StackAllocate, InitialTeb.StackReserve);
DPRINT("StackAllocate: %p ReserveSize: 0x%lX\n",
InitialTeb.StackAllocate, InitialTeb.StackReserve);
InitialTeb.StackBase = (PVOID)((ULONG)InitialTeb.StackAllocate + InitialTeb.StackReserve);
InitialTeb.StackLimit = (PVOID)((ULONG)InitialTeb.StackBase - InitialTeb.StackCommit);
InitialTeb.StackBase = (PVOID)((ULONG)InitialTeb.StackAllocate + InitialTeb.StackReserve);
InitialTeb.StackLimit = (PVOID)((ULONG)InitialTeb.StackBase - InitialTeb.StackCommit);
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))
DPRINT("StackBase: %p StackCommit: 0x%lX\n",
InitialTeb.StackBase, InitialTeb.StackCommit);
/* 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);
/* release the stack space */
NtFreeVirtualMemory(ProcessHandle,
InitialTeb.StackAllocate,
&InitialTeb.StackReserve,
MEM_RELEASE);
DPRINT("Error comitting stack page!\n");
return Status;
DPRINT("Error comitting stack page!\n");
return(Status);
}
DPRINT("StackLimit: %p\nStackCommit: 0x%lX\n",
@ -120,63 +124,62 @@ RtlCreateUserThread(HANDLE ProcessHandle,
DPRINT("Error protecting guard page!\n");
return(Status);
}
#endif
/* initialize thread context */
RtlInitializeContext (ProcessHandle,
&ThreadContext,
Parameter,
StartAddress,
&InitialTeb);
/* create the thread */
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = NULL;
ObjectAttributes.Attributes = OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = SecurityDescriptor;
ObjectAttributes.SecurityQualityOfService = NULL;
/* initialize thread context */
RtlInitializeContext(ProcessHandle,
&ThreadContext,
Parameter,
StartAddress,
&InitialTeb);
Status = NtCreateThread(&LocalThreadHandle,
THREAD_ALL_ACCESS,
&ObjectAttributes,
ProcessHandle,
&LocalClientId,
&ThreadContext,
&InitialTeb,
CreateSuspended);
/* create the thread */
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = NULL;
ObjectAttributes.Attributes = OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = SecurityDescriptor;
ObjectAttributes.SecurityQualityOfService = NULL;
if (!NT_SUCCESS(Status))
Status = NtCreateThread(&LocalThreadHandle,
THREAD_ALL_ACCESS,
&ObjectAttributes,
ProcessHandle,
&LocalClientId,
&ThreadContext,
&InitialTeb,
CreateSuspended);
if (!NT_SUCCESS(Status))
{
/* release the stack space */
NtFreeVirtualMemory(ProcessHandle,
InitialTeb.StackAllocate,
&InitialTeb.StackReserve,
MEM_RELEASE);
/* release the stack space */
NtFreeVirtualMemory(ProcessHandle,
InitialTeb.StackAllocate,
&InitialTeb.StackReserve,
MEM_RELEASE);
DPRINT("Error creating thread!\n");
return Status;
DPRINT("Error creating thread!\n");
return(Status);
}
/* return committed stack size */
if (StackCommit)
*StackCommit = InitialTeb.StackCommit;
/* return committed stack size */
if (StackCommit)
*StackCommit = InitialTeb.StackCommit;
/* return reserved stack size */
if (StackReserve)
*StackReserve = InitialTeb.StackReserve;
/* return reserved stack size */
if (StackReserve)
*StackReserve = InitialTeb.StackReserve;
/* return thread handle */
if (ThreadHandle)
*ThreadHandle = LocalThreadHandle;
/* return thread handle */
if (ThreadHandle)
*ThreadHandle = LocalThreadHandle;
/* return client id */
if (ClientId)
/* return client id */
if (ClientId)
{
ClientId->UniqueProcess = LocalClientId.UniqueProcess;
ClientId->UniqueThread = LocalClientId.UniqueThread;
ClientId->UniqueProcess = LocalClientId.UniqueProcess;
ClientId->UniqueThread = LocalClientId.UniqueThread;
}
return(STATUS_SUCCESS);
return(STATUS_SUCCESS);
}

View file

@ -51,6 +51,7 @@ NTSTATUS LdrLoadInitialProcess (VOID)
CONTEXT Context;
HANDLE ThreadHandle;
INITIAL_TEB InitialTeb;
ULONG OldPageProtection;
/*
* Get the absolute path to smss.exe using the
@ -153,22 +154,24 @@ NTSTATUS LdrLoadInitialProcess (VOID)
NTHeaders = RtlImageNtHeader(Peb->ImageBaseAddress);
DPRINT("NTHeaders %x\n", NTHeaders);
InitialTeb.StackReserve = NTHeaders->OptionalHeader.SizeOfStackReserve;
InitialTeb.StackCommit = NTHeaders->OptionalHeader.SizeOfStackCommit;
/* FIXME: use correct commit size */
InitialTeb.StackCommit = NTHeaders->OptionalHeader.SizeOfStackReserve - PAGESIZE;
// InitialTeb.StackCommit = NTHeaders->OptionalHeader.SizeOfStackCommit;
/* add guard page size */
InitialTeb.StackCommit += PAGESIZE;
DPRINT("StackReserve 0x%lX StackCommit 0x%lX\n",
InitialTeb.StackReserve, InitialTeb.StackCommit);
KeDetachProcess();
DPRINT("Dereferencing process\n");
// ObDereferenceObject(Process);
ObDereferenceObject(Process);
DPRINT("Allocating stack\n");
InitialTeb.StackAllocate = NULL;
Status = ZwAllocateVirtualMemory(ProcessHandle,
Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackAllocate,
0,
&InitialTeb.StackReserve,
MEM_COMMIT, // MEM_RESERVE,
MEM_RESERVE,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
@ -184,7 +187,7 @@ NTSTATUS LdrLoadInitialProcess (VOID)
DPRINT("StackBase: %p StackCommit: 0x%lX\n",
InitialTeb.StackBase, InitialTeb.StackCommit);
#if 0
/* Commit stack */
Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackLimit,
@ -225,45 +228,44 @@ NTSTATUS LdrLoadInitialProcess (VOID)
DPRINT("Error protecting guard page!\n");
return(Status);
}
#endif
DPRINT("Attaching to process\n");
KeAttachProcess(Process);
Peb = (PPEB)PEB_BASE;
DPRINT("Peb %x\n", Peb);
DPRINT("CurrentProcess %x Peb->ImageBaseAddress %x\n",
PsGetCurrentProcess(),
Peb->ImageBaseAddress);
KeDetachProcess();
DPRINT("Attaching to process\n");
KeAttachProcess(Process);
Peb = (PPEB)PEB_BASE;
DPRINT("Peb %x\n", Peb);
DPRINT("CurrentProcess %x Peb->ImageBaseAddress %x\n",
PsGetCurrentProcess(),
Peb->ImageBaseAddress);
KeDetachProcess();
/*
* Initialize context to point to LdrStartup
*/
memset(&Context,0,sizeof(CONTEXT));
Context.Eip = (ULONG)LdrStartupAddr;
Context.SegCs = USER_CS;
Context.SegDs = USER_DS;
Context.SegEs = USER_DS;
Context.SegFs = TEB_SELECTOR;
Context.SegGs = USER_DS;
Context.SegSs = USER_DS;
Context.EFlags = 0x202;
Context.Esp = (ULONG)InitialTeb.StackBase - 20;
/*
* Initialize context to point to LdrStartup
*/
memset(&Context,0,sizeof(CONTEXT));
Context.Eip = (ULONG)LdrStartupAddr;
Context.SegCs = USER_CS;
Context.SegDs = USER_DS;
Context.SegEs = USER_DS;
Context.SegFs = TEB_SELECTOR;
Context.SegGs = USER_DS;
Context.SegSs = USER_DS;
Context.EFlags = 0x202;
Context.Esp = (ULONG)InitialTeb.StackBase - 20;
DPRINT("LdrStartupAddr %x\n",LdrStartupAddr);
/*
* FIXME: Create process and let 'er rip
*/
DPRINT("Creating thread for initial process\n");
Status = ZwCreateThread(&ThreadHandle,
THREAD_ALL_ACCESS,
NULL,
ProcessHandle,
NULL,
&Context,
&InitialTeb,
FALSE);
DPRINT("LdrStartupAddr %x\n",LdrStartupAddr);
/*
* FIXME: Create process and let 'er rip
*/
DPRINT("Creating thread for initial process\n");
Status = ZwCreateThread(&ThreadHandle,
THREAD_ALL_ACCESS,
NULL,
ProcessHandle,
NULL,
&Context,
&InitialTeb,
FALSE);
if (!NT_SUCCESS(Status))
{
DPRINT("Thread creation failed (Status %x)\n", Status);
@ -273,22 +275,22 @@ NTSTATUS LdrLoadInitialProcess (VOID)
&InitialTeb.StackReserve,
MEM_RELEASE);
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
return Status;
}
DPRINT("Attaching to process\n");
KeAttachProcess(Process);
Peb = (PPEB)PEB_BASE;
DPRINT("Peb %x\n", Peb);
DPRINT("CurrentProcess %x Peb->ImageBaseAddress %x\n",
PsGetCurrentProcess(),
Peb->ImageBaseAddress);
KeDetachProcess();
return STATUS_SUCCESS;
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
return(Status);
}
DPRINT("Attaching to process\n");
KeAttachProcess(Process);
Peb = (PPEB)PEB_BASE;
DPRINT("Peb %x\n", Peb);
DPRINT("CurrentProcess %x Peb->ImageBaseAddress %x\n",
PsGetCurrentProcess(),
Peb->ImageBaseAddress);
KeDetachProcess();
return(STATUS_SUCCESS);
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: virtual.c,v 1.47 2001/05/05 19:13:10 chorns Exp $
/* $Id: virtual.c,v 1.48 2001/08/07 14:07:33 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -501,6 +501,7 @@ MmSplitSegment(PMADDRESS_SPACE AddressSpace,
ULONG OldProtect;
ULONG OldLength;
DPRINT("MmSplitSegment()\n");
/*
* Save the type and protection and length of the current segment
*/
@ -513,7 +514,7 @@ MmSplitSegment(PMADDRESS_SPACE AddressSpace,
* there is nothing to do.
*/
if (FirstSegment->Type == Type && FirstSegment->Protect == Protect)
{
{
return(STATUS_SUCCESS);
}
@ -672,7 +673,7 @@ NTSTATUS MmGatherSegment(PMADDRESS_SPACE AddressSpace,
*/
ULONG OldType;
ULONG OldProtect;
ULONG OldProtect;
OldType = FirstSegment->Type;
OldProtect = FirstSegment->Protect;
@ -823,12 +824,12 @@ NTSTATUS MmComplexVirtualMemoryOperation(PMADDRESS_SPACE AddressSpace,
}
NTSTATUS STDCALL
NTSTATUS STDCALL
NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
IN OUT PVOID* UBaseAddress,
IN ULONG ZeroBits,
IN OUT PULONG URegionSize,
IN ULONG AllocationType,
IN ULONG AllocationType,
IN ULONG Protect)
/*
* FUNCTION: Allocates a block of virtual memory in the process address space
@ -843,8 +844,8 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
* allocated at a address below a certain value.
* RegionSize = The number of bytes to allocate
* AllocationType = Indicates the type of virtual memory you like to
* allocated, can be one of the values : MEM_COMMIT,
* MEM_RESERVE, MEM_RESET, MEM_TOP_DOWN
* allocated, can be a combination of MEM_COMMIT,
* MEM_RESERVE, MEM_RESET, MEM_TOP_DOWN.
* Protect = Indicates the protection type of the pages allocated, can be
* a combination of PAGE_READONLY, PAGE_READWRITE,
* PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE, PAGE_GUARD,
@ -882,6 +883,16 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
{
return(STATUS_INVALID_PAGE_PROTECTION);
}
if ((AllocationType & (MEM_COMMIT | MEM_RESERVE)) == 0)
{
return(STATUS_INVALID_PARAMETER);
}
if (((AllocationType & (MEM_COMMIT | MEM_RESERVE)) == MEM_COMMIT) &&
(*UBaseAddress == 0))
{
return(STATUS_INVALID_PARAMETER);
}
PBaseAddress = *UBaseAddress;
PRegionSize = *URegionSize;
@ -902,19 +913,14 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
return(Status);
}
if (AllocationType & MEM_RESERVE)
{
Type = MEM_RESERVE;
}
else
{
Type = MEM_COMMIT;
}
Type = (AllocationType & MEM_COMMIT) ? MEM_COMMIT : MEM_RESERVE;
DPRINT("Type %x\n", Type);
AddressSpace = &Process->AddressSpace;
MmLockAddressSpace(AddressSpace);
if (PBaseAddress != 0)
if ((PBaseAddress != 0) &&
((AllocationType & (MEM_COMMIT | MEM_RESERVE)) == MEM_COMMIT))
{
MemoryArea = MmOpenMemoryAreaByAddress(&Process->AddressSpace,
BaseAddress);
@ -932,6 +938,7 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
/* FIXME: Reserve/dereserve swap pages */
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
DPRINT("NtAllocateVirtualMemory() = %x\n",Status);
return(Status);
}
else if (MemoryArea != NULL)
@ -941,8 +948,9 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
return(STATUS_UNSUCCESSFUL);
}
}
Segment = ExAllocatePoolWithTag(NonPagedPool, sizeof(MM_SEGMENT),
Segment = ExAllocatePoolWithTag(NonPagedPool,
sizeof(MM_SEGMENT),
TAG_MM_SEGMENT);
if (Segment == NULL)
{
@ -962,9 +970,9 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
if (!NT_SUCCESS(Status))
{
DPRINT("NtAllocateVirtualMemory() = %x\n",Status);
MmUnlockAddressSpace(AddressSpace);
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
DPRINT("NtAllocateVirtualMemory() = %x\n",Status);
return(Status);
}
@ -976,16 +984,16 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
InsertTailList(&MemoryArea->Data.VirtualMemoryData.SegmentListHead,
&Segment->SegmentListEntry);
DPRINT("*UBaseAddress %x\n",*UBaseAddress);
if ((AllocationType & MEM_COMMIT) &&
((Protect & PAGE_READWRITE) ||
(Protect & PAGE_EXECUTE_READWRITE)))
{
MmReserveSwapPages(RegionSize);
}
*UBaseAddress = BaseAddress;
*URegionSize = RegionSize;
DPRINT("*UBaseAddress %x *URegionSize %x\n", BaseAddress, RegionSize);
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
@ -1013,7 +1021,9 @@ NtFlushVirtualMemory(IN HANDLE ProcessHandle,
}
VOID STATIC
MmFreeVirtualMemoryPage(PVOID Context, PVOID Address, ULONG PhysicalAddr)
MmFreeVirtualMemoryPage(PVOID Context,
PVOID Address,
ULONG PhysicalAddr)
{
PEPROCESS Process = (PEPROCESS)Context;
@ -1024,17 +1034,21 @@ MmFreeVirtualMemoryPage(PVOID Context, PVOID Address, ULONG PhysicalAddr)
}
}
VOID
MmFreeVirtualMemory(PEPROCESS Process, PMEMORY_AREA MemoryArea)
VOID
MmFreeVirtualMemory(PEPROCESS Process,
PMEMORY_AREA MemoryArea)
{
PLIST_ENTRY current_entry;
PMM_SEGMENT current;
DPRINT("MmFreeVirtualMemory(Process %p MemoryArea %p)\n", Process, MemoryArea);
current_entry = MemoryArea->Data.VirtualMemoryData.SegmentListHead.Flink;
while (current_entry != &MemoryArea->Data.VirtualMemoryData.SegmentListHead)
{
current = CONTAINING_RECORD(current_entry, MM_SEGMENT, SegmentListEntry);
current_entry = current_entry->Flink;
DPRINT("ExFreePool(%p)\n", current);
ExFreePool(current);
}
@ -1124,7 +1138,7 @@ NtFreeVirtualMemory(IN HANDLE ProcessHandle,
ObDereferenceObject(Process);
return(STATUS_SUCCESS);
case MEM_DECOMMIT:
case MEM_DECOMMIT:
Status = MmComplexVirtualMemoryOperation(AddressSpace,
MemoryArea,
BaseAddress,
@ -1171,11 +1185,12 @@ MmChangeAreaProtection(PEPROCESS Process,
}
NTSTATUS STDCALL NtProtectVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID BaseAddress,
IN ULONG NumberOfBytesToProtect,
IN ULONG NewAccessProtection,
OUT PULONG OldAccessProtection)
NTSTATUS STDCALL
NtProtectVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID BaseAddress,
IN ULONG NumberOfBytesToProtect,
IN ULONG NewAccessProtection,
OUT PULONG OldAccessProtection)
{
PMEMORY_AREA MemoryArea;
PEPROCESS Process;
@ -1206,13 +1221,13 @@ NTSTATUS STDCALL NtProtectVirtualMemory(IN HANDLE ProcessHandle,
ObDereferenceObject(Process);
return(STATUS_UNSUCCESSFUL);
}
#if 0
*OldAccessProtection = MemoryArea->Attributes;
if (MemoryArea->BaseAddress == BaseAddress &&
MemoryArea->Length == NumberOfBytesToProtect)
{
MemoryArea->Attributes = NewAccessProtection;
MemoryArea->Attributes = NewAccessProtection;
}
else
{
@ -1228,6 +1243,7 @@ NTSTATUS STDCALL NtProtectVirtualMemory(IN HANDLE ProcessHandle,
BaseAddress,
NumberOfBytesToProtect,
NewAccessProtection);
#endif
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
return(STATUS_SUCCESS);