ReactOS 0.4.15-dev-7674-gc0b4db1
psapi.c File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winnls.h>
#include <ndk/exfuncs.h>
#include <ndk/mmfuncs.h>
#include <ndk/psfuncs.h>
#include <ndk/rtlfuncs.h>
#include <psapi.h>
#include <pseh/pseh2.h>
#include <debug.h>
Include dependency graph for psapi.c:

Go to the source code of this file.

Classes

struct  _INTERNAL_ENUM_PAGE_FILES_CONTEXT
 

Macros

#define WIN32_NO_STATUS
 
#define NTOS_MODE_USER
 
#define NDEBUG
 
#define MAX_MODULES   0x2710
 
#define INIT_MEMORY_SIZE   0x1000
 

Typedefs

typedef struct _INTERNAL_ENUM_PAGE_FILES_CONTEXT INTERNAL_ENUM_PAGE_FILES_CONTEXT
 
typedef struct _INTERNAL_ENUM_PAGE_FILES_CONTEXTPINTERNAL_ENUM_PAGE_FILES_CONTEXT
 

Functions

static BOOL NTAPI FindDeviceDriver (IN PVOID ImageBase, OUT PRTL_PROCESS_MODULE_INFORMATION MatchingModule)
 
static BOOL NTAPI FindModule (IN HANDLE hProcess, IN HMODULE hModule OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY Module)
 
static BOOL CALLBACK CallBackConvertToAscii (LPVOID pContext, PENUM_PAGE_FILE_INFORMATION pPageFileInfo, LPCWSTR lpFilename)
 
static VOID NTAPI PsParseCommandLine (VOID)
 
static VOID NTAPI PsInitializeAndStartProfile (VOID)
 
static VOID NTAPI PsStopAndAnalyzeProfile (VOID)
 
BOOLEAN WINAPI DllMain (HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved)
 
BOOL WINAPI EmptyWorkingSet (HANDLE hProcess)
 
BOOL WINAPI EnumDeviceDrivers (LPVOID *lpImageBase, DWORD cb, LPDWORD lpcbNeeded)
 
BOOL WINAPI EnumProcesses (DWORD *lpidProcess, DWORD cb, LPDWORD lpcbNeeded)
 
BOOL WINAPI EnumProcessModules (HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded)
 
DWORD WINAPI GetDeviceDriverBaseNameA (LPVOID ImageBase, LPSTR lpBaseName, DWORD nSize)
 
DWORD WINAPI GetDeviceDriverFileNameA (LPVOID ImageBase, LPSTR lpFilename, DWORD nSize)
 
DWORD WINAPI GetDeviceDriverBaseNameW (LPVOID ImageBase, LPWSTR lpBaseName, DWORD nSize)
 
DWORD WINAPI GetDeviceDriverFileNameW (LPVOID ImageBase, LPWSTR lpFilename, DWORD nSize)
 
DWORD WINAPI GetMappedFileNameA (HANDLE hProcess, LPVOID lpv, LPSTR lpFilename, DWORD nSize)
 
DWORD WINAPI GetMappedFileNameW (HANDLE hProcess, LPVOID lpv, LPWSTR lpFilename, DWORD nSize)
 
DWORD WINAPI GetModuleBaseNameA (HANDLE hProcess, HMODULE hModule, LPSTR lpBaseName, DWORD nSize)
 
DWORD WINAPI GetModuleBaseNameW (HANDLE hProcess, HMODULE hModule, LPWSTR lpBaseName, DWORD nSize)
 
DWORD WINAPI GetModuleFileNameExA (HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize)
 
DWORD WINAPI GetModuleFileNameExW (HANDLE hProcess, HMODULE hModule, LPWSTR lpFilename, DWORD nSize)
 
BOOL WINAPI GetModuleInformation (HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb)
 
BOOL WINAPI InitializeProcessForWsWatch (HANDLE hProcess)
 
BOOL WINAPI GetWsChanges (HANDLE hProcess, PPSAPI_WS_WATCH_INFORMATION lpWatchInfo, DWORD cb)
 
DWORD WINAPI GetProcessImageFileNameW (HANDLE hProcess, LPWSTR lpImageFileName, DWORD nSize)
 
DWORD WINAPI GetProcessImageFileNameA (HANDLE hProcess, LPSTR lpImageFileName, DWORD nSize)
 
BOOL WINAPI EnumPageFilesA (PENUM_PAGE_FILE_CALLBACKA pCallbackRoutine, LPVOID lpContext)
 
BOOL WINAPI EnumPageFilesW (PENUM_PAGE_FILE_CALLBACKW pCallbackRoutine, LPVOID lpContext)
 
BOOL WINAPI GetPerformanceInfo (PPERFORMANCE_INFORMATION pPerformanceInformation, DWORD cb)
 
BOOL WINAPI GetProcessMemoryInfo (HANDLE Process, PPROCESS_MEMORY_COUNTERS ppsmemCounters, DWORD cb)
 
BOOL WINAPI QueryWorkingSet (HANDLE hProcess, PVOID pv, DWORD cb)
 
BOOL WINAPI QueryWorkingSetEx (IN HANDLE hProcess, IN OUT PVOID pv, IN DWORD cb)
 

Macro Definition Documentation

◆ INIT_MEMORY_SIZE

#define INIT_MEMORY_SIZE   0x1000

Definition at line 34 of file psapi.c.

◆ MAX_MODULES

#define MAX_MODULES   0x2710

Definition at line 33 of file psapi.c.

◆ NDEBUG

#define NDEBUG

Definition at line 30 of file psapi.c.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 20 of file psapi.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 16 of file psapi.c.

Typedef Documentation

◆ INTERNAL_ENUM_PAGE_FILES_CONTEXT

◆ PINTERNAL_ENUM_PAGE_FILES_CONTEXT

Function Documentation

◆ CallBackConvertToAscii()

static BOOL CALLBACK CallBackConvertToAscii ( LPVOID  pContext,
PENUM_PAGE_FILE_INFORMATION  pPageFileInfo,
LPCWSTR  lpFilename 
)
static

Definition at line 213 of file psapi.c.

216{
217 BOOL Ret;
218 SIZE_T Len;
219 LPSTR AnsiFileName;
221
222 Len = wcslen(lpFilename);
223
224 /* Alloc space for the ANSI string */
225 AnsiFileName = LocalAlloc(LMEM_FIXED, (Len * sizeof(CHAR)) + sizeof(ANSI_NULL));
226 if (AnsiFileName == NULL)
227 {
229 return FALSE;
230 }
231
232 /* Convert string to ANSI */
233 if (WideCharToMultiByte(CP_ACP, 0, lpFilename, -1, AnsiFileName, (Len * sizeof(CHAR)) + sizeof(ANSI_NULL), NULL, NULL) == 0)
234 {
235 Context->dwErrCode = GetLastError();
236 LocalFree(AnsiFileName);
237 return FALSE;
238 }
239
240 /* And finally call "real" callback */
241 Ret = Context->pCallbackRoutine(Context->lpContext, pPageFileInfo, AnsiFileName);
242 LocalFree(AnsiFileName);
243
244 return Ret;
245}
#define Len
Definition: deflate.h:82
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
struct _INTERNAL_ENUM_PAGE_FILES_CONTEXT * PINTERNAL_ENUM_PAGE_FILES_CONTEXT
unsigned int BOOL
Definition: ntddk_ex.h:94
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define ANSI_NULL
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define LMEM_FIXED
Definition: winbase.h:368
char * LPSTR
Definition: xmlstorage.h:182
char CHAR
Definition: xmlstorage.h:175

Referenced by EnumPageFilesA().

◆ DllMain()

BOOLEAN WINAPI DllMain ( HINSTANCE  hDllHandle,
DWORD  nReason,
LPVOID  Reserved 
)

Definition at line 281 of file psapi.c.

284{
285 switch(nReason)
286 {
288 DisableThreadLibraryCalls(hDllHandle);
289 if (NtCurrentPeb()->ProcessParameters->Flags & RTL_USER_PROCESS_PARAMETERS_PROFILE_USER)
290 {
293 }
294 break;
295
297 if (NtCurrentPeb()->ProcessParameters->Flags & RTL_USER_PROCESS_PARAMETERS_PROFILE_USER)
298 {
300 }
301 break;
302 }
303
304 return TRUE;
305}
#define NtCurrentPeb()
Definition: FLS.c:22
#define TRUE
Definition: types.h:120
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
static VOID NTAPI PsStopAndAnalyzeProfile(VOID)
Definition: psapi.c:269
static VOID NTAPI PsParseCommandLine(VOID)
Definition: psapi.c:251
static VOID NTAPI PsInitializeAndStartProfile(VOID)
Definition: psapi.c:260
#define RTL_USER_PROCESS_PARAMETERS_PROFILE_USER
Definition: rtltypes.h:42

◆ EmptyWorkingSet()

BOOL WINAPI EmptyWorkingSet ( HANDLE  hProcess)

Definition at line 313 of file psapi.c.

314{
315 SYSTEM_INFO SystemInfo;
316 QUOTA_LIMITS QuotaLimits;
318
319 GetSystemInfo(&SystemInfo);
320
321 /* Query the working set */
324 &QuotaLimits,
325 sizeof(QuotaLimits),
326 NULL);
327
328 if (!NT_SUCCESS(Status))
329 {
331 return FALSE;
332 }
333
334 /* Empty the working set */
335 QuotaLimits.MinimumWorkingSetSize = -1;
336 QuotaLimits.MaximumWorkingSetSize = -1;
337
338 /* Set the working set */
341 &QuotaLimits,
342 sizeof(QuotaLimits));
344 {
346 return FALSE;
347 }
348
349 return TRUE;
350}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:752
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:143
Status
Definition: gdiplustypes.h:25
@ ProcessQuotaLimits
Definition: winternl.h:857
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1105
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
INT64 MaximumWorkingSetSize
Definition: lsa.idl:290
INT64 MinimumWorkingSetSize
Definition: lsa.idl:289

Referenced by test_ws_functions().

◆ EnumDeviceDrivers()

BOOL WINAPI EnumDeviceDrivers ( LPVOID lpImageBase,
DWORD  cb,
LPDWORD  lpcbNeeded 
)

Definition at line 358 of file psapi.c.

361{
365 /* By default, to prevent too many reallocations, we already make room for 4 modules */
367
368 do
369 {
370 /* Allocate a buffer to hold modules information */
372 if (!Information)
373 {
375 return FALSE;
376 }
377
378 /* Query information */
380 /* In case of an error */
381 if (!NT_SUCCESS(Status))
382 {
383 /* Save the amount of output modules */
384 NewSize = Information->NumberOfModules;
385 /* And free buffer */
387
388 /* If it was not a length mismatch (ie, buffer too small), just leave */
390 {
392 return FALSE;
393 }
394
395 /* Compute new size length */
396 ASSERT(Size >= sizeof(RTL_PROCESS_MODULES));
398 NewSize += sizeof(ULONG);
400 /* Check whether it is really bigger - otherwise, leave */
401 if (NewSize < Size)
402 {
405 return FALSE;
406 }
407
408 /* Loop again with that new buffer */
409 Size = NewSize;
410 continue;
411 }
412
413 /* End of allocation loop */
414 break;
415 } while (TRUE);
416
418 {
419 for (Count = 0; Count < Information->NumberOfModules && Count < cb / sizeof(LPVOID); ++Count)
420 {
421 lpImageBase[Count] = Information->Modules[Count].ImageBase;
422 }
423
424 *lpcbNeeded = Information->NumberOfModules * sizeof(LPVOID);
425 }
427 {
429 _SEH2_YIELD(return FALSE);
430 }
431 _SEH2_END;
432
433 return TRUE;
434}
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
unsigned long DWORD
Definition: ntddk_ex.h:95
@ SystemModuleInformation
Definition: ntddk_ex.h:22
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define ASSERT(a)
Definition: mode.c:44
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
struct _RTL_PROCESS_MODULES RTL_PROCESS_MODULES
struct _RTL_PROCESS_MODULE_INFORMATION RTL_PROCESS_MODULE_INFORMATION
int Count
Definition: noreturn.cpp:7
#define LPVOID
Definition: nt_native.h:45
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049
#define ERROR_NO_SYSTEM_RESOURCES
Definition: winerror.h:931

◆ EnumPageFilesA()

BOOL WINAPI EnumPageFilesA ( PENUM_PAGE_FILE_CALLBACKA  pCallbackRoutine,
LPVOID  lpContext 
)

Definition at line 1270 of file psapi.c.

1272{
1273 BOOL Ret;
1275
1276 Context.dwErrCode = ERROR_SUCCESS;
1277 Context.lpContext = lpContext;
1278 Context.pCallbackRoutine = pCallbackRoutine;
1279
1280 /* Call W with our own callback for W -> A conversions */
1282 /* If we succeed but we have error code, fail and set error */
1283 if (Ret && Context.dwErrCode != ERROR_SUCCESS)
1284 {
1285 Ret = FALSE;
1286 SetLastError(Context.dwErrCode);
1287 }
1288
1289 return Ret;
1290}
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI EnumPageFilesW(PENUM_PAGE_FILE_CALLBACKW pCallbackRoutine, LPVOID lpContext)
Definition: psapi.c:1298
static BOOL CALLBACK CallBackConvertToAscii(LPVOID pContext, PENUM_PAGE_FILE_INFORMATION pPageFileInfo, LPCWSTR lpFilename)
Definition: psapi.c:213

◆ EnumPageFilesW()

BOOL WINAPI EnumPageFilesW ( PENUM_PAGE_FILE_CALLBACKW  pCallbackRoutine,
LPVOID  lpContext 
)

Definition at line 1298 of file psapi.c.

1300{
1301 PWSTR Colon;
1303 DWORD Size = INIT_MEMORY_SIZE, Needed;
1305 PSYSTEM_PAGEFILE_INFORMATION PageFileInfoArray, PageFileInfo;
1306
1307 /* First loop till we have all the information about page files */
1308 do
1309 {
1310 PageFileInfoArray = LocalAlloc(LMEM_FIXED, Size);
1311 if (PageFileInfoArray == NULL)
1312 {
1314 return FALSE;
1315 }
1316
1317 Status = NtQuerySystemInformation(SystemPageFileInformation, PageFileInfoArray, Size, &Needed);
1318 if (NT_SUCCESS(Status))
1319 {
1320 break;
1321 }
1322
1323 LocalFree(PageFileInfoArray);
1324
1325 /* In case we have unexpected status, quit */
1327 {
1329 return FALSE;
1330 }
1331
1332 /* If needed size is smaller than actual size, guess it's something to add to our current size */
1333 if (Needed <= Size)
1334 {
1335 Size += Needed;
1336 }
1337 /* Otherwise, take it as size to allocate */
1338 else
1339 {
1340 Size = Needed;
1341 }
1342 }
1343 while (TRUE);
1344
1345 /* Start browsing all our entries */
1346 PageFileInfo = PageFileInfoArray;
1347 do
1348 {
1349 /* Ensure we really have an entry */
1350 if (Needed < sizeof(SYSTEM_PAGEFILE_INFORMATION))
1351 {
1352 break;
1353 }
1354
1355 /* Prepare structure to hand to the user */
1356 Information.Reserved = 0;
1357 Information.cb = sizeof(Information);
1358 Information.TotalSize = PageFileInfo->TotalSize;
1359 Information.TotalInUse = PageFileInfo->TotalInUse;
1360 Information.PeakUsage = PageFileInfo->PeakUsage;
1361
1362 /* Search for colon */
1363 Colon = wcschr(PageFileInfo->PageFileName.Buffer, L':');
1364 /* If it's found and not at the begin of the string */
1365 if (Colon != 0 && Colon != PageFileInfo->PageFileName.Buffer)
1366 {
1367 /* We can call the user callback routine with the colon */
1368 --Colon;
1369 pCallbackRoutine(lpContext, &Information, Colon);
1370 }
1371
1372 /* If no next entry, then, it's over */
1373 if (PageFileInfo->NextEntryOffset == 0 || PageFileInfo->NextEntryOffset > Needed)
1374 {
1375 break;
1376 }
1377
1378 /* Jump to next entry while keeping accurate bytes left count */
1379 Needed -= PageFileInfo->NextEntryOffset;
1380 PageFileInfo = (PSYSTEM_PAGEFILE_INFORMATION)((ULONG_PTR)PageFileInfo + PageFileInfo->NextEntryOffset);
1381 }
1382 while (TRUE);
1383
1384 LocalFree(PageFileInfoArray);
1385 return TRUE;
1386}
@ Colon
Definition: asmpp.cpp:43
#define wcschr
Definition: compat.h:17
#define INIT_MEMORY_SIZE
Definition: psapi.c:34
@ SystemPageFileInformation
Definition: ntddk_ex.h:29
struct _SYSTEM_PAGEFILE_INFORMATION * PSYSTEM_PAGEFILE_INFORMATION
#define L(x)
Definition: ntvdm.h:50
UNICODE_STRING PageFileName
Definition: extypes.h:1075
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by EnumPageFilesA().

◆ EnumProcesses()

BOOL WINAPI EnumProcesses ( DWORD lpidProcess,
DWORD  cb,
LPDWORD  lpcbNeeded 
)

Definition at line 442 of file psapi.c.

445{
449 PSYSTEM_PROCESS_INFORMATION ProcInfoArray;
450
451 /* First of all, query all the processes */
452 do
453 {
454 ProcInfoArray = LocalAlloc(LMEM_FIXED, Size);
455 if (ProcInfoArray == NULL)
456 {
457 return FALSE;
458 }
459
462 {
463 LocalFree(ProcInfoArray);
464 Size += MAXSHORT;
465 continue;
466 }
467
468 break;
469 }
470 while (TRUE);
471
472 if (!NT_SUCCESS(Status))
473 {
474 LocalFree(ProcInfoArray);
476 return FALSE;
477 }
478
479 /* Then, loop to output data */
480 Count = 0;
481 ProcInfo = ProcInfoArray;
482
484 {
485 do
486 {
487 /* It may sound weird, but actually MS only updated Count on
488 * successful write. So, it cannot measure the amount of space needed!
489 * This is really tricky.
490 */
491 if (Count < cb / sizeof(DWORD))
492 {
493 lpidProcess[Count] = HandleToUlong(ProcInfo->UniqueProcessId);
494 Count++;
495 }
496
497 if (ProcInfo->NextEntryOffset == 0)
498 {
499 break;
500 }
501
502 ProcInfo = (PSYSTEM_PROCESS_INFORMATION)((ULONG_PTR)ProcInfo + ProcInfo->NextEntryOffset);
503 }
504 while (TRUE);
505
506 *lpcbNeeded = Count * sizeof(DWORD);
507 }
509 {
511 LocalFree(ProcInfoArray);
512 _SEH2_YIELD(return FALSE);
513 }
514 _SEH2_END;
515
516 LocalFree(ProcInfoArray);
517 return TRUE;
518}
#define HandleToUlong(h)
Definition: basetsd.h:79
@ SystemProcessInformation
Definition: ntddk_ex.h:16
struct _SYSTEM_PROCESS_INFORMATION * PSYSTEM_PROCESS_INFORMATION
#define DWORD
Definition: nt_native.h:44
#define MAXSHORT
Definition: umtypes.h:114

Referenced by enumerate_processes(), ProcessList_Update(), and test_EnumProcesses().

◆ EnumProcessModules()

BOOL WINAPI EnumProcessModules ( HANDLE  hProcess,
HMODULE lphModule,
DWORD  cb,
LPDWORD  lpcbNeeded 
)

Definition at line 526 of file psapi.c.

530{
532 DWORD NbOfModules, Count;
533 PPEB_LDR_DATA LoaderData;
534 PLIST_ENTRY ListHead, ListEntry;
536 LDR_DATA_TABLE_ENTRY CurrentModule;
537
538 /* Query the process information to get its PEB address */
539 Status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &ProcInfo, sizeof(ProcInfo), NULL);
540 if (!NT_SUCCESS(Status))
541 {
543 return FALSE;
544 }
545
546 if (ProcInfo.PebBaseAddress == NULL)
547 {
549 return FALSE;
550 }
551
552 /* Read loader data address from PEB */
553 if (!ReadProcessMemory(hProcess, &ProcInfo.PebBaseAddress->Ldr, &LoaderData, sizeof(LoaderData), NULL))
554 {
555 return FALSE;
556 }
557
558 /* Store list head address */
559 ListHead = &LoaderData->InLoadOrderModuleList;
560
561 /* Read first element in the modules list */
562 if (!ReadProcessMemory(hProcess, &LoaderData->InLoadOrderModuleList.Flink, &ListEntry, sizeof(ListEntry), NULL))
563 {
564 return FALSE;
565 }
566
567 NbOfModules = cb / sizeof(HMODULE);
568 Count = 0;
569
570 /* Loop on the modules */
571 while (ListEntry != ListHead)
572 {
573 /* Load module data */
575 CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks),
576 &CurrentModule,
577 sizeof(CurrentModule),
578 NULL))
579 {
580 return FALSE;
581 }
582
583 /* Check if we can output module, do it if so */
584 if (Count < NbOfModules)
585 {
587 {
588 lphModule[Count] = CurrentModule.DllBase;
589 }
591 {
593 _SEH2_YIELD(return FALSE);
594 }
595 _SEH2_END;
596 }
597
598 ++Count;
599 if (Count > MAX_MODULES)
600 {
602 return FALSE;
603 }
604
605 /* Get to next listed module */
606 ListEntry = CurrentModule.InLoadOrderLinks.Flink;
607 }
608
610 {
611 *lpcbNeeded = Count * sizeof(HMODULE);
612 }
614 {
616 _SEH2_YIELD(return FALSE);
617 }
618 _SEH2_END;
619
620 return TRUE;
621}
#define ReadProcessMemory(a, b, c, d, e)
Definition: compat.h:758
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define MAX_MODULES
Definition: psapi.c:33
@ ProcessBasicInformation
Definition: winternl.h:394
#define STATUS_PARTIAL_COPY
Definition: ntstatus.h:193
Definition: btrfs_drv.h:1876
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:138
PVOID DllBase
Definition: btrfs_drv.h:1880
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY InLoadOrderModuleList
Definition: ldrtypes.h:120
PPEB_LDR_DATA Ldr
Definition: btrfs_drv.h:1912
HANDLE HMODULE
Definition: typedefs.h:77
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by debug_target_init_modules_info(), DllMain(), EnumerateLoadedModulesW64(), get_process_name_from_pid(), and test_EnumProcessModules().

◆ FindDeviceDriver()

static BOOL NTAPI FindDeviceDriver ( IN PVOID  ImageBase,
OUT PRTL_PROCESS_MODULE_INFORMATION  MatchingModule 
)
static

Definition at line 42 of file psapi.c.

44{
49 /* By default, to prevent too many reallocations, we already make room for 4 modules */
51
52 while (TRUE)
53 {
54 /* Allocate a buffer to hold modules information */
56 if (!Information)
57 {
59 return FALSE;
60 }
61
62 /* Query information */
64 if (!NT_SUCCESS(Status))
65 {
66 /* Free the current buffer */
68
69 /* If it was not a length mismatch (ie, buffer too small), just leave */
71 {
73 return FALSE;
74 }
75
76 /* Try again with the required size */
78 continue;
79 }
80
81 /* No modules returned? Leave */
82 if (Information->NumberOfModules == 0)
83 {
84 break;
85 }
86
87 /* Try to find which module matches the base address given */
88 for (i = 0; i < Information->NumberOfModules; ++i)
89 {
90 Module = Information->Modules[i];
91 if (Module.ImageBase == ImageBase)
92 {
93 /* Copy the matching module and leave */
94 memcpy(MatchingModule, &Module, sizeof(Module));
96 return TRUE;
97 }
98 }
99
100 /* If we arrive here, it means we were not able to find matching base address */
101 break;
102 }
103
104 /* Release and leave */
107
108 return FALSE;
109}
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 memcpy(s1, s2, n)
Definition: mkisofs.h:878
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID _Out_ PULONG RequiredSize
Definition: wdfdevice.h:4439

Referenced by GetDeviceDriverBaseNameA(), and GetDeviceDriverFileNameA().

◆ FindModule()

static BOOL NTAPI FindModule ( IN HANDLE  hProcess,
IN HMODULE hModule  OPTIONAL,
OUT PLDR_DATA_TABLE_ENTRY  Module 
)
static

Definition at line 115 of file psapi.c.

118{
119 DWORD Count;
121 PPEB_LDR_DATA LoaderData;
122 PLIST_ENTRY ListHead, ListEntry;
124
125 /* Query the process information to get its PEB address */
126 Status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &ProcInfo, sizeof(ProcInfo), NULL);
127 if (!NT_SUCCESS(Status))
128 {
130 return FALSE;
131 }
132
133 /* If no module was provided, get base as module */
134 if (hModule == NULL)
135 {
137 {
138 return FALSE;
139 }
140 }
141
142 /* Read loader data address from PEB */
143 if (!ReadProcessMemory(hProcess, &ProcInfo.PebBaseAddress->Ldr, &LoaderData, sizeof(LoaderData), NULL))
144 {
145 return FALSE;
146 }
147
148 if (LoaderData == NULL)
149 {
151 return FALSE;
152 }
153
154 /* Store list head address */
155 ListHead = &(LoaderData->InMemoryOrderModuleList);
156
157 /* Read first element in the modules list */
159 &(LoaderData->InMemoryOrderModuleList.Flink),
160 &ListEntry,
161 sizeof(ListEntry),
162 NULL))
163 {
164 return FALSE;
165 }
166
167 Count = 0;
168
169 /* Loop on the modules */
170 while (ListEntry != ListHead)
171 {
172 /* Load module data */
174 CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks),
175 Module,
176 sizeof(*Module),
177 NULL))
178 {
179 return FALSE;
180 }
181
182 /* Does that match the module we're looking for? */
183 if (Module->DllBase == hModule)
184 {
185 return TRUE;
186 }
187
188 ++Count;
189 if (Count > MAX_MODULES)
190 {
191 break;
192 }
193
194 /* Get to next listed module */
195 ListEntry = Module->InMemoryOrderLinks.Flink;
196 }
197
199 return FALSE;
200}
HMODULE hModule
Definition: animate.c:44
LIST_ENTRY InMemoryOrderModuleList
Definition: btrfs_drv.h:1895
PVOID ImageBaseAddress
Definition: ntddk_ex.h:245

Referenced by GetModuleBaseNameW(), GetModuleFileNameExW(), and GetModuleInformation().

◆ GetDeviceDriverBaseNameA()

DWORD WINAPI GetDeviceDriverBaseNameA ( LPVOID  ImageBase,
LPSTR  lpBaseName,
DWORD  nSize 
)

Definition at line 629 of file psapi.c.

632{
633 SIZE_T Len, LenWithNull;
635
636 /* Get the associated device driver to the base address */
637 if (!FindDeviceDriver(ImageBase, &Module))
638 {
639 return 0;
640 }
641
642 /* And copy as much as possible to output buffer.
643 * Try to add 1 to the len, to copy the null char as well.
644 */
645 Len =
646 LenWithNull = strlen(&Module.FullPathName[Module.OffsetToFileName]) + 1;
647 if (Len > nSize)
648 {
649 Len = nSize;
650 }
651
652 memcpy(lpBaseName, &Module.FullPathName[Module.OffsetToFileName], Len);
653 /* In case we copied null char, remove it from final len */
654 if (Len == LenWithNull)
655 {
656 --Len;
657 }
658
659 return Len;
660}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static BOOL NTAPI FindDeviceDriver(IN PVOID ImageBase, OUT PRTL_PROCESS_MODULE_INFORMATION MatchingModule)
Definition: psapi.c:42
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2084

Referenced by GetDeviceDriverBaseNameW(), and START_TEST().

◆ GetDeviceDriverBaseNameW()

DWORD WINAPI GetDeviceDriverBaseNameW ( LPVOID  ImageBase,
LPWSTR  lpBaseName,
DWORD  nSize 
)

Definition at line 707 of file psapi.c.

710{
711 DWORD Len;
712 LPSTR BaseName;
713
714 /* Allocate internal buffer for conversion */
715 BaseName = LocalAlloc(LMEM_FIXED, nSize);
716 if (BaseName == 0)
717 {
718 return 0;
719 }
720
721 /* Call A API */
722 Len = GetDeviceDriverBaseNameA(ImageBase, BaseName, nSize);
723 if (Len == 0)
724 {
725 LocalFree(BaseName);
726 return 0;
727 }
728
729 /* And convert output */
730 if (MultiByteToWideChar(CP_ACP, 0, BaseName, (Len < nSize) ? Len + 1 : Len, lpBaseName, nSize) == 0)
731 {
732 LocalFree(BaseName);
733 return 0;
734 }
735
736 LocalFree(BaseName);
737 return Len;
738}
#define MultiByteToWideChar
Definition: compat.h:110
DWORD WINAPI GetDeviceDriverBaseNameA(LPVOID ImageBase, LPSTR lpBaseName, DWORD nSize)
Definition: psapi.c:629

◆ GetDeviceDriverFileNameA()

DWORD WINAPI GetDeviceDriverFileNameA ( LPVOID  ImageBase,
LPSTR  lpFilename,
DWORD  nSize 
)

Definition at line 668 of file psapi.c.

671{
672 SIZE_T Len, LenWithNull;
674
675 /* Get the associated device driver to the base address */
676 if (!FindDeviceDriver(ImageBase, &Module))
677 {
678 return 0;
679 }
680
681 /* And copy as much as possible to output buffer.
682 * Try to add 1 to the len, to copy the null char as well.
683 */
684 Len =
685 LenWithNull = strlen(Module.FullPathName) + 1;
686 if (Len > nSize)
687 {
688 Len = nSize;
689 }
690
691 memcpy(lpFilename, Module.FullPathName, Len);
692 /* In case we copied null char, remove it from final len */
693 if (Len == LenWithNull)
694 {
695 --Len;
696 }
697
698 return Len;
699}

Referenced by GetDeviceDriverFileNameW(), and START_TEST().

◆ GetDeviceDriverFileNameW()

DWORD WINAPI GetDeviceDriverFileNameW ( LPVOID  ImageBase,
LPWSTR  lpFilename,
DWORD  nSize 
)

Definition at line 746 of file psapi.c.

749{
750 DWORD Len;
752
753 /* Allocate internal buffer for conversion */
755 if (FileName == 0)
756 {
757 return 0;
758 }
759
760 /* Call A API */
762 if (Len == 0)
763 {
765 return 0;
766 }
767
768 /* And convert output */
769 if (MultiByteToWideChar(CP_ACP, 0, FileName, (Len < nSize) ? Len + 1 : Len, lpFilename, nSize) == 0)
770 {
772 return 0;
773 }
774
776 return Len;
777}
DWORD WINAPI GetDeviceDriverFileNameA(LPVOID ImageBase, LPSTR lpFilename, DWORD nSize)
Definition: psapi.c:668
struct _FileName FileName
Definition: fatprocs.h:896

◆ GetMappedFileNameA()

DWORD WINAPI GetMappedFileNameA ( HANDLE  hProcess,
LPVOID  lpv,
LPSTR  lpFilename,
DWORD  nSize 
)

Definition at line 785 of file psapi.c.

789{
790 DWORD Len;
792
793 DPRINT("GetMappedFileNameA(%p, %p, %p, %lu)\n", hProcess, lpv, lpFilename, nSize);
794
795 /* Allocate internal buffer for conversion */
797 if (FileName == NULL)
798 {
799 return 0;
800 }
801
802 /* Call W API */
804
805 /* And convert output */
806 if (WideCharToMultiByte(CP_ACP, 0, FileName, (Len < nSize) ? Len + 1 : Len, lpFilename, nSize, NULL, NULL) == 0)
807 {
808 Len = 0;
809 }
810
812 return Len;
813}
DWORD WINAPI GetMappedFileNameW(HANDLE hProcess, LPVOID lpv, LPWSTR lpFilename, DWORD nSize)
Definition: psapi.c:821
#define DPRINT
Definition: sndvol32.h:71
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by test_GetMappedFileName(), and test_GetProcessImageFileName().

◆ GetMappedFileNameW()

DWORD WINAPI GetMappedFileNameW ( HANDLE  hProcess,
LPVOID  lpv,
LPWSTR  lpFilename,
DWORD  nSize 
)

Definition at line 821 of file psapi.c.

825{
826 DWORD Len;
827 SIZE_T OutSize;
829 struct
830 {
832 WCHAR CharBuffer[MAX_PATH];
833 } SectionName;
834
835 DPRINT("GetMappedFileNameW(%p, %p, %p, %lu)\n", hProcess, lpv, lpFilename, nSize);
836
837 /* If no buffer, no need to keep going on */
838 if (nSize == 0)
839 {
841 return 0;
842 }
843
844 /* Query section name */
846 &SectionName, sizeof(SectionName), &OutSize);
847 if (!NT_SUCCESS(Status))
848 {
850 return 0;
851 }
852
853 /* Prepare to copy file name */
854 Len =
855 OutSize = SectionName.SectionFileName.Length / sizeof(WCHAR);
856 if (OutSize + 1 > nSize)
857 {
858 Len = nSize - 1;
859 OutSize = nSize;
861 }
862 else
863 {
865 }
866
867 /* Copy, zero and return */
868 memcpy(lpFilename, SectionName.SectionFileName.Buffer, Len * sizeof(WCHAR));
869 lpFilename[Len] = 0;
870
871 return OutSize;
872}
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define MAX_PATH
Definition: compat.h:34
@ MemorySectionName
Definition: mmtypes.h:185
NTSTATUS NTAPI NtQueryVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, IN MEMORY_INFORMATION_CLASS MemoryInformationClass, OUT PVOID MemoryInformation, IN SIZE_T MemoryInformationLength, OUT PSIZE_T ReturnLength)
Definition: virtual.c:4407

Referenced by GetMappedFileNameA(), and test_GetMappedFileName().

◆ GetModuleBaseNameA()

DWORD WINAPI GetModuleBaseNameA ( HANDLE  hProcess,
HMODULE  hModule,
LPSTR  lpBaseName,
DWORD  nSize 
)

Definition at line 880 of file psapi.c.

884{
885 DWORD Len;
886 PWSTR BaseName;
887
888 /* Allocate internal buffer for conversion */
889 BaseName = LocalAlloc(LMEM_FIXED, nSize * sizeof(WCHAR));
890 if (BaseName == NULL)
891 {
892 return 0;
893 }
894
895 /* Call W API */
897 /* And convert output */
898 if (WideCharToMultiByte(CP_ACP, 0, BaseName, (Len < nSize) ? Len + 1 : Len, lpBaseName, nSize, NULL, NULL) == 0)
899 {
900 Len = 0;
901 }
902
903 LocalFree(BaseName);
904
905 return Len;
906}
DWORD WINAPI GetModuleBaseNameW(HANDLE hProcess, HMODULE hModule, LPWSTR lpBaseName, DWORD nSize)
Definition: psapi.c:914

Referenced by test_EnumProcessModules(), and test_GetModuleBaseName().

◆ GetModuleBaseNameW()

DWORD WINAPI GetModuleBaseNameW ( HANDLE  hProcess,
HMODULE  hModule,
LPWSTR  lpBaseName,
DWORD  nSize 
)

Definition at line 914 of file psapi.c.

918{
919 DWORD Len;
921
922 /* Get the matching module */
923 if (!FindModule(hProcess, hModule, &Module))
924 {
925 return 0;
926 }
927
928 /* Get the maximum len we have/can write in given size */
929 Len = Module.BaseDllName.Length + sizeof(UNICODE_NULL);
930 if (nSize * sizeof(WCHAR) < Len)
931 {
932 Len = nSize * sizeof(WCHAR);
933 }
934
935 /* Read string */
936 if (!ReadProcessMemory(hProcess, (&Module.BaseDllName)->Buffer, lpBaseName, Len, NULL))
937 {
938 return 0;
939 }
940
941 /* If we are at the end of the string, prepare to override to nullify string */
942 if (Len == Module.BaseDllName.Length + sizeof(UNICODE_NULL))
943 {
944 Len -= sizeof(UNICODE_NULL);
945 }
946
947 /* Nullify at the end if needed */
948 if (Len >= nSize * sizeof(WCHAR))
949 {
950 if (nSize)
951 {
952 ASSERT(nSize >= sizeof(UNICODE_NULL));
953 lpBaseName[nSize - 1] = UNICODE_NULL;
954 }
955 }
956 /* Otherwise, nullify at last written char */
957 else
958 {
959 ASSERT(Len + sizeof(UNICODE_NULL) <= nSize * sizeof(WCHAR));
960 lpBaseName[Len / sizeof(WCHAR)] = UNICODE_NULL;
961 }
962
963 return Len / sizeof(WCHAR);
964}
static BOOL NTAPI FindModule(IN HANDLE hProcess, IN HMODULE hModule OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY Module)
Definition: psapi.c:115
#define UNICODE_NULL
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:145

Referenced by EnumerateLoadedModulesW64(), get_process_name_from_pid(), GetModuleBaseNameA(), and GetOwnerModuleFromPidEntry().

◆ GetModuleFileNameExA()

DWORD WINAPI GetModuleFileNameExA ( HANDLE  hProcess,
HMODULE  hModule,
LPSTR  lpFilename,
DWORD  nSize 
)

Definition at line 972 of file psapi.c.

976{
977 DWORD Len;
979
980 /* Allocate internal buffer for conversion */
982 if (Filename == NULL)
983 {
984 return 0;
985 }
986
987 /* Call W API */
989 /* And convert output */
990 if (WideCharToMultiByte(CP_ACP, 0, Filename, (Len < nSize) ? Len + 1 : Len, lpFilename, nSize, NULL, NULL) == 0)
991 {
992 Len = 0;
993 }
994
996
997 return Len;
998}
#define GetModuleFileNameExW(w, x, y, z)
Definition: compat.h:922
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:939

Referenced by debug_target_init_modules_info(), test_EnumProcessModules(), test_GetModuleFileNameEx(), and ModuleData::Update().

◆ GetModuleFileNameExW()

DWORD WINAPI GetModuleFileNameExW ( HANDLE  hProcess,
HMODULE  hModule,
LPWSTR  lpFilename,
DWORD  nSize 
)

Definition at line 1006 of file psapi.c.

1010{
1011 DWORD Len;
1012 LDR_DATA_TABLE_ENTRY Module;
1013
1014 /* Get the matching module */
1015 if (!FindModule(hProcess, hModule, &Module))
1016 {
1017 return 0;
1018 }
1019
1020 /* Get the maximum len we have/can write in given size */
1021 Len = Module.FullDllName.Length + sizeof(UNICODE_NULL);
1022 if (nSize * sizeof(WCHAR) < Len)
1023 {
1024 Len = nSize * sizeof(WCHAR);
1025 }
1026
1027 /* Read string */
1028 if (!ReadProcessMemory(hProcess, (&Module.FullDllName)->Buffer, lpFilename, Len, NULL))
1029 {
1030 return 0;
1031 }
1032
1033 /* If we are at the end of the string, prepare to override to nullify string */
1034 if (Len == Module.FullDllName.Length + sizeof(UNICODE_NULL))
1035 {
1036 Len -= sizeof(UNICODE_NULL);
1037 }
1038
1039 /* Nullify at the end if needed */
1040 if (Len >= nSize * sizeof(WCHAR))
1041 {
1042 if (nSize)
1043 {
1044 ASSERT(nSize >= sizeof(UNICODE_NULL));
1045 lpFilename[nSize - 1] = UNICODE_NULL;
1046 }
1047 }
1048 /* Otherwise, nullify at last written char */
1049 else
1050 {
1051 ASSERT(Len + sizeof(UNICODE_NULL) <= nSize * sizeof(WCHAR));
1052 lpFilename[Len / sizeof(WCHAR)] = UNICODE_NULL;
1053 }
1054
1055 return Len / sizeof(WCHAR);
1056}
UNICODE_STRING FullDllName
Definition: btrfs_drv.h:1882

◆ GetModuleInformation()

BOOL WINAPI GetModuleInformation ( HANDLE  hProcess,
HMODULE  hModule,
LPMODULEINFO  lpmodinfo,
DWORD  cb 
)

Definition at line 1064 of file psapi.c.

1068{
1069 MODULEINFO LocalInfo;
1070 LDR_DATA_TABLE_ENTRY Module;
1071
1072 /* Check output size */
1073 if (cb < sizeof(MODULEINFO))
1074 {
1076 return FALSE;
1077 }
1078
1079 /* Get the matching module */
1080 if (!FindModule(hProcess, hModule, &Module))
1081 {
1082 return FALSE;
1083 }
1084
1085 /* Get a local copy first, to check for valid pointer once */
1086 LocalInfo.lpBaseOfDll = hModule;
1087 LocalInfo.SizeOfImage = Module.SizeOfImage;
1088 LocalInfo.EntryPoint = Module.EntryPoint;
1089
1090 /* Attempt to copy to output */
1091 _SEH2_TRY
1092 {
1093 memcpy(lpmodinfo, &LocalInfo, sizeof(LocalInfo));
1094 }
1096 {
1098 _SEH2_YIELD(return FALSE);
1099 }
1100 _SEH2_END;
1101
1102 return TRUE;
1103}
PVOID EntryPoint
Definition: ntddk_ex.h:203
ULONG SizeOfImage
Definition: ldrtypes.h:143
DWORD SizeOfImage
Definition: compat.h:919
LPVOID lpBaseOfDll
Definition: compat.h:918
LPVOID EntryPoint
Definition: compat.h:920

Referenced by debug_target_init_modules_info(), EnumerateLoadedModulesW64(), test_EnumProcessModules(), test_GetModuleInformation(), and ModuleData::Update().

◆ GetPerformanceInfo()

BOOL WINAPI GetPerformanceInfo ( PPERFORMANCE_INFORMATION  pPerformanceInformation,
DWORD  cb 
)

Definition at line 1394 of file psapi.c.

1396{
1400 SYSTEM_FILECACHE_INFORMATION SystemFileCacheInfo;
1401 PSYSTEM_PROCESS_INFORMATION ProcInfoArray, SystemProcInfo;
1402 DWORD Size = INIT_MEMORY_SIZE, Needed, ProcCount, ThreadsCount, HandleCount;
1403
1404 /* Validate output buffer */
1405 if (cb < sizeof(PERFORMANCE_INFORMATION))
1406 {
1408 return FALSE;
1409 }
1410
1411 /* First, gather as many information about the system as possible */
1414 sizeof(SystemBasicInfo),
1415 NULL);
1416 if (!NT_SUCCESS(Status))
1417 {
1419 return FALSE;
1420 }
1421
1424 sizeof(SystemPerfInfo),
1425 NULL);
1426 if (!NT_SUCCESS(Status))
1427 {
1429 return FALSE;
1430 }
1431
1433 &SystemFileCacheInfo,
1434 sizeof(SystemFileCacheInfo),
1435 NULL);
1436 if (!NT_SUCCESS(Status))
1437 {
1439 return FALSE;
1440 }
1441
1442 /* Then loop till we have all the information about processes */
1443 do
1444 {
1445 ProcInfoArray = LocalAlloc(LMEM_FIXED, Size);
1446 if (ProcInfoArray == NULL)
1447 {
1449 return FALSE;
1450 }
1451
1453 ProcInfoArray,
1454 Size,
1455 &Needed);
1456 if (NT_SUCCESS(Status))
1457 {
1458 break;
1459 }
1460
1461 LocalFree(ProcInfoArray);
1462
1463 /* In case we have unexpected status, quit */
1465 {
1467 return FALSE;
1468 }
1469
1470 /* If needed size is smaller than actual size, guess it's something to add to our current size */
1471 if (Needed <= Size)
1472 {
1473 Size += Needed;
1474 }
1475 /* Otherwise, take it as size to allocate */
1476 else
1477 {
1478 Size = Needed;
1479 }
1480 } while (TRUE);
1481
1482 /* Start browsing all our entries */
1483 ProcCount = 0;
1484 HandleCount = 0;
1485 ThreadsCount = 0;
1486 SystemProcInfo = ProcInfoArray;
1487 do
1488 {
1489 /* Ensure we really have an entry */
1490 if (Needed < sizeof(SYSTEM_PROCESS_INFORMATION))
1491 {
1492 break;
1493 }
1494
1495 /* Sum procs, threads and handles */
1496 ++ProcCount;
1497 ThreadsCount += SystemProcInfo->NumberOfThreads;
1498 HandleCount += SystemProcInfo->HandleCount;
1499
1500 /* If no next entry, then, it's over */
1501 if (SystemProcInfo->NextEntryOffset == 0 || SystemProcInfo->NextEntryOffset > Needed)
1502 {
1503 break;
1504 }
1505
1506 /* Jump to next entry while keeping accurate bytes left count */
1507 Needed -= SystemProcInfo->NextEntryOffset;
1508 SystemProcInfo = (PSYSTEM_PROCESS_INFORMATION)((ULONG_PTR)SystemProcInfo + SystemProcInfo->NextEntryOffset);
1509 }
1510 while (TRUE);
1511
1512 LocalFree(ProcInfoArray);
1513
1514 /* Output data */
1515 pPerformanceInformation->CommitTotal = SystemPerfInfo.CommittedPages;
1516 pPerformanceInformation->CommitLimit = SystemPerfInfo.CommitLimit;
1517 pPerformanceInformation->CommitPeak = SystemPerfInfo.PeakCommitment;
1518 pPerformanceInformation->PhysicalTotal = SystemBasicInfo.NumberOfPhysicalPages;
1519 pPerformanceInformation->PhysicalAvailable = SystemPerfInfo.AvailablePages;
1520 pPerformanceInformation->SystemCache = SystemFileCacheInfo.CurrentSizeIncludingTransitionInPages;
1521 pPerformanceInformation->KernelNonpaged = SystemPerfInfo.NonPagedPoolPages;
1522 pPerformanceInformation->PageSize = SystemBasicInfo.PageSize;
1523 pPerformanceInformation->cb = sizeof(PERFORMANCE_INFORMATION);
1525 pPerformanceInformation->KernelPaged = SystemPerfInfo.PagedPoolPages;
1526 pPerformanceInformation->HandleCount = HandleCount;
1527 pPerformanceInformation->ProcessCount = ProcCount;
1528 pPerformanceInformation->ThreadCount = ThreadsCount;
1529
1530 return TRUE;
1531}
@ SystemBasicInformation
Definition: ntddk_ex.h:11
@ SystemFileCacheInformation
Definition: ntddk_ex.h:32
#define SystemPerformanceInformation
Definition: memtest.h:87
SYSTEM_BASIC_INFORMATION SystemBasicInfo
Definition: perfdata.c:30
SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo
Definition: perfdata.c:29
struct _PERFORMANCE_INFORMATION PERFORMANCE_INFORMATION
SIZE_T PhysicalAvailable
Definition: psapi.h:70
SIZE_T CurrentSizeIncludingTransitionInPages
Definition: extypes.h:1127

Referenced by test_GetPerformanceInfo().

◆ GetProcessImageFileNameA()

DWORD WINAPI GetProcessImageFileNameA ( HANDLE  hProcess,
LPSTR  lpImageFileName,
DWORD  nSize 
)

Definition at line 1216 of file psapi.c.

1219{
1220 PUNICODE_STRING ImageFileName;
1223 DWORD Len;
1224
1225 /* Allocate string big enough to hold name */
1226 BufferSize = sizeof(UNICODE_STRING) + (nSize * sizeof(WCHAR));
1227 ImageFileName = LocalAlloc(LMEM_FIXED, BufferSize);
1228 if (ImageFileName == NULL)
1229 {
1230 return 0;
1231 }
1232
1233 /* Query name */
1236 ImageFileName,
1237 BufferSize,
1238 NULL);
1239 /* Len mismatch => buffer too small */
1241 {
1243 }
1244 if (!NT_SUCCESS(Status))
1245 {
1247 LocalFree(ImageFileName);
1248 return 0;
1249 }
1250
1251 /* Copy name */
1252 Len = WideCharToMultiByte(CP_ACP, 0, ImageFileName->Buffer,
1253 ImageFileName->Length, lpImageFileName, nSize, NULL, NULL);
1254 /* If conversion was successful, don't return len with added \0 */
1255 if (Len != 0)
1256 {
1257 Len -= sizeof(ANSI_NULL);
1258 }
1259
1260 LocalFree(ImageFileName);
1261 return Len;
1262}
#define BufferSize
Definition: mmc.h:75
struct _UNICODE_STRING UNICODE_STRING
@ ProcessImageFileName
Definition: winternl.h:397
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by test_GetProcessImageFileName().

◆ GetProcessImageFileNameW()

DWORD WINAPI GetProcessImageFileNameW ( HANDLE  hProcess,
LPWSTR  lpImageFileName,
DWORD  nSize 
)

Definition at line 1163 of file psapi.c.

1166{
1167 PUNICODE_STRING ImageFileName;
1170 DWORD Len;
1171
1172 /* Allocate string big enough to hold name */
1173 BufferSize = sizeof(UNICODE_STRING) + (nSize * sizeof(WCHAR));
1174 ImageFileName = LocalAlloc(LMEM_FIXED, BufferSize);
1175 if (ImageFileName == NULL)
1176 {
1177 return 0;
1178 }
1179
1180 /* Query name */
1183 ImageFileName,
1184 BufferSize,
1185 NULL);
1186 /* Len mismatch => buffer too small */
1188 {
1190 }
1191 if (!NT_SUCCESS(Status))
1192 {
1194 LocalFree(ImageFileName);
1195 return 0;
1196 }
1197
1198 /* Copy name and null-terminate if possible */
1199 memcpy(lpImageFileName, ImageFileName->Buffer, ImageFileName->Length);
1200 Len = ImageFileName->Length / sizeof(WCHAR);
1201 if (Len < nSize)
1202 {
1203 lpImageFileName[Len] = UNICODE_NULL;
1204 }
1205
1206 LocalFree(ImageFileName);
1207 return Len;
1208}

Referenced by NonConsoleProcessShutdown(), test_GetProcessImageFileName(), and UserClientShutdown().

◆ GetProcessMemoryInfo()

BOOL WINAPI GetProcessMemoryInfo ( HANDLE  Process,
PPROCESS_MEMORY_COUNTERS  ppsmemCounters,
DWORD  cb 
)

Definition at line 1539 of file psapi.c.

1542{
1544 VM_COUNTERS_EX Counters;
1545
1546 /* Validate output size
1547 * It can be either PROCESS_MEMORY_COUNTERS or PROCESS_MEMORY_COUNTERS_EX
1548 */
1549 if (cb < sizeof(PROCESS_MEMORY_COUNTERS))
1550 {
1552 return FALSE;
1553 }
1554
1555 _SEH2_TRY
1556 {
1557 ppsmemCounters->PeakPagefileUsage = 0;
1558
1559 /* Query counters */
1562 &Counters,
1563 sizeof(Counters),
1564 NULL);
1565 if (!NT_SUCCESS(Status))
1566 {
1568 _SEH2_YIELD(return FALSE);
1569 }
1570
1571 /* Properly set cb, according to what we received */
1572 if (cb >= sizeof(PROCESS_MEMORY_COUNTERS_EX))
1573 {
1574 ppsmemCounters->cb = sizeof(PROCESS_MEMORY_COUNTERS_EX);
1575 }
1576 else
1577 {
1578 ppsmemCounters->cb = sizeof(PROCESS_MEMORY_COUNTERS);
1579 }
1580
1581 /* Output data */
1582 ppsmemCounters->PageFaultCount = Counters.PageFaultCount;
1583 ppsmemCounters->PeakWorkingSetSize = Counters.PeakWorkingSetSize;
1584 ppsmemCounters->WorkingSetSize = Counters.WorkingSetSize;
1585 ppsmemCounters->QuotaPeakPagedPoolUsage = Counters.QuotaPeakPagedPoolUsage;
1586 ppsmemCounters->QuotaPagedPoolUsage = Counters.QuotaPagedPoolUsage;
1587 ppsmemCounters->QuotaPeakNonPagedPoolUsage = Counters.QuotaPeakNonPagedPoolUsage;
1588 ppsmemCounters->QuotaNonPagedPoolUsage = Counters.QuotaNonPagedPoolUsage;
1589 ppsmemCounters->PagefileUsage = Counters.PagefileUsage;
1590 ppsmemCounters->PeakPagefileUsage = Counters.PeakPagefileUsage;
1591 /* And if needed, additional field for _EX version */
1592 if (cb >= sizeof(PROCESS_MEMORY_COUNTERS_EX))
1593 {
1594 ((PPROCESS_MEMORY_COUNTERS_EX)ppsmemCounters)->PrivateUsage = Counters.PrivateUsage;
1595 }
1596 }
1598 {
1600 _SEH2_YIELD(return FALSE);
1601 }
1602 _SEH2_END;
1603
1604 return TRUE;
1605}
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
@ ProcessVmCounters
Definition: winternl.h:859
struct _PROCESS_MEMORY_COUNTERS_EX PROCESS_MEMORY_COUNTERS_EX
struct _PROCESS_MEMORY_COUNTERS_EX * PPROCESS_MEMORY_COUNTERS_EX
struct _PROCESS_MEMORY_COUNTERS PROCESS_MEMORY_COUNTERS
SIZE_T PeakPagefileUsage
Definition: psapi.h:47
SIZE_T QuotaNonPagedPoolUsage
Definition: psapi.h:45
SIZE_T PeakWorkingSetSize
Definition: psapi.h:40
SIZE_T QuotaPeakNonPagedPoolUsage
Definition: psapi.h:44
SIZE_T QuotaPeakPagedPoolUsage
Definition: psapi.h:42
SIZE_T QuotaPagedPoolUsage
Definition: psapi.h:43
SIZE_T QuotaNonPagedPoolUsage
Definition: pstypes.h:114
SIZE_T WorkingSetSize
Definition: pstypes.h:110
SIZE_T PeakWorkingSetSize
Definition: pstypes.h:109
SIZE_T QuotaPeakNonPagedPoolUsage
Definition: pstypes.h:113
SIZE_T QuotaPeakPagedPoolUsage
Definition: pstypes.h:111
SIZE_T PagefileUsage
Definition: pstypes.h:115
SIZE_T QuotaPagedPoolUsage
Definition: pstypes.h:112
SIZE_T PrivateUsage
Definition: pstypes.h:117
ULONG PageFaultCount
Definition: pstypes.h:108
SIZE_T PeakPagefileUsage
Definition: pstypes.h:116

Referenced by test_GetProcessMemoryInfo().

◆ GetWsChanges()

BOOL WINAPI GetWsChanges ( HANDLE  hProcess,
PPSAPI_WS_WATCH_INFORMATION  lpWatchInfo,
DWORD  cb 
)

Definition at line 1136 of file psapi.c.

1139{
1141
1142 /* Simply forward the call */
1145 lpWatchInfo,
1146 cb,
1147 NULL);
1148 if(!NT_SUCCESS(Status))
1149 {
1151 return FALSE;
1152 }
1153
1154 return TRUE;
1155}
@ ProcessWorkingSetWatch
Definition: winternl.h:871

Referenced by test_ws_functions().

◆ InitializeProcessForWsWatch()

BOOL WINAPI InitializeProcessForWsWatch ( HANDLE  hProcess)

Definition at line 1111 of file psapi.c.

1112{
1114
1115 /* Simply forward the call */
1118 NULL,
1119 0);
1120 /* In case the function returns this, MS considers the call as a success */
1122 {
1123 return TRUE;
1124 }
1125
1127 return FALSE;
1128}
#define STATUS_PORT_ALREADY_SET
Definition: ntstatus.h:308
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145

Referenced by test_ws_functions().

◆ PsInitializeAndStartProfile()

static VOID NTAPI PsInitializeAndStartProfile ( VOID  )
static

Definition at line 260 of file psapi.c.

261{
263}
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by DllMain().

◆ PsParseCommandLine()

static VOID NTAPI PsParseCommandLine ( VOID  )
static

Definition at line 251 of file psapi.c.

252{
254}

Referenced by DllMain().

◆ PsStopAndAnalyzeProfile()

static VOID NTAPI PsStopAndAnalyzeProfile ( VOID  )
static

Definition at line 269 of file psapi.c.

270{
272}

Referenced by DllMain().

◆ QueryWorkingSet()

BOOL WINAPI QueryWorkingSet ( HANDLE  hProcess,
PVOID  pv,
DWORD  cb 
)

Definition at line 1613 of file psapi.c.

1616{
1618
1619 /* Simply forward the call */
1621 NULL,
1623 pv,
1624 cb,
1625 NULL);
1626 if (!NT_SUCCESS(Status))
1627 {
1629 return FALSE;
1630 }
1631
1632 return TRUE;
1633}
@ MemoryWorkingSetList
Definition: mmtypes.h:184

Referenced by test_ws_functions().

◆ QueryWorkingSetEx()

BOOL WINAPI QueryWorkingSetEx ( IN HANDLE  hProcess,
IN OUT PVOID  pv,
IN DWORD  cb 
)

Definition at line 1640 of file psapi.c.

1643{
1645
1646 /* Simply forward the call */
1648 NULL,
1650 pv,
1651 cb,
1652 NULL);
1653 if (!NT_SUCCESS(Status))
1654 {
1656 return FALSE;
1657 }
1658
1659 return TRUE;
1660}
@ MemoryWorkingSetExList
Definition: mmtypes.h:187