ReactOS 0.4.17-dev-1218-gfae4549
libsupp.c File Reference
#include <ntdll.h>
#include <apisets.h>
#include <compat_undoc.h>
#include <debug.h>
Include dependency graph for libsupp.c:

Go to the source code of this file.

Classes

struct  _RTL_ATOM_HANDLE
 

Macros

#define NDEBUG
 
#define TAG_USTR   'RTSU'
 
#define RtlpAllocateStringMemory(Bytes, Tag)   RtlpAllocateMemory(Bytes, Tag)
 

Typedefs

typedef struct _RTL_ATOM_HANDLE RTL_ATOM_HANDLE
 
typedef struct _RTL_ATOM_HANDLE * PRTL_ATOM_HANDLE
 

Functions

BOOLEAN NTAPI RtlpCheckForActiveDebugger (VOID)
 
BOOLEAN NTAPI RtlpSetInDbgPrint (VOID)
 
VOID NTAPI RtlpClearInDbgPrint (VOID)
 
KPROCESSOR_MODE NTAPI RtlpGetMode (VOID)
 
PPEB NTAPI RtlGetCurrentPeb (VOID)
 
VOID NTAPI RtlAcquirePebLock (VOID)
 
VOID NTAPI RtlReleasePebLock (VOID)
 
ULONG NTAPI RtlGetNtGlobalFlags (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)
 
PVOID NTAPI RtlpAllocateMemory (UINT Bytes, ULONG Tag)
 
VOID NTAPI RtlpFreeMemory (PVOID Mem, ULONG Tag)
 
VOID NTAPI RtlpSetHeapParameters (IN PRTL_HEAP_PARAMETERS Parameters)
 
BOOLEAN NTAPI RtlpHandleDpcStackException (IN PEXCEPTION_REGISTRATION_RECORD RegistrationFrame, IN ULONG_PTR RegistrationFrameEnd, IN OUT PULONG_PTR StackLow, IN OUT PULONG_PTR StackHigh)
 
VOID NTAPI RtlpCheckLogException (IN PEXCEPTION_RECORD ExceptionRecord, IN PCONTEXT ContextRecord, IN PVOID ContextData, IN ULONG Size)
 
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)
 
BOOLEAN NTAPI RtlIsThreadWithinLoaderCallout (VOID)
 
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)
 
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_DIRECTORY * find_entry_by_name (IMAGE_RESOURCE_DIRECTORY *dir, LPCWSTR name, void *root, int want_dir)
 
IMAGE_RESOURCE_DIRECTORY * find_entry_by_id (IMAGE_RESOURCE_DIRECTORY *dir, WORD id, void *root, int want_dir)
 
IMAGE_RESOURCE_DIRECTORY * find_first_entry (IMAGE_RESOURCE_DIRECTORY *dir, void *root, int want_dir)
 
int push_language (USHORT *list, ULONG pos, WORD lang)
 
NTSTATUS find_entry (PVOID BaseAddress, LDR_RESOURCE_INFO *info, ULONG level, void **ret, int want_dir)
 
PVOID NTAPI RtlPcToFileHeader (IN PVOID PcValue, PVOID *BaseOfImage)
 
NTSTATUS get_buffer (LPWSTR *buffer, SIZE_T needed, PUNICODE_STRING CallerBuffer, BOOLEAN bAllocateBuffer)
 
NTSTATUS find_actctx_dll (PUNICODE_STRING pnameW, LPWSTR *fullname, PUNICODE_STRING CallerBuffer, BOOLEAN bAllocateBuffer)
 
NTSYSAPI NTSTATUS NTAPI RtlDosApplyFileIsolationRedirection_Ustr (IN ULONG Flags, IN PUNICODE_STRING OriginalName, IN PUNICODE_STRING Extension, IN OUT PUNICODE_STRING StaticString, IN OUT PUNICODE_STRING DynamicString, IN OUT PUNICODE_STRING *NewName, IN PULONG NewFlags, IN PSIZE_T FileNameSize, IN PSIZE_T RequiredLength)
 
static DWORD LdrpApisetVersion (VOID)
 
NTSYSAPI NTSTATUS NTAPI LdrpApplyFileNameRedirection (_In_ PUNICODE_STRING OriginalName, _In_ PUNICODE_STRING Extension, _Inout_opt_ PUNICODE_STRING StaticString, _Inout_opt_ PUNICODE_STRING DynamicString, _Inout_ PUNICODE_STRING *NewName, _Out_ PBOOLEAN RedirectedDll)
 
NTSYSAPI NTSTATUS NTAPI RtlWow64EnableFsRedirection (IN BOOLEAN Wow64FsEnableRedirection)
 
NTSYSAPI NTSTATUS NTAPI RtlWow64EnableFsRedirectionEx (IN PVOID Wow64FsEnableRedirection, OUT PVOID *OldFsRedirectionLevel)
 
NTSYSAPI NTSTATUS NTAPI RtlComputeImportTableHash (IN HANDLE FileHandle, OUT PCHAR Hash, IN ULONG ImportTableHashSize)
 
NTSTATUS NTAPI RtlpSafeCopyMemory (_Out_writes_bytes_all_(Length) VOID UNALIGNED *Destination, _In_reads_bytes_(Length) CONST VOID UNALIGNED *Source, _In_ SIZE_T Length)
 
ULONG NTAPI RtlGetTickCount (VOID)
 

Variables

SIZE_T RtlpAllocDeallocQueryBufferSize = PAGE_SIZE
 
PTEB LdrpTopLevelDllBeingLoadedTeb = NULL
 
PVOID MmHighestUserAddress = (PVOID)MI_HIGHEST_USER_ADDRESS
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file libsupp.c.

◆ RtlpAllocateStringMemory

#define RtlpAllocateStringMemory (   Bytes,
  Tag 
)    RtlpAllocateMemory(Bytes, Tag)

Definition at line 1011 of file libsupp.c.

◆ TAG_USTR

#define TAG_USTR   'RTSU'

Definition at line 1008 of file libsupp.c.

Typedef Documentation

◆ PRTL_ATOM_HANDLE

◆ RTL_ATOM_HANDLE

Function Documentation

◆ find_actctx_dll()

NTSTATUS find_actctx_dll ( PUNICODE_STRING  pnameW,
LPWSTR *  fullname,
PUNICODE_STRING  CallerBuffer,
BOOLEAN  bAllocateBuffer 
)

Definition at line 725 of file libsupp.c.

726{
727 static const WCHAR winsxsW[] = {'\\','w','i','n','s','x','s','\\'};
728 static const WCHAR dotManifestW[] = {'.','m','a','n','i','f','e','s','t',0};
729
730 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *info;
731 ACTCTX_SECTION_KEYED_DATA data;
733 SIZE_T needed, size = 1024;
734 WCHAR *p;
735
736 data.cbSize = sizeof(data);
737 status = RtlFindActivationContextSectionString( FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
738 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
739 pnameW, &data );
740 if (status != STATUS_SUCCESS)
741 {
742 //DPRINT1("RtlFindActivationContextSectionString returned 0x%x for %wZ\n", status, pnameW);
743 return status;
744 }
745
746 for (;;)
747 {
748 if (!(info = RtlAllocateHeap( RtlGetProcessHeap(), 0, size )))
749 {
751 goto done;
752 }
753 status = RtlQueryInformationActivationContext( 0, data.hActCtx, &data.ulAssemblyRosterIndex,
754 AssemblyDetailedInformationInActivationContext,
755 info, size, &needed );
756 if (status == STATUS_SUCCESS) break;
757 if (status != STATUS_BUFFER_TOO_SMALL) goto done;
758 RtlFreeHeap( RtlGetProcessHeap(), 0, info );
759 size = needed;
760 }
761
762 DPRINT("manifestpath === %S\n", info->lpAssemblyManifestPath);
763 DPRINT("DirectoryName === %S\n", info->lpAssemblyDirectoryName);
764 if (!info->lpAssemblyManifestPath /*|| !info->lpAssemblyDirectoryName*/)
765 {
767 goto done;
768 }
769
770 if ((p = wcsrchr( info->lpAssemblyManifestPath, '\\' )))
771 {
772 DWORD dirlen = info->ulAssemblyDirectoryNameLength / sizeof(WCHAR);
773
774 p++;
775 if (!info->lpAssemblyDirectoryName || _wcsnicmp( p, info->lpAssemblyDirectoryName, dirlen ) || _wcsicmp( p + dirlen, dotManifestW ))
776 {
777 /* manifest name does not match directory name, so it's not a global
778 * windows/winsxs manifest; use the manifest directory name instead */
779 dirlen = p - info->lpAssemblyManifestPath;
780 needed = (dirlen + 1) * sizeof(WCHAR) + pnameW->Length;
781
782 status = get_buffer(fullname, needed, CallerBuffer, bAllocateBuffer);
783 if (!NT_SUCCESS(status))
784 goto done;
785
786 p = *fullname;
787
788 memcpy( p, info->lpAssemblyManifestPath, dirlen * sizeof(WCHAR) );
789 p += dirlen;
790 memcpy( p, pnameW->Buffer, pnameW->Length);
791 p += (pnameW->Length / sizeof(WCHAR));
792 *p = L'\0';
793
794 goto done;
795 }
796 }
797
798 needed = (wcslen(SharedUserData->NtSystemRoot) * sizeof(WCHAR) +
799 sizeof(winsxsW) + info->ulAssemblyDirectoryNameLength + pnameW->Length + 2*sizeof(WCHAR));
800
801 status = get_buffer(fullname, needed, CallerBuffer, bAllocateBuffer);
802 if (!NT_SUCCESS(status))
803 goto done;
804
805 p = *fullname;
806
807 wcscpy( p, SharedUserData->NtSystemRoot );
808 p += wcslen(p);
809 memcpy( p, winsxsW, sizeof(winsxsW) );
810 p += sizeof(winsxsW) / sizeof(WCHAR);
811 memcpy( p, info->lpAssemblyDirectoryName, info->ulAssemblyDirectoryNameLength );
812 p += info->ulAssemblyDirectoryNameLength / sizeof(WCHAR);
813 *p++ = L'\\';
814 memcpy( p, pnameW->Buffer, pnameW->Length);
815 p += (pnameW->Length / sizeof(WCHAR));
816 *p = L'\0';
817
818done:
819 RtlFreeHeap( RtlGetProcessHeap(), 0, info );
821 DPRINT("%S\n", fullname);
822 return status;
823}
LONG NTSTATUS
Definition: precomp.h:26
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define wcsrchr
Definition: compat.h:16
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:164
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
_ACRTIMP int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:200
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLfloat GLfloat p
Definition: glext.h:8902
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
const char * fullname
Definition: shader.c:1979
#define STATUS_SXS_KEY_NOT_FOUND
Definition: ntstatus.h:1777
short WCHAR
Definition: pedump.c:58
wcscpy
#define SharedUserData
static char * get_buffer(void)
Definition: debug.c:124
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define DPRINT
Definition: sndvol32.h:73
Definition: ps.c:97
ULONG_PTR SIZE_T
Definition: typedefs.h:80
NTSYSAPI NTSTATUS WINAPI RtlFindActivationContextSectionString(ULONG, const GUID *, ULONG, const UNICODE_STRING *, PVOID)
Definition: actctx.c:6137
NTSYSAPI void WINAPI RtlReleaseActivationContext(HANDLE)
Definition: actctx.c:5664
NTSYSAPI NTSTATUS WINAPI RtlQueryInformationActivationContext(ULONG, HANDLE, PVOID, ULONG, PVOID, SIZE_T, SIZE_T *)
Definition: actctx.c:5833

Referenced by RtlDosApplyFileIsolationRedirection_Ustr().

◆ find_entry()

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

Definition at line 580 of file libsupp.c.

582{
583 ULONG size;
584 void *root;
585 IMAGE_RESOURCE_DIRECTORY *resdirptr;
586 USHORT list[9]; /* list of languages to try */
587 int i, pos = 0;
589
592 if (size < sizeof(*resdirptr)) return STATUS_RESOURCE_DATA_NOT_FOUND;
593 resdirptr = root;
594
595 if (!level--) goto done;
596 if (!(*ret = find_entry_by_name( resdirptr, (LPCWSTR)info->Type, root, want_dir || level )))
598 if (!level--) return STATUS_SUCCESS;
599
600 resdirptr = *ret;
601 if (!(*ret = find_entry_by_name( resdirptr, (LPCWSTR)info->Name, root, want_dir || level )))
603 if (!level--) return STATUS_SUCCESS;
604 if (level) return STATUS_INVALID_PARAMETER; /* level > 3 */
605
606 /* 1. specified language */
607 pos = push_language( list, pos, info->Language );
608
609 /* 2. specified language with neutral sublanguage */
611
612 /* 3. neutral language with neutral sublanguage */
614
615 /* if no explicitly specified language, try some defaults */
616 if (PRIMARYLANGID(info->Language) == LANG_NEUTRAL)
617 {
618 /* user defaults, unless SYS_DEFAULT sublanguage specified */
619 if (SUBLANGID(info->Language) != SUBLANG_SYS_DEFAULT)
620 {
621 /* 4. current thread locale language */
622 pos = push_language( list, pos, LANGIDFROMLCID(NtCurrentTeb()->CurrentLocale) );
623
625 {
626 /* 5. user locale language */
628
629 /* 6. user locale language with neutral sublanguage */
631 }
632 }
633
634 /* now system defaults */
635
637 {
638 /* 7. system locale language */
640
641 /* 8. system locale language with neutral sublanguage */
643 }
644
645 /* 9. English */
647 }
648
649 resdirptr = *ret;
650 for (i = 0; i < pos; i++)
651 if ((*ret = find_entry_by_id( resdirptr, list[i], root, want_dir ))) return STATUS_SUCCESS;
652
653 /* if no explicitly specified language, return the first entry */
654 if (PRIMARYLANGID(info->Language) == LANG_NEUTRAL)
655 {
656 if ((*ret = find_first_entry( resdirptr, root, want_dir ))) return STATUS_SUCCESS;
657 }
659
660done:
661 *ret = resdirptr;
662 return STATUS_SUCCESS;
663}
struct _root root
Definition: list.h:39
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
IMAGE_RESOURCE_DIRECTORY * find_entry_by_id(IMAGE_RESOURCE_DIRECTORY *dir, WORD id, void *root, int want_dir)
Definition: res.c:95
IMAGE_RESOURCE_DIRECTORY * find_entry_by_name(IMAGE_RESOURCE_DIRECTORY *dir, LPCWSTR name, void *root, int want_dir)
Definition: res.c:177
int push_language(USHORT *list, ULONG pos, WORD lang)
Definition: res.c:61
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
static LCID system_lcid
Definition: locale.c:308
static LCID user_lcid
Definition: locale.c:309
return ret
Definition: mutex.c:147
GLint level
Definition: gl.h:1546
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
#define NtCurrentTeb
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize _Pre_valid_ PVOID * BaseAddress
Definition: mmfuncs.h:408
NTSTATUS NTAPI NtQueryDefaultLocale(IN BOOLEAN UserProfile, OUT PLCID DefaultLocaleId)
Definition: locale.c:392
#define STATUS_RESOURCE_LANG_NOT_FOUND
Definition: ntstatus.h:770
#define STATUS_RESOURCE_NAME_NOT_FOUND
Definition: ntstatus.h:469
#define STATUS_RESOURCE_TYPE_NOT_FOUND
Definition: ntstatus.h:468
#define STATUS_RESOURCE_DATA_NOT_FOUND
Definition: ntstatus.h:467
unsigned short USHORT
Definition: pedump.c:61
#define IMAGE_DIRECTORY_ENTRY_RESOURCE
Definition: pedump.c:261
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANGID(l)
Definition: nls.h:17
#define LANG_ENGLISH
Definition: nls.h:52
#define LANGIDFROMLCID(l)
Definition: nls.h:18
#define SUBLANG_NEUTRAL
Definition: nls.h:167
#define SUBLANG_DEFAULT
Definition: nls.h:168
DWORD LCID
Definition: nls.h:13
#define PRIMARYLANGID(l)
Definition: nls.h:16
#define SUBLANG_SYS_DEFAULT
Definition: nls.h:169
const uint16_t * LPCWSTR
Definition: typedefs.h:57
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

◆ find_entry_by_id()

IMAGE_RESOURCE_DIRECTORY * find_entry_by_id ( IMAGE_RESOURCE_DIRECTORY *  dir,
WORD  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
uint32_t entry
Definition: isohybrid.c:63
#define min(a, b)
Definition: monoChain.cc:55
Definition: pedump.c:414
#define max(a, b)
Definition: svc.c:63

Referenced by find_entry().

◆ 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 177 of file res.c.

180{
183 int min, max, res, pos;
184
185 if (!((ULONG_PTR)name & 0xFFFF0000)) return find_entry_by_id( dir, (ULONG_PTR)name & 0xFFFF, root, want_dir );
187 min = 0;
188 max = dir->NumberOfNamedEntries - 1;
189 while (min <= max)
190 {
191 pos = (min + max) / 2;
192 str = (const IMAGE_RESOURCE_DIR_STRING_U *)((const char *)root + entry[pos].NameOffset);
194 if (!res)
195 {
196 if (!entry[pos].DataIsDirectory == !want_dir)
197 {
198 DPRINT("root %p dir %p name %ws ret %p\n",
199 root, dir, name, (const char*)root + entry[pos].OffsetToDirectory);
200 return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry[pos].OffsetToDirectory);
201 }
202 break;
203 }
204 if (res < 0) max = pos - 1;
205 else min = pos + 1;
206 }
207 DPRINT("root %p dir %p name %ws not found\n", root, dir, name);
208 return NULL;
209}
GLuint res
Definition: glext.h:9613
const WCHAR * str
IMAGE_RESOURCE_DIRECTORY * find_entry_by_id(IMAGE_RESOURCE_DIRECTORY *dir, WORD id, void *root, int want_dir)
Definition: res.c:95
static int CompareResourceString(const wchar_t *SearchString, const IMAGE_RESOURCE_DIR_STRING_U *ResourceString)
Definition: res.c:133
Definition: name.c:39
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by find_entry().

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

Referenced by find_entry().

◆ get_buffer()

NTSTATUS get_buffer ( LPWSTR *  buffer,
SIZE_T  needed,
PUNICODE_STRING  CallerBuffer,
BOOLEAN  bAllocateBuffer 
)

Definition at line 698 of file libsupp.c.

699{
700 WCHAR *p;
701
702 if (CallerBuffer && CallerBuffer->MaximumLength > needed)
703 {
704 p = CallerBuffer->Buffer;
705 CallerBuffer->Length = needed - sizeof(WCHAR);
706 }
707 else
708 {
709 if (!bAllocateBuffer)
711
712 if (CallerBuffer)
713 CallerBuffer->Buffer[0] = 0;
714
715 p = RtlAllocateHeap(RtlGetProcessHeap(), 0, needed );
716 if (!p)
717 return STATUS_NO_MEMORY;
718 }
719 *buffer = p;
720
721 return STATUS_SUCCESS;
722}
GLuint buffer
Definition: glext.h:5915
USHORT MaximumLength
Definition: env_spec_w32.h:370

◆ LdrpApisetVersion()

static DWORD LdrpApisetVersion ( VOID  )
static

Definition at line 1015 of file libsupp.c.

1016{
1017 static DWORD CachedApisetVersion = ~0u;
1018
1019 if (CachedApisetVersion == ~0u)
1020 {
1021 DWORD CompatVersion = RosGetProcessCompatVersion();
1022
1023 switch (CompatVersion)
1024 {
1025 case 0:
1026 break;
1027 case _WIN32_WINNT_VISTA:
1028 /* No apisets in vista yet*/
1029 CachedApisetVersion = 0;
1030 break;
1031 case _WIN32_WINNT_WIN7:
1032 CachedApisetVersion = APISET_WIN7;
1033 DPRINT1("Activating apisets for Win7\n");
1034 break;
1035 case _WIN32_WINNT_WIN8:
1036 CachedApisetVersion = APISET_WIN8;
1037 DPRINT1("Activating apisets for Win8\n");
1038 break;
1040 CachedApisetVersion = APISET_WIN81;
1041 DPRINT1("Activating apisets for Win8.1\n");
1042 break;
1043 case _WIN32_WINNT_WIN10:
1044 CachedApisetVersion = APISET_WIN10;
1045 DPRINT1("Activating apisets for Win10\n");
1046 break;
1047 default:
1048 DPRINT1("Unknown version 0x%x\n", CompatVersion);
1049 CachedApisetVersion = 0;
1050 break;
1051 }
1052 }
1053
1054 return CachedApisetVersion;
1055}
#define APISET_WIN7
Definition: apisets.h:16
#define APISET_WIN8
Definition: apisets.h:17
#define APISET_WIN81
Definition: apisets.h:18
#define APISET_WIN10
Definition: apisets.h:19
#define DPRINT1
Definition: precomp.h:8
static DWORD RosGetProcessCompatVersion(VOID)
Definition: compat_undoc.h:26
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 * u
Definition: glfuncs.h:240
#define _WIN32_WINNT_WIN10
Definition: sdkddkver.h:32
#define _WIN32_WINNT_WINBLUE
Definition: sdkddkver.h:30
#define _WIN32_WINNT_WIN8
Definition: sdkddkver.h:29
#define _WIN32_WINNT_WIN7
Definition: sdkddkver.h:28
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25

Referenced by LdrpApplyFileNameRedirection().

◆ LdrpApplyFileNameRedirection()

NTSYSAPI NTSTATUS NTAPI LdrpApplyFileNameRedirection ( _In_ PUNICODE_STRING  OriginalName,
_In_ PUNICODE_STRING  Extension,
_Inout_opt_ PUNICODE_STRING  StaticString,
_Inout_opt_ PUNICODE_STRING  DynamicString,
_Inout_ PUNICODE_STRING *  NewName,
_Out_ PBOOLEAN  RedirectedDll 
)

Definition at line 1060 of file libsupp.c.

1067{
1068
1069 /* Check for invalid parameters */
1070 if (!OriginalName)
1071 {
1073 }
1074
1075 if (!DynamicString && !StaticString)
1076 {
1078 }
1079
1080 if (!NewName)
1081 {
1083 }
1084
1085 *RedirectedDll = FALSE;
1086
1087 PCUNICODE_STRING PrevNewName = *NewName;
1088 UNICODE_STRING ApisetName = {0};
1090
1091 DWORD ApisetVersion = LdrpApisetVersion();
1092 if (ApisetVersion)
1093 {
1094 Status = ApiSetResolveToHost(ApisetVersion, OriginalName, RedirectedDll, &ApisetName);
1095 if (!NT_SUCCESS(Status))
1096 {
1097 DPRINT1("ApiSetResolveToHost FAILED: (Status 0x%x)\n", Status);
1098 return Status;
1099 }
1100 }
1101
1102 if (*RedirectedDll)
1103 {
1105 static const UNICODE_STRING System32 = RTL_CONSTANT_STRING(L"\\System32\\");
1106 PUNICODE_STRING ResultPath = NULL;
1107
1108 /* This is an apiset we can use */
1110
1111 SIZE_T Needed = System32.Length + ApisetName.Length + NtSystemRoot.Length + sizeof(UNICODE_NULL);
1112
1113 if (StaticString && StaticString->MaximumLength >= (USHORT)Needed)
1114 {
1115 StaticString->Length = 0;
1116 ResultPath = StaticString;
1117 }
1118 else if (DynamicString)
1119 {
1121 if (DynamicString->Buffer == NULL)
1122 {
1123 DPRINT1("LdrpApplyFileNameRedirection out of memory\n");
1124 return STATUS_NO_MEMORY;
1125 }
1127 DynamicString->Length = 0;
1128
1129 ResultPath = DynamicString;
1130 }
1131 else
1132 {
1133 DPRINT1("ERROR: LdrpApplyFileNameRedirection no inputbuffer valid\n");
1135 }
1136
1138 RtlAppendUnicodeStringToString(ResultPath, &System32);
1139 RtlAppendUnicodeStringToString(ResultPath, &ApisetName);
1140 DPRINT1("ApiSetResolveToHost redirected %wZ to %wZ\n", OriginalName, ResultPath);
1141 *NewName = ResultPath;
1142 }
1143 else
1144 {
1145 /* Check if the SxS Assemblies specify another file */
1146 Status = RtlDosApplyFileIsolationRedirection_Ustr(RTL_DOS_APPLY_FILE_REDIRECTION_USTR_FLAG_RESPECT_DOT_LOCAL, OriginalName, Extension, StaticString, DynamicString, NewName, NULL, NULL, NULL);
1147
1148 /* Check success */
1149 if (NT_SUCCESS(Status))
1150 {
1151 /* Let Ldrp know */
1152 *RedirectedDll = TRUE;
1153 }
1154 else if (Status == STATUS_SXS_KEY_NOT_FOUND)
1155 {
1156 ASSERT(*NewName == PrevNewName);
1158 }
1159 else
1160 {
1161 /* Unrecoverable SxS failure; did we get a string? */
1164 return Status;
1165 }
1166 }
1167
1168 return Status;
1169}
IN PUNICODE_STRING StaticString
IN PUNICODE_STRING IN PUNICODE_STRING DynamicString
#define TAG_USTR
Definition: libsupp.c:1008
static DWORD LdrpApisetVersion(VOID)
Definition: libsupp.c:1015
#define RtlpAllocateStringMemory(Bytes, Tag)
Definition: libsupp.c:1011
NTSYSAPI NTSTATUS NTAPI RtlDosApplyFileIsolationRedirection_Ustr(IN ULONG Flags, IN PUNICODE_STRING OriginalName, IN PUNICODE_STRING Extension, IN OUT PUNICODE_STRING StaticString, IN OUT PUNICODE_STRING DynamicString, IN OUT PUNICODE_STRING *NewName, IN PULONG NewFlags, IN PSIZE_T FileNameSize, IN PSIZE_T RequiredLength)
Definition: libsupp.c:831
#define RTL_CONSTANT_STRING(s)
Definition: combase.c:35
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define UNICODE_NULL
UNICODE_STRING NtSystemRoot
Definition: init.c:80
NTSTATUS ApiSetResolveToHost(_In_ DWORD ApisetVersion, _In_ PCUNICODE_STRING ApiToResolve, _Out_ PBOOLEAN Resolved, _Out_ PUNICODE_STRING Output)
Definition: apisets.c:32
_In_ PUNICODE_STRING NewName
Definition: zwfuncs.h:1203

◆ push_language()

int push_language ( USHORT *  list,
ULONG  pos,
WORD  lang 
)

Definition at line 61 of file res.c.

62{
63 ULONG i;
64 for (i = 0; i < pos; i++) if (list[i] == lang) return pos;
65 list[pos++] = lang;
66 return pos;
67}
static const WCHAR lang[]
Definition: wbemdisp.c:287

Referenced by find_entry().

◆ RtlAcquirePebLock()

VOID NTAPI RtlAcquirePebLock ( VOID  )

Definition at line 85 of file libsupp.c.

86{
89}
#define NtCurrentPeb()
Definition: FLS.c:22
PPEB Peb
Definition: dllmain.c:27
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
PVOID FastPebLock
Definition: ntddk_ex.h:250

◆ RtlComputeImportTableHash()

NTSYSAPI NTSTATUS NTAPI RtlComputeImportTableHash ( IN HANDLE  FileHandle,
OUT PCHAR  Hash,
IN ULONG  ImportTableHashSize 
)

Definition at line 1202 of file libsupp.c.

1205{
1208}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42

Referenced by BasepCheckWebBladeHashes().

◆ RtlDeleteHeapLock()

NTSTATUS NTAPI RtlDeleteHeapLock ( IN OUT PHEAP_LOCK  Lock)

Definition at line 114 of file libsupp.c.

115{
116 return RtlDeleteCriticalSection(&Lock->CriticalSection);
117}
NTSYSAPI NTSTATUS NTAPI RtlDeleteCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127

Referenced by RtlDestroyHeap(), and RtlpPageHeapDestroy().

◆ RtlDosApplyFileIsolationRedirection_Ustr()

NTSYSAPI NTSTATUS NTAPI RtlDosApplyFileIsolationRedirection_Ustr ( IN ULONG  Flags,
IN PUNICODE_STRING  OriginalName,
IN PUNICODE_STRING  Extension,
IN OUT PUNICODE_STRING  StaticString,
IN OUT PUNICODE_STRING  DynamicString,
IN OUT PUNICODE_STRING *  NewName,
IN PULONG  NewFlags,
IN PSIZE_T  FileNameSize,
IN PSIZE_T  RequiredLength 
)

Definition at line 831 of file libsupp.c.

840{
844 UNICODE_STRING localStr, localStr2, *pstrParam;
845 WCHAR *p;
846 BOOLEAN GotExtension;
847 WCHAR c;
848 C_ASSERT(sizeof(UNICODE_NULL) == sizeof(WCHAR));
849
850
851 /* Check for invalid parameters */
852 if (!OriginalName)
853 {
855 }
856
858 {
860 }
861
862 if ((DynamicString) && (StaticString) && !(NewName))
863 {
865 }
866
867 if (!OriginalName->Buffer || OriginalName->Length == 0)
868 {
870 }
871
872 if (StaticString && (OriginalName == StaticString || OriginalName->Buffer == StaticString->Buffer))
873 {
875 }
876
877 if ((Flags & RTL_DOS_APPLY_FILE_REDIRECTION_USTR_FLAG_RESPECT_DOT_LOCAL) &&
878 NtCurrentPeb()->ProcessParameters &&
879 (NtCurrentPeb()->ProcessParameters->Flags & RTL_USER_PROCESS_PARAMETERS_PRIVATE_DLL_PATH))
880 {
881 UNICODE_STRING RealName, LocalName;
882 WCHAR RealNameBuf[MAX_PATH], LocalNameBuf[MAX_PATH];
883
884 RtlInitEmptyUnicodeString(&RealName, RealNameBuf, sizeof(RealNameBuf));
885 RtlInitEmptyUnicodeString(&LocalName, LocalNameBuf, sizeof(LocalNameBuf));
886
887 Status = RtlComputePrivatizedDllName_U(OriginalName, &RealName, &LocalName);
888 if (!NT_SUCCESS(Status))
889 {
890 DPRINT1("RtlComputePrivatizedDllName_U failed for %wZ: 0x%lx\n", OriginalName, Status);
891 return Status;
892 }
893
894 if (RtlDoesFileExists_UStr(&LocalName))
895 {
897 if (NT_SUCCESS(Status))
898 {
899 RtlCopyMemory(fullname, LocalName.Buffer, LocalName.Length + sizeof(UNICODE_NULL));
900 }
901 else
902 {
903 DPRINT1("Error while retrieving buffer for %wZ: 0x%lx\n", OriginalName, Status);
904 }
905 }
906 else if (RtlDoesFileExists_UStr(&RealName))
907 {
909 if (NT_SUCCESS(Status))
910 {
911 RtlCopyMemory(fullname, RealName.Buffer, RealName.Length + sizeof(UNICODE_NULL));
912 }
913 else
914 {
915 DPRINT1("Error while retrieving buffer for %wZ: 0x%lx\n", OriginalName, Status);
916 }
917 }
918 else
919 {
921 }
922
923 if (RealName.Buffer != RealNameBuf)
924 RtlFreeUnicodeString(&RealName);
925 if (LocalName.Buffer != LocalNameBuf)
926 RtlFreeUnicodeString(&LocalName);
927
928 if (NT_SUCCESS(Status))
929 {
930 DPRINT("Redirecting %wZ to %S\n", OriginalName, fullname);
932 {
935 }
936 else
937 {
939 }
940 return Status;
941 }
942 }
943
944 pstrParam = OriginalName;
945
946 /* Get the file name with an extension */
947 p = OriginalName->Buffer + OriginalName->Length / sizeof(WCHAR) - 1;
948 GotExtension = FALSE;
949 while (p >= OriginalName->Buffer)
950 {
951 c = *p--;
952 if (c == L'.')
953 {
954 GotExtension = TRUE;
955 }
956 else if (c == L'\\')
957 {
958 localStr.Buffer = p + 2;
959 localStr.Length = OriginalName->Length - ((ULONG_PTR)localStr.Buffer - (ULONG_PTR)OriginalName->Buffer);
960 localStr.MaximumLength = OriginalName->MaximumLength - ((ULONG_PTR)localStr.Buffer - (ULONG_PTR)OriginalName->Buffer);
961 pstrParam = &localStr;
962 break;
963 }
964 }
965
966 if (!GotExtension)
967 {
968 if (!Extension)
969 {
971 }
972
973 if (pstrParam->Length + Extension->Length > sizeof(buffer))
974 {
975 //FIXME!
976 return STATUS_NO_MEMORY;
977 }
978
979 RtlInitEmptyUnicodeString(&localStr2, buffer, sizeof(buffer));
980 RtlAppendUnicodeStringToString(&localStr2, pstrParam);
982 pstrParam = &localStr2;
983 }
984
985 /* Use wine's function as long as we use wine's sxs implementation in ntdll */
987 if (!NT_SUCCESS(Status))
988 {
989 return Status;
990 }
991
992 DPRINT("Redirecting %wZ to %S\n", OriginalName, fullname);
993
995 {
998 }
999 else
1000 {
1002 }
1003
1004 return Status;
1005}
unsigned char BOOLEAN
Definition: actypes.h:127
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
NTSTATUS find_actctx_dll(PUNICODE_STRING pnameW, LPWSTR *fullname, PUNICODE_STRING CallerBuffer, BOOLEAN bAllocateBuffer)
Definition: libsupp.c:725
#define MAX_PATH
Definition: compat.h:34
#define ULONG_PTR
Definition: config.h:101
const GLubyte * c
Definition: glext.h:8905
#define C_ASSERT(e)
Definition: intsafe.h:73
#define c
Definition: ke_i.h:80
NTSYSAPI NTSTATUS NTAPI RtlComputePrivatizedDllName_U(_In_ PUNICODE_STRING DllName, _Inout_ PUNICODE_STRING RealName, _Inout_ PUNICODE_STRING LocalName)
Definition: path.c:586
#define RTL_USER_PROCESS_PARAMETERS_PRIVATE_DLL_PATH
Definition: rtltypes.h:52
BOOLEAN NTAPI RtlDoesFileExists_UStr(IN PUNICODE_STRING FileName)
Definition: path.c:1503
#define STATUS_NOT_FOUND
Definition: shellext.h:72
uint16_t * LPWSTR
Definition: typedefs.h:56
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by LdrpApplyFileNameRedirection(), RtlDosSearchPath_Ustr(), TestBuffers(), and TestRedirection().

◆ RtlEnterHeapLock()

◆ RtlGetCurrentPeb()

PPEB NTAPI RtlGetCurrentPeb ( VOID  )

Definition at line 76 of file libsupp.c.

77{
78 return NtCurrentPeb();
79}

◆ RtlGetNtGlobalFlags()

ULONG NTAPI RtlGetNtGlobalFlags ( VOID  )

Definition at line 106 of file libsupp.c.

107{
108 PPEB pPeb = NtCurrentPeb();
109 return pPeb->NtGlobalFlag;
110}
ULONG NtGlobalFlag
Definition: ntddk_ex.h:270

◆ RtlGetTickCount()

ULONG NTAPI RtlGetTickCount ( VOID  )

Definition at line 1233 of file libsupp.c.

1234{
1235 LARGE_INTEGER TickCount;
1236
1237 TickCount = KiReadSystemTime(&SharedUserData->TickCount);
1238
1239 /* Convert to milliseconds */
1240 return KiTickCountToMs(TickCount);
1241}
FORCEINLINE ULONG64 KiTickCountToMs(_In_ LARGE_INTEGER TickCount)
Definition: kefuncs.h:453
FORCEINLINE LARGE_INTEGER KiReadSystemTime(_In_ volatile const KSYSTEM_TIME *SystemTime)
Definition: kefuncs.h:403

◆ RtlImageNtHeaderEx()

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

Definition at line 536 of file libsupp.c.

541{
543
544 /* Assume failure. This is also done in RtlpImageNtHeaderEx, but this is guarded by SEH. */
545 if (OutHeaders != NULL)
546 *OutHeaders = NULL;
547
549 {
550 Status = RtlpImageNtHeaderEx(Flags, Base, Size, OutHeaders);
551 }
553 {
554 /* Fail with the SEH error */
556 }
557 _SEH2_END;
558
559 return Status;
560}
NTSTATUS NTAPI RtlpImageNtHeaderEx(_In_ ULONG Flags, _In_ PVOID Base, _In_ ULONG64 Size, _Out_ PIMAGE_NT_HEADERS *OutHeaders)
Definition: image.c:140
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2486
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:204
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539

◆ RtlInitializeHeapLock()

NTSTATUS NTAPI RtlInitializeHeapLock ( IN OUT PHEAP_LOCK *  Lock)

Definition at line 139 of file libsupp.c.

140{
141 return RtlInitializeCriticalSection(&(*Lock)->CriticalSection);
142}
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)

Referenced by RtlpDphInitializeDelayedFreeQueue(), RtlpDphProcessStartupInitialization(), RtlpInitializeHeap(), and RtlpPageHeapCreate().

◆ RtlIsThreadWithinLoaderCallout()

BOOLEAN NTAPI RtlIsThreadWithinLoaderCallout ( VOID  )

Definition at line 358 of file libsupp.c.

359{
361}
PTEB LdrpTopLevelDllBeingLoadedTeb
Definition: libsupp.c:20

Referenced by CtfImmTIMActivate(), ForceResetUserApiHook(), and LoadUserApiHook().

◆ RtlLeaveHeapLock()

◆ RtlpAllocateMemory()

PVOID NTAPI RtlpAllocateMemory ( UINT  Bytes,
ULONG  Tag 
)

Definition at line 153 of file libsupp.c.

155{
157
158 return RtlAllocateHeap(RtlGetProcessHeap(),
159 0,
160 Bytes);
161}
_In_ UINT Bytes
Definition: mmcopy.h:9
_Must_inspect_result_ _In_ UCXENDPOINT _In_ PVOID Tag
Definition: ucxendpoint.h:325

◆ RtlpAllocAtomTable()

PRTL_ATOM_TABLE RtlpAllocAtomTable ( ULONG  Size)

Definition at line 420 of file libsupp.c.

421{
422 return (PRTL_ATOM_TABLE)RtlAllocateHeap(RtlGetProcessHeap(),
424 Size);
425}
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
struct atom_table ** PRTL_ATOM_TABLE
Definition: atom.c:43

◆ RtlpAllocAtomTableEntry()

PRTL_ATOM_TABLE_ENTRY RtlpAllocAtomTableEntry ( ULONG  Size)

Definition at line 436 of file libsupp.c.

437{
438 return (PRTL_ATOM_TABLE_ENTRY)RtlAllocateHeap(RtlGetProcessHeap(),
440 Size);
441}
Definition: rtltypes.h:1719

◆ RtlpCaptureStackLimits()

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

Definition at line 224 of file libsupp.c.

227{
228 /* FIXME: Verify */
229 *StackBegin = (ULONG_PTR)NtCurrentTeb()->NtTib.StackLimit;
230 *StackEnd = (ULONG_PTR)NtCurrentTeb()->NtTib.StackBase;
231 return TRUE;
232}

Referenced by RtlWalkFrameChain().

◆ RtlpCheckForActiveDebugger()

BOOLEAN NTAPI RtlpCheckForActiveDebugger ( VOID  )

Definition at line 27 of file libsupp.c.

28{
29 /* Return the flag in the PEB */
30 return NtCurrentPeb()->BeingDebugged;
31}

Referenced by RtlRaiseException(), RtlRaiseStatus(), and vDbgPrintExWithPrefixInternal().

◆ RtlpCheckLogException()

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

Definition at line 214 of file libsupp.c.

218{
219 /* Exception logging is not done in user-mode */
220}

Referenced by RtlDispatchException(), and RtlpUnwindInternal().

◆ RtlpClearInDbgPrint()

VOID NTAPI RtlpClearInDbgPrint ( VOID  )

Definition at line 54 of file libsupp.c.

55{
56#if (NTDDI_VERSION < NTDDI_LONGHORN)
57 /* Clear the flag */
58 NtCurrentTeb()->InDbgPrint = FALSE;
59#else
60 NtCurrentTeb()->DbgInDebugPrint = FALSE;
61#endif
62}

Referenced by vDbgPrintExWithPrefixInternal().

◆ RtlpCreateAtomHandle()

BOOLEAN RtlpCreateAtomHandle ( PRTL_ATOM_TABLE  AtomTable,
PRTL_ATOM_TABLE_ENTRY  Entry 
)

Definition at line 466 of file libsupp.c.

467{
468 ULONG HandleIndex;
469 PRTL_HANDLE_TABLE_ENTRY RtlHandle;
470
471 RtlHandle = RtlAllocateHandle(&AtomTable->RtlHandleTable,
472 &HandleIndex);
473 if (RtlHandle != NULL)
474 {
475 PRTL_ATOM_HANDLE AtomHandle = (PRTL_ATOM_HANDLE)RtlHandle;
476
477 /* FIXME - Handle Indexes >= 0xC000 ?! */
478 if (HandleIndex < 0xC000)
479 {
480 Entry->HandleIndex = (USHORT)HandleIndex;
481 Entry->Atom = 0xC000 + (USHORT)HandleIndex;
482
483 AtomHandle->AtomEntry = Entry;
484 AtomHandle->Handle.Flags = RTL_HANDLE_VALID;
485
486 return TRUE;
487 }
488 else
489 {
490 /* set the valid flag, otherwise RtlFreeHandle will fail! */
491 AtomHandle->Handle.Flags = RTL_HANDLE_VALID;
492
493 RtlFreeHandle(&AtomTable->RtlHandleTable,
494 RtlHandle);
495 }
496 }
497
498 return FALSE;
499}
struct _RTL_ATOM_HANDLE * PRTL_ATOM_HANDLE
NTSYSAPI BOOLEAN NTAPI RtlFreeHandle(_In_ PRTL_HANDLE_TABLE HandleTable, _In_ PRTL_HANDLE_TABLE_ENTRY Handle)
NTSYSAPI PRTL_HANDLE_TABLE_ENTRY NTAPI RtlAllocateHandle(_In_ PRTL_HANDLE_TABLE HandleTable, _Inout_ PULONG Index)
#define RTL_HANDLE_VALID
Definition: rtltypes.h:378
Entry
Definition: section.c:5216
RTL_HANDLE_TABLE_ENTRY Handle
Definition: libsupp.c:367
PRTL_ATOM_TABLE_ENTRY AtomEntry
Definition: libsupp.c:368
Definition: rtltypes.h:1252
ULONG Flags
Definition: rtltypes.h:1255

◆ RtlpCreateAtomHandleTable()

BOOLEAN RtlpCreateAtomHandleTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 404 of file libsupp.c.

405{
407 sizeof(RTL_ATOM_HANDLE),
408 &AtomTable->RtlHandleTable);
409
410 return TRUE;
411}
NTSYSAPI VOID NTAPI RtlInitializeHandleTable(_In_ ULONG TableSize, _In_ ULONG HandleSize, _In_ PRTL_HANDLE_TABLE HandleTable)

◆ RtlPcToFileHeader()

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

Definition at line 669 of file libsupp.c.

671{
675 PVOID ImageBase = NULL;
676
678 ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
680 while (Entry != ModuleListHead)
681 {
682 Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
683
684 if ((ULONG_PTR)PcValue >= (ULONG_PTR)Module->DllBase &&
685 (ULONG_PTR)PcValue < (ULONG_PTR)Module->DllBase + Module->SizeOfImage)
686 {
687 ImageBase = Module->DllBase;
688 break;
689 }
690 Entry = Entry->Flink;
691 }
693
694 *BaseOfImage = ImageBase;
695 return ImageBase;
696}
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23
Definition: btrfs_drv.h:1876
ULONG SizeOfImage
Definition: ldrtypes.h:147
PVOID DllBase
Definition: btrfs_drv.h:1880
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by BasepGetModuleHandleExW(), GetModuleHandleExW(), RtlLookupFunctionTable(), rtti_rva_base(), and SeiGetModuleFromAddress().

◆ RtlpDestroyAtomHandleTable()

VOID RtlpDestroyAtomHandleTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 414 of file libsupp.c.

415{
416 RtlDestroyHandleTable(&AtomTable->RtlHandleTable);
417}
NTSYSAPI VOID NTAPI RtlDestroyHandleTable(_Inout_ PRTL_HANDLE_TABLE HandleTable)

◆ RtlpDestroyAtomTableLock()

VOID RtlpDestroyAtomTableLock ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 380 of file libsupp.c.

381{
382 RtlDeleteCriticalSection(&AtomTable->CriticalSection);
383}

◆ RtlpFreeAtomHandle()

VOID RtlpFreeAtomHandle ( PRTL_ATOM_TABLE  AtomTable,
PRTL_ATOM_TABLE_ENTRY  Entry 
)

Definition at line 452 of file libsupp.c.

453{
454 PRTL_HANDLE_TABLE_ENTRY RtlHandleEntry;
455
456 if (RtlIsValidIndexHandle(&AtomTable->RtlHandleTable,
457 (ULONG)Entry->HandleIndex,
458 &RtlHandleEntry))
459 {
460 RtlFreeHandle(&AtomTable->RtlHandleTable,
461 RtlHandleEntry);
462 }
463}
NTSYSAPI BOOLEAN WINAPI RtlIsValidIndexHandle(const RTL_HANDLE_TABLE *, ULONG Index, RTL_HANDLE **)

◆ RtlpFreeAtomTable()

VOID RtlpFreeAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 428 of file libsupp.c.

429{
430 RtlFreeHeap(RtlGetProcessHeap(),
431 0,
432 AtomTable);
433}

◆ RtlpFreeAtomTableEntry()

VOID RtlpFreeAtomTableEntry ( PRTL_ATOM_TABLE_ENTRY  Entry)

Definition at line 444 of file libsupp.c.

445{
446 RtlFreeHeap(RtlGetProcessHeap(),
447 0,
448 Entry);
449}

◆ RtlpFreeMemory()

VOID NTAPI RtlpFreeMemory ( PVOID  Mem,
ULONG  Tag 
)

Definition at line 166 of file libsupp.c.

168{
170
171 RtlFreeHeap(RtlGetProcessHeap(),
172 0,
173 Mem);
174}

◆ RtlpGetAtomEntry()

PRTL_ATOM_TABLE_ENTRY RtlpGetAtomEntry ( PRTL_ATOM_TABLE  AtomTable,
ULONG  Index 
)

Definition at line 502 of file libsupp.c.

503{
504 PRTL_HANDLE_TABLE_ENTRY RtlHandle;
505
506 if (RtlIsValidIndexHandle(&AtomTable->RtlHandleTable,
507 Index,
508 &RtlHandle))
509 {
510 PRTL_ATOM_HANDLE AtomHandle = (PRTL_ATOM_HANDLE)RtlHandle;
511
512 return AtomHandle->AtomEntry;
513 }
514
515 return NULL;
516}
_In_ WDFCOLLECTION _In_ ULONG Index

◆ RtlpGetMode()

KPROCESSOR_MODE NTAPI RtlpGetMode ( VOID  )

Definition at line 66 of file libsupp.c.

67{
68 return UserMode;
69}
#define UserMode
Definition: asm.h:39

Referenced by RtlCreateHeap(), RtlCreateProcessParameters(), RtlDestroyHeap(), RtlFreeHeap(), RtlpExtendHeap(), RtlpInitializeHeap(), and RtlWalkFrameChain().

◆ RtlpGetStackLimits()

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

Definition at line 348 of file libsupp.c.

351{
352 *LowLimit = (ULONG_PTR)NtCurrentTeb()->NtTib.StackLimit;
353 *HighLimit = (ULONG_PTR)NtCurrentTeb()->NtTib.StackBase;
354}
_Out_ PULONG_PTR HighLimit
Definition: iofuncs.h:2892

Referenced by RtlDispatchException(), RtlpUnwindInternal(), RtlUnwind(), and RtlWalkFrameChain().

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

207{
208 /* There's no such thing as a DPC stack in user-mode */
209 return FALSE;
210}

Referenced by RtlDispatchException(), and RtlUnwind().

◆ 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}
PVOID MmHighestUserAddress
Definition: libsupp.c:23
PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS
Definition: ntddk_ex.h:187
#define RTL_IMAGE_NT_HEADER_EX_FLAG_NO_RANGE_CHECK
Definition: rtltypes.h:360
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
Definition: ntbasedef.h:684
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:453
#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 372 of file libsupp.c.

373{
374 RtlInitializeCriticalSection(&AtomTable->CriticalSection);
375 return STATUS_SUCCESS;
376}

◆ RtlpLockAtomTable()

BOOLEAN RtlpLockAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 387 of file libsupp.c.

388{
389 RtlEnterCriticalSection(&AtomTable->CriticalSection);
390 return TRUE;
391}

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

1216{
1217 _SEH2_TRY
1218 {
1220 }
1222 {
1224 }
1225 _SEH2_END;
1226
1227 return STATUS_SUCCESS;
1228}
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3051
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:207

◆ RtlpSetHeapParameters()

VOID NTAPI RtlpSetHeapParameters ( IN PRTL_HEAP_PARAMETERS  Parameters)

Definition at line 187 of file libsupp.c.

188{
189 PPEB Peb;
190
191 /* Get PEB */
193
194 /* Apply defaults for non-set parameters */
195 if (!Parameters->SegmentCommit) Parameters->SegmentCommit = Peb->HeapSegmentCommit;
196 if (!Parameters->SegmentReserve) Parameters->SegmentReserve = Peb->HeapSegmentReserve;
197 if (!Parameters->DeCommitFreeBlockThreshold) Parameters->DeCommitFreeBlockThreshold = Peb->HeapDeCommitFreeBlockThreshold;
198 if (!Parameters->DeCommitTotalFreeThreshold) Parameters->DeCommitTotalFreeThreshold = Peb->HeapDeCommitTotalFreeThreshold;
199}
_In_ HANDLE _In_ CONST PDXGKMDT_OPM_GET_INFO_PARAMETERS Parameters
Definition: dispmprt.h:321
ULONG HeapSegmentReserve
Definition: ntddk_ex.h:275
ULONG HeapDeCommitFreeBlockThreshold
Definition: ntddk_ex.h:278
ULONG HeapDeCommitTotalFreeThreshold
Definition: ntddk_ex.h:277
ULONG HeapSegmentCommit
Definition: ntddk_ex.h:276
NTSYSAPI PEB *WINAPI RtlGetCurrentPeb(void)
Definition: libsupp.c:76

Referenced by RtlCreateHeap().

◆ RtlpSetInDbgPrint()

BOOLEAN NTAPI RtlpSetInDbgPrint ( VOID  )

Definition at line 35 of file libsupp.c.

36{
37 /* Check if it's already set and return TRUE if so */
38#if (NTDDI_VERSION < NTDDI_LONGHORN)
39 if (NtCurrentTeb()->InDbgPrint) return TRUE;
40
41 /* Set it and return */
42 NtCurrentTeb()->InDbgPrint = TRUE;
43#else
44 if (NtCurrentTeb()->DbgInDebugPrint) return TRUE;
45
46 /* Set it and return */
47 NtCurrentTeb()->DbgInDebugPrint = TRUE;
48#endif
49 return FALSE;
50}

Referenced by vDbgPrintExWithPrefixInternal().

◆ RtlpUnlockAtomTable()

VOID RtlpUnlockAtomTable ( PRTL_ATOM_TABLE  AtomTable)

Definition at line 395 of file libsupp.c.

396{
397 RtlLeaveCriticalSection(&AtomTable->CriticalSection);
398}

◆ RtlReleasePebLock()

VOID NTAPI RtlReleasePebLock ( VOID  )

Definition at line 95 of file libsupp.c.

◆ RtlTryEnterHeapLock()

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

Definition at line 130 of file libsupp.c.

131{
133
134 return RtlTryEnterCriticalSection(&Lock->CriticalSection);
135}
NTSYSAPI LOGICAL NTAPI RtlTryEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)

Referenced by RtlpDphEnterCriticalSection().

◆ RtlWalkFrameChain()

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

Definition at line 240 of file libsupp.c.

243{
244 ULONG_PTR Stack, NewStack, StackBegin, StackEnd = 0;
245 ULONG Eip;
246 BOOLEAN Result, StopSearch = FALSE;
247 ULONG i = 0;
248
249 /* Get current EBP */
250#if defined(_M_IX86)
251#if defined __GNUC__
252 __asm__("mov %%ebp, %0" : "=r" (Stack) : );
253#elif defined(_MSC_VER)
254 __asm mov Stack, ebp
255#endif
256#elif defined(_M_MIPS)
257 __asm__("move $sp, %0" : "=r" (Stack) : );
258#elif defined(_M_PPC)
259 __asm__("mr %0,1" : "=r" (Stack) : );
260#elif defined(_M_ARM)
261#if defined __GNUC__
262 __asm__("mov sp, %0" : "=r"(Stack) : );
263#elif defined(_MSC_VER)
264 // FIXME: Hack. Probably won't work if this ever actually manages to run someday.
266#endif
267#else
268#error Unknown architecture
269#endif
270
271 /* Set it as the stack begin limit as well */
272 StackBegin = (ULONG_PTR)Stack;
273
274 /* Check if we're called for non-logging mode */
275 if (!Flags)
276 {
277 /* Get the actual safe limits */
279 &StackBegin,
280 &StackEnd);
281 if (!Result) return 0;
282 }
283
284 /* Use a SEH block for maximum protection */
286 {
287 /* Loop the frames */
288 for (i = 0; i < Count; i++)
289 {
290 /*
291 * Leave if we're past the stack,
292 * if we're before the stack,
293 * or if we've reached ourselves.
294 */
295 if ((Stack >= StackEnd) ||
296 (!i ? (Stack < StackBegin) : (Stack <= StackBegin)) ||
297 ((StackEnd - Stack) < (2 * sizeof(ULONG_PTR))))
298 {
299 /* We're done or hit a bad address */
300 break;
301 }
302
303 /* Get new stack and EIP */
304 NewStack = *(PULONG_PTR)Stack;
305 Eip = *(PULONG_PTR)(Stack + sizeof(ULONG_PTR));
306
307 /* Check if the new pointer is above the oldone and past the end */
308 if (!((Stack < NewStack) && (NewStack < StackEnd)))
309 {
310 /* Stop searching after this entry */
311 StopSearch = TRUE;
312 }
313
314 /* Also make sure that the EIP isn't a stack address */
315 if ((StackBegin < Eip) && (Eip < StackEnd)) break;
316
317 /* FIXME: Check that EIP is inside a loaded module */
318
319 /* Save this frame */
320 Callers[i] = (PVOID)Eip;
321
322 /* Check if we should continue */
323 if (StopSearch)
324 {
325 /* Return the next index */
326 i++;
327 break;
328 }
329
330 /* Move to the next stack */
331 Stack = NewStack;
332 }
333 }
335 {
336 /* No index */
337 i = 0;
338 }
339 _SEH2_END;
340
341 /* Return frames parsed */
342 return i;
343}
BOOLEAN NTAPI RtlpCaptureStackLimits(IN ULONG_PTR Ebp, IN ULONG_PTR *StackBegin, IN ULONG_PTR *StackEnd)
Definition: libsupp.c:224
int Count
Definition: noreturn.cpp:7
__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" "\tpush %rbx\n" "\t.seh_pushreg %rbx\n" "\tpush %rdi\n" "\t.seh_pushreg %rdi\n" "\tpush %rsi\n" "\t.seh_pushreg %rsi\n" "\tpush %r12\n" "\t.seh_pushreg %r12\n" "\tpush %r13\n" "\t.seh_pushreg %r13\n" "\tpush %r14\n" "\t.seh_pushreg %r14\n" "\tpush %r15\n" "\t.seh_pushreg %r15\n" "\tsub $40, %rsp\n" "\t.seh_stackalloc 40\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 $40, %rsp\n" "\tpop %r15\n" "\tpop %r14\n" "\tpop %r13\n" "\tpop %r12\n" "\tpop %rsi\n" "\tpop %rdi\n" "\tpop %rbx\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")
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

Referenced by KeRosCaptureUserStackBackTrace(), lie_about_fs_type(), RtlCaptureStackBackTrace(), and TestStackWalk4().

◆ RtlWow64EnableFsRedirection()

NTSYSAPI NTSTATUS NTAPI RtlWow64EnableFsRedirection ( IN BOOLEAN  Wow64FsEnableRedirection)

Definition at line 1177 of file libsupp.c.

1178{
1179 /* This is what Windows returns on x86 */
1181}

Referenced by kernelbase_Wow64EnableWow64FsRedirection(), Wow64EnableWow64FsRedirection(), and Wow64RevertWow64FsRedirection().

◆ RtlWow64EnableFsRedirectionEx()

NTSYSAPI NTSTATUS NTAPI RtlWow64EnableFsRedirectionEx ( IN PVOID  Wow64FsEnableRedirection,
OUT PVOID *  OldFsRedirectionLevel 
)

Definition at line 1189 of file libsupp.c.

1191{
1192 /* This is what Windows returns on x86 */
1194}

Referenced by Wow64DisableWow64FsRedirection(), and Wow64RevertWow64FsRedirection().

Variable Documentation

◆ LdrpTopLevelDllBeingLoadedTeb

PTEB LdrpTopLevelDllBeingLoadedTeb = NULL

Definition at line 20 of file libsupp.c.

Referenced by LdrpRunInitializeRoutines(), and RtlIsThreadWithinLoaderCallout().

◆ MmHighestUserAddress

PVOID MmHighestUserAddress = (PVOID)MI_HIGHEST_USER_ADDRESS

Definition at line 21 of file libsupp.c.

◆ RtlpAllocDeallocQueryBufferSize

SIZE_T RtlpAllocDeallocQueryBufferSize = PAGE_SIZE

Definition at line 19 of file libsupp.c.