X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=reactos%2Fdll%2Fntdll%2Frtl%2Flibsupp.c;h=c10bb87461f28de4dbf0649a912d90c4f90fa133;hp=3c4e01bba643d6a736ce0c9a47427f945befa774;hb=cc5c0a08164f732809d06487a52217e788cd0324;hpb=e818f18502b09fe1584af9d09ca6bd5005d4a6a5 diff --git a/reactos/dll/ntdll/rtl/libsupp.c b/reactos/dll/ntdll/rtl/libsupp.c index 3c4e01bba64..c10bb87461f 100644 --- a/reactos/dll/ntdll/rtl/libsupp.c +++ b/reactos/dll/ntdll/rtl/libsupp.c @@ -15,9 +15,13 @@ SIZE_T RtlpAllocDeallocQueryBufferSize = PAGE_SIZE; PTEB LdrpTopLevelDllBeingLoadedTeb = NULL; +#define IMAGE_DOS_MAGIC 0x5a4d +#define IMAGE_PE_MAGIC 0x00004550 /* FUNCTIONS ***************************************************************/ +#ifndef _M_AMD64 +// FIXME: Why "Not implemented"??? /* * @implemented */ @@ -30,6 +34,7 @@ RtlWalkFrameChain(OUT PVOID *Callers, /* Not implemented for user-mode */ return 0; } +#endif BOOLEAN NTAPI @@ -205,6 +210,19 @@ RtlpCaptureStackLimits(IN ULONG_PTR Ebp, return TRUE; } +#ifdef _AMD64_ +VOID +NTAPI +RtlpGetStackLimits( + OUT PULONG_PTR LowLimit, + OUT PULONG_PTR HighLimit) +{ + *LowLimit = (ULONG_PTR)NtCurrentTeb()->Tib.StackLimit; + *HighLimit = (ULONG_PTR)NtCurrentTeb()->Tib.StackBase; + return; +} +#endif + BOOLEAN NTAPI RtlIsThreadWithinLoaderCallout(VOID) @@ -367,6 +385,62 @@ RtlpGetAtomEntry(PRTL_ATOM_TABLE AtomTable, ULONG Index) return NULL; } +PVOID +NTAPI +RtlpLookupModuleBase( + PVOID Address) +{ + NTSTATUS Status; + MEMORY_BASIC_INFORMATION MemoryInformation; + ULONG_PTR Base, Limit; + PIMAGE_DOS_HEADER DosHeader; + PIMAGE_NT_HEADERS NtHeader; + + Status = NtQueryVirtualMemory(NtCurrentProcess(), + Address, + MemoryBasicInformation, + &MemoryInformation, + sizeof(MEMORY_BASIC_INFORMATION), + NULL); + if (!NT_SUCCESS(Status)) + { + return NULL; + } + + /* FIXME: remove these checks? */ + Base = (ULONG_PTR)MemoryInformation.BaseAddress; + Limit = Base + MemoryInformation.RegionSize; + if ( ((ULONG_PTR)Address < Base) || + ((ULONG_PTR)Address >= Limit) ) + { + /* WTF? */ + return NULL; + } + + /* Check if we got the right kind of memory */ + if ( (MemoryInformation.State != MEM_COMMIT) || + (MemoryInformation.Type != MEM_IMAGE) ) + { + return NULL; + } + + /* Check DOS magic */ + DosHeader = MemoryInformation.AllocationBase; + if (DosHeader->e_magic != IMAGE_DOS_MAGIC) + { + return NULL; + } + + /* Check NT header */ + NtHeader = (PVOID)((ULONG_PTR)DosHeader + DosHeader->e_lfanew); + if (NtHeader->Signature != IMAGE_PE_MAGIC) + { + return NULL; + } + + return MemoryInformation.AllocationBase; +} + /* * Ldr Resource support code