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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -125,7 +125,7 @@ CopyFileExW (
(PVOID *)&lpBuffer, (PVOID *)&lpBuffer,
2, 2,
&RegionSize, &RegionSize,
MEM_COMMIT, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(errCode)) 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -13,11 +13,13 @@
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <ntdll/rtl.h> #include <ntdll/rtl.h>
#include <windows.h> #include <windows.h>
#include <kernel32/error.h>
//#include <wchar.h> //#include <wchar.h>
//#include <string.h> //#include <string.h>
#include <limits.h>
//#define NDEBUG
#include <kernel32/kernel32.h> #include <kernel32/kernel32.h>
#include <kernel32/error.h>
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
@ -52,6 +54,7 @@ CreateNamedPipeA(LPCSTR lpName,
return(NamedPipeHandle); return(NamedPipeHandle);
} }
HANDLE STDCALL HANDLE STDCALL
CreateNamedPipeW(LPCWSTR lpName, CreateNamedPipeW(LPCWSTR lpName,
DWORD dwOpenMode, DWORD dwOpenMode,
@ -88,6 +91,7 @@ CreateNamedPipeW(LPCWSTR lpName,
} }
DPRINT("Pipe name: %wZ\n", &NamedPipeName); DPRINT("Pipe name: %wZ\n", &NamedPipeName);
DPRINT("Pipe name: %S\n", NamedPipeName.Buffer);
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
&NamedPipeName, &NamedPipeName,
@ -110,6 +114,18 @@ CreateNamedPipeW(LPCWSTR lpName,
{ {
CreateOptions = CreateOptions | FILE_SYNCHRONOUS_IO_ALERT; 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) if (dwPipeMode & PIPE_TYPE_BYTE)
{ {
@ -150,6 +166,11 @@ CreateNamedPipeW(LPCWSTR lpName,
NonBlocking = FALSE; NonBlocking = FALSE;
} }
if (nMaxInstances >= PIPE_UNLIMITED_INSTANCES)
{
nMaxInstances = ULONG_MAX;
}
DefaultTimeOut.QuadPart = nDefaultTimeOut * 10000; DefaultTimeOut.QuadPart = nDefaultTimeOut * 10000;
Status = NtCreateNamedPipeFile(&PipeHandle, Status = NtCreateNamedPipeFile(&PipeHandle,
@ -179,6 +200,7 @@ CreateNamedPipeW(LPCWSTR lpName,
return(PipeHandle); return(PipeHandle);
} }
BOOL STDCALL BOOL STDCALL
WaitNamedPipeA(LPCSTR lpNamedPipeName, WaitNamedPipeA(LPCSTR lpNamedPipeName,
DWORD nTimeOut) DWORD nTimeOut)
@ -197,6 +219,7 @@ WaitNamedPipeA(LPCSTR lpNamedPipeName,
return(r); return(r);
} }
BOOL STDCALL BOOL STDCALL
WaitNamedPipeW(LPCWSTR lpNamedPipeName, WaitNamedPipeW(LPCWSTR lpNamedPipeName,
DWORD nTimeOut) DWORD nTimeOut)
@ -260,6 +283,7 @@ WaitNamedPipeW(LPCWSTR lpNamedPipeName,
return(TRUE); return(TRUE);
} }
BOOL STDCALL BOOL STDCALL
ConnectNamedPipe(HANDLE hNamedPipe, ConnectNamedPipe(HANDLE hNamedPipe,
LPOVERLAPPED lpOverlapped) LPOVERLAPPED lpOverlapped)
@ -311,6 +335,7 @@ ConnectNamedPipe(HANDLE hNamedPipe,
return(TRUE); return(TRUE);
} }
BOOL STDCALL BOOL STDCALL
SetNamedPipeHandleState(HANDLE hNamedPipe, SetNamedPipeHandleState(HANDLE hNamedPipe,
LPDWORD lpMode, LPDWORD lpMode,
@ -407,17 +432,15 @@ SetNamedPipeHandleState(HANDLE hNamedPipe,
return(TRUE); return(TRUE);
} }
WINBOOL
STDCALL WINBOOL STDCALL
CallNamedPipeA ( CallNamedPipeA(LPCSTR lpNamedPipeName,
LPCSTR lpNamedPipeName, LPVOID lpInBuffer,
LPVOID lpInBuffer, DWORD nInBufferSize,
DWORD nInBufferSize, LPVOID lpOutBuffer,
LPVOID lpOutBuffer, DWORD nOutBufferSize,
DWORD nOutBufferSize, LPDWORD lpBytesRead,
LPDWORD lpBytesRead, DWORD nTimeOut)
DWORD nTimeOut
)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE; return FALSE;
@ -425,15 +448,13 @@ CallNamedPipeA (
WINBOOL STDCALL WINBOOL STDCALL
CallNamedPipeW ( CallNamedPipeW(LPCWSTR lpNamedPipeName,
LPCWSTR lpNamedPipeName, LPVOID lpInBuffer,
LPVOID lpInBuffer, DWORD nInBufferSize,
DWORD nInBufferSize, LPVOID lpOutBuffer,
LPVOID lpOutBuffer, DWORD nOutBufferSize,
DWORD nOutBufferSize, LPDWORD lpBytesRead,
LPDWORD lpBytesRead, DWORD nTimeOut)
DWORD nTimeOut
)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE; return FALSE;
@ -478,15 +499,13 @@ DisconnectNamedPipe(HANDLE hNamedPipe)
WINBOOL STDCALL WINBOOL STDCALL
GetNamedPipeHandleStateW ( GetNamedPipeHandleStateW(HANDLE hNamedPipe,
HANDLE hNamedPipe, LPDWORD lpState,
LPDWORD lpState, LPDWORD lpCurInstances,
LPDWORD lpCurInstances, LPDWORD lpMaxCollectionCount,
LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
LPDWORD lpCollectDataTimeout, LPWSTR lpUserName,
LPWSTR lpUserName, DWORD nMaxUserNameSize)
DWORD nMaxUserNameSize
)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE; return FALSE;
@ -494,15 +513,13 @@ GetNamedPipeHandleStateW (
WINBOOL STDCALL WINBOOL STDCALL
GetNamedPipeHandleStateA ( GetNamedPipeHandleStateA(HANDLE hNamedPipe,
HANDLE hNamedPipe, LPDWORD lpState,
LPDWORD lpState, LPDWORD lpCurInstances,
LPDWORD lpCurInstances, LPDWORD lpMaxCollectionCount,
LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
LPDWORD lpCollectDataTimeout, LPSTR lpUserName,
LPSTR lpUserName, DWORD nMaxUserNameSize)
DWORD nMaxUserNameSize
)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE; return FALSE;
@ -516,8 +533,42 @@ GetNamedPipeInfo(HANDLE hNamedPipe,
LPDWORD lpInBufferSize, LPDWORD lpInBufferSize,
LPDWORD lpMaxInstances) LPDWORD lpMaxInstances)
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); FILE_PIPE_LOCAL_INFORMATION PipeLocalInformation;
return FALSE; 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -15,170 +15,187 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
LPVOID STDCALL VirtualAllocEx(HANDLE hProcess, LPVOID STDCALL
LPVOID lpAddress, VirtualAllocEx(HANDLE hProcess,
DWORD dwSize, LPVOID lpAddress,
DWORD flAllocationType, DWORD dwSize,
DWORD flProtect) DWORD flAllocationType,
DWORD flProtect)
{ {
NTSTATUS Status; NTSTATUS Status;
Status = ZwAllocateVirtualMemory(hProcess, Status = NtAllocateVirtualMemory(hProcess,
(PVOID *)&lpAddress, (PVOID *)&lpAddress,
0, 0,
(PULONG)&dwSize, (PULONG)&dwSize,
flAllocationType, flAllocationType,
flProtect); flProtect);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
SetLastErrorByStatus (Status); SetLastErrorByStatus(Status);
return(NULL); return(NULL);
} }
return(lpAddress); return(lpAddress);
}
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));
} }
WINBOOL STDCALL VirtualProtectEx(HANDLE hProcess, LPVOID STDCALL
LPVOID lpAddress, VirtualAlloc(LPVOID lpAddress,
DWORD dwSize, DWORD dwSize,
DWORD flNewProtect, DWORD flAllocationType,
PDWORD lpflOldProtect) DWORD flProtect)
{ {
NTSTATUS Status; return(VirtualAllocEx(GetCurrentProcess(),
lpAddress,
Status = ZwProtectVirtualMemory(hProcess, dwSize,
(PVOID)lpAddress, flAllocationType,
dwSize, flProtect));
flNewProtect,
(PULONG)lpflOldProtect);
if (Status != STATUS_SUCCESS)
{
SetLastErrorByStatus (Status);
return(FALSE);
}
return(TRUE);
} }
WINBOOL WINBOOL STDCALL
STDCALL VirtualFreeEx(HANDLE hProcess,
VirtualLock ( LPVOID lpAddress,
LPVOID lpAddress, DWORD dwSize,
DWORD dwSize DWORD dwFreeType)
)
{ {
ULONG BytesLocked; NTSTATUS Status;
NTSTATUS Status;
Status = NtLockVirtualMemory(NtCurrentProcess(),lpAddress,dwSize, &BytesLocked); Status = NtFreeVirtualMemory(hProcess,
if (!NT_SUCCESS(Status)) (PVOID *)&lpAddress,
{ (PULONG)&dwSize,
SetLastErrorByStatus (Status); dwFreeType);
return FALSE; if (!NT_SUCCESS(Status))
} {
return TRUE; SetLastErrorByStatus(Status);
return(FALSE);
}
return(TRUE);
} }
DWORD WINBOOL STDCALL
STDCALL VirtualFree(LPVOID lpAddress,
VirtualQuery ( DWORD dwSize,
LPCVOID lpAddress, DWORD dwFreeType)
PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength
)
{ {
return VirtualQueryEx (NtCurrentProcess(),lpAddress, lpBuffer, dwLength ); return(VirtualFreeEx(GetCurrentProcess(),
} lpAddress,
dwSize,
#define MemoryBasicInformation 0 dwFreeType));
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 WINBOOL STDCALL
STDCALL VirtualProtect(LPVOID lpAddress,
VirtualUnlock ( DWORD dwSize,
LPVOID lpAddress, DWORD flNewProtect,
DWORD dwSize PDWORD lpflOldProtect)
)
{ {
ULONG BytesLocked; return(VirtualProtectEx(GetCurrentProcess(),
NTSTATUS Status; lpAddress,
Status = NtUnlockVirtualMemory(NtCurrentProcess(),lpAddress,dwSize, &BytesLocked); dwSize,
if (!NT_SUCCESS(Status)) flNewProtect,
{ lpflOldProtect));
SetLastErrorByStatus (Status); }
return FALSE;
}
return TRUE; 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 */ /* 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -157,8 +157,12 @@ KlCreateFirstThread(HANDLE ProcessHandle,
else else
CreateSuspended = FALSE; CreateSuspended = FALSE;
InitialTeb.StackCommit = (StackCommit < PAGESIZE) ? PAGESIZE : StackCommit;
InitialTeb.StackReserve = (StackReserve < 0x100000) ? 0x100000 : StackReserve; 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 */ /* size of guard page */
InitialTeb.StackCommit += PAGESIZE; InitialTeb.StackCommit += PAGESIZE;
@ -169,7 +173,7 @@ KlCreateFirstThread(HANDLE ProcessHandle,
&InitialTeb.StackAllocate, &InitialTeb.StackAllocate,
0, 0,
&InitialTeb.StackReserve, &InitialTeb.StackReserve,
MEM_COMMIT, // MEM_RESERVE, MEM_RESERVE,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -186,7 +190,7 @@ KlCreateFirstThread(HANDLE ProcessHandle,
DPRINT("StackBase: %p\nStackCommit: %p\n", DPRINT("StackBase: %p\nStackCommit: %p\n",
InitialTeb.StackBase, InitialTeb.StackCommit); InitialTeb.StackBase, InitialTeb.StackCommit);
#if 0
/* Commit stack page(s) */ /* Commit stack page(s) */
Status = NtAllocateVirtualMemory(ProcessHandle, Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackLimit, &InitialTeb.StackLimit,
@ -228,7 +232,6 @@ KlCreateFirstThread(HANDLE ProcessHandle,
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
return(NULL); return(NULL);
} }
#endif
memset(&ThreadContext,0,sizeof(CONTEXT)); memset(&ThreadContext,0,sizeof(CONTEXT));
ThreadContext.Eip = (ULONG)lpStartAddress; ThreadContext.Eip = (ULONG)lpStartAddress;
@ -384,7 +387,7 @@ KlInitPeb (HANDLE ProcessHandle,
&EnvPtr, &EnvPtr,
0, 0,
&EnvSize, &EnvSize,
MEM_COMMIT, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -405,7 +408,7 @@ KlInitPeb (HANDLE ProcessHandle,
&PpbBase, &PpbBase,
0, 0,
&PpbSize, &PpbSize,
MEM_COMMIT, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -141,8 +141,12 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
else else
CreateSuspended = FALSE; CreateSuspended = FALSE;
InitialTeb.StackCommit = (dwStackSize == 0) ? PAGESIZE : dwStackSize;
InitialTeb.StackReserve = 0x100000; /* 1MByte */ 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 */ /* size of guard page */
InitialTeb.StackCommit += PAGESIZE; InitialTeb.StackCommit += PAGESIZE;
@ -153,7 +157,7 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
&InitialTeb.StackAllocate, &InitialTeb.StackAllocate,
0, 0,
&InitialTeb.StackReserve, &InitialTeb.StackReserve,
MEM_COMMIT, //MEM_RESERVE, MEM_RESERVE,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -171,7 +175,7 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
DPRINT("StackBase: %p\nStackCommit: 0x%lX\n", DPRINT("StackBase: %p\nStackCommit: 0x%lX\n",
InitialTeb.StackBase, InitialTeb.StackBase,
InitialTeb.StackCommit); InitialTeb.StackCommit);
#if 0
/* Commit stack pages */ /* Commit stack pages */
Status = NtAllocateVirtualMemory(hProcess, Status = NtAllocateVirtualMemory(hProcess,
&InitialTeb.StackLimit, &InitialTeb.StackLimit,
@ -213,7 +217,6 @@ HANDLE STDCALL CreateRemoteThread(HANDLE hProcess,
SetLastErrorByStatus(Status); SetLastErrorByStatus(Status);
return(NULL); return(NULL);
} }
#endif
memset(&ThreadContext,0,sizeof(CONTEXT)); memset(&ThreadContext,0,sizeof(CONTEXT));
ThreadContext.Eip = (LONG)ThreadStartup; 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -55,7 +55,7 @@ RtlCreateEnvironment(BOOLEAN Inherit,
&EnvPtr, &EnvPtr,
0, 0,
&RegionSize, &RegionSize,
MEM_COMMIT, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -79,7 +79,7 @@ RtlCreateEnvironment(BOOLEAN Inherit,
&EnvPtr, &EnvPtr,
0, 0,
&RegionSize, &RegionSize,
MEM_COMMIT, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
@ -322,7 +322,7 @@ found:
(VOID**)&new_env, (VOID**)&new_env,
0, 0,
&new_size, &new_size,
MEM_COMMIT, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -71,7 +71,7 @@ RtlAllocateHandle(PRTL_HANDLE_TABLE HandleTable,
(PVOID*)&ArrayPointer, (PVOID*)&ArrayPointer,
0, 0,
&ArraySize, &ArraySize,
MEM_COMMIT, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
return NULL; return NULL;

View file

@ -95,7 +95,7 @@ typedef struct tagSUBHEAP
struct tagHEAP *heap; /* Main heap structure */ struct tagHEAP *heap; /* Main heap structure */
DWORD magic; /* Magic number */ DWORD magic; /* Magic number */
WORD selector; /* Selector for HEAP_WINE_SEGPTR heaps */ WORD selector; /* Selector for HEAP_WINE_SEGPTR heaps */
} SUBHEAP; } SUBHEAP, *PSUBHEAP;
#define SUBHEAP_MAGIC ((DWORD)('S' | ('U'<<8) | ('B'<<16) | ('H'<<24))) #define SUBHEAP_MAGIC ((DWORD)('S' | ('U'<<8) | ('B'<<16) | ('H'<<24)))
@ -108,7 +108,7 @@ typedef struct tagHEAP
DWORD flags; /* Heap flags */ DWORD flags; /* Heap flags */
DWORD magic; /* Magic number */ DWORD magic; /* Magic number */
void *private; /* Private pointer for the user of the heap */ void *private; /* Private pointer for the user of the heap */
} HEAP; } HEAP, *PHEAP;
#define HEAP_MAGIC ((DWORD)('H' | ('E'<<8) | ('A'<<16) | ('P'<<24))) #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 * HEAP_Dump
*/ */
void HEAP_Dump( HEAP *heap ) void
HEAP_Dump(PHEAP heap)
{ {
int i; int i;
SUBHEAP *subheap; SUBHEAP *subheap;
@ -213,9 +214,9 @@ void HEAP_Dump( HEAP *heap )
* Pointer to the heap * Pointer to the heap
* NULL: Failure * NULL: Failure
*/ */
static HEAP *HEAP_GetPtr( static PHEAP
HANDLE heap /* [in] Handle to the heap */ HEAP_GetPtr(HANDLE heap) /* [in] Handle to the heap */
) { {
HEAP *heapPtr = (HEAP *)heap; HEAP *heapPtr = (HEAP *)heap;
if (!heapPtr || (heapPtr->magic != HEAP_MAGIC)) if (!heapPtr || (heapPtr->magic != HEAP_MAGIC))
{ {
@ -237,7 +238,9 @@ static HEAP *HEAP_GetPtr(
* *
* Insert a free block into the free list. * 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; FREE_LIST_ENTRY *pEntry = heap->freeList;
while (pEntry->size < pArena->size) pEntry++; while (pEntry->size < pArena->size) pEntry++;
@ -257,10 +260,10 @@ static void HEAP_InsertFreeBlock( HEAP *heap, ARENA_FREE *pArena )
* Pointer: Success * Pointer: Success
* NULL: Failure * NULL: Failure
*/ */
static SUBHEAP *HEAP_FindSubHeap( static PSUBHEAP
HEAP *heap, /* [in] Heap pointer */ HEAP_FindSubHeap(HEAP *heap, /* [in] Heap pointer */
LPCVOID ptr /* [in] Address */ LPCVOID ptr) /* [in] Address */
) { {
SUBHEAP *sub = &heap->subheap; SUBHEAP *sub = &heap->subheap;
while (sub) while (sub)
{ {
@ -277,7 +280,9 @@ static SUBHEAP *HEAP_FindSubHeap(
* *
* Make sure the heap storage is committed up to (not including) ptr. * 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); DWORD size = (DWORD)((char *)ptr - (char *)subheap);
NTSTATUS Status; NTSTATUS Status;
@ -291,7 +296,7 @@ static inline BOOL HEAP_Commit( SUBHEAP *subheap, void *ptr )
address = (PVOID)((char *)subheap + subheap->commitSize); address = (PVOID)((char *)subheap + subheap->commitSize);
commitsize = size - subheap->commitSize; commitsize = size - subheap->commitSize;
Status = ZwAllocateVirtualMemory(NtCurrentProcess(), Status = NtAllocateVirtualMemory(NtCurrentProcess(),
&address, &address,
0, 0,
&commitsize, &commitsize,
@ -586,7 +591,7 @@ static SUBHEAP *HEAP_CreateSubHeap(PVOID BaseAddress,
&address, &address,
0, 0,
(PULONG)&totalSize, (PULONG)&totalSize,
MEM_RESERVE, MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE); PAGE_EXECUTE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -1011,7 +1016,8 @@ RtlCreateHeap(ULONG flags,
* TRUE: Success * TRUE: Success
* FALSE: Failure * 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 ); HEAP *heapPtr = HEAP_GetPtr( heap );
SUBHEAP *subheap; SUBHEAP *subheap;
@ -1054,11 +1060,11 @@ BOOL STDCALL RtlDestroyHeap( HANDLE heap /* [in] Handle of heap */ )
* Pointer to allocated memory block * Pointer to allocated memory block
* NULL: Failure * NULL: Failure
*/ */
PVOID STDCALL RtlAllocateHeap( PVOID STDCALL
HANDLE heap, /* [in] Handle of private heap block */ RtlAllocateHeap(HANDLE heap, /* [in] Handle of private heap block */
ULONG flags, /* [in] Heap allocation control flags */ 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_FREE *pArena;
ARENA_INUSE *pInUse; ARENA_INUSE *pInUse;
SUBHEAP *subheap; SUBHEAP *subheap;
@ -1511,76 +1517,9 @@ HW_end:
return ret; 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 #endif
HANDLE STDCALL HANDLE STDCALL
RtlGetProcessHeap(VOID) RtlGetProcessHeap(VOID)
{ {
@ -1664,3 +1603,5 @@ RtlValidateProcessHeaps(VOID)
return Result; 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -146,7 +146,7 @@ RtlCreateProcessParameters(PRTL_USER_PROCESS_PARAMETERS *ProcessParameters,
(PVOID*)&Param, (PVOID*)&Param,
0, 0,
&RegionSize, &RegionSize,
MEM_COMMIT, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -43,23 +43,30 @@ RtlpCreateFirstThread(HANDLE ProcessHandle,
ObjectAttributes.Attributes = 0; ObjectAttributes.Attributes = 0;
ObjectAttributes.SecurityQualityOfService = NULL; ObjectAttributes.SecurityQualityOfService = NULL;
if (StackCommit > PAGESIZE)
InitialTeb.StackCommit = StackCommit;
else
InitialTeb.StackCommit = PAGESIZE;
if (StackReserve > 0x100000) if (StackReserve > 0x100000)
InitialTeb.StackReserve = StackReserve; InitialTeb.StackReserve = StackReserve;
else else
InitialTeb.StackReserve = 0x100000; /* 1MByte */ 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 */ /* Reserve stack */
InitialTeb.StackAllocate = NULL; InitialTeb.StackAllocate = NULL;
Status = NtAllocateVirtualMemory(ProcessHandle, Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackAllocate, &InitialTeb.StackAllocate,
0, 0,
&InitialTeb.StackReserve, &InitialTeb.StackReserve,
MEM_COMMIT, //MEM_RESERVE, MEM_RESERVE,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -71,12 +78,11 @@ RtlpCreateFirstThread(HANDLE ProcessHandle,
InitialTeb.StackAllocate, InitialTeb.StackReserve); InitialTeb.StackAllocate, InitialTeb.StackReserve);
InitialTeb.StackBase = (PVOID)((ULONG)InitialTeb.StackAllocate + InitialTeb.StackReserve); InitialTeb.StackBase = (PVOID)((ULONG)InitialTeb.StackAllocate + InitialTeb.StackReserve);
InitialTeb.StackLimit = (PVOID)((ULONG)InitialTeb.StackBase - InitialTeb.StackCommit - PAGESIZE); InitialTeb.StackLimit = (PVOID)((ULONG)InitialTeb.StackBase - InitialTeb.StackCommit);
InitialTeb.StackCommit += PAGESIZE;
DPRINT("StackBase: %p StackCommit: 0x%lX\n", DPRINT("StackBase: %p StackCommit: 0x%lX\n",
InitialTeb.StackBase, InitialTeb.StackCommit); InitialTeb.StackBase, InitialTeb.StackCommit);
#if 0
/* Commit stack */ /* Commit stack */
Status = NtAllocateVirtualMemory(ProcessHandle, Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackLimit, &InitialTeb.StackLimit,
@ -115,7 +121,7 @@ RtlpCreateFirstThread(HANDLE ProcessHandle,
DPRINT("Error comitting guard page!\n"); DPRINT("Error comitting guard page!\n");
return(Status); return(Status);
} }
#endif
memset(&ThreadContext,0,sizeof(CONTEXT)); memset(&ThreadContext,0,sizeof(CONTEXT));
ThreadContext.Eip = (ULONG)lpStartAddress; ThreadContext.Eip = (ULONG)lpStartAddress;
ThreadContext.SegGs = USER_DS; ThreadContext.SegGs = USER_DS;
@ -281,7 +287,7 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
&EnvPtr, &EnvPtr,
0, 0,
&EnvSize, &EnvSize,
MEM_COMMIT, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -303,7 +309,7 @@ static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
&PpbBase, &PpbBase,
0, 0,
&PpbSize, &PpbSize,
MEM_COMMIT, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -17,8 +17,9 @@
/* FUNCTIONS ***************************************************************/ /* FUNCTIONS ***************************************************************/
NTSTATUS STDCALL RtlCreateSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
ULONG Revision) RtlCreateSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
ULONG Revision)
{ {
if (Revision != 1) if (Revision != 1)
{ {
@ -34,7 +35,8 @@ NTSTATUS STDCALL RtlCreateSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescr
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
ULONG STDCALL RtlLengthSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor) ULONG STDCALL
RtlLengthSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor)
{ {
PSID Owner; PSID Owner;
PSID Group; PSID Group;
@ -88,10 +90,11 @@ ULONG STDCALL RtlLengthSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescript
return(Length); return(Length);
} }
NTSTATUS STDCALL RtlGetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
PBOOLEAN DaclPresent, RtlGetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PACL* Dacl, PBOOLEAN DaclPresent,
PBOOLEAN DaclDefaulted) PACL* Dacl,
PBOOLEAN DaclDefaulted)
{ {
if (SecurityDescriptor->Revision != 1) if (SecurityDescriptor->Revision != 1)
{ {
@ -130,10 +133,11 @@ NTSTATUS STDCALL RtlGetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDesc
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL RtlSetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
BOOLEAN DaclPresent, RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PACL Dacl, BOOLEAN DaclPresent,
BOOLEAN DaclDefaulted) PACL Dacl,
BOOLEAN DaclDefaulted)
{ {
if (SecurityDescriptor->Revision != 1) if (SecurityDescriptor->Revision != 1)
{ {
@ -158,14 +162,16 @@ NTSTATUS STDCALL RtlSetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDesc
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
BOOLEAN STDCALL RtlValidSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor) BOOLEAN STDCALL
RtlValidSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }
NTSTATUS STDCALL RtlSetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
PSID Owner, RtlSetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
BOOLEAN OwnerDefaulted) PSID Owner,
BOOLEAN OwnerDefaulted)
{ {
if (SecurityDescriptor->Revision != 1) if (SecurityDescriptor->Revision != 1)
{ {
@ -184,9 +190,10 @@ NTSTATUS STDCALL RtlSetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL RtlGetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
PSID* Owner, RtlGetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PBOOLEAN OwnerDefaulted) PSID* Owner,
PBOOLEAN OwnerDefaulted)
{ {
if (SecurityDescriptor->Revision != 1) if (SecurityDescriptor->Revision != 1)
{ {
@ -219,9 +226,10 @@ NTSTATUS STDCALL RtlGetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL RtlSetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
PSID Group, RtlSetGroupSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
BOOLEAN GroupDefaulted) PSID Group,
BOOLEAN GroupDefaulted)
{ {
if (SecurityDescriptor->Revision != 1) if (SecurityDescriptor->Revision != 1)
{ {
@ -240,9 +248,10 @@ NTSTATUS STDCALL RtlSetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL RtlGetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
PSID* Group, RtlGetGroupSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PBOOLEAN GroupDefaulted) PSID* Group,
PBOOLEAN GroupDefaulted)
{ {
if (SecurityDescriptor->Revision != 1) if (SecurityDescriptor->Revision != 1)
{ {
@ -275,58 +284,48 @@ NTSTATUS STDCALL RtlGetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlMakeSelfRelativeSD(PSECURITY_DESCRIPTOR AbsSD,
RtlMakeSelfRelativeSD ( PSECURITY_DESCRIPTOR RelSD,
PSECURITY_DESCRIPTOR AbsSD, PULONG BufferLength)
PSECURITY_DESCRIPTOR RelSD,
PULONG BufferLength
)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlAbsoluteToSelfRelativeSD(PSECURITY_DESCRIPTOR AbsSD,
RtlAbsoluteToSelfRelativeSD ( PSECURITY_DESCRIPTOR RelSD,
PSECURITY_DESCRIPTOR AbsSD, PULONG BufferLength
PSECURITY_DESCRIPTOR RelSD,
PULONG BufferLength
) )
{ {
if (AbsSD->Control & SE_SELF_RELATIVE) if (AbsSD->Control & SE_SELF_RELATIVE)
{ {
return STATUS_BAD_DESCRIPTOR_FORMAT; return(STATUS_BAD_DESCRIPTOR_FORMAT);
} }
return (RtlMakeSelfRelativeSD (AbsSD, RelSD, BufferLength)); return(RtlMakeSelfRelativeSD (AbsSD, RelSD, BufferLength));
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlGetControlSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
RtlGetControlSecurityDescriptor ( PSECURITY_DESCRIPTOR_CONTROL Control,
PSECURITY_DESCRIPTOR SecurityDescriptor, PULONG Revision)
PSECURITY_DESCRIPTOR_CONTROL Control,
PULONG Revision
)
{ {
*Revision = SecurityDescriptor->Revision; *Revision = SecurityDescriptor->Revision;
if (SecurityDescriptor->Revision != 1) if (SecurityDescriptor->Revision != 1)
return STATUS_UNKNOWN_REVISION; return(STATUS_UNKNOWN_REVISION);
*Control = SecurityDescriptor->Control; *Control = SecurityDescriptor->Control;
return STATUS_SUCCESS; return(STATUS_SUCCESS);
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlGetSaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
RtlGetSaclSecurityDescriptor ( PBOOLEAN SaclPresent,
PSECURITY_DESCRIPTOR SecurityDescriptor, PACL *Sacl,
PBOOLEAN SaclPresent, PBOOLEAN SaclDefaulted)
PACL *Sacl,
PBOOLEAN SaclDefaulted)
{ {
if (SecurityDescriptor->Revision != 1) if (SecurityDescriptor->Revision != 1)
{ {
@ -365,14 +364,11 @@ RtlGetSaclSecurityDescriptor (
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlSetSaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
RtlSetSaclSecurityDescriptor ( BOOLEAN SaclPresent,
PSECURITY_DESCRIPTOR SecurityDescriptor, PACL Sacl,
BOOLEAN SaclPresent, BOOLEAN SaclDefaulted)
PACL Sacl,
BOOLEAN SaclDefaulted
)
{ {
if (SecurityDescriptor->Revision != 1) if (SecurityDescriptor->Revision != 1)
{ {
@ -397,21 +393,18 @@ RtlSetSaclSecurityDescriptor (
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlSelfRelativeToAbsoluteSD(PSECURITY_DESCRIPTOR RelSD,
RtlSelfRelativeToAbsoluteSD ( PSECURITY_DESCRIPTOR AbsSD,
PSECURITY_DESCRIPTOR RelSD, PDWORD AbsSDSize,
PSECURITY_DESCRIPTOR AbsSD, PACL Dacl,
PDWORD AbsSDSize, PDWORD DaclSize,
PACL Dacl, PACL Sacl,
PDWORD DaclSize, PDWORD SaclSize,
PACL Sacl, PSID Owner,
PDWORD SaclSize, PDWORD OwnerSize,
PSID Owner, PSID Group,
PDWORD OwnerSize, PDWORD GroupSize)
PSID Group,
PDWORD GroupSize
)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }

View file

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

View file

@ -51,6 +51,7 @@ NTSTATUS LdrLoadInitialProcess (VOID)
CONTEXT Context; CONTEXT Context;
HANDLE ThreadHandle; HANDLE ThreadHandle;
INITIAL_TEB InitialTeb; INITIAL_TEB InitialTeb;
ULONG OldPageProtection;
/* /*
* Get the absolute path to smss.exe using the * Get the absolute path to smss.exe using the
@ -153,22 +154,24 @@ NTSTATUS LdrLoadInitialProcess (VOID)
NTHeaders = RtlImageNtHeader(Peb->ImageBaseAddress); NTHeaders = RtlImageNtHeader(Peb->ImageBaseAddress);
DPRINT("NTHeaders %x\n", NTHeaders); DPRINT("NTHeaders %x\n", NTHeaders);
InitialTeb.StackReserve = NTHeaders->OptionalHeader.SizeOfStackReserve; 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 */ /* add guard page size */
InitialTeb.StackCommit += PAGESIZE; InitialTeb.StackCommit += PAGESIZE;
DPRINT("StackReserve 0x%lX StackCommit 0x%lX\n", DPRINT("StackReserve 0x%lX StackCommit 0x%lX\n",
InitialTeb.StackReserve, InitialTeb.StackCommit); InitialTeb.StackReserve, InitialTeb.StackCommit);
KeDetachProcess(); KeDetachProcess();
DPRINT("Dereferencing process\n"); DPRINT("Dereferencing process\n");
// ObDereferenceObject(Process); ObDereferenceObject(Process);
DPRINT("Allocating stack\n"); DPRINT("Allocating stack\n");
InitialTeb.StackAllocate = NULL; InitialTeb.StackAllocate = NULL;
Status = ZwAllocateVirtualMemory(ProcessHandle, Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackAllocate, &InitialTeb.StackAllocate,
0, 0,
&InitialTeb.StackReserve, &InitialTeb.StackReserve,
MEM_COMMIT, // MEM_RESERVE, MEM_RESERVE,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -184,7 +187,7 @@ NTSTATUS LdrLoadInitialProcess (VOID)
DPRINT("StackBase: %p StackCommit: 0x%lX\n", DPRINT("StackBase: %p StackCommit: 0x%lX\n",
InitialTeb.StackBase, InitialTeb.StackCommit); InitialTeb.StackBase, InitialTeb.StackCommit);
#if 0
/* Commit stack */ /* Commit stack */
Status = NtAllocateVirtualMemory(ProcessHandle, Status = NtAllocateVirtualMemory(ProcessHandle,
&InitialTeb.StackLimit, &InitialTeb.StackLimit,
@ -225,45 +228,44 @@ NTSTATUS LdrLoadInitialProcess (VOID)
DPRINT("Error protecting guard page!\n"); DPRINT("Error protecting guard page!\n");
return(Status); return(Status);
} }
#endif
DPRINT("Attaching to process\n"); DPRINT("Attaching to process\n");
KeAttachProcess(Process); KeAttachProcess(Process);
Peb = (PPEB)PEB_BASE; Peb = (PPEB)PEB_BASE;
DPRINT("Peb %x\n", Peb); DPRINT("Peb %x\n", Peb);
DPRINT("CurrentProcess %x Peb->ImageBaseAddress %x\n", DPRINT("CurrentProcess %x Peb->ImageBaseAddress %x\n",
PsGetCurrentProcess(), PsGetCurrentProcess(),
Peb->ImageBaseAddress); Peb->ImageBaseAddress);
KeDetachProcess(); KeDetachProcess();
/* /*
* Initialize context to point to LdrStartup * Initialize context to point to LdrStartup
*/ */
memset(&Context,0,sizeof(CONTEXT)); memset(&Context,0,sizeof(CONTEXT));
Context.Eip = (ULONG)LdrStartupAddr; Context.Eip = (ULONG)LdrStartupAddr;
Context.SegCs = USER_CS; Context.SegCs = USER_CS;
Context.SegDs = USER_DS; Context.SegDs = USER_DS;
Context.SegEs = USER_DS; Context.SegEs = USER_DS;
Context.SegFs = TEB_SELECTOR; Context.SegFs = TEB_SELECTOR;
Context.SegGs = USER_DS; Context.SegGs = USER_DS;
Context.SegSs = USER_DS; Context.SegSs = USER_DS;
Context.EFlags = 0x202; Context.EFlags = 0x202;
Context.Esp = (ULONG)InitialTeb.StackBase - 20; Context.Esp = (ULONG)InitialTeb.StackBase - 20;
DPRINT("LdrStartupAddr %x\n",LdrStartupAddr); DPRINT("LdrStartupAddr %x\n",LdrStartupAddr);
/* /*
* FIXME: Create process and let 'er rip * FIXME: Create process and let 'er rip
*/ */
DPRINT("Creating thread for initial process\n"); DPRINT("Creating thread for initial process\n");
Status = ZwCreateThread(&ThreadHandle, Status = ZwCreateThread(&ThreadHandle,
THREAD_ALL_ACCESS, THREAD_ALL_ACCESS,
NULL, NULL,
ProcessHandle, ProcessHandle,
NULL, NULL,
&Context, &Context,
&InitialTeb, &InitialTeb,
FALSE); FALSE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("Thread creation failed (Status %x)\n", Status); DPRINT("Thread creation failed (Status %x)\n", Status);
@ -273,22 +275,22 @@ NTSTATUS LdrLoadInitialProcess (VOID)
&InitialTeb.StackReserve, &InitialTeb.StackReserve,
MEM_RELEASE); MEM_RELEASE);
/* FIXME: unmap the section here */ /* FIXME: unmap the section here */
/* FIXME: destroy the section here */ /* FIXME: destroy the section here */
return Status; return(Status);
} }
DPRINT("Attaching to process\n"); DPRINT("Attaching to process\n");
KeAttachProcess(Process); KeAttachProcess(Process);
Peb = (PPEB)PEB_BASE; Peb = (PPEB)PEB_BASE;
DPRINT("Peb %x\n", Peb); DPRINT("Peb %x\n", Peb);
DPRINT("CurrentProcess %x Peb->ImageBaseAddress %x\n", DPRINT("CurrentProcess %x Peb->ImageBaseAddress %x\n",
PsGetCurrentProcess(), PsGetCurrentProcess(),
Peb->ImageBaseAddress); Peb->ImageBaseAddress);
KeDetachProcess(); KeDetachProcess();
return STATUS_SUCCESS; return(STATUS_SUCCESS);
} }
/* EOF */ /* 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 * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -501,6 +501,7 @@ MmSplitSegment(PMADDRESS_SPACE AddressSpace,
ULONG OldProtect; ULONG OldProtect;
ULONG OldLength; ULONG OldLength;
DPRINT("MmSplitSegment()\n");
/* /*
* Save the type and protection and length of the current segment * 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. * allocated at a address below a certain value.
* RegionSize = The number of bytes to allocate * RegionSize = The number of bytes to allocate
* AllocationType = Indicates the type of virtual memory you like to * AllocationType = Indicates the type of virtual memory you like to
* allocated, can be one of the values : MEM_COMMIT, * allocated, can be a combination of MEM_COMMIT,
* MEM_RESERVE, MEM_RESET, MEM_TOP_DOWN * MEM_RESERVE, MEM_RESET, MEM_TOP_DOWN.
* Protect = Indicates the protection type of the pages allocated, can be * Protect = Indicates the protection type of the pages allocated, can be
* a combination of PAGE_READONLY, PAGE_READWRITE, * a combination of PAGE_READONLY, PAGE_READWRITE,
* PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE, PAGE_GUARD, * PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE, PAGE_GUARD,
@ -882,6 +883,16 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
{ {
return(STATUS_INVALID_PAGE_PROTECTION); 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; PBaseAddress = *UBaseAddress;
PRegionSize = *URegionSize; PRegionSize = *URegionSize;
@ -902,19 +913,14 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
return(Status); return(Status);
} }
if (AllocationType & MEM_RESERVE) Type = (AllocationType & MEM_COMMIT) ? MEM_COMMIT : MEM_RESERVE;
{ DPRINT("Type %x\n", Type);
Type = MEM_RESERVE;
}
else
{
Type = MEM_COMMIT;
}
AddressSpace = &Process->AddressSpace; AddressSpace = &Process->AddressSpace;
MmLockAddressSpace(AddressSpace); MmLockAddressSpace(AddressSpace);
if (PBaseAddress != 0) if ((PBaseAddress != 0) &&
((AllocationType & (MEM_COMMIT | MEM_RESERVE)) == MEM_COMMIT))
{ {
MemoryArea = MmOpenMemoryAreaByAddress(&Process->AddressSpace, MemoryArea = MmOpenMemoryAreaByAddress(&Process->AddressSpace,
BaseAddress); BaseAddress);
@ -932,6 +938,7 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
/* FIXME: Reserve/dereserve swap pages */ /* FIXME: Reserve/dereserve swap pages */
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process); ObDereferenceObject(Process);
DPRINT("NtAllocateVirtualMemory() = %x\n",Status);
return(Status); return(Status);
} }
else if (MemoryArea != NULL) 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); TAG_MM_SEGMENT);
if (Segment == NULL) if (Segment == NULL)
{ {
@ -962,9 +970,9 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("NtAllocateVirtualMemory() = %x\n",Status);
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process); ObDereferenceObject(Process);
DPRINT("NtAllocateVirtualMemory() = %x\n",Status);
return(Status); return(Status);
} }
@ -976,7 +984,6 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
InsertTailList(&MemoryArea->Data.VirtualMemoryData.SegmentListHead, InsertTailList(&MemoryArea->Data.VirtualMemoryData.SegmentListHead,
&Segment->SegmentListEntry); &Segment->SegmentListEntry);
DPRINT("*UBaseAddress %x\n",*UBaseAddress);
if ((AllocationType & MEM_COMMIT) && if ((AllocationType & MEM_COMMIT) &&
((Protect & PAGE_READWRITE) || ((Protect & PAGE_READWRITE) ||
(Protect & PAGE_EXECUTE_READWRITE))) (Protect & PAGE_EXECUTE_READWRITE)))
@ -986,6 +993,7 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
*UBaseAddress = BaseAddress; *UBaseAddress = BaseAddress;
*URegionSize = RegionSize; *URegionSize = RegionSize;
DPRINT("*UBaseAddress %x *URegionSize %x\n", BaseAddress, RegionSize);
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process); ObDereferenceObject(Process);
@ -1013,7 +1021,9 @@ NtFlushVirtualMemory(IN HANDLE ProcessHandle,
} }
VOID STATIC VOID STATIC
MmFreeVirtualMemoryPage(PVOID Context, PVOID Address, ULONG PhysicalAddr) MmFreeVirtualMemoryPage(PVOID Context,
PVOID Address,
ULONG PhysicalAddr)
{ {
PEPROCESS Process = (PEPROCESS)Context; PEPROCESS Process = (PEPROCESS)Context;
@ -1025,16 +1035,20 @@ MmFreeVirtualMemoryPage(PVOID Context, PVOID Address, ULONG PhysicalAddr)
} }
VOID VOID
MmFreeVirtualMemory(PEPROCESS Process, PMEMORY_AREA MemoryArea) MmFreeVirtualMemory(PEPROCESS Process,
PMEMORY_AREA MemoryArea)
{ {
PLIST_ENTRY current_entry; PLIST_ENTRY current_entry;
PMM_SEGMENT current; PMM_SEGMENT current;
DPRINT("MmFreeVirtualMemory(Process %p MemoryArea %p)\n", Process, MemoryArea);
current_entry = MemoryArea->Data.VirtualMemoryData.SegmentListHead.Flink; current_entry = MemoryArea->Data.VirtualMemoryData.SegmentListHead.Flink;
while (current_entry != &MemoryArea->Data.VirtualMemoryData.SegmentListHead) while (current_entry != &MemoryArea->Data.VirtualMemoryData.SegmentListHead)
{ {
current = CONTAINING_RECORD(current_entry, MM_SEGMENT, SegmentListEntry); current = CONTAINING_RECORD(current_entry, MM_SEGMENT, SegmentListEntry);
current_entry = current_entry->Flink; current_entry = current_entry->Flink;
DPRINT("ExFreePool(%p)\n", current);
ExFreePool(current); ExFreePool(current);
} }
@ -1171,11 +1185,12 @@ MmChangeAreaProtection(PEPROCESS Process,
} }
NTSTATUS STDCALL NtProtectVirtualMemory(IN HANDLE ProcessHandle, NTSTATUS STDCALL
IN PVOID BaseAddress, NtProtectVirtualMemory(IN HANDLE ProcessHandle,
IN ULONG NumberOfBytesToProtect, IN PVOID BaseAddress,
IN ULONG NewAccessProtection, IN ULONG NumberOfBytesToProtect,
OUT PULONG OldAccessProtection) IN ULONG NewAccessProtection,
OUT PULONG OldAccessProtection)
{ {
PMEMORY_AREA MemoryArea; PMEMORY_AREA MemoryArea;
PEPROCESS Process; PEPROCESS Process;
@ -1206,7 +1221,7 @@ NTSTATUS STDCALL NtProtectVirtualMemory(IN HANDLE ProcessHandle,
ObDereferenceObject(Process); ObDereferenceObject(Process);
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
#if 0
*OldAccessProtection = MemoryArea->Attributes; *OldAccessProtection = MemoryArea->Attributes;
if (MemoryArea->BaseAddress == BaseAddress && if (MemoryArea->BaseAddress == BaseAddress &&
@ -1228,6 +1243,7 @@ NTSTATUS STDCALL NtProtectVirtualMemory(IN HANDLE ProcessHandle,
BaseAddress, BaseAddress,
NumberOfBytesToProtect, NumberOfBytesToProtect,
NewAccessProtection); NewAccessProtection);
#endif
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process); ObDereferenceObject(Process);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);