kernel32: Move the psapi functions to kernelbase.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-05-06 16:24:24 +02:00
parent 7addca95b5
commit 876d7af94e
8 changed files with 928 additions and 991 deletions

View File

@ -46,77 +46,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(reg);
/***********************************************************************
* K32GetPerformanceInfo (KERNEL32.@)
*/
BOOL WINAPI K32GetPerformanceInfo(PPERFORMANCE_INFORMATION info, DWORD size)
{
SYSTEM_PERFORMANCE_INFORMATION perf;
SYSTEM_BASIC_INFORMATION basic;
SYSTEM_PROCESS_INFORMATION *process, *spi;
DWORD info_size;
NTSTATUS status;
TRACE( "(%p, %d)\n", info, size );
if (size < sizeof(*info))
{
SetLastError( ERROR_BAD_LENGTH );
return FALSE;
}
status = NtQuerySystemInformation( SystemPerformanceInformation, &perf, sizeof(perf), NULL );
if (status) goto err;
status = NtQuerySystemInformation( SystemBasicInformation, &basic, sizeof(basic), NULL );
if (status) goto err;
info->cb = sizeof(*info);
info->CommitTotal = perf.TotalCommittedPages;
info->CommitLimit = perf.TotalCommitLimit;
info->CommitPeak = perf.PeakCommitment;
info->PhysicalTotal = basic.MmNumberOfPhysicalPages;
info->PhysicalAvailable = perf.AvailablePages;
info->SystemCache = 0;
info->KernelTotal = perf.PagedPoolUsage + perf.NonPagedPoolUsage;
info->KernelPaged = perf.PagedPoolUsage;
info->KernelNonpaged = perf.NonPagedPoolUsage;
info->PageSize = basic.PageSize;
/* fields from SYSTEM_PROCESS_INFORMATION */
NtQuerySystemInformation( SystemProcessInformation, NULL, 0, &info_size );
for (;;)
{
process = HeapAlloc( GetProcessHeap(), 0, info_size );
if (!process)
{
SetLastError( ERROR_OUTOFMEMORY );
return FALSE;
}
status = NtQuerySystemInformation( SystemProcessInformation, process, info_size, &info_size );
if (!status) break;
HeapFree( GetProcessHeap(), 0, process );
if (status != STATUS_INFO_LENGTH_MISMATCH)
goto err;
}
info->HandleCount = info->ProcessCount = info->ThreadCount = 0;
spi = process;
for (;;)
{
info->ProcessCount++;
info->HandleCount += spi->HandleCount;
info->ThreadCount += spi->dwThreadCount;
if (spi->NextEntryOffset == 0) break;
spi = (SYSTEM_PROCESS_INFORMATION *)((char *)spi + spi->NextEntryOffset);
}
HeapFree( GetProcessHeap(), 0, process );
return TRUE;
err:
SetLastError( RtlNtStatusToDosError( status ) );
return FALSE;
}
/***********************************************************************
* GetActiveProcessorGroupCount (KERNEL32.@)
*/

View File

@ -661,69 +661,3 @@ error: /* We get here if there was an error opening the file */
WARN("(%s): return = HFILE_ERROR error= %d\n", name,ofs->nErrCode );
return HFILE_ERROR;
}
/***********************************************************************
* K32EnumDeviceDrivers (KERNEL32.@)
*/
BOOL WINAPI K32EnumDeviceDrivers(void **image_base, DWORD cb, DWORD *needed)
{
FIXME("(%p, %d, %p): stub\n", image_base, cb, needed);
if (needed)
*needed = 0;
return TRUE;
}
/***********************************************************************
* K32GetDeviceDriverBaseNameA (KERNEL32.@)
*/
DWORD WINAPI K32GetDeviceDriverBaseNameA(void *image_base, LPSTR base_name, DWORD size)
{
FIXME("(%p, %p, %d): stub\n", image_base, base_name, size);
if (base_name && size)
base_name[0] = '\0';
return 0;
}
/***********************************************************************
* K32GetDeviceDriverBaseNameW (KERNEL32.@)
*/
DWORD WINAPI K32GetDeviceDriverBaseNameW(void *image_base, LPWSTR base_name, DWORD size)
{
FIXME("(%p, %p, %d): stub\n", image_base, base_name, size);
if (base_name && size)
base_name[0] = '\0';
return 0;
}
/***********************************************************************
* K32GetDeviceDriverFileNameA (KERNEL32.@)
*/
DWORD WINAPI K32GetDeviceDriverFileNameA(void *image_base, LPSTR file_name, DWORD size)
{
FIXME("(%p, %p, %d): stub\n", image_base, file_name, size);
if (file_name && size)
file_name[0] = '\0';
return 0;
}
/***********************************************************************
* K32GetDeviceDriverFileNameW (KERNEL32.@)
*/
DWORD WINAPI K32GetDeviceDriverFileNameW(void *image_base, LPWSTR file_name, DWORD size)
{
FIXME("(%p, %p, %d): stub\n", image_base, file_name, size);
if (file_name && size)
file_name[0] = '\0';
return 0;
}

View File

@ -998,33 +998,33 @@
@ stdcall -import IsValidNLSVersion(long wstr ptr)
# @ stub IsValidUILanguage
@ stdcall -import IsWow64Process(ptr ptr)
@ stdcall K32EmptyWorkingSet(long)
@ stdcall K32EnumDeviceDrivers(ptr long ptr)
@ stdcall K32EnumPageFilesA(ptr ptr)
@ stdcall K32EnumPageFilesW(ptr ptr)
@ stdcall K32EnumProcessModules(long ptr long ptr)
@ stdcall K32EnumProcessModulesEx(long ptr long ptr long)
@ stdcall K32EnumProcesses(ptr long ptr)
@ stdcall K32GetDeviceDriverBaseNameA(ptr ptr long)
@ stdcall K32GetDeviceDriverBaseNameW(ptr ptr long)
@ stdcall K32GetDeviceDriverFileNameA(ptr ptr long)
@ stdcall K32GetDeviceDriverFileNameW(ptr ptr long)
@ stdcall K32GetMappedFileNameA(long ptr ptr long)
@ stdcall K32GetMappedFileNameW(long ptr ptr long)
@ stdcall K32GetModuleBaseNameA(long long ptr long)
@ 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 K32GetPerformanceInfo(ptr long)
@ stdcall K32GetProcessImageFileNameA(long ptr long)
@ stdcall K32GetProcessImageFileNameW(long ptr long)
@ stdcall K32GetProcessMemoryInfo(long ptr long)
@ stdcall K32GetWsChanges(long ptr long)
@ stdcall K32GetWsChangesEx(long ptr ptr)
@ stdcall K32InitializeProcessForWsWatch(long)
@ stdcall K32QueryWorkingSet(long ptr long)
@ stdcall K32QueryWorkingSetEx(long ptr long)
@ stdcall -import K32EmptyWorkingSet(long)
@ stdcall -import K32EnumDeviceDrivers(ptr long ptr)
@ stdcall -import K32EnumPageFilesA(ptr ptr)
@ stdcall -import K32EnumPageFilesW(ptr ptr)
@ stdcall -import K32EnumProcessModules(long ptr long ptr)
@ stdcall -import K32EnumProcessModulesEx(long ptr long ptr long)
@ stdcall -import K32EnumProcesses(ptr long ptr)
@ stdcall -import K32GetDeviceDriverBaseNameA(ptr ptr long)
@ stdcall -import K32GetDeviceDriverBaseNameW(ptr ptr long)
@ stdcall -import K32GetDeviceDriverFileNameA(ptr ptr long)
@ stdcall -import K32GetDeviceDriverFileNameW(ptr ptr long)
@ stdcall -import K32GetMappedFileNameA(long ptr ptr long)
@ stdcall -import K32GetMappedFileNameW(long ptr ptr long)
@ stdcall -import K32GetModuleBaseNameA(long long ptr long)
@ stdcall -import K32GetModuleBaseNameW(long long ptr long)
@ stdcall -import K32GetModuleFileNameExA(long long ptr long)
@ stdcall -import K32GetModuleFileNameExW(long long ptr long)
@ stdcall -import K32GetModuleInformation(long long ptr long)
@ stdcall -import K32GetPerformanceInfo(ptr long)
@ stdcall -import K32GetProcessImageFileNameA(long ptr long)
@ stdcall -import K32GetProcessImageFileNameW(long ptr long)
@ stdcall -import K32GetProcessMemoryInfo(long ptr long)
@ stdcall -import K32GetWsChanges(long ptr long)
@ stdcall -import K32GetWsChangesEx(long ptr ptr)
@ stdcall -import K32InitializeProcessForWsWatch(long)
@ stdcall -import K32QueryWorkingSet(long ptr long)
@ stdcall -import K32QueryWorkingSetEx(long ptr long)
@ stdcall -i386 -private -norelay K32Thk1632Epilog() krnl386.exe16.K32Thk1632Epilog
@ stdcall -i386 -private -norelay K32Thk1632Prolog() krnl386.exe16.K32Thk1632Prolog
@ stdcall -import LCIDToLocaleName(long ptr long long)
@ -1165,8 +1165,8 @@
@ stdcall QueryDepthSList(ptr) ntdll.RtlQueryDepthSList
@ stdcall QueryDosDeviceA(str ptr long)
@ stdcall -import QueryDosDeviceW(wstr ptr long)
@ stdcall QueryFullProcessImageNameA(ptr long ptr ptr)
@ stdcall QueryFullProcessImageNameW(ptr long ptr ptr)
@ stdcall -import QueryFullProcessImageNameA(ptr long ptr ptr)
@ stdcall -import QueryFullProcessImageNameW(ptr long ptr ptr)
# @ stub QueryIdleProcessorCycleTime
# @ stub QueryIdleProcessorCycleTimeEx
@ stdcall QueryInformationJobObject(long long ptr long ptr)

View File

@ -358,488 +358,6 @@ FARPROC WINAPI GetProcAddress( HMODULE hModule, LPCSTR function )
return get_proc_address_wrapper( hModule, function );
}
typedef struct _PEB32
{
BOOLEAN InheritedAddressSpace;
BOOLEAN ReadImageFileExecOptions;
BOOLEAN BeingDebugged;
BOOLEAN SpareBool;
DWORD Mutant;
DWORD ImageBaseAddress;
DWORD LdrData;
} PEB32;
typedef struct _LIST_ENTRY32
{
DWORD Flink;
DWORD Blink;
} LIST_ENTRY32;
typedef struct _PEB_LDR_DATA32
{
ULONG Length;
BOOLEAN Initialized;
DWORD SsHandle;
LIST_ENTRY32 InLoadOrderModuleList;
} PEB_LDR_DATA32;
typedef struct _UNICODE_STRING32
{
USHORT Length;
USHORT MaximumLength;
DWORD Buffer;
} UNICODE_STRING32;
typedef struct _LDR_DATA_TABLE_ENTRY32
{
LIST_ENTRY32 InLoadOrderModuleList;
LIST_ENTRY32 InMemoryOrderModuleList;
LIST_ENTRY32 InInitializationOrderModuleList;
DWORD BaseAddress;
DWORD EntryPoint;
ULONG SizeOfImage;
UNICODE_STRING32 FullDllName;
UNICODE_STRING32 BaseDllName;
} LDR_DATA_TABLE_ENTRY32;
typedef struct {
HANDLE process;
PLIST_ENTRY head, current;
LDR_DATA_TABLE_ENTRY ldr_module;
BOOL wow64;
LDR_DATA_TABLE_ENTRY32 ldr_module32;
} MODULE_ITERATOR;
static BOOL init_module_iterator(MODULE_ITERATOR *iter, HANDLE process)
{
PROCESS_BASIC_INFORMATION pbi;
PPEB_LDR_DATA ldr_data;
NTSTATUS status;
if (!IsWow64Process(process, &iter->wow64))
return FALSE;
/* Get address of PEB */
status = NtQueryInformationProcess(process, ProcessBasicInformation,
&pbi, sizeof(pbi), NULL);
if (status != STATUS_SUCCESS)
{
SetLastError(RtlNtStatusToDosError(status));
return FALSE;
}
if (sizeof(void *) == 8 && iter->wow64)
{
PEB_LDR_DATA32 *ldr_data32_ptr;
DWORD ldr_data32, first_module;
PEB32 *peb32;
peb32 = (PEB32 *)(DWORD_PTR)pbi.PebBaseAddress;
if (!ReadProcessMemory(process, &peb32->LdrData, &ldr_data32,
sizeof(ldr_data32), NULL))
return FALSE;
ldr_data32_ptr = (PEB_LDR_DATA32 *)(DWORD_PTR) ldr_data32;
if (!ReadProcessMemory(process,
&ldr_data32_ptr->InLoadOrderModuleList.Flink,
&first_module, sizeof(first_module), NULL))
return FALSE;
iter->head = (LIST_ENTRY *)&ldr_data32_ptr->InLoadOrderModuleList;
iter->current = (LIST_ENTRY *)(DWORD_PTR) first_module;
iter->process = process;
return TRUE;
}
/* Read address of LdrData from PEB */
if (!ReadProcessMemory(process, &pbi.PebBaseAddress->LdrData,
&ldr_data, sizeof(ldr_data), NULL))
return FALSE;
/* Read address of first module from LdrData */
if (!ReadProcessMemory(process,
&ldr_data->InLoadOrderModuleList.Flink,
&iter->current, sizeof(iter->current), NULL))
return FALSE;
iter->head = &ldr_data->InLoadOrderModuleList;
iter->process = process;
return TRUE;
}
static int module_iterator_next(MODULE_ITERATOR *iter)
{
if (iter->current == iter->head)
return 0;
if (sizeof(void *) == 8 && iter->wow64)
{
LIST_ENTRY32 *entry32 = (LIST_ENTRY32 *)iter->current;
if (!ReadProcessMemory(iter->process,
CONTAINING_RECORD(entry32, LDR_DATA_TABLE_ENTRY32, InLoadOrderModuleList),
&iter->ldr_module32, sizeof(iter->ldr_module32), NULL))
return -1;
iter->current = (LIST_ENTRY *)(DWORD_PTR) iter->ldr_module32.InLoadOrderModuleList.Flink;
return 1;
}
if (!ReadProcessMemory(iter->process,
CONTAINING_RECORD(iter->current, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks),
&iter->ldr_module, sizeof(iter->ldr_module), NULL))
return -1;
iter->current = iter->ldr_module.InLoadOrderLinks.Flink;
return 1;
}
static BOOL get_ldr_module(HANDLE process, HMODULE module, LDR_DATA_TABLE_ENTRY *ldr_module)
{
MODULE_ITERATOR iter;
INT ret;
if (!init_module_iterator(&iter, process))
return FALSE;
while ((ret = module_iterator_next(&iter)) > 0)
/* When hModule is NULL we return the process image - which will be
* the first module since our iterator uses InLoadOrderModuleList */
if (!module || module == iter.ldr_module.DllBase)
{
*ldr_module = iter.ldr_module;
return TRUE;
}
if (ret == 0)
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
static BOOL get_ldr_module32(HANDLE process, HMODULE module, LDR_DATA_TABLE_ENTRY32 *ldr_module)
{
MODULE_ITERATOR iter;
INT ret;
if (!init_module_iterator(&iter, process))
return FALSE;
while ((ret = module_iterator_next(&iter)) > 0)
/* When hModule is NULL we return the process image - which will be
* the first module since our iterator uses InLoadOrderModuleList */
if (!module || (DWORD)(DWORD_PTR) module == iter.ldr_module32.BaseAddress)
{
*ldr_module = iter.ldr_module32;
return TRUE;
}
if (ret == 0)
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
/***********************************************************************
* K32EnumProcessModules (KERNEL32.@)
*
* NOTES
* Returned list is in load order.
*/
BOOL WINAPI K32EnumProcessModules(HANDLE process, HMODULE *lphModule,
DWORD cb, DWORD *needed)
{
MODULE_ITERATOR iter;
DWORD size = 0;
INT ret;
if (process == GetCurrentProcess())
{
PPEB_LDR_DATA ldr_data = NtCurrentTeb()->Peb->LdrData;
PLIST_ENTRY head = &ldr_data->InLoadOrderModuleList;
PLIST_ENTRY entry = head->Flink;
if (cb && !lphModule)
{
SetLastError(ERROR_NOACCESS);
return FALSE;
}
while (entry != head)
{
PLDR_DATA_TABLE_ENTRY table_entry = (PLDR_DATA_TABLE_ENTRY)
((PBYTE)entry - offsetof(LDR_DATA_TABLE_ENTRY, InLoadOrderLinks));
if (cb >= sizeof(HMODULE))
{
*lphModule++ = table_entry->DllBase;
cb -= sizeof(HMODULE);
}
size += sizeof(HMODULE);
entry = entry->Flink;
}
if (!needed)
{
SetLastError(ERROR_NOACCESS);
return FALSE;
}
*needed = size;
return TRUE;
}
if (!init_module_iterator(&iter, process))
return FALSE;
if (cb && !lphModule)
{
SetLastError(ERROR_NOACCESS);
return FALSE;
}
while ((ret = module_iterator_next(&iter)) > 0)
{
if (cb >= sizeof(HMODULE))
{
if (sizeof(void *) == 8 && iter.wow64)
*lphModule++ = (HMODULE) (DWORD_PTR)iter.ldr_module32.BaseAddress;
else
*lphModule++ = iter.ldr_module.DllBase;
cb -= sizeof(HMODULE);
}
size += sizeof(HMODULE);
}
if (!needed)
{
SetLastError(ERROR_NOACCESS);
return FALSE;
}
*needed = size;
return ret == 0;
}
/***********************************************************************
* K32EnumProcessModulesEx (KERNEL32.@)
*
* NOTES
* Returned list is in load order.
*/
BOOL WINAPI K32EnumProcessModulesEx(HANDLE process, HMODULE *lphModule,
DWORD cb, DWORD *needed, DWORD filter)
{
FIXME("(%p, %p, %d, %p, %d) semi-stub\n",
process, lphModule, cb, needed, filter);
return K32EnumProcessModules(process, lphModule, cb, needed);
}
/***********************************************************************
* K32GetModuleBaseNameW (KERNEL32.@)
*/
DWORD WINAPI K32GetModuleBaseNameW(HANDLE process, HMODULE module,
LPWSTR base_name, DWORD size)
{
LDR_DATA_TABLE_ENTRY ldr_module;
BOOL wow64;
if (!IsWow64Process(process, &wow64))
return 0;
if (sizeof(void *) == 8 && wow64)
{
LDR_DATA_TABLE_ENTRY32 ldr_module32;
if (!get_ldr_module32(process, module, &ldr_module32))
return 0;
size = min(ldr_module32.BaseDllName.Length / sizeof(WCHAR), size);
if (!ReadProcessMemory(process, (void *)(DWORD_PTR)ldr_module32.BaseDllName.Buffer,
base_name, size * sizeof(WCHAR), NULL))
return 0;
}
else
{
if (!get_ldr_module(process, module, &ldr_module))
return 0;
size = min(ldr_module.BaseDllName.Length / sizeof(WCHAR), size);
if (!ReadProcessMemory(process, ldr_module.BaseDllName.Buffer,
base_name, size * sizeof(WCHAR), NULL))
return 0;
}
base_name[size] = 0;
return size;
}
/***********************************************************************
* K32GetModuleBaseNameA (KERNEL32.@)
*/
DWORD WINAPI K32GetModuleBaseNameA(HANDLE process, HMODULE module,
LPSTR base_name, DWORD size)
{
WCHAR *base_name_w;
DWORD len, ret = 0;
if(!base_name || !size) {
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}
base_name_w = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * size);
if(!base_name_w)
return 0;
len = K32GetModuleBaseNameW(process, module, base_name_w, size);
TRACE("%d, %s\n", len, debugstr_w(base_name_w));
if (len)
{
ret = WideCharToMultiByte(CP_ACP, 0, base_name_w, len,
base_name, size, NULL, NULL);
if (ret < size) base_name[ret] = 0;
}
HeapFree(GetProcessHeap(), 0, base_name_w);
return ret;
}
/***********************************************************************
* K32GetModuleFileNameExW (KERNEL32.@)
*/
DWORD WINAPI K32GetModuleFileNameExW(HANDLE process, HMODULE module,
LPWSTR file_name, DWORD size)
{
LDR_DATA_TABLE_ENTRY ldr_module;
BOOL wow64;
DWORD len;
if (!size) return 0;
if (!IsWow64Process(process, &wow64))
return 0;
if (sizeof(void *) == 8 && wow64)
{
LDR_DATA_TABLE_ENTRY32 ldr_module32;
if (!get_ldr_module32(process, module, &ldr_module32))
return 0;
len = ldr_module32.FullDllName.Length / sizeof(WCHAR);
if (!ReadProcessMemory(process, (void *)(DWORD_PTR)ldr_module32.FullDllName.Buffer,
file_name, min( len, size ) * sizeof(WCHAR), NULL))
return 0;
}
else
{
if (!get_ldr_module(process, module, &ldr_module))
return 0;
len = ldr_module.FullDllName.Length / sizeof(WCHAR);
if (!ReadProcessMemory(process, ldr_module.FullDllName.Buffer,
file_name, min( len, size ) * sizeof(WCHAR), NULL))
return 0;
}
if (len < size)
{
file_name[len] = 0;
return len;
}
else
{
file_name[size - 1] = 0;
return size;
}
}
/***********************************************************************
* K32GetModuleFileNameExA (KERNEL32.@)
*/
DWORD WINAPI K32GetModuleFileNameExA(HANDLE process, HMODULE module,
LPSTR file_name, DWORD size)
{
WCHAR *ptr;
DWORD len;
TRACE("(hProcess=%p, hModule=%p, %p, %d)\n", process, module, file_name, size);
if (!file_name || !size)
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
if ( process == GetCurrentProcess() )
{
len = GetModuleFileNameA( module, file_name, size );
file_name[size - 1] = '\0';
return len;
}
if (!(ptr = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)))) return 0;
len = K32GetModuleFileNameExW(process, module, ptr, size);
if (!len)
{
file_name[0] = '\0';
}
else
{
if (!WideCharToMultiByte( CP_ACP, 0, ptr, -1, file_name, size, NULL, NULL ))
{
file_name[size - 1] = 0;
len = size;
}
else if (len < size) len = strlen( file_name );
}
HeapFree(GetProcessHeap(), 0, ptr);
return len;
}
/***********************************************************************
* K32GetModuleInformation (KERNEL32.@)
*/
BOOL WINAPI K32GetModuleInformation(HANDLE process, HMODULE module,
MODULEINFO *modinfo, DWORD cb)
{
LDR_DATA_TABLE_ENTRY ldr_module;
BOOL wow64;
if (cb < sizeof(MODULEINFO))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
if (!IsWow64Process(process, &wow64))
return FALSE;
if (sizeof(void *) == 8 && wow64)
{
LDR_DATA_TABLE_ENTRY32 ldr_module32;
if (!get_ldr_module32(process, module, &ldr_module32))
return FALSE;
modinfo->lpBaseOfDll = (void *)(DWORD_PTR)ldr_module32.BaseAddress;
modinfo->SizeOfImage = ldr_module32.SizeOfImage;
modinfo->EntryPoint = (void *)(DWORD_PTR)ldr_module32.EntryPoint;
}
else
{
if (!get_ldr_module(process, module, &ldr_module))
return FALSE;
modinfo->lpBaseOfDll = ldr_module.DllBase;
modinfo->SizeOfImage = ldr_module.SizeOfImage;
modinfo->EntryPoint = ldr_module.EntryPoint;
}
return TRUE;
}
#ifdef __i386__
/***********************************************************************

View File

@ -518,15 +518,6 @@ BOOL WINAPI SetProcessWorkingSetSize(HANDLE process, SIZE_T minset, SIZE_T maxse
return SetProcessWorkingSetSizeEx(process, minset, maxset, 0);
}
/***********************************************************************
* K32EmptyWorkingSet (KERNEL32.@)
*/
BOOL WINAPI K32EmptyWorkingSet(HANDLE hProcess)
{
return SetProcessWorkingSetSize(hProcess, (SIZE_T)-1, (SIZE_T)-1);
}
/***********************************************************************
* GetProcessWorkingSetSize (KERNEL32.@)
*/
@ -544,221 +535,6 @@ BOOL WINAPI GetProcessIoCounters(HANDLE hProcess, PIO_COUNTERS ioc)
return set_ntstatus( NtQueryInformationProcess(hProcess, ProcessIoCounters, ioc, sizeof(*ioc), NULL ));
}
/******************************************************************
* QueryFullProcessImageNameA (KERNEL32.@)
*/
BOOL WINAPI QueryFullProcessImageNameA(HANDLE hProcess, DWORD dwFlags, LPSTR lpExeName, PDWORD pdwSize)
{
BOOL retval;
DWORD pdwSizeW = *pdwSize;
LPWSTR lpExeNameW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *pdwSize * sizeof(WCHAR));
retval = QueryFullProcessImageNameW(hProcess, dwFlags, lpExeNameW, &pdwSizeW);
if(retval)
retval = (0 != WideCharToMultiByte(CP_ACP, 0, lpExeNameW, -1,
lpExeName, *pdwSize, NULL, NULL));
if(retval)
*pdwSize = strlen(lpExeName);
HeapFree(GetProcessHeap(), 0, lpExeNameW);
return retval;
}
/******************************************************************
* QueryFullProcessImageNameW (KERNEL32.@)
*/
BOOL WINAPI QueryFullProcessImageNameW(HANDLE hProcess, DWORD dwFlags, LPWSTR lpExeName, PDWORD pdwSize)
{
BYTE buffer[sizeof(UNICODE_STRING) + MAX_PATH*sizeof(WCHAR)]; /* this buffer should be enough */
UNICODE_STRING *dynamic_buffer = NULL;
UNICODE_STRING *result = NULL;
NTSTATUS status;
DWORD needed;
/* FIXME: On Windows, ProcessImageFileName return an NT path. In Wine it
* is a DOS path and we depend on this. */
status = NtQueryInformationProcess(hProcess, ProcessImageFileName, buffer,
sizeof(buffer) - sizeof(WCHAR), &needed);
if (status == STATUS_INFO_LENGTH_MISMATCH)
{
dynamic_buffer = HeapAlloc(GetProcessHeap(), 0, needed + sizeof(WCHAR));
status = NtQueryInformationProcess(hProcess, ProcessImageFileName, (LPBYTE)dynamic_buffer, needed, &needed);
result = dynamic_buffer;
}
else
result = (PUNICODE_STRING)buffer;
if (status) goto cleanup;
if (dwFlags & PROCESS_NAME_NATIVE)
{
WCHAR drive[3];
WCHAR device[1024];
DWORD ntlen, devlen;
if (result->Buffer[1] != ':' || result->Buffer[0] < 'A' || result->Buffer[0] > 'Z')
{
/* We cannot convert it to an NT device path so fail */
status = STATUS_NO_SUCH_DEVICE;
goto cleanup;
}
/* Find this drive's NT device path */
drive[0] = result->Buffer[0];
drive[1] = ':';
drive[2] = 0;
if (!QueryDosDeviceW(drive, device, ARRAY_SIZE(device)))
{
status = STATUS_NO_SUCH_DEVICE;
goto cleanup;
}
devlen = lstrlenW(device);
ntlen = devlen + (result->Length/sizeof(WCHAR) - 2);
if (ntlen + 1 > *pdwSize)
{
status = STATUS_BUFFER_TOO_SMALL;
goto cleanup;
}
*pdwSize = ntlen;
memcpy(lpExeName, device, devlen * sizeof(*device));
memcpy(lpExeName + devlen, result->Buffer + 2, result->Length - 2 * sizeof(WCHAR));
lpExeName[*pdwSize] = 0;
TRACE("NT path: %s\n", debugstr_w(lpExeName));
}
else
{
if (result->Length/sizeof(WCHAR) + 1 > *pdwSize)
{
status = STATUS_BUFFER_TOO_SMALL;
goto cleanup;
}
*pdwSize = result->Length/sizeof(WCHAR);
memcpy( lpExeName, result->Buffer, result->Length );
lpExeName[*pdwSize] = 0;
}
cleanup:
HeapFree(GetProcessHeap(), 0, dynamic_buffer);
return set_ntstatus( status );
}
/***********************************************************************
* K32GetProcessImageFileNameA (KERNEL32.@)
*/
DWORD WINAPI K32GetProcessImageFileNameA( HANDLE process, LPSTR file, DWORD size )
{
return QueryFullProcessImageNameA(process, PROCESS_NAME_NATIVE, file, &size) ? size : 0;
}
/***********************************************************************
* K32GetProcessImageFileNameW (KERNEL32.@)
*/
DWORD WINAPI K32GetProcessImageFileNameW( HANDLE process, LPWSTR file, DWORD size )
{
return QueryFullProcessImageNameW(process, PROCESS_NAME_NATIVE, file, &size) ? size : 0;
}
/***********************************************************************
* K32EnumProcesses (KERNEL32.@)
*/
BOOL WINAPI K32EnumProcesses(DWORD *lpdwProcessIDs, DWORD cb, DWORD *lpcbUsed)
{
SYSTEM_PROCESS_INFORMATION *spi;
ULONG size = 0x4000;
void *buf = NULL;
NTSTATUS status;
do {
size *= 2;
HeapFree(GetProcessHeap(), 0, buf);
buf = HeapAlloc(GetProcessHeap(), 0, size);
if (!buf)
return FALSE;
status = NtQuerySystemInformation(SystemProcessInformation, buf, size, NULL);
} while(status == STATUS_INFO_LENGTH_MISMATCH);
if (!set_ntstatus( status ))
{
HeapFree(GetProcessHeap(), 0, buf);
return FALSE;
}
spi = buf;
for (*lpcbUsed = 0; cb >= sizeof(DWORD); cb -= sizeof(DWORD))
{
*lpdwProcessIDs++ = HandleToUlong(spi->UniqueProcessId);
*lpcbUsed += sizeof(DWORD);
if (spi->NextEntryOffset == 0)
break;
spi = (SYSTEM_PROCESS_INFORMATION *)(((PCHAR)spi) + spi->NextEntryOffset);
}
HeapFree(GetProcessHeap(), 0, buf);
return TRUE;
}
/***********************************************************************
* K32QueryWorkingSet (KERNEL32.@)
*/
BOOL WINAPI K32QueryWorkingSet( HANDLE process, LPVOID buffer, DWORD size )
{
TRACE( "(%p, %p, %d)\n", process, buffer, size );
return set_ntstatus( NtQueryVirtualMemory( process, NULL, MemoryWorkingSetList, buffer, size, NULL ));
}
/***********************************************************************
* K32QueryWorkingSetEx (KERNEL32.@)
*/
BOOL WINAPI K32QueryWorkingSetEx( HANDLE process, LPVOID buffer, DWORD size )
{
TRACE( "(%p, %p, %d)\n", process, buffer, size );
return set_ntstatus( NtQueryVirtualMemory( process, NULL, MemoryWorkingSetExInformation, buffer, size, NULL ));
}
/***********************************************************************
* K32GetProcessMemoryInfo (KERNEL32.@)
*
* Retrieve memory usage information for a given process
*
*/
BOOL WINAPI K32GetProcessMemoryInfo(HANDLE process,
PPROCESS_MEMORY_COUNTERS pmc, DWORD cb)
{
VM_COUNTERS vmc;
if (cb < sizeof(PROCESS_MEMORY_COUNTERS))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
if (!set_ntstatus( NtQueryInformationProcess( process, ProcessVmCounters, &vmc, sizeof(vmc), NULL )))
return FALSE;
pmc->cb = sizeof(PROCESS_MEMORY_COUNTERS);
pmc->PageFaultCount = vmc.PageFaultCount;
pmc->PeakWorkingSetSize = vmc.PeakWorkingSetSize;
pmc->WorkingSetSize = vmc.WorkingSetSize;
pmc->QuotaPeakPagedPoolUsage = vmc.QuotaPeakPagedPoolUsage;
pmc->QuotaPagedPoolUsage = vmc.QuotaPagedPoolUsage;
pmc->QuotaPeakNonPagedPoolUsage = vmc.QuotaPeakNonPagedPoolUsage;
pmc->QuotaNonPagedPoolUsage = vmc.QuotaNonPagedPoolUsage;
pmc->PagefileUsage = vmc.PagefileUsage;
pmc->PeakPagefileUsage = vmc.PeakPagefileUsage;
return TRUE;
}
/***********************************************************************
* RegisterServiceProcess (KERNEL32.@)
*

View File

@ -44,8 +44,7 @@
#include "kernel_private.h"
WINE_DECLARE_DEBUG_CHANNEL(seh);
WINE_DECLARE_DEBUG_CHANNEL(file);
WINE_DEFAULT_DEBUG_CHANNEL(seh);
static LONG WINAPI badptr_handler( EXCEPTION_POINTERS *eptr )
@ -98,7 +97,7 @@ BOOL WINAPI IsBadReadPtr( LPCVOID ptr, UINT_PTR size )
}
__EXCEPT( badptr_handler )
{
TRACE_(seh)("%p caused page fault during read\n", ptr);
TRACE("%p caused page fault during read\n", ptr);
return TRUE;
}
__ENDTRY
@ -139,7 +138,7 @@ BOOL WINAPI IsBadWritePtr( LPVOID ptr, UINT_PTR size )
}
__EXCEPT( badptr_handler )
{
TRACE_(seh)("%p caused page fault during write\n", ptr);
TRACE("%p caused page fault during write\n", ptr);
return TRUE;
}
__ENDTRY
@ -227,7 +226,7 @@ BOOL WINAPI IsBadStringPtrA( LPCSTR str, UINT_PTR max )
}
__EXCEPT( badptr_handler )
{
TRACE_(seh)("%p caused page fault during read\n", str);
TRACE("%p caused page fault during read\n", str);
return TRUE;
}
__ENDTRY
@ -251,93 +250,9 @@ BOOL WINAPI IsBadStringPtrW( LPCWSTR str, UINT_PTR max )
}
__EXCEPT( badptr_handler )
{
TRACE_(seh)("%p caused page fault during read\n", str);
TRACE("%p caused page fault during read\n", str);
return TRUE;
}
__ENDTRY
return FALSE;
}
/***********************************************************************
* K32GetMappedFileNameA (KERNEL32.@)
*/
DWORD WINAPI K32GetMappedFileNameA(HANDLE process, LPVOID lpv, LPSTR file_name, DWORD size)
{
FIXME_(file)("(%p, %p, %p, %d): stub\n", process, lpv, file_name, size);
if (file_name && size)
file_name[0] = '\0';
return 0;
}
/***********************************************************************
* K32GetMappedFileNameW (KERNEL32.@)
*/
DWORD WINAPI K32GetMappedFileNameW(HANDLE process, LPVOID lpv, LPWSTR file_name, DWORD size)
{
FIXME_(file)("(%p, %p, %p, %d): stub\n", process, lpv, file_name, size);
if (file_name && size)
file_name[0] = '\0';
return 0;
}
/***********************************************************************
* K32EnumPageFilesA (KERNEL32.@)
*/
BOOL WINAPI K32EnumPageFilesA( PENUM_PAGE_FILE_CALLBACKA callback, LPVOID context )
{
FIXME_(file)("(%p, %p) stub\n", callback, context );
return FALSE;
}
/***********************************************************************
* K32EnumPageFilesW (KERNEL32.@)
*/
BOOL WINAPI K32EnumPageFilesW( PENUM_PAGE_FILE_CALLBACKW callback, LPVOID context )
{
FIXME_(file)("(%p, %p) stub\n", callback, context );
return FALSE;
}
/***********************************************************************
* K32GetWsChanges (KERNEL32.@)
*/
BOOL WINAPI K32GetWsChanges(HANDLE process, PPSAPI_WS_WATCH_INFORMATION watchinfo, DWORD size)
{
NTSTATUS status;
TRACE_(seh)("(%p, %p, %d)\n", process, watchinfo, size);
status = NtQueryInformationProcess( process, ProcessWorkingSetWatch, watchinfo, size, NULL );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
return FALSE;
}
return TRUE;
}
/***********************************************************************
* K32GetWsChangesEx (KERNEL32.@)
*/
BOOL WINAPI K32GetWsChangesEx(HANDLE process, PSAPI_WS_WATCH_INFORMATION_EX *watchinfoex, DWORD *size)
{
FIXME_(seh)("(%p, %p, %p)\n", process, watchinfoex, size);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
/***********************************************************************
* K32InitializeProcessForWsWatch (KERNEL32.@)
*/
BOOL WINAPI K32InitializeProcessForWsWatch(HANDLE process)
{
FIXME_(seh)("(process=%p): stub\n", process);
return TRUE;
}

View File

@ -26,8 +26,10 @@
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "winnls.h"
#include "wingdi.h"
#include "winuser.h"
#include "psapi.h"
#include "werapi.h"
#include "wine/exception.h"
@ -849,3 +851,866 @@ HRESULT WINAPI /* DECLSPEC_HOTPATCH */ WerUnregisterRuntimeExceptionModule( cons
FIXME( "(%s, %p) stub\n", debugstr_w(dll), context );
return S_OK;
}
/***********************************************************************
* psapi functions
***********************************************************************/
typedef struct _PEB32
{
BOOLEAN InheritedAddressSpace;
BOOLEAN ReadImageFileExecOptions;
BOOLEAN BeingDebugged;
BOOLEAN SpareBool;
DWORD Mutant;
DWORD ImageBaseAddress;
DWORD LdrData;
} PEB32;
typedef struct _LIST_ENTRY32
{
DWORD Flink;
DWORD Blink;
} LIST_ENTRY32;
typedef struct _PEB_LDR_DATA32
{
ULONG Length;
BOOLEAN Initialized;
DWORD SsHandle;
LIST_ENTRY32 InLoadOrderModuleList;
} PEB_LDR_DATA32;
typedef struct _UNICODE_STRING32
{
USHORT Length;
USHORT MaximumLength;
DWORD Buffer;
} UNICODE_STRING32;
typedef struct _LDR_DATA_TABLE_ENTRY32
{
LIST_ENTRY32 InLoadOrderModuleList;
LIST_ENTRY32 InMemoryOrderModuleList;
LIST_ENTRY32 InInitializationOrderModuleList;
DWORD BaseAddress;
DWORD EntryPoint;
ULONG SizeOfImage;
UNICODE_STRING32 FullDllName;
UNICODE_STRING32 BaseDllName;
} LDR_DATA_TABLE_ENTRY32;
struct module_iterator
{
HANDLE process;
LIST_ENTRY *head;
LIST_ENTRY *current;
BOOL wow64;
LDR_DATA_TABLE_ENTRY ldr_module;
LDR_DATA_TABLE_ENTRY32 ldr_module32;
};
static BOOL init_module_iterator( struct module_iterator *iter, HANDLE process )
{
PROCESS_BASIC_INFORMATION pbi;
PPEB_LDR_DATA ldr_data;
if (!IsWow64Process( process, &iter->wow64 )) return FALSE;
/* get address of PEB */
if (!set_ntstatus( NtQueryInformationProcess( process, ProcessBasicInformation,
&pbi, sizeof(pbi), NULL )))
return FALSE;
if (is_win64 && iter->wow64)
{
PEB_LDR_DATA32 *ldr_data32_ptr;
DWORD ldr_data32, first_module;
PEB32 *peb32;
peb32 = (PEB32 *)(DWORD_PTR)pbi.PebBaseAddress;
if (!ReadProcessMemory( process, &peb32->LdrData, &ldr_data32, sizeof(ldr_data32), NULL ))
return FALSE;
ldr_data32_ptr = (PEB_LDR_DATA32 *)(DWORD_PTR) ldr_data32;
if (!ReadProcessMemory( process, &ldr_data32_ptr->InLoadOrderModuleList.Flink,
&first_module, sizeof(first_module), NULL ))
return FALSE;
iter->head = (LIST_ENTRY *)&ldr_data32_ptr->InLoadOrderModuleList;
iter->current = (LIST_ENTRY *)(DWORD_PTR)first_module;
iter->process = process;
return TRUE;
}
/* read address of LdrData from PEB */
if (!ReadProcessMemory( process, &pbi.PebBaseAddress->LdrData, &ldr_data, sizeof(ldr_data), NULL ))
return FALSE;
/* read address of first module from LdrData */
if (!ReadProcessMemory( process, &ldr_data->InLoadOrderModuleList.Flink,
&iter->current, sizeof(iter->current), NULL ))
return FALSE;
iter->head = &ldr_data->InLoadOrderModuleList;
iter->process = process;
return TRUE;
}
static int module_iterator_next( struct module_iterator *iter )
{
if (iter->current == iter->head) return 0;
if (is_win64 && iter->wow64)
{
LIST_ENTRY32 *entry32 = (LIST_ENTRY32 *)iter->current;
if (!ReadProcessMemory( iter->process,
CONTAINING_RECORD(entry32, LDR_DATA_TABLE_ENTRY32, InLoadOrderModuleList),
&iter->ldr_module32, sizeof(iter->ldr_module32), NULL ))
return -1;
iter->current = (LIST_ENTRY *)(DWORD_PTR)iter->ldr_module32.InLoadOrderModuleList.Flink;
return 1;
}
if (!ReadProcessMemory( iter->process,
CONTAINING_RECORD(iter->current, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks),
&iter->ldr_module, sizeof(iter->ldr_module), NULL ))
return -1;
iter->current = iter->ldr_module.InLoadOrderLinks.Flink;
return 1;
}
static BOOL get_ldr_module( HANDLE process, HMODULE module, LDR_DATA_TABLE_ENTRY *ldr_module )
{
struct module_iterator iter;
INT ret;
if (!init_module_iterator( &iter, process )) return FALSE;
while ((ret = module_iterator_next( &iter )) > 0)
/* When hModule is NULL we return the process image - which will be
* the first module since our iterator uses InLoadOrderModuleList */
if (!module || module == iter.ldr_module.DllBase)
{
*ldr_module = iter.ldr_module;
return TRUE;
}
if (ret == 0) SetLastError( ERROR_INVALID_HANDLE );
return FALSE;
}
static BOOL get_ldr_module32( HANDLE process, HMODULE module, LDR_DATA_TABLE_ENTRY32 *ldr_module )
{
struct module_iterator iter;
INT ret;
if (!init_module_iterator( &iter, process )) return FALSE;
while ((ret = module_iterator_next( &iter )) > 0)
/* When hModule is NULL we return the process image - which will be
* the first module since our iterator uses InLoadOrderModuleList */
if (!module || (DWORD)(DWORD_PTR)module == iter.ldr_module32.BaseAddress)
{
*ldr_module = iter.ldr_module32;
return TRUE;
}
if (ret == 0) SetLastError( ERROR_INVALID_HANDLE );
return FALSE;
}
/***********************************************************************
* K32EmptyWorkingSet (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH K32EmptyWorkingSet( HANDLE process )
{
return SetProcessWorkingSetSizeEx( process, (SIZE_T)-1, (SIZE_T)-1, 0 );
}
/***********************************************************************
* K32EnumDeviceDrivers (kernelbase.@)
*/
BOOL WINAPI K32EnumDeviceDrivers( void **image_base, DWORD count, DWORD *needed )
{
FIXME( "(%p, %d, %p): stub\n", image_base, count, needed );
if (needed) *needed = 0;
return TRUE;
}
/***********************************************************************
* K32EnumPageFilesA (kernelbase.@)
*/
BOOL WINAPI /* DECLSPEC_HOTPATCH */ K32EnumPageFilesA( PENUM_PAGE_FILE_CALLBACKA callback, void *context )
{
FIXME( "(%p, %p) stub\n", callback, context );
return FALSE;
}
/***********************************************************************
* K32EnumPageFilesW (kernelbase.@)
*/
BOOL WINAPI /* DECLSPEC_HOTPATCH */ K32EnumPageFilesW( PENUM_PAGE_FILE_CALLBACKW callback, void *context )
{
FIXME( "(%p, %p) stub\n", callback, context );
return FALSE;
}
/***********************************************************************
* K32EnumProcessModules (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH K32EnumProcessModules( HANDLE process, HMODULE *module,
DWORD count, DWORD *needed )
{
struct module_iterator iter;
DWORD size = 0;
INT ret;
if (process == GetCurrentProcess())
{
PPEB_LDR_DATA ldr_data = NtCurrentTeb()->Peb->LdrData;
PLIST_ENTRY head = &ldr_data->InLoadOrderModuleList;
PLIST_ENTRY entry = head->Flink;
if (count && !module)
{
SetLastError( ERROR_NOACCESS );
return FALSE;
}
while (entry != head)
{
LDR_DATA_TABLE_ENTRY *ldr = CONTAINING_RECORD( entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks );
if (count >= sizeof(HMODULE))
{
*module++ = ldr->DllBase;
count -= sizeof(HMODULE);
}
size += sizeof(HMODULE);
entry = entry->Flink;
}
if (!needed)
{
SetLastError( ERROR_NOACCESS );
return FALSE;
}
*needed = size;
return TRUE;
}
if (!init_module_iterator( &iter, process )) return FALSE;
if (count && !module)
{
SetLastError( ERROR_NOACCESS );
return FALSE;
}
while ((ret = module_iterator_next( &iter )) > 0)
{
if (count >= sizeof(HMODULE))
{
if (sizeof(void *) == 8 && iter.wow64)
*module++ = (HMODULE) (DWORD_PTR)iter.ldr_module32.BaseAddress;
else
*module++ = iter.ldr_module.DllBase;
count -= sizeof(HMODULE);
}
size += sizeof(HMODULE);
}
if (!needed)
{
SetLastError( ERROR_NOACCESS );
return FALSE;
}
*needed = size;
return ret == 0;
}
/***********************************************************************
* K32EnumProcessModulesEx (kernelbase.@)
*/
BOOL WINAPI K32EnumProcessModulesEx( HANDLE process, HMODULE *module, DWORD count,
DWORD *needed, DWORD filter )
{
FIXME( "(%p, %p, %d, %p, %d) semi-stub\n", process, module, count, needed, filter );
return K32EnumProcessModules( process, module, count, needed );
}
/***********************************************************************
* K32EnumProcesses (kernelbase.@)
*/
BOOL WINAPI K32EnumProcesses( DWORD *ids, DWORD count, DWORD *used )
{
SYSTEM_PROCESS_INFORMATION *spi;
ULONG size = 0x4000;
void *buf = NULL;
NTSTATUS status;
do
{
size *= 2;
HeapFree( GetProcessHeap(), 0, buf );
if (!(buf = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
status = NtQuerySystemInformation( SystemProcessInformation, buf, size, NULL );
} while (status == STATUS_INFO_LENGTH_MISMATCH);
if (!set_ntstatus( status ))
{
HeapFree( GetProcessHeap(), 0, buf );
return FALSE;
}
spi = buf;
for (*used = 0; count >= sizeof(DWORD); count -= sizeof(DWORD))
{
*ids++ = HandleToUlong( spi->UniqueProcessId );
*used += sizeof(DWORD);
if (spi->NextEntryOffset == 0) break;
spi = (SYSTEM_PROCESS_INFORMATION *)(((PCHAR)spi) + spi->NextEntryOffset);
}
HeapFree( GetProcessHeap(), 0, buf );
return TRUE;
}
/***********************************************************************
* K32GetDeviceDriverBaseNameA (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH K32GetDeviceDriverBaseNameA( void *image_base, char *name, DWORD size )
{
FIXME( "(%p, %p, %d): stub\n", image_base, name, size );
if (name && size) name[0] = 0;
return 0;
}
/***********************************************************************
* K32GetDeviceDriverBaseNameW (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH K32GetDeviceDriverBaseNameW( void *image_base, WCHAR *name, DWORD size )
{
FIXME( "(%p, %p, %d): stub\n", image_base, name, size );
if (name && size) name[0] = 0;
return 0;
}
/***********************************************************************
* K32GetDeviceDriverFileNameA (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH K32GetDeviceDriverFileNameA( void *image_base, char *name, DWORD size )
{
FIXME( "(%p, %p, %d): stub\n", image_base, name, size );
if (name && size) name[0] = 0;
return 0;
}
/***********************************************************************
* K32GetDeviceDriverFileNameW (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH K32GetDeviceDriverFileNameW( void *image_base, WCHAR *name, DWORD size )
{
FIXME( "(%p, %p, %d): stub\n", image_base, name, size );
if (name && size) name[0] = 0;
return 0;
}
/***********************************************************************
* K32GetMappedFileNameA (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH K32GetMappedFileNameA( HANDLE process, void *addr, char *name, DWORD size )
{
FIXME( "(%p, %p, %p, %d): stub\n", process, addr, name, size );
if (name && size) name[0] = 0;
return 0;
}
/***********************************************************************
* K32GetMappedFileNameW (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH K32GetMappedFileNameW( HANDLE process, void *addr, WCHAR *name, DWORD size )
{
FIXME( "(%p, %p, %p, %d): stub\n", process, addr, name, size );
if (name && size) name[0] = 0;
return 0;
}
/***********************************************************************
* K32GetModuleBaseNameA (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH K32GetModuleBaseNameA( HANDLE process, HMODULE module,
char *name, DWORD size )
{
WCHAR *name_w;
DWORD len, ret = 0;
if (!name || !size)
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
if (!(name_w = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR) * size ))) return 0;
len = K32GetModuleBaseNameW( process, module, name_w, size );
TRACE( "%d, %s\n", len, debugstr_w(name_w) );
if (len)
{
ret = WideCharToMultiByte( CP_ACP, 0, name_w, len, name, size, NULL, NULL );
if (ret < size) name[ret] = 0;
}
HeapFree( GetProcessHeap(), 0, name_w );
return ret;
}
/***********************************************************************
* K32GetModuleBaseNameW (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH K32GetModuleBaseNameW( HANDLE process, HMODULE module,
WCHAR *name, DWORD size )
{
BOOL wow64;
if (!IsWow64Process( process, &wow64 )) return 0;
if (is_win64 && wow64)
{
LDR_DATA_TABLE_ENTRY32 ldr_module32;
if (!get_ldr_module32(process, module, &ldr_module32)) return 0;
size = min( ldr_module32.BaseDllName.Length / sizeof(WCHAR), size );
if (!ReadProcessMemory( process, (void *)(DWORD_PTR)ldr_module32.BaseDllName.Buffer,
name, size * sizeof(WCHAR), NULL ))
return 0;
}
else
{
LDR_DATA_TABLE_ENTRY ldr_module;
if (!get_ldr_module( process, module, &ldr_module )) return 0;
size = min( ldr_module.BaseDllName.Length / sizeof(WCHAR), size );
if (!ReadProcessMemory( process, ldr_module.BaseDllName.Buffer,
name, size * sizeof(WCHAR), NULL ))
return 0;
}
name[size] = 0;
return size;
}
/***********************************************************************
* K32GetModuleFileNameExA (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH K32GetModuleFileNameExA( HANDLE process, HMODULE module,
char *name, DWORD size )
{
WCHAR *ptr;
DWORD len;
TRACE( "(process=%p, module=%p, %p, %d)\n", process, module, name, size );
if (!name || !size)
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
if (process == GetCurrentProcess())
{
len = GetModuleFileNameA( module, name, size );
name[size - 1] = '\0';
return len;
}
if (!(ptr = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return 0;
len = K32GetModuleFileNameExW( process, module, ptr, size );
if (!len)
{
name[0] = 0;
}
else
{
if (!WideCharToMultiByte( CP_ACP, 0, ptr, -1, name, size, NULL, NULL ))
{
name[size - 1] = 0;
len = size;
}
else if (len < size) len = strlen( name );
}
HeapFree( GetProcessHeap(), 0, ptr );
return len;
}
/***********************************************************************
* K32GetModuleFileNameExW (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH K32GetModuleFileNameExW( HANDLE process, HMODULE module,
WCHAR *name, DWORD size )
{
BOOL wow64;
DWORD len;
if (!size) return 0;
if (!IsWow64Process( process, &wow64 )) return 0;
if (is_win64 && wow64)
{
LDR_DATA_TABLE_ENTRY32 ldr_module32;
if (!get_ldr_module32( process, module, &ldr_module32 )) return 0;
len = ldr_module32.FullDllName.Length / sizeof(WCHAR);
if (!ReadProcessMemory( process, (void *)(DWORD_PTR)ldr_module32.FullDllName.Buffer,
name, min( len, size ) * sizeof(WCHAR), NULL ))
return 0;
}
else
{
LDR_DATA_TABLE_ENTRY ldr_module;
if (!get_ldr_module(process, module, &ldr_module)) return 0;
len = ldr_module.FullDllName.Length / sizeof(WCHAR);
if (!ReadProcessMemory( process, ldr_module.FullDllName.Buffer,
name, min( len, size ) * sizeof(WCHAR), NULL ))
return 0;
}
if (len < size)
{
name[len] = 0;
return len;
}
else
{
name[size - 1] = 0;
return size;
}
}
/***********************************************************************
* K32GetModuleInformation (kernelbase.@)
*/
BOOL WINAPI K32GetModuleInformation( HANDLE process, HMODULE module, MODULEINFO *modinfo, DWORD count )
{
BOOL wow64;
if (count < sizeof(MODULEINFO))
{
SetLastError( ERROR_INSUFFICIENT_BUFFER );
return FALSE;
}
if (!IsWow64Process( process, &wow64 )) return FALSE;
if (is_win64 && wow64)
{
LDR_DATA_TABLE_ENTRY32 ldr_module32;
if (!get_ldr_module32( process, module, &ldr_module32 )) return FALSE;
modinfo->lpBaseOfDll = (void *)(DWORD_PTR)ldr_module32.BaseAddress;
modinfo->SizeOfImage = ldr_module32.SizeOfImage;
modinfo->EntryPoint = (void *)(DWORD_PTR)ldr_module32.EntryPoint;
}
else
{
LDR_DATA_TABLE_ENTRY ldr_module;
if (!get_ldr_module( process, module, &ldr_module )) return FALSE;
modinfo->lpBaseOfDll = ldr_module.DllBase;
modinfo->SizeOfImage = ldr_module.SizeOfImage;
modinfo->EntryPoint = ldr_module.EntryPoint;
}
return TRUE;
}
/***********************************************************************
* K32GetPerformanceInfo (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH K32GetPerformanceInfo( PPERFORMANCE_INFORMATION info, DWORD size )
{
SYSTEM_PERFORMANCE_INFORMATION perf;
SYSTEM_BASIC_INFORMATION basic;
SYSTEM_PROCESS_INFORMATION *process, *spi;
DWORD info_size;
NTSTATUS status;
TRACE( "(%p, %d)\n", info, size );
if (size < sizeof(*info))
{
SetLastError( ERROR_BAD_LENGTH );
return FALSE;
}
status = NtQuerySystemInformation( SystemPerformanceInformation, &perf, sizeof(perf), NULL );
if (!set_ntstatus( status )) return FALSE;
status = NtQuerySystemInformation( SystemBasicInformation, &basic, sizeof(basic), NULL );
if (!set_ntstatus( status )) return FALSE;
info->cb = sizeof(*info);
info->CommitTotal = perf.TotalCommittedPages;
info->CommitLimit = perf.TotalCommitLimit;
info->CommitPeak = perf.PeakCommitment;
info->PhysicalTotal = basic.MmNumberOfPhysicalPages;
info->PhysicalAvailable = perf.AvailablePages;
info->SystemCache = 0;
info->KernelTotal = perf.PagedPoolUsage + perf.NonPagedPoolUsage;
info->KernelPaged = perf.PagedPoolUsage;
info->KernelNonpaged = perf.NonPagedPoolUsage;
info->PageSize = basic.PageSize;
/* fields from SYSTEM_PROCESS_INFORMATION */
NtQuerySystemInformation( SystemProcessInformation, NULL, 0, &info_size );
for (;;)
{
process = HeapAlloc( GetProcessHeap(), 0, info_size );
if (!process)
{
SetLastError( ERROR_OUTOFMEMORY );
return FALSE;
}
status = NtQuerySystemInformation( SystemProcessInformation, process, info_size, &info_size );
if (!status) break;
HeapFree( GetProcessHeap(), 0, process );
if (status != STATUS_INFO_LENGTH_MISMATCH)
{
SetLastError( RtlNtStatusToDosError( status ) );
return FALSE;
}
}
info->HandleCount = info->ProcessCount = info->ThreadCount = 0;
spi = process;
for (;;)
{
info->ProcessCount++;
info->HandleCount += spi->HandleCount;
info->ThreadCount += spi->dwThreadCount;
if (spi->NextEntryOffset == 0) break;
spi = (SYSTEM_PROCESS_INFORMATION *)((char *)spi + spi->NextEntryOffset);
}
HeapFree( GetProcessHeap(), 0, process );
return TRUE;
}
/***********************************************************************
* K32GetProcessImageFileNameA (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH K32GetProcessImageFileNameA( HANDLE process, char *file, DWORD size )
{
return QueryFullProcessImageNameA( process, PROCESS_NAME_NATIVE, file, &size ) ? size : 0;
}
/***********************************************************************
* K32GetProcessImageFileNameW (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH K32GetProcessImageFileNameW( HANDLE process, WCHAR *file, DWORD size )
{
return QueryFullProcessImageNameW( process, PROCESS_NAME_NATIVE, file, &size ) ? size : 0;
}
/***********************************************************************
* K32GetProcessMemoryInfo (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH K32GetProcessMemoryInfo( HANDLE process, PROCESS_MEMORY_COUNTERS *pmc,
DWORD count )
{
VM_COUNTERS vmc;
if (count < sizeof(PROCESS_MEMORY_COUNTERS))
{
SetLastError( ERROR_INSUFFICIENT_BUFFER );
return FALSE;
}
if (!set_ntstatus( NtQueryInformationProcess( process, ProcessVmCounters, &vmc, sizeof(vmc), NULL )))
return FALSE;
pmc->cb = sizeof(PROCESS_MEMORY_COUNTERS);
pmc->PageFaultCount = vmc.PageFaultCount;
pmc->PeakWorkingSetSize = vmc.PeakWorkingSetSize;
pmc->WorkingSetSize = vmc.WorkingSetSize;
pmc->QuotaPeakPagedPoolUsage = vmc.QuotaPeakPagedPoolUsage;
pmc->QuotaPagedPoolUsage = vmc.QuotaPagedPoolUsage;
pmc->QuotaPeakNonPagedPoolUsage = vmc.QuotaPeakNonPagedPoolUsage;
pmc->QuotaNonPagedPoolUsage = vmc.QuotaNonPagedPoolUsage;
pmc->PagefileUsage = vmc.PagefileUsage;
pmc->PeakPagefileUsage = vmc.PeakPagefileUsage;
return TRUE;
}
/***********************************************************************
* K32GetWsChanges (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH K32GetWsChanges( HANDLE process, PSAPI_WS_WATCH_INFORMATION *info, DWORD size )
{
TRACE( "(%p, %p, %d)\n", process, info, size );
return set_ntstatus( NtQueryInformationProcess( process, ProcessWorkingSetWatch, info, size, NULL ));
}
/***********************************************************************
* K32GetWsChangesEx (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH K32GetWsChangesEx( HANDLE process, PSAPI_WS_WATCH_INFORMATION_EX *info,
DWORD *size )
{
FIXME( "(%p, %p, %p)\n", process, info, size );
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
return FALSE;
}
/***********************************************************************
* K32InitializeProcessForWsWatch (kernelbase.@)
*/
BOOL WINAPI /* DECLSPEC_HOTPATCH */ K32InitializeProcessForWsWatch( HANDLE process )
{
FIXME( "(process=%p): stub\n", process );
return TRUE;
}
/***********************************************************************
* K32QueryWorkingSet (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH K32QueryWorkingSet( HANDLE process, void *buffer, DWORD size )
{
TRACE( "(%p, %p, %d)\n", process, buffer, size );
return set_ntstatus( NtQueryVirtualMemory( process, NULL, MemoryWorkingSetList, buffer, size, NULL ));
}
/***********************************************************************
* K32QueryWorkingSetEx (kernelbase.@)
*/
BOOL WINAPI K32QueryWorkingSetEx( HANDLE process, void *buffer, DWORD size )
{
TRACE( "(%p, %p, %d)\n", process, buffer, size );
return set_ntstatus( NtQueryVirtualMemory( process, NULL, MemoryWorkingSetExInformation,
buffer, size, NULL ));
}
/******************************************************************
* QueryFullProcessImageNameA (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH QueryFullProcessImageNameA( HANDLE process, DWORD flags,
char *name, DWORD *size )
{
BOOL ret;
DWORD sizeW = *size;
WCHAR *nameW = HeapAlloc( GetProcessHeap(), 0, *size * sizeof(WCHAR) );
ret = QueryFullProcessImageNameW( process, flags, nameW, &sizeW );
if (ret) ret = (WideCharToMultiByte( CP_ACP, 0, nameW, -1, name, *size, NULL, NULL) > 0);
if (ret) *size = strlen( name );
HeapFree( GetProcessHeap(), 0, nameW );
return ret;
}
/******************************************************************
* QueryFullProcessImageNameW (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH QueryFullProcessImageNameW( HANDLE process, DWORD flags,
WCHAR *name, DWORD *size )
{
BYTE buffer[sizeof(UNICODE_STRING) + MAX_PATH*sizeof(WCHAR)]; /* this buffer should be enough */
UNICODE_STRING *dynamic_buffer = NULL;
UNICODE_STRING *result = NULL;
NTSTATUS status;
DWORD needed;
/* FIXME: On Windows, ProcessImageFileName return an NT path. In Wine it
* is a DOS path and we depend on this. */
status = NtQueryInformationProcess( process, ProcessImageFileName, buffer,
sizeof(buffer) - sizeof(WCHAR), &needed );
if (status == STATUS_INFO_LENGTH_MISMATCH)
{
dynamic_buffer = HeapAlloc( GetProcessHeap(), 0, needed + sizeof(WCHAR) );
status = NtQueryInformationProcess( process, ProcessImageFileName, dynamic_buffer,
needed, &needed );
result = dynamic_buffer;
}
else
result = (UNICODE_STRING *)buffer;
if (status) goto cleanup;
if (flags & PROCESS_NAME_NATIVE)
{
WCHAR drive[3];
WCHAR device[1024];
DWORD ntlen, devlen;
if (result->Buffer[1] != ':' || result->Buffer[0] < 'A' || result->Buffer[0] > 'Z')
{
/* We cannot convert it to an NT device path so fail */
status = STATUS_NO_SUCH_DEVICE;
goto cleanup;
}
/* Find this drive's NT device path */
drive[0] = result->Buffer[0];
drive[1] = ':';
drive[2] = 0;
if (!QueryDosDeviceW(drive, device, ARRAY_SIZE(device)))
{
status = STATUS_NO_SUCH_DEVICE;
goto cleanup;
}
devlen = lstrlenW(device);
ntlen = devlen + (result->Length/sizeof(WCHAR) - 2);
if (ntlen + 1 > *size)
{
status = STATUS_BUFFER_TOO_SMALL;
goto cleanup;
}
*size = ntlen;
memcpy( name, device, devlen * sizeof(*device) );
memcpy( name + devlen, result->Buffer + 2, result->Length - 2 * sizeof(WCHAR) );
name[*size] = 0;
TRACE( "NT path: %s\n", debugstr_w(name) );
}
else
{
if (result->Length/sizeof(WCHAR) + 1 > *size)
{
status = STATUS_BUFFER_TOO_SMALL;
goto cleanup;
}
*size = result->Length/sizeof(WCHAR);
memcpy( name, result->Buffer, result->Length );
name[*size] = 0;
}
cleanup:
HeapFree( GetProcessHeap(), 0, dynamic_buffer );
return set_ntstatus( status );
}

View File

@ -885,33 +885,33 @@
@ stdcall IsWellKnownSid(ptr long)
@ stdcall IsWow64Process(ptr ptr)
# @ stub IsWow64Process2
@ stdcall K32EmptyWorkingSet(long) kernel32.K32EmptyWorkingSet
@ stdcall K32EnumDeviceDrivers(ptr long ptr) kernel32.K32EnumDeviceDrivers
@ stdcall K32EnumPageFilesA(ptr ptr) kernel32.K32EnumPageFilesA
@ stdcall K32EnumPageFilesW(ptr ptr) kernel32.K32EnumPageFilesW
@ stdcall K32EnumProcessModules(long ptr long ptr) kernel32.K32EnumProcessModules
@ stdcall K32EnumProcessModulesEx(long ptr long ptr long) kernel32.K32EnumProcessModulesEx
@ stdcall K32EnumProcesses(ptr long ptr) kernel32.K32EnumProcesses
@ stdcall K32GetDeviceDriverBaseNameA(ptr ptr long) kernel32.K32GetDeviceDriverBaseNameA
@ stdcall K32GetDeviceDriverBaseNameW(ptr ptr long) kernel32.K32GetDeviceDriverBaseNameW
@ stdcall K32GetDeviceDriverFileNameA(ptr ptr long) kernel32.K32GetDeviceDriverFileNameA
@ stdcall K32GetDeviceDriverFileNameW(ptr ptr long) kernel32.K32GetDeviceDriverFileNameW
@ stdcall K32GetMappedFileNameA(long ptr ptr long) kernel32.K32GetMappedFileNameA
@ stdcall K32GetMappedFileNameW(long ptr ptr long) kernel32.K32GetMappedFileNameW
@ stdcall K32GetModuleBaseNameA(long long ptr long) kernel32.K32GetModuleBaseNameA
@ stdcall K32GetModuleBaseNameW(long long ptr long) kernel32.K32GetModuleBaseNameW
@ stdcall K32GetModuleFileNameExA(long long ptr long) kernel32.K32GetModuleFileNameExA
@ stdcall K32GetModuleFileNameExW(long long ptr long) kernel32.K32GetModuleFileNameExW
@ stdcall K32GetModuleInformation(long long ptr long) kernel32.K32GetModuleInformation
@ stdcall K32GetPerformanceInfo(ptr long) kernel32.K32GetPerformanceInfo
@ stdcall K32GetProcessImageFileNameA(long ptr long) kernel32.K32GetProcessImageFileNameA
@ stdcall K32GetProcessImageFileNameW(long ptr long) kernel32.K32GetProcessImageFileNameW
@ stdcall K32GetProcessMemoryInfo(long ptr long) kernel32.K32GetProcessMemoryInfo
@ stdcall K32GetWsChanges(long ptr long) kernel32.K32GetWsChanges
@ stdcall K32GetWsChangesEx(long ptr ptr) kernel32.K32GetWsChangesEx
@ stdcall K32InitializeProcessForWsWatch(long) kernel32.K32InitializeProcessForWsWatch
@ stdcall K32QueryWorkingSet(long ptr long) kernel32.K32QueryWorkingSet
@ stdcall K32QueryWorkingSetEx(long ptr long) kernel32.K32QueryWorkingSetEx
@ stdcall K32EmptyWorkingSet(long)
@ stdcall K32EnumDeviceDrivers(ptr long ptr)
@ stdcall K32EnumPageFilesA(ptr ptr)
@ stdcall K32EnumPageFilesW(ptr ptr)
@ stdcall K32EnumProcessModules(long ptr long ptr)
@ stdcall K32EnumProcessModulesEx(long ptr long ptr long)
@ stdcall K32EnumProcesses(ptr long ptr)
@ stdcall K32GetDeviceDriverBaseNameA(ptr ptr long)
@ stdcall K32GetDeviceDriverBaseNameW(ptr ptr long)
@ stdcall K32GetDeviceDriverFileNameA(ptr ptr long)
@ stdcall K32GetDeviceDriverFileNameW(ptr ptr long)
@ stdcall K32GetMappedFileNameA(long ptr ptr long)
@ stdcall K32GetMappedFileNameW(long ptr ptr long)
@ stdcall K32GetModuleBaseNameA(long long ptr long)
@ 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 K32GetPerformanceInfo(ptr long)
@ stdcall K32GetProcessImageFileNameA(long ptr long)
@ stdcall K32GetProcessImageFileNameW(long ptr long)
@ stdcall K32GetProcessMemoryInfo(long ptr long)
@ stdcall K32GetWsChanges(long ptr long)
@ stdcall K32GetWsChangesEx(long ptr ptr)
@ stdcall K32InitializeProcessForWsWatch(long)
@ stdcall K32QueryWorkingSet(long ptr long)
@ stdcall K32QueryWorkingSetEx(long ptr long)
@ stub KernelBaseGetGlobalData
@ stdcall LCIDToLocaleName(long ptr long long)
@ stdcall LCMapStringA(long long str long ptr long)
@ -1195,8 +1195,8 @@
@ stdcall QueryActCtxW(long ptr ptr long ptr long ptr)
@ stdcall QueryDepthSList(ptr) ntdll.RtlQueryDepthSList
@ stdcall QueryDosDeviceW(wstr ptr long)
@ stdcall QueryFullProcessImageNameA(ptr long ptr ptr) kernel32.QueryFullProcessImageNameA
@ stdcall QueryFullProcessImageNameW(ptr long ptr ptr) kernel32.QueryFullProcessImageNameW
@ stdcall QueryFullProcessImageNameA(ptr long ptr ptr)
@ stdcall QueryFullProcessImageNameW(ptr long ptr ptr)
# @ stub QueryIdleProcessorCycleTime
# @ stub QueryIdleProcessorCycleTimeEx
# @ stub QueryInterruptTime