ReactOS 0.4.16-dev-88-ga65b6ae
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
 

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)
 
VOID NTAPI RtlpGetStackLimits (OUT PULONG_PTR LowLimit, OUT PULONG_PTR HighLimit)
 
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.

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 757 of file libsupp.c.

759{
760 ULONG size;
761 void *root;
762 IMAGE_RESOURCE_DIRECTORY *resdirptr;
763
766 if (size < sizeof(*resdirptr)) return STATUS_RESOURCE_DATA_NOT_FOUND;
767 resdirptr = root;
768
769 if (!level--) goto done;
770 if (!(*ret = find_entry_by_name( resdirptr, (LPCWSTR)info->Type, root, want_dir || level )))
772 if (!level--) return STATUS_SUCCESS;
773
774 resdirptr = *ret;
775 if (!(*ret = find_entry_by_name( resdirptr, (LPCWSTR)info->Name, root, want_dir || level )))
777 if (!level--) return STATUS_SUCCESS;
778 if (level) return STATUS_INVALID_PARAMETER; /* level > 3 */
779
780 resdirptr = *ret;
781
782 if ((*ret = find_first_entry( resdirptr, root, want_dir ))) return STATUS_SUCCESS;
783
785
786done:
787 *ret = resdirptr;
788 return STATUS_SUCCESS;
789}
struct _root root
#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
IMAGE_RESOURCE_DIRECTORY * find_first_entry(IMAGE_RESOURCE_DIRECTORY *dir, void *root, int want_dir)
Definition: res.c:75
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
GLint level
Definition: gl.h:1546
GLsizeiptr size
Definition: glext.h:5919
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define STATUS_RESOURCE_NAME_NOT_FOUND
Definition: ntstatus.h:375
#define STATUS_RESOURCE_TYPE_NOT_FOUND
Definition: ntstatus.h:374
#define STATUS_RESOURCE_DATA_NOT_FOUND
Definition: ntstatus.h:373
#define IMAGE_DIRECTORY_ENTRY_RESOURCE
Definition: pedump.c:261
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
int ret
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

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
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}
DWORD Id
unsigned int dir
Definition: maze.c:112
#define NULL
Definition: types.h:112
uint32_t entry
Definition: isohybrid.c:63
#define min(a, b)
Definition: monoChain.cc:55
#define DPRINT
Definition: sndvol32.h:73
Definition: pedump.c:414
#define max(a, b)
Definition: svc.c:63

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 );
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}
GLuint res
Definition: glext.h:9613
GLint namelen
Definition: glext.h:7232
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
const WCHAR * str
_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
Definition: name.c:39
uint32_t ULONG_PTR
Definition: typedefs.h:65

◆ 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}

◆ LdrShutdownThread()

NTSTATUS NTAPI LdrShutdownThread ( VOID  )

Definition at line 145 of file libsupp.c.

146{
147 return STATUS_SUCCESS;
148}

Referenced by ExitThread(), and RtlExitUserThread().

◆ RtlAcquirePebLock()

◆ RtlCallVectoredContinueHandlers()

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

Definition at line 822 of file libsupp.c.

824{
825 /* No vectored continue handlers either in kernel mode */
826 return;
827}

Referenced by RtlDispatchException().

◆ RtlCallVectoredExceptionHandlers()

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

Definition at line 813 of file libsupp.c.

815{
816 /* In the kernel we don't have vectored exception handlers */
817 return FALSE;
818}
#define FALSE
Definition: types.h:117

Referenced by RtlDispatchException().

◆ RtlDeleteHeapLock()

NTSTATUS NTAPI RtlDeleteHeapLock ( IN OUT PHEAP_LOCK  Lock)

Definition at line 160 of file libsupp.c.

161{
162 ExDeleteResourceLite(&Lock->Resource);
164
165 return STATUS_SUCCESS;
166}
#define ExDeleteResourceLite(res)
Definition: env_spec_w32.h:647
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define TAG_RTHL
Definition: tag.h:144
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127

◆ RtlEnterHeapLock()

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

Definition at line 170 of file libsupp.c.

171{
173
174 if (Exclusive)
176 else
178
179 return STATUS_SUCCESS;
180}
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
#define ExAcquireResourceSharedLite(res, wait)
Definition: env_spec_w32.h:621
__in PWDFDEVICE_INIT __in BOOLEAN Exclusive
#define KeEnterCriticalRegion()
Definition: ke_x.h:88

◆ RtlGetCurrentPeb()

◆ RtlImageNtHeaderEx()

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

Definition at line 714 of file libsupp.c.

719{
721
722 /* Assume failure. This is also done in RtlpImageNtHeaderEx, but this is guarded by SEH. */
723 if (OutHeaders != NULL)
724 *OutHeaders = NULL;
725
727 {
728 Status = RtlpImageNtHeaderEx(Flags, Base, Size, OutHeaders);
729 }
731 {
732 /* Fail with the SEH error */
734 }
735 _SEH2_END;
736
737 return Status;
738}
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI RtlpImageNtHeaderEx(_In_ ULONG Flags, _In_ PVOID Base, _In_ ULONG64 Size, _Out_ PIMAGE_NT_HEADERS *OutHeaders)
Definition: image.c:140
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
Status
Definition: gdiplustypes.h:25
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2451
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

◆ RtlInitializeHeapLock()

NTSTATUS NTAPI RtlInitializeHeapLock ( IN OUT PHEAP_LOCK Lock)

Definition at line 202 of file libsupp.c.

203{
205 sizeof(HEAP_LOCK),
206 TAG_RTHL);
207 if (HeapLock == NULL)
208 return STATUS_NO_MEMORY;
209
211 *Lock = HeapLock;
212
213 return STATUS_SUCCESS;
214}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define NonPagedPool
Definition: env_spec_w32.h:307
BOOL WINAPI HeapLock(HANDLE hHeap)
Definition: heapmem.c:123
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260

◆ RtlInitializeHeapManager()

VOID RtlInitializeHeapManager ( VOID  )

Definition at line 243 of file libsupp.c.

244{
245}

◆ RtlInitializeRangeListPackage()

VOID NTAPI RtlInitializeRangeListPackage ( VOID  )

Definition at line 62 of file libsupp.c.

63{
64 /* Setup the lookaside list for allocations (not used yet) */
66 NULL,
67 NULL,
69 sizeof(RTL_RANGE_ENTRY),
70 'elRR',
71 16);
72}
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
PAGED_LOOKASIDE_LIST RtlpRangeListEntryLookasideList
Definition: libsupp.c:24
Definition: libsupp.c:19
#define POOL_COLD_ALLOCATION

Referenced by Phase1InitializationDiscard().

◆ RtlLeaveHeapLock()

NTSTATUS NTAPI RtlLeaveHeapLock ( IN OUT PHEAP_LOCK  Lock)

Definition at line 218 of file libsupp.c.

219{
220 ExReleaseResourceLite(&Lock->Resource);
222
223 return STATUS_SUCCESS;
224}
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822

◆ RtlpAddHeapToProcessList()

VOID NTAPI RtlpAddHeapToProcessList ( struct _HEAP Heap)

Definition at line 230 of file libsupp.c.

231{
233}
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317

Referenced by RtlCreateHeap().

◆ RtlpAllocateMemory()

PVOID NTAPI RtlpAllocateMemory ( ULONG  Bytes,
ULONG  Tag 
)

Definition at line 106 of file libsupp.c.

108{
110 (SIZE_T)Bytes,
111 Tag);
112}
#define PagedPool
Definition: env_spec_w32.h:308
_In_ UINT Bytes
Definition: mmcopy.h:9
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065

◆ RtlpAllocAtomTable()

PRTL_ATOM_TABLE RtlpAllocAtomTable ( ULONG  Size)

Definition at line 587 of file libsupp.c.

588{
590 Size,
591 TAG_ATMT);
592 if (Table != NULL)
593 {
595 Size);
596 }
597
598 return Table;
599}
ASMGENDATA Table[]
Definition: genincdata.c:61
struct atom_table ** PRTL_ATOM_TABLE
Definition: atom.c:43
#define TAG_ATMT
Definition: tag.h:143
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by RtlCreateAtomTable().

◆ RtlpAllocAtomTableEntry()

PRTL_ATOM_TABLE_ENTRY RtlpAllocAtomTableEntry ( ULONG  Size)

Definition at line 608 of file libsupp.c.

609{
611
613 if (Entry != NULL)
614 {
616 }
617
618 return Entry;
619}
base of all file and directory entries
Definition: entries.h:83
Definition: rtltypes.h:1672

Referenced by RtlAddAtomToAtomTable().

◆ RtlpCaptureStackLimits()

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

Definition at line 321 of file libsupp.c.

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

◆ RtlpCheckForActiveDebugger()

BOOLEAN NTAPI RtlpCheckForActiveDebugger ( VOID  )

Definition at line 76 of file libsupp.c.

77{
78 /* This check is meaningless in kernel-mode */
79 return FALSE;
80}

◆ RtlpCheckLogException()

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

Definition at line 272 of file libsupp.c.

276{
277 /* Check the global flag */
279 {
280 /* FIXME: Log this exception */
281 }
282}
#define FLG_ENABLE_EXCEPTION_LOGGING
Definition: pstypes.h:82
ULONG NtGlobalFlag
Definition: init.c:54

◆ RtlpClearInDbgPrint()

VOID NTAPI RtlpClearInDbgPrint ( VOID  )

Definition at line 92 of file libsupp.c.

93{
94 /* Nothing to clear in kernel mode */
95}

◆ RtlpCloseHandleCallback()

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

Definition at line 564 of file libsupp.c.

568{
569 /* Destroy and unlock the handle entry */
570 return ExDestroyHandle(HandleTable, Handle, HandleTableEntry);
571}
ULONG Handle
Definition: gdb_input.c:15
static XMS_HANDLE HandleTable[XMS_MAX_HANDLES]
Definition: himem.c:83
BOOLEAN NTAPI ExDestroyHandle(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle, IN PHANDLE_TABLE_ENTRY HandleTableEntry OPTIONAL)
Definition: handle.c:984

Referenced by RtlpDestroyAtomHandleTable().

◆ RtlpCreateAtomHandle()

BOOLEAN RtlpCreateAtomHandle ( PRTL_ATOM_TABLE  AtomTable,
PRTL_ATOM_TABLE_ENTRY  Entry 
)

Definition at line 636 of file libsupp.c.

637{
638 HANDLE_TABLE_ENTRY ExEntry;
640 USHORT HandleIndex;
641
642 /* Initialize ex handle table entry */
643 ExEntry.Object = Entry;
644 ExEntry.GrantedAccess = 0x1; /* FIXME - valid handle */
645
646 /* Create ex handle */
647 Handle = ExCreateHandle(AtomTable->ExHandleTable,
648 &ExEntry);
649 if (!Handle) return FALSE;
650
651 /* Calculate HandleIndex (by getting rid of the first two bits) */
652 HandleIndex = (USHORT)((ULONG_PTR)Handle >> 2);
653
654 /* Index must be less than 0xC000 */
655 if (HandleIndex >= 0xC000)
656 {
657 /* Destroy ex handle */
658 ExDestroyHandle(AtomTable->ExHandleTable,
659 Handle,
660 NULL);
661
662 /* Return failure */
663 return FALSE;
664 }
665
666 /* Initialize atom table entry */
667 Entry->HandleIndex = HandleIndex;
668 Entry->Atom = 0xC000 + HandleIndex;
669
670 /* Return success */
671 return TRUE;
672}
HANDLE NTAPI ExCreateHandle(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:827
unsigned short USHORT
Definition: pedump.c:61
Definition: extypes.h:596
PVOID Object
Definition: extypes.h:599
ULONG GrantedAccess
Definition: extypes.h:606

Referenced by RtlAddAtomToAtomTable().

◆ RtlpCreateAtomHandleTable()

BOOLEAN RtlpCreateAtomHandleTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 556 of file libsupp.c.

557{
558 AtomTable->ExHandleTable = ExCreateHandleTable(NULL);
559 return (AtomTable->ExHandleTable != NULL);
560}
PHANDLE_TABLE NTAPI ExCreateHandleTable(IN PEPROCESS Process OPTIONAL)
Definition: handle.c:801

Referenced by RtlCreateAtomTable().

◆ RtlPcToFileHeader()

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

Definition at line 31 of file libsupp.c.

34{
35 PLDR_DATA_TABLE_ENTRY LdrEntry;
36 BOOLEAN InSystem;
38
39 /* Get the base for this file */
41 {
42 /* Acquire the loaded module spinlock */
44
45 /* We are in kernel */
46 *BaseOfImage = KiPcToFileHeader(PcValue, &LdrEntry, FALSE, &InSystem);
47
48 /* Release lock */
50 }
51 else
52 {
53 /* User mode is not handled here! */
54 *BaseOfImage = NULL;
55 }
56
57 return *BaseOfImage;
58}
unsigned char BOOLEAN
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
PVOID NTAPI KiPcToFileHeader(IN PVOID Eip, OUT PLDR_DATA_TABLE_ENTRY *LdrEntry, IN BOOLEAN DriversOnly, OUT PBOOLEAN InKernel)
Definition: bug.c:44
KSPIN_LOCK PsLoadedModuleSpinLock
Definition: sysldr.c:23
PVOID MmHighestUserAddress
Definition: rtlcompat.c:29
Definition: btrfs_drv.h:1876
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

◆ RtlpDestroyAtomHandleTable()

VOID RtlpDestroyAtomHandleTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 574 of file libsupp.c.

575{
576 if (AtomTable->ExHandleTable)
577 {
578 ExSweepHandleTable(AtomTable->ExHandleTable,
580 AtomTable->ExHandleTable);
581 ExDestroyHandleTable(AtomTable->ExHandleTable, NULL);
582 AtomTable->ExHandleTable = NULL;
583 }
584}
VOID NTAPI ExSweepHandleTable(IN PHANDLE_TABLE HandleTable, IN PEX_SWEEP_HANDLE_CALLBACK EnumHandleProcedure, IN PVOID Context)
Definition: handle.c:1232
VOID NTAPI ExDestroyHandleTable(IN PHANDLE_TABLE HandleTable, IN PVOID DestroyHandleProcedure OPTIONAL)
Definition: handle.c:963
BOOLEAN NTAPI RtlpCloseHandleCallback(IN PHANDLE_TABLE_ENTRY HandleTableEntry, IN HANDLE Handle, IN PVOID HandleTable)
Definition: libsupp.c:564

Referenced by RtlDestroyAtomTable().

◆ RtlpDestroyAtomTableLock()

VOID RtlpDestroyAtomTableLock ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 537 of file libsupp.c.

538{
539}

Referenced by RtlCreateAtomTable(), and RtlDestroyAtomTable().

◆ RtlpFreeAtomHandle()

VOID RtlpFreeAtomHandle ( PRTL_ATOM_TABLE  AtomTable,
PRTL_ATOM_TABLE_ENTRY  Entry 
)

Definition at line 628 of file libsupp.c.

629{
630 ExDestroyHandle(AtomTable->ExHandleTable,
631 (HANDLE)((ULONG_PTR)Entry->HandleIndex << 2),
632 NULL);
633}

Referenced by RtlDeleteAtomFromAtomTable(), and RtlEmptyAtomTable().

◆ RtlpFreeAtomTable()

VOID RtlpFreeAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 602 of file libsupp.c.

603{
604 ExFreePoolWithTag(AtomTable, TAG_ATMT);
605}

Referenced by RtlCreateAtomTable(), and RtlDestroyAtomTable().

◆ RtlpFreeAtomTableEntry()

VOID RtlpFreeAtomTableEntry ( PRTL_ATOM_TABLE_ENTRY  Entry)

◆ RtlpFreeMemory()

VOID NTAPI RtlpFreeMemory ( PVOID  Mem,
ULONG  Tag 
)

Definition at line 116 of file libsupp.c.

118{
119 if (Tag == TAG_ASTR || Tag == TAG_OSTR || Tag == TAG_USTR)
120 ExFreePool(Mem);
121 else
123}
#define TAG_USTR
Definition: libsupp.c:997
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define TAG_OSTR
Definition: tag.h:147
#define TAG_ASTR
Definition: tag.h:146

◆ RtlpGetAtomEntry()

PRTL_ATOM_TABLE_ENTRY RtlpGetAtomEntry ( PRTL_ATOM_TABLE  AtomTable,
ULONG  Index 
)

Definition at line 675 of file libsupp.c.

676{
677 PHANDLE_TABLE_ENTRY ExEntry;
679
680 /* NOTE: There's no need to explicitly enter a critical region because it's
681 guaranteed that we're in a critical region right now (as we hold
682 the atom table lock) */
683
684 ExEntry = ExMapHandleToPointer(AtomTable->ExHandleTable,
685 (HANDLE)((ULONG_PTR)Index << 2));
686 if (ExEntry != NULL)
687 {
688 Entry = ExEntry->Object;
689
690 ExUnlockHandleTableEntry(AtomTable->ExHandleTable,
691 ExEntry);
692 }
693
694 return Entry;
695}
PHANDLE_TABLE_ENTRY NTAPI ExMapHandleToPointer(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle)
Definition: handle.c:1046
VOID NTAPI ExUnlockHandleTableEntry(IN PHANDLE_TABLE HandleTable, IN PHANDLE_TABLE_ENTRY HandleTableEntry)
Definition: handle.c:923
_In_ WDFCOLLECTION _In_ ULONG Index

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

◆ RtlpGetMode()

KPROCESSOR_MODE NTAPI RtlpGetMode ( VOID  )

Definition at line 99 of file libsupp.c.

100{
101 return KernelMode;
102}
#define KernelMode
Definition: asm.h:34

◆ RtlpGetStackLimits()

VOID NTAPI RtlpGetStackLimits ( OUT PULONG_PTR  LowLimit,
OUT PULONG_PTR  HighLimit 
)

Definition at line 511 of file libsupp.c.

514{
515 PKTHREAD CurrentThread = KeGetCurrentThread();
516 *LowLimit = (ULONG_PTR)CurrentThread->StackLimit;
517#ifdef _M_IX86
518 *HighLimit = (ULONG_PTR)CurrentThread->InitialStack -
519 sizeof(FX_SAVE_AREA);
520#else
521 *HighLimit = (ULONG_PTR)CurrentThread->InitialStack;
522#endif
523}
struct _FX_SAVE_AREA FX_SAVE_AREA
PVOID InitialStack
Definition: ketypes.h:1664
volatile VOID * StackLimit
Definition: ketypes.h:1665
_Out_ PULONG_PTR HighLimit
Definition: iofuncs.h:2885

◆ 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 286 of file libsupp.c.

290{
291 PKPRCB Prcb;
292 ULONG_PTR DpcStack;
293
294 /* Check if we are at DISPATCH or higher */
296 {
297 /* Get the PRCB and DPC Stack */
298 Prcb = KeGetCurrentPrcb();
299 DpcStack = (ULONG_PTR)Prcb->DpcStack;
300
301 /* Check if we are in a DPC and the stack matches */
302 if ((Prcb->DpcRoutineActive) &&
303 (RegistrationFrameEnd <= DpcStack) &&
304 ((ULONG_PTR)RegistrationFrame >= DpcStack - KERNEL_STACK_SIZE))
305 {
306 /* Update the limits to the DPC Stack's */
307 *StackHigh = DpcStack;
308 *StackLow = DpcStack - KERNEL_STACK_SIZE;
309 return TRUE;
310 }
311 }
312
313 /* Not in DPC stack */
314 return FALSE;
315}
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1161
UCHAR DpcRoutineActive
Definition: ketypes.h:772
PVOID DpcStack
Definition: ketypes.h:761

◆ 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 */
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 */
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 DPRINT1
Definition: precomp.h:8
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187
#define RTL_IMAGE_NT_HEADER_EX_FLAG_NO_RANGE_CHECK
Definition: rtltypes.h:358
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
Definition: ntbasedef.h:672
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:359
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89

◆ RtlpInitAtomTableLock()

NTSTATUS RtlpInitAtomTableLock ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 528 of file libsupp.c.

529{
530 ExInitializeFastMutex(&AtomTable->FastMutex);
531
532 return STATUS_SUCCESS;
533}
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274

Referenced by RtlCreateAtomTable().

◆ RtlpLockAtomTable()

BOOLEAN RtlpLockAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 543 of file libsupp.c.

544{
545 ExAcquireFastMutex(&AtomTable->FastMutex);
546 return TRUE;
547}
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 237 of file libsupp.c.

238{
240}

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 793 of file libsupp.c.

797{
799 {
801 }
803 {
805 }
806 _SEH2_END;
807
808 return STATUS_SUCCESS;
809}
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3016
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

◆ RtlpSetHeapParameters()

VOID NTAPI RtlpSetHeapParameters ( IN PRTL_HEAP_PARAMETERS  Parameters)

Definition at line 261 of file libsupp.c.

262{
263 /* Apply defaults for non-set parameters */
264 if (!Parameters->SegmentCommit) Parameters->SegmentCommit = MmHeapSegmentCommit;
265 if (!Parameters->SegmentReserve) Parameters->SegmentReserve = MmHeapSegmentReserve;
266 if (!Parameters->DeCommitFreeBlockThreshold) Parameters->DeCommitFreeBlockThreshold = MmHeapDeCommitFreeBlockThreshold;
267 if (!Parameters->DeCommitTotalFreeThreshold) Parameters->DeCommitTotalFreeThreshold = MmHeapDeCommitTotalFreeThreshold;
268}
SIZE_T MmHeapSegmentReserve
Definition: mminit.c:366
SIZE_T MmHeapDeCommitFreeBlockThreshold
Definition: mminit.c:369
SIZE_T MmHeapDeCommitTotalFreeThreshold
Definition: mminit.c:368
SIZE_T MmHeapSegmentCommit
Definition: mminit.c:367
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869

◆ RtlpSetInDbgPrint()

BOOLEAN NTAPI RtlpSetInDbgPrint ( VOID  )

Definition at line 84 of file libsupp.c.

85{
86 /* Nothing to set in kernel mode */
87 return FALSE;
88}

◆ RtlpUnlockAtomTable()

VOID RtlpUnlockAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 550 of file libsupp.c.

551{
552 ExReleaseFastMutex(&AtomTable->FastMutex);
553}
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31

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

◆ RtlReleasePebLock()

◆ RtlTryEnterHeapLock()

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

Definition at line 184 of file libsupp.c.

185{
188
189 if (Exclusive)
191 else
193
194 if (!Success)
196
197 return Success;
198}
@ Success
Definition: eventcreate.c:712

◆ RtlWalkFrameChain()

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

Definition at line 369 of file libsupp.c.

372{
373 ULONG_PTR Stack, NewStack, StackBegin, StackEnd = 0;
374 ULONG Eip;
375 BOOLEAN Result, StopSearch = FALSE;
376 ULONG i = 0;
378 PTEB Teb;
379 PKTRAP_FRAME TrapFrame;
380
381 /* Get current EBP */
382#if defined(_M_IX86)
383#if defined __GNUC__
384 __asm__("mov %%ebp, %0" : "=r" (Stack) : );
385#elif defined(_MSC_VER)
386 __asm mov Stack, ebp
387#endif
388#elif defined(_M_MIPS)
389 __asm__("move $sp, %0" : "=r" (Stack) : );
390#elif defined(_M_PPC)
391 __asm__("mr %0,1" : "=r" (Stack) : );
392#elif defined(_M_ARM)
393 __asm__("mov sp, %0" : "=r"(Stack) : );
394#else
395#error Unknown architecture
396#endif
397
398 /* Set it as the stack begin limit as well */
399 StackBegin = (ULONG_PTR)Stack;
400
401 /* Check if we're called for non-logging mode */
402 if (!Flags)
403 {
404 /* Get the actual safe limits */
406 &StackBegin,
407 &StackEnd);
408 if (!Result) return 0;
409 }
410
411 /* Use a SEH block for maximum protection */
413 {
414 /* Check if we want the user-mode stack frame */
415 if (Flags == 1)
416 {
417 /* Get the trap frame and TEB */
418 TrapFrame = KeGetTrapFrame(&Thread->Tcb);
419 Teb = Thread->Tcb.Teb;
420
421 /* Make sure we can trust the TEB and trap frame */
422 if (!(Teb) ||
425 {
426 /* Invalid or unsafe attempt to get the stack */
427 _SEH2_YIELD(return 0;)
428 }
429
430 /* Get the stack limits */
431 StackBegin = (ULONG_PTR)Teb->NtTib.StackLimit;
432 StackEnd = (ULONG_PTR)Teb->NtTib.StackBase;
433#ifdef _M_IX86
434 Stack = TrapFrame->Ebp;
435#elif defined(_M_PPC)
436 Stack = TrapFrame->Gpr1;
437#else
438#error Unknown architecture
439#endif
440
441 /* Validate them */
442 if (StackEnd <= StackBegin) _SEH2_YIELD(return 0);
443 ProbeForRead((PVOID)StackBegin,
444 StackEnd - StackBegin,
445 sizeof(CHAR));
446 }
447
448 /* Loop the frames */
449 for (i = 0; i < Count; i++)
450 {
451 /*
452 * Leave if we're past the stack,
453 * if we're before the stack,
454 * or if we've reached ourselves.
455 */
456 if ((Stack >= StackEnd) ||
457 (!i ? (Stack < StackBegin) : (Stack <= StackBegin)) ||
458 ((StackEnd - Stack) < (2 * sizeof(ULONG_PTR))))
459 {
460 /* We're done or hit a bad address */
461 break;
462 }
463
464 /* Get new stack and EIP */
465 NewStack = *(PULONG_PTR)Stack;
466 Eip = *(PULONG_PTR)(Stack + sizeof(ULONG_PTR));
467
468 /* Check if the new pointer is above the oldone and past the end */
469 if (!((Stack < NewStack) && (NewStack < StackEnd)))
470 {
471 /* Stop searching after this entry */
472 StopSearch = TRUE;
473 }
474
475 /* Also make sure that the EIP isn't a stack address */
476 if ((StackBegin < Eip) && (Eip < StackEnd)) break;
477
478 /* Check if we reached a user-mode address */
479 if (!(Flags) && !(Eip & 0x80000000)) break; // FIXME: 3GB breakage
480
481 /* Save this frame */
482 Callers[i] = (PVOID)Eip;
483
484 /* Check if we should continue */
485 if (StopSearch)
486 {
487 /* Return the next index */
488 i++;
489 break;
490 }
491
492 /* Move to the next stack */
493 Stack = NewStack;
494 }
495 }
497 {
498 /* No index */
499 i = 0;
500 }
501 _SEH2_END;
502
503 /* Return frames parsed */
504 return i;
505}
BOOLEAN NTAPI RtlpCaptureStackLimits(IN ULONG_PTR Ebp, IN ULONG_PTR *StackBegin, IN ULONG_PTR *StackEnd)
Definition: libsupp.c:213
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
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
int Count
Definition: noreturn.cpp:7
#define KeGetTrapFrame(Thread)
Definition: ke.h:208
BOOLEAN NTAPI KeIsAttachedProcess(VOID)
Definition: procobj.c:693
__asm__(".p2align 4, 0x90\n" ".seh_proc __seh2_global_filter_func\n" "__seh2_global_filter_func:\n" "\tsub %rbp, %rax\n" "\tpush %rbp\n" "\t.seh_pushreg %rbp\n" "\tsub $32, %rsp\n" "\t.seh_stackalloc 32\n" "\t.seh_endprologue\n" "\tsub %rax, %rdx\n" "\tmov %rdx, %rbp\n" "\tjmp *%r8\n" "__seh2_global_filter_func_exit:\n" "\t.p2align 4\n" "\tadd $32, %rsp\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")
KTHREAD Tcb
Definition: pstypes.h:1104
PVOID Teb
Definition: ketypes.h:1807
ULONG Ebp
Definition: ketypes.h:319
PVOID StackLimit
Definition: compat.h:713
PVOID StackBase
Definition: compat.h:712
Definition: compat.h:836
NT_TIB NtTib
Definition: ntddk_ex.h:332
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx testl eax jnz xchgl ecx incl TEMP esp ecx subl ebx pushl ecx ecx edx ecx shrl 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 psrlq mm1 psrlq mm5 paddd mm0 paddd mm4 psrad mm0 psrad mm4 packssdw mm0 packssdw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz popl ecx andl ecx jecxz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 psrlq mm1 paddd mm0 psrad mm0 packssdw mm0 movd eax movw edi esi edx esi movl 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 psrlq mm1 psrlq mm5 paddd mm1 paddd mm5 psrad mm1 psrad mm5 packssdw mm1 packssdw mm5 psubd mm0 psubd mm4 psubsw mm0 psubsw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi subl esi addl edx edi decl ecx jnz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 psrlq mm1 paddd mm1 psrad mm1 packssdw mm1 psubd mm0 psubsw mm0 movd eax movw edi emms popl ebx popl esi popl edi mov ebp
Definition: synth_sse3d.h:266
uint32_t * PULONG_PTR
Definition: typedefs.h:65
void * PVOID
Definition: typedefs.h:50
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
_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
char CHAR
Definition: xmlstorage.h:175

Variable Documentation

◆ NtGlobalFlag

ULONG NtGlobalFlag
extern

Definition at line 54 of file init.c.

Referenced by RtlpCheckLogException().

◆ RtlpAllocDeallocQueryBufferSize

SIZE_T RtlpAllocDeallocQueryBufferSize = 128

Definition at line 25 of file libsupp.c.

Referenced by RtlQueryRegistryValues().

◆ RtlpRangeListEntryLookasideList

PAGED_LOOKASIDE_LIST RtlpRangeListEntryLookasideList

Definition at line 24 of file libsupp.c.

Referenced by RtlInitializeRangeListPackage().