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,7 +15,8 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
LPVOID STDCALL VirtualAllocEx(HANDLE hProcess, LPVOID STDCALL
VirtualAllocEx(HANDLE hProcess,
LPVOID lpAddress, LPVOID lpAddress,
DWORD dwSize, DWORD dwSize,
DWORD flAllocationType, DWORD flAllocationType,
@ -23,7 +24,7 @@ LPVOID STDCALL VirtualAllocEx(HANDLE hProcess,
{ {
NTSTATUS Status; NTSTATUS Status;
Status = ZwAllocateVirtualMemory(hProcess, Status = NtAllocateVirtualMemory(hProcess,
(PVOID *)&lpAddress, (PVOID *)&lpAddress,
0, 0,
(PULONG)&dwSize, (PULONG)&dwSize,
@ -31,46 +32,62 @@ LPVOID STDCALL VirtualAllocEx(HANDLE hProcess,
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,
LPVOID STDCALL
VirtualAlloc(LPVOID lpAddress,
DWORD dwSize, DWORD dwSize,
DWORD flAllocationType, DWORD flAllocationType,
DWORD flProtect) DWORD flProtect)
{ {
return(VirtualAllocEx(GetCurrentProcess(),lpAddress,dwSize,flAllocationType, return(VirtualAllocEx(GetCurrentProcess(),
lpAddress,
dwSize,
flAllocationType,
flProtect)); flProtect));
} }
WINBOOL STDCALL VirtualFreeEx(HANDLE hProcess,
WINBOOL STDCALL
VirtualFreeEx(HANDLE hProcess,
LPVOID lpAddress, LPVOID lpAddress,
DWORD dwSize, DWORD dwSize,
DWORD dwFreeType) DWORD dwFreeType)
{ {
NTSTATUS Status; NTSTATUS Status;
Status = ZwFreeVirtualMemory(hProcess, Status = NtFreeVirtualMemory(hProcess,
(PVOID *)&lpAddress, (PVOID *)&lpAddress,
(PULONG)&dwSize, (PULONG)&dwSize,
dwFreeType); dwFreeType);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
SetLastErrorByStatus (Status); SetLastErrorByStatus(Status);
return(FALSE); return(FALSE);
} }
return(TRUE); 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 dwSize,
DWORD flNewProtect, DWORD flNewProtect,
PDWORD lpflOldProtect) PDWORD lpflOldProtect)
@ -83,7 +100,8 @@ WINBOOL STDCALL VirtualProtect(LPVOID lpAddress,
} }
WINBOOL STDCALL VirtualProtectEx(HANDLE hProcess, WINBOOL STDCALL
VirtualProtectEx(HANDLE hProcess,
LPVOID lpAddress, LPVOID lpAddress,
DWORD dwSize, DWORD dwSize,
DWORD flNewProtect, DWORD flNewProtect,
@ -91,94 +109,93 @@ WINBOOL STDCALL VirtualProtectEx(HANDLE hProcess,
{ {
NTSTATUS Status; NTSTATUS Status;
Status = ZwProtectVirtualMemory(hProcess, Status = NtProtectVirtualMemory(hProcess,
(PVOID)lpAddress, (PVOID)lpAddress,
dwSize, dwSize,
flNewProtect, flNewProtect,
(PULONG)lpflOldProtect); (PULONG)lpflOldProtect);
if (Status != STATUS_SUCCESS) if (!NT_SUCCESS(Status))
{ {
SetLastErrorByStatus (Status); SetLastErrorByStatus(Status);
return(FALSE); return(FALSE);
} }
return(TRUE); return(TRUE);
} }
WINBOOL WINBOOL STDCALL
STDCALL VirtualLock(LPVOID lpAddress,
VirtualLock ( DWORD dwSize)
LPVOID lpAddress,
DWORD dwSize
)
{ {
ULONG BytesLocked; ULONG BytesLocked;
NTSTATUS Status; NTSTATUS Status;
Status = NtLockVirtualMemory(NtCurrentProcess(),lpAddress,dwSize, &BytesLocked);
Status = NtLockVirtualMemory(NtCurrentProcess(),
lpAddress,
dwSize,
&BytesLocked);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
SetLastErrorByStatus (Status); SetLastErrorByStatus(Status);
return FALSE; return(FALSE);
} }
return TRUE; return(TRUE);
} }
DWORD DWORD STDCALL
STDCALL VirtualQuery(LPCVOID lpAddress,
VirtualQuery (
LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer, PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength DWORD dwLength)
)
{ {
return VirtualQueryEx (NtCurrentProcess(),lpAddress, lpBuffer, dwLength ); return(VirtualQueryEx(NtCurrentProcess(),
lpAddress,
lpBuffer,
dwLength));
} }
#define MemoryBasicInformation 0
DWORD DWORD STDCALL
STDCALL VirtualQueryEx(HANDLE hProcess,
VirtualQueryEx (
HANDLE hProcess,
LPCVOID lpAddress, LPCVOID lpAddress,
PMEMORY_BASIC_INFORMATION lpBuffer, PMEMORY_BASIC_INFORMATION lpBuffer,
DWORD dwLength DWORD dwLength)
)
{ {
NTSTATUS Status; NTSTATUS Status;
ULONG ResultLength; ULONG ResultLength;
Status = NtQueryVirtualMemory( Status = NtQueryVirtualMemory(hProcess,
hProcess,(LPVOID)lpAddress, (LPVOID)lpAddress,
MemoryBasicInformation, lpBuffer, MemoryBasicInformation,
lpBuffer,
sizeof(MEMORY_BASIC_INFORMATION), sizeof(MEMORY_BASIC_INFORMATION),
&ResultLength ); &ResultLength );
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
SetLastErrorByStatus (Status); SetLastErrorByStatus(Status);
return ResultLength; return(ResultLength);
} }
return ResultLength; return(ResultLength);
} }
WINBOOL WINBOOL STDCALL
STDCALL VirtualUnlock(LPVOID lpAddress,
VirtualUnlock ( DWORD dwSize)
LPVOID lpAddress,
DWORD dwSize
)
{ {
ULONG BytesLocked; ULONG BytesLocked;
NTSTATUS Status; NTSTATUS Status;
Status = NtUnlockVirtualMemory(NtCurrentProcess(),lpAddress,dwSize, &BytesLocked);
Status = NtUnlockVirtualMemory(NtCurrentProcess(),
lpAddress,
dwSize,
&BytesLocked);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
SetLastErrorByStatus (Status); SetLastErrorByStatus(Status);
return FALSE; return(FALSE);
} }
return TRUE; 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,7 +17,8 @@
/* FUNCTIONS ***************************************************************/ /* FUNCTIONS ***************************************************************/
NTSTATUS STDCALL RtlCreateSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
RtlCreateSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
ULONG Revision) 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,7 +90,8 @@ ULONG STDCALL RtlLengthSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescript
return(Length); return(Length);
} }
NTSTATUS STDCALL RtlGetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
RtlGetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PBOOLEAN DaclPresent, PBOOLEAN DaclPresent,
PACL* Dacl, PACL* Dacl,
PBOOLEAN DaclDefaulted) PBOOLEAN DaclDefaulted)
@ -130,7 +133,8 @@ NTSTATUS STDCALL RtlGetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDesc
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL RtlSetDaclSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
BOOLEAN DaclPresent, BOOLEAN DaclPresent,
PACL Dacl, PACL Dacl,
BOOLEAN DaclDefaulted) BOOLEAN DaclDefaulted)
@ -158,12 +162,14 @@ 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
RtlSetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID Owner, PSID Owner,
BOOLEAN OwnerDefaulted) BOOLEAN OwnerDefaulted)
{ {
@ -184,7 +190,8 @@ NTSTATUS STDCALL RtlSetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL RtlGetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
RtlGetOwnerSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID* Owner, PSID* Owner,
PBOOLEAN OwnerDefaulted) PBOOLEAN OwnerDefaulted)
{ {
@ -219,7 +226,8 @@ NTSTATUS STDCALL RtlGetOwnerSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL RtlSetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
RtlSetGroupSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID Group, PSID Group,
BOOLEAN GroupDefaulted) BOOLEAN GroupDefaulted)
{ {
@ -240,7 +248,8 @@ NTSTATUS STDCALL RtlSetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL RtlGetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS STDCALL
RtlGetGroupSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
PSID* Group, PSID* Group,
PBOOLEAN GroupDefaulted) PBOOLEAN GroupDefaulted)
{ {
@ -275,55 +284,45 @@ NTSTATUS STDCALL RtlGetGroupSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDes
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlMakeSelfRelativeSD(PSECURITY_DESCRIPTOR AbsSD,
RtlMakeSelfRelativeSD (
PSECURITY_DESCRIPTOR AbsSD,
PSECURITY_DESCRIPTOR RelSD, PSECURITY_DESCRIPTOR RelSD,
PULONG BufferLength PULONG BufferLength)
)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlAbsoluteToSelfRelativeSD(PSECURITY_DESCRIPTOR AbsSD,
RtlAbsoluteToSelfRelativeSD (
PSECURITY_DESCRIPTOR AbsSD,
PSECURITY_DESCRIPTOR RelSD, PSECURITY_DESCRIPTOR RelSD,
PULONG BufferLength 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 SecurityDescriptor,
PSECURITY_DESCRIPTOR_CONTROL Control, PSECURITY_DESCRIPTOR_CONTROL Control,
PULONG Revision 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 (
PSECURITY_DESCRIPTOR SecurityDescriptor,
PBOOLEAN SaclPresent, PBOOLEAN SaclPresent,
PACL *Sacl, PACL *Sacl,
PBOOLEAN SaclDefaulted) PBOOLEAN SaclDefaulted)
@ -365,14 +364,11 @@ RtlGetSaclSecurityDescriptor (
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlSetSaclSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor,
RtlSetSaclSecurityDescriptor (
PSECURITY_DESCRIPTOR SecurityDescriptor,
BOOLEAN SaclPresent, BOOLEAN SaclPresent,
PACL Sacl, PACL Sacl,
BOOLEAN SaclDefaulted BOOLEAN SaclDefaulted)
)
{ {
if (SecurityDescriptor->Revision != 1) if (SecurityDescriptor->Revision != 1)
{ {
@ -397,10 +393,8 @@ RtlSetSaclSecurityDescriptor (
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS NTSTATUS STDCALL
STDCALL RtlSelfRelativeToAbsoluteSD(PSECURITY_DESCRIPTOR RelSD,
RtlSelfRelativeToAbsoluteSD (
PSECURITY_DESCRIPTOR RelSD,
PSECURITY_DESCRIPTOR AbsSD, PSECURITY_DESCRIPTOR AbsSD,
PDWORD AbsSDSize, PDWORD AbsSDSize,
PACL Dacl, PACL Dacl,
@ -410,8 +404,7 @@ RtlSelfRelativeToAbsoluteSD (
PSID Owner, PSID Owner,
PDWORD OwnerSize, PDWORD OwnerSize,
PSID Group, PSID Group,
PDWORD GroupSize PDWORD GroupSize)
)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }

View file

@ -44,16 +44,20 @@ RtlCreateUserThread(HANDLE ProcessHandle,
NTSTATUS Status; NTSTATUS Status;
/* initialize initial teb */ /* initialize initial teb */
if ((StackCommit != NULL) && (*StackCommit > PAGESIZE))
InitialTeb.StackCommit = *StackCommit;
else
InitialTeb.StackCommit = PAGESIZE;
if ((StackReserve != NULL) && (*StackReserve > 0x100000)) if ((StackReserve != NULL) && (*StackReserve > 0x100000))
InitialTeb.StackReserve = *StackReserve; InitialTeb.StackReserve = *StackReserve;
else else
InitialTeb.StackReserve = 0x100000; /* 1MByte */ 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 */ /* add size of guard page */
InitialTeb.StackCommit += PAGESIZE; InitialTeb.StackCommit += PAGESIZE;
@ -63,12 +67,12 @@ RtlCreateUserThread(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))
{ {
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",
@ -79,7 +83,7 @@ RtlCreateUserThread(HANDLE ProcessHandle,
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,
@ -96,7 +100,7 @@ RtlCreateUserThread(HANDLE ProcessHandle,
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,9 +124,9 @@ RtlCreateUserThread(HANDLE ProcessHandle,
DPRINT("Error protecting guard page!\n"); DPRINT("Error protecting guard page!\n");
return(Status); return(Status);
} }
#endif
/* initialize thread context */ /* initialize thread context */
RtlInitializeContext (ProcessHandle, RtlInitializeContext(ProcessHandle,
&ThreadContext, &ThreadContext,
Parameter, Parameter,
StartAddress, StartAddress,
@ -144,7 +148,6 @@ RtlCreateUserThread(HANDLE ProcessHandle,
&ThreadContext, &ThreadContext,
&InitialTeb, &InitialTeb,
CreateSuspended); CreateSuspended);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* release the stack space */ /* release the stack space */
@ -154,7 +157,7 @@ RtlCreateUserThread(HANDLE ProcessHandle,
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 */

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,7 +228,6 @@ 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);
@ -276,7 +278,7 @@ NTSTATUS LdrLoadInitialProcess (VOID)
/* 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");
@ -288,7 +290,7 @@ NTSTATUS LdrLoadInitialProcess (VOID)
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,7 +1185,8 @@ MmChangeAreaProtection(PEPROCESS Process,
} }
NTSTATUS STDCALL NtProtectVirtualMemory(IN HANDLE ProcessHandle, NTSTATUS STDCALL
NtProtectVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID BaseAddress, IN PVOID BaseAddress,
IN ULONG NumberOfBytesToProtect, IN ULONG NumberOfBytesToProtect,
IN ULONG NewAccessProtection, IN ULONG NewAccessProtection,
@ -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);