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,
WINBOOL STDCALL
CallNamedPipeA(LPCSTR lpNamedPipeName,
LPVOID lpInBuffer,
DWORD nInBufferSize,
LPVOID lpOutBuffer,
DWORD nOutBufferSize,
LPDWORD lpBytesRead,
DWORD nTimeOut
)
DWORD nTimeOut)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
@ -425,15 +448,13 @@ CallNamedPipeA (
WINBOOL STDCALL
CallNamedPipeW (
LPCWSTR lpNamedPipeName,
CallNamedPipeW(LPCWSTR lpNamedPipeName,
LPVOID lpInBuffer,
DWORD nInBufferSize,
LPVOID lpOutBuffer,
DWORD nOutBufferSize,
LPDWORD lpBytesRead,
DWORD nTimeOut
)
DWORD nTimeOut)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
@ -478,15 +499,13 @@ DisconnectNamedPipe(HANDLE hNamedPipe)
WINBOOL STDCALL
GetNamedPipeHandleStateW (
HANDLE hNamedPipe,
GetNamedPipeHandleStateW(HANDLE hNamedPipe,
LPDWORD lpState,
LPDWORD lpCurInstances,
LPDWORD lpMaxCollectionCount,
LPDWORD lpCollectDataTimeout,
LPWSTR lpUserName,
DWORD nMaxUserNameSize
)
DWORD nMaxUserNameSize)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
@ -494,15 +513,13 @@ GetNamedPipeHandleStateW (
WINBOOL STDCALL
GetNamedPipeHandleStateA (
HANDLE hNamedPipe,
GetNamedPipeHandleStateA(HANDLE hNamedPipe,
LPDWORD lpState,
LPDWORD lpCurInstances,
LPDWORD lpMaxCollectionCount,
LPDWORD lpCollectDataTimeout,
LPSTR lpUserName,
DWORD nMaxUserNameSize
)
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,7 +15,8 @@
/* FUNCTIONS *****************************************************************/
LPVOID STDCALL VirtualAllocEx(HANDLE hProcess,
LPVOID STDCALL
VirtualAllocEx(HANDLE hProcess,
LPVOID lpAddress,
DWORD dwSize,
DWORD flAllocationType,
@ -23,7 +24,7 @@ LPVOID STDCALL VirtualAllocEx(HANDLE hProcess,
{
NTSTATUS Status;
Status = ZwAllocateVirtualMemory(hProcess,
Status = NtAllocateVirtualMemory(hProcess,
(PVOID *)&lpAddress,
0,
(PULONG)&dwSize,
@ -37,23 +38,30 @@ LPVOID STDCALL VirtualAllocEx(HANDLE hProcess,
return(lpAddress);
}
LPVOID STDCALL VirtualAlloc(LPVOID lpAddress,
LPVOID STDCALL
VirtualAlloc(LPVOID lpAddress,
DWORD dwSize,
DWORD flAllocationType,
DWORD flProtect)
{
return(VirtualAllocEx(GetCurrentProcess(),lpAddress,dwSize,flAllocationType,
return(VirtualAllocEx(GetCurrentProcess(),
lpAddress,
dwSize,
flAllocationType,
flProtect));
}
WINBOOL STDCALL VirtualFreeEx(HANDLE hProcess,
WINBOOL STDCALL
VirtualFreeEx(HANDLE hProcess,
LPVOID lpAddress,
DWORD dwSize,
DWORD dwFreeType)
{
NTSTATUS Status;
Status = ZwFreeVirtualMemory(hProcess,
Status = NtFreeVirtualMemory(hProcess,
(PVOID *)&lpAddress,
(PULONG)&dwSize,
dwFreeType);
@ -65,12 +73,21 @@ WINBOOL STDCALL VirtualFreeEx(HANDLE hProcess,
return(TRUE);
}
WINBOOL STDCALL VirtualFree(LPVOID lpAddress, DWORD dwSize, DWORD dwFreeType)
WINBOOL STDCALL
VirtualFree(LPVOID lpAddress,
DWORD dwSize,
DWORD dwFreeType)
{
return(VirtualFreeEx(GetCurrentProcess(),lpAddress,dwSize,dwFreeType));
return(VirtualFreeEx(GetCurrentProcess(),
lpAddress,
dwSize,
dwFreeType));
}
WINBOOL STDCALL VirtualProtect(LPVOID lpAddress,
WINBOOL STDCALL
VirtualProtect(LPVOID lpAddress,
DWORD dwSize,
DWORD flNewProtect,
PDWORD lpflOldProtect)
@ -83,7 +100,8 @@ WINBOOL STDCALL VirtualProtect(LPVOID lpAddress,
}
WINBOOL STDCALL VirtualProtectEx(HANDLE hProcess,
WINBOOL STDCALL
VirtualProtectEx(HANDLE hProcess,
LPVOID lpAddress,
DWORD dwSize,
DWORD flNewProtect,
@ -91,12 +109,12 @@ WINBOOL STDCALL VirtualProtectEx(HANDLE hProcess,
{
NTSTATUS Status;
Status = ZwProtectVirtualMemory(hProcess,
Status = NtProtectVirtualMemory(hProcess,
(PVOID)lpAddress,
dwSize,
flNewProtect,
(PULONG)lpflOldProtect);
if (Status != STATUS_SUCCESS)
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return(FALSE);
@ -105,80 +123,79 @@ WINBOOL STDCALL VirtualProtectEx(HANDLE hProcess,
}
WINBOOL
STDCALL
VirtualLock (
LPVOID lpAddress,
DWORD dwSize
)
WINBOOL STDCALL
VirtualLock(LPVOID lpAddress,
DWORD dwSize)
{
ULONG BytesLocked;
NTSTATUS Status;
Status = NtLockVirtualMemory(NtCurrentProcess(),lpAddress,dwSize, &BytesLocked);
Status = NtLockVirtualMemory(NtCurrentProcess(),
lpAddress,
dwSize,
&BytesLocked);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return FALSE;
return(FALSE);
}
return TRUE;
return(TRUE);
}
DWORD
STDCALL
VirtualQuery (
LPCVOID lpAddress,
DWORD STDCALL
VirtualQuery(LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength
)
DWORD dwLength)
{
return VirtualQueryEx (NtCurrentProcess(),lpAddress, lpBuffer, dwLength );
return(VirtualQueryEx(NtCurrentProcess(),
lpAddress,
lpBuffer,
dwLength));
}
#define MemoryBasicInformation 0
DWORD
STDCALL
VirtualQueryEx (
HANDLE hProcess,
DWORD STDCALL
VirtualQueryEx(HANDLE hProcess,
LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength
)
DWORD dwLength)
{
NTSTATUS Status;
ULONG ResultLength;
Status = NtQueryVirtualMemory(
hProcess,(LPVOID)lpAddress,
MemoryBasicInformation, lpBuffer,
Status = NtQueryVirtualMemory(hProcess,
(LPVOID)lpAddress,
MemoryBasicInformation,
lpBuffer,
sizeof(MEMORY_BASIC_INFORMATION),
&ResultLength );
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return ResultLength;
return(ResultLength);
}
return ResultLength;
return(ResultLength);
}
WINBOOL
STDCALL
VirtualUnlock (
LPVOID lpAddress,
DWORD dwSize
)
WINBOOL STDCALL
VirtualUnlock(LPVOID lpAddress,
DWORD dwSize)
{
ULONG BytesLocked;
NTSTATUS Status;
Status = NtUnlockVirtualMemory(NtCurrentProcess(),lpAddress,dwSize, &BytesLocked);
Status = NtUnlockVirtualMemory(NtCurrentProcess(),
lpAddress,
dwSize,
&BytesLocked);
if (!NT_SUCCESS(Status))
{
SetLastErrorByStatus(Status);
return FALSE;
return(FALSE);
}
return TRUE;
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 */
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 */
) {
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,7 +17,8 @@
/* FUNCTIONS ***************************************************************/
NTSTATUS STDCALL RtlCreateSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
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,7 +90,8 @@ ULONG STDCALL RtlLengthSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescript
return(Length);
}
NTSTATUS STDCALL RtlGetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
NTSTATUS STDCALL
RtlGetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PBOOLEAN DaclPresent,
PACL* Dacl,
PBOOLEAN DaclDefaulted)
@ -130,7 +133,8 @@ NTSTATUS STDCALL RtlGetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDesc
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL RtlSetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
NTSTATUS STDCALL
RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
BOOLEAN DaclPresent,
PACL Dacl,
BOOLEAN DaclDefaulted)
@ -158,12 +162,14 @@ 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,
NTSTATUS STDCALL
RtlSetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID Owner,
BOOLEAN OwnerDefaulted)
{
@ -184,7 +190,8 @@ NTSTATUS STDCALL RtlSetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL RtlGetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
NTSTATUS STDCALL
RtlGetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID* Owner,
PBOOLEAN OwnerDefaulted)
{
@ -219,7 +226,8 @@ NTSTATUS STDCALL RtlGetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL RtlSetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
NTSTATUS STDCALL
RtlSetGroupSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID Group,
BOOLEAN GroupDefaulted)
{
@ -240,7 +248,8 @@ NTSTATUS STDCALL RtlSetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL RtlGetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor,
NTSTATUS STDCALL
RtlGetGroupSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID* Group,
PBOOLEAN GroupDefaulted)
{
@ -275,55 +284,45 @@ NTSTATUS STDCALL RtlGetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS);
}
NTSTATUS
STDCALL
RtlMakeSelfRelativeSD (
PSECURITY_DESCRIPTOR AbsSD,
NTSTATUS STDCALL
RtlMakeSelfRelativeSD(PSECURITY_DESCRIPTOR AbsSD,
PSECURITY_DESCRIPTOR RelSD,
PULONG BufferLength
)
PULONG BufferLength)
{
UNIMPLEMENTED;
}
NTSTATUS
STDCALL
RtlAbsoluteToSelfRelativeSD (
PSECURITY_DESCRIPTOR AbsSD,
NTSTATUS STDCALL
RtlAbsoluteToSelfRelativeSD(PSECURITY_DESCRIPTOR AbsSD,
PSECURITY_DESCRIPTOR RelSD,
PULONG BufferLength
)
{
if (AbsSD->Control & SE_SELF_RELATIVE)
{
return STATUS_BAD_DESCRIPTOR_FORMAT;
return(STATUS_BAD_DESCRIPTOR_FORMAT);
}
return(RtlMakeSelfRelativeSD (AbsSD, RelSD, BufferLength));
}
NTSTATUS
STDCALL
RtlGetControlSecurityDescriptor (
PSECURITY_DESCRIPTOR SecurityDescriptor,
NTSTATUS STDCALL
RtlGetControlSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSECURITY_DESCRIPTOR_CONTROL Control,
PULONG Revision
)
PULONG Revision)
{
*Revision = SecurityDescriptor->Revision;
if (SecurityDescriptor->Revision != 1)
return STATUS_UNKNOWN_REVISION;
return(STATUS_UNKNOWN_REVISION);
*Control = SecurityDescriptor->Control;
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
NTSTATUS
STDCALL
RtlGetSaclSecurityDescriptor (
PSECURITY_DESCRIPTOR SecurityDescriptor,
NTSTATUS STDCALL
RtlGetSaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PBOOLEAN SaclPresent,
PACL *Sacl,
PBOOLEAN SaclDefaulted)
@ -365,14 +364,11 @@ RtlGetSaclSecurityDescriptor (
return(STATUS_SUCCESS);
}
NTSTATUS
STDCALL
RtlSetSaclSecurityDescriptor (
PSECURITY_DESCRIPTOR SecurityDescriptor,
NTSTATUS STDCALL
RtlSetSaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
BOOLEAN SaclPresent,
PACL Sacl,
BOOLEAN SaclDefaulted
)
BOOLEAN SaclDefaulted)
{
if (SecurityDescriptor->Revision != 1)
{
@ -397,10 +393,8 @@ RtlSetSaclSecurityDescriptor (
return(STATUS_SUCCESS);
}
NTSTATUS
STDCALL
RtlSelfRelativeToAbsoluteSD (
PSECURITY_DESCRIPTOR RelSD,
NTSTATUS STDCALL
RtlSelfRelativeToAbsoluteSD(PSECURITY_DESCRIPTOR RelSD,
PSECURITY_DESCRIPTOR AbsSD,
PDWORD AbsSDSize,
PACL Dacl,
@ -410,8 +404,7 @@ RtlSelfRelativeToAbsoluteSD (
PSID Owner,
PDWORD OwnerSize,
PSID Group,
PDWORD GroupSize
)
PDWORD GroupSize)
{
UNIMPLEMENTED;
}

View file

@ -44,16 +44,20 @@ RtlCreateUserThread(HANDLE ProcessHandle,
NTSTATUS Status;
/* initialize initial teb */
if ((StackCommit != NULL) && (*StackCommit > PAGESIZE))
InitialTeb.StackCommit = *StackCommit;
else
InitialTeb.StackCommit = PAGESIZE;
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;
@ -63,12 +67,12 @@ RtlCreateUserThread(HANDLE ProcessHandle,
&InitialTeb.StackAllocate,
0,
&InitialTeb.StackReserve,
MEM_COMMIT, //MEM_RESERVE,
MEM_RESERVE,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DPRINT("Error reserving stack space!\n");
return Status;
return(Status);
}
DPRINT("StackAllocate: %p ReserveSize: 0x%lX\n",
@ -79,7 +83,7 @@ RtlCreateUserThread(HANDLE ProcessHandle,
DPRINT("StackBase: %p StackCommit: 0x%lX\n",
InitialTeb.StackBase, InitialTeb.StackCommit);
#if 0
/* Commit stack */
Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackLimit,
@ -96,7 +100,7 @@ RtlCreateUserThread(HANDLE ProcessHandle,
MEM_RELEASE);
DPRINT("Error comitting stack page!\n");
return Status;
return(Status);
}
DPRINT("StackLimit: %p\nStackCommit: 0x%lX\n",
@ -120,7 +124,7 @@ RtlCreateUserThread(HANDLE ProcessHandle,
DPRINT("Error protecting guard page!\n");
return(Status);
}
#endif
/* initialize thread context */
RtlInitializeContext(ProcessHandle,
&ThreadContext,
@ -144,7 +148,6 @@ RtlCreateUserThread(HANDLE ProcessHandle,
&ThreadContext,
&InitialTeb,
CreateSuspended);
if (!NT_SUCCESS(Status))
{
/* release the stack space */
@ -154,7 +157,7 @@ RtlCreateUserThread(HANDLE ProcessHandle,
MEM_RELEASE);
DPRINT("Error creating thread!\n");
return Status;
return(Status);
}
/* return committed stack size */

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,7 +228,6 @@ NTSTATUS LdrLoadInitialProcess (VOID)
DPRINT("Error protecting guard page!\n");
return(Status);
}
#endif
DPRINT("Attaching to process\n");
KeAttachProcess(Process);
@ -276,7 +278,7 @@ NTSTATUS LdrLoadInitialProcess (VOID)
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
return Status;
return(Status);
}
DPRINT("Attaching to process\n");
@ -288,7 +290,7 @@ NTSTATUS LdrLoadInitialProcess (VOID)
Peb->ImageBaseAddress);
KeDetachProcess();
return STATUS_SUCCESS;
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
*/
@ -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)
@ -942,7 +949,8 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
}
}
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);
ObDereferenceObject(Process);
DPRINT("NtAllocateVirtualMemory() = %x\n",Status);
return(Status);
}
@ -976,7 +984,6 @@ 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)))
@ -986,6 +993,7 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
*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;
@ -1025,16 +1035,20 @@ MmFreeVirtualMemoryPage(PVOID Context, PVOID Address, ULONG PhysicalAddr)
}
VOID
MmFreeVirtualMemory(PEPROCESS Process, PMEMORY_AREA MemoryArea)
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);
}
@ -1171,7 +1185,8 @@ MmChangeAreaProtection(PEPROCESS Process,
}
NTSTATUS STDCALL NtProtectVirtualMemory(IN HANDLE ProcessHandle,
NTSTATUS STDCALL
NtProtectVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID BaseAddress,
IN ULONG NumberOfBytesToProtect,
IN ULONG NewAccessProtection,
@ -1206,7 +1221,7 @@ NTSTATUS STDCALL NtProtectVirtualMemory(IN HANDLE ProcessHandle,
ObDereferenceObject(Process);
return(STATUS_UNSUCCESSFUL);
}
#if 0
*OldAccessProtection = MemoryArea->Attributes;
if (MemoryArea->BaseAddress == BaseAddress &&
@ -1228,6 +1243,7 @@ NTSTATUS STDCALL NtProtectVirtualMemory(IN HANDLE ProcessHandle,
BaseAddress,
NumberOfBytesToProtect,
NewAccessProtection);
#endif
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
return(STATUS_SUCCESS);