ReactOS 0.4.17-dev-1190-g4c812f4
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)
 
NTSTATUS WINAPI BaseGetNamedObjectDirectory (_Out_ PHANDLE DirectoryHandle)
 
HANDLE WINAPI BasepGetNamedObjectDirectory (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, OUT 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 894 of file utils.c.

895{
897}
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 381 of file utils.c.

386{
388 PIMAGE_NT_HEADERS Headers;
390 BOOLEAN UseGuard;
391 ULONG PageSize, AllocationGranularity, Dummy;
392 SIZE_T MinimumStackCommit, GuardPageSize;
393
394 DPRINT("BaseCreateStack(hProcess: 0x%p, Max: 0x%lx, Current: 0x%lx)\n",
395 hProcess, StackReserve, StackCommit);
396
397 /* Read page size */
399 AllocationGranularity = BaseStaticServerData->SysInfo.AllocationGranularity;
400
401 /* Get the Image Headers */
402 Headers = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress);
403 if (!Headers) return STATUS_INVALID_IMAGE_FORMAT;
404
405 if (StackReserve == 0)
406 StackReserve = Headers->OptionalHeader.SizeOfStackReserve;
407
408 if (StackCommit == 0)
409 {
410 StackCommit = Headers->OptionalHeader.SizeOfStackCommit;
411 }
412 /* Check if the commit is higher than the reserve */
413 else if (StackCommit >= StackReserve)
414 {
415 /* Grow the reserve beyond the commit, up to 1MB alignment */
416 StackReserve = ROUND_UP(StackCommit, 1024 * 1024);
417 }
418
419 /* Align everything to Page Size */
420 StackCommit = ROUND_UP(StackCommit, PageSize);
421 StackReserve = ROUND_UP(StackReserve, AllocationGranularity);
422
423 MinimumStackCommit = NtCurrentPeb()->MinimumStackCommit;
424 if ((MinimumStackCommit != 0) && (StackCommit < MinimumStackCommit))
425 {
426 StackCommit = MinimumStackCommit;
427 }
428
429 /* Check if the commit is higher than the reserve */
430 if (StackCommit >= StackReserve)
431 {
432 /* Grow the reserve beyond the commit, up to 1MB alignment */
433 StackReserve = ROUND_UP(StackCommit, 1024 * 1024);
434 }
435
436 /* Align everything to Page Size */
437 StackCommit = ROUND_UP(StackCommit, PageSize);
438 StackReserve = ROUND_UP(StackReserve, AllocationGranularity);
439
440 /* Reserve memory for the stack */
441 Stack = 0;
443 (PVOID*)&Stack,
444 0,
445 &StackReserve,
448 if (!NT_SUCCESS(Status))
449 {
450 DPRINT1("Failure to reserve stack: %lx\n", Status);
451 return Status;
452 }
453
454 /* Now set up some basic Initial TEB Parameters */
455 InitialTeb->AllocatedStackBase = (PVOID)Stack;
456 InitialTeb->StackBase = (PVOID)(Stack + StackReserve);
457 InitialTeb->PreviousStackBase = NULL;
458 InitialTeb->PreviousStackLimit = NULL;
459
460 /* Update the stack position */
461 Stack += StackReserve - StackCommit;
462
463 /* Check if we can add a guard page */
464 if (StackReserve >= StackCommit + PageSize)
465 {
466 Stack -= PageSize;
467 StackCommit += PageSize;
468 UseGuard = TRUE;
469 }
470 else
471 {
472 UseGuard = FALSE;
473 }
474
475 /* Allocate memory for the stack */
477 (PVOID*)&Stack,
478 0,
479 &StackCommit,
482 if (!NT_SUCCESS(Status))
483 {
484 DPRINT1("Failure to allocate stack\n");
485 GuardPageSize = 0;
486 NtFreeVirtualMemory(hProcess, (PVOID*)&Stack, &GuardPageSize, MEM_RELEASE);
487 return Status;
488 }
489
490 /* Now set the current Stack Limit */
491 InitialTeb->StackLimit = (PVOID)Stack;
492
493 /* Create a guard page if needed */
494 if (UseGuard)
495 {
496 GuardPageSize = PageSize;
498 (PVOID*)&Stack,
499 &GuardPageSize,
501 &Dummy);
502 if (!NT_SUCCESS(Status))
503 {
504 DPRINT1("Failure to set guard page\n");
505 return Status;
506 }
507
508 /* Update the Stack Limit keeping in mind the Guard Page */
509 InitialTeb->StackLimit = (PVOID)((ULONG_PTR)InitialTeb->StackLimit +
510 GuardPageSize);
511 }
512
513 /* We are done! */
514 return STATUS_SUCCESS;
515}
#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:24
_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 331 of file utils.c.

334{
338 DPRINT("BaseFormatObjectAttributes. Security: %p, Name: %p\n",
339 SecurityAttributes, ObjectName);
340
341 /* Get the attributes if present */
342 if (SecurityAttributes)
343 {
344 Attributes = SecurityAttributes->bInheritHandle ? OBJ_INHERIT : 0;
345 SecurityDescriptor = SecurityAttributes->lpSecurityDescriptor;
346 }
347 else
348 {
349 if (!ObjectName) return NULL;
350 Attributes = 0;
352 }
353
354 if (ObjectName)
355 {
358 }
359 else
360 {
362 }
363
364 /* Create the Object Attributes */
370 DPRINT("Attributes: %lx, RootDirectory: %p, SecurityDescriptor: %p\n",
372 return ObjectAttributes;
373}
WCHAR RootDirectory[MAX_PATH]
Definition: format.c:73
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
_In_ ULONG Attributes
Definition: dispmprt.h:1077
HANDLE WINAPI BasepGetNamedObjectDirectory(VOID)
Definition: utils.c:167
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_INHERIT
Definition: winternl.h:225
_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 315 of file utils.c.

317{
318 /* Check if this is an infinite wait, which means no timeout argument */
319 if (dwMilliseconds == INFINITE) return NULL;
320
321 /* Otherwise, convert the time to NT Format */
322 Timeout->QuadPart = dwMilliseconds * -10000LL;
323 return Timeout;
324}
#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 522 of file utils.c.

525{
526 SIZE_T Dummy = 0;
527
528 /* Free the Stack */
530 &InitialTeb->AllocatedStackBase,
531 &Dummy,
533}

Referenced by CreateRemoteThread().

◆ BaseGetNamedObjectDirectory()

NTSTATUS WINAPI BaseGetNamedObjectDirectory ( _Out_ PHANDLE  DirectoryHandle)

Definition at line 64 of file utils.c.

66{
69 HANDLE DirHandle, BnoHandle, Token, NewToken;
70
72
74 {
75 return STATUS_SUCCESS;
76 }
77
78 if (NtCurrentTeb()->IsImpersonating)
79 {
82 TRUE,
83 &Token);
84 if (!NT_SUCCESS(Status))
85 {
86 return Status;
87 }
88
89 NewToken = NULL;
92 &NewToken,
93 sizeof(HANDLE));
94 if (!NT_SUCCESS (Status))
95 {
97 return Status;
98 }
99 }
100 else
101 {
102 Token = NULL;
103 }
104
106 if (BaseNamedObjectDirectory) goto Quickie;
107
111 NULL,
112 NULL);
113
114 Status = NtOpenDirectoryObject(&BnoHandle,
120 if (!NT_SUCCESS(Status))
121 {
122 Status = NtOpenDirectoryObject(&DirHandle,
125
126 if (NT_SUCCESS(Status))
127 {
131 DirHandle,
132 NULL);
133
134 Status = NtOpenDirectoryObject(&BnoHandle,
140 NtClose(DirHandle);
141
142 }
143 }
144
146
147Quickie:
148
150
151 if (Token)
152 {
155 &Token,
156 sizeof(Token));
157
158 NtClose(Token);
159 }
160
162 return STATUS_SUCCESS;
163}
static HANDLE DirectoryHandle
Definition: ObType.cpp:48
@ ThreadImpersonationToken
Definition: compat.h:940
HANDLE BaseNamedObjectDirectory
Definition: dllmain.c:24
UNICODE_STRING Restricted
Definition: utils.c:24
#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:3434
#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:2301
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
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
UNICODE_STRING NamedObjectDirectory
Definition: base.h:123
NTSYSAPI void WINAPI RtlReleasePebLock(void)
Definition: libsupp.c:95
NTSYSAPI void WINAPI RtlAcquirePebLock(void)
Definition: libsupp.c:85
#define NtCurrentThread()
Definition: winternl.h:5372
#define TOKEN_IMPERSONATE
Definition: setypes.h:939

Referenced by BasepGetNamedObjectDirectory().

◆ BaseInitializeContext()

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

Definition at line 540 of file utils.c.

545{
546#ifdef _M_IX86
547 ULONG ContextFlags;
548 DPRINT("BaseInitializeContext: %p\n", Context);
549
550 /* Setup the Initial Win32 Thread Context */
551 Context->Eax = (ULONG)StartAddress;
552 Context->Ebx = (ULONG)Parameter;
553 Context->Esp = (ULONG)StackAddress;
554 /* The other registers are undefined */
555
556 /* Setup the Segments */
557 Context->SegFs = KGDT_R3_TEB;
558 Context->SegEs = KGDT_R3_DATA;
559 Context->SegDs = KGDT_R3_DATA;
560 Context->SegCs = KGDT_R3_CODE;
561 Context->SegSs = KGDT_R3_DATA;
562 Context->SegGs = 0;
563
564 /* Set the Context Flags */
565 ContextFlags = Context->ContextFlags;
566 Context->ContextFlags = CONTEXT_FULL;
567
568 /* Give it some room for the Parameter */
569 Context->Esp -= sizeof(PVOID);
570
571 /* Set the EFLAGS */
572 Context->EFlags = 0x3000; /* IOPL 3 */
573
574 /* What kind of context is being created? */
575 if (ContextType == 1)
576 {
577 /* For Threads */
579 }
580 else if (ContextType == 2)
581 {
582 /* This is a fiber: make space for the return address */
583 Context->Esp -= sizeof(PVOID);
584 *((PVOID*)Context->Esp) = BaseFiberStartup;
585
586 /* Is FPU state required? */
587 Context->ContextFlags |= ContextFlags;
588 if ((ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT)
589 {
590 /* Set an initial state */
591 Context->FloatSave.ControlWord = 0x27F;
592 Context->FloatSave.StatusWord = 0;
593 Context->FloatSave.TagWord = 0xFFFF;
594 Context->FloatSave.ErrorOffset = 0;
595 Context->FloatSave.ErrorSelector = 0;
596 Context->FloatSave.DataOffset = 0;
597 Context->FloatSave.DataSelector = 0;
598 if (SharedUserData->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE])
599 Context->Dr6 = 0x1F80;
600 }
601 }
602 else
603 {
604 /* For first thread in a Process */
606 }
607
608#elif defined(_M_AMD64)
609 DPRINT("BaseInitializeContext: %p\n", Context);
610 ASSERT(((ULONG_PTR)StackAddress & 15) == 0);
611
612 RtlZeroMemory(Context, sizeof(*Context));
613
614 /* Setup the Initial Win32 Thread Context */
615 Context->Rcx = (ULONG_PTR)StartAddress;
617 Context->Rsp = (ULONG_PTR)StackAddress;
618
619 /* Setup the Segments */
626
627 /* Set the EFLAGS */
628 Context->EFlags = 0x3000 | EFLAGS_INTERRUPT_MASK; /* IOPL 3 */
629
630 /* Set MXCSR */
631 Context->MxCsr = INITIAL_MXCSR;
632
633 if (ContextType == 1) /* For Threads */
634 {
636 }
637 else if (ContextType == 2) /* For Fibers */
638 {
640 }
641 else /* For first thread in a Process */
642 {
644 }
645
646 /* Set the Context Flags */
647 Context->ContextFlags = CONTEXT_FULL;
648#elif defined(_M_ARM)
649 DPRINT("BaseInitializeContext: %p\n", Context);
650
651 // FIXME: check if this is correct!
652 /* Setup the Initial Win32 Thread Context */
653 Context->R0 = (ULONG_PTR)StartAddress;
655 Context->Sp = (ULONG_PTR)StackAddress;
656
657 if (ContextType == 1) /* For Threads */
658 {
660 }
661 else if (ContextType == 2) /* For Fibers */
662 {
664 }
665 else /* For first thread in a Process */
666 {
668 }
669
670 /* Set the Context Flags */
671 Context->ContextFlags = CONTEXT_FULL;
672
673 /* Give it some room for the Parameter */
674 Context->Sp -= sizeof(PVOID);
675#else
676#warning Unknown architecture
679#endif
680}
#define EFLAGS_INTERRUPT_MASK
#define KGDT_R3_DATA
#define KGDT_R3_CODE
#define KGDT64_R3_CODE
#define KGDT_R3_TEB
#define KGDT64_R3_DATA
#define KGDT64_R3_CMTEB
#define RPL_MASK
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
DECLSPEC_NORETURN VOID WINAPI BaseProcessStartup(_In_ PPROCESS_START_ROUTINE lpStartAddress)
Definition: proc.c:451
DECLSPEC_NORETURN VOID WINAPI BaseThreadStartup(_In_ LPTHREAD_START_ROUTINE lpStartAddress, _In_ LPVOID lpParameter)
Definition: thread.c:58
#define ULONG_PTR
Definition: config.h:101
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE ContextType
Definition: fltkernel.h:1443
VOID WINAPI BaseThreadStartupThunk(VOID)
DECLSPEC_NORETURN VOID WINAPI BaseFiberStartup(VOID)
VOID WINAPI BaseProcessStartThunk(VOID)
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_ PVOID Context
Definition: kse.h:81
#define ASSERT(a)
Definition: mode.c:44
#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
NTSYSAPI void WINAPI DbgBreakPoint(void)
#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 904 of file utils.c.

906{
910
911 /* If no attributes were given, get them */
912 if (!FileAttributes)
913 {
914 FileBasicInfo.FileAttributes = 0;
918 sizeof(FileBasicInfo),
920 FileAttributes = FileBasicInfo.FileAttributes;
921 }
922
923 /* If file is marked as RO, reset its attributes */
925 {
927 FileBasicInfo.FileAttributes = FILE_ATTRIBUTE_NORMAL;
931 sizeof(FileBasicInfo),
933 }
934
935 /* Finally, mark the file for deletion */
936 FileDispositionInfo.DeleteFile = TRUE;
940 sizeof(FileDispositionInfo),
942}
_In_ PIO_STATUS_BLOCK IoStatusBlock
Definition: dispmprt.h:608
#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)

Referenced by CreateDirectoryExW().

◆ Basep8BitStringToDynamicUnicodeString()

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

Definition at line 252 of file utils.c.

254{
257
258 /* Initialize an ANSI String */
260 if (!NT_SUCCESS(Status))
261 {
263 }
264 else
265 {
266 /* Convert it */
268 }
269
270 if (NT_SUCCESS(Status)) return TRUE;
271
273 {
275 }
276 else
277 {
279 }
280
281 return FALSE;
282}
#define SetLastError(x)
Definition: compat.h:752
@ AnsiString
Definition: dnslib.h:19
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
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_opt_ PCUNICODE_STRING UnicodeString
Definition: wdfstring.h:64
NTSYSAPI NTSTATUS WINAPI RtlInitAnsiStringEx(PANSI_STRING, PCSZ)
#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 290 of file utils.c.

292{
293 ANSI_STRING AnsiTemp;
294 UNICODE_STRING UnicodeTemp;
295
296 DPRINT("BasepAnsiStringToHeapUnicodeString\n");
297
298 /* First create the ANSI_STRING */
299 RtlInitAnsiString(&AnsiTemp, AnsiString);
300
302 &AnsiTemp,
303 TRUE)))
304 {
305 *UnicodeString = UnicodeTemp.Buffer;
306 }
307 else
308 {
310 }
311}
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 949 of file utils.c.

955{
957
958 /* Validate that there's a name */
960 {
961 /* Validate that the required output parameters are there */
962 if ((InJob) && (NewToken) && (JobHandle))
963 {
964 /* Do the work (one day...) */
965 DPRINT("BasepCheckWinSaferRestrictions is UNIMPLEMENTED\n");
967 }
968 else
969 {
970 /* Act as if SEH hit this */
972 }
973 }
974 else
975 {
976 /* Input is invalid */
978 }
979
980 /* Return the status */
981 return Status;
982}
#define STATUS_ACCESS_VIOLATION
PVOID PVOID PWCHAR ApplicationName
Definition: env.c:47
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

Referenced by CreateProcessInternalW().

◆ BasepGetNamedObjectDirectory()

HANDLE WINAPI BasepGetNamedObjectDirectory ( VOID  )

Definition at line 167 of file utils.c.

168{
171
173 if (!NT_SUCCESS(Status))
174 {
175 return NULL;
176 }
177
178 return DirectoryHandle;
179}
NTSTATUS WINAPI BaseGetNamedObjectDirectory(_Out_ PHANDLE DirectoryHandle)
Definition: utils.c:64

Referenced by BaseFormatObjectAttributes(), and OpenFileMappingW().

◆ BasepIsRealtimeAllowed()

PVOID WINAPI BasepIsRealtimeAllowed ( IN BOOLEAN  Keep)

Definition at line 692 of file utils.c.

693{
695 PVOID State;
697
699 if (!NT_SUCCESS(Status)) return NULL;
700
701 if (!Keep)
702 {
704 State = (PVOID)TRUE;
705 }
706
707 return State;
708}
#define SE_INC_BASE_PRIORITY_PRIVILEGE
Definition: security.c:568
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 183 of file utils.c.

186{
187 /* Make sure we get Entry, Context and valid StopEnumeration pointer */
188 ASSERT(Entry);
190 ASSERT(StopEnumeration);
191
192 /* If entry is already found - signal to stop */
194 {
195 *StopEnumeration = TRUE;
196 return;
197 }
198
199 /* Otherwise keep enumerating until we find a match */
200 if (Entry->DllBase == Context)
201 {
202 /* It matches, so remember the ldr entry */
204
205 /* And stop enumeration */
206 *StopEnumeration = TRUE;
207 }
208}
PLDR_DATA_TABLE_ENTRY BasepExeLdrEntry
Definition: proc.c:25
Entry
Definition: section.c:5216

Referenced by BasepComputeProcessPath(), and LoadLibraryExW().

◆ BasepMapFile()

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

Definition at line 715 of file utils.c.

718{
719 RTL_RELATIVE_NAME_U RelativeName;
722 HANDLE hFile = NULL;
724
725 DPRINT("BasepMapFile\n");
726
727 /* Zero out the Relative Directory */
728 RelativeName.ContainingDirectory = NULL;
729
730 /* Find the application name */
731 if (!RtlDosPathNameToNtPathName_U(lpApplicationName,
733 NULL,
734 &RelativeName))
735 {
737 }
738
739 DPRINT("ApplicationName %wZ\n", ApplicationName);
740 DPRINT("RelativeName %wZ\n", &RelativeName.RelativeName);
741
742 /* Did we get a relative name? */
743 if (RelativeName.RelativeName.Length)
744 {
745 ApplicationName = &RelativeName.RelativeName;
746 }
747
748 /* Initialize the Object Attributes */
752 RelativeName.ContainingDirectory,
753 NULL);
754
755 /* Try to open the executable */
762 RtlReleaseRelativeName(&RelativeName);
763 if (!NT_SUCCESS(Status))
764 {
765 DPRINT1("Failed to open file\n");
767 return Status;
768 }
769
770 /* Create a section for this file */
773 NULL,
774 NULL,
776 SEC_IMAGE,
777 hFile);
778 NtClose(hFile);
779
780 /* Return status */
781 DPRINT("Section: %p for file: %p\n", *hSection, hFile);
782 return Status;
783}
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:3097
#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
VOID NTAPI RtlReleaseRelativeName(_In_ PRTL_RELATIVE_NAME_U RelativeName)
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:3951
#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:1402
HANDLE ContainingDirectory
Definition: rtltypes.h:1403
#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 877 of file utils.c.

878{
879 /* Set the correct Base Api */
884
885 /* FIXME: Old, deprecated way */
887}
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 859 of file utils.c.

860{
861 /* Set the correct Base Api */
866
867 /* FIXME: Old, deprecated way */
869}
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 813 of file utils.c.

814{
816 BOOL Result;
817
819 if (NT_SUCCESS(Status))
820 {
821 Result = TRUE;
822 }
823 else
824 {
826 Result = FALSE;
827 }
828 return Result;
829}
NTSYSAPI NTSTATUS NTAPI RtlWow64EnableFsRedirectionEx(IN PVOID Wow64FsEnableRedirection, OUT PVOID *OldFsRedirectionLevel)
Definition: libsupp.c:1189
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(), create_server(), create_surrogate_server(), custom_start_server(), get_systemdirectory(), msi_disable_fs_redirection(), run_winemenubuilder(), test_peb_teb(), and test_wow64().

◆ Wow64EnableWow64FsRedirection()

BOOLEAN WINAPI Wow64EnableWow64FsRedirection ( IN BOOLEAN  Wow64EnableWow64FsRedirection)

Definition at line 790 of file utils.c.

791{
793 BOOL Result;
794
796 if (NT_SUCCESS(Status))
797 {
798 Result = TRUE;
799 }
800 else
801 {
803 Result = FALSE;
804 }
805 return Result;
806}
NTSYSAPI NTSTATUS NTAPI RtlWow64EnableFsRedirection(IN BOOLEAN Wow64FsEnableRedirection)
Definition: libsupp.c:1177
BOOLEAN WINAPI Wow64EnableWow64FsRedirection(IN BOOLEAN Wow64EnableWow64FsRedirection)
Definition: utils.c:790

Referenced by Wow64EnableWow64FsRedirection().

◆ Wow64RevertWow64FsRedirection()

BOOL WINAPI Wow64RevertWow64FsRedirection ( IN PVOID  OldValue)

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().