ReactOS 0.4.16-dev-2284-g3529151
utils.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for utils.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

ULONG NTAPI BasepUnicodeStringToOemSize (IN PUNICODE_STRING String)
 
ULONG NTAPI BasepOemStringToUnicodeSize (IN PANSI_STRING String)
 
ULONG NTAPI BasepUnicodeStringToAnsiSize (IN PUNICODE_STRING String)
 
ULONG NTAPI BasepAnsiStringToUnicodeSize (IN PANSI_STRING String)
 
HANDLE WINAPI BaseGetNamedObjectDirectory (VOID)
 
VOID NTAPI BasepLocateExeLdrEntry (IN PLDR_DATA_TABLE_ENTRY Entry, IN PVOID Context, OUT BOOLEAN *StopEnumeration)
 
PUNICODE_STRING WINAPI Basep8BitStringToStaticUnicodeString (IN LPCSTR String)
 
BOOLEAN WINAPI Basep8BitStringToDynamicUnicodeString (OUT PUNICODE_STRING UnicodeString, IN LPCSTR String)
 
VOID WINAPI BasepAnsiStringToHeapUnicodeString (IN LPCSTR AnsiString, OUT LPWSTR *UnicodeString)
 
PLARGE_INTEGER WINAPI BaseFormatTimeOut (OUT PLARGE_INTEGER Timeout, IN DWORD dwMilliseconds)
 
POBJECT_ATTRIBUTES WINAPI BaseFormatObjectAttributes (OUT POBJECT_ATTRIBUTES ObjectAttributes, IN PSECURITY_ATTRIBUTES SecurityAttributes OPTIONAL, IN PUNICODE_STRING ObjectName)
 
NTSTATUS WINAPI BaseCreateStack (_In_ HANDLE hProcess, _In_opt_ SIZE_T StackCommit, _In_opt_ SIZE_T StackReserve, _Out_ PINITIAL_TEB InitialTeb)
 
VOID WINAPI BaseFreeThreadStack (_In_ HANDLE hProcess, _In_ PINITIAL_TEB InitialTeb)
 
VOID WINAPI BaseInitializeContext (IN PCONTEXT Context, IN PVOID Parameter, IN PVOID StartAddress, IN PVOID StackAddress, IN ULONG ContextType)
 
PVOID WINAPI BasepIsRealtimeAllowed (IN BOOLEAN Keep)
 
NTSTATUS WINAPI BasepMapFile (IN LPCWSTR lpApplicationName, OUT PHANDLE hSection, IN PUNICODE_STRING ApplicationName)
 
BOOLEAN WINAPI Wow64EnableWow64FsRedirection (IN BOOLEAN Wow64EnableWow64FsRedirection)
 
BOOL WINAPI Wow64DisableWow64FsRedirection (IN PVOID *OldValue)
 
BOOL WINAPI Wow64RevertWow64FsRedirection (IN PVOID OldValue)
 
VOID WINAPI SetFileApisToOEM (VOID)
 
VOID WINAPI SetFileApisToANSI (VOID)
 
BOOL WINAPI AreFileApisANSI (VOID)
 
VOID WINAPI BaseMarkFileForDelete (IN HANDLE FileHandle, IN ULONG FileAttributes)
 
NTSTATUS WINAPI BasepCheckWinSaferRestrictions (IN HANDLE UserToken, IN LPWSTR ApplicationName, IN HANDLE FileHandle, OUT PBOOLEAN InJob, OUT PHANDLE NewToken, OUT PHANDLE JobHandle)
 

Variables

UNICODE_STRING Restricted = RTL_CONSTANT_STRING(L"Restricted")
 
BOOL bIsFileApiAnsi = TRUE
 
PRTL_CONVERT_STRING Basep8BitStringToUnicodeString = RtlAnsiStringToUnicodeString
 
PRTL_CONVERT_STRINGA BasepUnicodeStringTo8BitString = RtlUnicodeStringToAnsiString
 
PRTL_COUNT_STRING BasepUnicodeStringTo8BitSize = BasepUnicodeStringToAnsiSize
 
PRTL_COUNT_STRINGA Basep8BitStringToUnicodeSize = BasepAnsiStringToUnicodeSize
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 19 of file utils.c.

Function Documentation

◆ AreFileApisANSI()

BOOL WINAPI AreFileApisANSI ( VOID  )

Definition at line 867 of file utils.c.

868{
870}
PRTL_CONVERT_STRING Basep8BitStringToUnicodeString
Definition: utils.c:27
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)

◆ BaseCreateStack()

NTSTATUS WINAPI BaseCreateStack ( _In_ HANDLE  hProcess,
_In_opt_ SIZE_T  StackCommit,
_In_opt_ SIZE_T  StackReserve,
_Out_ PINITIAL_TEB  InitialTeb 
)

Definition at line 355 of file utils.c.

360{
362 PIMAGE_NT_HEADERS Headers;
364 BOOLEAN UseGuard;
365 ULONG PageSize, AllocationGranularity, Dummy;
366 SIZE_T MinimumStackCommit, GuardPageSize;
367
368 DPRINT("BaseCreateStack(hProcess: 0x%p, Max: 0x%lx, Current: 0x%lx)\n",
369 hProcess, StackReserve, StackCommit);
370
371 /* Read page size */
373 AllocationGranularity = BaseStaticServerData->SysInfo.AllocationGranularity;
374
375 /* Get the Image Headers */
376 Headers = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress);
377 if (!Headers) return STATUS_INVALID_IMAGE_FORMAT;
378
379 if (StackReserve == 0)
380 StackReserve = Headers->OptionalHeader.SizeOfStackReserve;
381
382 if (StackCommit == 0)
383 {
384 StackCommit = Headers->OptionalHeader.SizeOfStackCommit;
385 }
386 /* Check if the commit is higher than the reserve */
387 else if (StackCommit >= StackReserve)
388 {
389 /* Grow the reserve beyond the commit, up to 1MB alignment */
390 StackReserve = ROUND_UP(StackCommit, 1024 * 1024);
391 }
392
393 /* Align everything to Page Size */
394 StackCommit = ROUND_UP(StackCommit, PageSize);
395 StackReserve = ROUND_UP(StackReserve, AllocationGranularity);
396
397 MinimumStackCommit = NtCurrentPeb()->MinimumStackCommit;
398 if ((MinimumStackCommit != 0) && (StackCommit < MinimumStackCommit))
399 {
400 StackCommit = MinimumStackCommit;
401 }
402
403 /* Check if the commit is higher than the reserve */
404 if (StackCommit >= StackReserve)
405 {
406 /* Grow the reserve beyond the commit, up to 1MB alignment */
407 StackReserve = ROUND_UP(StackCommit, 1024 * 1024);
408 }
409
410 /* Align everything to Page Size */
411 StackCommit = ROUND_UP(StackCommit, PageSize);
412 StackReserve = ROUND_UP(StackReserve, AllocationGranularity);
413
414 /* Reserve memory for the stack */
415 Stack = 0;
417 (PVOID*)&Stack,
418 0,
419 &StackReserve,
422 if (!NT_SUCCESS(Status))
423 {
424 DPRINT1("Failure to reserve stack: %lx\n", Status);
425 return Status;
426 }
427
428 /* Now set up some basic Initial TEB Parameters */
429 InitialTeb->AllocatedStackBase = (PVOID)Stack;
430 InitialTeb->StackBase = (PVOID)(Stack + StackReserve);
431 InitialTeb->PreviousStackBase = NULL;
432 InitialTeb->PreviousStackLimit = NULL;
433
434 /* Update the stack position */
435 Stack += StackReserve - StackCommit;
436
437 /* Check if we can add a guard page */
438 if (StackReserve >= StackCommit + PageSize)
439 {
440 Stack -= PageSize;
441 StackCommit += PageSize;
442 UseGuard = TRUE;
443 }
444 else
445 {
446 UseGuard = FALSE;
447 }
448
449 /* Allocate memory for the stack */
451 (PVOID*)&Stack,
452 0,
453 &StackCommit,
456 if (!NT_SUCCESS(Status))
457 {
458 DPRINT1("Failure to allocate stack\n");
459 GuardPageSize = 0;
460 NtFreeVirtualMemory(hProcess, (PVOID*)&Stack, &GuardPageSize, MEM_RELEASE);
461 return Status;
462 }
463
464 /* Now set the current Stack Limit */
465 InitialTeb->StackLimit = (PVOID)Stack;
466
467 /* Create a guard page if needed */
468 if (UseGuard)
469 {
470 GuardPageSize = PageSize;
472 (PVOID*)&Stack,
473 &GuardPageSize,
475 &Dummy);
476 if (!NT_SUCCESS(Status))
477 {
478 DPRINT1("Failure to set guard page\n");
479 return Status;
480 }
481
482 /* Update the Stack Limit keeping in mind the Guard Page */
483 InitialTeb->StackLimit = (PVOID)((ULONG_PTR)InitialTeb->StackLimit +
484 GuardPageSize);
485 }
486
487 /* We are done! */
488 return STATUS_SUCCESS;
489}
#define NtCurrentPeb()
Definition: FLS.c:22
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define RtlImageNtHeader
Definition: compat.h:806
PBASE_STATIC_SERVER_DATA BaseStaticServerData
Definition: dllmain.c:19
#define ROUND_UP(n, align)
Definition: eventvwr.h:34
Status
Definition: gdiplustypes.h:25
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
#define PAGE_READWRITE
Definition: nt_native.h:1307
#define MEM_RESERVE
Definition: nt_native.h:1317
#define MEM_RELEASE
Definition: nt_native.h:1319
#define MEM_COMMIT
Definition: nt_native.h:1316
#define PAGE_GUARD
Definition: nt_native.h:1313
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5192
NTSTATUS NTAPI NtProtectVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UnsafeBaseAddress, IN OUT SIZE_T *UnsafeNumberOfBytesToProtect, IN ULONG NewAccessProtection, OUT PULONG UnsafeOldAccessProtection)
Definition: virtual.c:3076
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4457
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:453
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
SYSTEM_BASIC_INFORMATION SysInfo
Definition: base.h:130
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639

Referenced by CreateFiberEx(), CreateProcessInternalW(), and CreateRemoteThread().

◆ BaseFormatObjectAttributes()

POBJECT_ATTRIBUTES WINAPI BaseFormatObjectAttributes ( OUT POBJECT_ATTRIBUTES  ObjectAttributes,
IN PSECURITY_ATTRIBUTES SecurityAttributes  OPTIONAL,
IN PUNICODE_STRING  ObjectName 
)

Definition at line 305 of file utils.c.

308{
312 DPRINT("BaseFormatObjectAttributes. Security: %p, Name: %p\n",
313 SecurityAttributes, ObjectName);
314
315 /* Get the attributes if present */
316 if (SecurityAttributes)
317 {
318 Attributes = SecurityAttributes->bInheritHandle ? OBJ_INHERIT : 0;
319 SecurityDescriptor = SecurityAttributes->lpSecurityDescriptor;
320 }
321 else
322 {
323 if (!ObjectName) return NULL;
324 Attributes = 0;
326 }
327
328 if (ObjectName)
329 {
332 }
333 else
334 {
336 }
337
338 /* Create the Object Attributes */
344 DPRINT("Attributes: %lx, RootDirectory: %p, SecurityDescriptor: %p\n",
346 return ObjectAttributes;
347}
WCHAR RootDirectory[MAX_PATH]
Definition: format.c:74
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
HANDLE WINAPI BaseGetNamedObjectDirectory(VOID)
Definition: utils.c:64
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_INHERIT
Definition: winternl.h:225
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:191
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:64

Referenced by CreateFileMappingW(), CreateProcessInternalW(), and CreateRemoteThread().

◆ BaseFormatTimeOut()

PLARGE_INTEGER WINAPI BaseFormatTimeOut ( OUT PLARGE_INTEGER  Timeout,
IN DWORD  dwMilliseconds 
)

Definition at line 289 of file utils.c.

291{
292 /* Check if this is an infinite wait, which means no timeout argument */
293 if (dwMilliseconds == INFINITE) return NULL;
294
295 /* Otherwise, convert the time to NT Format */
296 Timeout->QuadPart = dwMilliseconds * -10000LL;
297 return Timeout;
298}
#define INFINITE
Definition: serial.h:102
static ULONG Timeout
Definition: ping.c:61

Referenced by GetQueuedCompletionStatus(), SignalObjectAndWait(), SleepEx(), WaitForDebugEvent(), WaitForMultipleObjectsEx(), and WaitForSingleObjectEx().

◆ BaseFreeThreadStack()

VOID WINAPI BaseFreeThreadStack ( _In_ HANDLE  hProcess,
_In_ PINITIAL_TEB  InitialTeb 
)

Definition at line 496 of file utils.c.

499{
500 SIZE_T Dummy = 0;
501
502 /* Free the Stack */
504 &InitialTeb->AllocatedStackBase,
505 &Dummy,
507}

Referenced by CreateRemoteThread().

◆ BaseGetNamedObjectDirectory()

HANDLE WINAPI BaseGetNamedObjectDirectory ( VOID  )

Definition at line 64 of file utils.c.

65{
68 HANDLE DirHandle, BnoHandle, Token, NewToken;
69
71
72 if (NtCurrentTeb()->IsImpersonating)
73 {
76 TRUE,
77 &Token);
79
80 NewToken = NULL;
83 &NewToken,
84 sizeof(HANDLE));
85 if (!NT_SUCCESS (Status))
86 {
89 }
90 }
91 else
92 {
93 Token = NULL;
94 }
95
97 if (BaseNamedObjectDirectory) goto Quickie;
98
102 NULL,
103 NULL);
104
105 Status = NtOpenDirectoryObject(&BnoHandle,
111 if (!NT_SUCCESS(Status))
112 {
113 Status = NtOpenDirectoryObject(&DirHandle,
116
117 if (NT_SUCCESS(Status))
118 {
122 DirHandle,
123 NULL);
124
125 Status = NtOpenDirectoryObject(&BnoHandle,
131 NtClose(DirHandle);
132
133 }
134 }
135
137
138Quickie:
139
141
142 if (Token)
143 {
146 &Token,
147 sizeof(Token));
148
149 NtClose(Token);
150 }
151
153}
@ ThreadImpersonationToken
Definition: compat.h:940
HANDLE BaseNamedObjectDirectory
Definition: dllmain.c:24
UNICODE_STRING Restricted
Definition: utils.c:24
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI void WINAPI RtlReleasePebLock(void)
Definition: libsupp.c:84
NTSYSAPI void WINAPI RtlAcquirePebLock(void)
Definition: libsupp.c:74
#define NtCurrentThread()
Definition: winternl.h:5368
#define NtCurrentTeb
#define DIRECTORY_CREATE_OBJECT
Definition: nt_native.h:1259
#define DIRECTORY_QUERY
Definition: nt_native.h:1257
#define DIRECTORY_TRAVERSE
Definition: nt_native.h:1258
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define DIRECTORY_CREATE_SUBDIRECTORY
Definition: nt_native.h:1260
NTSTATUS NTAPI NtSetInformationThread(_In_ HANDLE ThreadHandle, _In_ THREADINFOCLASS ThreadInformationClass, _In_reads_bytes_(ThreadInformationLength) PVOID ThreadInformation, _In_ ULONG ThreadInformationLength)
Definition: query.c:2268
NTSTATUS NTAPI NtOpenThreadToken(_In_ HANDLE ThreadHandle, _In_ ACCESS_MASK DesiredAccess, _In_ BOOLEAN OpenAsSelf, _Out_ PHANDLE TokenHandle)
Opens a token that is tied to a thread handle.
Definition: token.c:2475
NTSTATUS NTAPI NtOpenDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:393
UNICODE_STRING NamedObjectDirectory
Definition: base.h:123
#define TOKEN_IMPERSONATE
Definition: setypes.h:939

Referenced by BaseFormatObjectAttributes(), and OpenFileMappingW().

◆ BaseInitializeContext()

VOID WINAPI BaseInitializeContext ( IN PCONTEXT  Context,
IN PVOID  Parameter,
IN PVOID  StartAddress,
IN PVOID  StackAddress,
IN ULONG  ContextType 
)

Definition at line 514 of file utils.c.

519{
520#ifdef _M_IX86
521 ULONG ContextFlags;
522 DPRINT("BaseInitializeContext: %p\n", Context);
523
524 /* Setup the Initial Win32 Thread Context */
525 Context->Eax = (ULONG)StartAddress;
526 Context->Ebx = (ULONG)Parameter;
527 Context->Esp = (ULONG)StackAddress;
528 /* The other registers are undefined */
529
530 /* Setup the Segments */
531 Context->SegFs = KGDT_R3_TEB;
532 Context->SegEs = KGDT_R3_DATA;
533 Context->SegDs = KGDT_R3_DATA;
534 Context->SegCs = KGDT_R3_CODE;
535 Context->SegSs = KGDT_R3_DATA;
536 Context->SegGs = 0;
537
538 /* Set the Context Flags */
539 ContextFlags = Context->ContextFlags;
540 Context->ContextFlags = CONTEXT_FULL;
541
542 /* Give it some room for the Parameter */
543 Context->Esp -= sizeof(PVOID);
544
545 /* Set the EFLAGS */
546 Context->EFlags = 0x3000; /* IOPL 3 */
547
548 /* What kind of context is being created? */
549 if (ContextType == 1)
550 {
551 /* For Threads */
553 }
554 else if (ContextType == 2)
555 {
556 /* This is a fiber: make space for the return address */
557 Context->Esp -= sizeof(PVOID);
558 *((PVOID*)Context->Esp) = BaseFiberStartup;
559
560 /* Is FPU state required? */
561 Context->ContextFlags |= ContextFlags;
562 if ((ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT)
563 {
564 /* Set an initial state */
565 Context->FloatSave.ControlWord = 0x27F;
566 Context->FloatSave.StatusWord = 0;
567 Context->FloatSave.TagWord = 0xFFFF;
568 Context->FloatSave.ErrorOffset = 0;
569 Context->FloatSave.ErrorSelector = 0;
570 Context->FloatSave.DataOffset = 0;
571 Context->FloatSave.DataSelector = 0;
572 if (SharedUserData->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE])
573 Context->Dr6 = 0x1F80;
574 }
575 }
576 else
577 {
578 /* For first thread in a Process */
580 }
581
582#elif defined(_M_AMD64)
583 DPRINT("BaseInitializeContext: %p\n", Context);
584 ASSERT(((ULONG_PTR)StackAddress & 15) == 0);
585
586 RtlZeroMemory(Context, sizeof(*Context));
587
588 /* Setup the Initial Win32 Thread Context */
589 Context->Rcx = (ULONG_PTR)StartAddress;
591 Context->Rsp = (ULONG_PTR)StackAddress - 5 * sizeof(PVOID);
592
593 /* Setup the Segments */
600
601 /* Set the EFLAGS */
602 Context->EFlags = 0x3000 | EFLAGS_INTERRUPT_MASK; /* IOPL 3 */
603
604 /* Set MXCSR */
605 Context->MxCsr = INITIAL_MXCSR;
606
607 if (ContextType == 1) /* For Threads */
608 {
610 }
611 else if (ContextType == 2) /* For Fibers */
612 {
614 }
615 else /* For first thread in a Process */
616 {
618 }
619
620 /* Set the Context Flags */
621 Context->ContextFlags = CONTEXT_FULL;
622#elif defined(_M_ARM)
623 DPRINT("BaseInitializeContext: %p\n", Context);
624
625 // FIXME: check if this is correct!
626 /* Setup the Initial Win32 Thread Context */
627 Context->R0 = (ULONG_PTR)StartAddress;
629 Context->Sp = (ULONG_PTR)StackAddress;
630
631 if (ContextType == 1) /* For Threads */
632 {
634 }
635 else if (ContextType == 2) /* For Fibers */
636 {
638 }
639 else /* For first thread in a Process */
640 {
642 }
643
644 /* Set the Context Flags */
645 Context->ContextFlags = CONTEXT_FULL;
646
647 /* Give it some room for the Parameter */
648 Context->Sp -= sizeof(PVOID);
649#else
650#warning Unknown architecture
653#endif
654}
#define EFLAGS_INTERRUPT_MASK
Definition: SystemCall.c:11
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
DECLSPEC_NORETURN VOID WINAPI BaseProcessStartup(_In_ PPROCESS_START_ROUTINE lpStartAddress)
Definition: proc.c:449
DECLSPEC_NORETURN VOID WINAPI BaseThreadStartup(_In_ LPTHREAD_START_ROUTINE lpStartAddress, _In_ LPVOID lpParameter)
Definition: thread.c:56
#define ULONG_PTR
Definition: config.h:101
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE ContextType
Definition: fltkernel.h:1443
NTSYSAPI void WINAPI DbgBreakPoint(void)
VOID WINAPI BaseThreadStartupThunk(VOID)
DECLSPEC_NORETURN VOID WINAPI BaseFiberStartup(VOID)
VOID WINAPI BaseProcessStartThunk(VOID)
#define ASSERT(a)
Definition: mode.c:44
#define KGDT64_R3_CODE
Definition: ketypes.h:131
#define KGDT64_R3_DATA
Definition: ketypes.h:130
#define KGDT64_R3_CMTEB
Definition: ketypes.h:133
#define RPL_MASK
Definition: ketypes.h:124
#define KGDT_R3_DATA
Definition: ketypes.h:126
#define KGDT_R3_CODE
Definition: ketypes.h:125
#define KGDT_R3_TEB
Definition: ketypes.h:129
#define CONTEXT_FLOATING_POINT
Definition: nt_native.h:1375
#define CONTEXT_FULL
Definition: nt_native.h:1378
#define SharedUserData
#define INITIAL_MXCSR
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define PF_XMMI_INSTRUCTIONS_AVAILABLE
Definition: ketypes.h:182
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336

Referenced by CreateFiberEx(), CreateProcessInternalW(), and CreateRemoteThread().

◆ BaseMarkFileForDelete()

VOID WINAPI BaseMarkFileForDelete ( IN HANDLE  FileHandle,
IN ULONG  FileAttributes 
)

Definition at line 877 of file utils.c.

879{
883
884 /* If no attributes were given, get them */
885 if (!FileAttributes)
886 {
887 FileBasicInfo.FileAttributes = 0;
891 sizeof(FileBasicInfo),
893 FileAttributes = FileBasicInfo.FileAttributes;
894 }
895
896 /* If file is marked as RO, reset its attributes */
898 {
900 FileBasicInfo.FileAttributes = FILE_ATTRIBUTE_NORMAL;
904 sizeof(FileBasicInfo),
906 }
907
908 /* Finally, mark the file for deletion */
909 FileDispositionInfo.DeleteFile = TRUE;
913 sizeof(FileDispositionInfo),
915}
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG FileAttributes
Definition: fltkernel.h:1236
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
@ FileBasicInformation
Definition: from_kernel.h:65
@ FileDispositionInformation
Definition: from_kernel.h:74
@ FileDispositionInfo
Definition: minwinbase.h:308
@ FileBasicInfo
Definition: minwinbase.h:304
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
NTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
Definition: iofunc.c:3096
NTSYSAPI NTSTATUS NTAPI NtQueryInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, OUT PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75

Referenced by CreateDirectoryExW().

◆ Basep8BitStringToDynamicUnicodeString()

BOOLEAN WINAPI Basep8BitStringToDynamicUnicodeString ( OUT PUNICODE_STRING  UnicodeString,
IN LPCSTR  String 
)

Definition at line 226 of file utils.c.

228{
231
232 /* Initialize an ANSI String */
234 if (!NT_SUCCESS(Status))
235 {
237 }
238 else
239 {
240 /* Convert it */
242 }
243
244 if (NT_SUCCESS(Status)) return TRUE;
245
247 {
249 }
250 else
251 {
253 }
254
255 return FALSE;
256}
#define SetLastError(x)
Definition: compat.h:752
@ AnsiString
Definition: dnslib.h:19
NTSYSAPI NTSTATUS WINAPI RtlInitAnsiStringEx(PANSI_STRING, PCSZ)
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2439
#define ERROR_FILENAME_EXCED_RANGE
Definition: winerror.h:385

Referenced by CopyFileA(), CopyFileExA(), CreateDirectoryExA(), CreateHardLinkA(), GetFullPathNameA(), GetLongPathNameA(), GetShortPathNameA(), GetTempFileNameA(), MoveFileWithProgressA(), ReplaceFileA(), SearchPathA(), SetVolumeLabelA(), and WaitNamedPipeA().

◆ Basep8BitStringToStaticUnicodeString()

◆ BasepAnsiStringToHeapUnicodeString()

VOID WINAPI BasepAnsiStringToHeapUnicodeString ( IN LPCSTR  AnsiString,
OUT LPWSTR UnicodeString 
)

Definition at line 264 of file utils.c.

266{
267 ANSI_STRING AnsiTemp;
268 UNICODE_STRING UnicodeTemp;
269
270 DPRINT("BasepAnsiStringToHeapUnicodeString\n");
271
272 /* First create the ANSI_STRING */
273 RtlInitAnsiString(&AnsiTemp, AnsiString);
274
276 &AnsiTemp,
277 TRUE)))
278 {
279 *UnicodeString = UnicodeTemp.Buffer;
280 }
281 else
282 {
284 }
285}
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)

◆ BasepAnsiStringToUnicodeSize()

ULONG NTAPI BasepAnsiStringToUnicodeSize ( IN PANSI_STRING  String)

Definition at line 57 of file utils.c.

58{
60}
#define RtlAnsiStringToUnicodeSize(STRING)
Definition: nt_native.h:404

Referenced by SetFileApisToANSI().

◆ BasepCheckWinSaferRestrictions()

NTSTATUS WINAPI BasepCheckWinSaferRestrictions ( IN HANDLE  UserToken,
IN LPWSTR  ApplicationName,
IN HANDLE  FileHandle,
OUT PBOOLEAN  InJob,
OUT PHANDLE  NewToken,
OUT PHANDLE  JobHandle 
)

Definition at line 922 of file utils.c.

928{
930
931 /* Validate that there's a name */
933 {
934 /* Validate that the required output parameters are there */
935 if ((InJob) && (NewToken) && (JobHandle))
936 {
937 /* Do the work (one day...) */
938 DPRINT("BasepCheckWinSaferRestrictions is UNIMPLEMENTED\n");
940 }
941 else
942 {
943 /* Act as if SEH hit this */
945 }
946 }
947 else
948 {
949 /* Input is invalid */
951 }
952
953 /* Return the status */
954 return Status;
955}
#define STATUS_ACCESS_VIOLATION
PVOID PVOID PWCHAR ApplicationName
Definition: env.c:47
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

Referenced by CreateProcessInternalW().

◆ BasepIsRealtimeAllowed()

PVOID WINAPI BasepIsRealtimeAllowed ( IN BOOLEAN  Keep)

Definition at line 666 of file utils.c.

667{
669 PVOID State;
671
673 if (!NT_SUCCESS(Status)) return NULL;
674
675 if (!Keep)
676 {
678 State = (PVOID)TRUE;
679 }
680
681 return State;
682}
#define SE_INC_BASE_PRIORITY_PRIVILEGE
Definition: security.c:668
NTSYSAPI NTSTATUS NTAPI RtlAcquirePrivilege(_In_ PULONG Privilege, _In_ ULONG NumPriv, _In_ ULONG Flags, _Out_ PVOID *ReturnedState)
NTSYSAPI VOID NTAPI RtlReleasePrivilege(_In_ PVOID ReturnedState)
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
Definition: user_lib.cpp:531

Referenced by CreateProcessInternalW(), and SetPriorityClass().

◆ BasepLocateExeLdrEntry()

VOID NTAPI BasepLocateExeLdrEntry ( IN PLDR_DATA_TABLE_ENTRY  Entry,
IN PVOID  Context,
OUT BOOLEAN StopEnumeration 
)

Definition at line 157 of file utils.c.

160{
161 /* Make sure we get Entry, Context and valid StopEnumeration pointer */
162 ASSERT(Entry);
164 ASSERT(StopEnumeration);
165
166 /* If entry is already found - signal to stop */
168 {
169 *StopEnumeration = TRUE;
170 return;
171 }
172
173 /* Otherwise keep enumerating until we find a match */
174 if (Entry->DllBase == Context)
175 {
176 /* It matches, so remember the ldr entry */
178
179 /* And stop enumeration */
180 *StopEnumeration = TRUE;
181 }
182}
PLDR_DATA_TABLE_ENTRY BasepExeLdrEntry
Definition: proc.c:23
base of all file and directory entries
Definition: entries.h:83

Referenced by BasepComputeProcessPath(), and LoadLibraryExW().

◆ BasepMapFile()

NTSTATUS WINAPI BasepMapFile ( IN LPCWSTR  lpApplicationName,
OUT PHANDLE  hSection,
IN PUNICODE_STRING  ApplicationName 
)

Definition at line 689 of file utils.c.

692{
693 RTL_RELATIVE_NAME_U RelativeName;
696 HANDLE hFile = NULL;
698
699 DPRINT("BasepMapFile\n");
700
701 /* Zero out the Relative Directory */
702 RelativeName.ContainingDirectory = NULL;
703
704 /* Find the application name */
705 if (!RtlDosPathNameToNtPathName_U(lpApplicationName,
707 NULL,
708 &RelativeName))
709 {
711 }
712
713 DPRINT("ApplicationName %wZ\n", ApplicationName);
714 DPRINT("RelativeName %wZ\n", &RelativeName.RelativeName);
715
716 /* Did we get a relative name? */
717 if (RelativeName.RelativeName.Length)
718 {
719 ApplicationName = &RelativeName.RelativeName;
720 }
721
722 /* Initialize the Object Attributes */
726 RelativeName.ContainingDirectory,
727 NULL);
728
729 /* Try to open the executable */
736 if (!NT_SUCCESS(Status))
737 {
738 DPRINT1("Failed to open file\n");
740 return Status;
741 }
742
743 /* Create a section for this file */
746 NULL,
747 NULL,
749 SEC_IMAGE,
750 hFile);
751 NtClose(hFile);
752
753 /* Return status */
754 DPRINT("Section: %p for file: %p\n", *hSection, hFile);
755 return Status;
756}
NTSTATUS NTAPI NtCreateSection(OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize OPTIONAL, IN ULONG SectionPageProtection OPTIONAL, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL)
Definition: section.c:3076
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define FILE_SHARE_READ
Definition: compat.h:136
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
_In_ HANDLE hFile
Definition: mswsock.h:90
#define SEC_IMAGE
Definition: mmtypes.h:97
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3953
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_READ_DATA
Definition: nt_native.h:628
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1296
#define PAGE_EXECUTE
Definition: nt_native.h:1309
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define FILE_EXECUTE
Definition: nt_native.h:642
UNICODE_STRING RelativeName
Definition: rtltypes.h:1374
HANDLE ContainingDirectory
Definition: rtltypes.h:1375
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: udferr_usr.h:151
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3685

◆ BasepOemStringToUnicodeSize()

ULONG NTAPI BasepOemStringToUnicodeSize ( IN PANSI_STRING  String)

Definition at line 43 of file utils.c.

44{
46}
#define RtlOemStringToUnicodeSize(STRING)

Referenced by SetFileApisToOEM().

◆ BasepUnicodeStringToAnsiSize()

ULONG NTAPI BasepUnicodeStringToAnsiSize ( IN PUNICODE_STRING  String)

Definition at line 50 of file utils.c.

51{
53}
#define RtlUnicodeStringToAnsiSize(String)
Definition: rtlfuncs.h:1022

Referenced by SetFileApisToANSI().

◆ BasepUnicodeStringToOemSize()

ULONG NTAPI BasepUnicodeStringToOemSize ( IN PUNICODE_STRING  String)

Definition at line 36 of file utils.c.

37{
39}
#define RtlUnicodeStringToOemSize(STRING)

Referenced by SetFileApisToOEM().

◆ SetFileApisToANSI()

VOID WINAPI SetFileApisToANSI ( VOID  )

Definition at line 850 of file utils.c.

851{
852 /* Set the correct Base Api */
857
858 /* FIXME: Old, deprecated way */
860}
PRTL_CONVERT_STRINGA BasepUnicodeStringTo8BitString
Definition: utils.c:28
PRTL_COUNT_STRINGA Basep8BitStringToUnicodeSize
Definition: utils.c:30
PRTL_COUNT_STRING BasepUnicodeStringTo8BitSize
Definition: utils.c:29
ULONG NTAPI BasepAnsiStringToUnicodeSize(IN PANSI_STRING String)
Definition: utils.c:57
ULONG NTAPI BasepUnicodeStringToAnsiSize(IN PUNICODE_STRING String)
Definition: utils.c:50
BOOL bIsFileApiAnsi
Definition: utils.c:25
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)

◆ SetFileApisToOEM()

VOID WINAPI SetFileApisToOEM ( VOID  )

Definition at line 832 of file utils.c.

833{
834 /* Set the correct Base Api */
839
840 /* FIXME: Old, deprecated way */
842}
ULONG NTAPI BasepUnicodeStringToOemSize(IN PUNICODE_STRING String)
Definition: utils.c:36
ULONG NTAPI BasepOemStringToUnicodeSize(IN PANSI_STRING String)
Definition: utils.c:43
NTSTATUS(NTAPI * PRTL_CONVERT_STRING)(IN PUNICODE_STRING UnicodeString, IN PANSI_STRING AnsiString, IN BOOLEAN AllocateMemory)
Definition: kernel32.h:272
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToOemString(POEM_STRING DestinationString, PCUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI NTSTATUS NTAPI RtlOemStringToUnicodeString(PUNICODE_STRING DestinationString, PCOEM_STRING SourceString, BOOLEAN AllocateDestinationString)

◆ Wow64DisableWow64FsRedirection()

BOOL WINAPI Wow64DisableWow64FsRedirection ( IN PVOID OldValue)

Definition at line 786 of file utils.c.

787{
789 BOOL Result;
790
792 if (NT_SUCCESS(Status))
793 {
794 Result = TRUE;
795 }
796 else
797 {
799 Result = FALSE;
800 }
801 return Result;
802}
NTSYSAPI NTSTATUS NTAPI RtlWow64EnableFsRedirectionEx(IN PVOID Wow64FsEnableRedirection, OUT PVOID *OldFsRedirectionLevel)
Definition: libsupp.c:1178
unsigned int BOOL
Definition: ntddk_ex.h:94
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by alloc_console(), create_pseudo_console(), custom_start_server(), get_systemdirectory(), msi_disable_fs_redirection(), run_winemenubuilder(), and test_wow64().

◆ Wow64EnableWow64FsRedirection()

BOOLEAN WINAPI Wow64EnableWow64FsRedirection ( IN BOOLEAN  Wow64EnableWow64FsRedirection)

Definition at line 763 of file utils.c.

764{
766 BOOL Result;
767
769 if (NT_SUCCESS(Status))
770 {
771 Result = TRUE;
772 }
773 else
774 {
776 Result = FALSE;
777 }
778 return Result;
779}
NTSYSAPI NTSTATUS NTAPI RtlWow64EnableFsRedirection(IN BOOLEAN Wow64FsEnableRedirection)
Definition: libsupp.c:1166
BOOLEAN WINAPI Wow64EnableWow64FsRedirection(IN BOOLEAN Wow64EnableWow64FsRedirection)
Definition: utils.c:763

Referenced by Wow64EnableWow64FsRedirection().

◆ Wow64RevertWow64FsRedirection()

BOOL WINAPI Wow64RevertWow64FsRedirection ( IN PVOID  OldValue)

Definition at line 809 of file utils.c.

810{
812 BOOL Result;
813
814 Status = RtlWow64EnableFsRedirectionEx(OldValue, &OldValue);
815 if (NT_SUCCESS(Status))
816 {
817 Result = TRUE;
818 }
819 else
820 {
822 Result = FALSE;
823 }
824 return Result;
825}

Referenced by alloc_console(), create_pseudo_console(), custom_start_server(), get_systemdirectory(), msi_revert_fs_redirection(), run_winemenubuilder(), and test_wow64().

Variable Documentation

◆ Basep8BitStringToUnicodeSize

PRTL_COUNT_STRINGA Basep8BitStringToUnicodeSize = BasepAnsiStringToUnicodeSize

Definition at line 30 of file utils.c.

Referenced by SetFileApisToANSI(), and SetFileApisToOEM().

◆ Basep8BitStringToUnicodeString

◆ BasepUnicodeStringTo8BitSize

PRTL_COUNT_STRING BasepUnicodeStringTo8BitSize = BasepUnicodeStringToAnsiSize

Definition at line 29 of file utils.c.

Referenced by GetDllDirectoryA(), SetFileApisToANSI(), and SetFileApisToOEM().

◆ BasepUnicodeStringTo8BitString

◆ bIsFileApiAnsi

BOOL bIsFileApiAnsi = TRUE

Definition at line 25 of file utils.c.

Referenced by CheckNameLegalDOS8Dot3A(), OpenFile(), SetFileApisToANSI(), and SetFileApisToOEM().

◆ Restricted

UNICODE_STRING Restricted = RTL_CONSTANT_STRING(L"Restricted")

Definition at line 24 of file utils.c.

Referenced by BaseGetNamedObjectDirectory(), SepCompareTokens(), and SepSidInTokenEx().