diff --git a/reactos/iface/native/genntdll.c b/reactos/iface/native/genntdll.c index e00823fed27..74c055e4c95 100644 --- a/reactos/iface/native/genntdll.c +++ b/reactos/iface/native/genntdll.c @@ -1,8 +1,9 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS version of ntdll - * FILE: lib/ntdll/genntdll.c + * FILE: iface/native/genntdll.c * PURPOSE: Generates the system call stubs in ntdll + * CHANGE HISTORY: Added a '@xx' to deal with stdcall [ Ariadne ] */ /* INCLUDE ******************************************************************/ @@ -29,6 +30,7 @@ int process(FILE* in, FILE* out, FILE *out2) fprintf(out,"; Machine generated, don't edit\n"); fprintf(out,"\n\n"); fprintf(out,"SECTION .text\n\n"); + fprintf(out,"BITS 32\n\n"); fprintf(out2,"// Machine generated, don't edit\n"); fprintf(out2,"\n\n"); @@ -41,12 +43,12 @@ int process(FILE* in, FILE* out, FILE *out2) while (!feof(in) && fgets(line,255,in) != NULL) { // fgets(line,255,in); - if ((s=(char *)strchr(line,'\n'))!=NULL) + if ((s=(char *)strchr(line,13))!=NULL) { *s=0; } s=&line[0]; - if ((*s)!='#') + if ((*s)!='#' && (*s) != 0) { name = (char *)strtok(s," \t"); name2 = (char *)strtok(NULL," \t"); @@ -54,10 +56,10 @@ int process(FILE* in, FILE* out, FILE *out2) nr_args = (char *)strtok(NULL," \t"); // printf("name %s value %d\n",name,value); - fprintf(out,"GLOBAL _%s\n",name); - fprintf(out,"GLOBAL _%s\n",name2); - fprintf(out,"_%s:\n",name); - fprintf(out,"_%s:\n",name2); + fprintf(out,"GLOBAL _%s@%s\n",name,nr_args); + fprintf(out,"GLOBAL _%s@%s\n",name2,nr_args); + fprintf(out,"_%s@%s:\n",name,nr_args); + fprintf(out,"_%s@%s:\n",name2,nr_args); fprintf(out,"\tmov\teax,%d\n",value); fprintf(out,"\tlea\tedx,[esp+4]\n"); fprintf(out,"\tint\t2Eh\n"); diff --git a/reactos/iface/native/makefile b/reactos/iface/native/makefile index 0088750d8f1..2c989639090 100644 --- a/reactos/iface/native/makefile +++ b/reactos/iface/native/makefile @@ -6,7 +6,7 @@ all: genntdll$(EXE_POSTFIX) ../../lib/ntdll/napi.asm ../../include/ntdll/napi.h: dummy genntdll$(EXE_POSTFIX): genntdll.c - $(NATIVE_CC) -g genntdll.c -o genntdll$(EXE_POSTFIX) + $(NATIVE_CC) -If:\gnu\mingw32\include -g genntdll.c -o genntdll$(EXE_POSTFIX) sysfuncs.lst: dummy diff --git a/reactos/iface/native/sysfuncs.lst b/reactos/iface/native/sysfuncs.lst index 2b90351fcc1..88dcb4b96bf 100644 --- a/reactos/iface/native/sysfuncs.lst +++ b/reactos/iface/native/sysfuncs.lst @@ -208,3 +208,4 @@ NtReplyWaitSendChannel ZwReplyWaitSendChannel 12 NtSendWaitReplyChannel ZwSendWaitReplyChannel 16 NtSetContextChannel ZwSetContextChannel 4 NtYieldExecution ZwYieldExecution 0 + diff --git a/reactos/include/ddk/pstypes.h b/reactos/include/ddk/pstypes.h index 327e38a566f..0dc179b92f8 100644 --- a/reactos/include/ddk/pstypes.h +++ b/reactos/include/ddk/pstypes.h @@ -1,9 +1,19 @@ #ifndef __INCLUDE_DDK_PSTYPES_H #define __INCLUDE_DDK_PSTYPES_H +#undef WIN32_LEAN_AND_MEAN +#include // might be redundant #include +#include #include +#ifndef TLS_MINIMUM_AVAILABLE + #define TLS_MINIMUM_AVAILABLE (64) +#endif +#ifndef MAX_PATH + #define MAX_PATH (260) +#endif + typedef NTSTATUS (*PKSTART_ROUTINE)(PVOID StartContext); typedef struct _STACK_INFORMATION @@ -39,17 +49,34 @@ typedef struct linux_sigcontext { typedef ULONG THREADINFOCLASS; -typedef void* ATOMTABLE; +typedef struct _STARTUPINFOW { + DWORD cb; + WCHAR WindowTitle[MAX_PATH]; + WCHAR ImageFile[MAX_PATH]; + WCHAR CommandLine[MAX_PATH]; + WCHAR DllPath[MAX_PATH]; + LPWSTR Reserved[MAX_PATH]; + LPWSTR Desktop[MAX_PATH]; + LPWSTR Title[MAX_PATH]; + DWORD dwX; + DWORD dwY; + DWORD dwXSize; + DWORD dwYSize; + DWORD dwXCountChars; + DWORD dwYCountChars; + DWORD dwFillAttribute; + DWORD dwFlags; + WORD wShowWindow; + WORD cbReserved2; + unsigned char * lpReserved2; + HANDLE hStdInput; + HANDLE hStdOutput; + HANDLE hStdError; +} PROCESSINFOW, *PPROCESSINFOW; -typedef struct _pPebInfo { - WCHAR* WindowTitle; - WCHAR* ImageFile; - WCHAR* CommandLine; - WCHAR* DllPath; -// STARTUPINFOW StartupInfo; -} PEBINFO; -typedef struct _LDR_ { + +typedef struct _LDR { UCHAR Initialized; UCHAR InInitializationOrderModuleList; PVOID InLoadOrderModuleList; @@ -64,15 +91,11 @@ typedef struct _NT_PEB UCHAR BeingDebugged; LONG ImageBaseAddress; LDR Ldr; - DWORD dwTlsBits[2]; // tls in use bits + WORD NumberOfProcessors; WORD NtGlobalFlag; - DWORD HeapReserve; - DWORD HeapCommit; - DWORD HeapDecommitFreeBlockThreshold; - DWORD NumberOfHeaps; - DWORD MaxiumNumberOfHeaps; - PEBINFO* PebInfo; + + PPROCESSINFOW StartupInfo; PHEAP ProcessHeap; ATOMTABLE LocalAtomTable; LPCRITICAL_SECTION CriticalSection; @@ -108,8 +131,9 @@ typedef struct _NT_TEB NT_TIB Tib; CLIENT_ID Cid; HANDLE RPCHandle; - PVOID TlsData; - NT_PEB *pPeb; + PVOID TlsData[TLS_MINIMUM_AVAILABLE]; + DWORD dwTlsIndex; + NT_PEB *Peb; DWORD LastErrorCode; NTSTATUS LastStatusValue; DWORD LockCount; @@ -135,7 +159,7 @@ typedef struct _KTHREAD PTRAP_FRAME TrapFrame; PVOID *Tls; KWAIT_BLOCK WaitBlock[4]; - struct _KMUTANT* MutantList; + struct _KMUTANT* MutantList; PLIST_ENTRY ApcList; UCHAR KernelApcDisable; KTIMER TimerBlock; @@ -154,61 +178,19 @@ typedef struct _KTHREAD // According to documentation the stack should have a commited [ 1 page ] and -// a reserved part [ 1 M ]. +// a reserved part [ 1 M ] but can be specified otherwise in the image file. typedef struct _INITIAL_TEB { + PVOID StackBase; + PVOID StackLimit; PVOID StackCommit; + PVOID StackCommitMax; PVOID StackReserved; } INITIAL_TEB, *PINITIAL_TEB; -//ThreadState defines the current state of a thread -//FIXME I am allready defined in psmgr.h as a enum -/* -enum -{ - THREAD_STATE_INITIALIZED = 0, - THREAD_STATE_READY, - THREAD_STATE_RUNNING, - THREAD_STATE_STANDBY, - THREAD_STATE_TERMINATED, - THREAD_STATE_WAIT, - THREAD_STATE_TRANSITION, - THREAD_STATE_RESERVED -}; -*/ - -// wait reason only applies for threads in a wait state -// part of this enum is double ???? - -/* -typedef _KWAIT_REASON -{ - WAIT_EXCECUTIVE1 = 0, - WAIT_FREE_PAGE1, - WAIT_PAGE_IN1, - WAIT_POOL_ALLOCATION1, - WAIT_EXECUTION_DELAY1, - WAIT_SUSPENDED_CONDITION1, - WAIT_USER_REQUEST1, - WAIT_EXCECUTIVE2, - WAIT_FREE_PAGE2, - WAIT_PAGE_IN2, - WAIT_POOL_ALLOCATION2, - WAIT_EXECUTION_DELAY2, - WAIT_SUSPENDED_CONDITION2, - WAIT_USER_REQUEST2, - WAIT_EVENT_PAIR_HIGH, - WAIT_EVENT_PAIR_LOW, - WAIT_LPC_RECEIVE, - WAIT_LPC_REPLY, - WAIT_VIRTUAL_MEMORY, - WAIT_PAGE_OUT -} KWAIT_REASON; - -*/ // TopLevelIrp can be one of the following values: @@ -259,19 +241,20 @@ typedef struct _ETHREAD { typedef struct _KPROCESS { DISPATCHER_HEADER DispatcherHeader; - PVOID PageTableDirectory; // FIXME: I shoud point to a PTD + PVOID PageTableDirectory; // FIXME: I shoud point to a PTD TIME ElapsedTime; TIME KernelTime; TIME UserTime; - LIST_ENTRY InOutSwap; // ?? + LIST_ENTRY InMemoryList; + LIST_ENTRY SwappedOutList; KSPIN_LOCK SpinLock; KAFFINITY Affinity; - ULONG StackCount; + ULONG StackCount; KPRIORITY BasePriority; - ULONG DefaultThreadQuantum; - UCHAR ProcessState; - ULONG ThreadSeed; - UCHAR DisableBoost; + ULONG DefaultThreadQuantum; + UCHAR ProcessState; + ULONG ThreadSeed; + UCHAR DisableBoost; /* * Added by David Welch (welch@mcmail.com) diff --git a/reactos/include/ddk/rtl.h b/reactos/include/ddk/rtl.h index 6071b12d463..926ba8ae835 100644 --- a/reactos/include/ddk/rtl.h +++ b/reactos/include/ddk/rtl.h @@ -153,6 +153,8 @@ LONG RtlCompareString(PSTRING String1, PSTRING String2, LONG RtlCompareUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN BaseInsensitive); +LARGE_INTEGER RtlConvertLongToLargeInteger(LONG SignedInteger); +LARGE_INTEGER RtlConvertUlongToLargeInteger(ULONG UnsignedInteger); VOID RtlCopyBytes(PVOID Destination, CONST VOID* Source, ULONG Length); VOID RtlCopyMemory(VOID* Destination, VOID* Source, ULONG Length); VOID RtlCopyString(PSTRING DestinationString, PSTRING SourceString); @@ -165,12 +167,27 @@ NTSTATUS RtlCreateSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor, NTSTATUS RtlDeleteRegistryValue(ULONG RelativeTo, PWSTR Path, PWSTR ValueName); +LARGE_INTEGER RtlEnlargedIntegerMultiply(LONG Multiplicand, + LONG Multiplier); +ULONG RtlEnlargedUnsignedDivide(ULARGE_INTEGER Dividend, + ULONG Divisor, + PULONG Remainder); +LARGE_INTEGER RtlEnlargedUnsignedMultiply(ULONG Multiplicand, + ULONG Multiplier); BOOLEAN RtlEqualString(PSTRING String1, PSTRING String2, BOOLEAN CaseInSensitive); BOOLEAN RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive); +LARGE_INTEGER RtlExtendedIntegerMultiply(LARGE_INTEGER Multiplicand, + LONG Multiplier); +LARGE_INTEGER RtlExtendedLargeIntegerDivide(LARGE_INTEGER Dividend, + ULONG Divisor, + PULONG Remainder); +LARGE_INTEGER RtlExtendedMagicDivide(LARGE_INTEGER Dividend, + LARGE_INTEGER MagicDivisor, + CCHAR ShiftCount); VOID RtlFillMemory(PVOID Destination, ULONG Length, UCHAR Fill); VOID RtlFreeAnsiString(PANSI_STRING AnsiString); VOID RtlFreeUnicodeString(PUNICODE_STRING UnicodeString); @@ -182,8 +199,13 @@ VOID RtlInitUnicodeString(PUNICODE_STRING DestinationString, NTSTATUS RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String); +LARGE_INTEGER RtlLargeIntegerAdd(LARGE_INTEGER Addend1, + LARGE_INTEGER Addend2); +VOID RtlLargeIntegerAnd(PLARGE_INTEGER Result, + LARGE_INTEGER Source, + LARGE_INTEGER Mask); -/** LARGE_INTEGER Functions *******************************************/ +/* MISSING FUNCTIONS GO HERE */ LARGE_INTEGER RtlConvertLongToLargeInteger(LONG SignedInteger); LARGE_INTEGER RtlConvertUlongToLargeInteger(ULONG UnsignedInteger); LARGE_INTEGER RtlEnlargedIntegerMultiply(LONG Multiplicand, @@ -240,8 +262,6 @@ LARGE_INTEGER RtlLargeIntegerShiftRight(LARGE_INTEGER LargeInteger, LARGE_INTEGER RtlLargeIntegerSubtract(LARGE_INTEGER Minuend, LARGE_INTEGER Subtrahend); -/* MISSING FUNCTIONS GO HERE */ - ULONG RtlLengthSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor); VOID RtlMoveMemory(PVOID Destination, CONST VOID* Source, ULONG Length); NTSTATUS RtlQueryRegistryValues(ULONG RelativeTo, @@ -324,5 +344,10 @@ VOID RtlStoreUlong(PULONG Address, ULONG Value); +DWORD RtlNtStatusToDosError(NTSTATUS StatusCode); + + + + #endif /* __DDK_RTL_H */ diff --git a/reactos/include/ddk/zw.h b/reactos/include/ddk/zw.h index 12c712e6a0a..1fe5ae97d4f 100644 --- a/reactos/include/ddk/zw.h +++ b/reactos/include/ddk/zw.h @@ -5,9 +5,9 @@ * FILE: include/ddk/zw.h * REVISION HISTORY: * ??/??/??: First few functions (David Welch) - * ??/??/??: Complete implementation by Boudewijn Dekker + * ??/??/??: Complete implementation by Ariadne * 13/07/98: Reorganised things a bit (David Welch) - * 04/08/98: Added some documentation (Boudewijn Dekker) + * 04/08/98: Added some documentation (Ariadne) * 14/08/98: Added type TIME and change variable type from [1] to [0] * 14/09/98: Added for each Nt call a corresponding Zw Call */ @@ -15,33 +15,101 @@ #ifndef __DDK_ZW_H #define __DDK_ZW_H + #include +//#ifndef WIN32_LEAN_AND_MEAN +#define PTOKEN_GROUPS PVOID +#define PTOKEN_PRIVILEGES PVOID +#define TOKEN_INFORMATION_CLASS CINT +#define LCID ULONG +#define SECURITY_INFORMATION ULONG +//#endif + + +/* + * FUNCTION: Checks a clients access rights to a object + * ARGUMENTS: + SecurityDescriptor = Security information against which the access is checked + * ClientToken = Represents a client + DesiredAcces = + GenericMapping = + PrivilegeSet = + ReturnLength = Bytes written + GrantedAccess = + AccessStatus = Indicates if the ClientToken allows the requested access + * REMARKS: The arguments map to the win32 AccessCheck + * RETURNS: Status + */ NTSTATUS STDCALL NtAccessCheck( IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN HANDLE ClientToken, - IN ULONG DesiredAcces, + IN ACCESS_MASK DesiredAcces, IN PGENERIC_MAPPING GenericMapping, OUT PRIVILEGE_SET PrivilegeSet, OUT PULONG ReturnLength, OUT PULONG GrantedAccess, - OUT PULONG AccessStatus + OUT PBOOLEAN AccessStatus ); NTSTATUS STDCALL ZwAccessCheck( IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN HANDLE ClientToken, - IN ULONG DesiredAcces, + IN ACCESS_MASK DesiredAcces, IN PGENERIC_MAPPING GenericMapping, OUT PRIVILEGE_SET PrivilegeSet, OUT PULONG ReturnLength, OUT PULONG GrantedAccess, - OUT PULONG AccessStatus + OUT PBOOLEAN AccessStatus ); +/* + * FUNCTION: Checks a clients access rights to a object and issues a audit a alarm. ( it logs the access ) + * ARGUMENTS: + SubsystemName = Specifies the name of the subsystem, can be "WIN32" or "DEBUG" + ObjectHandle = + ObjectAttributes = + DesiredAcces = + GenericMapping = + ObjectCreation = + GrantedAccess = + AccessStatus = + GenerateOnClose = + * REMARKS: The arguments map to the win32 AccessCheck + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtAccessCheckAndAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PHANDLE ObjectHandle, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN ACCESS_MASK DesiredAccess, + IN PGENERIC_MAPPING GenericMapping, + IN BOOLEAN ObjectCreation, + OUT PULONG GrantedAccess, + OUT PBOOLEAN AccessStatus, + OUT PBOOLEAN GenerateOnClose + ); + +NTSTATUS +STDCALL +ZwAccessCheckAndAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PHANDLE ObjectHandle, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN ACCESS_MASK DesiredAccess, + IN PGENERIC_MAPPING GenericMapping, + IN BOOLEAN ObjectCreation, + OUT PULONG GrantedAccess, + OUT PBOOLEAN AccessStatus, + OUT PBOOLEAN GenerateOnClose + ); + /* * FUNCTION: Adds an atom to the global atom table * ARGUMENTS: @@ -64,6 +132,84 @@ ZwAddAtom( OUT ATOM *Atom, IN PUNICODE_STRING AtomString ); + + +/* + * FUNCTION: Adjusts the groups in an access token + * ARGUMENTS: + TokenHandle = Specifies the access token + * ResetToDefault = If true the NewState parameter is ignored and the groups are set to + their default state, if false the groups specified in + NewState are set. + NewState = + BufferLength = Specifies the size of the buffer for the PreviousState. + PreviousState = + ReturnLength = Bytes written in PreviousState buffer. + * REMARKS: The arguments map to the win32 AdjustTokenGroups + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtAdjustGroupsToken( + IN HANDLE TokenHandle, + IN BOOLEAN ResetToDefault, + IN PTOKEN_GROUPS NewState, + IN ULONG BufferLength, + OUT PTOKEN_GROUPS PreviousState OPTIONAL, + OUT PULONG ReturnLength + ); + +NTSTATUS +STDCALL +ZwAdjustGroupsToken( + IN HANDLE TokenHandle, + IN BOOLEAN ResetToDefault, + IN PTOKEN_GROUPS NewState, + IN ULONG BufferLength, + OUT PTOKEN_GROUPS PreviousState, + OUT PULONG ReturnLength + ); + + +/* + * FUNCTION: + * + * ARGUMENTS: + * TokenHandle = Handle to the access token + * DisableAllPrivileges = The resulting suspend count. + NewState = + BufferLength = + PreviousState = + ReturnLength = + * REMARK: + * The arguments map to the win32 AdjustTokenPrivileges + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtAdjustPrivilegesToken( + IN HANDLE TokenHandle, + IN BOOLEAN DisableAllPrivileges, + IN PTOKEN_PRIVILEGES NewState, + IN ULONG BufferLength, + OUT PTOKEN_PRIVILEGES PreviousState, + OUT PULONG ReturnLength + ); + +NTSTATUS +STDCALL +ZwAdjustPrivilegesToken( + IN HANDLE TokenHandle, + IN BOOLEAN DisableAllPrivileges, + IN PTOKEN_PRIVILEGES NewState, + IN ULONG BufferLength, + OUT PTOKEN_PRIVILEGES PreviousState, + OUT PULONG ReturnLength + ); + + /* * FUNCTION: Decrements a thread's suspend count and places it in an alerted * state. @@ -116,13 +262,29 @@ ZwAlertThread( NTSTATUS STDCALL NtAllocateLocallyUniqueId( - OUT PVOID LocallyUniqueId + OUT LUID *LocallyUniqueId ); NTSTATUS STDCALL ZwAllocateLocallyUniqueId( - OUT PVOID LocallyUniqueId + OUT LUID *LocallyUniqueId + ); + +NTSTATUS +STDCALL +NtAllocateUuids( + PLARGE_INTEGER Time, + PULONG Version, // ??? + PULONG ClockCycle + ); + +NTSTATUS +STDCALL +ZwAllocateUuids( + PLARGE_INTEGER Time, + PULONG Version, // ??? + PULONG ClockCycle ); @@ -152,9 +314,9 @@ NTSTATUS STDCALL NtAllocateVirtualMemory( IN HANDLE ProcessHandle, - OUT PVOID *BaseAddress, + IN OUT PVOID *BaseAddress, IN ULONG ZeroBits, - IN ULONG RegionSize, + IN OUT PULONG RegionSize, IN ULONG AllocationType, IN ULONG Protect ); @@ -163,9 +325,9 @@ NTSTATUS STDCALL ZwAllocateVirtualMemory( IN HANDLE ProcessHandle, - OUT PVOID *BaseAddress, + IN OUT PVOID *BaseAddress, IN ULONG ZeroBits, - IN ULONG RegionSize, + IN OUT PULONG RegionSize, IN ULONG AllocationType, IN ULONG Protect ); @@ -274,6 +436,36 @@ ZwClose( IN HANDLE Handle ); +/* + * FUNCTION: Generates an audit message when a handle to an object is dereferenced + * ARGUMENTS: + * SubsystemName = + HandleId = Handle to the object + GenerateOnClose = + * REMARKS: + * This function maps to the win32 function ObjectCloseAuditAlarm. + * RETURNS: Status + */ + + + +NTSTATUS +STDCALL +NtCloseObjectAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PVOID HandleId, + IN BOOLEAN GenerateOnClose + ); + +NTSTATUS +STDCALL +ZwCloseObjectAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PVOID HandleId, + IN BOOLEAN GenerateOnClose + ); + + /* * FUNCTION: Continues a thread with the specified context @@ -348,7 +540,7 @@ ZwCreateDirectoryObject( NTSTATUS STDCALL NtCreateEvent( - OUT PHANDLE FileHandle, + OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN BOOLEAN ManualReset, @@ -358,7 +550,7 @@ NtCreateEvent( NTSTATUS STDCALL ZwCreateEvent( - OUT PHANDLE FileHandle, + OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN BOOLEAN ManualReset, @@ -376,7 +568,7 @@ ZwCreateEvent( NTSTATUS STDCALL NtCreateEventPair( - OUT PHANDLE FileHandle, + OUT PHANDLE EventPairHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes ); @@ -384,7 +576,7 @@ NtCreateEventPair( NTSTATUS STDCALL ZwCreateEventPair( - OUT PHANDLE FileHandle, + OUT PHANDLE EventPairHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes ); @@ -525,7 +717,48 @@ ZwCreateKey( ); -//NtCreateMailslotFile +/* + * FUNCTION: Creates a mail slot file + * ARGUMENTS: + * MailSlotFileHandle (OUT) = Caller supplied storage for the resulting handle + * DesiredAccess = Specifies the allowed or desired access to the file + * ObjectAttributes = Contains the name of the mailslotfile. + * IoStatusBlock = + * FileAttributes = + * ShareAccess = + * MaxMessageSize = + * TimeOut = + * + * REMARKS: This funciton maps to the win32 function CreateMailSlot + * RETURNS: + * Status + */ + +NTSTATUS +STDCALL +NtCreateMailslotFile( + OUT PHANDLE MailSlotFileHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN ULONG FileAttributes, + IN ULONG ShareAccess, + IN ULONG MaxMessageSize, + IN PLARGE_INTEGER TimeOut + ); + +NTSTATUS +STDCALL +ZwCreateMailslotFile( + OUT PHANDLE MailSlotFileHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN ULONG FileAttributes, + IN ULONG ShareAccess, + IN ULONG MaxMessageSize, + IN PLARGE_INTEGER TimeOut + ); /* * FUNCTION: Creates or opens a mutex @@ -544,7 +777,7 @@ STDCALL NtCreateMutant( OUT PHANDLE MutantHandle, IN ACCESS_MASK DesiredAccess, - IN OBJECT_ATTRIBUTES ObjectAttributes, + IN POBJECT_ATTRIBUTES ObjectAttributes, IN BOOLEAN InitialOwner ); @@ -553,11 +786,70 @@ STDCALL ZwCreateMutant( OUT PHANDLE MutantHandle, IN ACCESS_MASK DesiredAccess, - IN OBJECT_ATTRIBUTES ObjectAttributes, + IN POBJECT_ATTRIBUTES ObjectAttributes, IN BOOLEAN InitialOwner ); -//NtCreateNamedPipeFile +/* + * FUNCTION: Creates a named pipe + * ARGUMENTS: + * NamedPipeFileHandle (OUT) = Caller supplied storage for the resulting handle + * DesiredAccess = Specifies the allowed or desired access to the mutex + * ObjectAttributes = Contains the name of the mutex. + * IoStatusBlock = + * FileAttributes = + * ShareAccess = + * OpenMode = + * PipeType = + * PipeRead = + * PipeWait = + * MaxInstances = + * InBufferSize = + * OutBufferSize = + * TimeOut = + * REMARKS: This funciton maps to the win32 function CreateNamedPipe + * RETURNS: + * Status + */ + +NTSTATUS +STDCALL +NtCreateNamedPipeFile( + OUT PHANDLE NamedPipeFileHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN ULONG FileAttributes, + IN ULONG ShareAccess, + IN ULONG OpenMode, + IN ULONG PipeType, + IN ULONG PipeRead, + IN ULONG PipeWait, + IN ULONG MaxInstances, + IN ULONG InBufferSize, + IN ULONG OutBufferSize, + IN PLARGE_INTEGER TimeOut + ); + +NTSTATUS +STDCALL +ZwCreateNamedPipeFile( + OUT PHANDLE NamedPipeFileHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN ULONG FileAttributes, + IN ULONG ShareAccess, + IN ULONG OpenMode, + IN ULONG PipeType, + IN ULONG PipeRead, + IN ULONG PipeWait, + IN ULONG MaxInstances, + IN ULONG InBufferSize, + IN ULONG OutBufferSize, + IN PLARGE_INTEGER TimeOut + ); + /* * FUNCTION: Creates a paging file. @@ -629,6 +921,52 @@ ZwCreateProcess( IN HANDLE ExceptionPort OPTIONAL ); +/* + * FUNCTION: Creates a profile + * ARGUMENTS: + * ProfileHandle (OUT) = Caller supplied storage for the resulting handle + * ObjectAttribute = Initialized attributes for the object + * ImageBase = Start address of executable image + * ImageSize = Size of the image + * Granularity = Bucket size + * Buffer = Caller supplies buffer for profiling info + * ProfilingSize = Buffer size + * ClockSource = Specify 0 / FALSE ?? + * ProcessorMask = A value of -1 indicates disables per processor profiling, + otherwise bit set for the processor to profile. + * REMARKS: + * This function maps to the win32 CreateProcess. + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtCreateProfile( + OUT PHANDLE ProfileHandle, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN ULONG ImageBase, + IN ULONG ImageSize, + IN ULONG Granularity, + OUT PVOID Buffer, + IN ULONG ProfilingSize, + IN ULONG ClockSource, + IN ULONG ProcessorMask + ); + +NTSTATUS +STDCALL +ZwCreateProfile( + OUT PHANDLE ProfileHandle, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN ULONG ImageBase, + IN ULONG ImageSize, + IN ULONG Granularity, + OUT PVOID Buffer, + IN ULONG ProfilingSize, + IN ULONG ClockSource, + IN ULONG ProcessorMask + ); + /* * FUNCTION: Creates a section object. * ARGUMENTS: @@ -821,7 +1159,7 @@ NTSTATUS STDCALL NtDelayExecution( IN BOOLEAN Alertable, - IN TIME *Interval + IN TIME* Interval ); NTSTATUS @@ -853,7 +1191,7 @@ ZwDeleteAtom( ); /* - * FUNCTION: Deletes a file + * FUNCTION: Deletes a file or a directory * ARGUMENTS: * ObjectAttributes = Name of the file which should be deleted * REMARKS: @@ -891,6 +1229,33 @@ ZwDeleteKey( IN HANDLE KeyHandle ); +/* + * FUNCTION: Generates a audit message when an object is deleted + * ARGUMENTS: + * SubsystemName = Spefies the name of the subsystem can be 'WIN32' or 'DEBUG' + * HandleId= Handle to an audit object + * GenerateOnClose = Value returned by NtAccessCheckAndAuditAlarm + * REMARKS: This function maps to the win32 ObjectCloseAuditAlarm + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtDeleteObjectAuditAlarm ( + IN PUNICODE_STRING SubsystemName, + IN PVOID HandleId, + IN BOOLEAN GenerateOnClose + ); + +NTSTATUS +STDCALL +ZwDeleteObjectAuditAlarm ( + IN PUNICODE_STRING SubsystemName, + IN PVOID HandleId, + IN BOOLEAN GenerateOnClose + ); + + /* * FUNCTION: Deletes a value from a registry key * ARGUMENTS: @@ -1006,7 +1371,7 @@ NtDuplicateObject( OUT PHANDLE TargetHandle, IN ACCESS_MASK DesiredAccess, IN BOOLEAN InheritHandle, - ULONG Options + IN ULONG Options ); NTSTATUS @@ -1018,7 +1383,29 @@ ZwDuplicateObject( OUT PHANDLE TargetHandle, IN ACCESS_MASK DesiredAccess, IN BOOLEAN InheritHandle, - ULONG Options + IN ULONG Options + ); + +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 +ZwDuplicateToken( + IN HANDLE ExistingToken, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, + IN TOKEN_TYPE TokenType, + OUT PHANDLE NewToken ); /* * FUNCTION: Returns information about the subkeys of an open key @@ -1258,7 +1645,7 @@ STDCALL NtFreeVirtualMemory( IN HANDLE ProcessHandle, IN PVOID *BaseAddress, - IN ULONG RegionSize, + IN PULONG RegionSize, IN ULONG FreeType ); @@ -1267,7 +1654,7 @@ STDCALL ZwFreeVirtualMemory( IN HANDLE ProcessHandle, IN PVOID *BaseAddress, - IN ULONG RegionSize, + IN PULONG RegionSize, IN ULONG FreeType ); @@ -1362,7 +1749,30 @@ ZwGetTickCount( PULONG UpTime ); -//-- NtImpersonateThread +/* + * FUNCTION: Sets a thread to impersonate another + * ARGUMENTS: + * ThreadHandle = Server thread that will impersonate a client. + ThreadToImpersonate = Client thread that will be impersonated + SecurityQualityOfService = Specifies the impersonation level. + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtImpersonateThread( + IN HANDLE ThreadHandle, + IN HANDLE ThreadToImpersonate, + IN PSECURITY_QUALITY_OF_SERVICE SecurityQualityOfService + ); + +NTSTATUS +STDCALL +ZwImpersonateThread( + IN HANDLE ThreadHandle, + IN HANDLE ThreadToImpersonate, + IN PSECURITY_QUALITY_OF_SERVICE SecurityQualityOfService + ); /* * FUNCTION: Initializes the registry. @@ -1731,6 +2141,31 @@ ZwOpenEvent( IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes ); + +/* + * FUNCTION: Opens an existing event pair + * ARGUMENTS: + * EventHandle (OUT) = Caller supplied storage for the resulting handle + * DesiredAccess = Requested access to the event + * ObjectAttributes = Initialized attributes for the object + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtOpenEventPair( + OUT PHANDLE EventPairHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes + ); + +NTSTATUS +STDCALL +ZwOpenEventPair( + OUT PHANDLE EventPairHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes + ); /* * FUNCTION: Opens an existing file * ARGUMENTS: @@ -1834,7 +2269,36 @@ ZwOpenMutant( IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes ); - + +NTSTATUS +STDCALL +NtOpenObjectAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PVOID HandleId, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN HANDLE ClientToken, + IN ULONG DesiredAccess, + IN ULONG GrantedAccess, + IN PPRIVILEGE_SET Privileges, + IN BOOLEAN ObjectCreation, + IN BOOLEAN AccessGranted, + OUT PBOOLEAN GenerateOnClose + ); + +NTSTATUS +STDCALL +ZwOpenObjectAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PVOID HandleId, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN HANDLE ClientToken, + IN ULONG DesiredAccess, + IN ULONG GrantedAccess, + IN PPRIVILEGE_SET Privileges, + IN BOOLEAN ObjectCreation, + IN BOOLEAN AccessGranted, + OUT PBOOLEAN GenerateOnClose + ); /* * FUNCTION: Opens an existing process * ARGUMENTS: @@ -1860,6 +2324,33 @@ ZwOpenProcess ( IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId ); +/* + * FUNCTION: Opens an existing process + * ARGUMENTS: + * ProcessHandle = Handle of the process of which owns the token + * DesiredAccess = Requested access to the token + * TokenHandle (OUT) = Caller supplies storage for the resulting token. + * REMARKS: + This function maps to the win32 + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtOpenProcessToken( + IN HANDLE ProcessHandle, + IN ACCESS_MASK DesiredAccess, + OUT PHANDLE TokenHandle + ); + +NTSTATUS +STDCALL +ZwOpenProcessToken( + IN HANDLE ProcessHandle, + IN ACCESS_MASK DesiredAccess, + OUT PHANDLE TokenHandle + ); + /* * FUNCTION: Opens an existing section object * ARGUMENTS: @@ -1868,6 +2359,7 @@ ZwOpenProcess ( * ObjectAttribute = Initialized attributes for the object * RETURNS: Status */ + NTSTATUS STDCALL NtOpenSection( @@ -1951,6 +2443,24 @@ ZwOpenThread( IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId ); + +NTSTATUS +STDCALL +NtOpenThreadToken( + IN HANDLE ThreadHandle, + IN ACCESS_MASK DesiredAccess, + IN BOOLEAN OpenAsSelf, + OUT PHANDLE TokenHandle + ); + +NTSTATUS +STDCALL +ZwOpenThreadToken( + IN HANDLE ThreadHandle, + IN ACCESS_MASK DesiredAccess, + IN BOOLEAN OpenAsSelf, + OUT PHANDLE TokenHandle + ); /* * FUNCTION: Opens an existing timer * ARGUMENTS: @@ -1973,6 +2483,75 @@ ZwOpenTimer( IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes ); + +/* + * FUNCTION: Checks an access token for specific privileges + * ARGUMENTS: + * ClientToken = Handle to a access token structure + * RequiredPrivileges = Specifies the requested privileges. + * Result = Caller supplies storage for the result. If PRIVILEGE_SET_ALL_NECESSARY is + set in the Control member of PRIVILEGES_SET Result + will only be TRUE if all privileges are present in the access token. + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtPrivilegeCheck( + IN HANDLE ClientToken, + IN PPRIVILEGE_SET RequiredPrivileges, + IN PBOOLEAN Result + ); +NTSTATUS +STDCALL +ZwPrivilegeCheck( + IN HANDLE ClientToken, + IN PPRIVILEGE_SET RequiredPrivileges, + IN PBOOLEAN Result + ); + +NTSTATUS +STDCALL +NtPrivilegedServiceAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PUNICODE_STRING ServiceName, + IN HANDLE ClientToken, + IN PPRIVILEGE_SET Privileges, + IN BOOLEAN AccessGranted + ); + +NTSTATUS +STDCALL +ZwPrivilegedServiceAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PUNICODE_STRING ServiceName, + IN HANDLE ClientToken, + IN PPRIVILEGE_SET Privileges, + IN BOOLEAN AccessGranted + ); + +NTSTATUS +STDCALL +NtPrivilegeObjectAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PVOID HandleId, + IN HANDLE ClientToken, + IN ULONG DesiredAccess, + IN PPRIVILEGE_SET Privileges, + IN BOOLEAN AccessGranted + ); + +NTSTATUS +STDCALL +ZwPrivilegeObjectAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PVOID HandleId, + IN HANDLE ClientToken, + IN ULONG DesiredAccess, + IN PPRIVILEGE_SET Privileges, + IN BOOLEAN AccessGranted + ); + /* * FUNCTION: Entry point for native applications * ARGUMENTS: @@ -2295,7 +2874,7 @@ NtQueryInformationAtom( FileModeInformation FILE_MODE_INFORMATION FileAlignmentInformation FILE_ALIGNMENT_INFORMATION FileAllInformation FILE_ALL_INFORMATION - FileAllocationInformation FILE_ALLOCATION_INFORMATION + FileEndOfFileInformation FILE_END_OF_FILE_INFORMATION FileAlternateNameInformation FileStreamInformation FILE_STREAM_INFORMATION @@ -2454,15 +3033,65 @@ NtQueryInformationThread( NTSTATUS STDCALL -ZwQueryIoCompletion( - IN HANDLE CompletionPort, - IN CINT CompletionInformationClass, - OUT PVOID CompletionInformation, - IN ULONG Length, - OUT PULONG ReturnLength +NtQueryInformationToken( + IN HANDLE TokenHandle, + IN TOKEN_INFORMATION_CLASS TokenInformationClass, + OUT PVOID TokenInformation, + IN ULONG TokenInformationLength, + OUT PULONG ReturnLength ); - +NTSTATUS +STDCALL +ZwQueryInformationToken( + IN HANDLE TokenHandle, + IN TOKEN_INFORMATION_CLASS TokenInformationClass, + OUT PVOID TokenInformation, + IN ULONG TokenInformationLength, + OUT PULONG ReturnLength + ); + +/* + * FUNCTION: Query the interval and the clocksource for profiling + * ARGUMENTS: + Interval = + ClockSource = + * RETURNS: Status + */ +NTSTATUS +STDCALL +NtQueryIntervalProfile( + OUT PULONG Interval, + OUT PULONG ClockSource + ); + +NTSTATUS +STDCALL +ZwQueryIntervalProfile( + OUT PULONG Interval, + OUT PULONG ClockSource + ); + + + +NTSTATUS +STDCALL +NtQueryIoCompletion( + IN HANDLE CompletionPort, + IN ULONG CompletionKey, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PULONG NumberOfBytesTransferred + ); +NTSTATUS +STDCALL +ZwQueryIoCompletion( + IN HANDLE CompletionPort, + IN ULONG CompletionKey, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PULONG NumberOfBytesTransferred + ); + + /* * FUNCTION: Queries the information of a registry key object. * ARGUMENTS: @@ -2634,6 +3263,26 @@ ZwQuerySection( OUT PULONG ResultLength ); +NTSTATUS +STDCALL +NtQuerySecurityObject( + IN HANDLE Object, + IN CINT SecurityObjectInformationClass, + OUT PVOID SecurityObjectInformation, + IN ULONG Length, + OUT PULONG ReturnLength + ); + +NTSTATUS +STDCALL +ZwQuerySecurityObject( + IN HANDLE Object, + IN CINT SecurityObjectInformationClass, + OUT PVOID SecurityObjectInformation, + IN ULONG Length, + OUT PULONG ReturnLength + ); + /* * FUNCTION: Queries the information of a semaphore. @@ -2913,9 +3562,9 @@ ZwQueryVirtualMemory( * ARGUMENTS: * FileHandle = Handle to a file object on the target volume ReturnLength = DataWritten - FSInformation = Caller should supply storage for the information structure. + FsInformation = Caller should supply storage for the information structure. Length = Size of the information structure - FSInformationClass = Index to a information structure + FsInformationClass = Index to a information structure FileFsVolumeInformation FILE_FS_VOLUME_INFORMATION FileFsLabelInformation FILE_FS_LABEL_INFORMATION @@ -2936,9 +3585,9 @@ STDCALL NtQueryVolumeInformationFile( IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, - OUT PVOID FSInformation, + OUT PVOID FsInformation, IN ULONG Length, - IN CINT FSInformationClass + IN FS_INFORMATION_CLASS FsInformationClass ); NTSTATUS @@ -2946,9 +3595,9 @@ STDCALL ZwQueryVolumeInformationFile( IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, - OUT PVOID FSInformation, + OUT PVOID FsInformation, IN ULONG Length, - IN CINT FSInformationClass + IN FS_INFORMATION_CLASS FsInformationClass ); // draft // FIXME: Should I specify if the apc is user or kernel mode somewhere ?? @@ -3204,7 +3853,7 @@ NtRemoveIoCompletion( OUT PULONG CompletionKey, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PULONG CompletionStatus, - ULONG WaitTime + IN PLARGE_INTEGER WaitTime ); NTSTATUS @@ -3214,7 +3863,7 @@ ZwRemoveIoCompletion( OUT PULONG CompletionKey, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PULONG CompletionStatus, - ULONG WaitTime + IN PLARGE_INTEGER WaitTime ); /* * FUNCTION: Replaces one registry key with another @@ -3288,13 +3937,13 @@ NTSTATUS STDCALL NtResumeThread( IN HANDLE ThreadHandle, - IN PULONG SuspendCount + OUT PULONG SuspendCount ); NTSTATUS STDCALL ZwResumeThread( IN HANDLE ThreadHandle, - IN PULONG SuspendCount + OUT PULONG SuspendCount ); /* * FUNCTION: Writes the content of a registry key to ascii file @@ -3338,6 +3987,24 @@ ZwSetContextThread( IN HANDLE ThreadHandle, IN PCONTEXT Context ); + +/* + * FUNCTION: Sets the default hard error port + * ARGUMENTS: + * PortHandle = Handle to the port + * NOTE: The hard error port is used for first change exception handling + * RETURNS: Status + */ +NTSTATUS +STDCALL +NtSetDefaultHardErrorPort( + IN HANDLE PortHandle + ); +NTSTATUS +STDCALL +ZwSetDefaultHardErrorPort( + IN HANDLE PortHandle + ); /* * FUNCTION: Sets the extended attributes of a file. * ARGUMENTS: @@ -3401,13 +4068,13 @@ ZwSetEvent( NTSTATUS STDCALL NtSetHighEventPair( - IN HANDLE EventPair + IN HANDLE EventPairHandle ); NTSTATUS STDCALL ZwSetHighEventPair( - IN HANDLE EventPair + IN HANDLE EventPairHandle ); /* * FUNCTION: Sets the high part of an event pair and wait for the low part @@ -3418,12 +4085,12 @@ ZwSetHighEventPair( NTSTATUS STDCALL NtSetHighWaitLowEventPair( - IN HANDLE EventPair + IN HANDLE EventPairHandle ); NTSTATUS STDCALL ZwSetHighWaitLowEventPair( - IN HANDLE EventPair + IN HANDLE EventPairHandle ); /* @@ -3609,8 +4276,48 @@ ZwSetInformationThread( IN ULONG ThreadInformationLength ); - //FIXME: Are the arguments correct -// Might be a ordinary set function +/* + * FUNCTION: Changes a set of token specific parameters + * ARGUMENTS: + * TokenHandle = Handle to the token + * TokenInformationClass = Index to a certain information structure. + * Can be one of the following values: + * + TokenUser TOKEN_USER + TokenGroups TOKEN_GROUPS + TokenPrivileges TOKEN_PRIVILEGES + TokenOwner TOKEN_OWNER + TokenPrimaryGroup TOKEN_PRIMARY_GROUP + TokenDefaultDacl TOKEN_DEFAULT_DACL + TokenSource TOKEN_SOURCE + TokenType TOKEN_TYPE + TokenImpersonationLevel TOKEN_IMPERSONATION_LEVEL + TokenStatistics TOKEN_STATISTICS + * + * TokenInformation = Caller supplies storage for information structure. + * TokenInformationLength = Size of the information structure + * RETURNS: Status +*/ + +NTSTATUS +STDCALL +NtSetInformationToken( + IN HANDLE TokenHandle, + IN TOKEN_INFORMATION_CLASS TokenInformationClass, + OUT PVOID TokenInformation, + IN ULONG TokenInformationLength + ); + +NTSTATUS +STDCALL +ZwSetInformationToken( + IN HANDLE TokenHandle, + IN TOKEN_INFORMATION_CLASS TokenInformationClass, + OUT PVOID TokenInformation, + IN ULONG TokenInformationLength + ); + + /* * FUNCTION: Sets an io completion * ARGUMENTS: @@ -3639,20 +4346,30 @@ ZwSetIoCompletion( IN ULONG NumberOfBytesToTransfer, OUT PULONG NumberOfBytesTransferred ); -//FIXME: Should I have more parameters ? + /* - * FUNCTION: Initializes the Local Descriptor Table + * FUNCTION: Set properties for profiling * ARGUMENTS: - ProcessHandle = - LdtEntry = + * Interval = + * ClockSource = * RETURNS: Status -*/ -//NTSTATUS -//STDCALL -//NtSetLdtEntries( -// HANDLE ProcessHandle, -// PVOID LdtEntry // LDT_ENTR -// ); + * + */ + +NTSTATUS +STDCALL +NtSetIntervalProfile( + ULONG Interval, + ULONG ClockSource + ); + +NTSTATUS +STDCALL +ZwSetIntervalProfile( + ULONG Interval, + ULONG ClockSource + ); + /* * FUNCTION: Sets the low part of an event pair @@ -3688,7 +4405,23 @@ ZwSetLowWaitHighEventPair( HANDLE EventPair ); -//FIXME: Should Value be a void pointer or a pointer to a unicode string ? +NTSTATUS +STDCALL +NtSetSecurityObject( + IN HANDLE Handle, + IN SECURITY_INFORMATION SecurityInformation, + IN PSECURITY_DESCRIPTOR SecurityDescriptor + ); + +NTSTATUS +STDCALL +ZwSetSecurityObject( + IN HANDLE Handle, + IN SECURITY_INFORMATION SecurityInformation, + IN PSECURITY_DESCRIPTOR SecurityDescriptor + ); + + /* * FUNCTION: Sets a system environment variable * ARGUMENTS: @@ -3925,6 +4658,46 @@ ZwSignalAndWaitForSingleObject( IN PLARGE_INTEGER Time, PULONG NumberOfWaitingThreads OPTIONAL ); + +/* + * FUNCTION: Starts profiling + * ARGUMENTS: + * ProfileHandle = Handle to the profile + * RETURNS: Status + */ + + +NTSTATUS +STDCALL +NtStartProfile( + HANDLE ProfileHandle + ); + +NTSTATUS +STDCALL +ZwStartProfile( + HANDLE ProfileHandle + ); + +/* + * FUNCTION: Stops profiling + * ARGUMENTS: + * ProfileHandle = Handle to the profile + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtStopProfile( + HANDLE ProfileHandle + ); + +NTSTATUS +STDCALL +ZwStopProfile( + HANDLE ProfileHandle + ); + /* * FUNCTION: Increments a thread's resume count * ARGUMENTS: @@ -4064,8 +4837,8 @@ STDCALL NtUnlockFile( IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, - IN LARGE_INTEGER ByteOffset, - IN LARGE_INTEGER Lenght, + IN PLARGE_INTEGER ByteOffset, + IN PLARGE_INTEGER Lenght, OUT PULONG Key OPTIONAL ); NTSTATUS @@ -4073,8 +4846,8 @@ STDCALL ZwUnlockFile( IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, - IN LARGE_INTEGER ByteOffset, - IN LARGE_INTEGER Lenght, + IN PLARGE_INTEGER ByteOffset, + IN PLARGE_INTEGER Lenght, OUT PULONG Key OPTIONAL ); @@ -4092,19 +4865,19 @@ ZwUnlockFile( NTSTATUS STDCALL NtUnlockVirtualMemory( - HANDLE ProcessHandle, - PVOID BaseAddress, - ULONG NumberOfBytesToUnlock, - PULONG NumberOfBytesUnlocked OPTIONAL + IN HANDLE ProcessHandle, + IN PVOID BaseAddress, + IN ULONG NumberOfBytesToUnlock, + OUT PULONG NumberOfBytesUnlocked OPTIONAL ); NTSTATUS STDCALL ZwUnlockVirtualMemory( - HANDLE ProcessHandle, - PVOID BaseAddress, - ULONG NumberOfBytesToUnlock, - PULONG NumberOfBytesUnlocked OPTIONAL + IN HANDLE ProcessHandle, + IN PVOID BaseAddress, + IN ULONG NumberOfBytesToUnlock, + OUT PULONG NumberOfBytesUnlocked OPTIONAL ); /* * FUNCTION: Unmaps a piece of virtual memory backed by a file. @@ -4143,7 +4916,7 @@ NTSTATUS STDCALL NtWaitForMultipleObjects ( IN ULONG Count, - IN PHANDLE Object[], + IN HANDLE Object[], IN CINT WaitType, IN BOOLEAN Alertable, IN PLARGE_INTEGER Time @@ -4153,7 +4926,7 @@ NTSTATUS STDCALL ZwWaitForMultipleObjects ( IN ULONG Count, - IN PHANDLE Object[], + IN HANDLE Object[], IN CINT WaitType, IN BOOLEAN Alertable, IN PLARGE_INTEGER Time @@ -4171,7 +4944,7 @@ ZwWaitForMultipleObjects ( NTSTATUS STDCALL NtWaitForSingleObject ( - IN PHANDLE Object, + IN HANDLE Object, IN BOOLEAN Alertable, IN PLARGE_INTEGER Time ); @@ -4179,21 +4952,41 @@ NtWaitForSingleObject ( NTSTATUS STDCALL ZwWaitForSingleObject ( - IN PHANDLE Object, + IN HANDLE Object, IN BOOLEAN Alertable, IN PLARGE_INTEGER Time ); +/* + * FUNCTION: Waits for the high part of an eventpair to become signalled + * ARGUMENTS: + * EventPairHandle = Handle to the event pair. + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtWaitHighEventPair( + IN HANDLE EventPairHandle + ); + +NTSTATUS +STDCALL +ZwWaitHighEventPair( + IN HANDLE EventPairHandle + ); + + NTSTATUS STDCALL NtWaitLowEventPair( - IN HANDLE EventHandle + IN HANDLE EventPairHandle ); NTSTATUS STDCALL ZwWaitLowEventPair( - IN HANDLE EventHandle + IN HANDLE EventPairHandle ); /* * FUNCTION: Writes data to a file @@ -4347,58 +5140,45 @@ ZwYieldExecution( * These prototypes are unknown as yet */ NTSTATUS STDCALL NtAcceptConnectPort(VOID); -NTSTATUS STDCALL NtAccessCheckAndAuditAlarm(VOID); -NTSTATUS STDCALL NtAdjustGroupsToken(VOID); -NTSTATUS STDCALL NtAdjustPrivilegesToken(VOID); -NTSTATUS STDCALL NtAllocateUuids(VOID); -NTSTATUS STDCALL NtCloseObjectAuditAlarm(VOID); + + NTSTATUS STDCALL NtCompleteConnectPort(VOID); NTSTATUS STDCALL NtConnectPort(VOID); -NTSTATUS STDCALL NtCreateMailslotFile(VOID); -NTSTATUS STDCALL NtCreateNamedPipeFile(VOID); + NTSTATUS STDCALL NtCreatePort(VOID); -NTSTATUS STDCALL NtCreateProfile(VOID); NTSTATUS STDCALL NtCreateToken(VOID); -NTSTATUS STDCALL NtDeleteObjectAuditAlarm(VOID); -NTSTATUS STDCALL NtDuplicateToken(VOID); + NTSTATUS STDCALL NtGetPlugPlayEvent(VOID); NTSTATUS STDCALL NtImpersonateClientOfPort(VOID); -NTSTATUS STDCALL NtImpersonateThread(VOID); + NTSTATUS STDCALL NtListenPort(VOID); NTSTATUS STDCALL NtLoadKey2(VOID); -NTSTATUS STDCALL NtOpenEventPair(VOID); -NTSTATUS STDCALL NtOpenObjectAuditAlarm(VOID); -NTSTATUS STDCALL NtOpenProcessToken(VOID); -NTSTATUS STDCALL NtOpenThreadToken(VOID); + + NTSTATUS STDCALL NtPlugPlayControl(VOID); -NTSTATUS STDCALL NtPrivilegeCheck(VOID); -NTSTATUS STDCALL NtPrivilegedServiceAuditAlarm(VOID); -NTSTATUS STDCALL NtPrivilegeObjectAuditAlarm(VOID); + NTSTATUS STDCALL NtQueryDefaultLocale(VOID); -NTSTATUS STDCALL NtQueryIoCompletion(VOID); + NTSTATUS STDCALL NtQueryInformationPort(VOID); -NTSTATUS STDCALL NtQueryInformationToken(VOID); -NTSTATUS STDCALL NtQueryIntervalProfile(VOID); + NTSTATUS STDCALL NtQueryOleDirectoryFile(VOID); -NTSTATUS STDCALL NtQuerySecurityObject(VOID); + NTSTATUS STDCALL NtRaiseHardError(VOID); NTSTATUS STDCALL NtReadRequestData(VOID); NTSTATUS STDCALL NtReplyPort(VOID); NTSTATUS STDCALL NtReplyWaitReceivePort(VOID); NTSTATUS STDCALL NtReplyWaitReplyPort(VOID); NTSTATUS STDCALL NtRequestPort(VOID); -NTSTATUS STDCALL NtSetDefaultHardErrorPort(VOID); + NTSTATUS STDCALL NtSetDefaultLocale(VOID); -NTSTATUS STDCALL NtSetInformationToken(VOID); -NTSTATUS STDCALL NtSetIntervalProfile(VOID); + NTSTATUS STDCALL NtSetLdtEntries(VOID); -NTSTATUS STDCALL NtSetSecurityObject(VOID); + NTSTATUS STDCALL NtSetSystemPowerState(VOID); -NTSTATUS STDCALL NtStartProfile(VOID); -NTSTATUS STDCALL NtStopProfile(VOID); + NTSTATUS STDCALL NtSystemDebugControl(VOID); NTSTATUS STDCALL NtVdmControl(VOID); -NTSTATUS STDCALL NtWaitHighEventPair(VOID); + NTSTATUS STDCALL NtWriteRequestData(VOID); NTSTATUS STDCALL NtW32Call(VOID); NTSTATUS STDCALL NtCreateChannel(VOID); diff --git a/reactos/include/ddk/zwtypes.h b/reactos/include/ddk/zwtypes.h index b5cc1f4db6f..eec3f0d0e5d 100644 --- a/reactos/include/ddk/zwtypes.h +++ b/reactos/include/ddk/zwtypes.h @@ -265,8 +265,8 @@ typedef struct _OBJECT_NAME_INFORMATION typedef struct _OBJECT_DATA_INFORMATION { - BOOL bInheritHanlde; - BOOL bProtectFromClose; + BOOLEAN bInheritHandle; + BOOLEAN bProtectFromClose; } OBJECT_DATA_INFORMATION, *POBJECT_DATA_INFORMATION; diff --git a/reactos/include/kernel32/atom.h b/reactos/include/kernel32/atom.h index 27eec07af9b..41ffeac2c52 100644 --- a/reactos/include/kernel32/atom.h +++ b/reactos/include/kernel32/atom.h @@ -1,4 +1,12 @@ - +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: include/kernel32/atom.h + * PURPOSE: Include file for lib/kernel32/atom.c + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ /******************************************************************** @@ -24,7 +32,7 @@ Cambridge, MA 02139, USA. #define Atoms__h #include -#include +//#include //#include @@ -40,18 +48,11 @@ typedef ATOMENTRY *LPATOMENTRY; typedef struct { ATOMENTRY *AtomTable; /* pointer to table data */ - wchar_t *AtomData; /* pointer to name data */ + WCHAR *AtomData; /* pointer to name data */ unsigned long TableSize; /* number items in this table */ unsigned long DataSize; /* space used by string data */ LPVOID lpDrvData; } ATOMTABLE; typedef ATOMTABLE *LPATOMTABLE; - - - - - - - #endif /* Atoms__h */ diff --git a/reactos/include/kernel32/li.h b/reactos/include/kernel32/li.h new file mode 100644 index 00000000000..63072ad618d --- /dev/null +++ b/reactos/include/kernel32/li.h @@ -0,0 +1,20 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: include/kernel32/li.h + * PURPOSE: Include file for lib/kernel32 to discard large integers + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ +#ifdef COMPILER_LARGE_INTEGERS +#define GET_LARGE_INTEGER_HIGH_PART(LargeInteger) ( ( LargeInteger >> 32) ) +#define GET_LARGE_INTEGER_LOW_PART(LargeInteger) ( (LargeInteger & 0xFFFFFFFF) ) +#define SET_LARGE_INTEGER_HIGH_PART(LargeInteger,Signed_Long) ( LargeInteger |= ( ((LARGE_INTEGER)Signed_Long) << 32 ) ) +#define SET_LARGE_INTEGER_LOW_PART(LargeInteger,Unsigned_Long) ( LargeInteger |= Unsigned_Long ) +#else +#define GET_LARGE_INTEGER_HIGH_PART(LargeInteger) ( ( LargeInteger.HighPart) ) +#define GET_LARGE_INTEGER_LOW_PART(LargeInteger) ( (LargeInteger.LowPart) ) +#define SET_LARGE_INTEGER_HIGH_PART(LargeInteger,Signed_Long) ( LargeInteger.HighPart= Signed_Long ) +#define SET_LARGE_INTEGER_LOW_PART(LargeInteger,Unsigned_Long) ( LargeInteger.LowPart = Unsigned_Long ) +#endif \ No newline at end of file diff --git a/reactos/include/kernel32/proc.h b/reactos/include/kernel32/proc.h new file mode 100644 index 00000000000..94cdb5d0125 --- /dev/null +++ b/reactos/include/kernel32/proc.h @@ -0,0 +1,25 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: include/kernel32/process.h + * PURPOSE: Include file for lib/kernel32/proc.c + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ + + +#include +#include + + +NT_PEB *GetCurrentPeb(VOID); + +typedef +DWORD +(*WaitForInputIdleType)( + HANDLE hProcess, + DWORD dwMilliseconds); + + + diff --git a/reactos/include/kernel32/thread.h b/reactos/include/kernel32/thread.h index effe447a857..ce220eb9f1e 100644 --- a/reactos/include/kernel32/thread.h +++ b/reactos/include/kernel32/thread.h @@ -1,56 +1,15 @@ /* -This file contains a proposal for Thread Environment Block. -*/ -#ifndef __TEB_DEFINED -#define __TEB_DEFINED - - -typedef struct _NT_TIB { - - struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList; - - void *StackBase; - void *StackLimit; - void *SubSystemTib; - union { - void *FiberData; - DWORD Version; - }; - void *ArbitraryUserPointer; - struct _NT_TIB *Self; - -} NT_TIB; + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: include/kernel32/thread.h + * PURPOSE: Include file for lib/kernel32/thread.c + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ +#include +#include +NT_TEB *GetTeb(VOID); - - -typedef struct _NT_TEB -{ - - NT_TIB Tib; - DWORD dwProcessId; - DWORD dwThreadId; - HANDLE hRPC; - NT_PEB *pPeb; - DWORD dwErrCode; - WORD nMutexCount; - LCID Locale; - //HQUEUE MessageQueue - DWORD dwTlsIndex ; - LPVOID TlsData[512]; - - -} NT_TEB; - - -// should be an inline asm macro - -NT_TEB *GetTeb() -{ - return NULL; -} - -#endif - - diff --git a/reactos/lib/advapi32/makefile b/reactos/lib/advapi32/makefile new file mode 100644 index 00000000000..bb5bf2c9c25 --- /dev/null +++ b/reactos/lib/advapi32/makefile @@ -0,0 +1,19 @@ +all: advapi32.a + +TOKEN_OBJECTS = token/access.o + +REGISTRY_OBJECTS = reg/reg.o + +SEC_OBJECTS = sec/sec.o sec/rtlsec.o + + + +OBJECTS = $(TOKEN_OBJECTS) $(REGISTRY_OBJECTS) $(SEC_OBJECTS) + + +advapi32.a: $(OBJECTS) + $(AR) vrcs advapi32.a $(OBJECTS) + +dummy: + +include ../../rules.mak diff --git a/reactos/lib/advapi32/reg/reg.c b/reactos/lib/advapi32/reg/reg.c new file mode 100644 index 00000000000..2bc2cd42e09 --- /dev/null +++ b/reactos/lib/advapi32/reg/reg.c @@ -0,0 +1,42 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/advapi32/sec/rtlsec.c + * PURPOSE: Registry functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ +#include +#include +#undef WIN32_LEAN_AND_MEAN + +LONG +STDCALL +RegOpenKeyW ( + HKEY hKey, + LPCWSTR lpSubKey, + PHKEY phkResult + ) +{ + NTSTATUS errCode; + UNICODE_STRING SubKeyString; + + SubKeyString.Buffer = lpSubKey; + SubKeyString.Length = wcslen(lpSubKey); + SubKeyString.MaximumLength = SubKeyString.Length; + + ObjectAttributes.RootDirectory = hKey; + ObjectAttributes.ObjectName = &SubKeyString; + ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE; + errCode = NtOpenKey( + phkResult, + GENERIC_ALL, + &ObjectAttributes + ); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} \ No newline at end of file diff --git a/reactos/lib/advapi32/sec/rtlsec.c b/reactos/lib/advapi32/sec/rtlsec.c new file mode 100644 index 00000000000..89d656d573b --- /dev/null +++ b/reactos/lib/advapi32/sec/rtlsec.c @@ -0,0 +1,417 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/advapi32/reg/reg.c + * PURPOSE: Registry functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + Modified form Wine [ Marcus Meissner ] + * UPDATE HISTORY: + * Created 01/11/98 + */ + + +#undef WIN32_LEAN_AND_MEAN +#include +#include +#include "rtlsec.h" + + + + +NTSTATUS +STDCALL +RtlLengthSid(LPSID Sid) +{ + return sizeof(DWORD)*Sid->SubAuthorityCount+sizeof(SID); +} + +NTSTATUS +STDCALL +RtlCreateAcl(LPACL Acl,DWORD Size,DWORD Revision) { + if (Revision!=ACL_REVISION) + return STATUS_INVALID_PARAMETER; + if (size0xFFFF) + return STATUS_INVALID_PARAMETER; 52 + memset(Acl,'\0',sizeof(ACL)); + Acl->AclRevision = Revision; + Acl->AclSize = Size; + Acl->AceCount = 0; + return STATUS_SUCCESS; +} + +/************************************************************************** +* RtlFirstFreeAce [NTDLL] +* looks for the AceCount+1 ACE, and if it is still within the alloced +* ACL, return a pointer to it +*/ +BOOLEAN +STDCALL +RtlFirstFreeAce(LPACL Acl,LPACE_HEADER *AceHeader) +{ + LPACE_HEADER Ace; + int i; + *AceHeader = 0; + Ace = (LPACE_HEADER)(Acl+1); + for (i=0;iAceCount;i++) { + if ((DWORD)Ace>=(((DWORD)Acl)+Acl->AclSize)) + return 0; + Ace = (LPACE_HEADER)(((BYTE*)Ace)+Ace->AceSize); + } + if ((DWORD)Ace>=(((DWORD)Acl)+Acl->AclSize)) + return 0; + *AceHeader = Ace; + return 1; +} +/************************************************************************** + * RtlAddAce [NTDLL] + */ +NTSTATUS +STDCALL +RtlAddAce(LPACL Acl,DWORD Revision,DWORD xnrofaces, LPACE_HEADER AceStart,DWORD AceLen) +{ + LPACE_HEADER ace,targetace; + int nrofaces; + if (Acl->AclRevision != ACL_REVISION) + return STATUS_INVALID_PARAMETER; + if (!RtlFirstFreeAce(Acl,&targetace)) + return STATUS_INVALID_PARAMETER; + nrofaces=0; + ace=AceStart; + while (((DWORD)ace-(DWORD)AceStart)AceSize); + } + if ((DWORD)targetace+AceLen>(DWORD)Acl+Acl->AclSize) /* too much aces */ + return STATUS_INVALID_PARAMETER; + memcpy((LPBYTE)targetace,AceStart,AceLen); + Acl->AceCount+=nrofaces; + return 0; +} +/************************************************************************** + * RtlCreateSecurityDescriptor [NTDLL] + */ + +// Win32: InitializeSecurityDescriptor +NTSTATUS +STDCALL +RtlCreateSecurityDescriptor(LPSECURITY_DESCRIPTOR SecurityDescriptor ,ULONG Revision) +{ + if (Revision !=SECURITY_DESCRIPTOR_REVISION) + return STATUS_UNKNOWN_REVISION; + memset(SecurityDescriptor,'\0',sizeof(*SecurityDescriptor)); + SecurityDescriptor->Revision = SECURITY_DESCRIPTOR_REVISION; + return STATUS_SUCCESS; +} + + +// Win32: IsValidSecurityDescriptor +BOOLEAN +NTAPI +RtlValidSecurityDescriptor( + PSECURITY_DESCRIPTOR SecurityDescriptor + ) +{ + if ( SecurityDescriptor == NULL ) + return FALSE; + if ( SecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION ) + return FALSE; + +} + +// Win32: GetSecurityDescriptorLength +ULONG +NTAPI +RtlLengthSecurityDescriptor( + PSECURITY_DESCRIPTOR SecurityDescriptor + ) +{ + ULONG Size; + Size = SECURITY_DESCRIPTOR_MIN_LENGTH; + if ( SecurityDescriptor == NULL ) + return 0; + + if ( SecurityDescriptor->Owner != NULL ) + Size += SecurityDescriptor->Owner->SubAuthorityCount; + if ( SecurityDescriptor->Group != NULL ) + Size += SecurityDescriptor->Group->SubAuthorityCount; + + + if ( SecurityDescriptor->Sacl != NULL ) + Size += SecurityDescriptor->Sacl->AclSize; + if ( SecurityDescriptor->Dacl != NULL ) + Size += SecurityDescriptor->Dacl->AclSize; + + return Size; + + + +} + +/************************************************************************** +* RtlSetDaclSecurityDescriptor [NTDLL] +*/ +// Win32: SetSecurityDescriptorDacl +NTSTATUS +NTAPI +RtlSetDaclSecurityDescriptor( + PSECURITY_DESCRIPTOR SecurityDescriptor, + BOOLEAN DaclPresent, + PACL Dacl, + BOOLEAN DaclDefaulted + ) +{ + if (SecurityDescriptor->Revision!=SECURITY_DESCRIPTOR_REVISION) + return STATUS_UNKNOWN_REVISION; + if (SecurityDescriptor->Control & SE_SELF_RELATIVE) + return STATUS_INVALID_SECURITY_DESCR; + if (!DaclPresent) { + SecurityDescriptor->Control &= ~SE_DACL_PRESENT; + return 0; + } + SecurityDescriptor->Control |= SE_DACL_PRESENT; + SecurityDescriptor->Dacl = Dacl; + if (DaclDefaulted) + SecurityDescriptor->Control |= SE_DACL_DEFAULTED; + else + SecurityDescriptor->Control &= ~SE_DACL_DEFAULTED; + return STATUS_SUCCESS; +} + + +// Win32: GetSecurityDescriptorDacl +NTSTATUS +NTAPI +RtlGetDaclSecurityDescriptor( + PSECURITY_DESCRIPTOR SecurityDescriptor, + PBOOLEAN DaclPresent, + PACL *Dacl, + PBOOLEAN DaclDefaulted + ) +{ + if ( SecurityDescriptor == NULL || DaclPresent == NULL || Dacl == NULL || DaclDefaulted == NULL ) + return STATUS_INVALID_PARAMETER; + if ( SecurityDescriptor->Dacl != NULL ) { + Dacl = SecurityDescriptor->Dacl; + if ( Dacl->AceCount > 0 ) + *DaclPresent = TRUE; + else + *DaclPresent = FALSE; + if ( SecurityDescriptor->Control & SE_DACL_DEFAULTED == + SE_DACL_DEFAULTED ) { + *OwnerDefaulted = TRUE; + else + *OwnerDefaulted = FALSE; + } + +} + +/************************************************************************** +* RtlSetSaclSecurityDescriptor [NTDLL]147 */ +// Win32: SetSecurityDescriptorSacl +// NOTE: NT does not export RtlGetSaclSecurityDescriptor! +NTSTATUS +STDCALL +RtlSetSaclSecurityDescriptor ( + LPSECURITY_DESCRIPTOR SecurityDescriptor,BOOLEAN SaclPresent,LPACL Sacl,BOOLEAN SaclDefaulted) +{ + if (SecurityDescriptor->Revision!=SECURITY_DESCRIPTOR_REVISION) + return STATUS_UNKNOWN_REVISION; + if (SecurityDescriptor->Control & SE_SELF_RELATIVE) + return STATUS_INVALID_SECURITY_DESCR; + if (!SaclPresent) { + SecurityDescriptor->Control &= ~SE_SACL_PRESENT; + return 0; + } + SecurityDescriptor->Control |= SE_SACL_PRESENT; + SecurityDescriptor->Sacl = Sacl; + if (SaclDefaulted) + SecurityDescriptor->Control |= SE_SACL_DEFAULTED; + else + SecurityDescriptor->Control &= ~SE_SACL_DEFAULTED; + return NULL; +} +/************************************************************************** +* RtlSetOwnerSecurityDescriptor [NTDLL] +*/ +NTSTATUS +STDCALL +RtlSetOwnerSecurityDescriptor (LPSECURITY_DESCRIPTOR SecurityDescriptor,LPSID Owner,BOOLEAN OwnerDefaulted) +{ + if (SecurityDescriptor->Revision!=SECURITY_DESCRIPTOR_REVISION) + return STATUS_UNKNOWN_REVISION; + if (SecurityDescriptor->Control & SE_SELF_RELATIVE) + return STATUS_INVALID_SECURITY_DESCR;180 + SecurityDescriptor->Owner = Owner; + if (OwnerDefaulted) + SecurityDescriptor->Control |= SE_OWNER_DEFAULTED; + else + SecurityDescriptor->Control &= ~SE_OWNER_DEFAULTED; + return STATUS_SUCCESS; +} + + +// Win32: GetSecurityDescriptorOwner +NTSTATUS +NTAPI +RtlGetOwnerSecurityDescriptor( + PSECURITY_DESCRIPTOR SecurityDescriptor, + PSID *Owner, + PBOOLEAN OwnerDefaulted +) +{ + if ( SecurityDescriptor == NULL || Owner == NULL || OwnerDefaulted == NULL ) + return STATUS_INVALID_PARAMETER; + Owner = SecurityDescriptor->Owner; + if ( Owner != NULL ) { + if ( SecurityDescriptor->Control & SE_OWNER_DEFAULTED == + SE_OWNER_DEFAULTED ) { + *OwnerDefaulted = TRUE; + else + *OwnerDefaulted = FALSE; + } +} + + +/************************************************************************** +* RtlSetOwnerSecurityDescriptor [NTDLL] +*/ +// Win32: SetSecurityDescriptorGroup +NTSTATUS +STDCALL +RtlSetGroupSecurityDescriptor (LPSECURITY_DESCRIPTOR SecurityDescriptor,LPSID Group,BOOLEAN GroupDefaulted) +{ + if (SecurityDescriptor->Revision!=SECURITY_DESCRIPTOR_REVISION) + return STATUS_UNKNOWN_REVISION; + if (SecurityDescriptor->Control & SE_SELF_RELATIVE) + return STATUS_INVALID_SECURITY_DESCR; + SecurityDescriptor->Group = Group; + if (GroupDefaulted) + SecurityDescriptor->Control |= SE_GROUP_DEFAULTED; + else + SecurityDescriptor->Control &= ~SE_GROUP_DEFAULTED; + return STATUS_SUCCESS; +} + +// Win32: GetSecurityDescriptorGroup +NTSTATUS +NTAPI +RtlGetGroupSecurityDescriptor( + PSECURITY_DESCRIPTOR SecurityDescriptor, + PSID *Group, + PBOOLEAN GroupDefaulted +) +{ + if ( SecurityDescriptor == NULL || Group == NULL || GroupDefaulted == NULL ) + return STATUS_INVALID_PARAMETER; + Group = SecurityDescriptor->Group; + if ( Group != NULL ) { + if ( SecurityDescriptor->Control & SE_GROUP_DEFAULTED == + SE_GROUP_DEFAULTED ) { + *GroupDefaulted = TRUE; + else + *GroupDefaulted = FALSE; + } + + + +} + + + + +// Win32: GetSidLengthRequired +ULONG +NTAPI +RtlLengthRequiredSid( + UCHAR SubAuthorityCount + ) +{ + return sizeof(DWORD)*SubAuthorityCount+sizeof(SID); +} + +NTSTATUS +STDCALL +RtlInitializeSid(LPSID Sid,LPSID_IDENTIFIER_AUTHORITY SidIdentifierAuthority, DWORD nSubAuthorityCount) +{ + BYTE a = c&0xff; + if (a>=SID_MAX_SUB_AUTHORITIES) + return a; + Sid->SubAuthorityCount = nSubAuthorityCount; + Sid->Revision = SID_REVISION; + memcpy(&(Sid->IdentifierAuthority),SidIdentifierAuthority,sizeof(SID_IDENTIFIER_AUTHORITY)); + return STATUS_SUCCESS; +} + + +// Win32: GetSidSubAuthority +PULONG +NTAPI +RtlSubAuthoritySid( + PSID pSid, + ULONG nSubAuthority + ) +{ + return &(pSid->SubAuthority[nSubAuthority]); +} + +// Win32: IsEqualSid +BOOLEAN +NTAPI +RtlEqualSid( + PSID Sid1, + PSID Sid2 + ) +{ + if ( Sid1 == NULL || Sid2 == NULL ) + return STATUS_INVALID_PARAMETER; + + if ( Sid1 == Sid2 ) + return STATUS_SUCCESS; + + +} + + +// Win32: MakeSelfRelativeSD +NTSTATUS +NTAPI +RtlAbsoluteToSelfRelativeSD( + PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor, + PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor, + PULONG BufferLength + ) +{ + +} + +NTSTATUS +NTAPI +RtlValidSid( + PSID Sid + ) +{ + if ( Sid == NULL ) + return STATUS_INVALID_PARAMETER; + + if ( Sid->Revision == SID_REVISION ) + return STATUS_SUCCESS; +} + + + +LPBYTE STDCALL RtlSubAuthorityCountSid(LPSID Sid) +{ + return ((LPBYTE)Sid)+1; +} + + +DWORD STDCALL RtlCopySid(DWORD Length,LPSID DestinationSid,LPSID SourceSid) +{ + if (Length<(SourceSid->SubAuthorityCount*4+8)) + return STATUS_BUFFER_TOO_SMALL; + memmove(DestinationSid,SourceSid,SourceSid->SubAuthorityCount*4+8); + return STATUS_SUCCESS; +} + diff --git a/reactos/lib/advapi32/sec/rtlsec.h b/reactos/lib/advapi32/sec/rtlsec.h new file mode 100644 index 00000000000..51f3d1eb55d --- /dev/null +++ b/reactos/lib/advapi32/sec/rtlsec.h @@ -0,0 +1,133 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/advapi32/sec/rtlsec.h + * PURPOSE: Registry functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ +NTSTATUS +STDCALL +RtlLengthSid(LPSID Sid); + +NTSTATUS +STDCALL +RtlCreateAcl(LPACL Acl,DWORD Size,DWORD Revision); + +BOOLEAN +STDCALL +RtlFirstFreeAce(LPACL Acl,LPACE_HEADER *AceHeader); + +NTSTATUS +STDCALL +RtlAddAce(LPACL Acl,DWORD Revision,DWORD xnrofaces, LPACE_HEADER AceStart,DWORD AceLen) + +NTSTATUS +STDCALL +RtlCreateSecurityDescriptor(LPSECURITY_DESCRIPTOR SecurityDescriptor ,ULONG Revision); + +BOOLEAN +NTAPI +RtlValidSecurityDescriptor( + PSECURITY_DESCRIPTOR SecurityDescriptor + ); + +ULONG +NTAPI +RtlLengthSecurityDescriptor( + PSECURITY_DESCRIPTOR SecurityDescriptor + ); + +NTSTATUS +NTAPI +RtlSetDaclSecurityDescriptor( + PSECURITY_DESCRIPTOR SecurityDescriptor, + BOOLEAN DaclPresent, + PACL Dacl, + BOOLEAN DaclDefaulted + ); + +NTSTATUS +NTAPI +RtlGetDaclSecurityDescriptor( + PSECURITY_DESCRIPTOR SecurityDescriptor, + PBOOLEAN DaclPresent, + PACL *Dacl, + PBOOLEAN DaclDefaulted + ); + +NTSTATUS +STDCALL +RtlSetSaclSecurityDescriptor ( + LPSECURITY_DESCRIPTOR SecurityDescriptor,BOOLEAN SaclPresent,LPACL Sacl,BOOLEAN SaclDefaulted); + +NTSTATUS +STDCALL +RtlSetOwnerSecurityDescriptor (LPSECURITY_DESCRIPTOR SecurityDescriptor,LPSID Owner,BOOLEAN OwnerDefaulted); + +NTSTATUS +NTAPI +RtlGetOwnerSecurityDescriptor( + PSECURITY_DESCRIPTOR SecurityDescriptor, + PSID *Owner, + PBOOLEAN OwnerDefaulted +); + +NTSTATUS +STDCALL +RtlSetGroupSecurityDescriptor (LPSECURITY_DESCRIPTOR SecurityDescriptor,LPSID Group,BOOLEAN GroupDefaulted); + +NTSTATUS +NTAPI +RtlGetGroupSecurityDescriptor( + PSECURITY_DESCRIPTOR SecurityDescriptor, + PSID *Group, + PBOOLEAN GroupDefaulted +); + +ULONG +NTAPI +RtlLengthRequiredSid( + UCHAR SubAuthorityCount + ); + +NTSTATUS +STDCALL +RtlInitializeSid(LPSID Sid,LPSID_IDENTIFIER_AUTHORITY SidIdentifierAuthority, DWORD nSubAuthorityCount); + +PULONG +NTAPI +RtlSubAuthoritySid( + PSID pSid, + ULONG nSubAuthority + ); + +BOOLEAN +NTAPI +RtlEqualSid( + PSID Sid1, + PSID Sid2 + ); + +NTSTATUS +NTAPI +RtlAbsoluteToSelfRelativeSD( + PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor, + PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor, + PULONG BufferLength + ); + +NTSTATUS +NTAPI +RtlValidSid( + PSID Sid + ); + +LPBYTE STDCALL RtlSubAuthorityCountSid(LPSID Sid); + +DWORD STDCALL RtlCopySid(DWORD Length,LPSID DestinationSid,LPSID SourceSid); + + + + diff --git a/reactos/lib/advapi32/sec/sec.c b/reactos/lib/advapi32/sec/sec.c new file mode 100644 index 00000000000..9431075b695 --- /dev/null +++ b/reactos/lib/advapi32/sec/sec.c @@ -0,0 +1,17 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/advapi32/sec/sec.c + * PURPOSE: Registry functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ +DWORD +STDCALL +GetSecurityDescriptorLength ( + PSECURITY_DESCRIPTOR pSecurityDescriptor + ) +{ + return RtlSetSecurityDescriptorLength(pSecurityDescriptor); +} \ No newline at end of file diff --git a/reactos/lib/advapi32/token/token.c b/reactos/lib/advapi32/token/token.c new file mode 100644 index 00000000000..f9b650508ea --- /dev/null +++ b/reactos/lib/advapi32/token/token.c @@ -0,0 +1,159 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/advapi32/token/token.c + * PURPOSE: Registry functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ +WINBOOL +STDCALL +AdjustTokenGroups ( + HANDLE TokenHandle, + WINBOOL ResetToDefault, + PTOKEN_GROUPS NewState, + DWORD BufferLength, + PTOKEN_GROUPS PreviousState, + PDWORD ReturnLength + ) +{ + NTSTATUS errCode; + errCode = NtAdjustGroupsToken(TokenHandle,ResetToDefault,NewState, + BufferLength, PreviousState, ReturnLength ); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + +WINBOOL +STDCALL +AdjustTokenPrivileges ( + HANDLE TokenHandle, + WINBOOL DisableAllPrivileges, + PTOKEN_PRIVILEGES NewState, + DWORD BufferLength, + PTOKEN_PRIVILEGES PreviousState, + PDWORD ReturnLength + ) +{ NTSTATUS errCode; + errCode = NtAdjustPrivilegesToken(TokenHandle,ResetToDefault,NewState, + BufferLength, PreviousState, ReturnLength ); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + + +WINBOOL +STDCALL +GetTokenInformation ( + HANDLE TokenHandle, + TOKEN_INFORMATION_CLASS TokenInformationClass, + LPVOID TokenInformation, + DWORD TokenInformationLength, + PDWORD ReturnLength + ) +{ + NTSTATUS errCode; + errCode = NtQueryInformationToken(TokenHandle,TokenInformationClass,TokenInformation, + TokenInformationLength, ReturnLength); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + +WINBOOL +STDCALL +SetTokenInformation ( + HANDLE TokenHandle, + TOKEN_INFORMATION_CLASS TokenInformationClass, + LPVOID TokenInformation, + DWORD TokenInformationLength + ) +{ + NTSTATUS errCode; + errCode = NtSetnformationToken(TokenHandle,TokenInformationClass,TokenInformation, + TokenInformationLength); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + +WINBOOL +STDCALL +AccessCheck ( + PSECURITY_DESCRIPTOR pSecurityDescriptor, + HANDLE ClientToken, + DWORD DesiredAccess, + PGENERIC_MAPPING GenericMapping, + PPRIVILEGE_SET PrivilegeSet, + LPDWORD PrivilegeSetLength, + LPDWORD GrantedAccess, + LPBOOL AccessStatus + ) +{ + NTSTATUS errCode; + errCode = NtAccessCheck( pSecurityDescriptor, + ClientToken, + DesiredAccess, + GenericMapping, + PrivilegeSet, + PrivilegeSetLength, + GrantedAccess, + AccessStatus); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + + + +WINBOOL +STDCALL +OpenProcessToken ( + HANDLE ProcessHandle, + DWORD DesiredAccess, + PHANDLE TokenHandle + ) +{ + NTSTATUS errCode; + errCode = NtOpenProcessToken(ProcessHandle,DesiredAccess,TokenHandle); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + + + +WINBOOL +STDCALL +OpenThreadToken ( + HANDLE ThreadHandle, + DWORD DesiredAccess, + WINBOOL OpenAsSelf, + PHANDLE TokenHandle + ) +{ + NTSTATUS errCode; + errCode = NtOpenThreadToken(ThreadHandle,DesiredAccess,OpenAsSelf,TokenHandle); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + + diff --git a/reactos/lib/kernel32/except/except.c b/reactos/lib/kernel32/except/except.c new file mode 100644 index 00000000000..d3f18fed984 --- /dev/null +++ b/reactos/lib/kernel32/except/except.c @@ -0,0 +1,626 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/misc/except.c + * PURPOSE: Exception functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + modified from WINE [ Onno Hovers, (onno@stack.urc.tue.nl) ] + * UPDATE HISTORY: + * Created 01/11/98 + */ + +#include +#include + + +typedef LONG (STDCALL *LPTOP_LEVEL_EXCEPTION_FILTER)( + struct _EXCEPTION_POINTERS *ExceptionInfo + ); + +UINT GlobalErrMode; +LPTOP_LEVEL_EXCEPTION_FILTER GlobalTopLevelExceptionFilter; + +UINT GetErrorMode(void); + +//FIXME Please remove comments in funcs.h +LPTOP_LEVEL_EXCEPTION_FILTER +STDCALL +SetUnhandledExceptionFilter( + LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter + ); + + +// these are in various flavors + + +typedef enum _EXCEPTION_DISPOSITION +{ + ExceptionContinueExecution, + ExceptionContinueSearch, + ExceptionNestedException, + ExceptionCollidedUnwind +} EXCEPTION_DISPOSITION; + + +#define DISPOSITION_DISMISS 0 +#define DISPOSITION_CONTINUE_SEARCH 1 +#define DISPOSITION_NESTED_EXCEPTION 2 +#define DISPOSITION_COLLIDED_UNWIND 3 + +// following values can be returned by exception filters +// in a try{} except() block. + +//#define EXCEPTION_EXECUTE_HANDLER 1 +//#define EXCEPTION_CONTINUE_SEARCH 0 +//#define EXCEPTION_CONTINUE_EXECUTION -1 + +// OS/2 filter return codes +#define FILTER_ACCEPT 1 +#define FILTER_DISMISS -1 +#define FILTER_CONTINUE_SEARCH 0 + + +#define TRYLEVEL_NONE -1 +#define TRYLEVEL_INVALID -2 + +//callback interface codes (mimimal required set) + +#define CB_GET_MAX_CODE 0 +#define CB_DO_LOCAL_UNWIND 1 +#define CB_GET_FRAME_EBP 2 +#define CB_GET_SCOPE_INDEX 3 +#define CB_GET_SCOPE_DATA 4 +#define MAX_CALLBACK_CODE 4 + + +#define EH_NONCONTINUABLE 1 +#define EH_UNWINDING 2 +#define EH_EXIT_UNWIND 4 +#define EH_STACK_INVALID 8 +#define EH_NESTED_CALL 16 + +//#define FACILITY_RPC_RUNTIME 2 +//#define FACILITY_RPC_STUBS 3 +//#define FACILITY_IO_ERROR_CODE 4 + +//#define SEVERITY_CODE_SUCCESS 0 +//#define SEVERITY_CODE_INFORMATIONAL 1 +//#define SEVERITY_CODE_WARNING 2 +//#define SEVERITY_CODE_ERROR 3 + + +#define XCPT_FATAL_EXCEPTION (0xC0000000) +#define XCPT_SEVERITY_CODE (0xC0000000) +#define XCPT_CUSTOMER_CODE (0x20000000) +#define XCPT_FACILITY_CODE (0x1FFF0000) +#define XCPT_EXCEPTION_CODE (0x0000FFFF) + + +// this is the definition of NTSTATUS + +// definition of NTSTATUS + +typedef struct _NTSTATUSDEF +{ + USHORT Code; + USHORT Facility :12; + UCHAR Reserved : 1; + UCHAR CstCodeFlag : 1; + UCHAR Severity : 2; +} NTSTATUSDEF; + +// Violation flags in ExceptionInfo + +#define XCPT_UNKNOWN_ACCESS 0x00000000 +#define XCPT_READ_ACCESS 0x00000001 +#define XCPT_WRITE_ACCESS 0x00000002 +#define XCPT_EXECUTE_ACCESS 0x00000004 +#define XCPT_SPACE_ACCESS 0x00000008 // address space access violation +#define XCPT_LIMIT_ACCESS 0x00000010 // out of bounds +#define XCPT_DATA_UNKNOWN 0xFFFFFFFF + + +// some status values with corresponding ExceptionInfo values + +//#define STATUS_GUARD_PAGE_VIOLATION 0x80000001 + // ExceptionInfo[ 0 ] - Access Code: XCPT_READ_ACCESS | XCPT_WRITE_ACCESS + // ExceptionInfo[ 1 ] - FaultAddr + + +//#define STATUS_DATATYPE_MISALIGNMENT 0x80000002 + // OS/2 XCPT is at 0xC000009E + // ExceptionInfo[ 0 ] - Access Code: XCPT_READ_ACCESS | XCPT_WRITE_ACCESS + // ExceptionInfo[ 1 ] - Alignment + // ExceptionInfo[ 2 ] - FaultAddr + + +//#define STATUS_ACCESS_VIOLATION 0xC0000005 + // ExceptionInfo[ 0 ] - Access Code: XCPT_READ_ACCESS | XCPT_WRITE_ACCESS + // ExceptionInfo[ 1 ] - FaultAddr + + +//#define STATUS_IN_PAGE_ERROR 0xC0000006 + // ExceptionInfo[ 0 ] - FaultAddr + +//#define STATUS_NONCONTINUABLE_EXCEPTION 0xC0000025 +//#define STATUS_INVALID_DISPOSITION 0xC0000026 + + +// Exceptions generated by the exception handler + +#define STATUS_UNWIND 0xC0000027 +#define STATUS_BAD_STACK 0xC0000028 +#define STATUS_INVALID_UNWIND_TARGET 0xC0000029 + + +typedef struct _EXCEPTION_REGISTRATION; + +typedef EXCEPTION_DISPOSITION +(STDCALL *ExceptionHandlerType)( + struct _EXCEPTION_RECORD *ExceptionRecord, + struct _EXCEPTION_REGISTRATION *EstablisherFrame, + struct _CONTEXT *Context, + struct _EXCEPTION_RECORD *DispatcherContext + ); + + + + +typedef struct _SCOPE_TABLE { + DWORD prevTryLevel; + LPTOP_LEVEL_EXCEPTION_FILTER lpfnFilter; + ExceptionHandlerType lpfnHandler; +} SCOPE_TABLE , *PSCOPE_TABLE; + +typedef struct _EXCEPTION_REGISTRATION { + struct _EXCEPTION_REGISTRATION *Prev; + ExceptionHandlerType Handler; + PSCOPE_TABLE ScopeTable; + unsigned int TryLevel; + unsigned int _ebp; + PEXCEPTION_POINTERS *Pointers; +} EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION; + +#define END_OF_CHAIN ((PEXCEPTION_REGISTRATION) -1) + + + + + + + + + + + +EXCEPTION_DISPOSITION +CDECL +ExceptionHandler( + struct _EXCEPTION_RECORD *ExceptionRecord, + struct _EXCEPTION_REGISTRATION *RegistrationFrame, + CONTEXT *Context, + struct _EXCEPTION_RECORD *DispatcherContext + ); + +void KiUserExceptionDispatcher( + struct _EXCEPTION_RECORD *ExceptionRecord, + CONTEXT *Context); + +NTSTATUS RtlDispatchException( + struct _EXCEPTION_RECORD *ExceptionRecord, + CONTEXT *Context); + +struct _EXCEPTION_REGISTRATION *RtlpGetRegistrationHead(VOID); + +void RtlpCaptureContext(CONTEXT *Context); +void RtlpGetStackLimits(void *StackBase, void *StackLimit); +void RtlpUnlinkHandler(struct _EXCEPTION_REGISTRATION *__head); +void RtlpLinkHandler(struct _EXCEPTION_REGISTRATION *__head); +void RtlUnwind(struct _EXCEPTION_REGISTRATION *RegistratonFrame, + VOID *ReturnAddress, // Unused + struct _EXCEPTION_RECORD *ExceptionRecord, + DWORD _eax); + +void RtlRaiseException(struct _EXCEPTION_RECORD *ExceptionRecord); + + + + + +UINT GetErrorMode(void) +{ + return GlobalErrMode; +} + +UINT +STDCALL +SetErrorMode( UINT uMode ) +{ + UINT OldErrMode = GetErrorMode(); + GlobalErrMode = uMode; + return OldErrMode; +} + +LPTOP_LEVEL_EXCEPTION_FILTER +STDCALL +SetUnhandledExceptionFilter( + LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter + ) +{ + LPTOP_LEVEL_EXCEPTION_FILTER OldTopLevelExceptionFilter = + GlobalTopLevelExceptionFilter; + lpTopLevelExceptionFilter = GlobalTopLevelExceptionFilter; + return OldTopLevelExceptionFilter; +} + + + + + + + + +LONG +STDCALL +ExceptionFilter ( + PEXCEPTION_POINTERS ExceptionInfo + ) +{ + return TRUE; +} + +EXCEPTION_DISPOSITION +CDECL +ExceptionHandler( + struct _EXCEPTION_RECORD *ExceptionRecord, + struct _EXCEPTION_REGISTRATION *RegistrationFrame, + CONTEXT *Context, + struct _EXCEPTION_RECORD *DispatcherContext + ) +{ + int FilterRet; + unsigned int TryLevel; + EXCEPTION_POINTERS ExceptionPointers; + SCOPE_TABLE *ScopeTable; + unsigned int _ebp; + + +// __asm { cld }; + + if ( ExceptionRecord->ExceptionFlags != EH_UNWINDING && + ExceptionRecord->ExceptionFlags != EH_EXIT_UNWIND ) + { + ExceptionPointers.ExceptionRecord= ExceptionRecord; + ExceptionPointers.ContextRecord = Context; + + // + + TryLevel = RegistrationFrame->TryLevel; + + ScopeTable = RegistrationFrame->ScopeTable; + + if ( RegistrationFrame->TryLevel != TRYLEVEL_NONE ) + { + if ( RegistrationFrame->ScopeTable[TryLevel].lpfnFilter != NULL) + { + _ebp = RegistrationFrame->_ebp; + //__asm { push ebp + // mov ebp, _ebp + //} + FilterRet = ScopeTable->lpfnFilter(NULL); + //__asm { pop ebp } + + if ( FilterRet < 0 ) + return ExceptionContinueExecution; + + if ( FilterRet == EXCEPTION_EXECUTE_HANDLER ) + { + ScopeTable = RegistrationFrame->ScopeTable; + RtlUnwind(RegistrationFrame,NULL,ExceptionRecord,0); + //__asm { mov ebp, _ebp } + // local unwind + // nlg + + RegistrationFrame->TryLevel = ScopeTable->prevTryLevel; + RegistrationFrame->ScopeTable[TryLevel].lpfnHandler(ExceptionRecord,RegistrationFrame,Context, DispatcherContext); + NtContinue(Context,PASSIVE_LEVEL); + //return; + + } + else { + ScopeTable = RegistrationFrame->ScopeTable; + TryLevel = ScopeTable->prevTryLevel; + // search for handler + return DISPOSITION_CONTINUE_SEARCH; + } + + } + } else { // TRYLEVEL_NONE + return DISPOSITION_CONTINUE_SEARCH; + } + } else { // EXCEPTION_UNWINDING or EXCEPTION_EXIT_UNWIND + // + return DISPOSITION_CONTINUE_SEARCH; + } + return DISPOSITION_CONTINUE_SEARCH; +} + + + + + +LONG +STDCALL +UnhandledExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo) +{ + char message[80]; + DWORD dbgRet; + HANDLE DebugPort; + NTSTATUS errCode; + + DWORD DebuggerPresent; + + + if(ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION) { + // might check read only resource + // Is there a debugger running ? + errCode = NtQueryInformationProcess(NtCurrentProcess(),ProcessDebugPort,&DebugPort,sizeof(HANDLE),NULL); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return EXCEPTION_EXECUTE_HANDLER; + } + if ( DebugPort ) { + //return EXCEPTION_CONTINUE_SEARCH; + } + if(GlobalTopLevelExceptionFilter != NULL) { + dbgRet = GlobalTopLevelExceptionFilter(ExceptionInfo); + if(dbgRet == EXCEPTION_EXECUTE_HANDLER) + return EXCEPTION_EXECUTE_HANDLER; + else if(dbgRet == EXCEPTION_CONTINUE_EXECUTION) + return EXCEPTION_CONTINUE_EXECUTION; + } + + } + + //if ( GetErrorMode() & SEM_NOGPFAULTERRORBOX == SEM_NOGPFAULTERRORBOX ) { + // produce a stack trace or pop a message + //sprintf( message, "Unhandled exception 0x%08lx at address 0x%08lx.", + // ExceptionInfo->ExceptionRecord->ExceptionCode, + // (DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress ); + //MessageBoxA( 0, message, "Error", MB_OK | MB_ICONHAND ); + + //} + // Returning EXCEPTION_EXECUTE_HANDLER means that the code in + // the __execept block will be executed. Normally this will end up in a + // Terminate process. + + return EXCEPTION_EXECUTE_HANDLER; + +} + + +void KiUserExceptionDispatcher(PEXCEPTION_RECORD ExceptionRecord, PCONTEXT Context) +{ + NTSTATUS errCode; + + if ( RtlDispatchException(ExceptionRecord,Context) ) + errCode = NtContinue(Context,PASSIVE_LEVEL); + else + errCode = NtRaiseException(ExceptionRecord,Context,(BOOLEAN)FALSE); + + +} + + + +NTSTATUS RtlDispatchException(PEXCEPTION_RECORD ExceptionRecord, PCONTEXT Context) +{ + NTSTATUS errCode; + ULONG StackBase, StackLimit; + PEXCEPTION_REGISTRATION RegistrationFrame; + EXCEPTION_RECORD DispatcherContext; + EXCEPTION_RECORD FatalExceptionRecord; + + //RtlpGetStackLimits(&StackBase,&StackTop); + RegistrationFrame = RtlpGetRegistrationHead(); + + while( RegistrationFrame != END_OF_CHAIN ) { + + //FIXME Check the stack + RtlpGetStackLimits(&StackBase, &StackLimit); + + errCode = RegistrationFrame->Handler( + ExceptionRecord, + RegistrationFrame, + Context, + &DispatcherContext); + + //errCode = RtlpExecuteHandlerForException(ExceptionRecord, RegistrationFrame, + // Context, &DispatcherContext); + + if ( RegistrationFrame == NULL ) + ExceptionRecord->ExceptionFlags &= ~EH_NESTED_CALL; + + switch( errCode ) { + case DISPOSITION_DISMISS: + if ( ExceptionRecord->ExceptionFlags & EH_NONCONTINUABLE ) { + FatalExceptionRecord.ExceptionRecord = ExceptionRecord; + FatalExceptionRecord.ExceptionCode = STATUS_NONCONTINUABLE_EXCEPTION; + FatalExceptionRecord.ExceptionFlags = EH_NONCONTINUABLE; + FatalExceptionRecord.NumberParameters = 0; + RtlRaiseException(&FatalExceptionRecord); + } + else + return DISPOSITION_CONTINUE_SEARCH; + break; + case DISPOSITION_CONTINUE_SEARCH: + break; + case DISPOSITION_NESTED_EXCEPTION: + ExceptionRecord->ExceptionFlags |= EH_EXIT_UNWIND; + break; + + default: + FatalExceptionRecord.ExceptionRecord = ExceptionRecord; + FatalExceptionRecord.ExceptionCode = STATUS_NONCONTINUABLE_EXCEPTION; + FatalExceptionRecord.ExceptionFlags = EH_NONCONTINUABLE; + FatalExceptionRecord.NumberParameters = 0; + RtlRaiseException(&FatalExceptionRecord); + break; + } + + RegistrationFrame = RegistrationFrame->Prev; + } + return DISPOSITION_DISMISS; + + +} + +PEXCEPTION_REGISTRATION RtlpGetRegistrationHead(VOID) +{ + PEXCEPTION_REGISTRATION __head; +/* + __asm { + mov eax, fs:[0] + mov __head,eax + } +*/ + return __head; +} + + + +void RtlUnwind(PEXCEPTION_REGISTRATION RegistrationFrame, + PVOID ReturnAddress, // Unused + PEXCEPTION_RECORD ExceptionRecord, + DWORD _eax) +{ + NTSTATUS errCode, retval; + DWORD StackBase; + DWORD StackTop; + CONTEXT Context; + PEXCEPTION_REGISTRATION TraversingFrame; + EXCEPTION_RECORD TraversingRecord; + EXCEPTION_RECORD DispatcherContext; + + + /* build an exception record, if we do not have one */ + if(ExceptionRecord != NULL) + { + ExceptionRecord->ExceptionCode = (DWORD)STATUS_UNWIND; //STATUS_INVALID_DISPOSITION; + ExceptionRecord->ExceptionFlags = 0; + ExceptionRecord->ExceptionRecord = NULL; + //ExceptionRecord->ExceptionAddress = (LPVOID)pcontext->Eip; + ExceptionRecord->NumberParameters = 0; + ExceptionRecord->ExceptionInformation[0] =0; + + + if ( RegistrationFrame != NULL ) + ExceptionRecord->ExceptionFlags |= EH_UNWINDING; + else + ExceptionRecord->ExceptionFlags |= + (EH_UNWINDING|EH_EXIT_UNWIND); + } + Context.ContextFlags |= + (CONTEXT_i386|CONTEXT_FULL); + RtlpCaptureContext(&Context); + Context.Esp += 0x10; + Context.Eax = _eax; + + TraversingFrame = RtlpGetRegistrationHead(); + + while( ( TraversingFrame != NULL ) && ( TraversingFrame != END_OF_CHAIN ) && ( TraversingFrame != RegistrationFrame ) ) + { + + errCode = TraversingFrame->Handler( + ExceptionRecord, + TraversingFrame, + &Context, + &DispatcherContext); + if ( (retval == ExceptionCollidedUnwind) && (TraversingFrame != (LPVOID)&DispatcherContext) ) + TraversingFrame = (LPVOID)&DispatcherContext; + else if ((TraversingFrame != RegistrationFrame) && (TraversingFrame != TraversingFrame->Prev) ) { + RtlpUnlinkHandler(TraversingFrame); + TraversingFrame = TraversingFrame->Prev; + } + else + break; + } +} + + +void RtlpUnlinkHandler(PEXCEPTION_REGISTRATION __head) +{ + PEXCEPTION_REGISTRATION theHead; + PEXCEPTION_REGISTRATION theLast; + theHead = RtlpGetRegistrationHead(); + +/* + if ( __head == NULL ) + return; + + if ( theHead == __head ) { + theHead = theHead->Prev; + __asm { + mov eax, theHead + mov fs:[0], eax + } + + return; + } + else { + do { + theLast = theHead; + theHead = theHead->Prev; + if ( theHead == __head ) { + theLast->Prev = theHead->Prev; + } + } while ( theHead != NULL && theHead != END_OF_CHAIN ); + } + +*/ + return; +} + +void RtlpLinkHandler(PEXCEPTION_REGISTRATION __head) +{ + PEXCEPTION_REGISTRATION theHead; + if (__head == NULL) + return; + + theHead = RtlpGetRegistrationHead(); + __head->Prev = theHead; +/* + __asm { + mov eax, __head + mov fs:[0], eax + } +*/ +} + + +void RtlpCaptureContext(PCONTEXT Context) +{ + return; +} + +void RtlpGetStackLimits(void *StackBase, void *StackLimit) +{ +/* + __asm{ mov eax, fs:[4] + mov StackBase, eax } + __asm{ mov eax, fs:[5] + mov StackLimit, eax } +*/ + return; + +} + +void RtlRaiseException(struct _EXCEPTION_RECORD *ExceptionRecord) +{ + return; +} + + + + + diff --git a/reactos/lib/kernel32/file/curdir.c b/reactos/lib/kernel32/file/curdir.c index 6f5442374a1..2e0c613ee9b 100644 --- a/reactos/lib/kernel32/file/curdir.c +++ b/reactos/lib/kernel32/file/curdir.c @@ -15,19 +15,209 @@ /* GLOBALS *******************************************************************/ -static unsigned char CurrentDirectory[255]; + +static unsigned short CurrentDirectoryW[MAX_PATH]; + +static unsigned short SystemDirectoryW[MAX_PATH]; + +static unsigned short WindowsDirectoryW[MAX_PATH]; /* FUNCTIONS *****************************************************************/ - -DWORD GetCurrentDirectoryA(DWORD nBufferLength, LPSTR lpBuffer) + +DWORD +STDCALL +GetCurrentDirectoryA(DWORD nBufferLength, LPSTR lpBuffer) { - nBufferLength = min(nBufferLength, lstrlenA(CurrentDirectory)); - lstrncpyA(lpBuffer,CurrentDirectory,nBufferLength); - return(nBufferLength); + UINT uSize,i; + if ( lpBuffer == NULL ) + return 0; + uSize = lstrlenW(CurrentDirectoryW); + if ( nBufferLength > uSize ) { + i = 0; + while ((CurrentDirectoryW[i])!=0 && i < MAX_PATH) + { + lpBuffer[i] = (unsigned char)CurrentDirectoryW[i]; + i++; + } + lpBuffer[i] = 0; + } + return uSize; } -BOOL SetCurrentDirectoryA(LPCSTR lpPathName) +DWORD +STDCALL +GetCurrentDirectoryW( + DWORD nBufferLength, + LPWSTR lpBuffer + ) { - lstrcpyA(CurrentDirectory,lpPathName); + UINT uSize; + if ( lpBuffer == NULL ) + return 0; + uSize = lstrlenW(CurrentDirectoryW); + if ( nBufferLength > uSize ) + lstrcpynW(lpBuffer,CurrentDirectoryW,uSize); + + return uSize; +} + +BOOL +STDCALL +SetCurrentDirectoryA(LPCSTR lpPathName) +{ + UINT i; + + if ( lpPathName == NULL ); + return FALSE; + if ( lstrlenA(lpPathName) > MAX_PATH ); + return FALSE; + i = 0; + while ((lpPathName[i])!=0 && i < MAX_PATH) + { + CurrentDirectoryW[i] = (unsigned short)lpPathName[i]; + i++; + } + CurrentDirectoryW[i] = 0; + return(TRUE); } + + +WINBOOL +STDCALL +SetCurrentDirectoryW( + LPCWSTR lpPathName + ) +{ + if ( lpPathName == NULL ); + return FALSE; + if ( lstrlenW(lpPathName) > MAX_PATH ); + return FALSE; + lstrcpyW(CurrentDirectoryW,lpPathName); + return(TRUE); +} + +DWORD +STDCALL +GetTempPathA( + DWORD nBufferLength, + LPSTR lpBuffer + ) +{ + WCHAR BufferW[MAX_PATH]; + DWORD retCode; + UINT i; + retCode = GetTempPathW(nBufferLength,BufferW); + i = 0; + while ((BufferW[i])!=0 && i < MAX_PATH) + { + lpBuffer[i] = (unsigned char)BufferW[i]; + i++; + } + lpBuffer[i] = 0; + return retCode; + +} + +DWORD +STDCALL +GetTempPathW( + DWORD nBufferLength, + LPWSTR lpBuffer + ) +{ + + WCHAR EnvironmentBufferW[MAX_PATH]; + UINT i; + + EnvironmentBufferW[0] = 0; + i = GetEnvironmentVariableW(L"TMP",EnvironmentBufferW,MAX_PATH); + if ( i==0 ) + i = GetEnvironmentVariableW(L"TEMP",EnvironmentBufferW,MAX_PATH); + if ( i==0 ) + i = GetCurrentDirectoryW(MAX_PATH,EnvironmentBufferW); + + return i; +} + +UINT +STDCALL +GetSystemDirectoryA( + LPSTR lpBuffer, + UINT uSize + ) +{ + UINT uPathSize,i; + if ( lpBuffer == NULL ) + return 0; + uPathSize = lstrlenW(SystemDirectoryW); + if ( uSize > uPathSize ) { + i = 0; + while ((SystemDirectoryW[i])!=0 && i < uSize) + { + lpBuffer[i] = (unsigned char)SystemDirectoryW[i]; + i++; + } + lpBuffer[i] = 0; + } + + return uPathSize; +} + +UINT +STDCALL +GetWindowsDirectoryA( + LPSTR lpBuffer, + UINT uSize + ) +{ + UINT uPathSize,i; + if ( lpBuffer == NULL ) + return 0; + uPathSize = lstrlenW(WindowsDirectoryW); + if ( uSize > uPathSize ) { + i = 0; + while ((WindowsDirectoryW[i])!=0 && i < uSize) + { + lpBuffer[i] = (unsigned char)WindowsDirectoryW[i]; + i++; + } + lpBuffer[i] = 0; + } + return uPathSize; +} + +UINT +STDCALL +GetSystemDirectoryW( + LPWSTR lpBuffer, + UINT uSize + ) +{ + UINT uPathSize; + if ( lpBuffer == NULL ) + return 0; + uPathSize = lstrlenW(SystemDirectoryW); + if ( uSize > uPathSize ) + lstrcpynW(lpBuffer,SystemDirectoryW,uPathSize); + + + return uPathSize; +} + +UINT +STDCALL +GetWindowsDirectoryW( + LPWSTR lpBuffer, + UINT uSize + ) +{ + UINT uPathSize; + if ( lpBuffer == NULL ) + return 0; + uPathSize = lstrlenW(WindowsDirectoryW); + if ( uSize > uPathSize ); + lstrcpynW(lpBuffer,WindowsDirectoryW,uPathSize); + + return uPathSize; +} \ No newline at end of file diff --git a/reactos/lib/kernel32/file/deviceio.c b/reactos/lib/kernel32/file/deviceio.c new file mode 100644 index 00000000000..277e1854c26 --- /dev/null +++ b/reactos/lib/kernel32/file/deviceio.c @@ -0,0 +1,127 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/file/deviceio.c + * PURPOSE: Device I/O and Overlapped Result functions + * PROGRAMMER: Ariadne (ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ + +#include +#include + +WINBOOL +STDCALL +DeviceIoControl( + HANDLE hDevice, + DWORD dwIoControlCode, + LPVOID lpInBuffer, + DWORD nInBufferSize, + LPVOID lpOutBuffer, + DWORD nOutBufferSize, + LPDWORD lpBytesReturned, + LPOVERLAPPED lpOverlapped + ) +{ + + NTSTATUS errCode = 0; + HANDLE hEvent = NULL; + PIO_STATUS_BLOCK IoStatusBlock; + IO_STATUS_BLOCK IIosb; + + WINBOOL bFsIoControlCode = FALSE; + + if ( lpBytesReturned == NULL ) { + SetLastError(RtlNtStatusToDosError(STATUS_INVALID_PARAMETER)); + return FALSE;; + } + + if( ( ( dwIoControlCode >> 16 ) & FILE_DEVICE_FILE_SYSTEM ) == FILE_DEVICE_FILE_SYSTEM ) + bFsIoControlCode = TRUE; + else + bFsIoControlCode = FALSE; + + if(lpOverlapped != NULL) { + hEvent = lpOverlapped->hEvent; + lpOverlapped->Internal = STATUS_PENDING; + IoStatusBlock = (PIO_STATUS_BLOCK)lpOverlapped; + } + else { + IoStatusBlock = &IIosb; + } + + + if(bFsIoControlCode == TRUE) { + errCode = NtFsControlFile(hDevice,hEvent,NULL,NULL,IoStatusBlock,dwIoControlCode,lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize ); + } else { + errCode = NtDeviceIoControlFile(hDevice,hEvent,NULL,NULL,IoStatusBlock,dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize); + } + + if(errCode == STATUS_PENDING ) { + + if(NtWaitForSingleObject(hDevice,FALSE,NULL) < 0) { + *lpBytesReturned = IoStatusBlock->Information; + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE;; + } + + } else if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + *lpBytesReturned = lpOverlapped->InternalHigh; + return TRUE; + + + +} + + + +WINBOOL +STDCALL +GetOverlappedResult( + HANDLE hFile, + LPOVERLAPPED lpOverlapped, + LPDWORD lpNumberOfBytesTransferred, + WINBOOL bWait + ) +{ + DWORD WaitStatus; + + if ( lpOverlapped == NULL ) { + SetLastError(RtlNtStatusToDosError(STATUS_INVALID_PARAMETER)); + return FALSE; + } + if ( lpOverlapped ->Internal == STATUS_PENDING) { + if ( lpNumberOfBytesTransferred == 0 ) { + SetLastError(RtlNtStatusToDosError(STATUS_PENDING)); + return FALSE; + } + else if ( bWait == TRUE ) { + if ( lpOverlapped->hEvent != NULL ) { + WaitStatus = WaitForSingleObject(lpOverlapped->hEvent,-1); + if ( WaitStatus == STATUS_TIMEOUT ) { + SetLastError(ERROR_IO_INCOMPLETE); + return FALSE; + } + else + return GetOverlappedResult(hFile,lpOverlapped,lpNumberOfBytesTransferred,FALSE); + + } + } + } + *lpNumberOfBytesTransferred = lpOverlapped->InternalHigh; + if ( lpOverlapped->Internal < 0 ) { + SetLastError(RtlNtStatusToDosError(lpOverlapped->Internal)); + return FALSE; + } + return TRUE; + + + +} + + + diff --git a/reactos/lib/kernel32/file/dir.c b/reactos/lib/kernel32/file/dir.c new file mode 100644 index 00000000000..2c5ed3cbeeb --- /dev/null +++ b/reactos/lib/kernel32/file/dir.c @@ -0,0 +1,396 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/file/dir.c + * PURPOSE: Directory functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ + +#include +#include +#include +#include +#include + + +WINBOOL +STDCALL +CreateDirectoryA( + LPCSTR lpPathName, + LPSECURITY_ATTRIBUTES lpSecurityAttributes + ) +{ + return CreateDirectoryExA(NULL,lpPathName,lpSecurityAttributes); +} + +WINBOOL +STDCALL +CreateDirectoryExA( + LPCSTR lpTemplateDirectory, + LPCSTR lpNewDirectory, + LPSECURITY_ATTRIBUTES lpSecurityAttributes + ) +{ + WCHAR TemplateDirectoryW[MAX_PATH]; + WCHAR NewDirectoryW[MAX_PATH]; + ULONG i; + i = 0; + while ((*lpTemplateDirectory)!=0 && i < MAX_PATH) + { + TemplateDirectoryW[i] = *lpTemplateDirectory; + lpTemplateDirectory++; + i++; + } + TemplateDirectoryW[i] = 0; + + i = 0; + while ((*lpNewDirectory)!=0 && i < MAX_PATH) + { + NewDirectoryW[i] = *lpNewDirectory; + lpNewDirectory++; + i++; + } + NewDirectoryW[i] = 0; + return CreateDirectoryExW(TemplateDirectoryW,NewDirectoryW,lpSecurityAttributes); +} + + +WINBOOL +STDCALL +CreateDirectoryW( + LPCWSTR lpPathName, + LPSECURITY_ATTRIBUTES lpSecurityAttributes + ) +{ + + return CreateDirectoryExW(NULL,lpPathName,lpSecurityAttributes); +} + +WINBOOL +STDCALL +CreateDirectoryExW( + LPCWSTR lpTemplateDirectory, + LPCWSTR lpNewDirectory, + LPSECURITY_ATTRIBUTES lpSecurityAttributes + ) +{ + NTSTATUS errCode; + HANDLE DirectoryHandle; + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING DirectoryNameString; + + if ( lpTemplateDirectory != NULL ) { + // get object attributes from template directory + } + + + DirectoryNameString.Length = lstrlenW(lpNewDirectory)*sizeof(WCHAR); + DirectoryNameString.Buffer = (WCHAR *)lpNewDirectory; + DirectoryNameString.MaximumLength = DirectoryNameString.Length; + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + ObjectAttributes.ObjectName = &DirectoryNameString; + ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = NULL; + + + errCode = NtCreateDirectoryObject( + &DirectoryHandle, + GENERIC_ALL, + &ObjectAttributes + ); + if (!NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + + + +WINBOOL +STDCALL +RemoveDirectoryA( + LPCSTR lpPathName + ) +{ + WCHAR PathNameW[MAX_PATH]; + ULONG i; + i = 0; + while ((*lpPathName)!=0 && i < MAX_PATH) + { + PathNameW[i] = *lpPathName; + lpPathName++; + i++; + } + PathNameW[i] = 0; + return RemoveDirectoryW(PathNameW); +} + + +WINBOOL +STDCALL +RemoveDirectoryW( + LPCWSTR lpPathName + ) +{ + NTSTATUS errCode; + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING PathNameString; + + PathNameString.Length = lstrlenW(lpPathName)*sizeof(WCHAR); + PathNameString.Buffer = (WCHAR *)lpPathName; + PathNameString.MaximumLength = PathNameString.Length; + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + ObjectAttributes.ObjectName = &PathNameString; + ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = NULL; + + errCode = NtDeleteFile( + &ObjectAttributes + ); + if (!NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + +DWORD +STDCALL +GetFullPathNameA( + LPCSTR lpFileName, + DWORD nBufferLength, + LPSTR lpBuffer, + LPSTR *lpFilePart + ) +{ + +} + + + +DWORD +STDCALL +GetFullPathNameW( + LPCWSTR lpFileName, + DWORD nBufferLength, + LPWSTR lpBuffer, + LPWSTR *lpFilePart + ) +{ +} + +DWORD +STDCALL +GetShortPathNameA( + LPCSTR lpszLongPath, + LPSTR lpszShortPath, + DWORD cchBuffer + ) +{ + //1 remove unicode chars and spaces + //2 remove preceding and trailing periods. + //3 remove embedded periods except the last one + + //4 Split the string in two parts before and after the period + // truncate the part before the period to 6 chars and add ~1 + // truncate the part after the period to 3 chars + //3 Put the new name in uppercase + + //4 Increment the ~1 string if the resulting name allready exists + +} + +DWORD +STDCALL +GetShortPathNameW( + LPCWSTR lpszLongPath, + LPWSTR lpszShortPath, + DWORD cchBuffer + ) +{ + +} + +DWORD +STDCALL +SearchPathA( + LPCSTR lpPath, + LPCSTR lpFileName, + LPCSTR lpExtension, + DWORD nBufferLength, + LPSTR lpBuffer, + LPSTR *lpFilePart + ) +{ +} + +DWORD +STDCALL +SearchPathW( + LPCWSTR lpPath, + LPCWSTR lpFileName, + LPCWSTR lpExtension, + DWORD nBufferLength, + LPWSTR lpBuffer, + LPWSTR *lpFilePart + ) +{ + + //1. The directory from which the application loaded. + //2. The current directory. + //3. Windows NT: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is SYSTEM32. + //4. Windows NT only: The 16-bit Windows system directory. There is no Win32 function that obtains the path of this directory, but it is searched. The name of this directory is SYSTEM. + //5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. + //6. The directories that are listed in the PATH environment variable. + NTSTATUS errCode; + DWORD retCode = 0; + HANDLE FileHandle = NULL; + + ULONG i,j; + + WCHAR BufferW[MAX_PATH]; + WCHAR FileAndExtensionW[MAX_PATH]; + WCHAR *EnvironmentBufferW = NULL; + + UNICODE_STRING PathString; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + + + + + + if ( lpPath == NULL ) { + + // check the directory from which the application loaded + + if ( GetCurrentDirectoryW( MAX_PATH, BufferW ) > 0 ) { + retCode = SearchPathW(BufferW,lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart ); + if ( retCode != 0 ) + return retCode; + } + if ( GetSystemDirectoryW( BufferW, MAX_PATH ) > 0 ) { + retCode = SearchPathW(BufferW,lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart ); + if ( retCode != 0 ) + return retCode; + } + + if ( GetWindowsDirectoryW( BufferW, MAX_PATH ) > 0 ) { + retCode = SearchPathW(BufferW,lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart ); + if ( retCode != 0 ) + return retCode; + } + + j = GetEnvironmentVariableW(L"Path",EnvironmentBufferW,0); + EnvironmentBufferW = (WCHAR *) HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,(j+1)*sizeof(WCHAR)); + + j = GetEnvironmentVariableW(L"Path",EnvironmentBufferW,j+1); + + for(i=0;i +#include + + +WINBOOL +STDCALL +DefineDosDeviceA( + DWORD dwFlags, + LPCSTR lpDeviceName, + LPCSTR lpTargetPath + ) +{ + ULONG i; + + WCHAR DeviceNameW[MAX_PATH]; + WCHAR TargetPathW[MAX_PATH]; + + + + i = 0; + while ((*lpDeviceName)!=0 && i < MAX_PATH) + { + DeviceNameW[i] = *lpDeviceName; + lpDeviceName++; + i++; + } + DeviceNameW[i] = 0; + + i = 0; + while ((*lpTargetPath)!=0 && i < MAX_PATH) + { + TargetPathW[i] = *lpTargetPath; + lpTargetPath++; + i++; + } + TargetPathW[i] = 0; + return DefineDosDeviceW(dwFlags,DeviceNameW,TargetPathW); + +} + + + +DWORD +STDCALL +QueryDosDeviceA( + LPCSTR lpDeviceName, + LPSTR lpTargetPath, + DWORD ucchMax + ) +{ + ULONG i; + + WCHAR DeviceNameW[MAX_PATH]; + WCHAR TargetPathW[MAX_PATH]; + + + + i = 0; + while ((*lpDeviceName)!=0 && i < MAX_PATH) + { + DeviceNameW[i] = *lpDeviceName; + lpDeviceName++; + i++; + } + DeviceNameW[i] = 0; + + i = 0; + while ((*lpTargetPath)!=0 && i < MAX_PATH) + { + TargetPathW[i] = *lpTargetPath; + lpTargetPath++; + i++; + } + TargetPathW[i] = 0; + return QueryDosDeviceW(DeviceNameW,TargetPathW,ucchMax); +} + + +WINBOOL +STDCALL +DefineDosDeviceW( + DWORD dwFlags, + LPCWSTR lpDeviceName, + LPCWSTR lpTargetPath + ) +{ + return FALSE; +} + +DWORD +STDCALL +QueryDosDeviceW( + LPCWSTR lpDeviceName, + LPWSTR lpTargetPath, + DWORD ucchMax + ) +{ + return FALSE; +} + diff --git a/reactos/lib/kernel32/file/file.c b/reactos/lib/kernel32/file/file.c index 9fcb32cf8ad..465ad8af9bf 100644 --- a/reactos/lib/kernel32/file/file.c +++ b/reactos/lib/kernel32/file/file.c @@ -1,19 +1,58 @@ /* - * Win32 File Api functions - * Author: Boudewijn Dekker + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/file/file.c + * PURPOSE: Directory functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + GetTempFileName is modified from WINE [ Alexandre Juiliard ] + * UPDATE HISTORY: + * Created 01/11/98 */ + + #undef WIN32_LEAN_AND_MEAN #include #include +#include +#include +#include +#include +#define LPPROGRESS_ROUTINE void* + + + + +WINBOOL +CopyFileExW( + LPCWSTR lpExistingFileName, + LPCWSTR lpNewFileName, + LPPROGRESS_ROUTINE lpProgressRoutine, + LPVOID lpData, + WINBOOL * pbCancel, + DWORD dwCopyFlags + ); + +WINBOOL +CopyFileExA( + LPCSTR lpExistingFileName, + LPCSTR lpNewFileName, + LPPROGRESS_ROUTINE lpProgressRoutine, + LPVOID lpData, + WINBOOL * pbCancel, + DWORD dwCopyFlags + ); + +DWORD +GetCurrentTime(VOID); BOOLEAN bIsFileApiAnsi; // set the file api to ansi or oem -WINBASEAPI + VOID -WINAPI +STDCALL SetFileApisToOEM(VOID) { bIsFileApiAnsi = FALSE; @@ -28,37 +67,81 @@ HANDLE STDCALL CreateFileA(LPCSTR lpFileName, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { - HANDLE FileHandle; - NTSTATUS Status; - WCHAR FileNameW[255]; - OBJECT_ATTRIBUTES ObjectAttributes; - IO_STATUS_BLOCK IoStatusBlock; + + WCHAR FileNameW[MAX_PATH]; ULONG i = 0; - UNICODE_STRING FileNameString; - ULONG Flags = 0; - - if (!(dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED)) - { - Flags = Flags | FILE_SYNCHRONOUS_IO_ALERT; - } - - FileNameString.Length = 0; - - while ((*lpFileName)!=0) + + while ((*lpFileName)!=0 && i < MAX_PATH) { FileNameW[i] = *lpFileName; lpFileName++; i++; - FileNameString.Length++; } FileNameW[i] = 0; - FileNameString.Length++; + + return CreateFileW(FileNameW,dwDesiredAccess,dwShareMode, lpSecurityAttributes, + dwCreationDisposition,dwFlagsAndAttributes, hTemplateFile); +} + + +HANDLE STDCALL CreateFileW(LPCWSTR lpFileName, + DWORD dwDesiredAccess, + DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDisposition, + DWORD dwFlagsAndAttributes, + HANDLE hTemplateFile) +{ + HANDLE FileHandle; + NTSTATUS Status; + + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + UNICODE_STRING FileNameString; + ULONG Flags = 0; + WCHAR PathNameW[MAX_PATH]; + WCHAR *FilePart; + UINT Len = 0; - FileNameString.Buffer = &FileNameW; + if (!(dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED)) + { + Flags |= FILE_SYNCHRONOUS_IO_ALERT; + } + + + + if ( ( ( dwCreationDisposition & OPEN_EXISTING ) == OPEN_EXISTING ) || + ( ( dwCreationDisposition & TRUNCATE_EXISTING ) == TRUNCATE_EXISTING ) ) + Len = SearchPathW(NULL,lpFileName,NULL,MAX_PATH,PathNameW,&FilePart); + if ( Len == 0 ) + return NULL; + else { + Len = GetCurrentDirectoryW(MAX_PATH,PathNameW); + if ( Len == 0 ) + return NULL; + if ( PathNameW[Len-1] != L'\\' ) { + PathNameW[Len] = L'\\'; + PathNameW[Len+1] = 0; + } + lstrcatW(PathNameW,lpFileName); + } + FileNameString.Length = lstrlenW( PathNameW)*sizeof(WCHAR); + + if ( FileNameString.Length == 0 ) + return NULL; + + if ( FileNameString.Length > MAX_PATH ) + return NULL; + + FileNameString.Buffer = (WCHAR *)PathNameW; FileNameString.MaximumLength = FileNameString.Length; + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); ObjectAttributes.RootDirectory = NULL; ObjectAttributes.ObjectName = &FileNameString; + ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = NULL; Status = NtCreateFile(&FileHandle, dwDesiredAccess, @@ -74,6 +157,7 @@ HANDLE STDCALL CreateFileA(LPCSTR lpFileName, return(FileHandle); } + WINBASEAPI VOID WINAPI @@ -84,7 +168,7 @@ SetFileApisToANSI(VOID) } -WINBASEAPI + WINBOOL STDCALL AreFileApisANSI(VOID) @@ -96,13 +180,13 @@ AreFileApisANSI(VOID) -BOOL STDCALL WriteFile(HANDLE hFile, +WINBOOL STDCALL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverLapped) { - //FIXME: WriteFile should write to a console if appropriate + LARGE_INTEGER Offset; HANDLE hEvent = NULL; NTSTATUS errCode; @@ -116,7 +200,7 @@ BOOL STDCALL WriteFile(HANDLE hFile, } errCode = NtWriteFile(hFile,hEvent,NULL,NULL, (PIO_STATUS_BLOCK)lpOverLapped, - lpBuffer, + (PVOID)lpBuffer, nNumberOfBytesToWrite, &Offset, NULL); @@ -135,13 +219,13 @@ WINBOOL STDCALL ReadFile(HANDLE hFile, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverLapped) { -//FIXME ReadFile should write to a console if appropriate + HANDLE hEvent = NULL; LARGE_INTEGER Offset; NTSTATUS errCode; PIO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IIosb; - OVERLAPPED IOverlapped; + if ( lpOverLapped != NULL ) { @@ -165,7 +249,7 @@ WINBOOL STDCALL ReadFile(HANDLE hFile, nNumberOfBytesToRead, &Offset, NULL); - if ( errCode < 0 ) + if ( !NT_SUCCESS(errCode) ) { SetLastError(RtlNtStatusToDosError(errCode)); return FALSE; @@ -186,13 +270,23 @@ ReadFileEx( HANDLE hEvent = NULL; LARGE_INTEGER Offset; NTSTATUS errCode; + IO_STATUS_BLOCK IIosb; + PIO_STATUS_BLOCK IoStatusBlock; + if ( lpOverLapped != NULL ) { Offset.LowPart = lpOverLapped->Offset; Offset.HighPart = lpOverLapped->OffsetHigh; lpOverLapped->Internal = STATUS_PENDING; hEvent = lpOverLapped->hEvent; + IoStatusBlock = (PIO_STATUS_BLOCK)lpOverLapped; } + else { + Offset.LowPart = 0; + Offset.HighPart = 0; + IoStatusBlock = &IIosb; + } + @@ -200,12 +294,12 @@ ReadFileEx( hEvent, (PIO_APC_ROUTINE)lpCompletionRoutine, NULL, - (PIO_STATUS_BLOCK)lpOverLapped, + IoStatusBlock, lpBuffer, nNumberOfBytesToRead, &Offset, NULL); - if ( errCode < 0 ) { + if ( !NT_SUCCESS(errCode) ) { SetLastError(RtlNtStatusToDosError(errCode)); return FALSE; } @@ -285,7 +379,7 @@ LockFileEx( NULL, LockImmediate, LockExclusive); - if ( errCode < 0 ) + if ( !NT_SUCCESS(errCode) ) { SetLastError(RtlNtStatusToDosError(errCode)); return FALSE; @@ -316,11 +410,15 @@ UnlockFile( -WINBOOL STDCALL UnlockFileEx(HANDLE hFile, - DWORD dwReserved, - DWORD nNumberOfBytesToUnLockLow, - DWORD nNumberOfBytesToUnLockHigh, - LPOVERLAPPED lpOverlapped) +WINBOOL +STDCALL +UnlockFileEx( + HANDLE hFile, + DWORD dwReserved, + DWORD nNumberOfBytesToUnLockLow, + DWORD nNumberOfBytesToUnLockHigh, + LPOVERLAPPED lpOverlapped + ) { LARGE_INTEGER BytesToUnLock; LARGE_INTEGER StartAddress; @@ -345,10 +443,10 @@ WINBOOL STDCALL UnlockFileEx(HANDLE hFile, errCode = NtUnlockFile(hFile, (PIO_STATUS_BLOCK)lpOverlapped, - StartAddress, - BytesToUnLock, + &StartAddress, + &BytesToUnLock, NULL); - if ( errCode < 0 ) { + if ( !NT_SUCCESS(errCode) ) { SetLastError(RtlNtStatusToDosError(errCode)); return FALSE; } @@ -357,3 +455,960 @@ WINBOOL STDCALL UnlockFileEx(HANDLE hFile, } + + + + + +WINBOOL +STDCALL +CopyFileA( + LPCSTR lpExistingFileName, + LPCSTR lpNewFileName, + WINBOOL bFailIfExists + ) +{ + return CopyFileExA(lpExistingFileName,lpNewFileName,NULL,NULL,FALSE,bFailIfExists); +} + +WINBOOL +STDCALL +CopyFileExA( + LPCSTR lpExistingFileName, + LPCSTR lpNewFileName, + LPPROGRESS_ROUTINE lpProgressRoutine, + LPVOID lpData, + WINBOOL * pbCancel, + DWORD dwCopyFlags + ) +{ + ULONG i; + WCHAR ExistingFileNameW[MAX_PATH]; + WCHAR NewFileNameW[MAX_PATH]; + + + + i = 0; + while ((*lpExistingFileName)!=0 && i < MAX_PATH) + { + ExistingFileNameW[i] = *lpExistingFileName; + lpExistingFileName++; + i++; + } + ExistingFileNameW[i] = 0; + + i = 0; + while ((*lpNewFileName)!=0 && i < MAX_PATH) + { + NewFileNameW[i] = *lpNewFileName; + lpNewFileName++; + i++; + } + NewFileNameW[i] = 0; + + return CopyFileExW(ExistingFileNameW,NewFileNameW,lpProgressRoutine,lpData,pbCancel,dwCopyFlags); +} + + +WINBOOL +STDCALL +CopyFileW( + LPCWSTR lpExistingFileName, + LPCWSTR lpNewFileName, + WINBOOL bFailIfExists + ) +{ + return CopyFileExW(lpExistingFileName,lpNewFileName,NULL,NULL,NULL,bFailIfExists); +} + + + + + +WINBOOL +STDCALL +CopyFileExW( + LPCWSTR lpExistingFileName, + LPCWSTR lpNewFileName, + LPPROGRESS_ROUTINE lpProgressRoutine, + LPVOID lpData, + WINBOOL * pbCancel, + DWORD dwCopyFlags + ) +{ + + NTSTATUS errCode = 0; + HANDLE FileHandleSource, FileHandleDest; + IO_STATUS_BLOCK IoStatusBlock; + + FILE_STANDARD_INFORMATION FileStandard; + FILE_BASIC_INFORMATION FileBasic; + FILE_POSITION_INFORMATION FilePosition; + + UCHAR *lpBuffer = NULL; + + + + ULONG RegionSize = 0x1000000; + + BOOL bCancel = FALSE; + + + + FileHandleSource = CreateFileW( + lpExistingFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, + NULL + ); + + + + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + + errCode = NtQueryInformationFile(FileHandleSource, + &IoStatusBlock,&FileStandard, sizeof(FILE_STANDARD_INFORMATION), + FileStandardInformation); + if ( !NT_SUCCESS(errCode) ) { + NtClose(FileHandleSource); + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + errCode = NtQueryInformationFile(FileHandleSource, + &IoStatusBlock,&FileBasic, sizeof(FILE_BASIC_INFORMATION), + FileBasicInformation); + if ( !NT_SUCCESS(errCode) ) { + NtClose(FileHandleSource); + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + + + + + + FileHandleDest = CreateFileW( + lpNewFileName, + GENERIC_WRITE, + FILE_SHARE_WRITE, + NULL, + dwCopyFlags ? CREATE_NEW : CREATE_ALWAYS , + FileBasic.FileAttributes|FILE_FLAG_NO_BUFFERING, + NULL + ); + + if ( !NT_SUCCESS(errCode) ) { + NtClose(FileHandleSource); + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + + + + FilePosition.CurrentByteOffset.LowPart = 0; + FilePosition.CurrentByteOffset.HighPart = 0; + + errCode = NtSetInformationFile(FileHandleSource, + &IoStatusBlock,&FilePosition, sizeof(FILE_POSITION_INFORMATION), + FilePositionInformation); + if ( !NT_SUCCESS(errCode) ) { + NtClose(FileHandleSource); + NtClose(FileHandleDest); + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + errCode = NtSetInformationFile(FileHandleDest, + &IoStatusBlock,&FilePosition, sizeof(FILE_POSITION_INFORMATION), + FilePositionInformation); + + if ( !NT_SUCCESS(errCode) ) { + NtClose(FileHandleSource); + NtClose(FileHandleDest); + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + + + errCode = NtAllocateVirtualMemory( + NtCurrentProcess(), + (PVOID *)&lpBuffer, + 2, + &RegionSize, + MEM_COMMIT, + PAGE_READWRITE + ); + + if ( !NT_SUCCESS(errCode) ) { + NtClose(FileHandleSource); + NtClose(FileHandleDest); + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + + + + + + do { + + errCode = NtReadFile( + FileHandleSource, + NULL, + NULL, + NULL, + (PIO_STATUS_BLOCK)&IoStatusBlock, + lpBuffer, + RegionSize, + NULL, + NULL); + if ( pbCancel != NULL ) + bCancel = *pbCancel; + + + if ( !NT_SUCCESS(errCode) || bCancel ) { + NtFreeVirtualMemory(NtCurrentProcess(),(PVOID *)&lpBuffer, &RegionSize,MEM_RELEASE); + NtClose(FileHandleSource); + NtClose(FileHandleDest); + if ( errCode == STATUS_END_OF_FILE ) + break; + else + return FALSE; + + } + + errCode = NtWriteFile(FileHandleDest, + NULL, + lpProgressRoutine, + lpData, + (PIO_STATUS_BLOCK)&IoStatusBlock, + lpBuffer, + RegionSize, + NULL, + NULL); + + + + if ( !NT_SUCCESS(errCode) ) { + NtFreeVirtualMemory(NtCurrentProcess(),(PVOID *)&lpBuffer, &RegionSize,MEM_RELEASE); + NtClose(FileHandleSource); + NtClose(FileHandleDest); + return FALSE; + } + + } while ( TRUE ); + + return TRUE; + + +} + + +HFILE +STDCALL +OpenFile( + LPCSTR lpFileName, + LPOFSTRUCT lpReOpenBuff, + UINT uStyle + ) +{ + NTSTATUS errCode; + HANDLE FileHandle = NULL; + UNICODE_STRING FileNameString; + WCHAR FileNameW[MAX_PATH]; + WCHAR PathNameW[MAX_PATH]; + ULONG i; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + WCHAR *FilePart; + ULONG Len; + + if ( lpReOpenBuff == NULL ) { + return FALSE; + } + + + + + i = 0; + while ((*lpFileName)!=0 && i < MAX_PATH) + { + FileNameW[i] = *lpFileName; + lpFileName++; + i++; + } + FileNameW[i] = 0; + + + Len = SearchPathW(NULL,FileNameW,NULL,MAX_PATH,PathNameW,&FilePart); + if ( Len == 0 ) + return (HFILE)NULL; + + + if ( Len > MAX_PATH ) + return (HFILE)NULL; + + FileNameString.Length = lstrlenW(PathNameW)*sizeof(WCHAR); + FileNameString.Buffer = PathNameW; + FileNameString.MaximumLength = FileNameString.Length; + + + + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + ObjectAttributes.ObjectName = &FileNameString; + ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = NULL; + + // FILE_SHARE_READ + // FILE_NO_INTERMEDIATE_BUFFERING + + + + if ((uStyle & OF_PARSE) == OF_PARSE ) + return (HFILE)NULL; + + + errCode = NtOpenFile( + &FileHandle, + GENERIC_READ|SYNCHRONIZE, + &ObjectAttributes, + &IoStatusBlock, + FILE_SHARE_READ, + FILE_NON_DIRECTORY_FILE + ); + + lpReOpenBuff->nErrCode = RtlNtStatusToDosError(errCode); + + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return (HFILE)INVALID_HANDLE_VALUE; + } + + return (HFILE)FileHandle; + +} + + +WINBOOL +STDCALL +MoveFileA( + LPCSTR lpExistingFileName, + LPCSTR lpNewFileName + ) +{ + return MoveFileExA(lpExistingFileName,lpNewFileName,MOVEFILE_COPY_ALLOWED); +} + +WINBOOL +STDCALL +MoveFileExA( + LPCSTR lpExistingFileName, + LPCSTR lpNewFileName, + DWORD dwFlags + ) +{ + ULONG i; + WCHAR ExistingFileNameW[MAX_PATH]; + WCHAR NewFileNameW[MAX_PATH]; + + + + i = 0; + while ((*lpExistingFileName)!=0 && i < MAX_PATH) + { + ExistingFileNameW[i] = *lpExistingFileName; + lpExistingFileName++; + i++; + } + ExistingFileNameW[i] = 0; + + i = 0; + while ((*lpNewFileName)!=0 && i < MAX_PATH) + { + NewFileNameW[i] = *lpNewFileName; + lpNewFileName++; + i++; + } + NewFileNameW[i] = 0; + + return MoveFileExW(ExistingFileNameW,NewFileNameW,dwFlags); + +} + + + +WINBOOL +STDCALL +MoveFileW( + LPCWSTR lpExistingFileName, + LPCWSTR lpNewFileName + ) +{ + return MoveFileExW(lpExistingFileName,lpNewFileName,MOVEFILE_COPY_ALLOWED); +} + +#define FILE_RENAME_SIZE MAX_PATH +sizeof(FILE_RENAME_INFORMATION) + +WINBOOL +STDCALL +MoveFileExW( + LPCWSTR lpExistingFileName, + LPCWSTR lpNewFileName, + DWORD dwFlags + ) +{ + HANDLE hFile = NULL; + IO_STATUS_BLOCK IoStatusBlock; + FILE_RENAME_INFORMATION *FileRename; + USHORT Buffer[FILE_RENAME_SIZE]; + NTSTATUS errCode; + + hFile = CreateFileW( + lpExistingFileName, + GENERIC_ALL, + FILE_SHARE_WRITE|FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL + ); + + + + FileRename = (FILE_RENAME_INFORMATION *)Buffer; + if ( ( dwFlags & MOVEFILE_REPLACE_EXISTING ) == MOVEFILE_REPLACE_EXISTING ) + FileRename->Replace = TRUE; + else + FileRename->Replace = FALSE; + + FileRename->FileNameLength = lstrlenW(lpNewFileName); + memcpy(FileRename->FileName,lpNewFileName,min(FileRename->FileNameLength,MAX_PATH)); + + errCode = NtSetInformationFile(hFile,&IoStatusBlock,FileRename, FILE_RENAME_SIZE, FileRenameInformation); + if ( !NT_SUCCESS(errCode) ) { + if ( CopyFileW(lpExistingFileName,lpNewFileName,FileRename->Replace) ) + DeleteFileW(lpExistingFileName); + } + + CloseHandle(hFile); + return TRUE; +} + +WINBOOL +STDCALL +DeleteFileA( + LPCSTR lpFileName + ) +{ + ULONG i; + + WCHAR FileNameW[MAX_PATH]; + + + + i = 0; + while ((*lpFileName)!=0 && i < MAX_PATH) + { + FileNameW[i] = *lpFileName; + lpFileName++; + i++; + } + FileNameW[i] = 0; + return DeleteFileW(FileNameW); + +} + +WINBOOL +STDCALL +DeleteFileW( + LPCWSTR lpFileName + ) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING FileNameString; + NTSTATUS errCode; + WCHAR PathNameW[MAX_PATH]; + UINT Len; + + Len = GetCurrentDirectoryW(MAX_PATH,PathNameW); + if ( Len == 0 ) + return FALSE; + if ( PathNameW[Len-1] != L'\\' ) { + PathNameW[Len] = L'\\'; + PathNameW[Len+1] = 0; + } + lstrcatW(PathNameW,lpFileName); + FileNameString.Length = lstrlenW( PathNameW)*sizeof(WCHAR); + if ( FileNameString.Length == 0 ) + return FALSE; + + if ( FileNameString.Length > MAX_PATH ) + return FALSE; + + + + + FileNameString.Buffer = (WCHAR *)PathNameW; + FileNameString.MaximumLength = FileNameString.Length; + + + + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + ObjectAttributes.ObjectName = &FileNameString; + ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = NULL; + + + + + errCode = NtDeleteFile(&ObjectAttributes); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + +WINBOOL +STDCALL +FlushFileBuffers( + HANDLE hFile + ) +{ + NTSTATUS errCode; + IO_STATUS_BLOCK IoStatusBlock; + + errCode = NtFlushBuffersFile( + hFile, + &IoStatusBlock + ); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + + +DWORD +STDCALL +SetFilePointer( + HANDLE hFile, + LONG lDistanceToMove, + PLONG lpDistanceToMoveHigh, + DWORD dwMoveMethod + ) +{ + FILE_POSITION_INFORMATION FilePosition; + FILE_END_OF_FILE_INFORMATION FileEndOfFile; + NTSTATUS errCode; + IO_STATUS_BLOCK IoStatusBlock; + if ( dwMoveMethod == FILE_CURRENT ) { + NtQueryInformationFile(hFile,&IoStatusBlock,&FilePosition, sizeof(FILE_POSITION_INFORMATION),FilePositionInformation); + FilePosition.CurrentByteOffset.LowPart += lDistanceToMove; + if ( lpDistanceToMoveHigh != NULL ) + FilePosition.CurrentByteOffset.HighPart += *lpDistanceToMoveHigh; + } + else if ( dwMoveMethod == FILE_END ) { + NtQueryInformationFile(hFile,&IoStatusBlock,&FileEndOfFile, sizeof(FILE_END_OF_FILE_INFORMATION),FileEndOfFileInformation); + FilePosition.CurrentByteOffset.LowPart = FileEndOfFile.EndOfFile.LowPart - lDistanceToMove; + if ( lpDistanceToMoveHigh != NULL ) + FilePosition.CurrentByteOffset.HighPart = FileEndOfFile.EndOfFile.HighPart - *lpDistanceToMoveHigh; + else + FilePosition.CurrentByteOffset.HighPart = FileEndOfFile.EndOfFile.HighPart; + } + else if ( dwMoveMethod == FILE_CURRENT ) { + FilePosition.CurrentByteOffset.LowPart = lDistanceToMove; + if ( lpDistanceToMoveHigh != NULL ) + FilePosition.CurrentByteOffset.HighPart = *lpDistanceToMoveHigh; + else + FilePosition.CurrentByteOffset.HighPart = 0; + } + + errCode = NtSetInformationFile(hFile,&IoStatusBlock,&FilePosition, sizeof(FILE_POSITION_INFORMATION),FilePositionInformation); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return -1; + } + + if ( lpDistanceToMoveHigh != NULL ) + lpDistanceToMoveHigh = &FilePosition.CurrentByteOffset.HighPart ; + return FilePosition.CurrentByteOffset.LowPart; +} + +DWORD +STDCALL +GetFileType( + HANDLE hFile + ) +{ + return FILE_TYPE_UNKNOWN; +} + + +DWORD +STDCALL +GetFileSize( + HANDLE hFile, + LPDWORD lpFileSizeHigh + ) +{ + NTSTATUS errCode; + FILE_STANDARD_INFORMATION FileStandard; + IO_STATUS_BLOCK IoStatusBlock; + + + errCode = NtQueryInformationFile(hFile, + &IoStatusBlock,&FileStandard, sizeof(FILE_STANDARD_INFORMATION), + FileStandardInformation); + if ( !NT_SUCCESS(errCode) ) { + CloseHandle(hFile); + SetLastError(RtlNtStatusToDosError(errCode)); + if ( lpFileSizeHigh == NULL ) { + return -1; + } + else + return 0; + } + if ( lpFileSizeHigh != NULL ) + *lpFileSizeHigh = FileStandard.AllocationSize.HighPart; + + CloseHandle(hFile); + return FileStandard.AllocationSize.LowPart; +} + +DWORD +STDCALL +GetCompressedFileSizeA( + LPCSTR lpFileName, + LPDWORD lpFileSizeHigh + ) +{ + WCHAR FileNameW[MAX_PATH]; + ULONG i; + i = 0; + while ((*lpFileName)!=0 && i < MAX_PATH) + { + FileNameW[i] = *lpFileName; + lpFileName++; + i++; + } + FileNameW[i] = 0; + + + return GetCompressedFileSizeW(FileNameW,lpFileSizeHigh); + +} + +DWORD +STDCALL +GetCompressedFileSizeW( + LPCWSTR lpFileName, + LPDWORD lpFileSizeHigh + ) +{ + FILE_COMPRESSION_INFORMATION FileCompression; + NTSTATUS errCode; + IO_STATUS_BLOCK IoStatusBlock; + HANDLE hFile; + + hFile = CreateFileW( + lpFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL + ); + + errCode = NtQueryInformationFile(hFile, + &IoStatusBlock,&FileCompression, sizeof(FILE_COMPRESSION_INFORMATION), + FileCompressionInformation); + if ( !NT_SUCCESS(errCode) ) { + CloseHandle(hFile); + SetLastError(RtlNtStatusToDosError(errCode)); + return 0; + } + CloseHandle(hFile); + return 0; + +} + + + +WINBOOL +STDCALL +GetFileInformationByHandle( + HANDLE hFile, + LPBY_HANDLE_FILE_INFORMATION lpFileInformation + ) +{ + FILE_DIRECTORY_INFORMATION FileDirectory; + FILE_INTERNAL_INFORMATION FileInternal; + FILE_FS_VOLUME_INFORMATION FileFsVolume; + FILE_STANDARD_INFORMATION FileStandard; + + NTSTATUS errCode; + IO_STATUS_BLOCK IoStatusBlock; + errCode = NtQueryInformationFile(hFile,&IoStatusBlock,&FileDirectory, sizeof(FILE_DIRECTORY_INFORMATION),FileDirectoryInformation); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + lpFileInformation->dwFileAttributes = (DWORD)FileDirectory.FileAttributes; + memcpy(&lpFileInformation->ftCreationTime,&FileDirectory.CreationTime,sizeof(LARGE_INTEGER)); + memcpy(&lpFileInformation->ftLastAccessTime,&FileDirectory.LastAccessTime,sizeof(LARGE_INTEGER)); + memcpy(&lpFileInformation->ftLastWriteTime, &FileDirectory.LastWriteTime,sizeof(LARGE_INTEGER)); + lpFileInformation->nFileSizeHigh = FileDirectory.AllocationSize.HighPart; + lpFileInformation->nFileSizeLow = FileDirectory.AllocationSize.LowPart; + + + + errCode = NtQueryInformationFile(hFile,&IoStatusBlock,&FileInternal, sizeof(FILE_INTERNAL_INFORMATION),FileInternalInformation); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + lpFileInformation->nFileIndexHigh = FileInternal.IndexNumber.HighPart; + lpFileInformation->nFileIndexLow = FileInternal.IndexNumber.LowPart; + + + errCode = NtQueryVolumeInformationFile(hFile,&IoStatusBlock,&FileFsVolume, sizeof(FILE_FS_VOLUME_INFORMATION),FileFsVolumeInformation); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + lpFileInformation->dwVolumeSerialNumber = FileFsVolume.VolumeSerialNumber; + + + errCode = NtQueryInformationFile(hFile,&IoStatusBlock,&FileStandard, sizeof(FILE_STANDARD_INFORMATION),FileStandardInformation); + if ( !NT_SUCCESS(errCode) ) { + CloseHandle(hFile); + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + lpFileInformation->nNumberOfLinks = FileStandard.NumberOfLinks; + CloseHandle(hFile); + return TRUE; + +} + + + + + + +DWORD +STDCALL +GetFileAttributesA( + LPCSTR lpFileName + ) +{ + ULONG i; + WCHAR FileNameW[MAX_PATH]; + i = 0; + while ((*lpFileName)!=0 && i < MAX_PATH) + { + FileNameW[i] = *lpFileName; + lpFileName++; + i++; + } + FileNameW[i] = 0; + return GetFileAttributesW(FileNameW); +} + + +DWORD +STDCALL +GetFileAttributesW( + LPCWSTR lpFileName + ) +{ + IO_STATUS_BLOCK IoStatusBlock; + FILE_BASIC_INFORMATION FileBasic; + HANDLE hFile; + NTSTATUS errCode; + + + hFile = CreateFileW( + lpFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL + ); + + + errCode = NtQueryInformationFile(hFile,&IoStatusBlock,&FileBasic, sizeof(FILE_BASIC_INFORMATION),FileBasicInformation); + if ( !NT_SUCCESS(errCode) ) { + CloseHandle(hFile); + SetLastError(RtlNtStatusToDosError(errCode)); + return 0; + } + CloseHandle(hFile); + return (DWORD)FileBasic.FileAttributes; + +} + + + +DWORD +GetCurrentTime(VOID) +{ + NTSTATUS errCode; + FILETIME CurrentTime; + errCode = NtQuerySystemTime ( + (TIME *)&CurrentTime + ); + return CurrentTime.dwLowDateTime; +} + +UINT +STDCALL +GetTempFileNameA( + LPCSTR lpPathName, + LPCSTR lpPrefixString, + UINT uUnique, + LPSTR lpTempFileName + ) +{ + HANDLE hFile; + UINT unique = uUnique; + + if (lpPathName == NULL) + return 0; + + if (uUnique == 0) + uUnique = GetCurrentTime(); + + wsprintfA(lpTempFileName,"%s\\%c%.3s%4.4x%s", + lpPathName,'~',lpPrefixString,uUnique,".tmp"); + + if (unique) + return uUnique; + + while ((hFile = CreateFileA(lpTempFileName, GENERIC_WRITE, 0, NULL, + CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY, + 0)) == INVALID_HANDLE_VALUE) + { + wsprintfA(lpTempFileName,"%s\\%c%.3s%4.4x%s", + lpPathName,'~',lpPrefixString,++uUnique,".tmp"); + } + + CloseHandle((HANDLE)hFile); + return uUnique; +} + + +UINT +STDCALL +GetTempFileNameW( + LPCWSTR lpPathName, + LPCWSTR lpPrefixString, + UINT uUnique, + LPWSTR lpTempFileName + ) +{ + HANDLE hFile; + UINT unique = uUnique; + + if (lpPathName == NULL) + return 0; + + if (uUnique == 0) + uUnique = GetCurrentTime(); + + wsprintfW(lpTempFileName,L"%s\\%c%.3s%4.4x%s", + lpPathName,'~',lpPrefixString,uUnique,L".tmp"); + + if (unique) + return uUnique; + + while ((hFile = CreateFileW(lpTempFileName, GENERIC_WRITE, 0, NULL, + CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY, + 0)) == INVALID_HANDLE_VALUE) + { + wsprintfW(lpTempFileName,L"%s\\%c%.3s%4.4x%s", + lpPathName,'~',lpPrefixString,++uUnique,L".tmp"); + } + + CloseHandle((HANDLE)hFile); + return uUnique; +} + +WINBOOL +STDCALL +GetFileTime( + HANDLE hFile, + LPFILETIME lpCreationTime, + LPFILETIME lpLastAccessTime, + LPFILETIME lpLastWriteTime + ) +{ + IO_STATUS_BLOCK IoStatusBlock; + FILE_BASIC_INFORMATION FileBasic; + NTSTATUS errCode; + + + + errCode = NtQueryInformationFile(hFile,&IoStatusBlock,&FileBasic, sizeof(FILE_BASIC_INFORMATION),FileBasicInformation); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + memcpy(lpCreationTime,&FileBasic.CreationTime,sizeof(FILETIME)); + memcpy(lpLastAccessTime,&FileBasic.LastAccessTime,sizeof(FILETIME)); + memcpy(lpLastWriteTime,&FileBasic.LastWriteTime,sizeof(FILETIME)); + return TRUE; +} + +WINBOOL +STDCALL +SetFileTime( + HANDLE hFile, + CONST FILETIME *lpCreationTime, + CONST FILETIME *lpLastAccessTime, + CONST FILETIME *lpLastWriteTime + ) +{ + FILE_BASIC_INFORMATION FileBasic; + IO_STATUS_BLOCK IoStatusBlock; + NTSTATUS errCode; + + + + memcpy(&FileBasic.CreationTime,lpCreationTime,sizeof(FILETIME)); + memcpy(&FileBasic.LastAccessTime,lpLastAccessTime,sizeof(FILETIME)); + memcpy(&FileBasic.LastWriteTime,lpLastWriteTime,sizeof(FILETIME)); + + // shoud i initialize changetime ??? + + errCode = NtSetInformationFile(hFile,&IoStatusBlock,&FileBasic, sizeof(FILE_BASIC_INFORMATION),FileBasicInformation); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + return TRUE; +} \ No newline at end of file diff --git a/reactos/lib/kernel32/file/find.c b/reactos/lib/kernel32/file/find.c new file mode 100644 index 00000000000..bf2dbe79b24 --- /dev/null +++ b/reactos/lib/kernel32/file/find.c @@ -0,0 +1,521 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/file/find.c + * PURPOSE: Find functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ +#include +#include + +typedef enum _FINDEX_INFO_LEVELS +{ + FindExSearchNameMatch, + FindExSearchLimitToDirectories, + FindExSearchLimitToDevices, + +} FINDEX_INFO_LEVELS ; + +typedef enum _FINDEX_SEARCH_OPS +{ + FindExInfoStandard + +} FINDEX_SEARCH_OPS; + +int wcharicmp ( WCHAR char1, WCHAR char2 ); + +WINBOOL +mfs_regexp(LPCWSTR lpFileName,LPCWSTR lpFilter); + +HANDLE +STDCALL +FindFirstFileW( + LPWSTR lpFileName, + LPWIN32_FIND_DATA lpFindFileData + ); + +WINBOOL +STDCALL +FindNextFileW( + HANDLE hFind, + LPWIN32_FIND_DATA lpFindFileData + ); + +HANDLE +STDCALL +FindFirstFileExA( + LPCSTR lpFileName, + FINDEX_INFO_LEVELS fInfoLevelId, + LPVOID lpFindFileData, + FINDEX_SEARCH_OPS fSearchOp, + LPVOID lpSearchFilter, + DWORD dwAdditionalFlags + ); + +HANDLE +STDCALL +FindFirstFileExW( + LPCWSTR lpFileName, + FINDEX_INFO_LEVELS fInfoLevelId, + LPVOID lpFindFileData, + FINDEX_SEARCH_OPS fSearchOp, + LPVOID lpSearchFilter, + DWORD dwAdditionalFlags + ); + +typedef struct _FIND_FILE_INFO +{ + ULONG Offset; + PVOID SearchFilter; + WCHAR FileName[MAX_PATH]; + WCHAR PathName[MAX_PATH]; + FILE_DIRECTORY_INFORMATION *FileDirectory; +} FIND_FILE_INFO; + + +/* + +typedef struct _WIN32_FIND_DATAW { + DWORD dwFileAttributes; + FILETIME ftCreationTime; + FILETIME ftLastAccessTime; + FILETIME ftLastWriteTime; + DWORD nFileSizeHigh; + DWORD nFileSizeLow; + DWORD dwReserved0; + DWORD dwReserved1; + WCHAR cFileName[ MAX_PATH ]; + WCHAR cAlternateFileName[ 14 ]; +} WIN32_FIND_DATAW, *LPWIN32_FIND_DATAW, *PWIN32_FIND_DATAW; +*/ + +WINBOOL +STDCALL +FindClose( + HANDLE hFind + ) +{ + + if ( hFind == NULL) + return FALSE; + + + HeapFree(GetProcessHeap(),0,((FIND_FILE_INFO *)hFind)->FileDirectory); + HeapFree(GetProcessHeap(),0,hFind); + return TRUE; +} + + +HANDLE +STDCALL +FindFirstFileA( + LPCSTR lpFileName, + LPWIN32_FIND_DATA lpFindFileData + ) +{ + WIN32_FIND_DATA FindFileDataW; + WCHAR FileNameW[MAX_PATH]; + ULONG i; + + i = 0; + while ((*lpFileName)!=0 && i < MAX_PATH) + { + FileNameW[i] = *lpFileName; + lpFileName++; + i++; + } + FileNameW[i] = 0; + FindFirstFileW(FileNameW,&FindFileDataW); + + // converteer FindFileDataW + +} + +HANDLE +STDCALL +FindFirstFileW( + LPWSTR lpFileName, + LPWIN32_FIND_DATA lpFindFileData + ) +{ + return FindFirstFileExW(lpFileName,FindExInfoStandard,lpFindFileData,FindExSearchNameMatch,NULL,0); +} + +WINBOOL +STDCALL +FindNextFileA( + HANDLE hFind, + LPWIN32_FIND_DATA lpFindFileData + ) +{ + WIN32_FIND_DATA FindFileDataW; + FindNextFileW(hFind,&FindFileDataW); + // converteer FindFileDataW +} + +WINBOOL +STDCALL +FindNextFileW( + HANDLE hFind, + LPWIN32_FIND_DATA lpFindFileData + ) +{ + int i; + WCHAR *pNameRead; + WCHAR FileName[MAX_PATH]; + + FIND_FILE_INFO *FindPtr = hFind; + FILE_DIRECTORY_INFORMATION *FileDirectory; + + if ( FindPtr == NULL ) + return FALSE; + + /* Try to find a file */ + FileDirectory = FindPtr->Offset + FindPtr->FileDirectory; + while ( FileDirectory->NextEntryOffset != 0 ) { + + pNameRead = FileDirectory->FileName; + FindPtr->Offset += FileDirectory->NextEntryOffset; + for(i=0;iFileNameLength;i++) + printf("%c\n",(char)pNameRead[i]); + if (mfs_regexp(pNameRead, FindPtr->FileName)) + { + /* We found one! */ + if (FindPtr->PathName[0] != L'\0') + { + lstrcpyW(lpFindFileData->cFileName, FindPtr->PathName); + lstrcatW(lpFindFileData->cFileName, L"/"); + lstrcatW(lpFindFileData->cFileName, pNameRead); + } + else + + lstrcpyW(lpFindFileData->cFileName, pNameRead); + + + + lstrcpyW(lpFindFileData->cAlternateFileName, L""); + lpFindFileData->dwReserved0 = 0; + lpFindFileData->dwReserved1 = 0; + return TRUE; + } + FileDirectory = FindPtr->Offset + FindPtr->FileDirectory; + } + return FALSE; +} + + +HANDLE +STDCALL +FindFirstFileExA( + LPCSTR lpFileName, + FINDEX_INFO_LEVELS fInfoLevelId, + LPVOID lpFindFileData, + FINDEX_SEARCH_OPS fSearchOp, + LPVOID lpSearchFilter, + DWORD dwAdditionalFlags + ) +{ + WCHAR FileNameW[MAX_PATH]; + WIN32_FIND_DATAW FindFileDataW; + FindFirstFileExW(FileNameW,fInfoLevelId,&FindFileDataW,fSearchOp,lpSearchFilter,dwAdditionalFlags); + // conerteer FindFileDataW + +} + +HANDLE +STDCALL +FindFirstFileExW( + LPCWSTR lpFileName, + FINDEX_INFO_LEVELS fInfoLevelId, + LPVOID lpFindFileData, + FINDEX_SEARCH_OPS fSearchOp, + LPVOID lpSearchFilter, + DWORD dwAdditionalFlags + ) +{ + NTSTATUS errCode; + IO_STATUS_BLOCK IoStatusBlock; + HANDLE FileHandle = NULL; + FIND_FILE_INFO *hFind; + WCHAR *FilePart; + UNICODE_STRING FileNameString, PathNameString; + OBJECT_ATTRIBUTES ObjectAttributes; + + + ACCESS_MASK DesiredAccess=FILE_READ_DATA; + + ULONG FileAttributes=FILE_ATTRIBUTE_DIRECTORY; + ULONG ShareAccess=FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; + ULONG CreateDisposition=FILE_OPEN; + ULONG CreateOptions=FILE_DIRECTORY_FILE; + + + hFind = HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,sizeof(FIND_FILE_INFO)); + + hFind->FileDirectory = HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,8192); + + + + /* Try to find a path and a filename in the passed filename */ + + lstrcpyW(hFind->PathName, lpFileName); + FilePart = wcsrchr(hFind->PathName, '\\'); + + if (FilePart == NULL){ + GetCurrentDirectory(MAX_PATH, hFind->PathName); + lstrcpyW(hFind->FileName, lpFileName); + } + else { + FilePart[0] = L'\0'; + lstrcpyW(hFind->FileName, &FilePart[1]); + } + + hFind->Offset = 0; + + + PathNameString.Length = lstrlenW(hFind->PathName)*sizeof(WCHAR); + PathNameString.Buffer = hFind->PathName; + PathNameString.MaximumLength = FileNameString.Length; + + + FileNameString.Length = lstrlenW(hFind->FileName)*sizeof(WCHAR); + FileNameString.Buffer = hFind->FileName; + FileNameString.MaximumLength = FileNameString.Length; + + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + ObjectAttributes.ObjectName = &PathNameString; + ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE| OBJ_INHERIT; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = NULL; + + + + + + + errCode = NtCreateFile( + &FileHandle, + DesiredAccess, + &ObjectAttributes, + &IoStatusBlock, + NULL, // AllocationSize + FileAttributes, + ShareAccess, + CreateDisposition, + CreateOptions, + NULL, // EaBuffer + 0); // + + if ( !NT_SUCCESS(errCode) ) { + printf("%x\n",errCode); + return NULL; + } + + errCode = NtQueryDirectoryFile( + FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + hFind->FileDirectory, + 8192, + FileDirectoryInformation, + FALSE, + &FileNameString, + FALSE + ); + if ( !NT_SUCCESS(errCode) ) { + printf("%x\n",errCode); + return NULL; + } + + + + + if ( FindNextFileW(hFind,lpFindFileData) ) + return hFind; + else { + FindClose(hFind); + return NULL; + } + return NULL; +} + + +WINBOOL +FindCloseChangeNotification( + HANDLE hChangeHandle + ) +{ + return FALSE; +} + +HANDLE +STDCALL +FindFirstChangeNotificationA( + LPCSTR lpPathName, + WINBOOL bWatchSubtree, + DWORD dwNotifyFilter + ) +{ + ULONG i; + + WCHAR PathNameW[MAX_PATH]; + + + + + i = 0; + while ((*lpPathName)!=0 && i < MAX_PATH) + { + PathNameW[i] = *lpPathName; + lpPathName++; + i++; + } + PathNameW[i] = 0; + return FindFirstChangeNotificationW(PathNameW, bWatchSubtree, dwNotifyFilter ); + +} + +HANDLE +STDCALL +FindFirstChangeNotificationW( + LPCWSTR lpPathName, + WINBOOL bWatchSubtree, + DWORD dwNotifyFilter + ) +{ + return NULL; +} + +WINBOOL +STDCALL +FindNextChangeNotification( + HANDLE hChangeHandle + ) +{ + return FALSE; +} + + +/************************************************************************/ +WINBOOL +mfs_regexp(LPCWSTR lpFileName,LPCWSTR lpFilter) +{ + /* The following code is provided by Tarang and I trust him... + */ + LPWSTR lpTempFileName = (LPWSTR)lpFileName; + LPWSTR lpTempFilter = (LPWSTR)lpFilter; + WCHAR TempToken [ 2 ]; + WCHAR TempFilter [ 2 ]; + WINBOOL Matched = FALSE; + + if ( ( ! (LPWSTR)lpFileName ) || ( ! *(LPWSTR)lpFileName ) || + ( ! (LPWSTR)lpFilter ) || ( ! *(LPWSTR)lpFilter ) ) + return 0L; + + if ( ! lstrcmpW ( ( LPSTR )lpFilter, "*.*" ) ) + { + wsprintf ( TempFilter, "*" ); + lpTempFilter = TempFilter; + lpFilter = TempFilter; + } + + while ( ( lpTempFilter ) && ( *lpTempFilter ) && ( ! Matched ) ) + { + memset ( TempToken, 0, sizeof ( TempToken ) ); + switch ( *lpTempFilter ) + { + default: + if ( wcharicmp ( *lpTempFileName, *lpTempFilter ) ) + { + lpTempFileName = (LPWSTR)lpFileName; + lpTempFilter = wcspbrk ( lpTempFilter, L" ,;" ); + if ( lpTempFilter ) + lpTempFilter+=sizeof(WCHAR); + } + else + { + lpTempFilter+=sizeof(WCHAR); + lpTempFileName+=sizeof(WCHAR); + switch ( *lpTempFilter ) + { + default: + break; + + case L'\0': + case L' ': + case L',': + case L';': + if ( ! *lpTempFileName ) + Matched = TRUE; + break; + } + } + break; + + case L'?': + lpTempFilter+=sizeof(WCHAR); + lpTempFileName+=sizeof(WCHAR); + break; + + case L'*': + lpTempFilter += sizeof(WCHAR); + if ( ! ( TempToken [ 0 ] = *( lpTempFilter ) ) ) + Matched = TRUE; + else + { + lpTempFilter+=sizeof(WCHAR); + while ( ( lpTempFileName = wcspbrk ( lpTempFileName, TempToken ) ) && + ( ! Matched ) ) { + lpTempFileName+= sizeof(WCHAR); + Matched = mfs_regexp ( lpTempFileName, lpTempFilter ); + } + if ( ( ! lpTempFileName ) && ( ! Matched ) ) + { + lpTempFileName = (LPWSTR)lpFileName; + lpTempFilter = wcspbrk ( lpTempFilter, L" ,;" ); + if ( lpTempFilter ) + lpTempFilter+=sizeof(WCHAR); + } + } + break; + + case L'\0': + case L' ': + case L',': + case L';': + Matched = TRUE; + break; + } + } + + return (DWORD)Matched; + + +} + +int wcharicmp ( WCHAR char1, WCHAR char2 ) +{ + WCHAR Char1 = ( L'a' <= char1 ) && ( char1 <= L'z' ) ? + char1 - L'a' + L'A' : char1; + WCHAR Char2 = ( L'a' <= char2 ) && ( char2 <= L'z' ) ? + char2 - L'a' + L'A' : char2; + return ( Char2 - Char1 ); +} + + + + + + + + + + + + diff --git a/reactos/lib/kernel32/file/iocompl.c b/reactos/lib/kernel32/file/iocompl.c new file mode 100644 index 00000000000..b272f14c86a --- /dev/null +++ b/reactos/lib/kernel32/file/iocompl.c @@ -0,0 +1,149 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/file/iocompl.c + * PURPOSE: Io Completion functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ + +#include +#include +#include +#include + + +typedef struct _FILE_COMPLETION_INFORMATION { + HANDLE CompletionPort; + ULONG CompletionKey; +} FILE_COMPLETION_INFORMATION; +typedef FILE_COMPLETION_INFORMATION *PFILE_COMPLETION_INFORMATION; + + +VOID +STDCALL +FileIOCompletionRoutine( + DWORD dwErrorCode, + DWORD dwNumberOfBytesTransfered, + LPOVERLAPPED lpOverlapped + ); + + +HANDLE +STDCALL +CreateIoCompletionPort( + HANDLE FileHandle, + HANDLE ExistingCompletionPort, + DWORD CompletionKey, + DWORD NumberOfConcurrentThreads + ) +{ + HANDLE CompletionPort = NULL; + NTSTATUS errCode; + FILE_COMPLETION_INFORMATION CompletionInformation; + IO_STATUS_BLOCK IoStatusBlock; + + if ( ExistingCompletionPort == NULL && FileHandle == INVALID_HANDLE_VALUE ) { + SetLastError(RtlNtStatusToDosError(STATUS_INVALID_PARAMETER)); + return FALSE; + } + + if ( ExistingCompletionPort != NULL ) { + CompletionPort = ExistingCompletionPort; + } + else { + errCode = NtCreateIoCompletion(&CompletionPort,GENERIC_ALL,&IoStatusBlock,NumberOfConcurrentThreads); + if (!NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + } + if ( FileHandle != INVALID_HANDLE_VALUE ) { + + CompletionInformation.CompletionPort = CompletionPort; + CompletionInformation.CompletionKey = CompletionKey; + + errCode = NtSetInformationFile(FileHandle, &IoStatusBlock,&CompletionInformation,sizeof(FILE_COMPLETION_INFORMATION),FileCompletionInformation); + if ( !NT_SUCCESS(errCode) ) { + if ( ExistingCompletionPort == NULL ) + NtClose(CompletionPort); + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + } + + return CompletionPort; +} + + + +WINBOOL +STDCALL +GetQueuedCompletionStatus( + HANDLE CompletionPort, + LPDWORD lpNumberOfBytesTransferred, + LPDWORD lpCompletionKey, + LPOVERLAPPED *lpOverlapped, + DWORD dwMilliseconds + ) +{ + + NTSTATUS errCode; + ULONG CompletionStatus; + LARGE_INTEGER TimeToWait; + + errCode = NtRemoveIoCompletion(CompletionPort,(PULONG)lpCompletionKey,(PIO_STATUS_BLOCK)lpOverlapped,&CompletionStatus,&TimeToWait); + if (!NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + return TRUE; + +} + + + +WINBOOL +STDCALL +PostQueuedCompletionStatus( + HANDLE CompletionPort, + DWORD dwNumberOfBytesTransferred, + DWORD dwCompletionKey, + LPOVERLAPPED lpOverlapped +) +{ + + NTSTATUS errCode; + errCode = NtSetIoCompletion(CompletionPort, dwCompletionKey, (PIO_STATUS_BLOCK)lpOverlapped , 0, (PULONG)&dwNumberOfBytesTransferred ); + + + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + + +// this should be a place holder ?????????????????? +VOID +STDCALL +FileIOCompletionRoutine( + DWORD dwErrorCode, + DWORD dwNumberOfBytesTransfered, + LPOVERLAPPED lpOverlapped + ) +{ + return; +} + + + + + + + + diff --git a/reactos/lib/kernel32/file/lfile.c b/reactos/lib/kernel32/file/lfile.c index 4a98c4b06cb..fa02d642977 100644 --- a/reactos/lib/kernel32/file/lfile.c +++ b/reactos/lib/kernel32/file/lfile.c @@ -1,15 +1,18 @@ /* -* created: Boudewijn Dekker -* org. source: WINE -* date: june 1998 -* todo: check the _lopen for correctness -*/ + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/file/lfile.c + * PURPOSE: Find functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ #undef WIN32_LEAN_AND_MEAN #include #include #include -#include + @@ -20,7 +23,7 @@ long _hread( ) { DWORD NumberOfBytesRead; - if ( ReadFile((HANDLE)hFile,(LPCVOID)lpBuffer,(DWORD)lBytes,&NumberOfBytesRead, NULL) == FALSE ) + if ( ReadFile((HANDLE)hFile,(LPVOID)lpBuffer,(DWORD)lBytes,&NumberOfBytesRead, NULL) == FALSE ) return -1; else return NumberOfBytesRead; @@ -47,7 +50,7 @@ long _hwrite( else return 0; } - if ( WriteFile((HANDLE)hFile,(LPCVOID)lpBuffer,(DWORD)lBytes, &NumberOfBytesWritten,NULL) == FALSE ) + if ( WriteFile((HANDLE)hFile,(LPVOID)lpBuffer,(DWORD)lBytes, &NumberOfBytesWritten,NULL) == FALSE ) return -1; else return NumberOfBytesWritten; @@ -65,55 +68,65 @@ _lwrite( return _hwrite(hFile,lpBuffer,uBytes); } -#define OF_OPENMASK (OF_READ|OF_READWRITE|OF_WRITE|OF_CREATE) -#define OF_FILEMASK (OF_DELETE|OF_PARSE) -#define OF_MASK (OF_OPENMASK|OF_FILEMASK) -HFILE _open( LPCSTR lpPathName, int iReadWrite ) + + + +HFILE _lopen( LPCSTR lpPathName, int iReadWrite ) { - HFILE fd; - int nFunction; + DWORD dwAccessMask = 0; + DWORD dwShareMode = 0; + if ( (iReadWrite & OF_READWRITE ) == OF_READWRITE ) + dwAccessMask = GENERIC_READ | GENERIC_WRITE; + else if ( (iReadWrite & OF_READ ) == OF_READ ) + dwAccessMask = GENERIC_READ; + else if ( (iReadWrite & OF_WRITE ) == OF_WRITE ) + dwAccessMask = GENERIC_WRITE; - - /* Don't assume a 1:1 relationship between OF_* modes and O_* modes */ - /* Here we translate the read/write permission bits (which had better */ - /* be the low 2 bits. If not, we're in trouble. Other bits are */ - /* passed through unchanged */ + + + +if ((iReadWrite & OF_SHARE_COMPAT) == OF_SHARE_COMPAT ) + dwShareMode = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE; +else if ((iReadWrite & OF_SHARE_DENY_NONE) == OF_SHARE_DENY_NONE) + dwShareMode = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE; +else if ((iReadWrite & OF_SHARE_DENY_READ) == OF_SHARE_DENY_READ) + dwShareMode = FILE_SHARE_WRITE | FILE_SHARE_DELETE; +else if ((iReadWrite & OF_SHARE_DENY_WRITE) == OF_SHARE_DENY_WRITE ) + dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE; +else if ((iReadWrite & OF_SHARE_EXCLUSIVE) == OF_SHARE_EXCLUSIVE) + dwShareMode = 0; + - nFunction = wFunction & 3; - - switch (wFunction & 3) { - case OF_READ: - nFunction |= O_RDONLY; - break; - case OF_READWRITE: - nFunction |= O_RDWR; - break; - case OF_WRITE: - nFunction |= O_WRONLY; - break; - default: - //ERRSTR((LF_ERROR, "_lopen: bad file open mode %x\n", wFunction)); - return HFILE_ERROR; - } + SetLastError(0); - fd = CreateFileA( filename,nFunction,OPEN_EXISTING, - NULL,OPEN_EXISTING,NULL,NULL); - if (fd == INVALID_HANDLE_VALUE ) - return HFILE_ERROR; - return fd; + return (HFILE) CreateFileA( lpPathName,dwAccessMask,dwShareMode, + NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); + } -int _creat(const char *filename, int pmode) + +HFILE _lcreat( LPCSTR lpPathName, int iAttribute ) { - SetLastError(0); - return CreateFileA( filename,GENERIC_READ & GENERIC_WRITE,FILE_SHARE_WRITE, - NULL,CREATE_ALWAYS,pmode & 0x00003FB7,NULL); + + DWORD FileAttributes = 0; + + if ( iAttribute == 1 ) + FileAttributes |= FILE_ATTRIBUTE_NORMAL; + else if ( iAttribute == 2 ) + FileAttributes |= FILE_ATTRIBUTE_READONLY; + else if ( iAttribute == 3 ) + FileAttributes |= FILE_ATTRIBUTE_HIDDEN; + else if ( iAttribute == 4 ) + FileAttributes |= FILE_ATTRIBUTE_SYSTEM; + + return(HFILE) CreateFileA( lpPathName,GENERIC_ALL,FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL,CREATE_ALWAYS,iAttribute ,NULL); } diff --git a/reactos/lib/kernel32/file/volume.c b/reactos/lib/kernel32/file/volume.c new file mode 100644 index 00000000000..520d3a7b576 --- /dev/null +++ b/reactos/lib/kernel32/file/volume.c @@ -0,0 +1,273 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/file/volume.c + * PURPOSE: File volume functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ +#undef WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include + +DWORD +STDCALL +GetLogicalDrives(VOID) +{ + return (DWORD)-1; +} + +DWORD +STDCALL +GetLogicalDriveStringsA( + DWORD nBufferLength, + LPSTR lpBuffer + ) +{ +} + +DWORD +STDCALL +GetLogicalDriveStringsW( + DWORD nBufferLength, + LPWSTR lpBuffer + ) +{ +} + +WINBOOL +STDCALL +GetDiskFreeSpaceA( + LPCSTR lpRootPathName, + LPDWORD lpSectorsPerCluster, + LPDWORD lpBytesPerSector, + LPDWORD lpNumberOfFreeClusters, + LPDWORD lpTotalNumberOfClusters + ) +{ + ULONG i; + WCHAR RootPathNameW[MAX_PATH]; + i = 0; + while ((*lpRootPathName)!=0 && i < MAX_PATH) + { + RootPathNameW[i] = *lpRootPathName; + lpRootPathName++; + i++; + } + RootPathNameW[i] = 0; + return GetDiskFreeSpaceW(RootPathNameW,lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters ); +} + +WINBOOL +STDCALL +GetDiskFreeSpaceW( + LPCWSTR lpRootPathName, + LPDWORD lpSectorsPerCluster, + LPDWORD lpBytesPerSector, + LPDWORD lpNumberOfFreeClusters, + LPDWORD lpTotalNumberOfClusters + ) +{ + FILE_FS_SIZE_INFORMATION FileFsSize; + IO_STATUS_BLOCK IoStatusBlock; + HANDLE hFile; + NTSTATUS errCode; + + hFile = CreateFileW( + lpRootPathName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL + ); + + errCode = NtQueryVolumeInformationFile(hFile,&IoStatusBlock,&FileFsSize, sizeof(FILE_FS_SIZE_INFORMATION),FileFsSizeInformation); + if ( !NT_SUCCESS(errCode) ) { + CloseHandle(hFile); + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + memcpy(lpBytesPerSector,&FileFsSize.BytesPerSector,sizeof(DWORD));; + memcpy(lpSectorsPerCluster,&FileFsSize.SectorsPerAllocationUnit,sizeof(DWORD)); + memcpy(lpNumberOfFreeClusters,&GET_LARGE_INTEGER_LOW_PART(FileFsSize.AvailableAllocationUnits),sizeof(DWORD)); + memcpy(lpTotalNumberOfClusters,&GET_LARGE_INTEGER_LOW_PART(FileFsSize.TotalAllocationUnits),sizeof(DWORD)); + CloseHandle(hFile); + return TRUE; +} + +UINT +STDCALL +GetDriveTypeA( + LPCSTR lpRootPathName + ) +{ + ULONG i; + WCHAR RootPathNameW[MAX_PATH]; + i = 0; + while ((*lpRootPathName)!=0 && i < MAX_PATH) + { + RootPathNameW[i] = *lpRootPathName; + lpRootPathName++; + i++; + } + RootPathNameW[i] = 0; + return GetDriveTypeW(RootPathNameW); +} + +UINT +STDCALL +GetDriveTypeW( + LPCWSTR lpRootPathName + ) +{ + FILE_FS_DEVICE_INFORMATION FileFsDevice; + IO_STATUS_BLOCK IoStatusBlock; + + HANDLE hFile; + NTSTATUS errCode; + + hFile = CreateFileW( + lpRootPathName, + GENERIC_ALL, + FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL + ); + + errCode = NtQueryVolumeInformationFile(hFile,&IoStatusBlock,&FileFsDevice, sizeof(FILE_FS_DEVICE_INFORMATION),FileFsDeviceInformation); + if ( !NT_SUCCESS(errCode) ) { + CloseHandle(hFile); + SetLastError(RtlNtStatusToDosError(errCode)); + return 0; + } + CloseHandle(hFile); + return (UINT)FileFsDevice.DeviceType; + + + +} + +WINBOOL +STDCALL +GetVolumeInformationA( + LPCSTR lpRootPathName, + LPSTR lpVolumeNameBuffer, + DWORD nVolumeNameSize, + LPDWORD lpVolumeSerialNumber, + LPDWORD lpMaximumComponentLength, + LPDWORD lpFileSystemFlags, + LPSTR lpFileSystemNameBuffer, + DWORD nFileSystemNameSize + ) +{ + ULONG i; + WCHAR RootPathNameW[MAX_PATH]; + WCHAR VolumeNameBufferW[MAX_PATH]; + WCHAR FileSystemNameBufferW[MAX_PATH]; + + + i = 0; + while ((*lpRootPathName)!=0 && i < MAX_PATH) + { + RootPathNameW[i] = *lpRootPathName; + lpRootPathName++; + i++; + } + RootPathNameW[i] = 0; + + if ( GetVolumeInformationW(RootPathNameW, + VolumeNameBufferW, + nVolumeNameSize, + lpVolumeSerialNumber, + lpMaximumComponentLength, + lpFileSystemFlags, + FileSystemNameBufferW, + nFileSystemNameSize ) ) { + for(i=0;iVolumeSerialNumber, sizeof(DWORD)); + memcpy(lpVolumeNameBuffer, FileFsVolume->VolumeLabel,min(nVolumeNameSize,MAX_PATH)); + + errCode = NtQueryVolumeInformationFile(hFile,&IoStatusBlock,FileFsAttribute, FS_ATTRIBUTE_BUFFER_SIZE,FileFsAttributeInformation); + if ( !NT_SUCCESS(errCode) ) { + CloseHandle(hFile); + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + memcpy(lpFileSystemFlags,&FileFsAttribute->FileSystemAttributes,sizeof(DWORD)); + memcpy(lpMaximumComponentLength, &FileFsAttribute->MaximumComponentNameLength, sizeof(DWORD)); + memcpy(lpFileSystemNameBuffer, FileFsAttribute->FileSystemName,min(nFileSystemNameSize,MAX_PATH)); + CloseHandle(hFile); + return TRUE; + +} + diff --git a/reactos/lib/kernel32/internal/dprintf.c b/reactos/lib/kernel32/internal/dprintf.c index 3886b2cf355..705ff845d06 100644 --- a/reactos/lib/kernel32/internal/dprintf.c +++ b/reactos/lib/kernel32/internal/dprintf.c @@ -1,9 +1,42 @@ #include +#include #include VOID STDCALL OutputDebugStringA(LPCSTR lpOutputString) { - NtDisplayString(lpOutputString); + WCHAR DebugStringW[161]; + int i,j; + i = 0; + j = 0; + while ( lpOutputString[i] != 0 ) + { + while ( j < 160 && lpOutputString[i] != 0 ) + { + DebugStringW[j] = (WCHAR)lpOutputString[i]; + i++; + j++; + } + DebugStringW[j] = 0; + OutputDebugStringW(DebugStringW); + j = 0; + } + + return; +} + +VOID +STDCALL +OutputDebugStringW( + LPCWSTR lpOutputString + ) +{ + UNICODE_STRING UnicodeOutput; + + UnicodeOutput.Buffer = (WCHAR *)lpOutputString; + UnicodeOutput.Length = lstrlenW(lpOutputString)*sizeof(WCHAR); + UnicodeOutput.MaximumLength = UnicodeOutput.Length; + + NtDisplayString(&UnicodeOutput); } void dprintf(char* fmt, ...) diff --git a/reactos/lib/kernel32/internal/vsprintf.c b/reactos/lib/kernel32/internal/vsprintf.c index c8039b03f72..e1ef386667a 100644 --- a/reactos/lib/kernel32/internal/vsprintf.c +++ b/reactos/lib/kernel32/internal/vsprintf.c @@ -338,3 +338,42 @@ int sprintf(char * buf, const char *fmt, ...) return i; } +int wsprintfA(char * buf, const char *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + i=vsprintf(buf,fmt,args); + va_end(args); + return i; +} + +int wsprintfW(unsigned short * buf, const unsigned short *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + //i=vsprintf(buf,fmt,args); + va_end(args); + return i; +} + + +unsigned short towupper(unsigned short w) +{ + if ( w < L'A' ) + return w + 'A'; + else + return w; +} + +char iswlower(unsigned short w) +{ + if ( w < L'A' ) + return 1; + else + return 0; +} + diff --git a/reactos/lib/kernel32/kernel32.def b/reactos/lib/kernel32/kernel32.def index 78ba330d391..5aa62feec47 100644 --- a/reactos/lib/kernel32/kernel32.def +++ b/reactos/lib/kernel32/kernel32.def @@ -330,7 +330,6 @@ GetTempFileNameW@16 GetTempPathA@8 GetTempPathW@8 GetThreadContext@8 -_imp__GetThreadContext@8 GetThreadLocale@0 GetThreadPriority@4 GetThreadSelectorEntry@12 diff --git a/reactos/lib/kernel32/makefile b/reactos/lib/kernel32/makefile index 349acf004c4..9b82017699e 100644 --- a/reactos/lib/kernel32/makefile +++ b/reactos/lib/kernel32/makefile @@ -1,16 +1,14 @@ all: kernel32.a -SYNCH_OBJECTS = synch/critical.o +SYNCH_OBJECTS = synch/critical.o synch/event.o synch/wait.o -#MISC_OBJECTS = misc/atom.o -MISC_OBJECTS = misc/error.o +MISC_OBJECTS = misc/error.o misc/atom.o misc/handle.o misc/env.o misc/dllmain.o -#FILE_OBJECTS = file/file.o file/lfile.o -FILE_OBJECTS = file/file.o file/curdir.o +FILE_OBJECTS = file/file.o file/curdir.o file/lfile.o file/dir.o file/iocompl.o file/volume.o file/deviceio.o file/dosdev.o MEM_OBJECTS = mem/virtual.o mem/heap.o mem/utils.o -#THREAD_OBJECTS = thread/thread.o +THREAD_OBJECTS = thread/thread.o PROCESS_OBJECTS = process/proc.o @@ -18,9 +16,14 @@ STRING_OBJECTS = string/lstring.o INTERNAL_OBJECTS = internal/dprintf.o internal/vsprintf.o +EXCEPT_OBJECTS = except/except.o + + + + OBJECTS = $(MISC_OBJECTS) $(FILE_OBJECTS) $(THREAD_OBJECTS) \ $(PROCESS_OBJECTS) $(STRING_OBJECTS) $(MEM_OBJECTS) \ - $(INTERNAL_OBJECTS) $(SYNCH_OBJECTS) + $(INTERNAL_OBJECTS) $(SYNCH_OBJECTS) $(EXCEPT_OBJECTS) kernel32.a: $(OBJECTS) diff --git a/reactos/lib/kernel32/mem/global.c b/reactos/lib/kernel32/mem/global.c index cec05c9b816..216a4dce0e1 100644 --- a/reactos/lib/kernel32/mem/global.c +++ b/reactos/lib/kernel32/mem/global.c @@ -156,7 +156,7 @@ HGLOBAL WINAPI GlobalReAlloc(HGLOBAL hmem, DWORD size, UINT flags) palloc=GlobalLock(hnew); memcpy(palloc, (LPVOID) hmem, size); GlobalUnlock(hnew); - GlobalFree(hmem); + GlobalHeapFree(GetProcessHeap(),0,hmem); } else if((((ULONG)hmem%8) != 0)&&(flags & GMEM_DISCARDABLE)) { @@ -205,7 +205,7 @@ HGLOBAL WINAPI GlobalReAlloc(HGLOBAL hmem, DWORD size, UINT flags) { if(phandle->Pointer) { - HeapFree(__ProcessHeap, 0, phandle->Pointer-sizeof(HANDLE)); + HeapHeapFree(GetProcessHeap(),0,__ProcessHeap, 0, phandle->Pointer-sizeof(HANDLE)); phandle->Pointer=NULL; } } @@ -218,15 +218,15 @@ HGLOBAL WINAPI GlobalReAlloc(HGLOBAL hmem, DWORD size, UINT flags) /********************************************************************* * GlobalFree -- KERNEL32 * *********************************************************************/ -HGLOBAL WINAPI GlobalFree(HGLOBAL hmem) +HGLOBAL WINAPI GlobalHeapFree(GetProcessHeap(),0,HGLOBAL hmem) { PGLOBAL_HANDLE phandle; - aprintf("GlobalFree( 0x%lX )\n", (ULONG) hmem ); + aprintf("GlobalHeapFree(GetProcessHeap(),0, 0x%lX )\n", (ULONG) hmem ); if(((ULONG)hmem%4)==0) /* POINTER */ { - HeapFree(__ProcessHeap, 0, (LPVOID) hmem); + HeapHeapFree(GetProcessHeap(),0,__ProcessHeap, 0, (LPVOID) hmem); } else /* HANDLE */ { @@ -238,7 +238,7 @@ HGLOBAL WINAPI GlobalFree(HGLOBAL hmem) if(phandle->LockCount!=0) SetLastError(ERROR_INVALID_HANDLE); if(phandle->Pointer) - HeapFree(__ProcessHeap, 0, phandle->Pointer-sizeof(HANDLE)); + HeapHeapFree(GetProcessHeap(),0,__ProcessHeap, 0, phandle->Pointer-sizeof(HANDLE)); __HeapFreeFragment(__ProcessHeap, 0, phandle); } HeapUnlock(__ProcessHeap); diff --git a/reactos/lib/kernel32/mem/heap.c b/reactos/lib/kernel32/mem/heap.c index b310344135a..61acdab5c9e 100644 --- a/reactos/lib/kernel32/mem/heap.c +++ b/reactos/lib/kernel32/mem/heap.c @@ -26,10 +26,12 @@ * Put the type definitions of the heap in a seperate header. Boudewijn Dekker */ +#include #include #include #include + static HEAP_BUCKET __HeapDefaultBuckets[]= { { NULL, 16, 18, 504 }, @@ -773,7 +775,7 @@ DWORD WINAPI GetProcessHeaps(DWORD maxheaps, PHANDLE phandles ) aprintf("GetProcessHeaps( %u, 0x%lX )\n", maxheaps, (ULONG) phandles ); - pheap=__ProcessHeap; + pheap= __ProcessHeap; retval=0; while((pheap)&&(maxheaps)) { diff --git a/reactos/lib/kernel32/mem/local.c b/reactos/lib/kernel32/mem/local.c index da2641d9800..58d813e4929 100644 --- a/reactos/lib/kernel32/mem/local.c +++ b/reactos/lib/kernel32/mem/local.c @@ -101,9 +101,9 @@ HLOCAL WINAPI LocalReAlloc(HLOCAL hmem, UINT size, UINT flags) /********************************************************************* * LocalFree -- KERNEL32 * *********************************************************************/ -HLOCAL WINAPI LocalFree(HLOCAL hmem) +HLOCAL WINAPI LocalHeapFree(GetProcessHeap(),0,HLOCAL hmem) { - return (HLOCAL) GlobalFree( (HGLOBAL) hmem ); + return (HLOCAL) GlobalHeapFree(GetProcessHeap(),0, (HGLOBAL) hmem ); } /********************************************************************* diff --git a/reactos/lib/kernel32/mem/virtual.c b/reactos/lib/kernel32/mem/virtual.c index 606036c718e..205a9189de4 100644 --- a/reactos/lib/kernel32/mem/virtual.c +++ b/reactos/lib/kernel32/mem/virtual.c @@ -22,13 +22,14 @@ LPVOID STDCALL VirtualAllocEx(HANDLE hProcess, NTSTATUS Status; Status = ZwAllocateVirtualMemory(hProcess, - &lpAddress, + (PVOID *)&lpAddress, 0, - dwSize, + (PULONG)&dwSize, flAllocationType, flProtect); - if (Status != STATUS_SUCCESS) + if (!NT_SUCCESS(Status)) { + SetLastError(RtlNtStatusToDosError(Status)); return(NULL); } return(lpAddress); @@ -51,11 +52,12 @@ WINBOOL STDCALL VirtualFreeEx(HANDLE hProcess, NTSTATUS Status; Status = ZwFreeVirtualMemory(hProcess, - &lpAddress, - dwSize, + (PVOID *)&lpAddress, + (PULONG)&dwSize, dwFreeType); - if (Status != STATUS_SUCCESS) + if (!NT_SUCCESS(Status)) { + SetLastError(RtlNtStatusToDosError(Status)); return(FALSE); } return(TRUE); @@ -88,12 +90,13 @@ WINBOOL STDCALL VirtualProtectEx(HANDLE hProcess, NTSTATUS Status; Status = ZwProtectVirtualMemory(hProcess, - lpAddress, - dwSize, + (PVOID)lpAddress, + (PULONG)dwSize, flNewProtect, lpflOldProtect); if (Status != STATUS_SUCCESS) { + SetLastError(RtlNtStatusToDosError(Status)); return(FALSE); } return(TRUE); diff --git a/reactos/lib/kernel32/misc/atom.c b/reactos/lib/kernel32/misc/atom.c index c8d9d163bdc..809c2052ee8 100644 --- a/reactos/lib/kernel32/misc/atom.c +++ b/reactos/lib/kernel32/misc/atom.c @@ -1,23 +1,24 @@ - - -#include -#include -#include -#include - - /* - title: atom.c - author: Boudewijn Dekker - hsitory:copied from twin wine source - modified: -- add wide char support - -- removed ex functions - -- use a per process local atom table - todo : - check initatomtable - check if not calling down to ntdll conflicts with anything - check anis2unicode procedure -*/ + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/misc/atom.c + * PURPOSE: Atom functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + modified from WINE [ Onno Hovers, (onno@stack.urc.tue.nl) ] + * UPDATE HISTORY: + * Created 01/11/98 + */ + +#include +#include +#include +#include +#include +#include + + + + /* system global and local atom tables */ @@ -26,15 +27,17 @@ static ATOMTABLE GlobalAtomTable; /* internal functions */ ATOM GLDeleteAtom(ATOMTABLE *at, ATOM nAtom); -ATOM AWGLAddAtom( ATOMTABLE *at, const wchar_t *lpString); -ATOM AWGLFindAtom(ATOMTABLE *at, const wchar_t *lpString); -UINT AWGLGetAtomName(ATOMTABLE *at,ATOM atom, wchar_t *lpString, int nSize); +ATOM AWGLAddAtom( ATOMTABLE *at, const WCHAR *lpString); +ATOM AWGLFindAtom(ATOMTABLE *at, const WCHAR *lpString); +UINT AWGLGetAtomName(ATOMTABLE *at,ATOM atom, WCHAR *lpString, int nSize); static ATOMENTRY *GetAtomPointer(ATOMTABLE *,int); -static ATOMID AtomHashString(const wchar_t *,int *); +static ATOMID AtomHashString(const WCHAR *,int *); #define ATOMBASE 0xcc00 +int unicode2ansi( char *ansi,const WCHAR *uni, int s); +int ansi2unicode( WCHAR *uni,const char *ansi, int s); ATOM @@ -58,13 +61,12 @@ InitAtomTable( if ( nSize < 4 || nSize >= 512 ) { nSize = 37; } - /* - if ( GetTeb()->pPeb->LocalAtomTable == NULL ) { - GetTeb()->pPeb->LocalAtomTable = (ATOMTABLE *)malloc(nSize*sizeof(ATOMTABLE)); + + if ( (GetCurrentPeb()->LocalAtomTable).lpDrvData == NULL ) { + (GetCurrentPeb()->LocalAtomTable).lpDrvData = HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,nSize*sizeof(ATOMENTRY)); } - GetTeb()->pPeb->LocalAtomTable->TableSize = nSize; - */ + return TRUE; } @@ -75,7 +77,7 @@ DeleteAtom( ATOM nAtom ) { - return GLDeleteAtom(&GetTeb()->pPeb->LocalAtomTable, nAtom); + return GLDeleteAtom(&GetCurrentPeb()->LocalAtomTable, nAtom); } @@ -85,16 +87,16 @@ DeleteAtom( ATOM STDCALL GlobalAddAtomA( - const char *lpString + LPCSTR lpString ) { UINT BufLen = strlen(lpString); - wchar_t *lpBuffer = (wchar_t *)malloc(BufLen*sizeof(wchar_t)); + WCHAR *lpBuffer = (WCHAR *)HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,BufLen*sizeof(WCHAR)); ATOM atom; ansi2unicode(lpBuffer, lpString,BufLen); atom = AWGLAddAtom(&GlobalAtomTable,lpBuffer ); - free(lpBuffer); + HeapFree(GetProcessHeap(),0,lpBuffer); return atom; } @@ -105,7 +107,7 @@ GlobalAddAtomA( ATOM STDCALL GlobalAddAtomW( - const wchar_t *lpString + LPCWSTR lpString ) { return AWGLAddAtom(&GlobalAtomTable, lpString); @@ -115,15 +117,15 @@ GlobalAddAtomW( ATOM STDCALL GlobalFindAtomA( - const char *lpString + LPCSTR lpString ) { ATOM a; UINT BufLen = strlen(lpString); - wchar_t *lpBuffer = (wchar_t *)malloc(BufLen*sizeof(wchar_t)); + WCHAR *lpBuffer = (WCHAR *)HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,BufLen*sizeof(WCHAR)); ansi2unicode(lpBuffer, lpString,BufLen); a = AWGLFindAtom(&GlobalAtomTable, lpBuffer); - free(lpBuffer); + HeapFree(GetProcessHeap(),0,lpBuffer); return a; } @@ -131,7 +133,7 @@ GlobalFindAtomA( ATOM STDCALL GlobalFindAtomW( - const wchar_t *lpString + const WCHAR *lpString ) { return AWGLFindAtom(&GlobalAtomTable, lpString); @@ -148,10 +150,10 @@ GlobalGetAtomNameA( ) { - wchar_t *lpUnicode = (wchar_t *)malloc(nSize *sizeof(wchar_t)); + WCHAR *lpUnicode = (WCHAR *)HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,nSize *sizeof(WCHAR)); UINT x = AWGLGetAtomName(&GlobalAtomTable,nAtom, lpUnicode,nSize); unicode2ansi(lpBuffer,lpUnicode,nSize); - free(lpUnicode); + HeapFree(GetProcessHeap(),0,lpUnicode); return x; } @@ -160,7 +162,7 @@ UINT STDCALL GlobalGetAtomNameW( ATOM nAtom, - wchar_t * lpBuffer, + WCHAR * lpBuffer, int nSize ) { @@ -175,11 +177,11 @@ AddAtomA( ) { UINT BufLen = strlen(lpString); - wchar_t *lpBuffer = (wchar_t*)malloc(BufLen*2); + WCHAR *lpBuffer = (WCHAR*)HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,BufLen*2); ATOM a; ansi2unicode(lpBuffer, lpString,BufLen); - a = AWGLAddAtom(&GetTeb()->pPeb->LocalAtomTable, lpBuffer); - free(lpBuffer); + a = AWGLAddAtom(&GetCurrentPeb()->LocalAtomTable, lpBuffer); + HeapFree(GetProcessHeap(),0,lpBuffer); return a; } @@ -188,10 +190,10 @@ AddAtomA( ATOM STDCALL AddAtomW( - const wchar_t * lpString + const WCHAR * lpString ) { - return AWGLAddAtom(&GetTeb()->pPeb->LocalAtomTable, lpString); + return AWGLAddAtom(&GetCurrentPeb()->LocalAtomTable, lpString); } @@ -204,11 +206,11 @@ FindAtomA( ) { UINT BufLen = strlen(lpString); - wchar_t *lpBuffer = (wchar_t *)malloc(BufLen*2); + WCHAR *lpBuffer = (WCHAR *)HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,BufLen*2); ATOM a; ansi2unicode(lpBuffer, lpString,BufLen); - a = AWGLFindAtom(&GetTeb()->pPeb->LocalAtomTable, lpBuffer); - free(lpBuffer); + a = AWGLFindAtom(&GetCurrentPeb()->LocalAtomTable, lpBuffer); + HeapFree(GetProcessHeap(),0,lpBuffer); return a; } @@ -216,10 +218,10 @@ FindAtomA( ATOM STDCALL FindAtomW( - const wchar_t * lpString + const WCHAR * lpString ) { - return AWGLFindAtom(&GetTeb()->pPeb->LocalAtomTable, lpString); + return AWGLFindAtom(&GetCurrentPeb()->LocalAtomTable, lpString); } @@ -232,10 +234,10 @@ GetAtomNameA( int nSize ) { - LPWSTR lpUnicode = (wchar_t *)malloc(nSize *2); + LPWSTR lpUnicode = (WCHAR *)HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,nSize *2); UINT x = AWGLGetAtomName(&GlobalAtomTable, nAtom,lpUnicode,nSize); unicode2ansi(lpBuffer,lpUnicode,nSize); - free(lpUnicode); + HeapFree(GetProcessHeap(),0,lpUnicode); return x; } @@ -244,11 +246,11 @@ UINT STDCALL GetAtomNameW( ATOM nAtom, - wchar_t * lpBuffer, + WCHAR * lpBuffer, int nSize ) { - return AWGLGetAtomName(&GetTeb()->pPeb->LocalAtomTable,nAtom,lpBuffer, nSize); + return AWGLGetAtomName(&GetCurrentPeb()->LocalAtomTable,nAtom,lpBuffer, nSize); } ATOM @@ -265,9 +267,9 @@ GLDeleteAtom( lp->refcnt--; if(lp->refcnt == 0) { - free(at->AtomTable); + HeapFree(GetProcessHeap(),0,at->AtomTable); at->AtomTable = NULL; - free(at->AtomData); + HeapFree(GetProcessHeap(),0,at->AtomData); at->AtomData = NULL; return lp->q = 0; } @@ -281,7 +283,7 @@ GLDeleteAtom( ATOM AWGLAddAtom( - ATOMTABLE *at, const wchar_t *lpString + ATOMTABLE *at, const WCHAR *lpString ) { ATOM atom; @@ -329,13 +331,13 @@ AWGLAddAtom( /* no space was available, or we have an INTATOM */ /* so expand or create the table */ if(at->AtomTable == 0) { - at->AtomTable = (ATOMENTRY *) malloc(sizeof(ATOMENTRY)); + at->AtomTable = (ATOMENTRY *) HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,sizeof(ATOMENTRY)); at->TableSize = 1; lp = at->AtomTable; index = 0; } else { at->TableSize++; - at->AtomTable = (ATOMENTRY *) realloc( + at->AtomTable = (ATOMENTRY *) HeapReAlloc(GetProcessHeap(),0, (LPVOID) at->AtomTable, at->TableSize * sizeof(ATOMENTRY)); lp = &at->AtomTable[at->TableSize - 1]; @@ -352,15 +354,15 @@ AWGLAddAtom( newlen = at->DataSize + atomlen; if(at->AtomData == 0) { - at->AtomData = (wchar_t *) malloc(newlen*2); + at->AtomData = (WCHAR *) HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,newlen*2); lp->idx = 0; } else { - at->AtomData = (wchar_t *) realloc(at->AtomData,newlen*2); + at->AtomData = (WCHAR *) HeapReAlloc(GetProcessHeap(),0,at->AtomData,newlen*2); lp->idx = at->DataSize; } - wcscpy(&at->AtomData[lp->idx],lpString); + lstrcpyW(&at->AtomData[lp->idx],lpString); at->DataSize = newlen; } @@ -378,7 +380,7 @@ AWGLAddAtom( ATOM AWGLFindAtom( - ATOMTABLE *at, const wchar_t *lpString + ATOMTABLE *at, const WCHAR *lpString ) { @@ -408,11 +410,11 @@ AWGLFindAtom( UINT -AWGLGetAtomName(ATOMTABLE *at, ATOM atom, wchar_t *lpString,int len) +AWGLGetAtomName(ATOMTABLE *at, ATOM atom, WCHAR *lpString,int len) { ATOMENTRY *lp; - wchar_t *atomstr; + WCHAR *atomstr; int atomlen; @@ -420,17 +422,17 @@ AWGLGetAtomName(ATOMTABLE *at, ATOM atom, wchar_t *lpString,int len) /* return the atom name, or create the INTATOM */ if((lp = GetAtomPointer(at,atom - ATOMBASE))) { if(lp->idsize) { - atomlen = wcslen(atomstr = &at->AtomData[lp->idx]); + atomlen = lstrlenW(atomstr = &at->AtomData[lp->idx]); if (atomlen < len) - wcscpy(lpString,atomstr); + lstrcpyW(lpString,atomstr); else { wcsncpy(lpString,atomstr,len-1); lpString[len-1] = '\0'; } - return (UINT)wcslen(lpString); + return (UINT)lstrlenW(lpString); } else { //wsprintf((wchar *)lpString,"#%d",lp->q); - return (UINT)wcslen(lpString); + return (UINT)lstrlenW(lpString); } } return 0; @@ -444,10 +446,10 @@ AWGLGetAtomName(ATOMTABLE *at, ATOM atom, wchar_t *lpString,int len) /********************************************************/ static ATOMID -AtomHashString(const wchar_t * lp,int *lplen) +AtomHashString(const WCHAR * lp,int *lplen) { ATOMID q; - wchar_t *p,ch; + WCHAR *p,ch; int len; /* if we have an intatom... */ @@ -457,7 +459,7 @@ AtomHashString(const wchar_t * lp,int *lplen) } /* convert the string to an internal representation */ - for(p=(wchar_t *)lp,q=0,len=0;(p++,ch=*p++);len++) + for(p=(WCHAR *)lp,q=0,len=0;(p++,ch=*p++);len++) q = (q<<1) + iswlower(ch)?towupper(ch):ch; /* 0 is reserved for empty slots */ @@ -503,22 +505,22 @@ GetAtomPointer(ATOMTABLE *at,int index) return lp; } -int ansi2unicode( wchar_t *uni, char *ansi, int s) +int ansi2unicode( WCHAR *uni,const char *ansi, int s) { register int i; for(i=0;i<=s;i++) - uni[i] = (wchar_t)ansi[i]; - return; + uni[i] = (WCHAR)ansi[i]; + return i; } -int unicode2ansi( char *ansi, wchar_t *uni, int s) +int unicode2ansi( char *ansi,const WCHAR *uni, int s) { register int i; for(i=0;i<=s;i++) ansi[i] = (char)uni[i]; - return; + return i; } diff --git a/reactos/lib/kernel32/misc/dllmain.c b/reactos/lib/kernel32/misc/dllmain.c new file mode 100644 index 00000000000..7fcd1f5ea0d --- /dev/null +++ b/reactos/lib/kernel32/misc/dllmain.c @@ -0,0 +1,75 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/misc/dllmain.c + * PURPOSE: Initialization + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ + +#include +#include +#include + +WINBOOL +STDCALL +DllMain ( + HANDLE hInst, + ULONG ul_reason_for_call, + LPVOID lpReserved ); + + +NT_PEB Peb; + + + +NT_PEB *CurrentPeb; +NT_TEB *Teb; +PROCESSINFOW ProcessInfo; + + + +WINBOOL +STDCALL +DllMain ( + HANDLE hInst, + ULONG ul_reason_for_call, + LPVOID lpReserved ) +{ + switch( ul_reason_for_call ) { + case DLL_PROCESS_ATTACH: + { + CurrentPeb = &Peb; + CurrentPeb->ProcessHeap = HeapCreate(HEAP_GENERATE_EXCEPTIONS,8192,0); + InitAtomTable(13); + } + case DLL_THREAD_ATTACH: + { + Teb = HeapAlloc(GetProcessHeap(),0,sizeof(NT_TEB)); + Teb->Peb = GetCurrentPeb(); + Teb->HardErrorMode = SEM_NOGPFAULTERRORBOX; + Teb->dwTlsIndex=0; + break; + } + case DLL_PROCESS_DETACH: + { + HeapFree(GetProcessHeap(),0,Teb); + HeapDestroy(GetCurrentPeb()->ProcessHeap); + break; + } + case DLL_THREAD_DETACH: + { + HeapFree(GetProcessHeap(),0,Teb); + break; + } + default: + break; + + } + return TRUE; + +} + + + diff --git a/reactos/lib/kernel32/misc/env.c b/reactos/lib/kernel32/misc/env.c new file mode 100644 index 00000000000..77a6e523a18 --- /dev/null +++ b/reactos/lib/kernel32/misc/env.c @@ -0,0 +1,161 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/misc/env.c + * PURPOSE: Environment functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ + +#include +#include +#include +#include + +#define MAX_ENVIRONMENT_VARS 255 + +typedef struct _ENV_ELEMENT +{ + UNICODE_STRING Name; + UNICODE_STRING Value; +} ENV_ELEMENT; + +ENV_ELEMENT Environment[MAX_ENVIRONMENT_VARS+1]; +UINT nEnvVar = 0; + +int wcsncmp2(CONST WCHAR *s, CONST WCHAR *t,UINT n); + +DWORD +STDCALL +GetEnvironmentVariableW( + LPCWSTR lpName, + LPWSTR lpBuffer, + DWORD nSize + ) +{ + UINT NameLen; + UINT i; + NameLen = lstrlenW(lpName); + i = 0; + + while (i < nEnvVar) + { + if ( wcsncmp2(Environment[i].Name.Buffer,lpName,min(NameLen,Environment[i].Name.Length)) != 0 ) { + lstrcpynW(lpBuffer,Environment[i].Value.Buffer,min(nSize,Environment[i].Value.Length)); + + return lstrlenW(lpBuffer); + + } + i++; + } + return 0; + +} + + +int wcsncmp2(CONST WCHAR *s, CONST WCHAR *t,UINT n) +{ + for(;towupper(*s) == towupper(*t) && n > 0; s++, t++, n--) + if ( *s == 0 ) + return 0; + return *s - *t; +} + + +WINBOOL +STDCALL +SetEnvironmentVariableW( + LPCWSTR lpName, + LPCWSTR lpValue + ) +{ + UINT NameLen, ValueLen; + UINT i; + WCHAR *NameBuffer; + WCHAR *ValueBuffer; + NameLen = lstrlenW(lpName); + ValueLen = lstrlenW(lpValue); + i = 0; + + while (i < nEnvVar) + { + if ( wcsncmp2(Environment[i].Name.Buffer,lpName,min(NameLen,Environment[i].Name.Length)) != 0 ) { + lstrcpynW(Environment[i].Value.Buffer,lpValue,min(ValueLen,Environment[i].Value.MaximumLength)); + return TRUE; + + } + i++; + } + + if ( nEnvVar > MAX_ENVIRONMENT_VARS ) + return FALSE; + NameBuffer = (WCHAR *)HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,MAX_PATH*sizeof(WCHAR)); + ValueBuffer = (WCHAR *)HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,1024*sizeof(WCHAR)); + + Environment[i].Name.Buffer = NameBuffer; + Environment[i].Name.MaximumLength = MAX_PATH; + lstrcpynW(Environment[i].Name.Buffer,lpValue,min(NameLen,Environment[i].Name.MaximumLength)); + Environment[i].Name.Length = NameLen; + + Environment[i].Value.Buffer = ValueBuffer; + Environment[i].Value.MaximumLength = 1024; + lstrcpynW(Environment[i].Value.Buffer,lpValue,min(ValueLen,Environment[i].Value.MaximumLength)); + Environment[i].Value.Length = ValueLen; + + + nEnvVar++; + + return TRUE; + +} + +DWORD +STDCALL +GetVersion(VOID) +{ + DWORD Version = 0; + OSVERSIONINFO VersionInformation; + GetVersionExW(&VersionInformation); + + Version |= ( VersionInformation.dwMajorVersion << 8 ); + Version |= VersionInformation.dwMinorVersion; + + Version |= ( VersionInformation.dwPlatformId << 16 ); + + return Version; + +} + + + +WINBOOL +STDCALL +GetVersionExW( + LPOSVERSIONINFO lpVersionInformation + ) +{ + lpVersionInformation->dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + lpVersionInformation->dwMajorVersion = 4; + lpVersionInformation->dwMinorVersion = 0; + lpVersionInformation->dwBuildNumber = 12; + lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT; + lstrcpyW((WCHAR *)lpVersionInformation->szCSDVersion,L"ReactOs Pre-Alpha 12"); + return TRUE; +} + +WINBOOL +STDCALL +GetVersionExA( + LPOSVERSIONINFO lpVersionInformation + ) +{ + lpVersionInformation->dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + lpVersionInformation->dwMajorVersion = 4; + lpVersionInformation->dwMinorVersion = 0; + lpVersionInformation->dwBuildNumber = 12; + lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT; + lstrcpyA((char *)lpVersionInformation->szCSDVersion,"ReactOs Pre-Alpha 12"); + return TRUE; +} + diff --git a/reactos/lib/kernel32/misc/handle.c b/reactos/lib/kernel32/misc/handle.c new file mode 100644 index 00000000000..f16eabc245d --- /dev/null +++ b/reactos/lib/kernel32/misc/handle.c @@ -0,0 +1,133 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/misc/handle.c + * PURPOSE: Object functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ +#include +#include + + + + +WINBOOL +WINAPI +GetHandleInformation( + HANDLE hObject, + LPDWORD lpdwFlags + ) +{ + OBJECT_DATA_INFORMATION HandleInfo; + ULONG BytesWritten; + NTSTATUS errCode; + + errCode = NtQueryObject(hObject,ObjectDataInformation, &HandleInfo, sizeof(OBJECT_DATA_INFORMATION),&BytesWritten); + if (!NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + if ( HandleInfo.bInheritHandle ) + *lpdwFlags &= HANDLE_FLAG_INHERIT; + if ( HandleInfo.bProtectFromClose ) + *lpdwFlags &= HANDLE_FLAG_PROTECT_FROM_CLOSE; + return TRUE; + + +} + +WINBOOL +STDCALL +SetHandleInformation( + HANDLE hObject, + DWORD dwMask, + DWORD dwFlags + ) +{ + OBJECT_DATA_INFORMATION HandleInfo; + NTSTATUS errCode; + ULONG BytesWritten; + + errCode = NtQueryObject(hObject,ObjectDataInformation,&HandleInfo,sizeof(OBJECT_DATA_INFORMATION),&BytesWritten); + if (!NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + if ( (dwMask & HANDLE_FLAG_INHERIT)== HANDLE_FLAG_INHERIT) { + HandleInfo.bInheritHandle = (BOOLEAN)((dwFlags & HANDLE_FLAG_INHERIT) == HANDLE_FLAG_INHERIT); + } + if ( (dwMask & HANDLE_FLAG_PROTECT_FROM_CLOSE) == HANDLE_FLAG_PROTECT_FROM_CLOSE ) { + HandleInfo.bProtectFromClose = (BOOLEAN)((dwFlags & HANDLE_FLAG_PROTECT_FROM_CLOSE) == HANDLE_FLAG_PROTECT_FROM_CLOSE ) ; + } + + errCode = NtSetInformationObject(hObject,ObjectDataInformation,&HandleInfo,sizeof(OBJECT_DATA_INFORMATION)); + if (!NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + return TRUE; +} + + + +WINBOOL +STDCALL +CloseHandle( HANDLE hObject ) +{ + + NTSTATUS errCode; + + errCode = NtClose(hObject); + if(!NT_SUCCESS(errCode)) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + return TRUE; +} + + + +WINBOOL +STDCALL +DuplicateHandle( + HANDLE hSourceProcessHandle, + HANDLE hSourceHandle, + HANDLE hTargetProcessHandle, + LPHANDLE lpTargetHandle, + DWORD dwDesiredAccess, + BOOL bInheritHandle, + DWORD dwOptions + ) +{ + + + NTSTATUS errCode; + + errCode = NtDuplicateObject(hSourceProcessHandle,hSourceHandle,hTargetProcessHandle,lpTargetHandle, dwDesiredAccess, (BOOLEAN)bInheritHandle,dwOptions); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + + + return TRUE; + +} + +UINT STDCALL +SetHandleCount(UINT nCount) +{ + return nCount; +} + + + + + + + diff --git a/reactos/lib/kernel32/process/proc.c b/reactos/lib/kernel32/process/proc.c index 633e088f1ad..9cf5c6d4c50 100644 --- a/reactos/lib/kernel32/process/proc.c +++ b/reactos/lib/kernel32/process/proc.c @@ -1,83 +1,440 @@ -#include -#include /* - * Win32 Process Api functions - * Author: Boudewijn Dekker - * to do: many more to add .. - * open matters: ProcessInformation should be per process - and part of larger structure. + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/proc/proc.c + * PURPOSE: Process functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 */ +#define UNICODE +#include +#include +#include +#include +#include +#include +#include + +extern NT_PEB *CurrentPeb; +extern NT_PEB Peb; + +WaitForInputIdleType lpfnGlobalRegisterWaitForInputIdle; + +VOID RegisterWaitForInputIdle(WaitForInputIdleType lpfnRegisterWaitForInputIdle); + +WINBOOL +STDCALL +GetProcessId(HANDLE hProcess, LPDWORD lpProcessId ); - - -#define NT_CURRENT_PROCESS 0xFFFFFFFF -#define NT_CURRENT_THREAD 0xFFFFFFFE - +NT_PEB *GetCurrentPeb(VOID) +{ + if ( CurrentPeb != NULL ) + return CurrentPeb; + else // hack to be able to return a process environment any time. + return &Peb; +} HANDLE STDCALL GetCurrentProcess(VOID) { - return NT_CURRENT_PROCESS; + return (HANDLE)NtCurrentProcess(); } -HANDLE STDCALL GetCurrentThread() +HANDLE STDCALL GetCurrentThread(VOID) { - return NT_CURRENT_PROCESS; + return (HANDLE)NtCurrentThread(); } -#if 0 - -WINBASEAPI -DWORD -WINAPI -GetCurrentProcessId() +DWORD +STDCALL +GetCurrentProcessId(VOID) { - return GetTeb()->dwProcessId; + + return (DWORD)(GetTeb()->Cid).UniqueProcess; + + +} + +unsigned char CommandLineA[MAX_PATH]; + +LPSTR +STDCALL +GetCommandLineA( + VOID + ) +{ + WCHAR *CommandLineW; + ULONG i = 0; + + CommandLineW = GetCommandLineW(); + while ((CommandLineW[i])!=0 && i < MAX_PATH) + { + CommandLineA[i] = (unsigned char)CommandLineW[i]; + i++; + } + CommandLineA[i] = 0; + return CommandLineA; +} +LPWSTR +STDCALL +GetCommandLineW( + VOID + ) +{ + return GetCurrentPeb()->StartupInfo->CommandLine; } -WINBASEAPI -DWORD -WINAPI -GetCurrentThreadId() +WINBOOL +STDCALL +GetExitCodeProcess( + HANDLE hProcess, + LPDWORD lpExitCode + ) +{ + NTSTATUS errCode; + PROCESS_BASIC_INFORMATION ProcessBasic; + ULONG BytesWritten; + + errCode = NtQueryInformationProcess(hProcess,ProcessBasicInformation,&ProcessBasic,sizeof(PROCESS_BASIC_INFORMATION),&BytesWritten); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + memcpy( lpExitCode ,&ProcessBasic.ExitStatus,sizeof(DWORD)); + return TRUE; + +} + +WINBOOL +STDCALL +GetProcessId( + HANDLE hProcess, + LPDWORD lpProcessId + ) +{ + NTSTATUS errCode; + PROCESS_BASIC_INFORMATION ProcessBasic; + ULONG BytesWritten; + + errCode = NtQueryInformationProcess(hProcess,ProcessBasicInformation,&ProcessBasic,sizeof(PROCESS_BASIC_INFORMATION),&BytesWritten); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + memcpy( lpProcessId ,&ProcessBasic.UniqueProcessId,sizeof(DWORD)); + return TRUE; + +} + +WINBOOL +STDCALL +CreateProcessA( + LPCSTR lpApplicationName, + LPSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + WINBOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCSTR lpCurrentDirectory, + LPSTARTUPINFO lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation + ) +{ + WCHAR ApplicationNameW[MAX_PATH]; + WCHAR CommandLineW[MAX_PATH]; + WCHAR CurrentDirectoryW[MAX_PATH]; + + + ULONG i; + + i = 0; + while ((*lpApplicationName)!=0 && i < MAX_PATH) + { + ApplicationNameW[i] = *lpApplicationName; + lpApplicationName++; + i++; + } + ApplicationNameW[i] = 0; + + + i = 0; + while ((*lpCommandLine)!=0 && i < MAX_PATH) + { + CommandLineW[i] = *lpCommandLine; + lpCommandLine++; + i++; + } + CommandLineW[i] = 0; + + i = 0; + while ((*lpCurrentDirectory)!=0 && i < MAX_PATH) + { + CurrentDirectoryW[i] = *lpCurrentDirectory; + lpCurrentDirectory++; + i++; + } + CurrentDirectoryW[i] = 0; + + return CreateProcessW(ApplicationNameW,CommandLineW, lpProcessAttributes,lpThreadAttributes, + bInheritHandles,dwCreationFlags,lpEnvironment,CurrentDirectoryW,lpStartupInfo, + lpProcessInformation); + + +} + + +WINBOOL +STDCALL +CreateProcessW( + LPCWSTR lpApplicationName, + LPWSTR lpCommandLine, + LPSECURITY_ATTRIBUTES lpProcessAttributes, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + WINBOOL bInheritHandles, + DWORD dwCreationFlags, + LPVOID lpEnvironment, + LPCWSTR lpCurrentDirectory, + LPSTARTUPINFO lpStartupInfo, + LPPROCESS_INFORMATION lpProcessInformation + ) +{ + HANDLE hFile, hSection, hProcess, hThread; + KPRIORITY PriorityClass; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + BOOLEAN CreateSuspended; + + NTSTATUS errCode; + + UNICODE_STRING ApplicationNameString; + + + + LPTHREAD_START_ROUTINE lpStartAddress = NULL; + LPVOID lpParameter = NULL; + + hFile = NULL; + + ApplicationNameString.Length = lstrlenW(lpApplicationName)*sizeof(WCHAR); + + ApplicationNameString.Buffer = (WCHAR *)lpApplicationName; + ApplicationNameString.MaximumLength = ApplicationNameString.Length; + + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + + + + if ( lpProcessAttributes != NULL ) { + if ( lpProcessAttributes->bInheritHandle ) + ObjectAttributes.Attributes = OBJ_INHERIT; + else + ObjectAttributes.Attributes = 0; + ObjectAttributes.SecurityDescriptor = lpProcessAttributes->lpSecurityDescriptor; + } + ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; + + errCode = NtOpenFile(&hFile,(SYNCHRONIZE|FILE_EXECUTE), &ObjectAttributes, + &IoStatusBlock,(FILE_SHARE_DELETE|FILE_SHARE_READ),(FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE)); + + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + errCode = NtCreateSection(&hSection,SECTION_ALL_ACCESS,NULL,NULL,PAGE_EXECUTE,SEC_IMAGE,hFile); + NtClose(hFile); + + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + + if ( lpProcessAttributes != NULL ) { + if ( lpProcessAttributes->bInheritHandle ) + ObjectAttributes.Attributes = OBJ_INHERIT; + else + ObjectAttributes.Attributes = 0; + ObjectAttributes.SecurityDescriptor = lpProcessAttributes->lpSecurityDescriptor; + } + + errCode = NtCreateProcess(&hProcess,PROCESS_ALL_ACCESS, &ObjectAttributes,NtCurrentProcess(),bInheritHandles,hSection,NULL,NULL); + NtClose(hSection); + + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + + PriorityClass = NORMAL_PRIORITY_CLASS; + NtSetInformationProcess(hProcess,ProcessBasePriority,&PriorityClass,sizeof(KPRIORITY)); + + if ( ( dwCreationFlags & CREATE_SUSPENDED ) == CREATE_SUSPENDED) + CreateSuspended = TRUE; + else + CreateSuspended = FALSE; + + hThread = CreateRemoteThread( + hProcess, + lpThreadAttributes, + 4096, // 1 page ?? + lpStartAddress, + lpParameter, + CREATE_SUSPENDED, + &lpProcessInformation->dwThreadId + ); + + + if ( hThread == NULL ) + return FALSE; + + + + lpProcessInformation->hProcess = hProcess; + lpProcessInformation->hThread = hThread; + + + + + GetProcessId(hProcess,&lpProcessInformation->dwProcessId); + + + + return TRUE; + + + } + + + +HANDLE +STDCALL +OpenProcess( + DWORD dwDesiredAccess, + WINBOOL bInheritHandle, + DWORD dwProcessId + ) { - return GetTeb()->dwThreadId; + + NTSTATUS errCode; + HANDLE ProcessHandle; + OBJECT_ATTRIBUTES ObjectAttributes; + CLIENT_ID ClientId ; + + ClientId.UniqueProcess = (HANDLE)dwProcessId; + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = (HANDLE)NULL; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = NULL; + + if ( bInheritHandle == TRUE ) + ObjectAttributes.Attributes = OBJ_INHERIT; + else + ObjectAttributes.Attributes = 0; + + errCode = NtOpenProcess ( &ProcessHandle, dwDesiredAccess, &ObjectAttributes, &ClientId); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return NULL; + } + return ProcessHandle; } + + + + + + + + + + + + UINT WinExec ( LPCSTR lpCmdLine, UINT uCmdShow ) { - STARTUPINFO StartUpInfo; - StartupInfo.wShowWindow = uCmdShow ; + STARTUPINFO StartupInfo; PROCESS_INFORMATION ProcessInformation; + + HINSTANCE hInst; + DWORD dosErr; + + + StartupInfo.cb = sizeof(STARTUPINFO); + StartupInfo.wShowWindow = uCmdShow ; StartupInfo.dwFlags = 0; - HINSTANCE hInst = CreateProcess(NULL,lpCmdLine,NULL,NULL,FALSE,NULL,NULL,NULL,&StartupInfo, &ProcessInformation); + hInst = (HINSTANCE)CreateProcessA(NULL,(PVOID)lpCmdLine,NULL,NULL,FALSE,0,NULL,NULL,&StartupInfo, &ProcessInformation); if ( hInst == NULL ) { dosErr = GetLastError(); - if ( dosErr == 0x000000C1 ) - return 0; // out of resources - else - return dosErr; + return dosErr; } - if ( lpfuncGlobalRegisterWaitForInputIdle != NULL ) - lpfuncGlobalRegisterWaitForInputIdle(0x00007530,ProcessInformation->hProcess); - NtClose(ProcessInformation->hProcess); - NtClose(ProcessInformation->hThread); - return; + if ( lpfnGlobalRegisterWaitForInputIdle != NULL ) + lpfnGlobalRegisterWaitForInputIdle(ProcessInformation.hProcess,10000); + NtClose(ProcessInformation.hProcess); + NtClose(ProcessInformation.hThread); + return 0; } -VOID RegisterWaitForInputIdle(lpfuncRegisterWaitForInputIdle) +VOID RegisterWaitForInputIdle(WaitForInputIdleType lpfnRegisterWaitForInputIdle) { - lpfuncGlobalRegisterWaitForInputIdle = lpfuncRegisterWaitForInputIdle; //77F450C8 + lpfnGlobalRegisterWaitForInputIdle = lpfnRegisterWaitForInputIdle; + return; +} + +DWORD +STDCALL +WaitForInputIdle( + HANDLE hProcess, + DWORD dwMilliseconds + ) +{ + return 0; +} + +VOID +STDCALL +Sleep( + DWORD dwMilliseconds + ) +{ + SleepEx(dwMilliseconds,FALSE); + return; +} + +DWORD +STDCALL +SleepEx( + DWORD dwMilliseconds, + BOOL bAlertable + ) +{ + TIME Interval; + NTSTATUS errCode; + SET_LARGE_INTEGER_LOW_PART(Interval,dwMilliseconds*1000); + + errCode = NtDelayExecution(bAlertable,&Interval); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return -1; + } + return 0; } -#define STARTF_IO 0x00000700 + + VOID STDCALL @@ -85,40 +442,97 @@ GetStartupInfoW( LPSTARTUPINFO lpStartupInfo ) { - NT_PEB *pPeb = GetTeb()->pPeb; + NT_PEB *pPeb = GetCurrentPeb(); if (lpStartupInfo == NULL ) { - SetLastError(-1); + SetLastError(ERROR_INVALID_PARAMETER); return; } + lpStartupInfo->cb = sizeof(STARTUPINFO); + lstrcpyW(lpStartupInfo->lpDesktop, pPeb->StartupInfo->Desktop); + lstrcpyW(lpStartupInfo->lpTitle, pPeb->StartupInfo->Title); + lpStartupInfo->dwX = pPeb->StartupInfo->dwX; + lpStartupInfo->dwY = pPeb->StartupInfo->dwY; + lpStartupInfo->dwXSize = pPeb->StartupInfo->dwXSize; + lpStartupInfo->dwYSize = pPeb->StartupInfo->dwYSize; + lpStartupInfo->dwXCountChars = pPeb->StartupInfo->dwXCountChars; + lpStartupInfo->dwYCountChars = pPeb->StartupInfo->dwYCountChars; + lpStartupInfo->dwFillAttribute = pPeb->StartupInfo->dwFillAttribute; + lpStartupInfo->dwFlags = pPeb->StartupInfo->dwFlags; + lpStartupInfo->wShowWindow = pPeb->StartupInfo->wShowWindow; + //lpStartupInfo->cbReserved2 = pPeb->StartupInfo->cbReserved; + //lpStartupInfo->lpReserved = pPeb->StartupInfo->lpReserved1; + //lpStartupInfo->lpReserved2 = pPeb->StartupInfo->lpReserved2; - lpStartupInfo->cb = pPeb->pPebInfo->cb; - lpStartupInfo->lpReserved = pPeb->pPebInfo->lpReserved1; - lpStartupInfo->lpDesktop = pPeb->pPebInfo->lpDesktop; - lpStartupInfo->lpTitle = pPeb->pPebInfo->lpTitle; - lpStartupInfo->dwX = pPeb->pPebInfo->dwX; - lpStartupInfo->dwY = pPeb->pPebInfo->dwY; - lpStartupInfo->dwXSize = pPeb->pPebInfo->dwXSize; - lpStartupInfo->dwYSize = pPeb->pPebInfo->dwYSize; - lpStartupInfo->dwXCountChars = pPeb->pPebInfo->dwXCountChars; - lpStartupInfo->dwYCountChars = pPeb->pPebInfo->dwYCountChars; - lpStartupInfo->dwFillAttribute = pPeb->pPebInfo->dwFillAttribute; - lpStartupInfo->dwFlags = pPeb->pPebInfo->dwFlags; - lpStartupInfo->wShowWindow = pPeb->pPebInfo->wShowWindow; - lpStartupInfo->cbReserved2 = pPeb->pPebInfo->cbReserved; - lpStartupInfo->lpReserved2 = pPeb->pPebInfo->lpReserved2; - if ( lpStartupInfo.dwFlags == STARTF_IO ) { - lpStartupInfo->hStdInput = pPeb->pPebInfo->hStdInput; - lpStartupInfo->hStdOutput = pPeb->pPebInfo->hStdOutput; - lpStartupInfo->hStdError = pPeb->pPebInfo->hStdError; - } + lpStartupInfo->hStdInput = pPeb->StartupInfo->hStdInput; + lpStartupInfo->hStdOutput = pPeb->StartupInfo->hStdOutput; + lpStartupInfo->hStdError = pPeb->StartupInfo->hStdError; + + + + return; + } -BOOL FlushInstructionCache( +VOID +STDCALL +GetStartupInfoA( + LPSTARTUPINFO lpStartupInfo + ) +{ + NT_PEB *pPeb = GetCurrentPeb(); + ULONG i = 0; + if (lpStartupInfo == NULL ) { + SetLastError(ERROR_INVALID_PARAMETER); + return; + } + + + lpStartupInfo->cb = sizeof(STARTUPINFO); + i = 0; + + while ((pPeb->StartupInfo->Desktop[i])!=0 && i < MAX_PATH) + { + lpStartupInfo->lpDesktop[i] = (unsigned char)pPeb->StartupInfo->Desktop[i]; + i++; + } + lpStartupInfo->lpDesktop[i] = 0; + + i = 0; + while ((pPeb->StartupInfo->Title[i])!=0 && i < MAX_PATH) + { + lpStartupInfo->lpTitle[i] = (unsigned char)pPeb->StartupInfo->Title[i]; + i++; + } + lpStartupInfo->lpTitle[i] = 0; + + lpStartupInfo->dwX = pPeb->StartupInfo->dwX; + lpStartupInfo->dwY = pPeb->StartupInfo->dwY; + lpStartupInfo->dwXSize = pPeb->StartupInfo->dwXSize; + lpStartupInfo->dwYSize = pPeb->StartupInfo->dwYSize; + lpStartupInfo->dwXCountChars = pPeb->StartupInfo->dwXCountChars; + lpStartupInfo->dwYCountChars = pPeb->StartupInfo->dwYCountChars; + lpStartupInfo->dwFillAttribute = pPeb->StartupInfo->dwFillAttribute; + lpStartupInfo->dwFlags = pPeb->StartupInfo->dwFlags; + lpStartupInfo->wShowWindow = pPeb->StartupInfo->wShowWindow; + //lpStartupInfo->cbReserved2 = pPeb->StartupInfo->cbReserved; + //lpStartupInfo->lpReserved = pPeb->StartupInfo->lpReserved1; + //lpStartupInfo->lpReserved2 = pPeb->StartupInfo->lpReserved2; + + lpStartupInfo->hStdInput = pPeb->StartupInfo->hStdInput; + lpStartupInfo->hStdOutput = pPeb->StartupInfo->hStdOutput; + lpStartupInfo->hStdError = pPeb->StartupInfo->hStdError; + + return; +} + +BOOL +STDCALL +FlushInstructionCache( HANDLE hProcess, @@ -126,11 +540,61 @@ BOOL FlushInstructionCache( DWORD dwSize ) { - errCode = NtFlushInstructionCache(hProcess,lpBaseAddress,dwSize); - if ( errCode < 0 ) { - CompatibleError(errCode); + NTSTATUS errCode; + errCode = NtFlushInstructionCache(hProcess,(PVOID)lpBaseAddress,dwSize); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); return FALSE; } + return TRUE; } -#endif +VOID +STDCALL +ExitProcess( + UINT uExitCode + ) +{ + + NtTerminateProcess( + NtCurrentProcess() , + uExitCode + ); + + +} + +VOID +STDCALL +FatalAppExitA( + UINT uAction, + LPCSTR lpMessageText + ) +{ + WCHAR MessageTextW[MAX_PATH]; + UINT i; + i = 0; + while ((*lpMessageText)!=0 && i < 35) + { + MessageTextW[i] = *lpMessageText; + lpMessageText++; + i++; + } + MessageTextW[i] = 0; + + return FatalAppExitW(uAction,MessageTextW); +} + + + +VOID +STDCALL +FatalAppExitW( + UINT uAction, + LPCWSTR lpMessageText + ) +{ + return; +} + + diff --git a/reactos/lib/kernel32/string/lstring.c b/reactos/lib/kernel32/string/lstring.c index bdfcabcfc4e..c69aade5605 100644 --- a/reactos/lib/kernel32/string/lstring.c +++ b/reactos/lib/kernel32/string/lstring.c @@ -1,9 +1,18 @@ - +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/file/lstring.c + * PURPOSE: Local string functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ #undef WIN32_LEAN_AND_MEAN #include #include #include + int STDCALL lstrcmpA( @@ -122,4 +131,12 @@ lstrlenW( ) { return wcslen(lpString); + } + + + + + + + diff --git a/reactos/lib/kernel32/synch/critical.c b/reactos/lib/kernel32/synch/critical.c index 0ddaf719294..046df3da6da 100644 --- a/reactos/lib/kernel32/synch/critical.c +++ b/reactos/lib/kernel32/synch/critical.c @@ -35,6 +35,7 @@ VOID LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection) { } -BOOL TryEntryCriticalSection(LPCRITICAL_SECTION lpCriticalSection) +WINBOOL TryEntryCriticalSection(LPCRITICAL_SECTION lpCriticalSection) { } + diff --git a/reactos/lib/kernel32/synch/event.c b/reactos/lib/kernel32/synch/event.c new file mode 100644 index 00000000000..55cce0bb824 --- /dev/null +++ b/reactos/lib/kernel32/synch/event.c @@ -0,0 +1,198 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/synch/event.c + * PURPOSE: Local string functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ +#undef WIN32_LEAN_AND_MEAN +#include +#include +#include +#include + + +WINBOOL +STDCALL +SetEvent( + HANDLE hEvent + ) +{ + NTSTATUS errCode; + ULONG Count; + errCode = NtSetEvent(hEvent,&Count); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + +WINBOOL +STDCALL +ResetEvent( + HANDLE hEvent + ) +{ + NTSTATUS errCode; + ULONG Count; + errCode = NtResetEvent(hEvent, &Count); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + + + +HANDLE +STDCALL +CreateEventW( + LPSECURITY_ATTRIBUTES lpEventAttributes, + WINBOOL bManualReset, + WINBOOL bInitialState, + LPCWSTR lpName + ) +{ + NTSTATUS errCode; + HANDLE hEvent; + UNICODE_STRING EventNameString; + OBJECT_ATTRIBUTES ObjectAttributes; + ObjectAttributes.Attributes = 0; + if ( lpEventAttributes != NULL ) { + ObjectAttributes.SecurityDescriptor = lpEventAttributes->lpSecurityDescriptor; + if ( lpEventAttributes->bInheritHandle == TRUE ) + ObjectAttributes.Attributes |= OBJ_INHERIT; + + } + + + if(lpName != NULL) { + EventNameString.Buffer = (WCHAR *)lpName; + EventNameString.Length = lstrlenW(lpName)*sizeof(WCHAR); + EventNameString.MaximumLength = EventNameString.Length; + ObjectAttributes.ObjectName = &EventNameString; + } + else + ObjectAttributes.ObjectName = NULL; + + + + errCode = NtCreateEvent(&hEvent,STANDARD_RIGHTS_ALL|EVENT_READ_ACCESS|EVENT_WRITE_ACCESS,&ObjectAttributes,bManualReset,bInitialState); + if(!NT_SUCCESS(errCode)) { + SetLastError(RtlNtStatusToDosError(errCode)); + return NULL; + } + + + return hEvent; +} + + +HANDLE +STDCALL +OpenEventW( + DWORD dwDesiredAccess, + WINBOOL bInheritHandle, + LPCWSTR lpName + ) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING EventNameString; + NTSTATUS errCode; + HANDLE hEvent = NULL; + + if(lpName == NULL) { + SetLastError(ERROR_INVALID_PARAMETER); + return NULL; + } + + ObjectAttributes.Attributes = 0; + ObjectAttributes.SecurityDescriptor = NULL; + EventNameString.Buffer = (WCHAR *)lpName; + EventNameString.Length = lstrlenW(lpName)*sizeof(WCHAR); + EventNameString.MaximumLength = EventNameString.Length; + ObjectAttributes.ObjectName = &EventNameString; + + if (bInheritHandle == TRUE ) + ObjectAttributes.Attributes |= OBJ_INHERIT; + + + errCode = NtOpenEvent(hEvent,dwDesiredAccess,&ObjectAttributes); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return NULL; + } + + return hEvent; +} + + +HANDLE +STDCALL +CreateEventA( + LPSECURITY_ATTRIBUTES lpEventAttributes, + WINBOOL bManualReset, + WINBOOL bInitialState, + LPCSTR lpName + ) +{ + int i; + WCHAR EventNameW[MAX_PATH]; + i = 0; + while ((*lpName)!=0 && i < MAX_PATH) + { + EventNameW[i] = *lpName; + lpName++; + i++; + } + EventNameW[i] = 0; + + return CreateEventW(lpEventAttributes,bManualReset,bInitialState,EventNameW); +} + + +HANDLE +STDCALL +OpenEventA( + DWORD dwDesiredAccess, + WINBOOL bInheritHandle, + LPCSTR lpName + ) +{ + ULONG i; + WCHAR EventNameW[MAX_PATH]; + + + + i = 0; + while ((*lpName)!=0 && i < MAX_PATH) + { + EventNameW[i] = *lpName; + lpName++; + i++; + } + EventNameW[i] = 0; + + + return OpenEventW(dwDesiredAccess,bInheritHandle,EventNameW); +} + +WINBOOL +STDCALL +PulseEvent( + HANDLE hEvent + ) +{ + ULONG Count; + NTSTATUS errCode; + errCode = NtPulseEvent(hEvent,&Count); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} \ No newline at end of file diff --git a/reactos/lib/kernel32/synch/wait.c b/reactos/lib/kernel32/synch/wait.c new file mode 100644 index 00000000000..cdfe761038c --- /dev/null +++ b/reactos/lib/kernel32/synch/wait.c @@ -0,0 +1,246 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/synch/wait.c + * PURPOSE: Wait functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + * UPDATE HISTORY: + * Created 01/11/98 + */ + +#include +#include +#include +#include + +HANDLE +STDCALL +CreateSemaphoreA( + LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, + LONG lInitialCount, + LONG lMaximumCount, + LPCSTR lpName + ) +{ + WCHAR NameW[MAX_PATH]; + ULONG i = 0; + + while ((*lpName)!=0 && i < MAX_PATH) + { + NameW[i] = *lpName; + lpName++; + i++; + } + NameW[i] = 0; + return CreateSemaphoreW( + lpSemaphoreAttributes, + lInitialCount, + lMaximumCount, + NameW + ); +} + +HANDLE +STDCALL +CreateSemaphoreW( + LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, + LONG lInitialCount, + LONG lMaximumCount, + LPCWSTR lpName + ) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + NTSTATUS errCode; + UNICODE_STRING NameString; + HANDLE SemaphoreHandle; + + NameString.Length = lstrlenW(lpName)*sizeof(WCHAR); + NameString.Buffer = (WCHAR *)lpName; + NameString.MaximumLength = NameString.Length; + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + ObjectAttributes.ObjectName = &NameString; + ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = NULL; + + if ( lpSemaphoreAttributes != NULL ) { + ObjectAttributes.SecurityDescriptor = lpSemaphoreAttributes->lpSecurityDescriptor; + if ( lpSemaphoreAttributes->bInheritHandle == TRUE ) + ObjectAttributes.Attributes |= OBJ_INHERIT; + } + + + errCode = NtCreateSemaphore( + &SemaphoreHandle, + GENERIC_ALL, + &ObjectAttributes, + lInitialCount, + lMaximumCount + ); + if (!NT_SUCCESS(errCode)) + { + SetLastError(RtlNtStatusToDosError(errCode)); + return NULL; + } + + return SemaphoreHandle; + + + +} + +HANDLE +STDCALL +CreateMutexA( + LPSECURITY_ATTRIBUTES lpMutexAttributes, + WINBOOL bInitialOwner, + LPCSTR lpName + ) +{ + WCHAR NameW[MAX_PATH]; + ULONG i = 0; + + while ((*lpName)!=0 && i < MAX_PATH) + { + NameW[i] = *lpName; + lpName++; + i++; + } + NameW[i] = 0; + + return CreateMutexW( + lpMutexAttributes, + bInitialOwner, + NameW + ); +} + +HANDLE +STDCALL +CreateMutexW( + LPSECURITY_ATTRIBUTES lpMutexAttributes, + WINBOOL bInitialOwner, + LPCWSTR lpName + ) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + NTSTATUS errCode; + UNICODE_STRING NameString; + HANDLE MutantHandle; + + NameString.Length = lstrlenW(lpName)*sizeof(WCHAR); + NameString.Buffer = (WCHAR *)lpName; + NameString.MaximumLength = NameString.Length; + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + ObjectAttributes.ObjectName = &NameString; + ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = NULL; + + if ( lpMutexAttributes != NULL ) { + ObjectAttributes.SecurityDescriptor = lpMutexAttributes->lpSecurityDescriptor; + if ( lpMutexAttributes->bInheritHandle == TRUE ) + ObjectAttributes.Attributes |= OBJ_INHERIT; + } + + + errCode = NtCreateMutant(&MutantHandle,GENERIC_ALL, &ObjectAttributes,(BOOLEAN)bInitialOwner); + if (!NT_SUCCESS(errCode)) + { + SetLastError(RtlNtStatusToDosError(errCode)); + return NULL; + } + + return MutantHandle; + + + +} + + +DWORD +STDCALL +WaitForSingleObject( + HANDLE hHandle, + DWORD dwMilliseconds + ) +{ + return WaitForSingleObjectEx(hHandle,dwMilliseconds,FALSE); +} + +DWORD +STDCALL +WaitForSingleObjectEx( + HANDLE hHandle, + DWORD dwMilliseconds, + BOOL bAlertable + ) +{ + + NTSTATUS errCode; + LARGE_INTEGER Time; + DWORD retCode; + + SET_LARGE_INTEGER_LOW_PART(Time,dwMilliseconds); + + errCode = NtWaitForSingleObject( + hHandle, + (BOOLEAN) bAlertable, + &Time + ); + + retCode = RtlNtStatusToDosError(errCode); + SetLastError(retCode); + return retCode; + + + +} + +DWORD +STDCALL +WaitForMultipleObjects( + DWORD nCount, + CONST HANDLE * lpHandles, + BOOL bWaitAll, + DWORD dwMilliseconds + ) +{ + return WaitForMultipleObjectsEx(nCount,lpHandles,bWaitAll,dwMilliseconds,FALSE); +} + +DWORD +STDCALL +WaitForMultipleObjectsEx( + DWORD nCount, + CONST HANDLE * lpHandles, + BOOL bWaitAll, + DWORD dwMilliseconds, + BOOL bAlertable + ) +{ + NTSTATUS errCode; + LARGE_INTEGER Time; + DWORD retCode; + + SET_LARGE_INTEGER_LOW_PART(Time,dwMilliseconds); + + + errCode = NtWaitForMultipleObjects ( + nCount, + (PHANDLE)lpHandles, + (CINT)bWaitAll, + (BOOLEAN)bAlertable, + &Time + ); + + retCode = RtlNtStatusToDosError(errCode); + SetLastError(retCode); + return retCode; + + +} \ No newline at end of file diff --git a/reactos/lib/kernel32/thread/thread.c b/reactos/lib/kernel32/thread/thread.c index 631314c5bec..a6e47ef9628 100644 --- a/reactos/lib/kernel32/thread/thread.c +++ b/reactos/lib/kernel32/thread/thread.c @@ -1,27 +1,314 @@ - /* -author: Boudewijn Dekker -original source : wine -todo: improve debug info -*/ + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/kernel32/thread/thread.c + * PURPOSE: Thread functions + * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) + Tls functions are modified from WINE + * UPDATE HISTORY: + * Created 01/11/98 + */ -#include +#include +#include +#include +#include -WINBASEAPI BOOL WINAPI SwitchToThread(VOID ) +HANDLE +STDCALL +CreateThread( + LPSECURITY_ATTRIBUTES lpThreadAttributes, + DWORD dwStackSize, + LPTHREAD_START_ROUTINE lpStartAddress, + LPVOID lpParameter, + DWORD dwCreationFlags, + LPDWORD lpThreadId + ) { - return NtYieldExecution(); + return CreateRemoteThread(NtCurrentProcess(),lpThreadAttributes,dwStackSize, + lpStartAddress,lpParameter,dwCreationFlags,lpThreadId); } + + + +HANDLE +STDCALL +CreateRemoteThread( + HANDLE hProcess, + LPSECURITY_ATTRIBUTES lpThreadAttributes, + DWORD dwStackSize, + LPTHREAD_START_ROUTINE lpStartAddress, + LPVOID lpParameter, + DWORD dwCreationFlags, + LPDWORD lpThreadId + ) +{ + NTSTATUS errCode; + HANDLE ThreadHandle; + OBJECT_ATTRIBUTES ObjectAttributes; + CLIENT_ID ClientId; + CONTEXT ThreadContext; + INITIAL_TEB InitialTeb; + BOOLEAN CreateSuspended = FALSE; + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = NULL; + ObjectAttributes.ObjectName = NULL; + ObjectAttributes.Attributes = 0; + if ( lpThreadAttributes != NULL ) { + if ( lpThreadAttributes->bInheritHandle ) + ObjectAttributes.Attributes = OBJ_INHERIT; + ObjectAttributes.SecurityDescriptor = lpThreadAttributes->lpSecurityDescriptor; + } + ObjectAttributes.SecurityQualityOfService = NULL; + + if ( ( dwCreationFlags & CREATE_SUSPENDED ) == CREATE_SUSPENDED ) + CreateSuspended = TRUE; + else + CreateSuspended = FALSE; + // fix context + GetThreadContext(NtCurrentThread(),&ThreadContext); + // fix teb [ stack context ] --> check the image file + + errCode = NtCreateThread( + &ThreadHandle, + THREAD_ALL_ACCESS, + &ObjectAttributes, + hProcess, + &ClientId, + &ThreadContext, + &InitialTeb, + CreateSuspended + ); + if ( lpThreadId != NULL ) + memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG)); + + return ThreadHandle; +} + +NT_TEB *GetTeb(VOID) +{ + return NULL; +} + +WINBOOL STDCALL +SwitchToThread(VOID ) +{ + NTSTATUS errCode; + errCode = NtYieldExecution(); + return TRUE; +} + +DWORD +STDCALL +GetCurrentThreadId() +{ + + return (DWORD)(GetTeb()->Cid).UniqueThread; +} + +VOID +STDCALL +ExitThread( + UINT uExitCode + ) +{ + NTSTATUS errCode; + + errCode = NtTerminateThread( + NtCurrentThread() , + uExitCode + ); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + } + return; +} + +WINBOOL +STDCALL +GetThreadTimes( + HANDLE hThread, + LPFILETIME lpCreationTime, + LPFILETIME lpExitTime, + LPFILETIME lpKernelTime, + LPFILETIME lpUserTime + ) +{ + NTSTATUS errCode; + KERNEL_USER_TIMES KernelUserTimes; + ULONG ReturnLength; + errCode = NtQueryInformationThread(hThread,ThreadTimes,&KernelUserTimes,sizeof(KERNEL_USER_TIMES),&ReturnLength); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + memcpy(lpCreationTime, &KernelUserTimes.CreateTime, sizeof(FILETIME)); + memcpy(lpExitTime, &KernelUserTimes.ExitTime, sizeof(FILETIME)); + memcpy(lpKernelTime, &KernelUserTimes.KernelTime, sizeof(FILETIME)); + memcpy(lpUserTime, &KernelUserTimes.UserTime, sizeof(FILETIME)); + return TRUE; + +} + + +WINBOOL +STDCALL GetThreadContext( + HANDLE hThread, + LPCONTEXT lpContext + ) +{ + NTSTATUS errCode; + errCode = NtGetContextThread(hThread,lpContext); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + +WINBOOL +STDCALL +SetThreadContext( + HANDLE hThread, + CONST CONTEXT *lpContext + ) +{ + NTSTATUS errCode; + + errCode = NtSetContextThread(hThread,(void *)lpContext); + if (!NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + + + +WINBOOL +STDCALL +GetExitCodeThread( + HANDLE hThread, + LPDWORD lpExitCode + ) +{ + NTSTATUS errCode; + THREAD_BASIC_INFORMATION ThreadBasic; + ULONG DataWritten; + errCode = NtQueryInformationThread(hThread,ThreadBasicInformation,&ThreadBasic,sizeof(THREAD_BASIC_INFORMATION),&DataWritten); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + memcpy( lpExitCode ,&ThreadBasic.ExitStatus,sizeof(DWORD)); + return TRUE; + +} + + +DWORD +STDCALL +ResumeThread( + HANDLE hThread + ) +{ + NTSTATUS errCode; + ULONG PreviousResumeCount; + + errCode = NtResumeThread(hThread,&PreviousResumeCount ); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return -1; + } + return PreviousResumeCount; +} + +DWORD +STDCALL +SuspendThread( + HANDLE hThread + ) +{ + NTSTATUS errCode; + ULONG PreviousSuspendCount; + + errCode = NtSuspendThread(hThread,&PreviousSuspendCount ); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return -1; + } + return PreviousSuspendCount; +} + + +DWORD +STDCALL +SetThreadAffinityMask( + HANDLE hThread, + DWORD dwThreadAffinityMask + ) +{ + return 0; +} + + +WINBOOL +STDCALL +SetThreadPriority( + HANDLE hThread, + int nPriority + ) +{ + NTSTATUS errCode; + THREAD_BASIC_INFORMATION ThreadBasic; + ULONG DataWritten; + errCode = NtQueryInformationThread(hThread,ThreadBasicInformation,&ThreadBasic,sizeof(THREAD_BASIC_INFORMATION),&DataWritten); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + ThreadBasic.BasePriority = nPriority; + errCode = NtSetInformationThread(hThread,ThreadBasicInformation,&ThreadBasic,sizeof(THREAD_BASIC_INFORMATION)); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return FALSE; + } + return TRUE; +} + + +int +STDCALL +GetThreadPriority( + HANDLE hThread + ) +{ + NTSTATUS errCode; + THREAD_BASIC_INFORMATION ThreadBasic; + ULONG DataWritten; + errCode = NtQueryInformationThread(hThread,ThreadBasicInformation,&ThreadBasic,sizeof(THREAD_BASIC_INFORMATION),&DataWritten); + if ( !NT_SUCCESS(errCode) ) { + SetLastError(RtlNtStatusToDosError(errCode)); + return THREAD_PRIORITY_ERROR_RETURN; + } + return ThreadBasic.BasePriority; +} + + /* (WIN32) Thread Local Storage ******************************************** */ -DWORD WINAPI +DWORD STDCALL TlsAlloc(VOID) { DWORD dwTlsIndex = GetTeb()->dwTlsIndex; + + void **TlsData = GetTeb()->TlsData; - APISTR((LF_API, "TlsAlloc: (API)\n")); + if (dwTlsIndex < sizeof(TlsData) / sizeof(TlsData[0])) { TlsData[dwTlsIndex] = NULL; @@ -30,45 +317,42 @@ TlsAlloc(VOID) return (0xFFFFFFFFUL); } -BOOL WINAPI +WINBOOL STDCALL TlsFree(DWORD dwTlsIndex) { - APISTR((LF_APISTUB, "TlsFree(DWORD=%ld)\n", dwTlsIndex)); + return (TRUE); } -LPVOID WINAPI +LPVOID STDCALL TlsGetValue(DWORD dwTlsIndex) { - DWORD dwTlsIndex = GetTeb()->dwTlsIndex; + void **TlsData = GetTeb()->TlsData; - APISTR((LF_API, "TlsGetValue: (API) dwTlsIndex %ld\n", dwTlsIndex)); + if (dwTlsIndex < sizeof(TlsData) / sizeof(TlsData[0])) { - LOGSTR((LF_LOG, "TlsGetValue: (LOG) [%ld] = %p\n", - dwTlsIndex, TlsData[dwTlsIndex])); + SetLastError(NO_ERROR); return (TlsData[dwTlsIndex]); } - SetLastErrorEx(1, 0); + SetLastError(1); return (NULL); } -BOOL WINAPI +WINBOOL STDCALL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue) { - DWORD dwTlsIndex = GetTeb()->dwTlsIndex; + void **TlsData = GetTeb()->TlsData; - APISTR((LF_API, "TlsSetValue: (API) dwTlsIndex %ld lpTlsValue %p\n", - dwTlsIndex, lpTlsValue)); + if (dwTlsIndex < sizeof(TlsData) / sizeof(TlsData[0])) { - LOGSTR((LF_LOG, "TlsSetValue: (LOG) [%ld] = %p\n", - dwTlsIndex, lpTlsValue)); + TlsData[dwTlsIndex] = lpTlsValue; return (TRUE); } diff --git a/reactos/loaders/dos/loadros.asm b/reactos/loaders/dos/loadros.asm index 0c5eab88404..9f973cba9ac 100644 --- a/reactos/loaders/dos/loadros.asm +++ b/reactos/loaders/dos/loadros.asm @@ -384,6 +384,7 @@ last_addr dw 0 ; Generic error message ; err_msg db 'Error during operation',0 +rostitle db '',0 ; ; @@ -453,6 +454,50 @@ _to_pmode: ; ; Save cursor position ; + mov ax,3 ;! Reset video mode + int 10h + + + mov bl,10 + mov ah,12 + int 10h + + mov ax,1112h ;! Use 8x8 font + xor bl,bl + int 10h + mov ax,1200h ;! Use alternate print screen + mov bl,20h + int 10h + mov ah,1h ;! Define cursor (scan lines 6 to 7) + mov cx,0607h + int 10h + + mov ah,1 + mov cx,0600h + int 10h + + MOV AH,6 ;SCROLL ACTIVE PAGE UP + MOV AL,32H ;CLEAR 25 LINES + MOV CX,0H ;UPPER LEFT OF SCROLL + MOV DX,314FH ;LOWER RIGHT OF SCROLL + MOV BH,1*10h+1 ;USE NORMAL ATTRIBUTE ON BLANKED LINE + INT 10H ;VIDEO-IO + + + mov dx,0 + mov dh,0 + + mov ah,02h + mov bh,0 + int 10h + + mov dx,0 + mov dh,0 + + mov ah,02h + mov bh,0 + int 010h + mov ah,03h mov bh,0h int 010h @@ -461,7 +506,6 @@ _to_pmode: movzx eax,dh mov [_cursory],eax - mov bx,ds movzx eax,bx shl eax,4 diff --git a/reactos/ntoskrnl/hal/x86/bios32.c b/reactos/ntoskrnl/hal/x86/bios32.c index 834d2a50bdf..55c91865952 100644 --- a/reactos/ntoskrnl/hal/x86/bios32.c +++ b/reactos/ntoskrnl/hal/x86/bios32.c @@ -132,7 +132,7 @@ VOID Hal_bios32_probe() { continue; } - DbgPrint("BIOS32 detected at %x\n",i); + DbgPrint("ReactOS: BIOS32 detected at %x\n",i); bios32_indirect.address = service_entry->entry; bios32_detected=TRUE; } diff --git a/reactos/ntoskrnl/hal/x86/printk.c b/reactos/ntoskrnl/hal/x86/printk.c index 0c96c618a11..51985268f32 100644 --- a/reactos/ntoskrnl/hal/x86/printk.c +++ b/reactos/ntoskrnl/hal/x86/printk.c @@ -66,10 +66,12 @@ static unsigned int cursorx=0, cursory=0; static unsigned int lines_seen = 0; -#define NR_ROWS 25 +//#define NR_ROWS 25 +#define NR_ROWS 50 #define NR_COLUMNS 80 #define VIDMEM_BASE 0xb8000 + /* * PURPOSE: Points to the base of text mode video memory */ @@ -189,7 +191,7 @@ static void putchar(char c) default: vidmem[(cursorx*2) + (cursory*80*2)]=c; - vidmem[(cursorx*2) + (cursory*80*2)+1]=0x7; + vidmem[(cursorx*2) + (cursory*80*2)+1]=0x17; cursorx++; if (cursorx>=NR_COLUMNS) { @@ -208,7 +210,7 @@ static void putchar(char c) for (i=0;str[i]!=0;i++) { vidmem[NR_COLUMNS*(NR_ROWS-1)*2+i*2]=str[i]; - vidmem[NR_COLUMNS*(NR_ROWS-1)*2+i*2+1]=0x7; + vidmem[NR_COLUMNS*(NR_ROWS-1)*2+i*2+1]=0x37; // 17 for white on blue 37 } while (inb_p(0x60)!=0x81); @@ -221,7 +223,7 @@ static void putchar(char c) memcpy(vidmem,&vidmem[NR_COLUMNS*2], NR_COLUMNS*(NR_ROWS-1)*2); memset(&vidmem[NR_COLUMNS*(NR_ROWS-1)*2],0,NR_COLUMNS*2); - cursory=NR_ROWS-1; + cursory=NR_ROWS-1; } /* diff --git a/reactos/ntoskrnl/io/iocomp.c b/reactos/ntoskrnl/io/iocomp.c index 143efa7fab6..ff4844e9dea 100644 --- a/reactos/ntoskrnl/io/iocomp.c +++ b/reactos/ntoskrnl/io/iocomp.c @@ -1,11 +1,12 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: ntoskrnl/ke/bug.c - * PURPOSE: Graceful system shutdown if a bug is detected + * FILE: ntoskrnl/ke/iocomp.c + * PURPOSE: * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 + Changed NtQueryIoCompletion */ /* INCLUDES *****************************************************************/ @@ -58,10 +59,30 @@ ZwOpenIoCompletion( { } -NTSTATUS STDCALL NtQueryIoCompletion(VOID) +NTSTATUS +STDCALL +NtQueryIoCompletion( + IN HANDLE CompletionPort, + IN ULONG CompletionKey, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PULONG NumberOfBytesTransferred + ) { + +return ZwQueryIoCompletion(CompletionPort,CompletionKey,IoStatusBlock,NumberOfBytesTransferred); + } +NTSTATUS +STDCALL +ZwQueryIoCompletion( + IN HANDLE CompletionPort, + IN ULONG CompletionKey, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PULONG NumberOfBytesTransferred + ) +{ +} NTSTATUS STDCALL NtRemoveIoCompletion( @@ -69,7 +90,7 @@ NtRemoveIoCompletion( OUT PULONG CompletionKey, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PULONG CompletionStatus, - ULONG WaitTime + PLARGE_INTEGER WaitTime ) { } @@ -81,7 +102,7 @@ ZwRemoveIoCompletion( OUT PULONG CompletionKey, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PULONG CompletionStatus, - ULONG WaitTime + PLARGE_INTEGER WaitTime ) { } diff --git a/reactos/ntoskrnl/io/lock.c b/reactos/ntoskrnl/io/lock.c index 6b974296a4c..70702c93b92 100644 --- a/reactos/ntoskrnl/io/lock.c +++ b/reactos/ntoskrnl/io/lock.c @@ -55,8 +55,8 @@ NTSTATUS STDCALL ZwLockFile(IN HANDLE FileHandle, NTSTATUS STDCALL NtUnlockFile(IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, - IN LARGE_INTEGER ByteOffset, - IN LARGE_INTEGER Length, + IN PLARGE_INTEGER ByteOffset, + IN PLARGE_INTEGER Length, OUT PULONG Key OPTIONAL) { return(ZwUnlockFile(FileHandle, @@ -68,8 +68,8 @@ NTSTATUS STDCALL NtUnlockFile(IN HANDLE FileHandle, NTSTATUS STDCALL ZwUnlockFile(IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, - IN LARGE_INTEGER ByteOffset, - IN LARGE_INTEGER Length, + IN PLARGE_INTEGER ByteOffset, + IN PLARGE_INTEGER Length, OUT PULONG Key OPTIONAL) { UNIMPLEMENTED; diff --git a/reactos/ntoskrnl/io/mailslot.c b/reactos/ntoskrnl/io/mailslot.c index c146b3336be..b70c12618d8 100644 --- a/reactos/ntoskrnl/io/mailslot.c +++ b/reactos/ntoskrnl/io/mailslot.c @@ -6,6 +6,7 @@ * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 + Changed NtCreateMailslotFile */ /* INCLUDES *****************************************************************/ @@ -16,6 +17,32 @@ /* FUNCTIONS *****************************************************************/ -NTSTATUS STDCALL NtCreateMailslotFile(VOID) +NTSTATUS +STDCALL +NtCreateMailslotFile( + OUT PHANDLE MailSlotFileHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN ULONG FileAttributes, + IN ULONG ShareAccess, + IN ULONG MaxMessageSize, + IN PLARGE_INTEGER TimeOut + ) { } + +NTSTATUS +STDCALL +ZwCreateMailslotFile( + OUT PHANDLE MailSlotFileHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN ULONG FileAttributes, + IN ULONG ShareAccess, + IN ULONG MaxMessageSize, + IN PLARGE_INTEGER TimeOut + ) +{ +} \ No newline at end of file diff --git a/reactos/ntoskrnl/io/npipe.c b/reactos/ntoskrnl/io/npipe.c index 121e8993f4f..441a97a083a 100644 --- a/reactos/ntoskrnl/io/npipe.c +++ b/reactos/ntoskrnl/io/npipe.c @@ -16,6 +16,44 @@ /* FUNCTIONS *****************************************************************/ -NTSTATUS STDCALL NtCreateNamedPipeFile(VOID) +NTSTATUS +STDCALL +NtCreateNamedPipeFile( + OUT PHANDLE NamedPipeFileHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN ULONG FileAttributes, + IN ULONG ShareAccess, + IN ULONG OpenMode, + IN ULONG PipeType, + IN ULONG PipeRead, + IN ULONG PipeWait, + IN ULONG MaxInstances, + IN ULONG InBufferSize, + IN ULONG OutBufferSize, + IN PLARGE_INTEGER TimeOut + ) +{ +} + +NTSTATUS +STDCALL +ZwCreateNamedPipeFile( + OUT PHANDLE NamedPipeFileHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN ULONG FileAttributes, + IN ULONG ShareAccess, + IN ULONG OpenMode, + IN ULONG PipeType, + IN ULONG PipeRead, + IN ULONG PipeWait, + IN ULONG MaxInstances, + IN ULONG InBufferSize, + IN ULONG OutBufferSize, + IN PLARGE_INTEGER TimeOut + ) { } diff --git a/reactos/ntoskrnl/io/vpb.c b/reactos/ntoskrnl/io/vpb.c index 7b2bd27611b..5d56101b7bb 100644 --- a/reactos/ntoskrnl/io/vpb.c +++ b/reactos/ntoskrnl/io/vpb.c @@ -93,7 +93,7 @@ NTSTATUS STDCALL NtQueryVolumeInformationFile( OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID FSInformation, IN ULONG Length, - IN CINT FSInformationClass) + IN FS_INFORMATION_CLASS FSInformationClass) /* * FUNCTION: Queries the volume information @@ -129,7 +129,7 @@ ZwQueryVolumeInformationFile( OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID FSInformation, IN ULONG Length, - IN CINT FSInformationClass) + IN FS_INFORMATION_CLASS FSInformationClass) { PFILE_OBJECT FileObject; PDEVICE_OBJECT DeviceObject; diff --git a/reactos/ntoskrnl/ke/error.c b/reactos/ntoskrnl/ke/error.c index 3f2970f4230..be48b410dfc 100644 --- a/reactos/ntoskrnl/ke/error.c +++ b/reactos/ntoskrnl/ke/error.c @@ -50,6 +50,10 @@ NTSTATUS STDCALL NtRaiseHardError(VOID) { } -NTSTATUS STDCALL NtSetDefaultHardErrorPort(VOID) +NTSTATUS +STDCALL +NtSetDefaultHardErrorPort( + IN HANDLE PortHandle + ) { } diff --git a/reactos/ntoskrnl/ke/wait.c b/reactos/ntoskrnl/ke/wait.c index 5353cf778c8..6a0d2b4c046 100644 --- a/reactos/ntoskrnl/ke/wait.c +++ b/reactos/ntoskrnl/ke/wait.c @@ -197,7 +197,7 @@ VOID KeInitializeDispatcher(VOID) } NTSTATUS STDCALL NtWaitForMultipleObjects (IN ULONG Count, - IN PHANDLE Object[], + IN HANDLE Object[], IN CINT WaitType, IN BOOLEAN Alertable, IN PLARGE_INTEGER Time) @@ -210,7 +210,7 @@ NTSTATUS STDCALL NtWaitForMultipleObjects (IN ULONG Count, } NTSTATUS STDCALL ZwWaitForMultipleObjects (IN ULONG Count, - IN PHANDLE Object[], + IN HANDLE Object[], IN CINT WaitType, IN BOOLEAN Alertable, IN PLARGE_INTEGER Time) @@ -218,7 +218,7 @@ NTSTATUS STDCALL ZwWaitForMultipleObjects (IN ULONG Count, UNIMPLEMENTED; } -NTSTATUS STDCALL NtWaitForSingleObject (IN PHANDLE Object, +NTSTATUS STDCALL NtWaitForSingleObject (IN HANDLE Object, IN BOOLEAN Alertable, IN PLARGE_INTEGER Time) { @@ -227,7 +227,7 @@ NTSTATUS STDCALL NtWaitForSingleObject (IN PHANDLE Object, Time)); } -NTSTATUS STDCALL ZwWaitForSingleObject (IN PHANDLE Object, +NTSTATUS STDCALL ZwWaitForSingleObject (IN HANDLE Object, IN BOOLEAN Alertable, IN PLARGE_INTEGER Time) { diff --git a/reactos/ntoskrnl/mm/virtual.c b/reactos/ntoskrnl/mm/virtual.c index f666c211037..cf147486767 100644 --- a/reactos/ntoskrnl/mm/virtual.c +++ b/reactos/ntoskrnl/mm/virtual.c @@ -247,12 +247,16 @@ BOOLEAN MmIsAddressValid(PVOID VirtualAddress) return(TRUE); } -NTSTATUS STDCALL NtAllocateVirtualMemory(IN HANDLE ProcessHandle, - OUT PVOID *BaseAddress, - IN ULONG ZeroBits, - IN ULONG RegionSize, - IN ULONG AllocationType, - IN ULONG Protect) +NTSTATUS +STDCALL +NtAllocateVirtualMemory( + IN HANDLE ProcessHandle, + IN OUT PVOID *BaseAddress, + IN ULONG ZeroBits, + IN OUT PULONG RegionSize, + IN ULONG AllocationType, + IN ULONG Protect + ) { return(ZwAllocateVirtualMemory(ProcessHandle, BaseAddress, @@ -262,12 +266,16 @@ NTSTATUS STDCALL NtAllocateVirtualMemory(IN HANDLE ProcessHandle, Protect)); } -NTSTATUS STDCALL ZwAllocateVirtualMemory(IN HANDLE ProcessHandle, - OUT PVOID *BaseAddress, - IN ULONG ZeroBits, - IN ULONG RegionSize, - IN ULONG AllocationType, - IN ULONG Protect) +NTSTATUS +STDCALL +ZwAllocateVirtualMemory( + IN HANDLE ProcessHandle, + IN OUT PVOID *BaseAddress, + IN ULONG ZeroBits, + IN OUT PULONG RegionSize, + IN ULONG AllocationType, + IN ULONG Protect + ) /* * FUNCTION: Allocates a block of virtual memory in the process address space * ARGUMENTS: @@ -300,7 +308,6 @@ NTSTATUS STDCALL ZwAllocateVirtualMemory(IN HANDLE ProcessHandle, PEPROCESS Process; MEMORY_AREA* MemoryArea; ULONG Type; - ULONG i; NTSTATUS Status; DbgPrint("ZwAllocateVirtualMemory(ProcessHandle %x, *BaseAddress %x, " @@ -336,7 +343,7 @@ NTSTATUS STDCALL ZwAllocateVirtualMemory(IN HANDLE ProcessHandle, if (MemoryArea != NULL) { if (MemoryArea->BaseAddress == (*BaseAddress) && - MemoryArea->Length == RegionSize) + MemoryArea->Length == *RegionSize) { MemoryArea->Type = Type; MemoryArea->Attributes =Protect; @@ -347,7 +354,7 @@ NTSTATUS STDCALL ZwAllocateVirtualMemory(IN HANDLE ProcessHandle, MemoryArea = MmSplitMemoryArea(Process, MemoryArea, *BaseAddress, - RegionSize, + *RegionSize, Type, Protect); DbgPrint("*BaseAddress %x\n",*BaseAddress); @@ -355,11 +362,14 @@ NTSTATUS STDCALL ZwAllocateVirtualMemory(IN HANDLE ProcessHandle, } } + //FIXME RegionSize should be passed as pointer + + Status = MmCreateMemoryArea(UserMode, Process, Type, - (PULONG)BaseAddress, - RegionSize, + BaseAddress, + *RegionSize, Protect, &MemoryArea); @@ -406,7 +416,7 @@ NTSTATUS STDCALL ZwFlushVirtualMemory(IN HANDLE ProcessHandle, NTSTATUS STDCALL NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *BaseAddress, - IN ULONG RegionSize, + IN PULONG RegionSize, IN ULONG FreeType) { return(ZwFreeVirtualMemory(ProcessHandle, @@ -417,7 +427,7 @@ NTSTATUS STDCALL NtFreeVirtualMemory(IN HANDLE ProcessHandle, NTSTATUS STDCALL ZwFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *BaseAddress, - IN ULONG RegionSize, + IN PULONG RegionSize, IN ULONG FreeType) /* diff --git a/reactos/ntoskrnl/nt/evtpair.c b/reactos/ntoskrnl/nt/evtpair.c index 125f7955a9e..4e434cff19d 100644 --- a/reactos/ntoskrnl/nt/evtpair.c +++ b/reactos/ntoskrnl/nt/evtpair.c @@ -19,7 +19,7 @@ NTSTATUS STDCALL NtCreateEventPair( - OUT PHANDLE FileHandle, + OUT PHANDLE EventPairHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes ) @@ -29,7 +29,7 @@ NtCreateEventPair( NTSTATUS STDCALL ZwCreateEventPair( - OUT PHANDLE FileHandle, + OUT PHANDLE EventPairHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes ) @@ -40,7 +40,7 @@ ZwCreateEventPair( NTSTATUS STDCALL NtSetHighEventPair( - IN HANDLE EventPair + IN HANDLE EventPairHandle ) { } @@ -48,7 +48,7 @@ NtSetHighEventPair( NTSTATUS STDCALL ZwSetHighEventPair( - IN HANDLE EventPair + IN HANDLE EventPairHandle ) { } @@ -56,7 +56,7 @@ ZwSetHighEventPair( NTSTATUS STDCALL NtSetHighWaitLowEventPair( - IN HANDLE EventPair + IN HANDLE EventPairHandle ) { } @@ -64,7 +64,7 @@ NtSetHighWaitLowEventPair( NTSTATUS STDCALL ZwSetHighWaitLowEventPair( - IN HANDLE EventPair + IN HANDLE EventPairHandle ) { } @@ -73,7 +73,7 @@ ZwSetHighWaitLowEventPair( NTSTATUS STDCALL NtSetLowEventPair( - HANDLE EventPair + HANDLE EventPairHandle ) { } @@ -81,7 +81,7 @@ NtSetLowEventPair( NTSTATUS STDCALL ZwSetLowEventPair( - HANDLE EventPair + HANDLE EventPairHandle ) { } @@ -90,7 +90,7 @@ ZwSetLowEventPair( NTSTATUS STDCALL NtSetLowWaitHighEventPair( - HANDLE EventPair + HANDLE EventPairHandle ) { } @@ -98,7 +98,7 @@ NtSetLowWaitHighEventPair( NTSTATUS STDCALL ZwSetLowWaitHighEventPair( - HANDLE EventPair + HANDLE EventPairHandle ) { } @@ -106,7 +106,7 @@ ZwSetLowWaitHighEventPair( NTSTATUS STDCALL NtWaitLowEventPair( - IN HANDLE EventHandle + IN HANDLE EventPairHandle ) { } @@ -114,15 +114,43 @@ NtWaitLowEventPair( NTSTATUS STDCALL ZwWaitLowEventPair( - IN HANDLE EventHandle + IN HANDLE EventPairHandle ) { } -NTSTATUS STDCALL NtOpenEventPair(VOID) +NTSTATUS +STDCALL +NtOpenEventPair( + OUT PHANDLE EventPairHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes + ) { } -NTSTATUS STDCALL NtWaitHighEventPair(VOID) +NTSTATUS +STDCALL +ZwOpenEventPair( + OUT PHANDLE EventPairHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes + ) { } + +NTSTATUS +STDCALL +NtWaitHighEventPair( + IN HANDLE EventPairHandle + ) +{ +} + +NTSTATUS +STDCALL +ZwWaitHighEventPair( + IN HANDLE EventPairHandle + ) +{ +} \ No newline at end of file diff --git a/reactos/ntoskrnl/nt/mutant.c b/reactos/ntoskrnl/nt/mutant.c index f31e94dbf50..0b5accf403b 100644 --- a/reactos/ntoskrnl/nt/mutant.c +++ b/reactos/ntoskrnl/nt/mutant.c @@ -21,7 +21,7 @@ STDCALL NtCreateMutant( OUT PHANDLE MutantHandle, IN ACCESS_MASK DesiredAccess, - IN OBJECT_ATTRIBUTES ObjectAttributes, + IN POBJECT_ATTRIBUTES ObjectAttributes, IN BOOLEAN InitialOwner ) { @@ -32,7 +32,7 @@ STDCALL ZwCreateMutant( OUT PHANDLE MutantHandle, IN ACCESS_MASK DesiredAccess, - IN OBJECT_ATTRIBUTES ObjectAttributes, + IN POBJECT_ATTRIBUTES ObjectAttributes, IN BOOLEAN InitialOwner ) { diff --git a/reactos/ntoskrnl/nt/profile.c b/reactos/ntoskrnl/nt/profile.c index e2d0e5d722b..6c62e332957 100644 --- a/reactos/ntoskrnl/nt/profile.c +++ b/reactos/ntoskrnl/nt/profile.c @@ -1,11 +1,11 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: ntoskrnl/ke/bug.c - * PURPOSE: Graceful system shutdown if a bug is detected - * PROGRAMMER: David Welch (welch@mcmail.com) + * FILE: ntoskrnl/nt/Profile.c + * PURPOSE: + * PROGRAMMER: * UPDATE HISTORY: - * Created 22/05/98 + * */ /* INCLUDES *****************************************************************/ @@ -16,22 +16,52 @@ /* FUNCTIONS *****************************************************************/ -NTSTATUS STDCALL NtCreateProfile(VOID) +NTSTATUS +STDCALL +NtCreateProfile( + OUT PHANDLE ProfileHandle, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN ULONG ImageBase, + IN ULONG ImageSize, + IN ULONG Granularity, + OUT PVOID Buffer, + IN ULONG ProfilingSize, + IN ULONG ClockSource, + IN ULONG ProcessorMask + ) { } -NTSTATUS STDCALL NtQueryIntervalProfile(VOID) +NTSTATUS +STDCALL +NtQueryIntervalProfile( + OUT PULONG Interval, + OUT PULONG ClockSource + ) { } -NTSTATUS STDCALL NtSetIntervalProfile(VOID) +NTSTATUS +STDCALL +NtSetIntervalProfile( + IN ULONG Interval, + IN ULONG ClockSource + ) { } -NTSTATUS STDCALL NtStartProfile(VOID) +NTSTATUS +STDCALL +NtStartProfile( + IN HANDLE ProfileHandle + ) { } -NTSTATUS STDCALL NtStopProfile(VOID) +NTSTATUS +STDCALL +NtStopProfile( + IN HANDLE ProfileHandle + ) { } diff --git a/reactos/ntoskrnl/rtl/wstring.c b/reactos/ntoskrnl/rtl/wstring.c index baba2dde261..e6cb3b1a298 100644 --- a/reactos/ntoskrnl/rtl/wstring.c +++ b/reactos/ntoskrnl/rtl/wstring.c @@ -62,7 +62,7 @@ wchar_t* wcsrchr(const wchar_t* str, wchar_t ch) { if (str[len-1]==ch) { - return(&str[len-1]); + return((wchar_t*)&str[len-1]); } } return(NULL); @@ -92,23 +92,41 @@ wchar_t * wcscpy(wchar_t * str1,const wchar_t * str2) return(0); } } - return( (*str1) - (*str2) ); + return(wchar_t *)( (*str1) - (*str2) ); } + unsigned long wstrlen(PWSTR s) { - WCHAR c=' '; + return wcslen(s); +} + +#ifndef __MACHINE_STRING_FUNCTIONS + +size_t wcslen(const wchar_t * s) +{ + unsigned int len=0; - while(c!=0) { - c=*s; - s++; + while(s[len]!=0) { len++; }; - s-=len; - - return len-1; + return len; } +#else +size_t wcslen(const wchar_t * s) +{ +register int __res; +__asm__ __volatile__( + "cld\n\t" + "repne\n\t" + "scasw\n\t" + "notl %0\n\t" + "decl %0" + :"=c" (__res):"D" (s),"a" (0),"0" (0xffffffff):"edi"); +return __res; +} +#endif inline int wcscmp(const wchar_t* cs,const wchar_t * ct) { @@ -129,6 +147,64 @@ __asm__ __volatile__( return __res; } +int wcsicmp(const wchar_t* cs,const wchar_t * ct) +{ +register int __res; + + +__asm__ __volatile__( + "cld\n" + "1:\tmovw (%%esi), %%eax\n\t" + "movw (%%edi), %%edx \n\t" + "cmpw $0x5A, %%eax\n\t" + "ja 2f\t\n" + "cmpw $0x40, %%eax\t\n" + "jbe 2f\t\n" + "addw $0x20, %%eax\t\n" + "2:\t cmpw $0x5A, %%edx\t\n" + "ja 3f\t\n" + "cmpw $0x40, %%edx\t\n" + "jbe 3f\t\n" + "addw $0x20, %%edx\t\n" + "3:\t inc %%esi\t\n" + "inc %%esi\t\n" + "inc %%edi\t\n" + "inc %%edi\t\n" + "cmpw %%eax, %%edx\t\n" + "jne 4f\n\t" + "cmpw $00, %%eax\n\t" + "jne 1b\n\t" + "xorl %%eax,%%eax\n\t" + "jmp 5f\n" + "4:\tsbbl %%eax,%%eax\n\t" + "orw $1,%%eax\n" + "5:" + :"=a" (__res):"S" (cs),"D" (ct):"esi","edi"); + +return __res; +} + +wchar_t * wcscat(wchar_t * dest,const wchar_t * src) +{ +__asm__ __volatile__( + "cld\n\t" + "repnz\n\t" + "scasw\n\t" + "decl %1\n" + "decl %1\n\t" + "1:\tlodsw\n\t" + "stosw\n\t" + "testw %%eax,%%eax\n\t" + "jne 1b" + : // no output + :"S" (src),"D" (dest),"a" (0),"c" (0xffffffff):"esi","edi","eax","ecx"); +return dest; +} + + + + + #ifdef __MACHINE_STRING_FUNCTIONS /* * Include machine specific inline routines @@ -196,7 +272,7 @@ __asm__ __volatile__( :"S" (src),"D" (dest),"c" (count):"esi","edi","eax","ecx","memory"); return dest; } - +/* #define __HAVE_ARCH_WCSCAT inline wchar_t * wcscat(wchar_t * dest,const wchar_t * src) { @@ -210,11 +286,11 @@ __asm__ __volatile__( "stosw\n\t" "testw %%eax,%%eax\n\t" "jne 1b" - : /* no output */ + : // no output :"S" (src),"D" (dest),"a" (0),"c" (0xffffffff):"esi","edi","eax","ecx"); return dest; } - +*/ #define __HAVE_ARCH_WCSNCAT inline wchar_t * wcsncat(wchar_t * dest,const wchar_t * src,size_t count) { @@ -410,7 +486,7 @@ __asm__ __volatile__( return __res; } - +/* #define __HAVE_ARCH_WCSLEN inline size_t wcslen(const wchar_t * s) { @@ -425,7 +501,7 @@ __asm__ __volatile__( return __res; } - +*/ #define __HAVE_ARCH_WCSTOK @@ -499,7 +575,7 @@ return __res; } -#define __HAVE_ARCH_WCSNNLEN +#define __HAVE_ARCH_WCSNLEN inline size_t wcsnlen(const wchar_t * s, size_t count) { register int __res; @@ -520,7 +596,7 @@ return __res; } - +/* #define __HAVE_ARCH_WCSICMP inline int wcsicmp(const wchar_t* cs,const wchar_t * ct) { @@ -559,7 +635,7 @@ __asm__ __volatile__( return __res; } - +*/ #define __HAVE_ARCH_WCSNICMP inline int wcsnicmp(const wchar_t* cs,const wchar_t * ct, size_t count) { diff --git a/reactos/ntoskrnl/se/semgr.c b/reactos/ntoskrnl/se/semgr.c index f5c93e9543e..329c3073220 100644 --- a/reactos/ntoskrnl/se/semgr.c +++ b/reactos/ntoskrnl/se/semgr.c @@ -16,55 +16,149 @@ /* FUNCTIONS ***************************************************************/ -NTSTATUS STDCALL NtQueryInformationToken(VOID) +NTSTATUS +STDCALL +NtQueryInformationToken( + IN HANDLE TokenHandle, + IN TOKEN_INFORMATION_CLASS TokenInformationClass, + OUT PVOID TokenInformation, + IN ULONG TokenInformationLength, + OUT PULONG ReturnLength + ) { } -NTSTATUS STDCALL NtQuerySecurityObject(VOID) +NTSTATUS +STDCALL +NtQuerySecurityObject( + IN HANDLE Object, + IN CINT SecurityObjectInformationClass, + OUT PVOID SecurityObjectInformation, + IN ULONG Length, + OUT PULONG ReturnLength + ) { } -NTSTATUS STDCALL NtSetSecurityObject(VOID) +NTSTATUS +STDCALL +NtSetSecurityObject( + IN HANDLE Handle, + IN SECURITY_INFORMATION SecurityInformation, + IN PSECURITY_DESCRIPTOR SecurityDescriptor + ) { } -NTSTATUS STDCALL NtSetInformationToken(VOID) +NTSTATUS +STDCALL +NtSetInformationToken( + IN HANDLE TokenHandle, + IN TOKEN_INFORMATION_CLASS TokenInformationClass, + OUT PVOID TokenInformation, + IN ULONG TokenInformationLength + ) { } -NTSTATUS STDCALL NtPrivilegeCheck(VOID) +NTSTATUS +STDCALL +NtPrivilegeCheck( + IN HANDLE ClientToken, + IN PPRIVILEGE_SET RequiredPrivileges, + IN PBOOLEAN Result + ) { } -NTSTATUS STDCALL NtPrivilegedServiceAuditAlarm(VOID) +NTSTATUS +STDCALL +NtPrivilegedServiceAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PUNICODE_STRING ServiceName, + IN HANDLE ClientToken, + IN PPRIVILEGE_SET Privileges, + IN BOOLEAN AccessGranted + ) { } -NTSTATUS STDCALL NtPrivilegeObjectAuditAlarm(VOID) +NTSTATUS +STDCALL +NtPrivilegeObjectAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PVOID HandleId, + IN HANDLE ClientToken, + IN ULONG DesiredAccess, + IN PPRIVILEGE_SET Privileges, + IN BOOLEAN AccessGranted + ) { } -NTSTATUS STDCALL NtOpenObjectAuditAlarm(VOID) +NTSTATUS +STDCALL +NtOpenObjectAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PVOID HandleId, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN HANDLE ClientToken, + IN ULONG DesiredAccess, + IN ULONG GrantedAccess, + IN PPRIVILEGE_SET Privileges, + IN BOOLEAN ObjectCreation, + IN BOOLEAN AccessGranted, + OUT PBOOLEAN GenerateOnClose + ) { } -NTSTATUS STDCALL NtOpenProcessToken(VOID) +NTSTATUS +STDCALL +NtOpenProcessToken( + IN HANDLE ProcessHandle, + IN ACCESS_MASK DesiredAccess, + OUT PHANDLE TokenHandle + ) { } -NTSTATUS STDCALL NtOpenThreadToken(VOID) +NTSTATUS +STDCALL +NtOpenThreadToken( + IN HANDLE ThreadHandle, + IN ACCESS_MASK DesiredAccess, + IN BOOLEAN OpenAsSelf, + OUT PHANDLE TokenHandle + ) { } -NTSTATUS STDCALL NtDuplicateToken(VOID) +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 NtImpersonateClientOfPort(VOID) { } -NTSTATUS STDCALL NtImpersonateThread(VOID) +NTSTATUS +STDCALL +NtImpersonateThread( + IN HANDLE ThreadHandle, + IN HANDLE ThreadToImpersonate, + IN PSECURITY_QUALITY_OF_SERVICE SecurityQualityOfService + ) { } @@ -72,7 +166,13 @@ NTSTATUS STDCALL NtCreateToken(VOID) { } -NTSTATUS STDCALL NtDeleteObjectAuditAlarm(VOID) +NTSTATUS +STDCALL +NtDeleteObjectAuditAlarm ( + IN PUNICODE_STRING SubsystemName, + IN PVOID HandleId, + IN BOOLEAN GenerateOnClose + ) { } @@ -80,7 +180,7 @@ NTSTATUS STDCALL NtDeleteObjectAuditAlarm(VOID) NTSTATUS STDCALL NtAllocateLocallyUniqueId( - OUT PVOID LocallyUniqueId + OUT LUID *LocallyUniqueId ) { } @@ -88,28 +188,92 @@ NtAllocateLocallyUniqueId( NTSTATUS STDCALL ZwAllocateLocallyUniqueId( - OUT PVOID LocallyUniqueId + OUT LUID *LocallyUniqueId ) { } -NTSTATUS STDCALL NtAccessCheckAndAuditAlarm(VOID) +NTSTATUS +STDCALL +NtAccessCheckAndAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PHANDLE ObjectHandle, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN ACCESS_MASK DesiredAccess, + IN PGENERIC_MAPPING GenericMapping, + IN BOOLEAN ObjectCreation, + OUT PULONG GrantedAccess, + OUT PBOOLEAN AccessStatus, + OUT PBOOLEAN GenerateOnClose + ) { } -NTSTATUS STDCALL NtAdjustGroupsToken(VOID) +NTSTATUS +STDCALL +NtAdjustGroupsToken( + IN HANDLE TokenHandle, + IN BOOLEAN ResetToDefault, + IN PTOKEN_GROUPS NewState, + IN ULONG BufferLength, + OUT PTOKEN_GROUPS PreviousState OPTIONAL, + OUT PULONG ReturnLength + ) { } -NTSTATUS STDCALL NtAdjustPrivilegesToken(VOID) +NTSTATUS +STDCALL +NtAdjustPrivilegesToken( + IN HANDLE TokenHandle, + IN BOOLEAN DisableAllPrivileges, + IN PTOKEN_PRIVILEGES NewState, + IN ULONG BufferLength, + OUT PTOKEN_PRIVILEGES PreviousState, + OUT PULONG ReturnLength + ) +{ +} +NTSTATUS +STDCALL +ZwAdjustPrivilegesToken( + IN HANDLE TokenHandle, + IN BOOLEAN DisableAllPrivileges, + IN PTOKEN_PRIVILEGES NewState, + IN ULONG BufferLength, + OUT PTOKEN_PRIVILEGES PreviousState, + OUT PULONG ReturnLength + ) { } -NTSTATUS STDCALL NtAllocateUuids(VOID) +NTSTATUS +STDCALL +NtAllocateUuids( + PLARGE_INTEGER Time, + PULONG Version, // ??? + PULONG ClockCycle + ) { } -NTSTATUS STDCALL NtCloseObjectAuditAlarm(VOID) +NTSTATUS +STDCALL +ZwAllocateUuids( + PLARGE_INTEGER Time, + PULONG Version, // ??? + PULONG ClockCycle + ) +{ +} + +NTSTATUS +STDCALL +NtCloseObjectAuditAlarm( + IN PUNICODE_STRING SubsystemName, + IN PVOID HandleId, + IN BOOLEAN GenerateOnClose + ) { } @@ -118,12 +282,12 @@ STDCALL NtAccessCheck( IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN HANDLE ClientToken, - IN ULONG DesiredAcces, + IN ACCESS_MASK DesiredAcces, IN PGENERIC_MAPPING GenericMapping, OUT PRIVILEGE_SET PrivilegeSet, OUT PULONG ReturnLength, OUT PULONG GrantedAccess, - OUT PULONG AccessStatus + OUT PBOOLEAN AccessStatus ) { } @@ -133,12 +297,12 @@ STDCALL ZwAccessCheck( IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN HANDLE ClientToken, - IN ULONG DesiredAcces, + IN ACCESS_MASK DesiredAcces, IN PGENERIC_MAPPING GenericMapping, OUT PRIVILEGE_SET PrivilegeSet, OUT PULONG ReturnLength, OUT PULONG GrantedAccess, - OUT PULONG AccessStatus + OUT PBOOLEAN AccessStatus ) { }