More improvements to LPC code

Updated TEB structure
Changed selectors value to be closer to nt
Some bugfixes

svn path=/trunk/; revision=965
This commit is contained in:
David Welch 2000-01-26 10:07:30 +00:00
parent 52404fd1c8
commit d24a48cd94
32 changed files with 2002 additions and 1326 deletions

View file

@ -3,6 +3,7 @@
#include <kernel32/atom.h>
#include <internal/hal.h>
#include <internal/teb.h>
#ifndef TLS_MINIMUM_AVAILABLE
#define TLS_MINIMUM_AVAILABLE (64)
@ -46,127 +47,6 @@ typedef struct linux_sigcontext {
typedef ULONG THREADINFOCLASS;
typedef struct _CURDIR
{
UNICODE_STRING DosPath;
HANDLE Handle;
} CURDIR, *PCURDIR;
typedef struct _RTL_DRIVE_LETTER_CURDIR
{
USHORT Flags;
USHORT Length;
ULONG TimeStamp;
UNICODE_STRING DosPath;
} RTL_DRIVE_LETTER_CURDIR, *PRTL_DRIVE_LETTER_CURDIR;
typedef struct _RTL_USER_PROCESS_PARAMETERS
{
ULONG MaximumLength; // 00h
ULONG Length; // 04h
ULONG Flags; // 08h
ULONG DebugFlags; // 0Ch
HANDLE ConsoleHandle; // 10h
ULONG ConsoleFlags; // 14h
HANDLE StandardInput; // 18h
HANDLE StandardOutput; // 1Ch
HANDLE StandardError; // 20h
CURDIR CurrentDirectory; // 24h
UNICODE_STRING DllPath; // 30h
UNICODE_STRING ImagePathName; // 38h
UNICODE_STRING CommandLine; // 40h
PVOID Environment; // 48h
ULONG StartingX; // 4Ch
ULONG StartingY; // 50h
ULONG CountX; // 54h
ULONG CountY; // 58h
ULONG CountCharsX; // 5Ch
ULONG CountCharsY; // 60h
ULONG FillAttribute; // 64h
ULONG WindowFlags; // 68h
ULONG ShowWindowFlags; // 6Ch
UNICODE_STRING WindowTitle; // 70h
UNICODE_STRING DesktopInfo; // 78h
UNICODE_STRING ShellInfo; // 80h
UNICODE_STRING RuntimeData; // 88h
RTL_DRIVE_LETTER_CURDIR DLCurrentDirectory[32]; // 90h
} RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
typedef struct _LDR
{
UCHAR Initialized;
UCHAR InInitializationOrderModuleList;
PVOID InLoadOrderModuleList;
PVOID InMemoryOrderModuleList;
} LDR, *PLDR;
typedef struct _PEB
{
UCHAR InheritedAddressSpace; // 00
UCHAR ReadImageFileExecOptions; // 01h
UCHAR BeingDebugged; // 02h
LONG ImageBaseAddress; // 03h
LDR Ldr; // 07h
PRTL_USER_PROCESS_PARAMETERS ProcessParameters; // 10h
WORD NumberOfProcessors; // 11h
WORD NtGlobalFlag; // 13h
HANDLE ProcessHeap; // 19h
ATOMTABLE LocalAtomTable; // 1Dh
LPCRITICAL_SECTION CriticalSection; // 35h
DWORD CriticalSectionTimeout; // 39h
WORD MajorVersion; // 3Dh
WORD MinorVersion; // 3Fh
WORD BuildNumber; // 41h
WORD PlatformId; // 43h
} PEB, *PPEB;
typedef struct _CLIENT_ID
{
HANDLE UniqueProcess;
HANDLE UniqueThread;
} CLIENT_ID, *PCLIENT_ID;
typedef struct _NT_TIB {
struct _EXCEPTION_REGISTRATION_RECORD* ExceptionList; // 00h
PVOID StackBase; // 04h
PVOID StackLimit; // 08h
PVOID SubSystemTib; // 0Ch
union {
PVOID FiberData; // 10h
ULONG Version; // 10h
} Fib;
PVOID ArbitraryUserPointer; // 14h
struct _NT_TIB *Self; // 18h
} NT_TIB, *PNT_TIB;
typedef struct _NT_TEB
{
NT_TIB Tib; // 00h
ULONG reserved1; // 1Ch ???
CLIENT_ID Cid; // 20h
ULONG reserved2; // 28h ???
ULONG reserved3; // 2Ch ???
PPEB Peb; // 30h
DWORD LastErrorCode; // 34h
HANDLE RPCHandle; // 36
PVOID TlsData[TLS_MINIMUM_AVAILABLE]; // 40
DWORD dwTlsIndex; // 230
NTSTATUS LastStatusValue; // 242
DWORD LockCount; // 244
UCHAR HardErrorMode; // 248
/* reactos only ??? (Eric Kohl) */
PVOID StackCommit;
PVOID StackCommitMax;
PVOID StackReserved;
} NT_TEB, *PNT_TEB;
struct _KPROCESS;
typedef struct _KAPC_STATE
@ -428,4 +308,10 @@ typedef struct _EPROCESS
#define PROCESS_STATE_TERMINATED (1)
#define PROCESS_STATE_ACTIVE (2)
#define LOW_PRIORITY (0)
#define LOW_REALTIME_PRIORITY (16)
#define HIGH_PRIORITY (31)
#define MAXIMUM_PRIORITY (32)
#endif /* __INCLUDE_DDK_PSTYPES_H */

View file

@ -1,6 +1,6 @@
#ifndef _INCLUDE_DDK_SEFUNCS_H
#define _INCLUDE_DDK_SEFUNCS_H
/* $Id: sefuncs.h,v 1.4 2000/01/05 21:56:58 dwelch Exp $ */
/* $Id: sefuncs.h,v 1.5 2000/01/26 10:07:22 dwelch Exp $ */
NTSTATUS STDCALL RtlCreateSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor, ULONG Revision);
BOOLEAN STDCALL RtlValidSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor);
ULONG STDCALL RtlLengthSecurityDescriptor (PSECURITY_DESCRIPTOR SecurityDescriptor);
@ -26,11 +26,12 @@ BOOLEAN STDCALL SeAccessCheck (IN PSECURITY_DESCRIPTOR SecurityDescriptor,
OUT PACCESS_MODE GrantedAccess,
OUT PNTSTATUS AccessStatus);
NTSTATUS STDCALL SeAssignSecurity (PSECURITY_DESCRIPTOR ParentDescriptor,
PSECURITY_DESCRIPTOR ExplicitDescriptor,
BOOLEAN IsDirectoryObject,
PSECURITY_SUBJECT_CONTEXT SubjectContext,
PGENERIC_MAPPING GenericMapping,
POOL_TYPE PoolType);
PSECURITY_DESCRIPTOR ExplicitDescriptor,
PSECURITY_DESCRIPTOR* NewDescriptor,
BOOLEAN IsDirectoryObject,
PSECURITY_SUBJECT_CONTEXT SubjectContext,
PGENERIC_MAPPING GenericMapping,
POOL_TYPE PoolType);
NTSTATUS STDCALL SeDeassignSecurity (PSECURITY_DESCRIPTOR* SecurityDescriptor);
BOOLEAN STDCALL SeSinglePrivilegeCheck (LUID PrivilegeValue, KPROCESSOR_MODE PreviousMode);
ULONG STDCALL RtlLengthSid (PSID Sid);
@ -43,6 +44,20 @@ NTSTATUS SeCreateClientSecurity(PETHREAD Thread,
PSECURITY_QUALITY_OF_SERVICE Qos,
ULONG e,
PSE_SOME_STRUCT2 f);
NTSTATUS SeExchangePrimaryToken(PEPROCESS Process,
PACCESS_TOKEN NewToken,
PACCESS_TOKEN* OldTokenP);
VOID STDCALL SeReleaseSubjectContext (PSECURITY_SUBJECT_CONTEXT SubjectContext);
VOID STDCALL SeCaptureSubjectContext (PSECURITY_SUBJECT_CONTEXT SubjectContext);
NTSTATUS SeCaptureLuidAndAttributesArray(PLUID_AND_ATTRIBUTES Src,
ULONG PrivilegeCount,
KPROCESSOR_MODE PreviousMode,
PLUID_AND_ATTRIBUTES AllocatedMem,
ULONG AllocatedLength,
POOL_TYPE PoolType,
ULONG d,
PLUID_AND_ATTRIBUTES* Dest,
PULONG Length);
#endif /* ndef _INCLUDE_DDK_SEFUNCS_H */

View file

@ -1,11 +1,19 @@
#ifndef _ASM_SEGMENT_H
#define _ASM_SEGMENT_H
#define USER_CS (0x8+0x3)
#define USER_DS (0x10+0x3)
#define ZERO_DS 0x18
#define KERNEL_CS 0x20
#define KERNEL_DS 0x28
#define KERNEL_CS (0x8)
#define KERNEL_DS (0x10)
#define USER_CS (0x18 + 0x3)
#define USER_DS (0x20 + 0x3)
#define RESERVED_FOR_TSS (0x28)
#define PCR_SELECTOR (0x30)
#define TEB_SELECTOR (0x38 + 0x3)
//#define USER_CS (0x8+0x3)
//#define USER_DS (0x10+0x3)
//#define ZERO_DS 0x18
//#define KERNEL_CS 0x20
//#define KERNEL_DS 0x28
#ifndef __ASSEMBLY__

View file

@ -0,0 +1,23 @@
typedef struct _EPORT
{
KSPIN_LOCK Lock;
KEVENT Event;
struct _EPORT* OtherPort;
ULONG QueueLength;
LIST_ENTRY QueueListHead;
ULONG ConnectQueueLength;
LIST_ENTRY ConnectQueueListHead;
ULONG MaxDataLength;
ULONG MaxConnectInfoLength;
} EPORT, *PEPORT;
NTSTATUS STDCALL LpcRequestPort(PEPORT Port,
PLPCMESSAGE LpcMessage);
#define PORT_ALL_ACCESS (0x1)
extern POBJECT_TYPE ExPortType;

View file

@ -2,9 +2,214 @@
#ifndef __INCLUDE_INTERNAL_TEB
#define __INCLUDE_INTERNAL_TEB
#include <internal/ps.h>
typedef struct _CLIENT_ID
{
HANDLE UniqueProcess;
HANDLE UniqueThread;
} CLIENT_ID, *PCLIENT_ID;
typedef struct _CURDIR
{
UNICODE_STRING DosPath;
PVOID Handle;
} CURDIR, *PCURDIR;
typedef struct RTL_DRIVE_LETTER_CURDIR
{
USHORT Flags;
USHORT Length;
ULONG TimeStamp;
UNICODE_STRING DosPath;
} RTL_DRIVE_LETTER_CURDIR, *PRTL_DRIVE_LETTER_CURDIR;
typedef struct _PEB_FREE_BLOCK
{
struct _PEB_FREE_BLOCK* Next;
ULONG Size;
} PEB_FREE_BLOCK, *PPEB_FREE_BLOCK;
typedef struct _RTL_USER_PROCESS_PARAMETERS
{
ULONG TotalSize; // 00h
ULONG DataSize; // 04h
ULONG Flags; // 08h
ULONG DebugFlags; // 0Ch
PVOID ConsoleHandle; // 10h
ULONG ConsoleFlags; // 14h
HANDLE InputHandle; // 18h
HANDLE OutputHandle; // 1Ch
HANDLE ErrorHandle; // 20h
CURDIR CurrentDirectory; // 24h
UNICODE_STRING LibraryPath; // 30h
UNICODE_STRING CommandLine; // 38h
UNICODE_STRING ImageName; // 40h
PVOID Environment; // 48h
DWORD X; // 4Ch
DWORD Y; // 50h
DWORD XSize; // 54h
DWORD YSize; // 58h
DWORD XCountChars; // 5Ch
DWORD YCountChars; // 60h
DWORD FillAttribute; // 64h
DWORD WindowFlags; // 68h
DWORD ShowWindow; // 6Ch
UNICODE_STRING Title; // 70h
UNICODE_STRING Desktop; // 78h
UNICODE_STRING ShellInfo; // 80h
UNICODE_STRING RuntimeData; // 88h
RTL_DRIVE_LETTER_CURDIR RtlCurrentDirectory[0x20]; // 90h
} RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
#define PEB_BASE (0x7FFDF000)
typedef struct _PEB_LDR_DATA
{
ULONG Length;
UCHAR Initialized;
PVOID SsHandle;
LIST_ENTRY InLoadOrderModuleList;
LIST_ENTRY InMemoryOrderModuleList;
LIST_ENTRY InInitializationOrderModuleList;
} PEB_LDR_DATA, *PPEB_LDR_DATA;
typedef struct _PEB
{
UCHAR InheritedAddressSpace; // 00h
UCHAR ReadImageFileExecOptions; // 01h
UCHAR BeingDebugged; // 02h
UCHAR Spare; // 03h
PVOID Mutant; // 04h
PVOID ImageBaseAddress; // 08h
PPEB_LDR_DATA Ldr; // 0Ch
PRTL_USER_PROCESS_PARAMETERS ProcessParameters; // 10h
PVOID SubSystemData; // 14h
PVOID ProcessHeap; // 18h
PVOID LastPebLock; // 1Ch
PVOID FastPebLockRoutine; // 20h
PVOID FastPebUnlockRoutine; // 24h
ULONG EnvironmentUpdateCount; // 28h
PVOID KernelCallbackTable; // 2Ch
PVOID EventLogSection; // 30h
PVOID EventLog; // 34h
PPEB_FREE_BLOCK FreeList; // 38h
ULONG TlsExpansionCounter; // 3Ch
PVOID TlsBitmap; // 40h
ULONG TlsBitmapBits[0x2]; // 44h
PVOID ReadOnlySharedMemoryBase; // 4Ch
PVOID ReadOnlySharedMemoryHeap; // 50h
PVOID* ReadOnlyStaticServerData; // 54h
PVOID AnsiCodePageData; // 58h
PVOID OemCodePageData; // 5Ch
PVOID UnicodeCaseTableData; // 60h
ULONG NumberOfProcessors; // 64h
ULONG NtGlobalFlag; // 68h
UCHAR Spare2[0x4]; // 6Ch
LARGE_INTEGER CriticalSectionTimeout; // 70h
ULONG HeapSegmentReserve; // 78h
ULONG HeapSegmentCommit; // 7Ch
ULONG HeapDeCommitTotalFreeThreshold; // 80h
ULONG HeapDeCommitFreeBlockThreshold; // 84h
ULONG NumberOfHeaps; // 88h
ULONG MaximumNumberOfHeaps; // 8Ch
PVOID** ProcessHeaps; // 90h
PVOID GdiSharedHandleTable; // 94h
PVOID ProcessStarterHelper; // 98h
PVOID GdiDCAttributeList; // 9Ch
PVOID LoaderLock; // A0h
ULONG OSMajorVersion; // A4h
ULONG OSMinorVersion; // A8h
ULONG OSBuildNumber; // ACh
ULONG OSPlatformId; // B0h
ULONG ImageSubSystem; // B4h
ULONG ImageSubSystemMajorVersion; // B8h
ULONG ImageSubSystemMinorVersion; // C0h
ULONG GdiHandleBuffer[0x22]; // C4h
} PEB, *PPEB;
typedef struct _NT_TIB {
struct _EXCEPTION_REGISTRATION_RECORD* ExceptionList; // 00h
PVOID StackBase; // 04h
PVOID StackLimit; // 08h
PVOID SubSystemTib; // 0Ch
union {
PVOID FiberData; // 10h
ULONG Version; // 10h
} Fib;
PVOID ArbitraryUserPointer; // 14h
struct _NT_TIB *Self; // 18h
} NT_TIB, *PNT_TIB;
typedef struct _GDI_TEB_BATCH
{
ULONG Offset;
ULONG HDC;
ULONG Buffer[0x136];
} GDI_TEB_BATCH, *PGDI_TEB_BATCH;
typedef struct _NT_TEB
{
NT_TIB Tib; // 00h
PVOID EnvironmentPointer; // 1Ch
CLIENT_ID Cid; // 20h
PVOID ActiveRpcInfo; // 28h
PVOID ThreadLocalStoragePointer; // 2Ch
PPEB Peb; // 30h
ULONG LastErrorValue; // 34h
ULONG CountOfOwnedCriticalSections; // 38h
PVOID CsrClientThread; // 3Ch
PVOID Win32ThreadInfo; // 40h
ULONG Win32ClientInfo[0x1F]; // 44h
PVOID WOW32Reserved; // C0h
ULONG CurrentLocale; // C4h
ULONG FpSoftwareStatusRegister; // C8h
PVOID SystemReserved1[0x36]; // CCh
PVOID Spare1; // 1A4h
LONG ExceptionCode; // 1A8h
ULONG SpareBytes1[0x28]; // 1ACh
PVOID SystemReserved2[0xA]; // 1D4h
GDI_TEB_BATCH GdiTebBatch; // 1FCh
ULONG gdiRgn; // 6DCh
ULONG gdiPen; // 6E0h
ULONG gdiBrush; // 6E4h
CLIENT_ID RealClientId; // 6E8h
PVOID GdiCachedProcessHandle; // 6F0h
ULONG GdiClientPID; // 6F4h
ULONG GdiClientTID; // 6F8h
PVOID GdiThreadLocaleInfo; // 6FCh
PVOID UserReserved[5]; // 700h
PVOID glDispatchTable[0x118]; // 714h
ULONG glReserved1[0x1A]; // B74h
PVOID glReserved2; // BDCh
PVOID glSectionInfo; // BE0h
PVOID glSection; // BE4h
PVOID glTable; // BE8h
PVOID glCurrentRC; // BECh
PVOID glContext; // BF0h
ULONG LastStatusValue; // BF4h
UNICODE_STRING StaticUnicodeString; // BF8h
WCHAR StaticUnicodeBuffer[0x105]; // C00h
PVOID DeallocationStack; // E0Ch
PVOID TlsSlots[0x40]; // E10h
LIST_ENTRY TlsLinks; // F10h
PVOID Vdm; // F18h
PVOID ReservedForNtRpc; // F1Ch
PVOID DbgSsReserved[0x2]; // F20h
ULONG HardErrorDisabled; // F28h
PVOID Instrumentation[0x10]; // F2Ch
PVOID WinSockData; // F6Ch
ULONG GdiBatchCount; // F70h
ULONG Spare2; // F74h
ULONG Spare3; // F78h
ULONG Spare4; // F7Ch
PVOID ReservedForOle; // F80h
ULONG WaitingOnLoaderLock; // F84h
PVOID StackCommit; // F88h
PVOID StackCommitMax; // F8Ch
PVOID StackReserved; // F90h
} NT_TEB, *PNT_TEB;
#define PEB_BASE (0xb0001000)
#define PEB_STARTUPINFO (0xb0003000)
#define NtCurrentPeb() ((PPEB)PEB_BASE)

View file

@ -1,37 +1,19 @@
/* $Id: rtl.h,v 1.6 2000/01/11 17:28:11 ekohl Exp $
/* $Id: rtl.h,v 1.7 2000/01/26 10:07:22 dwelch Exp $
*
*/
VOID
WINAPI
__RtlInitHeap (
PVOID base,
ULONG minsize,
ULONG maxsize
);
VOID WINAPI __RtlInitHeap(PVOID base,
ULONG minsize,
ULONG maxsize);
#define HEAP_BASE (0xa0000000)
VOID
RtlDeleteCriticalSection (
LPCRITICAL_SECTION lpCriticalSection
);
VOID
RtlEnterCriticalSection (
LPCRITICAL_SECTION lpCriticalSection
);
VOID
RtlInitializeCriticalSection (
LPCRITICAL_SECTION pcritical
);
VOID
RtlLeaveCriticalSection (
LPCRITICAL_SECTION lpCriticalSection
);
WINBOOL
RtlTryEntryCriticalSection (
LPCRITICAL_SECTION lpCriticalSection
);
VOID RtlDeleteCriticalSection (LPCRITICAL_SECTION lpCriticalSection);
VOID RtlEnterCriticalSection (LPCRITICAL_SECTION lpCriticalSection);
VOID RtlInitializeCriticalSection (LPCRITICAL_SECTION pcritical);
VOID RtlLeaveCriticalSection (LPCRITICAL_SECTION lpCriticalSection);
WINBOOL RtlTryEntryCriticalSection (LPCRITICAL_SECTION lpCriticalSection);
UINT
STDCALL
RtlCompactHeap (
@ -162,4 +144,4 @@ RtlNormalizeProcessParams (
IN OUT PRTL_USER_PROCESS_PARAMETERS ProcessParameters
);
/* EOF */
/* EOF */

View file

@ -92,40 +92,40 @@ typedef struct _IMAGE_OPTIONAL_HEADER {
// Standard fields.
//
WORD Magic;
WORD Magic; // 0x04
BYTE MajorLinkerVersion;
BYTE MinorLinkerVersion;
DWORD SizeOfCode;
DWORD SizeOfInitializedData;
DWORD SizeOfUninitializedData;
DWORD AddressOfEntryPoint;
DWORD BaseOfCode;
DWORD BaseOfData;
DWORD SizeOfCode; // 0x08
DWORD SizeOfInitializedData; // 0x0C
DWORD SizeOfUninitializedData; // 0x10
DWORD AddressOfEntryPoint; // 0x14
DWORD BaseOfCode; // 0x18
DWORD BaseOfData; // 0x1C
//
// NT additional fields.
//
DWORD ImageBase;
DWORD SectionAlignment;
DWORD FileAlignment;
WORD MajorOperatingSystemVersion;
WORD MinorOperatingSystemVersion;
WORD MajorImageVersion;
WORD MinorImageVersion;
WORD MajorSubsystemVersion;
WORD MinorSubsystemVersion;
DWORD Win32VersionValue;
DWORD SizeOfImage;
DWORD SizeOfHeaders;
DWORD CheckSum;
WORD Subsystem;
WORD DllCharacteristics;
DWORD SizeOfStackReserve;
DWORD SizeOfStackCommit;
DWORD SizeOfHeapReserve;
DWORD SizeOfHeapCommit;
DWORD LoaderFlags;
DWORD ImageBase; // 0x20
DWORD SectionAlignment; // 0x24
DWORD FileAlignment; // 0x28
WORD MajorOperatingSystemVersion; // 0x2C
WORD MinorOperatingSystemVersion; // 0x2E
WORD MajorImageVersion; // 0x30
WORD MinorImageVersion; // 0x32
WORD MajorSubsystemVersion; // 0x34
WORD MinorSubsystemVersion; // 0x36
DWORD Win32VersionValue; // 0x38
DWORD SizeOfImage; // 0x3C
DWORD SizeOfHeaders; // 0x40
DWORD CheckSum; // 0x44
WORD Subsystem; // 0x48
WORD DllCharacteristics; // 0x4A
DWORD SizeOfStackReserve; // 0x4C
DWORD SizeOfStackCommit; // 0x50
DWORD SizeOfHeapReserve; // 0x54
DWORD SizeOfHeapCommit; // 0x58
DWORD LoaderFlags; // 0x5C
DWORD NumberOfRvaAndSizes;
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;

View file

@ -1,4 +1,4 @@
/* $Id: cmdline.c,v 1.10 2000/01/11 17:30:46 ekohl Exp $
/* $Id: cmdline.c,v 1.11 2000/01/26 10:07:23 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -41,7 +41,6 @@ static VOID
InitCommandLines (VOID)
{
PRTL_USER_PROCESS_PARAMETERS Params;
// initialize command line buffers
CommandLineW[0] = 0;
CommandLineStringW.Buffer = CommandLineW;

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.17 2000/01/11 17:30:46 ekohl Exp $
/* $Id: create.c,v 1.18 2000/01/26 10:07:23 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -236,19 +236,19 @@ HANDLE KERNEL32_MapFile(LPCWSTR lpApplicationName,
TempApplicationName[3] = '\\';
TempApplicationName[4] = 0;
DPRINT("TempApplicationName '%S'\n",TempApplicationName);
DPRINT("TempApplicationName '%w'\n",TempApplicationName);
if (lpApplicationName != NULL)
{
wcscpy(TempFileName, lpApplicationName);
DPRINT("TempFileName '%S'\n",TempFileName);
DPRINT("TempFileName '%w'\n",TempFileName);
}
else
{
wcscpy(TempFileName, lpCommandLine);
DPRINT("TempFileName '%S'\n",TempFileName);
DPRINT("TempFileName '%w'\n",TempFileName);
for (i=0; TempFileName[i]!=' ' && TempFileName[i] != 0; i++);
TempFileName[i]=0;
@ -268,7 +268,7 @@ HANDLE KERNEL32_MapFile(LPCWSTR lpApplicationName,
RtlInitUnicodeString(&ApplicationNameString, TempApplicationName);
DPRINT("ApplicationName %S\n",ApplicationNameString.Buffer);
DPRINT("ApplicationName %w\n",ApplicationNameString.Buffer);
InitializeObjectAttributes(&ObjectAttributes,
&ApplicationNameString,
@ -349,7 +349,7 @@ static NTSTATUS
CreatePeb (
PPEB *PebPtr,
HANDLE ProcessHandle,
PRTL_USER_PROCESS_PARAMETERS Ppb)
PRTL_USER_PROCESS_PARAMETERS Ppb)
{
NTSTATUS Status;
PVOID PebBase;
@ -361,7 +361,7 @@ CreatePeb (
/* create the PPB */
PpbBase = (PVOID)PEB_STARTUPINFO;
PpbSize = Ppb->MaximumLength;
PpbSize = Ppb->TotalSize;
Status = NtAllocateVirtualMemory(ProcessHandle,
&PpbBase,
0,
@ -373,11 +373,11 @@ CreatePeb (
return(Status);
}
DPRINT("Ppb->MaximumLength %x\n", Ppb->MaximumLength);
DPRINT("Ppb->TotalSize %x\n", Ppb->TotalSize);
NtWriteVirtualMemory(ProcessHandle,
PpbBase,
Ppb,
Ppb->MaximumLength,
Ppb->TotalSize,
&BytesWritten);
@ -439,11 +439,11 @@ CreateProcessW (
PROCESS_BASIC_INFORMATION ProcessBasicInfo;
ULONG retlen;
DWORD len = 0;
PRTL_USER_PROCESS_PARAMETERS ProcessParams;
PRTL_USER_PROCESS_PARAMETERS Ppb;
UNICODE_STRING CommandLine_U;
PPEB Peb;
DPRINT("CreateProcessW(lpApplicationName '%S', lpCommandLine '%S')\n",
DPRINT("CreateProcessW(lpApplicationName '%w', lpCommandLine '%w')\n",
lpApplicationName,lpCommandLine);
if (lpApplicationName[1] != ':')
@ -469,10 +469,10 @@ CreateProcessW (
&CommandLine_U,
TempCommandLine);
DPRINT("CommandLine_U %S\n", CommandLine_U.Buffer);
DPRINT("CommandLine_U %w\n", CommandLine_U.Buffer);
RtlCreateProcessParameters (
&ProcessParams,
&Ppb,
&CommandLine_U,
NULL,
NULL,
@ -529,7 +529,7 @@ CreateProcessW (
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
RtlDestroyProcessParameters (ProcessParams);
RtlDestroyProcessParameters (Ppb);
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
@ -538,9 +538,9 @@ CreateProcessW (
* Create Process Environment Block
*/
DPRINT("Creating peb\n");
CreatePeb(&Peb, hProcess, ProcessParams);
CreatePeb(&Peb, hProcess, Ppb);
RtlDestroyProcessParameters (ProcessParams);
RtlDestroyProcessParameters (Ppb);
DPRINT("Creating thread for process\n");
lpStartAddress = (LPTHREAD_START_ROUTINE)

View file

@ -1,4 +1,4 @@
/* $Id: proc.c,v 1.27 2000/01/20 22:56:49 ekohl Exp $
/* $Id: proc.c,v 1.28 2000/01/26 10:07:23 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -23,6 +23,30 @@
#define NDEBUG
#include <kernel32/kernel32.h>
/* TYPES *********************************************************************/
/*
typedef struct _WSTARTUPINFO {
DWORD cb;
LPWSTR lpReserved;
LPWSTR lpDesktop;
LPWSTR lpTitle;
DWORD dwX;
DWORD dwY;
DWORD dwXSize;
DWORD dwYSize;
DWORD dwXCountChars;
DWORD dwYCountChars;
DWORD dwFillAttribute;
DWORD dwFlags;
WORD wShowWindow;
WORD cbReserved2;
LPBYTE lpReserved2;
HANDLE hStdInput;
HANDLE hStdOutput;
HANDLE hStdError;
} WSTARTUPINFO, *LPWSTARTUPINFO;
*/
/* GLOBALS *******************************************************************/
WaitForInputIdleType lpfnGlobalRegisterWaitForInputIdle;
@ -56,7 +80,7 @@ GetProcessTimes (
LPFILETIME lpUserTime
)
{
DPRINT("GetProcessTimes is unimplemented\n");
dprintf("GetProcessTimes is unimplemented\n");
return FALSE;
}
@ -296,9 +320,7 @@ GetStartupInfoW (
LPSTARTUPINFOW lpStartupInfo
)
{
PRTL_USER_PROCESS_PARAMETERS Params;
Params = NtCurrentPeb()->ProcessParameters;
PPEB pPeb = NtCurrentPeb();
if (lpStartupInfo == NULL)
{
@ -307,24 +329,24 @@ GetStartupInfoW (
}
lpStartupInfo->cb = sizeof(STARTUPINFOW);
wcscpy (lpStartupInfo->lpDesktop, Params->DesktopInfo.Buffer);
wcscpy (lpStartupInfo->lpTitle, Params->WindowTitle.Buffer);
lpStartupInfo->dwX = Params->StartingX;
lpStartupInfo->dwY = Params->StartingY;
lpStartupInfo->dwXSize = Params->CountX;
lpStartupInfo->dwYSize = Params->CountY;
lpStartupInfo->dwXCountChars = Params->CountCharsX;
lpStartupInfo->dwYCountChars = Params->CountCharsY;
lpStartupInfo->dwFillAttribute = Params->FillAttribute;
lpStartupInfo->dwFlags = Params->WindowFlags;
lpStartupInfo->wShowWindow = Params->ShowWindowFlags;
wcscpy (lpStartupInfo->lpReserved, Params->ShellInfo.Buffer);
// lpStartupInfo->cbReserved2 = Params->cbReserved;
// lpStartupInfo->lpReserved2 = Params->lpReserved2;
// lstrcpyW(lpStartupInfo->lpDesktop, pPeb->Ppb->Desktop);
// lstrcpyW(lpStartupInfo->lpTitle, pPeb->Ppb->Title);
lpStartupInfo->dwX = pPeb->ProcessParameters->X;
lpStartupInfo->dwY = pPeb->ProcessParameters->Y;
lpStartupInfo->dwXSize = pPeb->ProcessParameters->XSize;
lpStartupInfo->dwYSize = pPeb->ProcessParameters->YSize;
lpStartupInfo->dwXCountChars = pPeb->ProcessParameters->XCountChars;
lpStartupInfo->dwYCountChars = pPeb->ProcessParameters->YCountChars;
lpStartupInfo->dwFillAttribute = pPeb->ProcessParameters->FillAttribute;
lpStartupInfo->dwFlags = pPeb->ProcessParameters->Flags;
lpStartupInfo->wShowWindow = pPeb->ProcessParameters->ShowWindow;
// lpStartupInfo->lpReserved = pPeb->ProcessParameters->lpReserved1;
// lpStartupInfo->cbReserved2 = pPeb->ProcessParameters->cbReserved;
// lpStartupInfo->lpReserved2 = pPeb->ProcessParameters->lpReserved2;
lpStartupInfo->hStdInput = Params->StandardInput;
lpStartupInfo->hStdOutput = Params->StandardOutput;
lpStartupInfo->hStdError = Params->StandardError;
lpStartupInfo->hStdInput = pPeb->ProcessParameters->InputHandle;
lpStartupInfo->hStdOutput = pPeb->ProcessParameters->OutputHandle;
lpStartupInfo->hStdError = pPeb->ProcessParameters->ErrorHandle;
}
@ -334,11 +356,9 @@ GetStartupInfoA (
LPSTARTUPINFOA lpStartupInfo
)
{
PRTL_USER_PROCESS_PARAMETERS Params;
PPEB pPeb = NtCurrentPeb();
ULONG i = 0;
Params = NtCurrentPeb()->ProcessParameters;
if (lpStartupInfo == NULL)
{
SetLastError(ERROR_INVALID_PARAMETER);
@ -348,38 +368,38 @@ GetStartupInfoA (
lpStartupInfo->cb = sizeof(STARTUPINFOA);
#if 0
i = 0;
while ((pPeb->Ppb->Desktop[i])!=0 && i < MAX_PATH)
while ((pPeb->ProcessParameters->Desktop[i])!=0 && i < MAX_PATH)
{
lpStartupInfo->lpDesktop[i] = (unsigned char)
pPeb->Ppb->Desktop[i];
pPeb->ProcessParameters->Desktop[i];
i++;
}
lpStartupInfo->lpDesktop[i] = 0;
i = 0;
while ((pPeb->Ppb->Title[i])!=0 && i < MAX_PATH)
while ((pPeb->ProcessParameters->Title[i])!=0 && i < MAX_PATH)
{
lpStartupInfo->lpTitle[i] = (unsigned char)pPeb->ProcessParameters->Title[i];
i++;
}
lpStartupInfo->lpTitle[i] = 0;
#endif
lpStartupInfo->dwX = Params->StartingX;
lpStartupInfo->dwY = Params->StartingY;
lpStartupInfo->dwXSize = Params->CountX;
lpStartupInfo->dwYSize = Params->CountY;
lpStartupInfo->dwXCountChars = Params->CountCharsX;
lpStartupInfo->dwYCountChars = Params->CountCharsY;
lpStartupInfo->dwFillAttribute = Params->FillAttribute;
lpStartupInfo->dwFlags = Params->WindowFlags;
lpStartupInfo->wShowWindow = Params->ShowWindowFlags;
// lpStartupInfo->cbReserved2 = Params->cbReserved;
// lpStartupInfo->lpReserved = Params->lpReserved1;
// lpStartupInfo->lpReserved2 = Params->lpReserved2;
lpStartupInfo->dwX = pPeb->ProcessParameters->X;
lpStartupInfo->dwY = pPeb->ProcessParameters->Y;
lpStartupInfo->dwXSize = pPeb->ProcessParameters->XSize;
lpStartupInfo->dwYSize = pPeb->ProcessParameters->YSize;
lpStartupInfo->dwXCountChars = pPeb->ProcessParameters->XCountChars;
lpStartupInfo->dwYCountChars = pPeb->ProcessParameters->YCountChars;
lpStartupInfo->dwFillAttribute = pPeb->ProcessParameters->FillAttribute;
lpStartupInfo->dwFlags = pPeb->ProcessParameters->Flags;
lpStartupInfo->wShowWindow = pPeb->ProcessParameters->ShowWindow;
// lpStartupInfo->cbReserved2 = pPeb->ProcessParameters->cbReserved;
// lpStartupInfo->lpReserved = pPeb->ProcessParameters->lpReserved1;
// lpStartupInfo->lpReserved2 = pPeb->ProcessParameters->lpReserved2;
lpStartupInfo->hStdInput = Params->StandardInput;
lpStartupInfo->hStdOutput = Params->StandardOutput;
lpStartupInfo->hStdError = Params->StandardError;
lpStartupInfo->hStdInput = pPeb->ProcessParameters->InputHandle;
lpStartupInfo->hStdOutput = pPeb->ProcessParameters->OutputHandle;
lpStartupInfo->hStdError = pPeb->ProcessParameters->ErrorHandle;
}

View file

@ -20,6 +20,7 @@
DWORD STDCALL TlsAlloc(VOID)
{
#if 0
DWORD dwTlsIndex = GetTeb()->dwTlsIndex;
void **TlsData = GetTeb()->TlsData;
@ -29,15 +30,19 @@ DWORD STDCALL TlsAlloc(VOID)
return (dwTlsIndex++);
}
return (0xFFFFFFFFUL);
#endif
}
WINBOOL STDCALL TlsFree(DWORD dwTlsIndex)
{
#if 0
return (TRUE);
#endif
}
LPVOID STDCALL TlsGetVlue(DWORD dwTlsIndex)
{
#if 0
void **TlsData = GetTeb()->TlsData;
if (dwTlsIndex < (sizeof(TlsData) / sizeof(TlsData[0])))
@ -47,10 +52,12 @@ LPVOID STDCALL TlsGetVlue(DWORD dwTlsIndex)
}
SetLastError(1);
return (NULL);
#endif
}
WINBOOL STDCALL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
{
#if 0
void **TlsData = GetTeb()->TlsData;
if (dwTlsIndex < (sizeof(TlsData) / sizeof(TlsData[0])))
@ -59,4 +66,5 @@ WINBOOL STDCALL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
return (TRUE);
}
return (FALSE);
#endif
}

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.8 2000/01/11 17:28:57 ekohl Exp $
/* $Id: process.c,v 1.9 2000/01/26 10:07:24 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -161,7 +161,7 @@ RtlpMapFile(PUNICODE_STRING ApplicationName,
*Section = NULL;
DPRINT("ApplicationName %S\n", ApplicationName->Buffer);
DPRINT("ApplicationName %w\n", ApplicationName->Buffer);
InitializeObjectAttributes(&ObjectAttributes,
ApplicationName,
@ -229,7 +229,7 @@ static NTSTATUS
RtlpCreatePpbAndPeb (
PPEB *PebPtr,
HANDLE ProcessHandle,
PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
PRTL_USER_PROCESS_PARAMETERS Ppb)
{
NTSTATUS Status;
ULONG BytesWritten;
@ -239,52 +239,48 @@ RtlpCreatePpbAndPeb (
PVOID PpbBase;
ULONG PpbSize;
/* create the process parameter block */
PpbBase = (PVOID)PEB_STARTUPINFO;
PpbSize = ProcessParameters->MaximumLength;
Status = NtAllocateVirtualMemory (
ProcessHandle,
&PpbBase,
0,
&PpbSize,
MEM_COMMIT,
PAGE_READWRITE);
/* create the PPB */
PpbBase = (PVOID)PEB_STARTUPINFO;
PpbSize = Ppb->TotalSize;
Status = NtAllocateVirtualMemory (ProcessHandle,
&PpbBase,
0,
&PpbSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
return(Status);
if (!NT_SUCCESS(Status))
return(Status);
DPRINT("Ppb size %x\n", PpbSize);
NtWriteVirtualMemory (
ProcessHandle,
PpbBase,
ProcessParameters,
ProcessParameters->MaximumLength,
&BytesWritten);
/* create the PEB */
PebBase = (PVOID)PEB_BASE;
PebSize = 0x1000;
Status = NtAllocateVirtualMemory (
ProcessHandle,
&PebBase,
0,
&PebSize,
MEM_COMMIT,
PAGE_READWRITE);
memset (&Peb, 0, sizeof(PEB));
Peb.ProcessParameters = (PRTL_USER_PROCESS_PARAMETERS)PpbBase;
NtWriteVirtualMemory (
ProcessHandle,
PebBase,
&Peb,
sizeof(PEB),
&BytesWritten);
*PebPtr = (PPEB)PebBase;
return STATUS_SUCCESS;
DPRINT("Ppb size %x\n", PpbSize);
NtWriteVirtualMemory (ProcessHandle,
PpbBase,
Ppb,
Ppb->TotalSize,
&BytesWritten);
/* create the PEB */
PebBase = (PVOID)PEB_BASE;
PebSize = 0x1000;
Status = NtAllocateVirtualMemory (ProcessHandle,
&PebBase,
0,
&PebSize,
MEM_COMMIT,
PAGE_READWRITE);
memset (&Peb, 0, sizeof(PEB));
Peb.ProcessParameters = (PRTL_USER_PROCESS_PARAMETERS)PpbBase;
NtWriteVirtualMemory (ProcessHandle,
PebBase,
&Peb,
sizeof(PEB),
&BytesWritten);
*PebPtr = (PPEB)PebBase;
return STATUS_SUCCESS;
}
@ -293,7 +289,7 @@ STDCALL
RtlCreateUserProcess (
PUNICODE_STRING CommandLine,
ULONG Unknown1,
PRTL_USER_PROCESS_PARAMETERS Params,
PRTL_USER_PROCESS_PARAMETERS Ppb,
PSECURITY_DESCRIPTOR ProcessSd,
PSECURITY_DESCRIPTOR ThreadSd,
WINBOOL bInheritHandles,
@ -316,7 +312,7 @@ RtlCreateUserProcess (
ULONG retlen;
PPEB Peb;
DPRINT ("RtlCreateUserProcess(CommandLine '%S')\n",
DPRINT ("RtlCreateUserProcess(CommandLine '%w')\n",
CommandLine->Buffer);
Status = RtlpMapFile(CommandLine,
@ -340,7 +336,7 @@ RtlCreateUserProcess (
&retlen);
DPRINT("ProcessBasicInfo.UniqueProcessId %d\n",
ProcessBasicInfo.UniqueProcessId);
LocalClientId.UniqueProcess = (HANDLE)ProcessBasicInfo.UniqueProcessId;
LocalClientId.UniqueProcess = ProcessBasicInfo.UniqueProcessId;
/*
* Map NT DLL into the process
@ -370,7 +366,7 @@ RtlCreateUserProcess (
*
*/
DPRINT("Creating PPB and PEB\n");
RtlpCreatePpbAndPeb (&Peb, hProcess, Params);
RtlpCreatePpbAndPeb (&Peb, hProcess, Ppb);
DPRINT("Creating thread for process\n");
lpStartAddress = (LPTHREAD_START_ROUTINE)
@ -384,7 +380,7 @@ RtlCreateUserProcess (
lpStartAddress,
Peb,
dwCreationFlags,
(LPDWORD)&LocalClientId.UniqueThread,
&LocalClientId.UniqueThread,
NTDllSection,
hSection,
(PVOID)Headers.OptionalHeader.ImageBase);
@ -407,16 +403,14 @@ RtlCreateUserProcess (
return STATUS_SUCCESS;
}
VOID
STDCALL
RtlAcquirePebLock (VOID)
VOID STDCALL RtlAcquirePebLock(VOID)
{
}
VOID
STDCALL
RtlReleasePebLock (VOID)
VOID STDCALL RtlReleasePebLock(VOID)
{
}
@ -424,20 +418,20 @@ RtlReleasePebLock (VOID)
NTSTATUS
STDCALL
RtlCreateProcessParameters (
PRTL_USER_PROCESS_PARAMETERS *ProcessParameters,
PUNICODE_STRING CommandLine,
PUNICODE_STRING DllPath,
PUNICODE_STRING CurrentDirectory,
PUNICODE_STRING ImagePathName,
PVOID Environment,
PUNICODE_STRING WindowTitle,
PUNICODE_STRING DesktopInfo,
PUNICODE_STRING ShellInfo,
PVOID Reserved2
PRTL_USER_PROCESS_PARAMETERS *Ppb,
PUNICODE_STRING CommandLine,
PUNICODE_STRING LibraryPath,
PUNICODE_STRING CurrentDirectory,
PUNICODE_STRING ImageName,
PVOID Environment,
PUNICODE_STRING Title,
PUNICODE_STRING Desktop,
PUNICODE_STRING Reserved,
PVOID Reserved2
)
{
NTSTATUS Status = STATUS_SUCCESS;
PRTL_USER_PROCESS_PARAMETERS Params = NULL;
PRTL_USER_PROCESS_PARAMETERS Param = NULL;
ULONG RegionSize = 0;
ULONG DataSize = 0;
PWCHAR Dest;
@ -449,34 +443,37 @@ RtlCreateProcessParameters (
/* size of process parameter block */
DataSize = sizeof (RTL_USER_PROCESS_PARAMETERS);
/* size of (reserved) buffer */
DataSize += (256 * sizeof(WCHAR));
/* size of current directory buffer */
DataSize += (MAX_PATH * sizeof(WCHAR));
/* add string lengths */
if (DllPath != NULL)
DataSize += (DllPath->Length + sizeof(WCHAR));
if (ImagePathName != NULL)
DataSize += (ImagePathName->Length + sizeof(WCHAR));
if (LibraryPath != NULL)
DataSize += (LibraryPath->Length + sizeof(WCHAR));
if (CommandLine != NULL)
DataSize += (CommandLine->Length + sizeof(WCHAR));
if (WindowTitle != NULL)
DataSize += (WindowTitle->Length + sizeof(WCHAR));
if (ImageName != NULL)
DataSize += (ImageName->Length + sizeof(WCHAR));
if (DesktopInfo != NULL)
DataSize += (DesktopInfo->Length + sizeof(WCHAR));
if (Title != NULL)
DataSize += (Title->Length + sizeof(WCHAR));
if (ShellInfo != NULL)
DataSize += (ShellInfo->Length + sizeof(WCHAR));
if (Desktop != NULL)
DataSize += (Desktop->Length + sizeof(WCHAR));
if (Reserved != NULL)
DataSize += (Reserved->Length + sizeof(WCHAR));
/* Calculate the required block size */
RegionSize = ROUNDUP(DataSize, PAGESIZE);
Status = NtAllocateVirtualMemory (
NtCurrentProcess (),
(PVOID*)&Params,
(PVOID*)&Param,
0,
&RegionSize,
MEM_COMMIT,
@ -487,153 +484,124 @@ RtlCreateProcessParameters (
return Status;
}
DPRINT ("Process parameter block allocated\n");
DPRINT ("Ppb allocated\n");
Params->MaximumLength = RegionSize;
Params->Length = DataSize;
Params->Flags = TRUE;
Params->Environment = Environment;
// Params->Unknown1 =
// Params->Unknown2 =
// Params->Unknown3 =
// Params->Unknown4 =
Param->TotalSize = RegionSize;
Param->DataSize = DataSize;
Param->Flags = TRUE;
Param->Environment = Environment;
// Param->Unknown1 =
// Param->Unknown2 =
// Param->Unknown3 =
// Param->Unknown4 =
/* copy current directory */
Dest = (PWCHAR)(((PBYTE)Params) +
sizeof(RTL_USER_PROCESS_PARAMETERS));
Dest = (PWCHAR)(((PBYTE)Param) +
sizeof(RTL_USER_PROCESS_PARAMETERS) +
(256 * sizeof(WCHAR)));
Params->CurrentDirectory.DosPath.Buffer = Dest;
if (CurrentDirectory != NULL)
{
Params->CurrentDirectory.DosPath.Length =
CurrentDirectory->Length;
Params->CurrentDirectory.DosPath.MaximumLength =
CurrentDirectory->Length + sizeof(WCHAR);
Param->CurrentDirectory.DosPath.Buffer = Dest;
if (CurrentDirectory != NULL)
{
Param->CurrentDirectory.DosPath.Length = CurrentDirectory->Length;
Param->CurrentDirectory.DosPath.MaximumLength =
CurrentDirectory->Length + sizeof(WCHAR);
memcpy(Dest,
CurrentDirectory->Buffer,
CurrentDirectory->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + CurrentDirectory->Length);
}
*Dest = 0;
Dest = (PWCHAR)(((PBYTE)Param) + sizeof(RTL_USER_PROCESS_PARAMETERS) +
(256 * sizeof(WCHAR)) + (MAX_PATH * sizeof(WCHAR)));
/* copy library path */
Param->LibraryPath.Buffer = Dest;
if (LibraryPath != NULL)
{
Param->LibraryPath.Length = LibraryPath->Length;
memcpy (Dest,
LibraryPath->Buffer,
LibraryPath->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + LibraryPath->Length);
}
Param->LibraryPath.MaximumLength = Param->LibraryPath.Length +
sizeof(WCHAR);
*Dest = 0;
Dest++;
/* copy command line */
Param->CommandLine.Buffer = Dest;
if (CommandLine != NULL)
{
Param->CommandLine.Length = CommandLine->Length;
memcpy (Dest,
CommandLine->Buffer,
CommandLine->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + CommandLine->Length);
}
Param->CommandLine.MaximumLength = Param->CommandLine.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
/* copy image name */
Param->ImageName.Buffer = Dest;
if (ImageName != NULL)
{
Param->ImageName.Length = ImageName->Length;
memcpy (Dest,
CurrentDirectory->Buffer,
CurrentDirectory->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + CurrentDirectory->Length);
}
*Dest = 0;
ImageName->Buffer,
ImageName->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + ImageName->Length);
}
Param->ImageName.MaximumLength = Param->ImageName.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
Dest = (PWCHAR)(((PBYTE)Params) +
sizeof(RTL_USER_PROCESS_PARAMETERS) +
(MAX_PATH * sizeof(WCHAR)));
/* copy dll path */
Params->DllPath.Buffer = Dest;
if (DllPath != NULL)
/* copy title */
Param->Title.Buffer = Dest;
if (Title != NULL)
{
Params->DllPath.Length = DllPath->Length;
Param->Title.Length = Title->Length;
memcpy (Dest,
DllPath->Buffer,
DllPath->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + DllPath->Length);
Title->Buffer,
Title->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + Title->Length);
}
Params->DllPath.MaximumLength =
Params->DllPath.Length + sizeof(WCHAR);
Param->Title.MaximumLength = Param->Title.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
/* copy image path name */
Params->ImagePathName.Buffer = Dest;
if (ImagePathName != NULL)
{
Params->ImagePathName.Length = ImagePathName->Length;
memcpy (Dest,
ImagePathName->Buffer,
ImagePathName->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + ImagePathName->Length);
}
Params->ImagePathName.MaximumLength =
Params->ImagePathName.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
/* copy command line */
Params->CommandLine.Buffer = Dest;
if (CommandLine != NULL)
{
Params->CommandLine.Length = CommandLine->Length;
memcpy (Dest,
CommandLine->Buffer,
CommandLine->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + CommandLine->Length);
}
Params->CommandLine.MaximumLength =
Params->CommandLine.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
/* copy window title */
Params->WindowTitle.Buffer = Dest;
if (WindowTitle != NULL)
{
Params->WindowTitle.Length = WindowTitle->Length;
memcpy (Dest,
WindowTitle->Buffer,
WindowTitle->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + WindowTitle->Length);
}
Params->WindowTitle.MaximumLength =
Params->WindowTitle.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
/* copy desktop info */
Params->DesktopInfo.Buffer = Dest;
if (DesktopInfo != NULL)
{
Params->DesktopInfo.Length = DesktopInfo->Length;
memcpy (Dest,
DesktopInfo->Buffer,
DesktopInfo->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + DesktopInfo->Length);
}
Params->DesktopInfo.MaximumLength =
Params->DesktopInfo.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
/* copy shell info */
Params->ShellInfo.Buffer = Dest;
if (ShellInfo != NULL)
{
Params->ShellInfo.Length = ShellInfo->Length;
memcpy (Dest,
ShellInfo->Buffer,
ShellInfo->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + ShellInfo->Length);
}
Params->ShellInfo.MaximumLength =
Params->ShellInfo.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
/* set runtime data */
Params->RuntimeData.Length = 0;
Params->RuntimeData.MaximumLength = 0;
Params->RuntimeData.Buffer = NULL;
RtlDeNormalizeProcessParams (Params);
*ProcessParameters = Params;
RtlReleasePebLock ();
return Status;
/* copy desktop */
Param->Desktop.Buffer = Dest;
if (Desktop != NULL)
{
Param->Desktop.Length = Desktop->Length;
memcpy (Dest,
Desktop->Buffer,
Desktop->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + Desktop->Length);
}
Param->Desktop.MaximumLength = Param->Desktop.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
RtlDeNormalizeProcessParams (Param);
*Ppb = Param;
RtlReleasePebLock ();
return(Status);
}
VOID
STDCALL
RtlDestroyProcessParameters (
PRTL_USER_PROCESS_PARAMETERS ProcessParameters
)
VOID STDCALL RtlDestroyProcessParameters (PRTL_USER_PROCESS_PARAMETERS Ppb)
{
ULONG RegionSize = 0;
ULONG RegionSize = 0;
NtFreeVirtualMemory (NtCurrentProcess (),
(PVOID)ProcessParameters,
&RegionSize,
MEM_RELEASE);
NtFreeVirtualMemory (NtCurrentProcess (),
(PVOID)Ppb,
&RegionSize,
MEM_RELEASE);
}
/*
@ -642,132 +610,114 @@ RtlDestroyProcessParameters (
VOID
STDCALL
RtlDeNormalizeProcessParams (
PRTL_USER_PROCESS_PARAMETERS Params
PRTL_USER_PROCESS_PARAMETERS Ppb
)
{
if (Params == NULL)
if (Ppb == NULL)
return;
if (Params->Flags == FALSE)
if (Ppb->Flags == FALSE)
return;
if (Params->CurrentDirectory.DosPath.Buffer != NULL)
if (Ppb->CurrentDirectory.DosPath.Buffer != NULL)
{
Params->CurrentDirectory.DosPath.Buffer =
(PWSTR)((ULONG)Params->CurrentDirectory.DosPath.Buffer -
(ULONG)Params);
Ppb->CurrentDirectory.DosPath.Buffer =
(PWSTR)((ULONG)Ppb->CurrentDirectory.DosPath.Buffer -
(ULONG)Ppb);
}
if (Params->DllPath.Buffer != NULL)
if (Ppb->LibraryPath.Buffer != NULL)
{
Params->DllPath.Buffer =
(PWSTR)((ULONG)Params->DllPath.Buffer -
(ULONG)Params);
Ppb->LibraryPath.Buffer =
(PWSTR)((ULONG)Ppb->LibraryPath.Buffer -
(ULONG)Ppb);
}
if (Params->ImagePathName.Buffer != NULL)
if (Ppb->CommandLine.Buffer != NULL)
{
Params->ImagePathName.Buffer =
(PWSTR)((ULONG)Params->ImagePathName.Buffer -
(ULONG)Params);
Ppb->CommandLine.Buffer =
(PWSTR)((ULONG)Ppb->CommandLine.Buffer -
(ULONG)Ppb);
}
if (Params->CommandLine.Buffer != NULL)
if (Ppb->ImageName.Buffer != NULL)
{
Params->CommandLine.Buffer =
(PWSTR)((ULONG)Params->CommandLine.Buffer -
(ULONG)Params);
Ppb->ImageName.Buffer =
(PWSTR)((ULONG)Ppb->ImageName.Buffer -
(ULONG)Ppb);
}
if (Params->WindowTitle.Buffer != NULL)
if (Ppb->Title.Buffer != NULL)
{
Params->WindowTitle.Buffer =
(PWSTR)((ULONG)Params->WindowTitle.Buffer -
(ULONG)Params);
Ppb->Title.Buffer =
(PWSTR)((ULONG)Ppb->Title.Buffer -
(ULONG)Ppb);
}
if (Params->DesktopInfo.Buffer != NULL)
if (Ppb->Desktop.Buffer != NULL)
{
Params->DesktopInfo.Buffer =
(PWSTR)((ULONG)Params->DesktopInfo.Buffer -
(ULONG)Params);
Ppb->Desktop.Buffer =
(PWSTR)((ULONG)Ppb->Desktop.Buffer -
(ULONG)Ppb);
}
if (Params->ShellInfo.Buffer != NULL)
{
Params->ShellInfo.Buffer =
(PWSTR)((ULONG)Params->ShellInfo.Buffer -
(ULONG)Params);
}
Params->Flags = FALSE;
Ppb->Flags = FALSE;
}
/*
* normalize process parameters (Offset-->Pointer)
*/
VOID
STDCALL
RtlNormalizeProcessParams (
PRTL_USER_PROCESS_PARAMETERS Params
)
VOID STDCALL RtlNormalizeProcessParams (PRTL_USER_PROCESS_PARAMETERS Ppb)
{
if (Params == NULL)
return;
if (Ppb == NULL)
return;
if (Ppb->Flags == TRUE)
return;
if (Ppb->CurrentDirectory.DosPath.Buffer != NULL)
{
Ppb->CurrentDirectory.DosPath.Buffer =
(PWSTR)((ULONG)Ppb->CurrentDirectory.DosPath.Buffer +
(ULONG)Ppb);
}
if (Ppb->LibraryPath.Buffer != NULL)
{
Ppb->LibraryPath.Buffer =
(PWSTR)((ULONG)Ppb->LibraryPath.Buffer +
(ULONG)Ppb);
}
if (Ppb->CommandLine.Buffer != NULL)
{
Ppb->CommandLine.Buffer =
(PWSTR)((ULONG)Ppb->CommandLine.Buffer +
(ULONG)Ppb);
}
if (Ppb->ImageName.Buffer != NULL)
{
Ppb->ImageName.Buffer =
(PWSTR)((ULONG)Ppb->ImageName.Buffer +
(ULONG)Ppb);
}
if (Ppb->Title.Buffer != NULL)
{
Ppb->Title.Buffer =
(PWSTR)((ULONG)Ppb->Title.Buffer +
(ULONG)Ppb);
}
if (Ppb->Desktop.Buffer != NULL)
{
Ppb->Desktop.Buffer =
(PWSTR)((ULONG)Ppb->Desktop.Buffer +
(ULONG)Ppb);
}
if (Params->Flags == TRUE) // & PPF_NORMALIZED
return;
if (Params->CurrentDirectory.DosPath.Buffer != NULL)
{
Params->CurrentDirectory.DosPath.Buffer =
(PWSTR)((ULONG)Params->CurrentDirectory.DosPath.Buffer +
(ULONG)Params);
}
if (Params->DllPath.Buffer != NULL)
{
Params->DllPath.Buffer =
(PWSTR)((ULONG)Params->DllPath.Buffer +
(ULONG)Params);
}
if (Params->ImagePathName.Buffer != NULL)
{
Params->ImagePathName.Buffer =
(PWSTR)((ULONG)Params->ImagePathName.Buffer +
(ULONG)Params);
}
if (Params->CommandLine.Buffer != NULL)
{
Params->CommandLine.Buffer =
(PWSTR)((ULONG)Params->CommandLine.Buffer +
(ULONG)Params);
}
if (Params->WindowTitle.Buffer != NULL)
{
Params->WindowTitle.Buffer =
(PWSTR)((ULONG)Params->WindowTitle.Buffer +
(ULONG)Params);
}
if (Params->DesktopInfo.Buffer != NULL)
{
Params->DesktopInfo.Buffer =
(PWSTR)((ULONG)Params->DesktopInfo.Buffer +
(ULONG)Params);
}
if (Params->ShellInfo.Buffer != NULL)
{
Params->ShellInfo.Buffer =
(PWSTR)((ULONG)Params->ShellInfo.Buffer +
(ULONG)Params);
}
Params->Flags = TRUE; // |= PPF_NORMALIZED;
Ppb->Flags = TRUE;
}
/* EOF */

View file

@ -11,10 +11,13 @@ KERNEL_BASE equ 0c0000000h
;
; Segment selectors
;
USER_CS equ 08h
USER_DS equ 010h
KERNEL_CS equ 020h
KERNEL_DS equ 028h
;USER_CS equ 08h
;USER_DS equ 010h
;KERNEL_CS equ 020h
;KERNEL_DS equ 028h
KERNEL_CS equ 08h
KERNEL_DS equ 010h
;
; Space reserved in the gdt for tss descriptors
@ -850,7 +853,7 @@ empty_8042:
align 8
gdt_descr:
gdt_limit:
dw (((6+NR_TASKS)*8)-1)
dw (3*8)-1
gdt_base:
dd gdt
@ -1122,20 +1125,20 @@ gdt:
dw 0
dw 0
dw 00000h ; User code descriptor
dw 00000h ; base: 0h limit: 3gb
dw 0fa00h
dw 000cch
;dw 00000h ; User code descriptor
;dw 00000h ; base: 0h limit: 3gb
;dw 0fa00h
;dw 000cch
dw 00000h ; User data descriptor
dw 00000h ; base: 0h limit: 3gb
dw 0f200h
dw 000cch
;dw 00000h ; User data descriptor
;dw 00000h ; base: 0h limit: 3gb
;dw 0f200h
;dw 000cch
dw 00000h
dw 00000h
dw 00000h
dw 00000h
;dw 00000h
;dw 00000h
;dw 00000h
;dw 00000h
dw 0ffffh ; Kernel code descriptor
dw 00000h ;
@ -1148,7 +1151,7 @@ gdt:
dw 000cfh
times NR_TASKS*8 db 0
;times NR_TASKS*8 db 0
_end:

View file

@ -13,11 +13,9 @@
/* FUNCTIONS ****************************************************************/
VOID
ExInit (VOID)
VOID ExInit (VOID)
{
ExInitTimeZoneInfo ();
ExInitTimeZoneInfo();
}
/* EOF */

View file

@ -12,11 +12,17 @@
#include <ddk/ntddk.h>
#include <internal/ps.h>
#include <internal/debug.h>
/* DEFINES *******************************************************************/
#define NUMBER_OF_WORKER_THREADS (5)
/* TYPES *********************************************************************/
typedef struct
typedef struct _WORK_QUEUE
{
/*
* PURPOSE: Head of the list of waiting work items
@ -31,12 +37,12 @@ typedef struct
/*
* PURPOSE: Worker threads with nothing to do wait on this event
*/
KEVENT Busy;
KSEMAPHORE Sem;
/*
* PURPOSE: Thread associated with work queue
*/
HANDLE Thread;
HANDLE Thread[NUMBER_OF_WORKER_THREADS];
} WORK_QUEUE, *PWORK_QUEUE;
/* GLOBALS *******************************************************************/
@ -44,9 +50,11 @@ typedef struct
/*
* PURPOSE: Queue of items waiting to be processed at normal priority
*/
WORK_QUEUE normal_work_queue = {{0,}};
WORK_QUEUE EiNormalWorkQueue;
#define WAIT_INTERVAL (0)
WORK_QUEUE EiCriticalWorkQueue;
WORK_QUEUE EiHyperCriticalWorkQueue;
/* FUNCTIONS ****************************************************************/
@ -60,13 +68,14 @@ static NTSTATUS ExWorkerThreadEntryPoint(PVOID context)
* calls PsTerminateSystemThread
*/
{
PWORK_QUEUE param = (PWORK_QUEUE)context;
PWORK_QUEUE queue = (PWORK_QUEUE)context;
PWORK_QUEUE_ITEM item;
PLIST_ENTRY current;
while (1)
for(;;)
{
current = ExInterlockedRemoveHeadList(&param->Head,&param->Lock);
current = ExInterlockedRemoveHeadList(&queue->Head,
&queue->Lock);
if (current!=NULL)
{
item = CONTAINING_RECORD(current,WORK_QUEUE_ITEM,Entry);
@ -74,37 +83,55 @@ static NTSTATUS ExWorkerThreadEntryPoint(PVOID context)
}
else
{
KeClearEvent(&param->Busy);
KeWaitForSingleObject((PVOID)&param->Busy,Executive,KernelMode,
FALSE,WAIT_INTERVAL);
KeWaitForSingleObject((PVOID)&queue->Sem,
Executive,
KernelMode,
FALSE,
NULL);
}
};
}
}
static VOID ExKillWorkerThreadCallback(PVOID Context)
static VOID ExInitializeWorkQueue(PWORK_QUEUE WorkQueue,
KPRIORITY Priority)
{
PsTerminateSystemThread(STATUS_SUCCESS);
}
void ExKillWorkerThreads(void)
/*
* FUNCTION: Kill all running worker threads in preparation for a shutdown
*/
{
WORK_QUEUE_ITEM item1;
ULONG i;
PETHREAD Thread;
ExInitializeWorkItem(&item1,ExKillWorkerThreadCallback,NULL);
ExQueueWorkItem(&item1,DelayedWorkQueue);
InitializeListHead(&WorkQueue->Head);
KeInitializeSpinLock(&WorkQueue->Lock);
KeInitializeSemaphore(&WorkQueue->Sem,
0,
256);
for (i=0; i<NUMBER_OF_WORKER_THREADS; i++)
{
PsCreateSystemThread(&WorkQueue->Thread[i],
THREAD_ALL_ACCESS,
NULL,
NULL,
NULL,
ExWorkerThreadEntryPoint,
WorkQueue);
ObReferenceObjectByHandle(WorkQueue->Thread[i],
THREAD_ALL_ACCESS,
PsThreadType,
KernelMode,
(PVOID*)&Thread,
NULL);
KeSetPriorityThread(&Thread->Tcb,
Priority);
ObDereferenceObject(Thread);
}
}
void ExInitializeWorkerThreads(void)
VOID ExInitializeWorkerThreads(VOID)
{
InitializeListHead(&normal_work_queue.Head);
KeInitializeSpinLock(&normal_work_queue.Lock);
KeInitializeEvent(&normal_work_queue.Busy,NotificationEvent,FALSE);
PsCreateSystemThread(&normal_work_queue.Thread,THREAD_ALL_ACCESS,
NULL,NULL,NULL,ExWorkerThreadEntryPoint,
&normal_work_queue);
ExInitializeWorkQueue(&EiNormalWorkQueue,
LOW_PRIORITY);
ExInitializeWorkQueue(&EiCriticalWorkQueue,
LOW_REALTIME_PRIORITY);
ExInitializeWorkQueue(&EiHyperCriticalWorkQueue,
HIGH_PRIORITY);
}
VOID ExInitializeWorkItem(PWORK_QUEUE_ITEM Item,
@ -121,10 +148,10 @@ VOID ExInitializeWorkItem(PWORK_QUEUE_ITEM Item,
{
ASSERT_IRQL(DISPATCH_LEVEL);
Item->Routine=Routine;
Item->Context=Context;
Item->Entry.Flink=NULL;
Item->Entry.Blink=NULL;
Item->Routine = Routine;
Item->Context = Context;
Item->Entry.Flink = NULL;
Item->Entry.Blink = NULL;
}
VOID ExQueueWorkItem(PWORK_QUEUE_ITEM WorkItem,
@ -147,9 +174,34 @@ VOID ExQueueWorkItem(PWORK_QUEUE_ITEM WorkItem,
switch(QueueType)
{
case DelayedWorkQueue:
ExInterlockedInsertTailList(&normal_work_queue.Head,&(WorkItem->Entry),
&normal_work_queue.Lock);
KeSetEvent(&normal_work_queue.Busy,IO_NO_INCREMENT,FALSE);
ExInterlockedInsertTailList(&EiNormalWorkQueue.Head,
&WorkItem->Entry,
&EiNormalWorkQueue.Lock);
KeReleaseSemaphore(&EiNormalWorkQueue.Sem,
1,
IO_NO_INCREMENT,
FALSE);
break;
case CriticalWorkQueue:
ExInterlockedInsertTailList(&EiCriticalWorkQueue.Head,
&WorkItem->Entry,
&EiCriticalWorkQueue.Lock);
KeReleaseSemaphore(&EiCriticalWorkQueue.Sem,
1,
IO_NO_INCREMENT,
FALSE);
break;
case HyperCriticalWorkQueue:
ExInterlockedInsertTailList(&EiHyperCriticalWorkQueue.Head,
&WorkItem->Entry,
&EiHyperCriticalWorkQueue.Lock);
KeReleaseSemaphore(&EiHyperCriticalWorkQueue.Sem,
1,
IO_NO_INCREMENT,
FALSE);
break;
}
}

View file

@ -16,7 +16,7 @@ start:
lidt _idt_descr
lgdt _gdt_descr
movw $0x28,%ax
movw $0x10,%ax
movw %ax,%ds
popl %eax
@ -34,7 +34,7 @@ _idt_descr:
.long _KiIdt
_gdt_descr:
.word ((6+NR_TASKS)*8)-1
.word ((8+NR_TASKS)*8)-1
.long _KiGdt
/*_idt:

View file

@ -12,10 +12,192 @@
#include <ddk/ntddk.h>
#include <internal/port.h>
#include <internal/debug.h>
/* TYPES *********************************************************************/
typedef struct _IO_ERROR_LOG_PACKET
{
UCHAR MajorFunctionCode;
UCHAR RetryCount;
USHORT DumpDataSize;
USHORT NumberOfStrings;
USHORT StringOffset;
USHORT EventCategory;
NTSTATUS ErrorCode;
ULONG UniqueErrorValue;
NTSTATUS FinalStatus;
ULONG SequenceNumber;
ULONG IoControlCode;
LARGE_INTEGER DeviceOffset;
ULONG DumpData[1];
} IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
typedef struct _ERROR_LOG_MESSAGE
{
PIO_ERROR_LOG_PACKET Packet;
LIST_ENTRY ListEntry;
} IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
/* GLOBALS *******************************************************************/
static HANDLE ErrorLogPortHandle;
static HANDLE ErrorLogThreadHandle;
static PEPORT ErrorLogPort;
static LIST_ENTRY ErrorLogListHead;
static KSPIN_LOCK ErrorLogListLock;
static KSEMAPHORE ErrorLogSemaphore;
/* FUNCTIONS *****************************************************************/
static VOID IoSendErrorLogEntry(PIO_ERROR_LOG_PACKET Packet)
{
LPCMESSAGE Message;
ULONG Size;
ULONG i;
Size = sizeof(IO_ERROR_LOG_PACKET) +
(Packet->DumpDataSize * sizeof(UCHAR));
for (i=0; i<((Size % MAX_MESSAGE_DATA) - 1); i++)
{
Message.ActualMessageLength = MAX_MESSAGE_DATA;
Message.TotalMessageLength = sizeof(LPCMESSAGE);
Message.MessageType = i;
memcpy(Message.MessageData, (PVOID)Packet, MAX_MESSAGE_DATA);
LpcRequestPort(ErrorLogPort, &Message);
}
Message.ActualMessageLength = MAX_MESSAGE_DATA;
Message.TotalMessageLength = sizeof(LPCMESSAGE);
Message.MessageType = i;
memcpy(Message.MessageData, (PVOID)Packet, Size % MAX_MESSAGE_DATA);
LpcRequestPort(ErrorLogPort, &Message);
}
NTSTATUS IoErrorLogThreadMain(PVOID Context)
{
NTSTATUS Status;
LPCMESSAGE ConnectMsg;
HANDLE PortHandle;
PIO_ERROR_LOG_MESSAGE Message;
KIRQL oldIrql;
PLIST_ENTRY ListEntry;
for (;;)
{
Status = NtListenPort(ErrorLogPortHandle, &ConnectMsg);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Status = NtAcceptConnectPort(&PortHandle,
ErrorLogPortHandle,
NULL,
1,
0,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Status = NtCompleteConnectPort(PortHandle);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Status = ObReferenceObjectByHandle(PortHandle,
PORT_ALL_ACCESS,
ExPortType,
UserMode,
(PVOID*)&ErrorLogPort,
NULL);
if (!NT_SUCCESS(Status))
{
ZwClose(PortHandle);
return(Status);
}
ZwClose(PortHandle);
for (;;)
{
KeWaitForSingleObject(&ErrorLogSemaphore,
UserRequest,
KernelMode,
FALSE,
NULL);
KeAcquireSpinLock(&ErrorLogListLock, &oldIrql);
ListEntry = RemoveHeadList(&ErrorLogListHead);
KeReleaseSpinLock(&ErrorLogListLock, oldIrql);
Message = CONTAINING_RECORD(ListEntry,
IO_ERROR_LOG_MESSAGE,
ListEntry);
IoSendErrorLogEntry(Message->Packet);
ExFreePool(Message->Packet);
ExFreePool(Message);
}
}
}
NTSTATUS IoInitErrorLog(VOID)
{
NTSTATUS Status;
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING PortName;
CLIENT_ID Cid;
InitializeListHead(&ErrorLogListHead);
KeInitializeSpinLock(&ErrorLogListLock);
KeInitializeSemaphore(&ErrorLogSemaphore,
0,
500);
RtlInitUnicodeString(&PortName, L"\\ErrorLogPort");
InitializeObjectAttributes(&ObjectAttributes,
&PortName,
0,
NULL,
NULL);
Status = NtCreatePort(&ErrorLogPortHandle,
&ObjectAttributes,
0,
0,
0);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Status = PsCreateSystemThread(ErrorLogThreadHandle,
0,
NULL,
NULL,
&Cid,
IoErrorLogThreadMain,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
return(STATUS_SUCCESS);
}
PVOID IoAllocateErrorLogEntry(PVOID IoObject, UCHAR EntrySize)
{
UNIMPLEMENTED;
@ -23,6 +205,21 @@ PVOID IoAllocateErrorLogEntry(PVOID IoObject, UCHAR EntrySize)
VOID IoWriteErrorLogEntry(PVOID ElEntry)
{
UNIMPLEMENTED;
KIRQL oldIrql;
PIO_ERROR_LOG_MESSAGE Message;
Message = ExAllocatePool(NonPagedPool, sizeof(IO_ERROR_LOG_MESSAGE));
Message->Packet = (PIO_ERROR_LOG_PACKET)ElEntry;
KeAcquireSpinLock(&ErrorLogListLock, &oldIrql);
InsertTailList(&ErrorLogListHead, &Message->ListEntry);
KeReleaseSemaphore(&ErrorLogSemaphore,
IO_NO_INCREMENT,
1,
FALSE);
KeReleaseSpinLock(&ErrorLogListLock, oldIrql);
}

View file

@ -21,13 +21,9 @@ VOID ExRaiseStatus(NTSTATUS Status)
}
NTSTATUS
STDCALL
NtRaiseException (
IN PEXCEPTION_RECORD ExceptionRecord,
IN PCONTEXT Context,
IN BOOL IsDebugger OPTIONAL
)
NTSTATUS STDCALL NtRaiseException(IN PEXCEPTION_RECORD ExceptionRecord,
IN PCONTEXT Context,
IN BOOL IsDebugger OPTIONAL)
{
UNIMPLEMENTED;
UNIMPLEMENTED;
}

View file

@ -19,12 +19,14 @@
#define NR_TASKS 128
USHORT KiGdt[(6 + NR_TASKS) * 4] = {0x0, 0x0, 0x0, 0x0,
USHORT KiGdt[(8 + NR_TASKS) * 4] = {0x0, 0x0, 0x0, 0x0,
0xffff, 0x0, 0x9a00, 0xcf,
0xffff, 0x0, 0x9200, 0xcf,
0x0, 0x0, 0xfa00, 0xcc,
0x0, 0x0, 0xf200, 0xcc,
0xffff, 0x0, 0x9200, 0xcf,
0xffff, 0x0, 0x9a00, 0xcf,
0xffff, 0x0, 0x9200, 0xcf};
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0};
static KSPIN_LOCK GdtLock;
/* FUNCTIONS *****************************************************************/
@ -44,7 +46,7 @@ VOID KeFreeGdtSelector(ULONG Entry)
DPRINT("KeFreeGdtSelector(Entry %d)\n",Entry);
if (Entry > (6 + NR_TASKS))
if (Entry > (8 + NR_TASKS))
{
DPRINT1("Entry too large\n");
KeBugCheck(0);
@ -52,7 +54,9 @@ VOID KeFreeGdtSelector(ULONG Entry)
KeAcquireSpinLock(&GdtLock, &oldIrql);
KiGdt[Entry*4] = 0;
KiGdt[Entry*4 + 1] = 0;
KiGdt[Entry*4 + 2] = 0;
KiGdt[Entry*4 + 3] = 0;
KeReleaseSpinLock(&GdtLock, oldIrql);
}
@ -71,10 +75,12 @@ ULONG KeAllocateGdtSelector(ULONG Desc[2])
Desc[0], Desc[1]);
KeAcquireSpinLock(&GdtLock, &oldIrql);
for (i=6; i<(6 + NR_TASKS); i++)
for (i=8; i<(8 + NR_TASKS); i++)
{
if (KiGdt[i*4] == 0 &&
KiGdt[i*4 + 2] == 0)
KiGdt[i*4 + 1] == 0 &&
KiGdt[i*4 + 2] == 0 &&
KiGdt[i*4 + 3] == 0)
{
((PULONG)KiGdt)[i*2] = Desc[0];
((PULONG)KiGdt)[i*2 + 1] = Desc[1];

View file

@ -181,7 +181,7 @@ asmlinkage void exception_handler(unsigned int edi,
unsigned int cr2, cr3;
unsigned int i;
// unsigned int j, sym;
unsigned int* stack;
PULONG stack;
static char *TypeStrings[] =
{
"Divide Error",
@ -282,8 +282,9 @@ asmlinkage void exception_handler(unsigned int edi,
if ((cs & 0xffff) == KERNEL_CS)
{
DbgPrint("ESP %x\n",esp);
stack = (unsigned int *) (esp + 24);
stack = (PULONG) (esp + 24);
stack = (PULONG)(((ULONG)stack) & (~0x3));
DbgPrint("Stack:\n");
for (i = 0; i < 16; i = i + 4)
{
@ -309,7 +310,7 @@ asmlinkage void exception_handler(unsigned int edi,
else
{
DbgPrint("SS:ESP %x:%x\n",ss0,esp0);
stack=(unsigned int *)(esp0);
stack=(PULONG)(esp0);
DbgPrint("Stack:\n");
for (i=0; i<16; i++)
@ -348,6 +349,11 @@ VOID KeDumpStackFrames(PVOID _Stack, ULONG NrFrames)
Stack = (PVOID)(((ULONG)Stack) & (~0x3));
DbgPrint("Stack: %x\n", Stack);
if (PsGetCurrentThread() != NULL)
{
DbgPrint("kernel stack base %x\n",
PsGetCurrentThread()->Tcb.Context.KernelStackBase);
}
DbgPrint("Frames:\n");
for (i=0; i<NrFrames; i++)

View file

@ -193,7 +193,7 @@ NTSTATUS HalInitTaskWithContext(PETHREAD Thread, PCONTEXT Context)
return(STATUS_UNSUCCESSFUL);
}
stack_start = kernel_stack + 4096 - sizeof(CONTEXT);
stack_start = kernel_stack + 3*PAGESIZE - sizeof(CONTEXT);
memcpy(stack_start, Context, sizeof(CONTEXT));
/*

View file

@ -40,97 +40,86 @@
#define STACK_TOP (0xb0000000)
static NTSTATUS
LdrCreatePpb (
PRTL_USER_PROCESS_PARAMETERS *PpbPtr,
HANDLE ProcessHandle
)
static NTSTATUS LdrCreateUserProcessParameters (
PRTL_USER_PROCESS_PARAMETERS *PpbPtr,
HANDLE ProcessHandle)
{
RTL_USER_PROCESS_PARAMETERS Ppb;
PVOID PpbBase;
ULONG PpbSize;
ULONG BytesWritten;
NTSTATUS Status;
PVOID PpbBase;
ULONG PpbSize;
RTL_USER_PROCESS_PARAMETERS Ppb;
ULONG BytesWritten;
NTSTATUS Status;
/* Create process parameters block (PPB)*/
PpbBase = (PVOID)PEB_STARTUPINFO;
PpbSize = sizeof (RTL_USER_PROCESS_PARAMETERS);
/* Create process parameters block (PPB)*/
PpbBase = (PVOID)PEB_STARTUPINFO;
PpbSize = sizeof (RTL_USER_PROCESS_PARAMETERS);
Status = ZwAllocateVirtualMemory (ProcessHandle,
(PVOID*)&PpbBase,
0,
&PpbSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("Ppb allocation failed (Status %x)\n", Status);
return Status;
}
Status = NtAllocateVirtualMemory (
ProcessHandle,
(PVOID*)&PpbBase,
0,
&PpbSize,
MEM_COMMIT,
PAGE_READWRITE
);
if (!NT_SUCCESS(Status))
{
DbgPrint ("Process Parameters allocation failed \n");
DbgPrintErrorMessage (Status);
return Status;
}
/* initialize the ppb */
memset (&Ppb, 0, sizeof(RTL_USER_PROCESS_PARAMETERS));
NtWriteVirtualMemory (
ProcessHandle,
/* initialize the ppb */
memset (&Ppb, 0, sizeof(RTL_USER_PROCESS_PARAMETERS));
DPRINT("PpbBase %x\n", PpbBase);
ZwWriteVirtualMemory(ProcessHandle,
PpbBase,
&Ppb,
sizeof(RTL_USER_PROCESS_PARAMETERS),
&BytesWritten);
*PpbPtr = PpbBase;
return STATUS_SUCCESS;
*PpbPtr = PpbBase;
return STATUS_SUCCESS;
}
static NTSTATUS
LdrCreatePeb (
PPEB *PebPtr,
HANDLE ProcessHandle,
PRTL_USER_PROCESS_PARAMETERS Ppb
)
static NTSTATUS LdrCreatePeb (PPEB *PebPtr,
HANDLE ProcessHandle,
PRTL_USER_PROCESS_PARAMETERS Ppb)
{
PPEB PebBase;
ULONG PebSize;
PEB Peb;
ULONG BytesWritten;
NTSTATUS Status;
PPEB PebBase;
ULONG PebSize;
PEB Peb;
ULONG BytesWritten;
NTSTATUS Status;
PebBase = (PVOID)PEB_BASE;
PebSize = 0x1000;
Status = ZwAllocateVirtualMemory (ProcessHandle,
(PVOID*)&PebBase,
0,
&PebSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint ("Peb allocation failed (Status %x)\n", Status);
return(Status);
}
PebBase = (PVOID)PEB_BASE;
PebSize = 0x1000;
Status = ZwAllocateVirtualMemory (
ProcessHandle,
(PVOID*)&PebBase,
0,
&PebSize,
MEM_COMMIT,
PAGE_READWRITE
);
if (!NT_SUCCESS(Status))
{
DbgPrint ("Peb allocation failed \n");
DbgPrintErrorMessage (Status);
}
/* initialize the peb */
memset(&Peb, 0, sizeof Peb);
Peb.ProcessParameters = Ppb;
ZwWriteVirtualMemory (
ProcessHandle,
PebBase,
&Peb,
sizeof(Peb),
&BytesWritten);
*PebPtr = (PPEB)PebBase;
return(STATUS_SUCCESS);
/* initialize the peb */
memset(&Peb, 0, sizeof Peb);
Peb.ProcessParameters = Ppb;
ZwWriteVirtualMemory (ProcessHandle,
PebBase,
&Peb,
sizeof(Peb),
&BytesWritten);
*PebPtr = (PPEB)PebBase;
return(STATUS_SUCCESS);
}
@ -177,7 +166,7 @@ NTSTATUS LdrLoadImage(HANDLE ProcessHandle,
WCHAR TmpNameBuffer [MAX_PATH];
PRTL_USER_PROCESS_PARAMETERS Ppb;
PRTL_USER_PROCESS_PARAMETERS Ppb;
PPEB Peb;
@ -459,117 +448,102 @@ NTSTATUS LdrLoadImage(HANDLE ProcessHandle,
/* -- PART III -- */
/* Create the process parameter block (PPB) */
Status = LdrCreatePpb (&Ppb,
ProcessHandle);
if (!NT_SUCCESS(Status))
{
DPRINT("PPB creation failed ");
DbgPrintErrorMessage(Status);
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
return Status;
/* Create the process parameter block (PPB) */
DPRINT("Creating PPB\n");
Status = LdrCreateUserProcessParameters (&Ppb, ProcessHandle);
if (!NT_SUCCESS(Status))
{
DPRINT("PPB creation failed ");
DbgPrintErrorMessage(Status);
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
return Status;
}
/* Create the process environment block (PEB) */
Status = LdrCreatePeb (&Peb,
ProcessHandle,
Ppb);
if (!NT_SUCCESS(Status))
{
DPRINT("PEB creation failed ");
/* Create the process environment block (PEB) */
DPRINT("Creating Peb\n");
Status = LdrCreatePeb (&Peb,
ProcessHandle,
Ppb);
if (!NT_SUCCESS(Status))
{
DPRINT("PEB creation failed ");
DbgPrintErrorMessage(Status);
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
/* FIXME: free the PPB */
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
/* FIXME: free the PPB */
return Status;
}
}
/*
* Create page backed section for stack
*/
DPRINT("Allocating stack\n");
StackBase = (STACK_TOP - NTHeaders->OptionalHeader.SizeOfStackReserve);
StackSize = NTHeaders->OptionalHeader.SizeOfStackReserve;
DbgPrint ("Stack size %x\n", StackSize);
/*
* Create page backed section for stack
*/
StackBase = (
STACK_TOP
- NTHeaders->OptionalHeader.SizeOfStackReserve
);
StackSize =
NTHeaders->OptionalHeader.SizeOfStackReserve;
DbgPrint ("Stack size %x\n", StackSize);
Status = ZwAllocateVirtualMemory(ProcessHandle,
(PVOID*)&StackBase,
0,
&StackSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DPRINT("Stack allocation failed ");
DbgPrintErrorMessage(Status);
Status = ZwAllocateVirtualMemory(
ProcessHandle,
(PVOID *) & StackBase,
0,
& StackSize,
MEM_COMMIT,
PAGE_READWRITE
);
if (!NT_SUCCESS(Status))
{
DPRINT("Stack allocation failed ");
DbgPrintErrorMessage(Status);
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
return Status;
}
ZwDuplicateObject(NtCurrentProcess(),
&SectionHandle,
ProcessHandle,
&DupSectionHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
ZwDuplicateObject(NtCurrentProcess(),
&NTDllSectionHandle,
ProcessHandle,
&DupNTDllSectionHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
DPRINT("DupNTDllSectionHandle %x\n", DupNTDllSectionHandle);
ZwWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 4),
&DupNTDllSectionHandle,
sizeof(DupNTDllSectionHandle),
&BytesWritten);
ZwWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 8),
&ImageBase,
sizeof (ImageBase),
&BytesWritten);
ZwWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 12),
&DupSectionHandle,
sizeof (DupSectionHandle),
&BytesWritten);
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
return Status;
}
ZwDuplicateObject(
NtCurrentProcess(),
& SectionHandle,
ProcessHandle,
& DupSectionHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS
);
ZwDuplicateObject(
NtCurrentProcess(),
& NTDllSectionHandle,
ProcessHandle,
&DupNTDllSectionHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS
);
ZwWriteVirtualMemory(
ProcessHandle,
(PVOID) (STACK_TOP - 4),
& DupNTDllSectionHandle,
sizeof (DupNTDllSectionHandle),
& BytesWritten
);
ZwWriteVirtualMemory(
ProcessHandle,
(PVOID) (STACK_TOP - 8),
& ImageBase,
sizeof (ImageBase),
& BytesWritten
);
ZwWriteVirtualMemory(
ProcessHandle,
(PVOID) (STACK_TOP - 12),
& DupSectionHandle,
sizeof (DupSectionHandle),
& BytesWritten
);
/* write pointer to peb on the stack (parameter of NtProcessStartup) */
ZwWriteVirtualMemory(
ProcessHandle,
(PVOID) (STACK_TOP - 16),
&Peb,
sizeof (ULONG),
&BytesWritten
);
DbgPrint ("NTOSKRNL: Peb = %x\n", Peb);
/* write pointer to peb on the stack (parameter of NtProcessStartup) */
ZwWriteVirtualMemory(ProcessHandle,
(PVOID) (STACK_TOP - 16),
&Peb,
sizeof (ULONG),
&BytesWritten);
DbgPrint ("NTOSKRNL: Peb = %x\n", Peb);
/*
* Initialize context to point to LdrStartup
*/

View file

@ -1,4 +1,4 @@
# $Id: makefile_rex,v 1.48 2000/01/20 22:14:08 ea Exp $
# $Id: makefile_rex,v 1.49 2000/01/26 10:07:24 dwelch Exp $
#
# ReactOS Operating System
#
@ -58,7 +58,8 @@ EX_OBJECTS = ex/work.o ex/fmutex.o ex/resource.o ex/time.o ex/interlck.o \
FS_OBJECTS = fs/mcb.o fs/unc.o fs/util.o
SE_OBJECTS = se/semgr.o se/acl.o se/sid.o se/sd.o se/token.o se/luid.o
SE_OBJECTS = se/semgr.o se/acl.o se/sid.o se/sd.o se/token.o se/luid.o \
se/priv.o
CM_OBJECTS = cm/registry.o

View file

@ -138,6 +138,19 @@ static MEMORY_AREA* MmInternalOpenMemoryAreaByAddress(PLIST_ENTRY ListHead,
DPRINT("Scanning %x BaseAddress %x Length %x\n",
current, current->BaseAddress, current->Length);
assert(current_entry->Blink->Flink == current_entry);
if (current_entry->Flink->Blink != current_entry)
{
DPRINT("BaseAddress %x\n", current->BaseAddress);
DPRINT("current_entry->Flink %x ", current_entry->Flink);
DPRINT("&current_entry->Flink %x\n",
&current_entry->Flink);
DPRINT("current_entry->Flink->Blink %x\n",
current_entry->Flink->Blink);
DPRINT("&current_entry->Flink->Blink %x\n",
&current_entry->Flink->Blink);
DPRINT("&current_entry->Flink %x\n",
&current_entry->Flink);
}
assert(current_entry->Flink->Blink == current_entry);
assert(previous_entry->Flink == current_entry);
if (current->BaseAddress <= Address &&
@ -170,7 +183,7 @@ MEMORY_AREA* MmInternalOpenMemoryAreaByRegion(PLIST_ENTRY ListHead,
DPRINT("MmInternalOpenMemoryAreaByRegion(ListHead %x, Address %x, "
"Length %x)\n",ListHead,Address,Length);
// MmDumpMemoryAreas();
// MmDumpMemoryAreas(ListHead);
current_entry = ListHead->Flink;
while (current_entry!=ListHead)
@ -179,7 +192,7 @@ MEMORY_AREA* MmInternalOpenMemoryAreaByRegion(PLIST_ENTRY ListHead,
DPRINT("current->BaseAddress %x current->Length %x\n",
current->BaseAddress,current->Length);
if (current->BaseAddress >= Address &&
current->BaseAddress <= (Address+Length))
current->BaseAddress < (Address+Length))
{
DPRINT("Finished MmInternalOpenMemoryAreaByRegion() = %x\n",
current);
@ -273,7 +286,7 @@ static VOID MmInsertMemoryAreaWithoutLock(PEPROCESS Process,
{
PLIST_ENTRY ListHead;
PLIST_ENTRY current_entry;
PLIST_ENTRY inserted_entry = &(marea->Entry);
PLIST_ENTRY inserted_entry = &marea->Entry;
MEMORY_AREA* current;
MEMORY_AREA* next;
@ -288,6 +301,7 @@ static VOID MmInsertMemoryAreaWithoutLock(PEPROCESS Process,
{
CHECKPOINT;
InsertHeadList(ListHead,&marea->Entry);
DPRINT("Inserting at list head\n");
CHECKPOINT;
return;
}
@ -298,6 +312,7 @@ static VOID MmInsertMemoryAreaWithoutLock(PEPROCESS Process,
{
CHECKPOINT;
InsertHeadList(ListHead,&marea->Entry);
DPRINT("Inserting at list head\n");
CHECKPOINT;
return;
}
@ -312,15 +327,17 @@ static VOID MmInsertMemoryAreaWithoutLock(PEPROCESS Process,
if (current->BaseAddress < marea->BaseAddress &&
current->Entry.Flink==ListHead)
{
DPRINT("Insert after %x\n", current_entry);
current_entry->Flink = inserted_entry;
inserted_entry->Flink=ListHead;
inserted_entry->Blink=current_entry;
ListHead->Blink = inserted_entry;
ListHead->Blink = inserted_entry;
return;
}
if (current->BaseAddress < marea->BaseAddress &&
next->BaseAddress > marea->BaseAddress)
{
DPRINT("Inserting before %x\n", current_entry);
inserted_entry->Flink = current_entry->Flink;
inserted_entry->Blink = current_entry;
inserted_entry->Flink->Blink = inserted_entry;
@ -330,6 +347,7 @@ static VOID MmInsertMemoryAreaWithoutLock(PEPROCESS Process,
current_entry = current_entry->Flink;
}
CHECKPOINT;
DPRINT("Inserting at list tail\n");
InsertTailList(ListHead,inserted_entry);
}

View file

@ -130,7 +130,8 @@ VOID MmBuildMdlFromPages(PMDL Mdl)
}
VOID MmProbeAndLockPages(PMDL Mdl, KPROCESSOR_MODE AccessMode,
VOID MmProbeAndLockPages(PMDL Mdl,
KPROCESSOR_MODE AccessMode,
LOCK_OPERATION Operation)
/*
* FUNCTION: Probes the specified pages, makes them resident and locks them

View file

@ -1,4 +1,4 @@
/* $Id: port.c,v 1.16 2000/01/12 19:04:01 ekohl Exp $
/* $Id: port.c,v 1.17 2000/01/26 10:07:28 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -24,6 +24,7 @@
#include <internal/ob.h>
#include <string.h>
#include <internal/string.h>
#include <internal/port.h>
#define NDEBUG
#include <internal/debug.h>
@ -31,8 +32,6 @@
/* TYPES ********************************************************************/
#define PORT_ALL_ACCESS (0x1)
#define EPORT_INACTIVE (0)
#define EPORT_WAIT_FOR_CONNECT (1)
#define EPORT_WAIT_FOR_ACCEPT (2)
@ -49,23 +48,6 @@ typedef struct _QUEUEDMESSAGE
LPCMESSAGE Message;
} QUEUEDMESSAGE, *PQUEUEDMESSAGE;
typedef struct _EPORT
{
KSPIN_LOCK Lock;
KEVENT Event;
struct _EPORT* OtherPort;
ULONG QueueLength;
LIST_ENTRY QueueListHead;
ULONG ConnectQueueLength;
LIST_ENTRY ConnectQueueListHead;
ULONG MaxDataLength;
ULONG MaxConnectInfoLength;
} EPORT, *PEPORT;
/* GLOBALS *******************************************************************/
POBJECT_TYPE ExPortType = NULL;
@ -603,6 +585,21 @@ NTSTATUS STDCALL NtReplyWaitReceivePort (IN HANDLE PortHandle,
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL LpcRequestPort(PEPORT Port,
PLPCMESSAGE LpcMessage)
{
NTSTATUS Status;
DPRINT("LpcRequestPort(PortHandle %x LpcMessage %x)\n", Port, LpcMessage);
Status = EiReplyOrRequestPort(Port->OtherPort,
LpcMessage,
LPC_DATAGRAM,
Port);
KeSetEvent(&Port->OtherPort->Event, IO_NO_INCREMENT, FALSE);
return(Status);
}
NTSTATUS STDCALL NtRequestPort (IN HANDLE PortHandle,
IN PLPCMESSAGE LpcMessage /* guess */)
@ -625,11 +622,7 @@ NTSTATUS STDCALL NtRequestPort (IN HANDLE PortHandle,
return(Status);
}
Status = EiReplyOrRequestPort(Port->OtherPort,
LpcMessage,
LPC_DATAGRAM,
Port);
KeSetEvent(&Port->OtherPort->Event, IO_NO_INCREMENT, FALSE);
Status = LpcRequestPort(Port, LpcMessage);
ObDereferenceObject(Port);
return(Status);

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.7 2000/01/05 21:57:00 dwelch Exp $
/* $Id: create.c,v 1.8 2000/01/26 10:07:29 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -307,11 +307,11 @@ VOID PiCloseThread(PVOID ObjectBody, ULONG HandleCount)
ObGetHandleCount(ObjectBody));
}
NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
PETHREAD * ThreadPtr,
PHANDLE ThreadHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ThreadAttributes)
NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
PETHREAD* ThreadPtr,
PHANDLE ThreadHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ThreadAttributes)
{
PETHREAD Thread;
NTSTATUS Status;
@ -363,7 +363,7 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
Thread->Tcb.KernelApcDisable = 1;
Thread->Tcb.WaitIrql = PASSIVE_LEVEL;
Thread->ThreadsProcess = Process;
KeInitializeDpc( &Thread->Tcb.TimerDpc, PiTimeoutThread, Thread );
KeInitializeDpc(&Thread->Tcb.TimerDpc, PiTimeoutThread, Thread);
Thread->Tcb.WaitBlockList = NULL;
InsertTailList( &Thread->ThreadsProcess->Pcb.ThreadListHead, &Thread->Tcb.ProcessThreadListEntry );
KeInitializeDispatcherHeader(&Thread->Tcb.DispatcherHeader,
@ -395,7 +395,7 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
PETHREAD Thread,
PINITIAL_TEB InitialTeb)
{
MEMORY_BASIC_INFORMATION Info;
// MEMORY_BASIC_INFORMATION Info;
NTSTATUS Status;
ULONG ByteCount;
ULONG RegionSize;
@ -423,9 +423,12 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
else
{
DPRINT ("TEB allocation failed! Status %x\n",Status);
for(;;);
return(Status);
}
TebBase = Info.BaseAddress - TebSize;
// TebBase = Info.BaseAddress - TebSize;
TebBase = TebBase - TebSize;
}
DPRINT ("TebBase %p TebSize %lu\n", TebBase, TebSize);

View file

@ -334,7 +334,7 @@ NTSTATUS STDCALL NtCreateProcess (
InitializeListHead( &KProcess->ThreadListHead );
KeReleaseSpinLock(&PsProcessListLock, oldIrql);
Status = PsCreatePeb (*ProcessHandle);
Status = PsCreatePeb(*ProcessHandle);
if (!NT_SUCCESS(Status))
{
// DPRINT("NtCreateProcess() Peb creation failed: Status %x\n",Status);
@ -358,14 +358,10 @@ NTSTATUS STDCALL NtCreateProcess (
}
NTSTATUS
STDCALL
NtOpenProcess (
OUT PHANDLE ProcessHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes,
IN PCLIENT_ID ClientId
)
NTSTATUS STDCALL NtOpenProcess (OUT PHANDLE ProcessHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes,
IN PCLIENT_ID ClientId)
{
DPRINT("NtOpenProcess(ProcessHandle %x, DesiredAccess %x, "
"ObjectAttributes %x, ClientId %x { UniP %d, UniT %d })\n",
@ -444,15 +440,11 @@ NtOpenProcess (
}
NTSTATUS
STDCALL
NtQueryInformationProcess (
IN HANDLE ProcessHandle,
IN CINT ProcessInformationClass,
OUT PVOID ProcessInformation,
IN ULONG ProcessInformationLength,
OUT PULONG ReturnLength
)
NTSTATUS STDCALL NtQueryInformationProcess (IN HANDLE ProcessHandle,
IN CINT ProcessInformationClass,
OUT PVOID ProcessInformation,
IN ULONG ProcessInformationLength,
OUT PULONG ReturnLength)
{
PEPROCESS Process;
NTSTATUS Status;
@ -474,7 +466,8 @@ NtQueryInformationProcess (
case ProcessBasicInformation:
ProcessBasicInformationP = (PPROCESS_BASIC_INFORMATION)
ProcessInformation;
memset(ProcessBasicInformationP, 0, sizeof(PROCESS_BASIC_INFORMATION));
ProcessBasicInformationP->ExitStatus = Process->ExitStatus;
ProcessBasicInformationP->PebBaseAddress = Process->Peb;
ProcessBasicInformationP->AffinityMask = Process->Pcb.Affinity;
ProcessBasicInformationP->UniqueProcessId =
Process->UniqueProcessId;
@ -494,7 +487,13 @@ NtQueryInformationProcess (
case ProcessAccessToken:
case ProcessLdtInformation:
case ProcessLdtSize:
Status = STATUS_NOT_IMPLEMENTED;
break;
case ProcessDefaultHardErrorMode:
*((PULONG)ProcessInformation) = Process->DefaultHardErrorProcessing;
break;
case ProcessIoPortHandlers:
case ProcessWorkingSetWatch:
case ProcessUserModeIOPL:
@ -510,19 +509,41 @@ NtQueryInformationProcess (
return(Status);
}
NTSTATUS PspAssignPrimaryToken(PEPROCESS Process,
HANDLE TokenHandle)
{
PACCESS_TOKEN Token;
PACCESS_TOKEN OldToken;
NTSTATUS Status;
Status = ObReferenceObjectByHandle(TokenHandle,
0,
SeTokenType,
UserMode,
(PVOID*)&Token,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Status = SeExchangePrimaryToken(Process, Token, &OldToken);
if (!NT_SUCCESS(Status))
{
ObDereferenceObject(OldToken);
}
ObDereferenceObject(Token);
return(Status);
}
NTSTATUS
STDCALL
NtSetInformationProcess (
IN HANDLE ProcessHandle,
IN CINT ProcessInformationClass,
IN PVOID ProcessInformation,
IN ULONG ProcessInformationLength
)
NTSTATUS STDCALL NtSetInformationProcess(IN HANDLE ProcessHandle,
IN CINT ProcessInformationClass,
IN PVOID ProcessInformation,
IN ULONG ProcessInformationLength)
{
PEPROCESS Process;
NTSTATUS Status;
PPROCESS_BASIC_INFORMATION ProcessBasicInformationP;
PHANDLE ProcessAccessTokenP;
Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_SET_INFORMATION,
@ -530,7 +551,7 @@ NtSetInformationProcess (
UserMode,
(PVOID*)&Process,
NULL);
if (Status != STATUS_SUCCESS)
if (!NT_SUCCESS(Status))
{
return(Status);
}
@ -554,6 +575,10 @@ NtSetInformationProcess (
case ProcessDebugPort:
case ProcessExceptionPort:
case ProcessAccessToken:
ProcessAccessTokenP = (PHANDLE)ProcessInformation;
Status = PspAssignPrimaryToken(Process, *ProcessAccessTokenP);
break;
case ProcessLdtInformation:
case ProcessLdtSize:
case ProcessDefaultHardErrorMode:

244
reactos/ntoskrnl/se/priv.c Normal file
View file

@ -0,0 +1,244 @@
/* $Id: priv.c,v 1.1 2000/01/26 10:07:30 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Security manager
* FILE: kernel/se/priv.c
* PROGRAMER: ?
* REVISION HISTORY:
* 26/07/98: Added stubs for security functions
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS ***************************************************************/
BOOLEAN SepPrivilegeCheck(PACCESS_TOKEN Token,
PLUID_AND_ATTRIBUTES Privileges,
ULONG PrivilegeCount,
ULONG PrivilegeControl,
KPROCESSOR_MODE PreviousMode)
{
ULONG i;
PLUID_AND_ATTRIBUTES Current;
ULONG j;
ULONG k;
if (PreviousMode == KernelMode)
{
return(TRUE);
}
j = 0;
if (PrivilegeCount != 0)
{
k = PrivilegeCount;
do
{
i = Token->PrivilegeCount;
Current = Token->Privileges;
for (i = 0; i < Token->PrivilegeCount; i++)
{
if (!(Current[i].Attributes & SE_PRIVILEGE_ENABLED) &&
Privileges[i].Luid.u.LowPart ==
Current[i].Luid.u.LowPart &&
Privileges[i].Luid.u.HighPart ==
Current[i].Luid.u.HighPart)
{
Privileges[i].Attributes =
Privileges[i].Attributes |
SE_PRIVILEGE_USED_FOR_ACCESS;
j++;
break;
}
}
k--;
} while (k > 0);
}
if ((PrivilegeControl & PRIVILEGE_SET_ALL_NECESSARY) &&
PrivilegeCount == j)
{
return(TRUE);
}
if (j > 0 &&
!(PrivilegeControl & PRIVILEGE_SET_ALL_NECESSARY))
{
return(TRUE);
}
return(FALSE);
}
NTSTATUS SeCaptureLuidAndAttributesArray(PLUID_AND_ATTRIBUTES Src,
ULONG PrivilegeCount,
KPROCESSOR_MODE PreviousMode,
PLUID_AND_ATTRIBUTES AllocatedMem,
ULONG AllocatedLength,
POOL_TYPE PoolType,
ULONG d,
PLUID_AND_ATTRIBUTES* Dest,
PULONG Length)
{
PLUID_AND_ATTRIBUTES* NewMem;
ULONG SrcLength;
if (PrivilegeCount == 0)
{
*Dest = 0;
*Length = 0;
return(STATUS_SUCCESS);
}
if (PreviousMode == 0 && d == 0)
{
*Dest = Src;
return(STATUS_SUCCESS);
}
SrcLength = ((PrivilegeCount * sizeof(LUID_AND_ATTRIBUTES)) + 3) & 0xfc;
*Length = SrcLength;
if (AllocatedMem == NULL)
{
NewMem = ExAllocatePool(PoolType, SrcLength);
*Dest = (PLUID_AND_ATTRIBUTES)NewMem;
if (NewMem == NULL)
{
return(STATUS_UNSUCCESSFUL);
}
}
else
{
if (SrcLength > AllocatedLength)
{
return(STATUS_UNSUCCESSFUL);
}
*Dest = AllocatedMem;
}
memmove(*Dest, Src, SrcLength);
return(STATUS_SUCCESS);
}
VOID SeReleaseLuidAndAttributesArray(PLUID_AND_ATTRIBUTES Privilege,
KPROCESSOR_MODE PreviousMode,
ULONG a)
{
ExFreePool(Privilege);
}
NTSTATUS STDCALL NtPrivilegeCheck (IN HANDLE ClientToken,
IN PPRIVILEGE_SET RequiredPrivileges,
IN PBOOLEAN Result)
{
NTSTATUS Status;
PACCESS_TOKEN Token;
ULONG PrivilegeCount;
BOOLEAN TResult;
ULONG PrivilegeControl;
PLUID_AND_ATTRIBUTES Privilege;
ULONG Length;
Status = ObReferenceObjectByHandle(ClientToken,
0,
SeTokenType,
UserMode,
(PVOID*)&Token,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
if (Token->TokenType == TokenImpersonation &&
Token->ImpersonationLevel < SecurityAnonymous)
{
ObDereferenceObject(Token);
return(STATUS_UNSUCCESSFUL);
}
PrivilegeCount = RequiredPrivileges->PrivilegeCount;
PrivilegeControl = RequiredPrivileges->Control;
Privilege = 0;
Status = SeCaptureLuidAndAttributesArray(RequiredPrivileges->Privilege,
PrivilegeCount,
1,
0,
0,
1,
1,
&Privilege,
&Length);
if (!NT_SUCCESS(Status))
{
ObDereferenceObject(Token);
return(STATUS_UNSUCCESSFUL);
}
TResult = SepPrivilegeCheck(Token,
Privilege,
PrivilegeCount,
PrivilegeControl,
UserMode);
memmove(RequiredPrivileges->Privilege, Privilege, Length);
*Result = TResult;
SeReleaseLuidAndAttributesArray(Privilege, UserMode, 1);
return(STATUS_SUCCESS);
}
BOOLEAN STDCALL SePrivilegeCheck(PPRIVILEGE_SET Privileges,
PSECURITY_SUBJECT_CONTEXT SubjectContext,
KPROCESSOR_MODE PreviousMode)
{
PACCESS_TOKEN Token = NULL;
if (SubjectContext->ClientToken == NULL)
{
Token = SubjectContext->PrimaryToken;
}
else
{
Token = SubjectContext->ClientToken;
if (SubjectContext->ImpersonationLevel < 2)
{
return(FALSE);
}
}
return(SepPrivilegeCheck(Token,
Privileges->Privilege,
Privileges->PrivilegeCount,
Privileges->Control,
PreviousMode));
}
BOOLEAN STDCALL SeSinglePrivilegeCheck(LUID PrivilegeValue,
KPROCESSOR_MODE PreviousMode)
{
SECURITY_SUBJECT_CONTEXT SubjectContext;
BOOLEAN r;
PRIVILEGE_SET Priv;
SeCaptureSubjectContext(&SubjectContext);
Priv.PrivilegeCount = 1;
Priv.Control = 1;
Priv.Privilege[0].Luid = PrivilegeValue;
Priv.Privilege[0].Attributes = 0;
r = SePrivilegeCheck(&Priv,
&SubjectContext,
PreviousMode);
if (PreviousMode != KernelMode)
{
#if 0
SePrivilegeServiceAuditAlarm(0,
&SubjectContext,
&PrivilegeValue);
#endif
}
SeReleaseSubjectContext(&SubjectContext);
return(r);
}

View file

@ -1,4 +1,4 @@
/* $Id: semgr.c,v 1.14 2000/01/05 21:57:00 dwelch Exp $
/* $Id: semgr.c,v 1.15 2000/01/26 10:07:30 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -27,266 +27,6 @@ VOID SepDeReferenceLogonSession(PLUID AuthenticationId)
UNIMPLEMENTED;
}
VOID SepFreeProxyData(PVOID ProxyData)
{
UNIMPLEMENTED;
}
NTSTATUS SepCopyProxyData(PVOID* Dest, PVOID Src)
{
UNIMPLEMENTED;
}
NTSTATUS SepDuplicationToken(PACCESS_TOKEN Token,
PULONG a,
ULONG b,
TOKEN_TYPE TokenType,
SECURITY_IMPERSONATION_LEVEL Level,
ULONG d,
PACCESS_TOKEN* e)
{
#if 0
PVOID mem1;
PVOID mem2;
PVOID f;
PACCESS_TOKEN g;
NTSTATUS Status;
if (TokenType == 2 &&
(Level > 3 || Level < 0))
{
return(STATUS_UNSUCCESSFUL);
}
SepReferenceLogonSession(&Token->AuthenticationId);
mem1 = ExAllocatePool(NonPagedPool, Token->DynamicCharged);
if (mem1 == NULL)
{
SepDeReferenceLogonSession(&Token->AuthenticationId);
return(STATUS_UNSUCCESSFUL);
}
if (Token->ProxyData != NULL)
{
Status = SepCopyProxyData(&f, Token->ProxyData);
if (!NT_SUCCESS(Status))
{
SepDeReferenceLogonSession(&Token->AuthenticationId);
ExFreePool(mem1);
return(Status);
}
}
else
{
f = 0;
}
if (Token->AuditData != NULL)
{
mem2 = ExAllocatePool(NonPagedPool, 0xc);
if (mem2 == NULL)
{
SepFreeProxyData(f);
SepDeReferenceLogonSession(&Token->AuthenticationId);
ExFreePool(mem1);
return(STATUS_UNSUCCESSFUL);
}
memcpy(mem2, Token->AuditData, 0xc);
}
else
{
mem2 = NULL;
}
Status = ObCreateObject(d,
SeTokenType,
b,
d,
0,
Token->VariableLength + 0x78,
Token->DynamicCharged,
Token->VariableLength + 0x78,
&g);
if (!NT_SUCCESS(Status))
{
SepDeReferenceLogonSession(Token->AuthenticationId);
ExFreePool(mem1);
SepFreeProxyData(f);
if (mem2 != NULL)
{
ExFreePool(mem2);
}
return(Status);
}
g->TokenId = Token->TokenId;
g->ModifiedId = Token->ModifiedId;
g->ExpirationTime = Token->ExpirationTime;
memcpy(&g->TokenSource, &Token->TokenSource, sizeof(TOKEN_SOURCE));
g->DynamicCharged = Token->DynamicCharged;
g->DynamicAvailable = Token->DynamicAvailable;
g->DefaultOwnerIndex = Token->DefaultOwnerIndex;
g->UserAndGroupCount = Token->UserAndGroupCount;
g->PrivilegeCount = Token->PrivilegeCount;
g->VariableLength = Token->VariableLength;
g->TokenFlags = Token->TokenFlags;
g->ProxyData = f;
g->AuditData = mem2;
//g->TokenId = ExInterlockedExchangeAdd();
g->TokenInUse = 0;
g->TokenType = TokenType;
g->ImpersonationLevel = Level;
memmove(g->VariablePart, Token->VariablePart, Token->VariableLength);
/* ... */
*e = g;
return(STATUS_SUCCESS);
#endif
UNIMPLEMENTED;
}
NTSTATUS SeCopyClientToken(PACCESS_TOKEN Token,
SECURITY_IMPERSONATION_LEVEL Level,
ULONG a,
PACCESS_TOKEN* b)
{
ULONG c;
PACCESS_TOKEN d;
NTSTATUS Status;
c = 18;
Status = SepDuplicationToken(Token,
&c,
0,
TokenImpersonation,
Level,
a,
&d);
*b = d;
return(Status);
}
NTSTATUS SeCreateClientSecurity(PETHREAD Thread,
PSECURITY_QUALITY_OF_SERVICE Qos,
ULONG e,
PSE_SOME_STRUCT2 f)
{
TOKEN_TYPE TokenType;
UCHAR b;
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
PACCESS_TOKEN Token;
ULONG g;
PACCESS_TOKEN NewToken;
Token = PsReferenceEffectiveToken(Thread,
&TokenType,
&b,
&ImpersonationLevel);
if (TokenType != 2)
{
f->Unknown9 = Qos->EffectiveOnly;
}
else
{
if (Qos->ImpersonationLevel > ImpersonationLevel)
{
if (Token != NULL)
{
ObDereferenceObject(Token);
}
return(STATUS_UNSUCCESSFUL);
}
if (ImpersonationLevel == 0 ||
ImpersonationLevel == 1 ||
(e != 0 && ImpersonationLevel != 3))
{
if (Token != NULL)
{
ObDereferenceObject(Token);
}
return(STATUS_UNSUCCESSFUL);
}
if (b != 0 ||
Qos->EffectiveOnly != 0)
{
f->Unknown9 = 1;
}
else
{
f->Unknown9 = 0;
}
}
if (Qos->ContextTrackingMode == 0)
{
f->Unknown8 = 0;
g = SeCopyClientToken(Token, ImpersonationLevel, 0, &NewToken);
if (g >= 0)
{
// ObDeleteCapturedInsertInfo(NewToken);
}
if (TokenType == TokenPrimary || Token != NULL)
{
ObDereferenceObject(Token);
}
if (g < 0)
{
return(g);
}
}
else
{
f->Unknown8 = 1;
if (e != 0)
{
// SeGetTokenControlInformation(Token, &f->Unknown11);
}
NewToken = Token;
}
f->Unknown1 = 0xc;
f->Level = Qos->ImpersonationLevel;
f->ContextTrackingMode = Qos->ContextTrackingMode;
f->EffectiveOnly = Qos->EffectiveOnly;
f->Unknown10 = e;
f->Token = NewToken;
return(STATUS_SUCCESS);
}
VOID SeImpersonateClient(PSE_SOME_STRUCT2 a,
PETHREAD Thread)
{
UCHAR b;
if (a->Unknown8 == 0)
{
b = a->EffectiveOnly;
}
else
{
b = a->Unknown9;
}
if (Thread == NULL)
{
Thread = PsGetCurrentThread();
}
PsImpersonateClient(Thread,
a->Token,
1,
(ULONG)b,
a->Level);
}
NTSTATUS STDCALL NtPrivilegeCheck (IN HANDLE ClientToken,
IN PPRIVILEGE_SET RequiredPrivileges,
IN PBOOLEAN Result)
{
UNIMPLEMENTED;
}
NTSTATUS STDCALL NtPrivilegedServiceAuditAlarm(
IN PUNICODE_STRING SubsystemName,
IN PUNICODE_STRING ServiceName,
@ -392,6 +132,8 @@ NtDeleteObjectAuditAlarm (
UNIMPLEMENTED;
}
VOID STDCALL SeReleaseSubjectContext (PSECURITY_SUBJECT_CONTEXT SubjectContext)
{
ObDereferenceObject(SubjectContext->PrimaryToken);
@ -417,129 +159,127 @@ VOID STDCALL SeCaptureSubjectContext (PSECURITY_SUBJECT_CONTEXT SubjectContext)
&SubjectContext->ImpersonationLevel);
SubjectContext->PrimaryToken = PsReferencePrimaryToken(Process);
}
BOOLEAN SepPrivilegeCheck(PACCESS_TOKEN Token,
PLUID_AND_ATTRIBUTES Privileges,
ULONG PrivilegeCount,
ULONG PrivilegeControl,
KPROCESSOR_MODE PreviousMode)
NTSTATUS STDCALL SeDeassignSecurity(PSECURITY_DESCRIPTOR* SecurityDescriptor)
{
ULONG i;
PLUID_AND_ATTRIBUTES Current;
ULONG j;
ULONG k;
if (PreviousMode == KernelMode)
if ((*SecurityDescriptor) != NULL)
{
return(TRUE);
ExFreePool(*SecurityDescriptor);
(*SecurityDescriptor) = NULL;
}
j = 0;
if (PrivilegeCount != 0)
{
k = PrivilegeCount;
do
{
i = Token->PrivilegeCount;
Current = Token->Privileges;
for (i = 0; i < Token->PrivilegeCount; i++)
{
if (!(Current[i].Attributes & 2) &&
Privileges[i].Luid.u.LowPart ==
Current[i].Luid.u.LowPart &&
Privileges[i].Luid.u.HighPart ==
Current[i].Luid.u.HighPart)
{
Privileges[i].Attributes =
Privileges[i].Attributes | 0x80;
j++;
break;
}
}
k--;
} while (k > 0);
}
if ((PrivilegeControl & 0x2) && PrivilegeCount == j)
{
return(TRUE);
}
if (j > 0 && !(PrivilegeControl & 0x2))
{
return(TRUE);
}
return(FALSE);
return(STATUS_SUCCESS);
}
BOOLEAN STDCALL SePrivilegeCheck(PPRIVILEGE_SET Privileges,
PSECURITY_SUBJECT_CONTEXT SubjectContext,
KPROCESSOR_MODE PreviousMode)
#if 0
VOID SepGetDefaultsSubjectContext(PSECURITY_SUBJECT_CONTEXT SubjectContext,
PSID* Owner,
PSID* PrimaryGroup,
PSID* ProcessOwner,
PSID* ProcessPrimaryGroup,
PACL* DefaultDacl)
{
PACCESS_TOKEN Token = NULL;
PACCESS_TOKEN Token;
if (SubjectContext->ClientToken == NULL)
if (SubjectContext->ClientToken != NULL)
{
Token = SubjectContext->PrimaryToken;
Token = SubjectContext->ClientToken;
}
else
{
Token = SubjectContext->ClientToken;
if (SubjectContext->ImpersonationLevel < 2)
{
return(FALSE);
}
Token = SubjectContext->PrimaryToken;
}
return(SepPrivilegeCheck(Token,
Privileges->Privilege,
Privileges->PrivilegeCount,
Privileges->Control,
PreviousMode));
*Owner = Token->UserAndGroups[Token->DefaultOwnerIndex].Sid;
*PrimaryGroup = Token->PrimaryGroup;
*DefaultDacl = Token->DefaultDacl;
*ProcessOwner = SubjectContext->PrimaryToken->
UserAndGroups[Token->DefaultOwnerIndex].Sid;
*ProcessPrimaryGroup = SubjectContext->PrimaryToken->PrimaryGroup;
}
BOOLEAN STDCALL SeSinglePrivilegeCheck(LUID PrivilegeValue,
KPROCESSOR_MODE PreviousMode)
NTSTATUS SepInheritAcl(PACL Acl,
BOOLEAN IsDirectoryObject,
PSID Owner,
PSID PrimaryGroup,
PACL DefaultAcl,
PSID ProcessOwner,
PSID ProcessGroup,
PGENERIC_MAPPING GenericMapping)
{
SECURITY_SUBJECT_CONTEXT SubjectContext;
BOOLEAN r;
PRIVILEGE_SET Priv;
SeCaptureSubjectContext(&SubjectContext);
Priv.PrivilegeCount = 1;
Priv.Control = 1;
Priv.Privilege[0].Luid = PrivilegeValue;
Priv.Privilege[0].Attributes = 0;
r = SePrivilegeCheck(&Priv,
&SubjectContext,
PreviousMode);
if (PreviousMode != KernelMode)
if (Acl == NULL)
{
/* SePrivilegeServiceAuditAlarm(0,
&SubjectContext,
&PrivilegeValue);*/
return(STATUS_UNSUCCESSFUL);
}
SeReleaseSubjectContext(&SubjectContext);
return(r);
}
NTSTATUS STDCALL SeDeassignSecurity(PSECURITY_DESCRIPTOR* SecurityDescriptor)
{
UNIMPLEMENTED;
if (Acl->AclRevision != 2 &&
Acl->AclRevision != 3 )
{
return(STATUS_UNSUCCESSFUL);
}
}
#endif
NTSTATUS STDCALL SeAssignSecurity(PSECURITY_DESCRIPTOR ParentDescriptor,
PSECURITY_DESCRIPTOR ExplicitDescriptor,
PSECURITY_DESCRIPTOR* NewDescriptor,
BOOLEAN IsDirectoryObject,
PSECURITY_SUBJECT_CONTEXT SubjectContext,
PGENERIC_MAPPING GenericMapping,
POOL_TYPE PoolType)
{
UNIMPLEMENTED;
#if 0
PSECURITY_DESCRIPTOR Descriptor;
PSID Owner;
PSID PrimaryGroup;
PACL DefaultDacl;
PSID ProcessOwner;
PSID ProcessPrimaryGroup;
PACL Sacl;
if (ExplicitDescriptor == NULL)
{
RtlCreateSecurityDescriptor(&Descriptor, 1);
}
else
{
Descriptor = ExplicitDescriptor;
}
SeLockSubjectContext(SubjectContext);
SepGetDefaultsSubjectContext(SubjectContext,
&Owner,
&PrimaryGroup,
&DefaultDacl,
&ProcessOwner,
&ProcessPrimaryGroup);
if (Descriptor->Control & SE_SACL_PRESENT ||
Descriptor->Control & SE_SACL_DEFAULTED)
{
if (ParentDescriptor == NULL)
{
}
if (Descriptor->Control & SE_SACL_PRESENT ||
Descriptor->Sacl == NULL ||)
{
Sacl = NULL;
}
else
{
Sacl = Descriptor->Sacl;
if (Descriptor->Control & SE_SELF_RELATIVE)
{
Sacl = (PACL)(((PVOID)Sacl) + (PVOID)Descriptor);
}
}
SepInheritAcl(Sacl,
IsDirectoryObject,
Owner,
PrimaryGroup,
DefaultDacl,
ProcessOwner,
GenericMapping);
}
#else
UNIMPLEMENTED;
#endif
}
BOOLEAN SepSidInToken(PACCESS_TOKEN Token,
@ -557,7 +297,7 @@ BOOLEAN SepSidInToken(PACCESS_TOKEN Token,
if (RtlEqualSid(Sid, Token->UserAndGroups[i].Sid))
{
if (i == 0 ||
(!(Token->UserAndGroups[i].Attributes & 0x4)))
(!(Token->UserAndGroups[i].Attributes & SE_GROUP_ENABLED)))
{
return(TRUE);
}

View file

@ -1,4 +1,4 @@
/* $Id: token.c,v 1.3 2000/01/05 21:57:00 dwelch Exp $
/* $Id: token.c,v 1.4 2000/01/26 10:07:30 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -21,6 +21,188 @@ POBJECT_TYPE SeTokenType = NULL;
/* FUNCTIONS *****************************************************************/
VOID SepFreeProxyData(PVOID ProxyData)
{
UNIMPLEMENTED;
}
NTSTATUS SepCopyProxyData(PVOID* Dest, PVOID Src)
{
UNIMPLEMENTED;
}
NTSTATUS SeExchangePrimaryToken(PEPROCESS Process,
PACCESS_TOKEN NewToken,
PACCESS_TOKEN* OldTokenP)
{
PACCESS_TOKEN OldToken;
if (NewToken->TokenType != TokenPrimary)
{
return(STATUS_UNSUCCESSFUL);
}
if (NewToken->TokenInUse != 0)
{
return(STATUS_UNSUCCESSFUL);
}
OldToken = Process->Token;
Process->Token = NewToken;
NewToken->TokenInUse = 1;
ObReferenceObjectByPointer(NewToken,
GENERIC_ALL,
SeTokenType,
KernelMode);
OldToken->TokenInUse = 0;
*OldTokenP = OldToken;
return(STATUS_SUCCESS);
}
NTSTATUS SepDuplicationToken(PACCESS_TOKEN Token,
POBJECT_ATTRIBUTES ObjectAttributes,
TOKEN_TYPE TokenType,
SECURITY_IMPERSONATION_LEVEL Level,
SECURITY_IMPERSONATION_LEVEL ExistingLevel,
KPROCESSOR_MODE PreviousMode,
PACCESS_TOKEN* NewAccessToken)
{
UNIMPLEMENTED;
}
NTSTATUS SeCopyClientToken(PACCESS_TOKEN Token,
SECURITY_IMPERSONATION_LEVEL Level,
KPROCESSOR_MODE PreviousMode,
PACCESS_TOKEN* NewToken)
{
NTSTATUS Status;
OBJECT_ATTRIBUTES ObjectAttributes;
InitializeObjectAttributes(&ObjectAttributes,
NULL,
0,
NULL,
NULL);
Status = SepDuplicationToken(Token,
&ObjectAttributes,
0,
SecurityIdentification,
Level,
PreviousMode,
NewToken);
return(Status);
}
NTSTATUS SeCreateClientSecurity(PETHREAD Thread,
PSECURITY_QUALITY_OF_SERVICE Qos,
ULONG e,
PSE_SOME_STRUCT2 f)
{
TOKEN_TYPE TokenType;
UCHAR b;
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
PACCESS_TOKEN Token;
ULONG g;
PACCESS_TOKEN NewToken;
Token = PsReferenceEffectiveToken(Thread,
&TokenType,
&b,
&ImpersonationLevel);
if (TokenType != 2)
{
f->Unknown9 = Qos->EffectiveOnly;
}
else
{
if (Qos->ImpersonationLevel > ImpersonationLevel)
{
if (Token != NULL)
{
ObDereferenceObject(Token);
}
return(STATUS_UNSUCCESSFUL);
}
if (ImpersonationLevel == 0 ||
ImpersonationLevel == 1 ||
(e != 0 && ImpersonationLevel != 3))
{
if (Token != NULL)
{
ObDereferenceObject(Token);
}
return(STATUS_UNSUCCESSFUL);
}
if (b != 0 ||
Qos->EffectiveOnly != 0)
{
f->Unknown9 = 1;
}
else
{
f->Unknown9 = 0;
}
}
if (Qos->ContextTrackingMode == 0)
{
f->Unknown8 = 0;
g = SeCopyClientToken(Token, ImpersonationLevel, 0, &NewToken);
if (g >= 0)
{
// ObDeleteCapturedInsertInfo(NewToken);
}
if (TokenType == TokenPrimary || Token != NULL)
{
ObDereferenceObject(Token);
}
if (g < 0)
{
return(g);
}
}
else
{
f->Unknown8 = 1;
if (e != 0)
{
// SeGetTokenControlInformation(Token, &f->Unknown11);
}
NewToken = Token;
}
f->Unknown1 = 0xc;
f->Level = Qos->ImpersonationLevel;
f->ContextTrackingMode = Qos->ContextTrackingMode;
f->EffectiveOnly = Qos->EffectiveOnly;
f->Unknown10 = e;
f->Token = NewToken;
return(STATUS_SUCCESS);
}
VOID SeImpersonateClient(PSE_SOME_STRUCT2 a,
PETHREAD Thread)
{
UCHAR b;
if (a->Unknown8 == 0)
{
b = a->EffectiveOnly;
}
else
{
b = a->Unknown9;
}
if (Thread == NULL)
{
Thread = PsGetCurrentThread();
}
PsImpersonateClient(Thread,
a->Token,
1,
(ULONG)b,
a->Level);
}
VOID SeInitializeTokenManager(VOID)
{
UNICODE_STRING TypeName;
@ -214,20 +396,54 @@ NtSetInformationToken(
UNIMPLEMENTED;
}
NTSTATUS
STDCALL
NtDuplicateToken (
IN HANDLE ExistingToken,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes,
IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
IN TOKEN_TYPE TokenType,
OUT PHANDLE NewToken
)
NTSTATUS STDCALL NtDuplicateToken(IN HANDLE ExistingTokenHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes,
IN SECURITY_IMPERSONATION_LEVEL
ImpersonationLevel,
IN TOKEN_TYPE TokenType,
OUT PHANDLE NewTokenHandle)
{
UNIMPLEMENTED;
#if 0
PACCESS_TOKEN Token;
PACCESS_TOKEN NewToken;
NTSTATUS Status;
ULONG ExistingImpersonationLevel;
Status = ObReferenceObjectByHandle(ExistingTokenHandle,
?,
SeTokenType,
UserMode,
(PVOID*)&Token,
NULL);
ExistingImpersonationLevel = Token->ImpersonationLevel;
SepDuplicateToken(Token,
ObjectAttributes,
ImpersonationLevel,
TokenType,
ExistingImpersonationLevel,
KeGetPreviousMode(),
&NewToken);
#else
UNIMPLEMENTED;
#endif
}
VOID SepAdjustGroups(PACCESS_TOKEN Token,
ULONG a,
BOOLEAN ResetToDefault,
PSID_AND_ATTRIBUTES Groups,
ULONG b,
KPROCESSOR_MODE PreviousMode,
ULONG c,
PULONG d,
PULONG e,
PULONG f)
{
UNIMPLEMENTED;
}
NTSTATUS STDCALL NtAdjustGroupsToken(IN HANDLE TokenHandle,
IN BOOLEAN ResetToDefault,
IN PTOKEN_GROUPS NewState,
@ -235,20 +451,128 @@ NTSTATUS STDCALL NtAdjustGroupsToken(IN HANDLE TokenHandle,
OUT PTOKEN_GROUPS PreviousState OPTIONAL,
OUT PULONG ReturnLength)
{
#if 0
NTSTATUS Status;
PACCESS_TOKEN Token;
ULONG a;
ULONG b;
ULONG c;
Status = ObReferenceObjectByHandle(TokenHandle,
?,
SeTokenType,
UserMode,
(PVOID*)&Token,
NULL);
SepAdjustGroups(Token,
0,
ResetToDefault,
NewState->Groups,
?,
PreviousState,
0,
&a,
&b,
&c);
#else
UNIMPLEMENTED;
#endif
}
NTSTATUS
STDCALL
NtAdjustPrivilegesToken(IN HANDLE TokenHandle,
#if 0
NTSTATUS SepAdjustPrivileges(PACCESS_TOKEN Token, // 0x8
ULONG a, // 0xC
KPROCESSOR_MODE PreviousMode, // 0x10
ULONG PrivilegeCount, // 0x14
PLUID_AND_ATTRIBUTES Privileges, // 0x18
PTOKEN_PRIVILEGES* PreviousState, // 0x1C
PULONG b, // 0x20
PULONG c, // 0x24
PULONG d) // 0x28
{
ULONG i;
*c = 0;
if (Token->PrivilegeCount > 0)
{
for (i=0; i<Token->PrivilegeCount; i++)
{
if (PreviousMode != 0)
{
if (!(Token->Privileges[i]->Attributes &
SE_PRIVILEGE_ENABLED))
{
if (a != 0)
{
if (PreviousState != NULL)
{
memcpy(&PreviousState[i],
&Token->Privileges[i],
sizeof(LUID_AND_ATTRIBUTES));
}
Token->Privileges[i].Attributes =
Token->Privileges[i].Attributes &
(~SE_PRIVILEGE_ENABLED);
}
}
}
}
}
if (PreviousMode != 0)
{
Token->TokenFlags = Token->TokenFlags & (~1);
}
else
{
if (PrivilegeCount <= ?)
{
}
}
if (
}
#endif
NTSTATUS STDCALL NtAdjustPrivilegesToken(IN HANDLE TokenHandle,
IN BOOLEAN DisableAllPrivileges,
IN PTOKEN_PRIVILEGES NewState,
IN ULONG BufferLength,
OUT PTOKEN_PRIVILEGES PreviousState,
IN PTOKEN_PRIVILEGES NewState,
IN ULONG BufferLength,
OUT PTOKEN_PRIVILEGES PreviousState,
OUT PULONG ReturnLength)
{
UNIMPLEMENTED;
#if 0
ULONG PrivilegeCount;
ULONG Length;
PSID_AND_ATTRIBUTES Privileges;
ULONG a;
ULONG b;
ULONG c;
PrivilegeCount = NewState->PrivilegeCount;
SeCaptureLuidAndAttributesArray(NewState->Privileges,
&PrivilegeCount,
KeGetPreviousMode(),
NULL,
0,
NonPagedPool,
1,
&Privileges.
&Length);
SepAdjustPrivileges(Token,
0,
KeGetPreviousMode(),
PrivilegeCount,
Privileges,
PreviousState,
&a,
&b,
&c);
#else
UNIMPLEMENTED;
#endif
}
NTSTATUS STDCALL NtCreateToken(OUT PHANDLE TokenHandle,

View file

@ -1,4 +1,4 @@
/* $Id: smss.c,v 1.4 1999/12/15 06:48:10 phreak Exp $
/* $Id: smss.c,v 1.5 2000/01/26 10:07:30 dwelch Exp $
*
* smss.c - Session Manager
*
@ -66,67 +66,66 @@ PrintString (char* fmt,...)
/* Native image's entry point */
void
NtProcessStartup (PPEB Peb)
void NtProcessStartup (PPEB Peb)
{
HANDLE Children[2]; /* csrss, winlogon */
HANDLE Children[2]; /* csrss, winlogon */
DisplayString( L"Session Manager\n" );
DisplayString( L"Session Manager\n" );
PrintString ("Peb %x\n", Peb);
PrintString ("Peb %x\n", Peb);
if (TRUE == InitSessionManager(Children))
{
NTSTATUS wws;
DisplayString( L"SM: Waiting for process termination...\n" );
if (TRUE == InitSessionManager(Children))
{
NTSTATUS wws;
DisplayString( L"SM: Waiting for process termination...\n" );
#if 0
wws = NtWaitForMultipleObjects (
((LONG) sizeof Children / sizeof (HANDLE)),
Children,
WaitAny,
TRUE, /* alertable */
NULL /* NULL for infinite */
);
wws = NtWaitForMultipleObjects (
((LONG) sizeof Children / sizeof (HANDLE)),
Children,
WaitAny,
TRUE, /* alertable */
NULL /* NULL for infinite */
);
#endif
wws = NtWaitForSingleObject (
Children[CHILD_WINLOGON],
TRUE, /* alertable */
NULL
);
// if (!NT_SUCCESS(wws))
if (wws > 1)
{
DisplayString( L"SM: NtWaitForMultipleObjects failed!\n" );
/* FIXME: CRASH THE SYSTEM (BSOD) */
}
else
{
DisplayString( L"SM: Process terminated!\n" );
/* FIXME: CRASH THE SYSTEM (BSOD) */
}
}
wws = NtWaitForSingleObject (
Children[CHILD_WINLOGON],
TRUE, /* alertable */
NULL
);
// if (!NT_SUCCESS(wws))
if (wws > 1)
{
DisplayString( L"SM: NtWaitForMultipleObjects failed!\n" );
/* FIXME: CRASH THE SYSTEM (BSOD) */
}
else
{
DisplayString( L"SM: initialization failed!\n" );
/* FIXME: CRASH SYSTEM (BSOD)*/
}
/*
* OK: CSRSS asked to shutdown the system;
* We die.
*/
{
DisplayString( L"SM: Process terminated!\n" );
/* FIXME: CRASH THE SYSTEM (BSOD) */
}
}
else
{
DisplayString( L"SM: initialization failed!\n" );
/* FIXME: CRASH SYSTEM (BSOD)*/
}
/*
* OK: CSRSS asked to shutdown the system;
* We die.
*/
#if 0
NtRaiseHardError (
STATUS_SYSTEM_PROCESS_TERMINATED,
NtRaiseHardError (
STATUS_SYSTEM_PROCESS_TERMINATED,
...);
#endif
NtTerminateProcess( NtCurrentProcess(), 0 );
NtTerminateProcess( NtCurrentProcess(), 0 );
}
/* EOF */