ReactOS  0.4.10-dev-19-g39281f0
utils.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS system libraries
4  * FILE: dll/win32/kernel32/client/utils.c
5  * PURPOSE: Utility and Support Functions
6  * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7  * Pierre Schweitzer (pierre.schweitzer@reactos.org)
8  */
9 
10 /* INCLUDES ******************************************************************/
11 
12 #include <k32.h>
13 #ifdef _M_IX86
14 #include "i386/ketypes.h"
15 #elif defined _M_AMD64
16 #include "amd64/ketypes.h"
17 #endif
18 
19 #define NDEBUG
20 #include <debug.h>
21 
22 /* GLOBALS ********************************************************************/
23 
25 BOOL bIsFileApiAnsi = TRUE; // set the file api to ansi or oem
30 
31 /* FUNCTIONS ******************************************************************/
32 
33 ULONG
34 NTAPI
36 {
37  return RtlUnicodeStringToOemSize(String);
38 }
39 
40 ULONG
41 NTAPI
43 {
44  return RtlOemStringToUnicodeSize(String);
45 }
46 
47 ULONG
48 NTAPI
50 {
51  return RtlUnicodeStringToAnsiSize(String);
52 }
53 
54 ULONG
55 NTAPI
57 {
58  return RtlAnsiStringToUnicodeSize(String);
59 }
60 
61 HANDLE
62 WINAPI
64 {
67  HANDLE DirHandle, BnoHandle, Token, NewToken;
68 
70 
71  if (NtCurrentTeb()->IsImpersonating)
72  {
75  TRUE,
76  &Token);
77  if (!NT_SUCCESS(Status)) return BaseNamedObjectDirectory;
78 
79  NewToken = NULL;
82  &NewToken,
83  sizeof(HANDLE));
84  if (!NT_SUCCESS (Status))
85  {
86  NtClose(Token);
88  }
89  }
90  else
91  {
92  Token = NULL;
93  }
94 
96  if (BaseNamedObjectDirectory) goto Quickie;
97 
98  InitializeObjectAttributes(&ObjectAttributes,
101  NULL,
102  NULL);
103 
104  Status = NtOpenDirectoryObject(&BnoHandle,
109  &ObjectAttributes);
110  if (!NT_SUCCESS(Status))
111  {
112  Status = NtOpenDirectoryObject(&DirHandle,
114  &ObjectAttributes);
115 
116  if (NT_SUCCESS(Status))
117  {
118  InitializeObjectAttributes(&ObjectAttributes,
119  (PUNICODE_STRING)&Restricted,
121  DirHandle,
122  NULL);
123 
124  Status = NtOpenDirectoryObject(&BnoHandle,
129  &ObjectAttributes);
130  NtClose(DirHandle);
131 
132  }
133  }
134 
135  if (NT_SUCCESS(Status)) BaseNamedObjectDirectory = BnoHandle;
136 
137 Quickie:
138 
140 
141  if (Token)
142  {
145  &Token,
146  sizeof(Token));
147 
148  NtClose(Token);
149  }
150 
152 }
153 
154 VOID
155 NTAPI
157  IN PVOID Context,
158  OUT BOOLEAN *StopEnumeration)
159 {
160  /* Make sure we get Entry, Context and valid StopEnumeration pointer */
161  ASSERT(Entry);
162  ASSERT(Context);
163  ASSERT(StopEnumeration);
164 
165  /* If entry is already found - signal to stop */
166  if (BasepExeLdrEntry)
167  {
168  *StopEnumeration = TRUE;
169  return;
170  }
171 
172  /* Otherwise keep enumerating until we find a match */
173  if (Entry->DllBase == Context)
174  {
175  /* It matches, so remember the ldr entry */
177 
178  /* And stop enumeration */
179  *StopEnumeration = TRUE;
180  }
181 }
182 
183 /*
184  * Converts an ANSI or OEM String to the TEB StaticUnicodeString
185  */
187 WINAPI
189 {
190  PUNICODE_STRING StaticString = &(NtCurrentTeb()->StaticUnicodeString);
193 
194  /* Initialize an ANSI String */
195  Status = RtlInitAnsiStringEx(&AnsiString, String);
196  if (!NT_SUCCESS(Status))
197  {
198  Status = STATUS_BUFFER_OVERFLOW;
199  }
200  else
201  {
202  /* Convert it */
203  Status = Basep8BitStringToUnicodeString(StaticString, &AnsiString, FALSE);
204  }
205 
206  if (NT_SUCCESS(Status)) return StaticString;
207 
208  if (Status == STATUS_BUFFER_OVERFLOW)
209  {
211  }
212  else
213  {
214  BaseSetLastNTError(Status);
215  }
216 
217  return NULL;
218 }
219 
220 /*
221  * Allocates space from the Heap and converts an Unicode String into it
222  */
223 BOOLEAN
224 WINAPI
226  IN LPCSTR String)
227 {
230 
231  /* Initialize an ANSI String */
232  Status = RtlInitAnsiStringEx(&AnsiString, String);
233  if (!NT_SUCCESS(Status))
234  {
235  Status = STATUS_BUFFER_OVERFLOW;
236  }
237  else
238  {
239  /* Convert it */
240  Status = Basep8BitStringToUnicodeString(UnicodeString, &AnsiString, TRUE);
241  }
242 
243  if (NT_SUCCESS(Status)) return TRUE;
244 
245  if (Status == STATUS_BUFFER_OVERFLOW)
246  {
248  }
249  else
250  {
251  BaseSetLastNTError(Status);
252  }
253 
254  return FALSE;
255 }
256 
257 /*
258  * Allocates space from the Heap and converts an Ansi String into it
259  */
260  /*NOTE: API IS A HACK */
261 VOID
262 WINAPI
265 {
266  ANSI_STRING AnsiTemp;
267  UNICODE_STRING UnicodeTemp;
268 
269  DPRINT("BasepAnsiStringToHeapUnicodeString\n");
270 
271  /* First create the ANSI_STRING */
272  RtlInitAnsiString(&AnsiTemp, AnsiString);
273 
274  if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&UnicodeTemp,
275  &AnsiTemp,
276  TRUE)))
277  {
278  *UnicodeString = UnicodeTemp.Buffer;
279  }
280  else
281  {
282  *UnicodeString = NULL;
283  }
284 }
285 
287 WINAPI
289  IN DWORD dwMilliseconds)
290 {
291  /* Check if this is an infinite wait, which means no timeout argument */
292  if (dwMilliseconds == INFINITE) return NULL;
293 
294  /* Otherwise, convert the time to NT Format */
295  Timeout->QuadPart = dwMilliseconds * -10000LL;
296  return Timeout;
297 }
298 
299 /*
300  * Converts lpSecurityAttributes + Object Name into ObjectAttributes.
301  */
303 WINAPI
305  IN PSECURITY_ATTRIBUTES SecurityAttributes OPTIONAL,
307 {
311  DPRINT("BaseFormatObjectAttributes. Security: %p, Name: %p\n",
312  SecurityAttributes, ObjectName);
313 
314  /* Get the attributes if present */
315  if (SecurityAttributes)
316  {
317  Attributes = SecurityAttributes->bInheritHandle ? OBJ_INHERIT : 0;
318  SecurityDescriptor = SecurityAttributes->lpSecurityDescriptor;
319  }
320  else
321  {
322  if (!ObjectName) return NULL;
323  Attributes = 0;
324  SecurityDescriptor = NULL;
325  }
326 
327  if (ObjectName)
328  {
329  Attributes |= OBJ_OPENIF;
330  RootDirectory = BaseGetNamedObjectDirectory();
331  }
332  else
333  {
334  RootDirectory = NULL;
335  }
336 
337  /* Create the Object Attributes */
338  InitializeObjectAttributes(ObjectAttributes,
339  ObjectName,
340  Attributes,
341  RootDirectory,
342  SecurityDescriptor);
343  DPRINT("Attributes: %lx, RootDirectory: %p, SecurityDescriptor: %p\n",
344  Attributes, RootDirectory, SecurityDescriptor);
345  return ObjectAttributes;
346 }
347 
348 /*
349  * Creates a stack for a thread or fiber
350  */
351 NTSTATUS
352 WINAPI
354  SIZE_T StackCommit,
355  SIZE_T StackReserve,
356  PINITIAL_TEB InitialTeb)
357 {
359  PIMAGE_NT_HEADERS Headers;
360  ULONG_PTR Stack;
361  BOOLEAN UseGuard;
362  ULONG PageSize, Dummy, AllocationGranularity;
363  SIZE_T StackReserveHeader, StackCommitHeader, GuardPageSize, GuaranteedStackCommit;
364  DPRINT("BaseCreateStack (hProcess: %p, Max: %lx, Current: %lx)\n",
365  hProcess, StackReserve, StackCommit);
366 
367  /* Read page size */
369  AllocationGranularity = BaseStaticServerData->SysInfo.AllocationGranularity;
370 
371  /* Get the Image Headers */
372  Headers = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress);
373  if (!Headers) return STATUS_INVALID_IMAGE_FORMAT;
374 
375  StackCommitHeader = Headers->OptionalHeader.SizeOfStackCommit;
376  StackReserveHeader = Headers->OptionalHeader.SizeOfStackReserve;
377 
378  if (!StackReserve) StackReserve = StackReserveHeader;
379 
380  if (!StackCommit)
381  {
382  StackCommit = StackCommitHeader;
383  }
384  else if (StackCommit >= StackReserve)
385  {
386  StackReserve = ROUND_UP(StackCommit, 1024 * 1024);
387  }
388 
389  StackCommit = ROUND_UP(StackCommit, PageSize);
390  StackReserve = ROUND_UP(StackReserve, AllocationGranularity);
391 
392  GuaranteedStackCommit = NtCurrentTeb()->GuaranteedStackBytes;
393  if ((GuaranteedStackCommit) && (StackCommit < GuaranteedStackCommit))
394  {
395  StackCommit = GuaranteedStackCommit;
396  }
397 
398  if (StackCommit >= StackReserve)
399  {
400  StackReserve = ROUND_UP(StackCommit, 1024 * 1024);
401  }
402 
403  StackCommit = ROUND_UP(StackCommit, PageSize);
404  StackReserve = ROUND_UP(StackReserve, AllocationGranularity);
405 
406  /* Reserve memory for the stack */
407  Stack = 0;
408  Status = NtAllocateVirtualMemory(hProcess,
409  (PVOID*)&Stack,
410  0,
411  &StackReserve,
412  MEM_RESERVE,
414  if (!NT_SUCCESS(Status))
415  {
416  DPRINT1("Failure to reserve stack: %lx\n", Status);
417  return Status;
418  }
419 
420  /* Now set up some basic Initial TEB Parameters */
421  InitialTeb->AllocatedStackBase = (PVOID)Stack;
422  InitialTeb->StackBase = (PVOID)(Stack + StackReserve);
423  InitialTeb->PreviousStackBase = NULL;
424  InitialTeb->PreviousStackLimit = NULL;
425 
426  /* Update the Stack Position */
427  Stack += StackReserve - StackCommit;
428 
429  /* Check if we will need a guard page */
430  if (StackReserve > StackCommit)
431  {
432  Stack -= PageSize;
433  StackCommit += PageSize;
434  UseGuard = TRUE;
435  }
436  else
437  {
438  UseGuard = FALSE;
439  }
440 
441  /* Allocate memory for the stack */
442  Status = NtAllocateVirtualMemory(hProcess,
443  (PVOID*)&Stack,
444  0,
445  &StackCommit,
446  MEM_COMMIT,
448  if (!NT_SUCCESS(Status))
449  {
450  DPRINT1("Failure to allocate stack\n");
451  GuardPageSize = 0;
452  NtFreeVirtualMemory(hProcess, (PVOID*)&Stack, &GuardPageSize, MEM_RELEASE);
453  return Status;
454  }
455 
456  /* Now set the current Stack Limit */
457  InitialTeb->StackLimit = (PVOID)Stack;
458 
459  /* Create a guard page */
460  if (UseGuard)
461  {
462  /* Set the guard page */
463  GuardPageSize = PAGE_SIZE;
464  Status = NtProtectVirtualMemory(hProcess,
465  (PVOID*)&Stack,
466  &GuardPageSize,
468  &Dummy);
469  if (!NT_SUCCESS(Status))
470  {
471  DPRINT1("Failure to set guard page\n");
472  return Status;
473  }
474 
475  /* Update the Stack Limit keeping in mind the Guard Page */
476  InitialTeb->StackLimit = (PVOID)((ULONG_PTR)InitialTeb->StackLimit +
477  GuardPageSize);
478  }
479 
480  /* We are done! */
481  return STATUS_SUCCESS;
482 }
483 
484 VOID
485 WINAPI
487  IN PINITIAL_TEB InitialTeb)
488 {
489  SIZE_T Dummy = 0;
490 
491  /* Free the Stack */
492  NtFreeVirtualMemory(hProcess,
493  &InitialTeb->AllocatedStackBase,
494  &Dummy,
495  MEM_RELEASE);
496 }
497 
498 /*
499  * Creates the Initial Context for a Thread or Fiber
500  */
501 VOID
502 WINAPI
505  IN PVOID StartAddress,
506  IN PVOID StackAddress,
508 {
509 #ifdef _M_IX86
510  ULONG ContextFlags;
511  DPRINT("BaseInitializeContext: %p\n", Context);
512 
513  /* Setup the Initial Win32 Thread Context */
514  Context->Eax = (ULONG)StartAddress;
515  Context->Ebx = (ULONG)Parameter;
516  Context->Esp = (ULONG)StackAddress;
517  /* The other registers are undefined */
518 
519  /* Setup the Segments */
520  Context->SegFs = KGDT_R3_TEB;
521  Context->SegEs = KGDT_R3_DATA;
522  Context->SegDs = KGDT_R3_DATA;
523  Context->SegCs = KGDT_R3_CODE;
524  Context->SegSs = KGDT_R3_DATA;
525  Context->SegGs = 0;
526 
527  /* Set the Context Flags */
528  ContextFlags = Context->ContextFlags;
529  Context->ContextFlags = CONTEXT_FULL;
530 
531  /* Give it some room for the Parameter */
532  Context->Esp -= sizeof(PVOID);
533 
534  /* Set the EFLAGS */
535  Context->EFlags = 0x3000; /* IOPL 3 */
536 
537  /* What kind of context is being created? */
538  if (ContextType == 1)
539  {
540  /* For Threads */
541  Context->Eip = (ULONG)BaseThreadStartupThunk;
542  }
543  else if (ContextType == 2)
544  {
545  /* This is a fiber: make space for the return address */
546  Context->Esp -= sizeof(PVOID);
547  *((PVOID*)Context->Esp) = BaseFiberStartup;
548 
549  /* Is FPU state required? */
550  Context->ContextFlags |= ContextFlags;
551  if ((ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT)
552  {
553  /* Set an initial state */
554  Context->FloatSave.ControlWord = 0x27F;
555  Context->FloatSave.StatusWord = 0;
556  Context->FloatSave.TagWord = 0xFFFF;
557  Context->FloatSave.ErrorOffset = 0;
558  Context->FloatSave.ErrorSelector = 0;
559  Context->FloatSave.DataOffset = 0;
560  Context->FloatSave.DataSelector = 0;
561  if (SharedUserData->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE])
562  Context->Dr6 = 0x1F80;
563  }
564  }
565  else
566  {
567  /* For first thread in a Process */
568  Context->Eip = (ULONG)BaseProcessStartThunk;
569  }
570 
571 #elif defined(_M_AMD64)
572  DPRINT("BaseInitializeContext: %p\n", Context);
573 
574  /* Setup the Initial Win32 Thread Context */
575  Context->Rax = (ULONG_PTR)StartAddress;
576  Context->Rbx = (ULONG_PTR)Parameter;
577  Context->Rsp = (ULONG_PTR)StackAddress;
578  /* The other registers are undefined */
579 
580  /* Setup the Segments */
581  Context->SegGs = KGDT64_R3_DATA | RPL_MASK;
582  Context->SegEs = KGDT64_R3_DATA | RPL_MASK;
583  Context->SegDs = KGDT64_R3_DATA | RPL_MASK;
584  Context->SegCs = KGDT64_R3_CODE | RPL_MASK;
585  Context->SegSs = KGDT64_R3_DATA | RPL_MASK;
586  Context->SegFs = KGDT64_R3_CMTEB | RPL_MASK;
587 
588  /* Set the EFLAGS */
589  Context->EFlags = 0x3000; /* IOPL 3 */
590 
591  if (ContextType == 1) /* For Threads */
592  {
593  Context->Rip = (ULONG_PTR)BaseThreadStartupThunk;
594  }
595  else if (ContextType == 2) /* For Fibers */
596  {
597  Context->Rip = (ULONG_PTR)BaseFiberStartup;
598  }
599  else /* For first thread in a Process */
600  {
601  Context->Rip = (ULONG_PTR)BaseProcessStartThunk;
602  }
603 
604  /* Set the Context Flags */
605  Context->ContextFlags = CONTEXT_FULL;
606 
607  /* Give it some room for the Parameter */
608  Context->Rsp -= sizeof(PVOID);
609 #elif defined(_M_ARM)
610  DPRINT("BaseInitializeContext: %p\n", Context);
611 
612  // FIXME: check if this is correct!
613  /* Setup the Initial Win32 Thread Context */
614  Context->R0 = (ULONG_PTR)StartAddress;
615  Context->R1 = (ULONG_PTR)Parameter;
616  Context->Sp = (ULONG_PTR)StackAddress;
617 
618  if (ContextType == 1) /* For Threads */
619  {
620  Context->Pc = (ULONG_PTR)BaseThreadStartupThunk;
621  }
622  else if (ContextType == 2) /* For Fibers */
623  {
624  Context->Pc = (ULONG_PTR)BaseFiberStartup;
625  }
626  else /* For first thread in a Process */
627  {
628  Context->Pc = (ULONG_PTR)BaseProcessStartThunk;
629  }
630 
631  /* Set the Context Flags */
632  Context->ContextFlags = CONTEXT_FULL;
633 
634  /* Give it some room for the Parameter */
635  Context->Sp -= sizeof(PVOID);
636 #else
637 #warning Unknown architecture
639  DbgBreakPoint();
640 #endif
641 }
642 
643 /*
644  * Checks if the privilege for Real-Time Priority is there
645  * Beware about this function behavior:
646  * - In case Keep is set to FALSE, then the function will only check
647  * whether real time is allowed and won't grant the privilege. In that case
648  * it will return TRUE if allowed, FALSE otherwise. Not a state!
649  * It means you don't have to release privilege when calling with FALSE.
650  */
651 PVOID
652 WINAPI
654 {
656  PVOID State;
658 
659  Status = RtlAcquirePrivilege(&Privilege, 1, 0, &State);
660  if (!NT_SUCCESS(Status)) return NULL;
661 
662  if (!Keep)
663  {
664  RtlReleasePrivilege(State);
665  State = (PVOID)TRUE;
666  }
667 
668  return State;
669 }
670 
671 /*
672  * Maps an image file into a section
673  */
674 NTSTATUS
675 WINAPI
676 BasepMapFile(IN LPCWSTR lpApplicationName,
679 {
680  RTL_RELATIVE_NAME_U RelativeName;
683  HANDLE hFile = NULL;
685 
686  DPRINT("BasepMapFile\n");
687 
688  /* Zero out the Relative Directory */
689  RelativeName.ContainingDirectory = NULL;
690 
691  /* Find the application name */
692  if (!RtlDosPathNameToNtPathName_U(lpApplicationName,
693  ApplicationName,
694  NULL,
695  &RelativeName))
696  {
698  }
699 
700  DPRINT("ApplicationName %wZ\n", ApplicationName);
701  DPRINT("RelativeName %wZ\n", &RelativeName.RelativeName);
702 
703  /* Did we get a relative name? */
704  if (RelativeName.RelativeName.Length)
705  {
706  ApplicationName = &RelativeName.RelativeName;
707  }
708 
709  /* Initialize the Object Attributes */
710  InitializeObjectAttributes(&ObjectAttributes,
711  ApplicationName,
713  RelativeName.ContainingDirectory,
714  NULL);
715 
716  /* Try to open the executable */
717  Status = NtOpenFile(&hFile,
719  &ObjectAttributes,
720  &IoStatusBlock,
723  if (!NT_SUCCESS(Status))
724  {
725  DPRINT1("Failed to open file\n");
726  BaseSetLastNTError(Status);
727  return Status;
728  }
729 
730  /* Create a section for this file */
731  Status = NtCreateSection(hSection,
733  NULL,
734  NULL,
735  PAGE_EXECUTE,
736  SEC_IMAGE,
737  hFile);
738  NtClose(hFile);
739 
740  /* Return status */
741  DPRINT("Section: %p for file: %p\n", *hSection, hFile);
742  return Status;
743 }
744 
745 /*
746  * @implemented
747  */
748 BOOLEAN
749 WINAPI
751 {
753  BOOL Result;
754 
755  Status = RtlWow64EnableFsRedirection(Wow64EnableWow64FsRedirection);
756  if (NT_SUCCESS(Status))
757  {
758  Result = TRUE;
759  }
760  else
761  {
762  BaseSetLastNTError(Status);
763  Result = FALSE;
764  }
765  return Result;
766 }
767 
768 /*
769  * @implemented
770  */
771 BOOL
772 WINAPI
774 {
776  BOOL Result;
777 
778  Status = RtlWow64EnableFsRedirectionEx((PVOID)TRUE, OldValue);
779  if (NT_SUCCESS(Status))
780  {
781  Result = TRUE;
782  }
783  else
784  {
785  BaseSetLastNTError(Status);
786  Result = FALSE;
787  }
788  return Result;
789 }
790 
791 /*
792  * @implemented
793  */
794 BOOL
795 WINAPI
797 {
799  BOOL Result;
800 
801  Status = RtlWow64EnableFsRedirectionEx(OldValue, &OldValue);
802  if (NT_SUCCESS(Status))
803  {
804  Result = TRUE;
805  }
806  else
807  {
808  BaseSetLastNTError(Status);
809  Result = FALSE;
810  }
811  return Result;
812 }
813 
814 /*
815  * @implemented
816  */
817 VOID
818 WINAPI
820 {
821  /* Set the correct Base Api */
826 
827  /* FIXME: Old, deprecated way */
829 }
830 
831 
832 /*
833  * @implemented
834  */
835 VOID
836 WINAPI
838 {
839  /* Set the correct Base Api */
844 
845  /* FIXME: Old, deprecated way */
847 }
848 
849 /*
850  * @implemented
851  */
852 BOOL
853 WINAPI
855 {
857 }
858 
859 /*
860  * @implemented
861  */
862 VOID
863 WINAPI
866 {
868  FILE_BASIC_INFORMATION FileBasicInfo;
869  FILE_DISPOSITION_INFORMATION FileDispositionInfo;
870 
871  /* If no attributes were given, get them */
872  if (!FileAttributes)
873  {
874  FileBasicInfo.FileAttributes = 0;
875  NtQueryInformationFile(FileHandle,
876  &IoStatusBlock,
877  &FileBasicInfo,
878  sizeof(FileBasicInfo),
880  FileAttributes = FileBasicInfo.FileAttributes;
881  }
882 
883  /* If file is marked as RO, reset its attributes */
884  if (FileAttributes & FILE_ATTRIBUTE_READONLY)
885  {
886  RtlZeroMemory(&FileBasicInfo, sizeof(FileBasicInfo));
887  FileBasicInfo.FileAttributes = FILE_ATTRIBUTE_NORMAL;
888  NtSetInformationFile(FileHandle,
889  &IoStatusBlock,
890  &FileBasicInfo,
891  sizeof(FileBasicInfo),
893  }
894 
895  /* Finally, mark the file for deletion */
896  FileDispositionInfo.DeleteFile = TRUE;
897  NtSetInformationFile(FileHandle,
898  &IoStatusBlock,
899  &FileDispositionInfo,
900  sizeof(FileDispositionInfo),
902 }
903 
904 /*
905  * @unimplemented
906  */
907 NTSTATUS
908 WINAPI
912  OUT PBOOLEAN InJob,
913  OUT PHANDLE NewToken,
914  OUT PHANDLE JobHandle)
915 {
917 
918  /* Validate that there's a name */
919  if ((ApplicationName) && *(ApplicationName))
920  {
921  /* Validate that the required output parameters are there */
922  if ((InJob) && (NewToken) && (JobHandle))
923  {
924  /* Do the work (one day...) */
925  DPRINT("BasepCheckWinSaferRestrictions is UNIMPLEMENTED\n");
926  Status = STATUS_SUCCESS;
927  }
928  else
929  {
930  /* Act as if SEH hit this */
931  Status = STATUS_ACCESS_VIOLATION;
932  }
933  }
934  else
935  {
936  /* Input is invalid */
937  Status = STATUS_INVALID_PARAMETER;
938  }
939 
940  /* Return the status */
941  return Status;
942 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define KGDT64_R3_CODE
Definition: ketypes.h:76
PVOID WINAPI BasepIsRealtimeAllowed(IN BOOLEAN Keep)
Definition: utils.c:653
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
BOOL WINAPI Wow64RevertWow64FsRedirection(IN PVOID OldValue)
Definition: utils.c:796
#define IN
Definition: typedefs.h:38
VOID WINAPI BaseInitializeContext(IN PCONTEXT Context, IN PVOID Parameter, IN PVOID StartAddress, IN PVOID StackAddress, IN ULONG ContextType)
Definition: utils.c:503
PUNICODE_STRING WINAPI Basep8BitStringToStaticUnicodeString(IN LPCSTR String)
Definition: utils.c:188
#define TRUE
Definition: types.h:120
NTSYSAPI DWORD WINAPI RtlUnicodeStringToAnsiSize(const UNICODE_STRING *)
#define LL
Definition: tui.h:72
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
BOOL bIsFileApiAnsi
Definition: utils.c:25
WCHAR RootDirectory[MAX_PATH]
Definition: format.c:74
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:3369
struct _Entry Entry
Definition: kefuncs.h:640
PBASE_STATIC_SERVER_DATA BaseStaticServerData
Definition: dllmain.c:19
Definition: bidi.c:85
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
PRTL_CONVERT_STRINGA BasepUnicodeStringTo8BitString
Definition: utils.c:27
_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:182
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
VOID WINAPI BasepAnsiStringToHeapUnicodeString(IN LPCSTR AnsiString, OUT LPWSTR *UnicodeString)
Definition: utils.c:263
NTSYSAPI NTSTATUS WINAPI RtlInitAnsiStringEx(PANSI_STRING, PCSZ)
#define DIRECTORY_CREATE_OBJECT
Definition: nt_native.h:1256
return STATUS_SUCCESS
Definition: btrfs.c:2690
NTSTATUS WINAPI BasepCheckWinSaferRestrictions(IN HANDLE UserToken, IN LPWSTR ApplicationName, IN HANDLE FileHandle, OUT PBOOLEAN InJob, OUT PHANDLE NewToken, OUT PHANDLE JobHandle)
Definition: utils.c:909
#define PAGE_GUARD
Definition: nt_native.h:1310
NTSTATUS NTAPI NtOpenDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:359
ULONG NTAPI BasepAnsiStringToUnicodeSize(IN PANSI_STRING String)
Definition: utils.c:56
HANDLE ContainingDirectory
Definition: rtltypes.h:1364
NTSTATUS NTAPI NtProtectVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UnsafeBaseAddress, IN OUT SIZE_T *UnsafeNumberOfBytesToProtect, IN ULONG NewAccessProtection, OUT PULONG UnsafeOldAccessProtection)
Definition: virtual.c:2986
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE Token
#define NtCurrentThread()
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
NTSYSAPI NTSTATUS NTAPI RtlWow64EnableFsRedirection(IN BOOLEAN Wow64FsEnableRedirection)
Definition: libsupp.c:891
#define KGDT64_R3_CMTEB
Definition: ketypes.h:78
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
#define CONTEXT_FULL
Definition: compat.h:270
#define TOKEN_IMPERSONATE
Definition: setypes.h:873
_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:426
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:62
_In_ PVOID Parameter
Definition: ldrtypes.h:239
void DbgBreakPoint()
Definition: mach.c:558
#define MEM_COMMIT
Definition: nt_native.h:1313
NTSYSAPI DWORD WINAPI RtlUnicodeStringToOemSize(const UNICODE_STRING *)
DWORD DWORD
Definition: winlogon.h:75
PLARGE_INTEGER WINAPI BaseFormatTimeOut(OUT PLARGE_INTEGER Timeout, IN DWORD dwMilliseconds)
Definition: utils.c:288
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
#define FILE_SHARE_READ
Definition: compat.h:125
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define OBJ_OPENIF
Definition: winternl.h:229
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
CHAR16 * String
Definition: acefiex.h:201
BOOLEAN WINAPI Basep8BitStringToDynamicUnicodeString(OUT PUNICODE_STRING UnicodeString, IN LPCSTR String)
Definition: utils.c:225
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
#define KGDT64_R3_DATA
Definition: ketypes.h:75
BOOL WINAPI AreFileApisANSI(VOID)
Definition: utils.c:854
PRTL_COUNT_STRINGA Basep8BitStringToUnicodeSize
Definition: utils.c:29
#define FILE_READ_DATA
Definition: nt_native.h:628
#define MEM_RESERVE
Definition: nt_native.h:1314
#define PF_XMMI_INSTRUCTIONS_AVAILABLE
VOID WINAPI SetFileApisToANSI(VOID)
Definition: utils.c:837
#define RPL_MASK
Definition: ketypes.h:69
UNICODE_STRING NamedObjectDirectory
Definition: base.h:115
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI VOID NTAPI RtlReleasePrivilege(_In_ PVOID ReturnedState)
#define PAGE_EXECUTE
Definition: nt_native.h:1306
PVOID StackBase
Definition: pstypes.h:678
void DPRINT(...)
Definition: polytest.cpp:61
#define KGDT_R3_DATA
Definition: ketypes.h:77
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:1969
const char * LPCSTR
Definition: xmlstorage.h:183
_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:1230
PLDR_DATA_TABLE_ENTRY BasepExeLdrEntry
Definition: proc.c:25
SYSTEM_BASIC_INFORMATION SysInfo
Definition: base.h:122
UNICODE_STRING Restricted
Definition: utils.c:24
#define DIRECTORY_TRAVERSE
Definition: nt_native.h:1255
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:3508
unsigned char BOOLEAN
ULONG NTAPI BasepUnicodeStringToOemSize(IN PUNICODE_STRING String)
Definition: utils.c:35
HANDLE BaseNamedObjectDirectory
Definition: dllmain.c:24
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:345
#define DIRECTORY_CREATE_SUBDIRECTORY
Definition: nt_native.h:1257
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define OBJ_INHERIT
Definition: winternl.h:225
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
BOOLEAN WINAPI Wow64EnableWow64FsRedirection(IN BOOLEAN Wow64EnableWow64FsRedirection)
Definition: utils.c:750
#define KGDT_R3_TEB
Definition: ketypes.h:80
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: udferr_usr.h:151
ULONG NTAPI BasepUnicodeStringToAnsiSize(IN PUNICODE_STRING String)
Definition: utils.c:49
#define SetLastError(x)
Definition: compat.h:409
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
Definition: user_lib.cpp:531
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3392
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSTATUS WINAPI BasepMapFile(IN LPCWSTR lpApplicationName, OUT PHANDLE hSection, IN PUNICODE_STRING ApplicationName)
Definition: utils.c:676
ULONG(NTAPI * PRTL_COUNT_STRING)(IN PUNICODE_STRING UnicodeString)
Definition: kernel32.h:272
PVOID StackLimit
Definition: pstypes.h:679
#define SharedUserData
char * PBOOLEAN
Definition: retypes.h:11
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
NTSTATUS WINAPI BaseCreateStack(HANDLE hProcess, SIZE_T StackCommit, SIZE_T StackReserve, PINITIAL_TEB InitialTeb)
Definition: utils.c:353
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:411
PVOID AllocatedStackBase
Definition: pstypes.h:680
#define FILE_EXECUTE
Definition: nt_native.h:642
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToOemString(POEM_STRING DestinationString, PCUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
Definition: btrfs_drv.h:1762
#define SE_INC_BASE_PRIORITY_PRIVILEGE
Definition: security.c:668
#define PAGE_SIZE
Definition: env_spec_w32.h:49
VOID NTAPI BasepLocateExeLdrEntry(IN PLDR_DATA_TABLE_ENTRY Entry, IN PVOID Context, OUT BOOLEAN *StopEnumeration)
Definition: utils.c:156
NTSTATUS NTAPI NtQueryInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
#define SYNCHRONIZE
Definition: nt_native.h:61
_In_ HANDLE hFile
Definition: mswsock.h:90
NTSYSAPI NTSTATUS NTAPI RtlOemStringToUnicodeString(PUNICODE_STRING DestinationString, PCOEM_STRING SourceString, BOOLEAN AllocateDestinationString)
#define WINAPI
Definition: msvc.h:20
POBJECT_ATTRIBUTES WINAPI BaseFormatObjectAttributes(OUT POBJECT_ATTRIBUTES ObjectAttributes, IN PSECURITY_ATTRIBUTES SecurityAttributes OPTIONAL, IN PUNICODE_STRING ObjectName)
Definition: utils.c:304
Status
Definition: gdiplustypes.h:24
VOID WINAPI SetFileApisToOEM(VOID)
Definition: utils.c:819
HANDLE WINAPI BaseGetNamedObjectDirectory(VOID)
Definition: utils.c:63
static HANDLE FileHandle
Definition: cabinet.c:48
ULONG_PTR SIZE_T
Definition: typedefs.h:78
enum State_ State
Definition: pofuncs.h:54
PVOID PVOID PWCHAR ApplicationName
Definition: env.c:45
DWORD *typedef HANDLE
Definition: winlogon.h:52
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:4367
static ULONG Timeout
Definition: ping.c:61
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:49
NTSYSAPI DWORD WINAPI RtlAnsiStringToUnicodeSize(const STRING *)
PRTL_COUNT_STRING BasepUnicodeStringTo8BitSize
Definition: utils.c:28
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
NTSYSAPI NTSTATUS NTAPI RtlWow64EnableFsRedirectionEx(IN PVOID Wow64FsEnableRedirection, OUT PVOID *OldFsRedirectionLevel)
Definition: libsupp.c:903
#define CONTEXT_FLOATING_POINT
Definition: compat.h:267
ULONG NTAPI BasepOemStringToUnicodeSize(IN PANSI_STRING String)
Definition: utils.c:42
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
PRTL_CONVERT_STRING Basep8BitStringToUnicodeString
Definition: utils.c:26
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72
NTSTATUS(NTAPI * PRTL_CONVERT_STRING)(IN PUNICODE_STRING UnicodeString, IN PANSI_STRING AnsiString, IN BOOLEAN AllocateMemory)
Definition: kernel32.h:268
#define DPRINT1
Definition: precomp.h:8
#define RtlImageNtHeader
Definition: compat.h:457
NTSYSAPI NTSTATUS NTAPI RtlAcquirePrivilege(_In_ PULONG Privilege, _In_ ULONG NumPriv, _In_ ULONG Flags, _Out_ PVOID *ReturnedState)
NTSTATUS(NTAPI * PRTL_CONVERT_STRINGA)(IN PANSI_STRING AnsiString, IN PCUNICODE_STRING UnicodeString, IN BOOLEAN AllocateMemory)
Definition: kernel32.h:274
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
NTSTATUS NTAPI NtOpenThreadToken(IN HANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN BOOLEAN OpenAsSelf, OUT PHANDLE TokenHandle)
Definition: token.c:3449
#define MEM_RELEASE
Definition: nt_native.h:1316
#define KGDT_R3_CODE
Definition: ketypes.h:76
#define OUT
Definition: typedefs.h:39
VOID WINAPI BaseProcessStartThunk(VOID)
unsigned int ULONG
Definition: retypes.h:1
#define DIRECTORY_QUERY
Definition: nt_native.h:1254
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE ContextType
Definition: fltkernel.h:1444
#define UNIMPLEMENTED
Definition: debug.h:114
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
#define SEC_IMAGE
Definition: mmtypes.h:96
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
UNICODE_STRING RelativeName
Definition: rtltypes.h:1363
PVOID PreviousStackBase
Definition: pstypes.h:676
PVOID PreviousStackLimit
Definition: pstypes.h:677
#define INFINITE
Definition: serial.h:102
WCHAR * LPWSTR
Definition: xmlstorage.h:184
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3216
IN HDEVINFO IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
Definition: devinst.c:44
base of all file and directory entries
Definition: entries.h:82
IN PUNICODE_STRING StaticString
VOID WINAPI BaseThreadStartupThunk(VOID)
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:2854
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)
struct _ACPI_EFI_FILE_HANDLE CHAR16 UINT64 UINT64 Attributes
Definition: acefiex.h:335
#define NtCurrentPeb()
Definition: rtlfuncs.h:1073
#define PAGE_READWRITE
Definition: nt_native.h:1304
NTSYSAPI UINT WINAPI RtlOemStringToUnicodeSize(const STRING *)
BOOL WINAPI Wow64DisableWow64FsRedirection(IN PVOID *OldValue)
Definition: utils.c:773
VOID WINAPI BaseFreeThreadStack(IN HANDLE hProcess, IN PINITIAL_TEB InitialTeb)
Definition: utils.c:486
#define ERROR_FILENAME_EXCED_RANGE
Definition: winerror.h:263
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
VOID WINAPI BaseMarkFileForDelete(IN HANDLE FileHandle, IN ULONG FileAttributes)
Definition: utils.c:864
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5090
ULONG(NTAPI * PRTL_COUNT_STRINGA)(IN PANSI_STRING UnicodeString)
Definition: kernel32.h:278