kernel32: Moved GetModuleInformation implementation to kernel32.
This commit is contained in:
parent
9bbf3f9075
commit
0d0f2fa4a9
|
@ -776,6 +776,7 @@
|
|||
@ stdcall K32GetModuleBaseNameW(long long ptr long)
|
||||
@ stdcall K32GetModuleFileNameExA(long long ptr long)
|
||||
@ stdcall K32GetModuleFileNameExW(long long ptr long)
|
||||
@ stdcall K32GetModuleInformation(long long ptr long)
|
||||
@ stdcall K32GetProcessMemoryInfo(long ptr long)
|
||||
@ stdcall K32QueryWorkingSet(long ptr long)
|
||||
@ stdcall K32QueryWorkingSetEx(long ptr long)
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "winbase.h"
|
||||
#include "winternl.h"
|
||||
#include "kernel_private.h"
|
||||
#include "psapi.h"
|
||||
|
||||
#include "wine/exception.h"
|
||||
#include "wine/debug.h"
|
||||
|
@ -1283,6 +1284,29 @@ DWORD WINAPI K32GetModuleFileNameExA(HANDLE process, HMODULE module,
|
|||
return strlen(file_name);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* K32GetModuleInformation (KERNEL32.@)
|
||||
*/
|
||||
BOOL WINAPI K32GetModuleInformation(HANDLE process, HMODULE module,
|
||||
MODULEINFO *modinfo, DWORD cb)
|
||||
{
|
||||
LDR_MODULE ldr_module;
|
||||
|
||||
if (cb < sizeof(MODULEINFO))
|
||||
{
|
||||
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!get_ldr_module(process, module, &ldr_module))
|
||||
return FALSE;
|
||||
|
||||
modinfo->lpBaseOfDll = ldr_module.BaseAddress;
|
||||
modinfo->SizeOfImage = ldr_module.SizeOfImage;
|
||||
modinfo->EntryPoint = ldr_module.EntryPoint;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef __i386__
|
||||
|
||||
/***********************************************************************
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
@ stdcall GetModuleBaseNameW(long long ptr long) kernel32.K32GetModuleBaseNameW
|
||||
@ stdcall GetModuleFileNameExA(long long ptr long) kernel32.K32GetModuleFileNameExA
|
||||
@ stdcall GetModuleFileNameExW(long long ptr long) kernel32.K32GetModuleFileNameExW
|
||||
@ stdcall GetModuleInformation(long long ptr long)
|
||||
@ stdcall GetModuleInformation(long long ptr long) kernel32.K32GetModuleInformation
|
||||
@ stdcall GetPerformanceInfo(ptr long)
|
||||
@ stdcall GetProcessImageFileNameA(long ptr long) kernel32.K32GetProcessImageFileNameA
|
||||
@ stdcall GetProcessImageFileNameW(long ptr long) kernel32.K32GetProcessImageFileNameW
|
||||
|
|
|
@ -34,119 +34,6 @@
|
|||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(psapi);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
HANDLE hProcess;
|
||||
PLIST_ENTRY pHead, pCurrent;
|
||||
LDR_MODULE LdrModule;
|
||||
} MODULE_ITERATOR;
|
||||
|
||||
/***********************************************************************
|
||||
* PSAPI_ModuleIteratorInit [internal]
|
||||
*
|
||||
* Prepares to iterate through the loaded modules of the given process.
|
||||
*
|
||||
* RETURNS
|
||||
* Success: TRUE
|
||||
* Failure: FALSE
|
||||
*/
|
||||
static BOOL PSAPI_ModuleIteratorInit(MODULE_ITERATOR *iter, HANDLE hProcess)
|
||||
{
|
||||
PROCESS_BASIC_INFORMATION pbi;
|
||||
PPEB_LDR_DATA pLdrData;
|
||||
NTSTATUS status;
|
||||
|
||||
/* Get address of PEB */
|
||||
status = NtQueryInformationProcess(hProcess, ProcessBasicInformation,
|
||||
&pbi, sizeof(pbi), NULL);
|
||||
if (status != STATUS_SUCCESS)
|
||||
{
|
||||
SetLastError(RtlNtStatusToDosError(status));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Read address of LdrData from PEB */
|
||||
if (!ReadProcessMemory(hProcess, &pbi.PebBaseAddress->LdrData,
|
||||
&pLdrData, sizeof(pLdrData), NULL))
|
||||
return FALSE;
|
||||
|
||||
/* Read address of first module from LdrData */
|
||||
if (!ReadProcessMemory(hProcess,
|
||||
&pLdrData->InLoadOrderModuleList.Flink,
|
||||
&iter->pCurrent, sizeof(iter->pCurrent), NULL))
|
||||
return FALSE;
|
||||
|
||||
iter->pHead = &pLdrData->InLoadOrderModuleList;
|
||||
iter->hProcess = hProcess;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* PSAPI_ModuleIteratorNext [internal]
|
||||
*
|
||||
* Iterates to the next module.
|
||||
*
|
||||
* RETURNS
|
||||
* 1 : Success
|
||||
* 0 : No more modules
|
||||
* -1 : Failure
|
||||
*
|
||||
* NOTES
|
||||
* Every function which uses this routine suffers from a race condition
|
||||
* when a module is unloaded during the enumeration which can cause the
|
||||
* function to fail. As there is no way to lock the loader of another
|
||||
* process we can't avoid that.
|
||||
*/
|
||||
static INT PSAPI_ModuleIteratorNext(MODULE_ITERATOR *iter)
|
||||
{
|
||||
if (iter->pCurrent == iter->pHead)
|
||||
return 0;
|
||||
|
||||
if (!ReadProcessMemory(iter->hProcess, CONTAINING_RECORD(iter->pCurrent,
|
||||
LDR_MODULE, InLoadOrderModuleList),
|
||||
&iter->LdrModule, sizeof(iter->LdrModule), NULL))
|
||||
return -1;
|
||||
else
|
||||
iter->pCurrent = iter->LdrModule.InLoadOrderModuleList.Flink;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* PSAPI_GetLdrModule [internal]
|
||||
*
|
||||
* Reads the LDR_MODULE structure of the given module.
|
||||
*
|
||||
* RETURNS
|
||||
* Success: TRUE
|
||||
* Failure: FALSE
|
||||
*/
|
||||
|
||||
static BOOL PSAPI_GetLdrModule(HANDLE hProcess, HMODULE hModule,
|
||||
LDR_MODULE *pLdrModule)
|
||||
{
|
||||
MODULE_ITERATOR iter;
|
||||
INT ret;
|
||||
|
||||
if (!PSAPI_ModuleIteratorInit(&iter, hProcess))
|
||||
return FALSE;
|
||||
|
||||
while ((ret = PSAPI_ModuleIteratorNext(&iter)) > 0)
|
||||
/* When hModule is NULL we return the process image - which will be
|
||||
* the first module since our iterator uses InLoadOrderModuleList */
|
||||
if (!hModule || hModule == iter.LdrModule.BaseAddress)
|
||||
{
|
||||
*pLdrModule = iter.LdrModule;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (ret == 0)
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* EnumDeviceDrivers (PSAPI.@)
|
||||
*/
|
||||
|
@ -262,29 +149,6 @@ DWORD WINAPI GetMappedFileNameW(HANDLE hProcess, LPVOID lpv, LPWSTR lpFilename,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* GetModuleInformation (PSAPI.@)
|
||||
*/
|
||||
BOOL WINAPI GetModuleInformation(HANDLE hProcess, HMODULE hModule,
|
||||
LPMODULEINFO lpmodinfo, DWORD cb)
|
||||
{
|
||||
LDR_MODULE LdrModule;
|
||||
|
||||
if (cb < sizeof(MODULEINFO))
|
||||
{
|
||||
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!PSAPI_GetLdrModule(hProcess, hModule, &LdrModule))
|
||||
return FALSE;
|
||||
|
||||
lpmodinfo->lpBaseOfDll = LdrModule.BaseAddress;
|
||||
lpmodinfo->SizeOfImage = LdrModule.SizeOfImage;
|
||||
lpmodinfo->EntryPoint = LdrModule.EntryPoint;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* GetPerformanceInfo (PSAPI.@)
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue