ReactOS  0.4.15-dev-3291-gea4c1a0
libsupp.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for libsupp.c:

Go to the source code of this file.

Classes

struct  _RTL_RANGE_ENTRY
 

Macros

#define NDEBUG
 
#define TAG_ATMT   'TotA' /* Atom table */
 
#define TAG_RTHL   'LHtR' /* Heap Lock */
 
#define TAG_USTR   'RTSU'
 
#define TAG_ASTR   'RTSA'
 
#define TAG_OSTR   'RTSO'
 

Typedefs

typedef struct _RTL_RANGE_ENTRY RTL_RANGE_ENTRY
 
typedef struct _RTL_RANGE_ENTRYPRTL_RANGE_ENTRY
 

Functions

PVOID NTAPI RtlPcToFileHeader (IN PVOID PcValue, OUT PVOID *BaseOfImage)
 
VOID NTAPI RtlInitializeRangeListPackage (VOID)
 
BOOLEAN NTAPI RtlpCheckForActiveDebugger (VOID)
 
BOOLEAN NTAPI RtlpSetInDbgPrint (VOID)
 
VOID NTAPI RtlpClearInDbgPrint (VOID)
 
KPROCESSOR_MODE NTAPI RtlpGetMode (VOID)
 
PVOID NTAPI RtlpAllocateMemory (ULONG Bytes, ULONG Tag)
 
VOID NTAPI RtlpFreeMemory (PVOID Mem, ULONG Tag)
 
VOID NTAPI RtlAcquirePebLock (VOID)
 
VOID NTAPI RtlReleasePebLock (VOID)
 
NTSTATUS NTAPI LdrShutdownThread (VOID)
 
PPEB NTAPI RtlGetCurrentPeb (VOID)
 
NTSTATUS NTAPI RtlDeleteHeapLock (IN OUT PHEAP_LOCK Lock)
 
NTSTATUS NTAPI RtlEnterHeapLock (IN OUT PHEAP_LOCK Lock, IN BOOLEAN Exclusive)
 
BOOLEAN NTAPI RtlTryEnterHeapLock (IN OUT PHEAP_LOCK Lock, IN BOOLEAN Exclusive)
 
NTSTATUS NTAPI RtlInitializeHeapLock (IN OUT PHEAP_LOCK *Lock)
 
NTSTATUS NTAPI RtlLeaveHeapLock (IN OUT PHEAP_LOCK Lock)
 
VOID NTAPI RtlpAddHeapToProcessList (struct _HEAP *Heap)
 
VOID NTAPI RtlpRemoveHeapFromProcessList (struct _HEAP *Heap)
 
VOID RtlInitializeHeapManager (VOID)
 
VOID NTAPI RtlpSetHeapParameters (IN PRTL_HEAP_PARAMETERS Parameters)
 
VOID NTAPI RtlpCheckLogException (IN PEXCEPTION_RECORD ExceptionRecord, IN PCONTEXT ContextRecord, IN PVOID ContextData, IN ULONG Size)
 
BOOLEAN NTAPI RtlpHandleDpcStackException (IN PEXCEPTION_REGISTRATION_RECORD RegistrationFrame, IN ULONG_PTR RegistrationFrameEnd, IN OUT PULONG_PTR StackLow, IN OUT PULONG_PTR StackHigh)
 
BOOLEAN NTAPI RtlpCaptureStackLimits (IN ULONG_PTR Ebp, IN ULONG_PTR *StackBegin, IN ULONG_PTR *StackEnd)
 
ULONG NTAPI RtlWalkFrameChain (OUT PVOID *Callers, IN ULONG Count, IN ULONG Flags)
 
NTSTATUS RtlpInitAtomTableLock (PRTL_ATOM_TABLE AtomTable)
 
VOID RtlpDestroyAtomTableLock (PRTL_ATOM_TABLE AtomTable)
 
BOOLEAN RtlpLockAtomTable (PRTL_ATOM_TABLE AtomTable)
 
VOID RtlpUnlockAtomTable (PRTL_ATOM_TABLE AtomTable)
 
BOOLEAN RtlpCreateAtomHandleTable (PRTL_ATOM_TABLE AtomTable)
 
BOOLEAN NTAPI RtlpCloseHandleCallback (IN PHANDLE_TABLE_ENTRY HandleTableEntry, IN HANDLE Handle, IN PVOID HandleTable)
 
VOID RtlpDestroyAtomHandleTable (PRTL_ATOM_TABLE AtomTable)
 
PRTL_ATOM_TABLE RtlpAllocAtomTable (ULONG Size)
 
VOID RtlpFreeAtomTable (PRTL_ATOM_TABLE AtomTable)
 
PRTL_ATOM_TABLE_ENTRY RtlpAllocAtomTableEntry (ULONG Size)
 
VOID RtlpFreeAtomTableEntry (PRTL_ATOM_TABLE_ENTRY Entry)
 
VOID RtlpFreeAtomHandle (PRTL_ATOM_TABLE AtomTable, PRTL_ATOM_TABLE_ENTRY Entry)
 
BOOLEAN RtlpCreateAtomHandle (PRTL_ATOM_TABLE AtomTable, PRTL_ATOM_TABLE_ENTRY Entry)
 
PRTL_ATOM_TABLE_ENTRY RtlpGetAtomEntry (PRTL_ATOM_TABLE AtomTable, ULONG Index)
 
NTSTATUS NTAPI RtlpImageNtHeaderEx (_In_ ULONG Flags, _In_ PVOID Base, _In_ ULONG64 Size, _Out_ PIMAGE_NT_HEADERS *OutHeaders)
 
NTSTATUS NTAPI RtlImageNtHeaderEx (_In_ ULONG Flags, _In_ PVOID Base, _In_ ULONG64 Size, _Out_ PIMAGE_NT_HEADERS *OutHeaders)
 
IMAGE_RESOURCE_DIRECTORYfind_entry_by_name (IMAGE_RESOURCE_DIRECTORY *dir, LPCWSTR name, void *root, int want_dir)
 
IMAGE_RESOURCE_DIRECTORYfind_entry_by_id (IMAGE_RESOURCE_DIRECTORY *dir, USHORT id, void *root, int want_dir)
 
IMAGE_RESOURCE_DIRECTORYfind_first_entry (IMAGE_RESOURCE_DIRECTORY *dir, void *root, int want_dir)
 
NTSTATUS find_entry (PVOID BaseAddress, LDR_RESOURCE_INFO *info, ULONG level, void **ret, int want_dir)
 
NTSTATUS NTAPI RtlpSafeCopyMemory (_Out_writes_bytes_all_(Length) VOID UNALIGNED *Destination, _In_reads_bytes_(Length) CONST VOID UNALIGNED *Source, _In_ SIZE_T Length)
 
BOOLEAN NTAPI RtlCallVectoredExceptionHandlers (_In_ PEXCEPTION_RECORD ExceptionRecord, _In_ PCONTEXT Context)
 
VOID NTAPI RtlCallVectoredContinueHandlers (_In_ PEXCEPTION_RECORD ExceptionRecord, _In_ PCONTEXT Context)
 

Variables

ULONG NtGlobalFlag
 
PAGED_LOOKASIDE_LIST RtlpRangeListEntryLookasideList
 
SIZE_T RtlpAllocDeallocQueryBufferSize = 128
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file libsupp.c.

◆ TAG_ASTR

#define TAG_ASTR   'RTSA'

Definition at line 119 of file libsupp.c.

◆ TAG_ATMT

#define TAG_ATMT   'TotA' /* Atom table */

Definition at line 16 of file libsupp.c.

◆ TAG_OSTR

#define TAG_OSTR   'RTSO'

Definition at line 120 of file libsupp.c.

◆ TAG_RTHL

#define TAG_RTHL   'LHtR' /* Heap Lock */

Definition at line 17 of file libsupp.c.

◆ TAG_USTR

#define TAG_USTR   'RTSU'

Definition at line 118 of file libsupp.c.

Typedef Documentation

◆ PRTL_RANGE_ENTRY

◆ RTL_RANGE_ENTRY

Function Documentation

◆ find_entry()

NTSTATUS find_entry ( PVOID  BaseAddress,
LDR_RESOURCE_INFO info,
ULONG  level,
void **  ret,
int  want_dir 
)

Definition at line 761 of file libsupp.c.

763 {
764  ULONG size;
765  void *root;
766  IMAGE_RESOURCE_DIRECTORY *resdirptr;
767 
770  if (size < sizeof(*resdirptr)) return STATUS_RESOURCE_DATA_NOT_FOUND;
771  resdirptr = root;
772 
773  if (!level--) goto done;
774  if (!(*ret = find_entry_by_name( resdirptr, (LPCWSTR)info->Type, root, want_dir || level )))
776  if (!level--) return STATUS_SUCCESS;
777 
778  resdirptr = *ret;
779  if (!(*ret = find_entry_by_name( resdirptr, (LPCWSTR)info->Name, root, want_dir || level )))
781  if (!level--) return STATUS_SUCCESS;
782  if (level) return STATUS_INVALID_PARAMETER; /* level > 3 */
783 
784  resdirptr = *ret;
785 
786  if ((*ret = find_first_entry( resdirptr, root, want_dir ))) return STATUS_SUCCESS;
787 
789 
790 done:
791  *ret = resdirptr;
792  return STATUS_SUCCESS;
793 }
GLint level
Definition: gl.h:1546
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
IMAGE_RESOURCE_DIRECTORY * find_entry_by_name(IMAGE_RESOURCE_DIRECTORY *dir, LPCWSTR name, void *root, int want_dir)
Definition: res.c:130
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _root root
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
GLsizeiptr size
Definition: glext.h:5919
IMAGE_RESOURCE_DIRECTORY * find_first_entry(IMAGE_RESOURCE_DIRECTORY *dir, void *root, int want_dir)
Definition: res.c:75
int ret
#define STATUS_RESOURCE_DATA_NOT_FOUND
Definition: ntstatus.h:373
#define RtlImageDirectoryEntryToData
Definition: compat.h:668
#define STATUS_RESOURCE_NAME_NOT_FOUND
Definition: ntstatus.h:375
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IMAGE_DIRECTORY_ENTRY_RESOURCE
Definition: pedump.c:261
#define STATUS_RESOURCE_TYPE_NOT_FOUND
Definition: ntstatus.h:374

Referenced by LdrFindResource_U(), and LdrFindResourceDirectory_U().

◆ find_entry_by_id()

IMAGE_RESOURCE_DIRECTORY* find_entry_by_id ( IMAGE_RESOURCE_DIRECTORY dir,
USHORT  id,
void root,
int  want_dir 
)

Definition at line 95 of file res.c.

97 {
99  int min, max, pos;
100 
101  entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
102  min = dir->NumberOfNamedEntries;
103  max = min + dir->NumberOfIdEntries - 1;
104  while (min <= max)
105  {
106  pos = (min + max) / 2;
107  if (entry[pos].Id == id)
108  {
109  if (!entry[pos].DataIsDirectory == !want_dir)
110  {
111  DPRINT("root %p dir %p id %04x ret %p\n",
112  root, dir, id, (const char*)root + entry[pos].OffsetToDirectory);
113  return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].OffsetToDirectory);
114  }
115  break;
116  }
117  if (entry[pos].Id > id) max = pos - 1;
118  else min = pos + 1;
119  }
120  DPRINT("root %p dir %p id %04x not found\n", root, dir, id );
121  return NULL;
122 }
#define max(a, b)
Definition: svc.c:63
DWORD Id
unsigned int dir
Definition: maze.c:112
uint32_t entry
Definition: isohybrid.c:63
Definition: pedump.c:413
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
#define DPRINT
Definition: sndvol32.h:71

Referenced by find_entry_by_name().

◆ find_entry_by_name()

IMAGE_RESOURCE_DIRECTORY* find_entry_by_name ( IMAGE_RESOURCE_DIRECTORY dir,
LPCWSTR  name,
void root,
int  want_dir 
)

Definition at line 130 of file res.c.

133 {
136  int min, max, res, pos;
137  size_t namelen;
138 
139  if (!((ULONG_PTR)name & 0xFFFF0000)) return find_entry_by_id( dir, (ULONG_PTR)name & 0xFFFF, root, want_dir );
140  entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
141  namelen = wcslen(name);
142  min = 0;
143  max = dir->NumberOfNamedEntries - 1;
144  while (min <= max)
145  {
146  pos = (min + max) / 2;
147  str = (const IMAGE_RESOURCE_DIR_STRING_U *)((const char *)root + entry[pos].NameOffset);
148  res = _wcsnicmp( name, str->NameString, str->Length );
149  if (!res && namelen == str->Length)
150  {
151  if (!entry[pos].DataIsDirectory == !want_dir)
152  {
153  DPRINT("root %p dir %p name %ws ret %p\n",
154  root, dir, name, (const char*)root + entry[pos].OffsetToDirectory);
155  return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].OffsetToDirectory);
156  }
157  break;
158  }
159  if (res < 0) max = pos - 1;
160  else min = pos + 1;
161  }
162  DPRINT("root %p dir %p name %ws not found\n", root, dir, name);
163  return NULL;
164 }
#define max(a, b)
Definition: svc.c:63
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
IMAGE_RESOURCE_DIRECTORY * find_entry_by_id(IMAGE_RESOURCE_DIRECTORY *dir, WORD id, void *root, int want_dir)
Definition: res.c:95
GLint namelen
Definition: glext.h:7232
uint32_t ULONG_PTR
Definition: typedefs.h:65
const WCHAR * str
unsigned int dir
Definition: maze.c:112
uint32_t entry
Definition: isohybrid.c:63
Definition: pedump.c:413
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
Definition: name.c:38
GLuint res
Definition: glext.h:9613
#define DPRINT
Definition: sndvol32.h:71

◆ find_first_entry()

IMAGE_RESOURCE_DIRECTORY* find_first_entry ( IMAGE_RESOURCE_DIRECTORY dir,
void root,
int  want_dir 
)

Definition at line 75 of file res.c.

77 {
79  int pos;
80 
81  for (pos = 0; pos < dir->NumberOfNamedEntries + dir->NumberOfIdEntries; pos++)
82  {
83  if (!entry[pos].DataIsDirectory == !want_dir)
84  return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].OffsetToDirectory);
85  }
86  return NULL;
87 }
unsigned int dir
Definition: maze.c:112
uint32_t entry
Definition: isohybrid.c:63
Definition: pedump.c:413
#define NULL
Definition: types.h:112

◆ LdrShutdownThread()

NTSTATUS NTAPI LdrShutdownThread ( VOID  )

Definition at line 152 of file libsupp.c.

153 {
154  return STATUS_SUCCESS;
155 }
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ RtlAcquirePebLock()

VOID NTAPI RtlAcquirePebLock ( VOID  )

Definition at line 136 of file libsupp.c.

137 {
138 
139 }

◆ RtlCallVectoredContinueHandlers()

VOID NTAPI RtlCallVectoredContinueHandlers ( _In_ PEXCEPTION_RECORD  ExceptionRecord,
_In_ PCONTEXT  Context 
)

Definition at line 826 of file libsupp.c.

828 {
829  /* No vectored continue handlers either in kernel mode */
830  return;
831 }

Referenced by RtlDispatchException().

◆ RtlCallVectoredExceptionHandlers()

BOOLEAN NTAPI RtlCallVectoredExceptionHandlers ( _In_ PEXCEPTION_RECORD  ExceptionRecord,
_In_ PCONTEXT  Context 
)

Definition at line 817 of file libsupp.c.

819 {
820  /* In the kernel we don't have vectored exception handlers */
821  return FALSE;
822 }
#define FALSE
Definition: types.h:117

Referenced by RtlDispatchException().

◆ RtlDeleteHeapLock()

NTSTATUS NTAPI RtlDeleteHeapLock ( IN OUT PHEAP_LOCK  Lock)

Definition at line 167 of file libsupp.c.

168 {
169  ExDeleteResourceLite(&Lock->Resource);
171 
172  return STATUS_SUCCESS;
173 }
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
#define TAG_RTHL
Definition: libsupp.c:17
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

◆ RtlEnterHeapLock()

NTSTATUS NTAPI RtlEnterHeapLock ( IN OUT PHEAP_LOCK  Lock,
IN BOOLEAN  Exclusive 
)

Definition at line 177 of file libsupp.c.

178 {
180 
181  if (Exclusive)
183  else
185 
186  return STATUS_SUCCESS;
187 }
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
__in PWDFDEVICE_INIT __in BOOLEAN Exclusive
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ RtlGetCurrentPeb()

PPEB NTAPI RtlGetCurrentPeb ( VOID  )

Definition at line 160 of file libsupp.c.

161 {
162  return ((PEPROCESS)(KeGetCurrentThread()->ApcState.Process))->Peb;
163 }
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1679
#define KeGetCurrentThread
Definition: hal.h:55

◆ RtlImageNtHeaderEx()

NTSTATUS NTAPI RtlImageNtHeaderEx ( _In_ ULONG  Flags,
_In_ PVOID  Base,
_In_ ULONG64  Size,
_Out_ PIMAGE_NT_HEADERS OutHeaders 
)

Definition at line 718 of file libsupp.c.

723 {
725 
726  /* Assume failure. This is also done in RtlpImageNtHeaderEx, but this is guarded by SEH. */
727  if (OutHeaders != NULL)
728  *OutHeaders = NULL;
729 
730  _SEH2_TRY
731  {
732  Status = RtlpImageNtHeaderEx(Flags, Base, Size, OutHeaders);
733  }
735  {
736  /* Fail with the SEH error */
738  }
739  _SEH2_END;
740 
741  return Status;
742 }
NTSTATUS NTAPI RtlpImageNtHeaderEx(_In_ ULONG Flags, _In_ PVOID Base, _In_ ULONG64 Size, _Out_ PIMAGE_NT_HEADERS *OutHeaders)
Definition: image.c:140
LONG NTSTATUS
Definition: precomp.h:26
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2386
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
_SEH2_TRY
Definition: create.c:4226
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_SEH2_END
Definition: create.c:4400
#define NULL
Definition: types.h:112
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165

◆ RtlInitializeHeapLock()

NTSTATUS NTAPI RtlInitializeHeapLock ( IN OUT PHEAP_LOCK Lock)

Definition at line 209 of file libsupp.c.

210 {
212  sizeof(HEAP_LOCK),
213  TAG_RTHL);
214  if (HeapLock == NULL)
215  return STATUS_NO_MEMORY;
216 
218  *Lock = HeapLock;
219 
220  return STATUS_SUCCESS;
221 }
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
BOOL WINAPI HeapLock(HANDLE hHeap)
Definition: heapmem.c:123
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define TAG_RTHL
Definition: libsupp.c:17
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ RtlInitializeHeapManager()

VOID RtlInitializeHeapManager ( VOID  )

Definition at line 250 of file libsupp.c.

251 {
252 }

◆ RtlInitializeRangeListPackage()

VOID NTAPI RtlInitializeRangeListPackage ( VOID  )

Definition at line 65 of file libsupp.c.

66 {
67  /* Setup the lookaside list for allocations (not used yet) */
69  NULL,
70  NULL,
72  sizeof(RTL_RANGE_ENTRY),
73  'elRR',
74  16);
75 }
PAGED_LOOKASIDE_LIST RtlpRangeListEntryLookasideList
Definition: libsupp.c:27
VOID NTAPI ExInitializePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:270
#define POOL_COLD_ALLOCATION
Definition: libsupp.c:21
#define NULL
Definition: types.h:112

Referenced by Phase1InitializationDiscard().

◆ RtlLeaveHeapLock()

NTSTATUS NTAPI RtlLeaveHeapLock ( IN OUT PHEAP_LOCK  Lock)

Definition at line 225 of file libsupp.c.

226 {
227  ExReleaseResourceLite(&Lock->Resource);
229 
230  return STATUS_SUCCESS;
231 }
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ RtlpAddHeapToProcessList()

VOID NTAPI RtlpAddHeapToProcessList ( struct _HEAP Heap)

Definition at line 237 of file libsupp.c.

238 {
240 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317

Referenced by RtlCreateHeap().

◆ RtlpAllocateMemory()

PVOID NTAPI RtlpAllocateMemory ( ULONG  Bytes,
ULONG  Tag 
)

Definition at line 109 of file libsupp.c.

111 {
113  (SIZE_T)Bytes,
114  Tag);
115 }
_In_ UINT Bytes
Definition: mmcopy.h:9
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4061
ULONG_PTR SIZE_T
Definition: typedefs.h:80

◆ RtlpAllocAtomTable()

PRTL_ATOM_TABLE RtlpAllocAtomTable ( ULONG  Size)

Definition at line 591 of file libsupp.c.

592 {
594  Size,
595  TAG_ATMT);
596  if (Table != NULL)
597  {
599  Size);
600  }
601 
602  return Table;
603 }
ASMGENDATA Table[]
Definition: genincdata.c:61
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define TAG_ATMT
Definition: libsupp.c:16
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
struct atom_table ** PRTL_ATOM_TABLE
Definition: atom.c:43
#define NULL
Definition: types.h:112
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by RtlCreateAtomTable().

◆ RtlpAllocAtomTableEntry()

PRTL_ATOM_TABLE_ENTRY RtlpAllocAtomTableEntry ( ULONG  Size)

Definition at line 612 of file libsupp.c.

613 {
615 
617  if (Entry != NULL)
618  {
620  }
621 
622  return Entry;
623 }
Definition: rtltypes.h:1669
struct _Entry Entry
Definition: kefuncs.h:627
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define TAG_ATMT
Definition: libsupp.c:16
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NULL
Definition: types.h:112
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
base of all file and directory entries
Definition: entries.h:82

Referenced by RtlAddAtomToAtomTable().

◆ RtlpCaptureStackLimits()

BOOLEAN NTAPI RtlpCaptureStackLimits ( IN ULONG_PTR  Ebp,
IN ULONG_PTR StackBegin,
IN ULONG_PTR StackEnd 
)

Definition at line 328 of file libsupp.c.

331 {
333 
334  /* Don't even try at ISR level or later */
335  if (KeGetCurrentIrql() > DISPATCH_LEVEL) return FALSE;
336 
337  /* Start with defaults */
338  *StackBegin = Thread->StackLimit;
339  *StackEnd = (ULONG_PTR)Thread->StackBase;
340 
341  /* Check if EBP is inside the stack */
342  if ((*StackBegin <= Ebp) && (Ebp <= *StackEnd))
343  {
344  /* Then make the stack start at EBP */
345  *StackBegin = Ebp;
346  }
347  else
348  {
349  /* Now we're going to assume we're on the DPC stack */
350  *StackEnd = (ULONG_PTR)(KeGetPcr()->Prcb->DpcStack);
351  *StackBegin = *StackEnd - KERNEL_STACK_SIZE;
352 
353  /* Check if we seem to be on the DPC stack */
354  if ((*StackEnd) && (*StackBegin < Ebp) && (Ebp <= *StackEnd))
355  {
356  /* We're on the DPC stack */
357  *StackBegin = Ebp;
358  }
359  else
360  {
361  /* We're somewhere else entirely... use EBP for safety */
362  *StackBegin = Ebp;
363  *StackEnd = (ULONG_PTR)PAGE_ALIGN(*StackBegin);
364  }
365  }
366 
367  /* Return success */
368  return TRUE;
369 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define TRUE
Definition: types.h:120
if(dx==0 &&dy==0)
Definition: linetemp.h:174
#define KeGetPcr()
Definition: ke.h:26
#define FALSE
Definition: types.h:117
#define PAGE_ALIGN(Va)
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
#define KERNEL_STACK_SIZE
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define ULONG_PTR
Definition: config.h:101
#define KeGetCurrentThread
Definition: hal.h:55

◆ RtlpCheckForActiveDebugger()

BOOLEAN NTAPI RtlpCheckForActiveDebugger ( VOID  )

Definition at line 79 of file libsupp.c.

80 {
81  /* This check is meaningless in kernel-mode */
82  return FALSE;
83 }
#define FALSE
Definition: types.h:117

◆ RtlpCheckLogException()

VOID NTAPI RtlpCheckLogException ( IN PEXCEPTION_RECORD  ExceptionRecord,
IN PCONTEXT  ContextRecord,
IN PVOID  ContextData,
IN ULONG  Size 
)

Definition at line 279 of file libsupp.c.

283 {
284  /* Check the global flag */
286  {
287  /* FIXME: Log this exception */
288  }
289 }
#define FLG_ENABLE_EXCEPTION_LOGGING
Definition: pstypes.h:82
ULONG NtGlobalFlag
Definition: init.c:52

◆ RtlpClearInDbgPrint()

VOID NTAPI RtlpClearInDbgPrint ( VOID  )

Definition at line 95 of file libsupp.c.

96 {
97  /* Nothing to clear in kernel mode */
98 }

◆ RtlpCloseHandleCallback()

BOOLEAN NTAPI RtlpCloseHandleCallback ( IN PHANDLE_TABLE_ENTRY  HandleTableEntry,
IN HANDLE  Handle,
IN PVOID  HandleTable 
)

Definition at line 568 of file libsupp.c.

572 {
573  /* Destroy and unlock the handle entry */
574  return ExDestroyHandle(HandleTable, Handle, HandleTableEntry);
575 }
BOOLEAN NTAPI ExDestroyHandle(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle, IN PHANDLE_TABLE_ENTRY HandleTableEntry OPTIONAL)
Definition: handle.c:948
static XMS_HANDLE HandleTable[XMS_MAX_HANDLES]
Definition: himem.c:83
_In_ HANDLE Handle
Definition: extypes.h:390

Referenced by RtlpDestroyAtomHandleTable().

◆ RtlpCreateAtomHandle()

BOOLEAN RtlpCreateAtomHandle ( PRTL_ATOM_TABLE  AtomTable,
PRTL_ATOM_TABLE_ENTRY  Entry 
)

Definition at line 640 of file libsupp.c.

641 {
642  HANDLE_TABLE_ENTRY ExEntry;
643  HANDLE Handle;
644  USHORT HandleIndex;
645 
646  /* Initialize ex handle table entry */
647  ExEntry.Object = Entry;
648  ExEntry.GrantedAccess = 0x1; /* FIXME - valid handle */
649 
650  /* Create ex handle */
651  Handle = ExCreateHandle(AtomTable->ExHandleTable,
652  &ExEntry);
653  if (!Handle) return FALSE;
654 
655  /* Calculate HandleIndex (by getting rid of the first two bits) */
656  HandleIndex = (USHORT)((ULONG_PTR)Handle >> 2);
657 
658  /* Index must be less than 0xC000 */
659  if (HandleIndex >= 0xC000)
660  {
661  /* Destroy ex handle */
662  ExDestroyHandle(AtomTable->ExHandleTable,
663  Handle,
664  NULL);
665 
666  /* Return failure */
667  return FALSE;
668  }
669 
670  /* Initialize atom table entry */
671  Entry->HandleIndex = HandleIndex;
672  Entry->Atom = 0xC000 + HandleIndex;
673 
674  /* Return success */
675  return TRUE;
676 }
BOOLEAN NTAPI ExDestroyHandle(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle, IN PHANDLE_TABLE_ENTRY HandleTableEntry OPTIONAL)
Definition: handle.c:948
struct _Entry Entry
Definition: kefuncs.h:627
#define TRUE
Definition: types.h:120
uint32_t ULONG_PTR
Definition: typedefs.h:65
HANDLE NTAPI ExCreateHandle(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:791
#define FALSE
Definition: types.h:117
Definition: extypes.h:595
ULONG GrantedAccess
Definition: extypes.h:606
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
_In_ HANDLE Handle
Definition: extypes.h:390
PVOID Object
Definition: extypes.h:599
base of all file and directory entries
Definition: entries.h:82

Referenced by RtlAddAtomToAtomTable().

◆ RtlpCreateAtomHandleTable()

BOOLEAN RtlpCreateAtomHandleTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 560 of file libsupp.c.

561 {
562  AtomTable->ExHandleTable = ExCreateHandleTable(NULL);
563  return (AtomTable->ExHandleTable != NULL);
564 }
PHANDLE_TABLE NTAPI ExCreateHandleTable(IN PEPROCESS Process OPTIONAL)
Definition: handle.c:765
#define NULL
Definition: types.h:112

Referenced by RtlCreateAtomTable().

◆ RtlPcToFileHeader()

PVOID NTAPI RtlPcToFileHeader ( IN PVOID  PcValue,
OUT PVOID BaseOfImage 
)

Definition at line 34 of file libsupp.c.

37 {
38  PLDR_DATA_TABLE_ENTRY LdrEntry;
39  BOOLEAN InSystem;
40  KIRQL OldIrql;
41 
42  /* Get the base for this file */
44  {
45  /* Acquire the loaded module spinlock */
47 
48  /* We are in kernel */
49  *BaseOfImage = KiPcToFileHeader(PcValue, &LdrEntry, FALSE, &InSystem);
50 
51  /* Release lock */
53  }
54  else
55  {
56  /* User mode is not handled here! */
57  *BaseOfImage = NULL;
58  }
59 
60  return *BaseOfImage;
61 }
PVOID NTAPI KiPcToFileHeader(IN PVOID Eip, OUT PLDR_DATA_TABLE_ENTRY *LdrEntry, IN BOOLEAN DriversOnly, OUT PBOOLEAN InKernel)
Definition: bug.c:41
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
UCHAR KIRQL
Definition: env_spec_w32.h:591
KSPIN_LOCK PsLoadedModuleSpinLock
Definition: sysldr.c:36
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
KIRQL OldIrql
Definition: mm.h:1502
PVOID MmHighestUserAddress
Definition: libsupp.c:23
Definition: btrfs_drv.h:1922
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

◆ RtlpDestroyAtomHandleTable()

VOID RtlpDestroyAtomHandleTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 578 of file libsupp.c.

579 {
580  if (AtomTable->ExHandleTable)
581  {
582  ExSweepHandleTable(AtomTable->ExHandleTable,
584  AtomTable->ExHandleTable);
585  ExDestroyHandleTable(AtomTable->ExHandleTable, NULL);
586  AtomTable->ExHandleTable = NULL;
587  }
588 }
VOID NTAPI ExDestroyHandleTable(IN PHANDLE_TABLE HandleTable, IN PVOID DestroyHandleProcedure OPTIONAL)
Definition: handle.c:927
BOOLEAN NTAPI RtlpCloseHandleCallback(IN PHANDLE_TABLE_ENTRY HandleTableEntry, IN HANDLE Handle, IN PVOID HandleTable)
Definition: libsupp.c:568
#define NULL
Definition: types.h:112
VOID NTAPI ExSweepHandleTable(IN PHANDLE_TABLE HandleTable, IN PEX_SWEEP_HANDLE_CALLBACK EnumHandleProcedure, IN PVOID Context)
Definition: handle.c:1196

Referenced by RtlDestroyAtomTable().

◆ RtlpDestroyAtomTableLock()

VOID RtlpDestroyAtomTableLock ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 541 of file libsupp.c.

542 {
543 }

Referenced by RtlCreateAtomTable(), and RtlDestroyAtomTable().

◆ RtlpFreeAtomHandle()

VOID RtlpFreeAtomHandle ( PRTL_ATOM_TABLE  AtomTable,
PRTL_ATOM_TABLE_ENTRY  Entry 
)

Definition at line 632 of file libsupp.c.

633 {
634  ExDestroyHandle(AtomTable->ExHandleTable,
635  (HANDLE)((ULONG_PTR)Entry->HandleIndex << 2),
636  NULL);
637 }
BOOLEAN NTAPI ExDestroyHandle(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle, IN PHANDLE_TABLE_ENTRY HandleTableEntry OPTIONAL)
Definition: handle.c:948
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define NULL
Definition: types.h:112
base of all file and directory entries
Definition: entries.h:82

Referenced by RtlDeleteAtomFromAtomTable(), and RtlEmptyAtomTable().

◆ RtlpFreeAtomTable()

VOID RtlpFreeAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 606 of file libsupp.c.

607 {
608  ExFreePoolWithTag(AtomTable, TAG_ATMT);
609 }
#define TAG_ATMT
Definition: libsupp.c:16
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by RtlCreateAtomTable(), and RtlDestroyAtomTable().

◆ RtlpFreeAtomTableEntry()

VOID RtlpFreeAtomTableEntry ( PRTL_ATOM_TABLE_ENTRY  Entry)

Definition at line 626 of file libsupp.c.

627 {
629 }
#define TAG_ATMT
Definition: libsupp.c:16
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
base of all file and directory entries
Definition: entries.h:82

Referenced by RtlAddAtomToAtomTable(), RtlDeleteAtomFromAtomTable(), RtlDestroyAtomTable(), and RtlEmptyAtomTable().

◆ RtlpFreeMemory()

VOID NTAPI RtlpFreeMemory ( PVOID  Mem,
ULONG  Tag 
)

Definition at line 123 of file libsupp.c.

125 {
126  if (Tag == TAG_ASTR || Tag == TAG_OSTR || Tag == TAG_USTR)
127  ExFreePool(Mem);
128  else
129  ExFreePoolWithTag(Mem, Tag);
130 }
#define TAG_OSTR
Definition: libsupp.c:120
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4061
#define TAG_USTR
Definition: libsupp.c:118
#define TAG_ASTR
Definition: libsupp.c:119
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ RtlpGetAtomEntry()

PRTL_ATOM_TABLE_ENTRY RtlpGetAtomEntry ( PRTL_ATOM_TABLE  AtomTable,
ULONG  Index 
)

Definition at line 679 of file libsupp.c.

680 {
681  PHANDLE_TABLE_ENTRY ExEntry;
683 
684  /* NOTE: There's no need to explicitly enter a critical region because it's
685  guaranteed that we're in a critical region right now (as we hold
686  the atom table lock) */
687 
688  ExEntry = ExMapHandleToPointer(AtomTable->ExHandleTable,
689  (HANDLE)((ULONG_PTR)Index << 2));
690  if (ExEntry != NULL)
691  {
692  Entry = ExEntry->Object;
693 
694  ExUnlockHandleTableEntry(AtomTable->ExHandleTable,
695  ExEntry);
696  }
697 
698  return Entry;
699 }
Definition: rtltypes.h:1669
struct _Entry Entry
Definition: kefuncs.h:627
PHANDLE_TABLE_ENTRY NTAPI ExMapHandleToPointer(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle)
Definition: handle.c:1010
VOID NTAPI ExUnlockHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:887
uint32_t ULONG_PTR
Definition: typedefs.h:65
Definition: extypes.h:595
_In_ WDFCOLLECTION _In_ ULONG Index
#define NULL
Definition: types.h:112
PVOID Object
Definition: extypes.h:599
base of all file and directory entries
Definition: entries.h:82

Referenced by RtlDeleteAtomFromAtomTable(), RtlPinAtomInAtomTable(), and RtlQueryAtomInAtomTable().

◆ RtlpGetMode()

KPROCESSOR_MODE NTAPI RtlpGetMode ( VOID  )

Definition at line 102 of file libsupp.c.

103 {
104  return KernelMode;
105 }

◆ RtlpHandleDpcStackException()

BOOLEAN NTAPI RtlpHandleDpcStackException ( IN PEXCEPTION_REGISTRATION_RECORD  RegistrationFrame,
IN ULONG_PTR  RegistrationFrameEnd,
IN OUT PULONG_PTR  StackLow,
IN OUT PULONG_PTR  StackHigh 
)

Definition at line 293 of file libsupp.c.

297 {
298  PKPRCB Prcb;
299  ULONG_PTR DpcStack;
300 
301  /* Check if we are at DISPATCH or higher */
303  {
304  /* Get the PRCB and DPC Stack */
305  Prcb = KeGetCurrentPrcb();
306  DpcStack = (ULONG_PTR)Prcb->DpcStack;
307 
308  /* Check if we are in a DPC and the stack matches */
309  if ((Prcb->DpcRoutineActive) &&
310  (RegistrationFrameEnd <= DpcStack) &&
311  ((ULONG_PTR)RegistrationFrame >= DpcStack - KERNEL_STACK_SIZE))
312  {
313  /* Update the limits to the DPC Stack's */
314  *StackHigh = DpcStack;
315  *StackLow = DpcStack - KERNEL_STACK_SIZE;
316  return TRUE;
317  }
318  }
319 
320  /* Not in DPC stack */
321  return FALSE;
322 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define TRUE
Definition: types.h:120
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1079
if(dx==0 &&dy==0)
Definition: linetemp.h:174
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
#define KERNEL_STACK_SIZE
UCHAR DpcRoutineActive
Definition: ketypes.h:692
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
PVOID DpcStack
Definition: ketypes.h:681
#define ULONG_PTR
Definition: config.h:101

◆ RtlpImageNtHeaderEx()

NTSTATUS NTAPI RtlpImageNtHeaderEx ( _In_ ULONG  Flags,
_In_ PVOID  Base,
_In_ ULONG64  Size,
_Out_ PIMAGE_NT_HEADERS OutHeaders 
)

Definition at line 140 of file image.c.

145 {
146  PIMAGE_NT_HEADERS NtHeaders;
147  PIMAGE_DOS_HEADER DosHeader;
148  BOOLEAN WantsRangeCheck;
149  ULONG NtHeaderOffset;
150 
151  /* You must want NT Headers, no? */
152  if (OutHeaders == NULL)
153  {
154  DPRINT1("OutHeaders is NULL\n");
156  }
157 
158  /* Assume failure */
159  *OutHeaders = NULL;
160 
161  /* Validate Flags */
163  {
164  DPRINT1("Invalid flags: 0x%lx\n", Flags);
166  }
167 
168  /* Validate base */
169  if ((Base == NULL) || (Base == (PVOID)-1))
170  {
171  DPRINT1("Invalid base address: %p\n", Base);
173  }
174 
175  /* Check if the caller wants range checks */
176  WantsRangeCheck = !(Flags & RTL_IMAGE_NT_HEADER_EX_FLAG_NO_RANGE_CHECK);
177  if (WantsRangeCheck)
178  {
179  /* Make sure the image size is at least big enough for the DOS header */
180  if (Size < sizeof(IMAGE_DOS_HEADER))
181  {
182  DPRINT1("Size too small\n");
184  }
185  }
186 
187  /* Check if the DOS Signature matches */
188  DosHeader = Base;
189  if (DosHeader->e_magic != IMAGE_DOS_SIGNATURE)
190  {
191  /* Not a valid COFF */
192  DPRINT1("Invalid image DOS signature!\n");
194  }
195 
196  /* Get the offset to the NT headers (and copy from LONG to ULONG) */
197  NtHeaderOffset = DosHeader->e_lfanew;
198 
199  /* The offset must not be larger than 256MB, as a hard-coded check.
200  In Windows this check is only done in user mode, not in kernel mode,
201  but it shouldn't harm to have it anyway. Note that without this check,
202  other overflow checks would become necessary! */
203  if (NtHeaderOffset >= (256 * 1024 * 1024))
204  {
205  /* Fail */
206  DPRINT1("NT headers offset is larger than 256MB!\n");
208  }
209 
210  /* Check if the caller wants validation */
211  if (WantsRangeCheck)
212  {
213  /* Make sure the file header fits into the size */
214  if ((NtHeaderOffset +
216  {
217  /* Fail */
218  DPRINT1("NT headers beyond image size!\n");
220  }
221  }
222 
223  /* Now get a pointer to the NT Headers */
224  NtHeaders = (PIMAGE_NT_HEADERS)((ULONG_PTR)Base + NtHeaderOffset);
225 
226  /* Check if the mapping is in user space */
227  if (Base <= MmHighestUserAddress)
228  {
229  /* Make sure we don't overflow into kernel space */
230  if ((PVOID)(NtHeaders + 1) > MmHighestUserAddress)
231  {
232  DPRINT1("Image overflows from user space into kernel space!\n");
234  }
235  }
236 
237  /* Verify the PE Signature */
238  if (NtHeaders->Signature != IMAGE_NT_SIGNATURE)
239  {
240  /* Fail */
241  DPRINT1("Invalid image NT signature!\n");
243  }
244 
245  /* Now return success and the NT header */
246  *OutHeaders = NtHeaders;
247  return STATUS_SUCCESS;
248 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2386
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
unsigned char BOOLEAN
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:359
#define RTL_IMAGE_NT_HEADER_EX_FLAG_NO_RANGE_CHECK
Definition: rtltypes.h:356
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
Definition: ntbasedef.h:672
#define NULL
Definition: types.h:112
PVOID MmHighestUserAddress
Definition: rtlcompat.c:29
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187

◆ RtlpInitAtomTableLock()

NTSTATUS RtlpInitAtomTableLock ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 532 of file libsupp.c.

533 {
534  ExInitializeFastMutex(&AtomTable->FastMutex);
535 
536  return STATUS_SUCCESS;
537 }
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by RtlCreateAtomTable().

◆ RtlpLockAtomTable()

BOOLEAN RtlpLockAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 547 of file libsupp.c.

548 {
549  ExAcquireFastMutex(&AtomTable->FastMutex);
550  return TRUE;
551 }
#define TRUE
Definition: types.h:120
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23

Referenced by RtlAddAtomToAtomTable(), RtlDeleteAtomFromAtomTable(), RtlDestroyAtomTable(), RtlEmptyAtomTable(), RtlLookupAtomInAtomTable(), RtlPinAtomInAtomTable(), RtlQueryAtomInAtomTable(), and RtlQueryAtomListInAtomTable().

◆ RtlpRemoveHeapFromProcessList()

VOID NTAPI RtlpRemoveHeapFromProcessList ( struct _HEAP Heap)

Definition at line 244 of file libsupp.c.

245 {
247 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317

Referenced by RtlDestroyHeap().

◆ RtlpSafeCopyMemory()

NTSTATUS NTAPI RtlpSafeCopyMemory ( _Out_writes_bytes_all_(Length) VOID UNALIGNED Destination,
_In_reads_bytes_(Length) CONST VOID UNALIGNED Source,
_In_ SIZE_T  Length 
)

Definition at line 797 of file libsupp.c.

801 {
802  _SEH2_TRY
803  {
805  }
807  {
809  }
810  _SEH2_END;
811 
812  return STATUS_SUCCESS;
813 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_SEH2_TRY
Definition: create.c:4226
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2950
_SEH2_END
Definition: create.c:4400
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168

◆ RtlpSetHeapParameters()

VOID NTAPI RtlpSetHeapParameters ( IN PRTL_HEAP_PARAMETERS  Parameters)

Definition at line 268 of file libsupp.c.

269 {
270  /* Apply defaults for non-set parameters */
271  if (!Parameters->SegmentCommit) Parameters->SegmentCommit = MmHeapSegmentCommit;
272  if (!Parameters->SegmentReserve) Parameters->SegmentReserve = MmHeapSegmentReserve;
273  if (!Parameters->DeCommitFreeBlockThreshold) Parameters->DeCommitFreeBlockThreshold = MmHeapDeCommitFreeBlockThreshold;
274  if (!Parameters->DeCommitTotalFreeThreshold) Parameters->DeCommitTotalFreeThreshold = MmHeapDeCommitTotalFreeThreshold;
275 }
SIZE_T MmHeapDeCommitTotalFreeThreshold
Definition: mminit.c:368
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:863
SIZE_T MmHeapDeCommitFreeBlockThreshold
Definition: mminit.c:369
SIZE_T MmHeapSegmentReserve
Definition: mminit.c:366
SIZE_T MmHeapSegmentCommit
Definition: mminit.c:367

◆ RtlpSetInDbgPrint()

BOOLEAN NTAPI RtlpSetInDbgPrint ( VOID  )

Definition at line 87 of file libsupp.c.

88 {
89  /* Nothing to set in kernel mode */
90  return FALSE;
91 }
#define FALSE
Definition: types.h:117

◆ RtlpUnlockAtomTable()

VOID RtlpUnlockAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 554 of file libsupp.c.

555 {
556  ExReleaseFastMutex(&AtomTable->FastMutex);
557 }
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31

Referenced by RtlAddAtomToAtomTable(), RtlDeleteAtomFromAtomTable(), RtlDestroyAtomTable(), RtlEmptyAtomTable(), RtlLookupAtomInAtomTable(), RtlPinAtomInAtomTable(), RtlQueryAtomInAtomTable(), and RtlQueryAtomListInAtomTable().

◆ RtlReleasePebLock()

VOID NTAPI RtlReleasePebLock ( VOID  )

Definition at line 145 of file libsupp.c.

146 {
147 
148 }

◆ RtlTryEnterHeapLock()

BOOLEAN NTAPI RtlTryEnterHeapLock ( IN OUT PHEAP_LOCK  Lock,
IN BOOLEAN  Exclusive 
)

Definition at line 191 of file libsupp.c.

192 {
195 
196  if (Exclusive)
198  else
200 
201  if (!Success)
203 
204  return Success;
205 }
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
__in PWDFDEVICE_INIT __in BOOLEAN Exclusive
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124

◆ RtlWalkFrameChain()

ULONG NTAPI RtlWalkFrameChain ( OUT PVOID Callers,
IN ULONG  Count,
IN ULONG  Flags 
)

Definition at line 376 of file libsupp.c.

379 {
380  ULONG_PTR Stack, NewStack, StackBegin, StackEnd = 0;
381  ULONG Eip;
382  BOOLEAN Result, StopSearch = FALSE;
383  ULONG i = 0;
385  PTEB Teb;
386  PKTRAP_FRAME TrapFrame;
387 
388  /* Get current EBP */
389 #if defined(_M_IX86)
390 #if defined __GNUC__
391  __asm__("mov %%ebp, %0" : "=r" (Stack) : );
392 #elif defined(_MSC_VER)
393  __asm mov Stack, ebp
394 #endif
395 #elif defined(_M_MIPS)
396  __asm__("move $sp, %0" : "=r" (Stack) : );
397 #elif defined(_M_PPC)
398  __asm__("mr %0,1" : "=r" (Stack) : );
399 #elif defined(_M_ARM)
400  __asm__("mov sp, %0" : "=r"(Stack) : );
401 #else
402 #error Unknown architecture
403 #endif
404 
405  /* Set it as the stack begin limit as well */
406  StackBegin = (ULONG_PTR)Stack;
407 
408  /* Check if we're called for non-logging mode */
409  if (!Flags)
410  {
411  /* Get the actual safe limits */
413  &StackBegin,
414  &StackEnd);
415  if (!Result) return 0;
416  }
417 
418  /* Use a SEH block for maximum protection */
419  _SEH2_TRY
420  {
421  /* Check if we want the user-mode stack frame */
422  if (Flags == 1)
423  {
424  /* Get the trap frame and TEB */
425  TrapFrame = KeGetTrapFrame(&Thread->Tcb);
426  Teb = Thread->Tcb.Teb;
427 
428  /* Make sure we can trust the TEB and trap frame */
429  if (!(Teb) ||
430  (KeIsAttachedProcess()) ||
432  {
433  /* Invalid or unsafe attempt to get the stack */
434  _SEH2_YIELD(return 0;)
435  }
436 
437  /* Get the stack limits */
438  StackBegin = (ULONG_PTR)Teb->NtTib.StackLimit;
439  StackEnd = (ULONG_PTR)Teb->NtTib.StackBase;
440 #ifdef _M_IX86
441  Stack = TrapFrame->Ebp;
442 #elif defined(_M_PPC)
443  Stack = TrapFrame->Gpr1;
444 #else
445 #error Unknown architecture
446 #endif
447 
448  /* Validate them */
449  if (StackEnd <= StackBegin) _SEH2_YIELD(return 0);
450  ProbeForRead((PVOID)StackBegin,
451  StackEnd - StackBegin,
452  sizeof(CHAR));
453  }
454 
455  /* Loop the frames */
456  for (i = 0; i < Count; i++)
457  {
458  /*
459  * Leave if we're past the stack,
460  * if we're before the stack,
461  * or if we've reached ourselves.
462  */
463  if ((Stack >= StackEnd) ||
464  (!i ? (Stack < StackBegin) : (Stack <= StackBegin)) ||
465  ((StackEnd - Stack) < (2 * sizeof(ULONG_PTR))))
466  {
467  /* We're done or hit a bad address */
468  break;
469  }
470 
471  /* Get new stack and EIP */
472  NewStack = *(PULONG_PTR)Stack;
473  Eip = *(PULONG_PTR)(Stack + sizeof(ULONG_PTR));
474 
475  /* Check if the new pointer is above the oldone and past the end */
476  if (!((Stack < NewStack) && (NewStack < StackEnd)))
477  {
478  /* Stop searching after this entry */
479  StopSearch = TRUE;
480  }
481 
482  /* Also make sure that the EIP isn't a stack address */
483  if ((StackBegin < Eip) && (Eip < StackEnd)) break;
484 
485  /* Check if we reached a user-mode address */
486  if (!(Flags) && !(Eip & 0x80000000)) break; // FIXME: 3GB breakage
487 
488  /* Save this frame */
489  Callers[i] = (PVOID)Eip;
490 
491  /* Check if we should continue */
492  if (StopSearch)
493  {
494  /* Return the next index */
495  i++;
496  break;
497  }
498 
499  /* Move to the next stack */
500  Stack = NewStack;
501  }
502  }
504  {
505  /* No index */
506  i = 0;
507  }
508  _SEH2_END;
509 
510  /* Return frames parsed */
511  return i;
512 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx eax jnz xchgl ecx incl TEMP esp ecx subl ebx pushl ecx ecx edx ecx ecx mm0 mm4 mm0 mm4 mm1 mm5 mm1 mm5 mm2 mm6 mm2 mm6 mm3 mm7 mm3 mm7 paddd mm0 paddd mm4 paddd mm0 paddd mm4 paddd mm0 paddd mm4 movq mm1 movq mm5 mm1 mm5 paddd mm0 paddd mm4 mm0 mm4 packssdw mm0 packssdw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz popl ecx ecx jecxz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 mm1 paddd mm0 mm0 packssdw mm0 movd eax movw edi esi edx esi ecx mm0 mm4 mm0 mm4 mm1 mm5 mm1 mm5 mm2 mm6 mm2 mm6 mm3 mm7 mm3 mm7 paddd mm0 paddd mm4 paddd mm0 paddd mm4 paddd mm0 paddd mm4 movq mm1 movq mm5 mm1 mm5 paddd mm1 paddd mm5 mm1 mm5 packssdw mm1 packssdw mm5 psubd mm0 psubd mm4 psubsw mm0 psubsw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 mm1 paddd mm1 mm1 packssdw mm1 psubd mm0 psubsw mm0 movd eax movw edi emms popl ebx popl esi popl edi mov ebp
Definition: synth_sse3d.h:248
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
KTHREAD Tcb
Definition: pstypes.h:1103
__asm__("\n\t \ NewInt3Handler:\n\t \ pushl $" STR(REASON_INT3) "\n\t \ // call debugger loop\n\t \ jmp NewInt31Handler\n\t \ ")
_SEH2_TRY
Definition: create.c:4226
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
#define FALSE
Definition: types.h:117
BOOLEAN NTAPI KeIsAttachedProcess(VOID)
Definition: procobj.c:693
unsigned char BOOLEAN
ULONG Gpr1
Definition: ketypes.h:103
_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
void * PVOID
Definition: retypes.h:9
BOOLEAN NTAPI RtlpCaptureStackLimits(IN ULONG_PTR Ebp, IN ULONG_PTR *StackBegin, IN ULONG_PTR *StackEnd)
Definition: libsupp.c:211
int Count
Definition: noreturn.cpp:7
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
Definition: compat.h:694
_SEH2_END
Definition: create.c:4400
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PVOID StackBase
Definition: compat.h:571
PVOID Teb
Definition: ketypes.h:1739
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
uint32_t * PULONG_PTR
Definition: typedefs.h:65
PVOID StackLimit
Definition: compat.h:572
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define KeGetTrapFrame(Thread)
Definition: ke.h:204
NT_TIB NtTib
Definition: ntddk_ex.h:332
ULONG Ebp
Definition: ketypes.h:265

Variable Documentation

◆ NtGlobalFlag

ULONG NtGlobalFlag

Definition at line 52 of file init.c.

Referenced by RtlpCheckLogException().

◆ RtlpAllocDeallocQueryBufferSize

SIZE_T RtlpAllocDeallocQueryBufferSize = 128

Definition at line 28 of file libsupp.c.

Referenced by RtlQueryRegistryValues().

◆ RtlpRangeListEntryLookasideList

PAGED_LOOKASIDE_LIST RtlpRangeListEntryLookasideList

Definition at line 27 of file libsupp.c.

Referenced by RtlInitializeRangeListPackage().