ReactOS  0.4.14-dev-98-gb0d4763
psapi.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _MODULEINFO
 
struct  _PSAPI_WS_WATCH_INFORMATION
 
struct  _PROCESS_MEMORY_COUNTERS
 
struct  _PROCESS_MEMORY_COUNTERS_EX
 
struct  _PERFORMANCE_INFORMATION
 
struct  _ENUM_PAGE_FILE_INFORMATION
 

Macros

#define PENUM_PAGE_FILE_CALLBACK   PENUM_PAGE_FILE_CALLBACKA
 
#define EnumPageFiles   EnumPageFilesA
 
#define GetModuleBaseName   GetModuleBaseNameA
 
#define GetModuleFileNameEx   GetModuleFileNameExA
 
#define GetMappedFilenameEx   GetMappedFilenameExA
 
#define GetDeviceDriverBaseName   GetDeviceDriverBaseNameA
 
#define GetDeviceDriverFileName   GetDeviceDriverFileNameA
 
#define GetProcessImageFileName   GetProcessImageFileNameA
 

Typedefs

typedef struct _MODULEINFO MODULEINFO
 
typedef struct _MODULEINFOLPMODULEINFO
 
typedef struct _PSAPI_WS_WATCH_INFORMATION PSAPI_WS_WATCH_INFORMATION
 
typedef struct _PSAPI_WS_WATCH_INFORMATIONPPSAPI_WS_WATCH_INFORMATION
 
typedef struct _PROCESS_MEMORY_COUNTERS PROCESS_MEMORY_COUNTERS
 
typedef struct _PROCESS_MEMORY_COUNTERSPPROCESS_MEMORY_COUNTERS
 
typedef struct _PROCESS_MEMORY_COUNTERS_EX PROCESS_MEMORY_COUNTERS_EX
 
typedef struct _PROCESS_MEMORY_COUNTERS_EXPPROCESS_MEMORY_COUNTERS_EX
 
typedef struct _PERFORMANCE_INFORMATION PERFORMANCE_INFORMATION
 
typedef struct _PERFORMANCE_INFORMATIONPPERFORMANCE_INFORMATION
 
typedef struct _ENUM_PAGE_FILE_INFORMATION ENUM_PAGE_FILE_INFORMATION
 
typedef struct _ENUM_PAGE_FILE_INFORMATIONPENUM_PAGE_FILE_INFORMATION
 
typedef BOOL(CALLBACKPENUM_PAGE_FILE_CALLBACKA) (LPVOID, PENUM_PAGE_FILE_INFORMATION, LPCSTR)
 
typedef BOOL(CALLBACKPENUM_PAGE_FILE_CALLBACKW) (LPVOID, PENUM_PAGE_FILE_INFORMATION, LPCWSTR)
 

Functions

BOOL WINAPI EnumProcesses (DWORD *, DWORD, DWORD *)
 
BOOL WINAPI EnumProcessModules (HANDLE, HMODULE *, DWORD, LPDWORD)
 
BOOL WINAPI EnumPageFilesA (PENUM_PAGE_FILE_CALLBACKA, LPVOID)
 
BOOL WINAPI EnumPageFilesW (PENUM_PAGE_FILE_CALLBACKW, LPVOID)
 
DWORD WINAPI GetModuleBaseNameA (HANDLE, HMODULE, LPSTR, DWORD)
 
DWORD WINAPI GetModuleBaseNameW (HANDLE, HMODULE, LPWSTR, DWORD)
 
DWORD WINAPI GetModuleFileNameExA (HANDLE, HMODULE, LPSTR, DWORD)
 
DWORD WINAPI GetModuleFileNameExW (HANDLE, HMODULE, LPWSTR, DWORD)
 
BOOL WINAPI GetModuleInformation (HANDLE, HMODULE, LPMODULEINFO, DWORD)
 
BOOL WINAPI EmptyWorkingSet (HANDLE)
 
BOOL WINAPI QueryWorkingSet (HANDLE, PVOID, DWORD)
 
BOOL WINAPI InitializeProcessForWsWatch (HANDLE)
 
BOOL WINAPI GetWsChanges (HANDLE, PPSAPI_WS_WATCH_INFORMATION, DWORD)
 
DWORD WINAPI GetMappedFileNameW (HANDLE, LPVOID, LPWSTR, DWORD)
 
DWORD WINAPI GetMappedFileNameA (HANDLE, LPVOID, LPSTR, DWORD)
 
BOOL WINAPI EnumDeviceDrivers (LPVOID *, DWORD, LPDWORD)
 
DWORD WINAPI GetDeviceDriverBaseNameA (LPVOID, LPSTR, DWORD)
 
DWORD WINAPI GetDeviceDriverBaseNameW (LPVOID, LPWSTR, DWORD)
 
DWORD WINAPI GetDeviceDriverFileNameA (LPVOID, LPSTR, DWORD)
 
DWORD WINAPI GetDeviceDriverFileNameW (LPVOID, LPWSTR, DWORD)
 
BOOL WINAPI GetProcessMemoryInfo (HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD)
 
BOOL WINAPI GetPerformanceInfo (PPERFORMANCE_INFORMATION, DWORD)
 
DWORD WINAPI GetProcessImageFileNameW (HANDLE, LPWSTR, DWORD)
 
DWORD WINAPI GetProcessImageFileNameA (HANDLE, LPSTR, DWORD)
 

Macro Definition Documentation

◆ EnumPageFiles

#define EnumPageFiles   EnumPageFilesA

Definition at line 131 of file psapi.h.

◆ GetDeviceDriverBaseName

#define GetDeviceDriverBaseName   GetDeviceDriverBaseNameA

Definition at line 135 of file psapi.h.

◆ GetDeviceDriverFileName

#define GetDeviceDriverFileName   GetDeviceDriverFileNameA

Definition at line 136 of file psapi.h.

◆ GetMappedFilenameEx

#define GetMappedFilenameEx   GetMappedFilenameExA

Definition at line 134 of file psapi.h.

◆ GetModuleBaseName

#define GetModuleBaseName   GetModuleBaseNameA

Definition at line 132 of file psapi.h.

◆ GetModuleFileNameEx

#define GetModuleFileNameEx   GetModuleFileNameExA

Definition at line 133 of file psapi.h.

◆ GetProcessImageFileName

#define GetProcessImageFileName   GetProcessImageFileNameA

Definition at line 137 of file psapi.h.

◆ PENUM_PAGE_FILE_CALLBACK

#define PENUM_PAGE_FILE_CALLBACK   PENUM_PAGE_FILE_CALLBACKA

Definition at line 130 of file psapi.h.

Typedef Documentation

◆ ENUM_PAGE_FILE_INFORMATION

◆ LPMODULEINFO

◆ MODULEINFO

◆ PENUM_PAGE_FILE_CALLBACKA

typedef BOOL(CALLBACK * PENUM_PAGE_FILE_CALLBACKA) (LPVOID, PENUM_PAGE_FILE_INFORMATION, LPCSTR)

Definition at line 89 of file psapi.h.

◆ PENUM_PAGE_FILE_CALLBACKW

typedef BOOL(CALLBACK * PENUM_PAGE_FILE_CALLBACKW) (LPVOID, PENUM_PAGE_FILE_INFORMATION, LPCWSTR)

Definition at line 90 of file psapi.h.

◆ PENUM_PAGE_FILE_INFORMATION

◆ PERFORMANCE_INFORMATION

◆ PPERFORMANCE_INFORMATION

◆ PPROCESS_MEMORY_COUNTERS

◆ PPROCESS_MEMORY_COUNTERS_EX

◆ PPSAPI_WS_WATCH_INFORMATION

◆ PROCESS_MEMORY_COUNTERS

◆ PROCESS_MEMORY_COUNTERS_EX

◆ PSAPI_WS_WATCH_INFORMATION

Function Documentation

◆ EmptyWorkingSet()

BOOL WINAPI EmptyWorkingSet ( HANDLE  )

Definition at line 329 of file psapi.c.

330 {
331  SYSTEM_INFO SystemInfo;
332  QUOTA_LIMITS QuotaLimits;
334 
335  GetSystemInfo(&SystemInfo);
336 
337  /* Query the working set */
340  &QuotaLimits,
341  sizeof(QuotaLimits),
342  NULL);
343 
344  if (!NT_SUCCESS(Status))
345  {
347  return FALSE;
348  }
349 
350  /* Empty the working set */
351  QuotaLimits.MinimumWorkingSetSize = -1;
352  QuotaLimits.MaximumWorkingSetSize = -1;
353 
354  /* Set the working set */
357  &QuotaLimits,
358  sizeof(QuotaLimits));
360  {
362  return FALSE;
363  }
364 
365  return TRUE;
366 }
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
INT64 MinimumWorkingSetSize
Definition: lsa.idl:289
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:142
INT64 MaximumWorkingSetSize
Definition: lsa.idl:290

Referenced by test_ws_functions().

◆ EnumDeviceDrivers()

BOOL WINAPI EnumDeviceDrivers ( LPVOID ,
DWORD  ,
LPDWORD   
)

Definition at line 374 of file psapi.c.

377 {
381  /* By default, to prevent too many reallocations, we already make room for 4 modules */
383 
384  do
385  {
386  /* Allocate a buffer to hold modules information */
388  if (!Information)
389  {
391  return FALSE;
392  }
393 
394  /* Query information */
396  /* In case of an error */
397  if (!NT_SUCCESS(Status))
398  {
399  /* Save the amount of output modules */
400  NewSize = Information->NumberOfModules;
401  /* And free buffer */
403 
404  /* If it was not a length mismatch (ie, buffer too small), just leave */
406  {
408  return FALSE;
409  }
410 
411  /* Compute new size length */
412  ASSERT(Size >= sizeof(RTL_PROCESS_MODULES));
414  NewSize += sizeof(ULONG);
415  ASSERT(NewSize >= sizeof(RTL_PROCESS_MODULES));
416  /* Check whether it is really bigger - otherwise, leave */
417  if (NewSize < Size)
418  {
419  ASSERT(NewSize > Size);
421  return FALSE;
422  }
423 
424  /* Loop again with that new buffer */
425  Size = NewSize;
426  continue;
427  }
428 
429  /* End of allocation loop */
430  break;
431  } while (TRUE);
432 
433  _SEH2_TRY
434  {
435  for (Count = 0; Count < Information->NumberOfModules && Count < cb / sizeof(LPVOID); ++Count)
436  {
437  lpImageBase[Count] = Information->Modules[Count].ImageBase;
438  }
439 
440  *lpcbNeeded = Information->NumberOfModules * sizeof(LPVOID);
441  }
443  {
445  _SEH2_YIELD(return FALSE);
446  }
447  _SEH2_END;
448 
449  return TRUE;
450 }
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONG NTSTATUS
Definition: precomp.h:26
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define ERROR_NO_SYSTEM_RESOURCES
Definition: winerror.h:931
struct _RTL_PROCESS_MODULES RTL_PROCESS_MODULES
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define LMEM_FIXED
Definition: winbase.h:349
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
static DWORD cb
Definition: integrity.c:41
#define LPVOID
Definition: nt_native.h:45
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _RTL_PROCESS_MODULE_INFORMATION RTL_PROCESS_MODULE_INFORMATION
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
_SEH2_END
Definition: create.c:4424
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
unsigned int ULONG
Definition: retypes.h:1
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
Iosb Information
Definition: create.c:4377

◆ EnumPageFilesA()

BOOL WINAPI EnumPageFilesA ( PENUM_PAGE_FILE_CALLBACKA  ,
LPVOID   
)

Definition at line 1286 of file psapi.c.

1288 {
1289  BOOL Ret;
1291 
1292  Context.dwErrCode = ERROR_SUCCESS;
1293  Context.lpContext = lpContext;
1294  Context.pCallbackRoutine = pCallbackRoutine;
1295 
1296  /* Call W with our own callback for W -> A conversions */
1298  /* If we succeed but we have error code, fail and set error */
1299  if (Ret && Context.dwErrCode != ERROR_SUCCESS)
1300  {
1301  Ret = FALSE;
1302  SetLastError(Context.dwErrCode);
1303  }
1304 
1305  return Ret;
1306 }
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI EnumPageFilesW(PENUM_PAGE_FILE_CALLBACKW pCallbackRoutine, LPVOID lpContext)
Definition: psapi.c:1314
static BOOL CALLBACK CallBackConvertToAscii(LPVOID pContext, PENUM_PAGE_FILE_INFORMATION pPageFileInfo, LPCWSTR lpFilename)
Definition: psapi.c:229
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SetLastError(x)
Definition: compat.h:409
struct tagContext Context
Definition: acpixf.h:1024

◆ EnumPageFilesW()

BOOL WINAPI EnumPageFilesW ( PENUM_PAGE_FILE_CALLBACKW  ,
LPVOID   
)

Definition at line 1314 of file psapi.c.

1316 {
1317  PWSTR Colon;
1318  NTSTATUS Status;
1319  DWORD Size = INIT_MEMORY_SIZE, Needed;
1321  PSYSTEM_PAGEFILE_INFORMATION PageFileInfoArray, PageFileInfo;
1322 
1323  /* First loop till we have all the information about page files */
1324  do
1325  {
1326  PageFileInfoArray = LocalAlloc(LMEM_FIXED, Size);
1327  if (PageFileInfoArray == NULL)
1328  {
1330  return FALSE;
1331  }
1332 
1333  Status = NtQuerySystemInformation(SystemPageFileInformation, PageFileInfoArray, Size, &Needed);
1334  if (NT_SUCCESS(Status))
1335  {
1336  break;
1337  }
1338 
1339  LocalFree(PageFileInfoArray);
1340 
1341  /* In case we have unexpected status, quit */
1343  {
1345  return FALSE;
1346  }
1347 
1348  /* If needed size is smaller than actual size, guess it's something to add to our current size */
1349  if (Needed <= Size)
1350  {
1351  Size += Needed;
1352  }
1353  /* Otherwise, take it as size to allocate */
1354  else
1355  {
1356  Size = Needed;
1357  }
1358  }
1359  while (TRUE);
1360 
1361  /* Start browsing all our entries */
1362  PageFileInfo = PageFileInfoArray;
1363  do
1364  {
1365  /* Ensure we really have an entry */
1366  if (Needed < sizeof(SYSTEM_PAGEFILE_INFORMATION))
1367  {
1368  break;
1369  }
1370 
1371  /* Prepare structure to hand to the user */
1372  Information.Reserved = 0;
1373  Information.cb = sizeof(Information);
1374  Information.TotalSize = PageFileInfo->TotalSize;
1375  Information.TotalInUse = PageFileInfo->TotalInUse;
1376  Information.PeakUsage = PageFileInfo->PeakUsage;
1377 
1378  /* Search for colon */
1379  Colon = wcschr(PageFileInfo->PageFileName.Buffer, L':');
1380  /* If it's found and not at the begin of the string */
1381  if (Colon != 0 && Colon != PageFileInfo->PageFileName.Buffer)
1382  {
1383  /* We can call the user callback routine with the colon */
1384  --Colon;
1385  pCallbackRoutine(lpContext, &Information, Colon);
1386  }
1387 
1388  /* If no next entry, then, it's over */
1389  if (PageFileInfo->NextEntryOffset == 0 || PageFileInfo->NextEntryOffset > Needed)
1390  {
1391  break;
1392  }
1393 
1394  /* Jump to next entry while keeping accurate bytes left count */
1395  Needed -= PageFileInfo->NextEntryOffset;
1396  PageFileInfo = (PSYSTEM_PAGEFILE_INFORMATION)((ULONG_PTR)PageFileInfo + PageFileInfo->NextEntryOffset);
1397  }
1398  while (TRUE);
1399 
1400  LocalFree(PageFileInfoArray);
1401  return TRUE;
1402 }
#define INIT_MEMORY_SIZE
Definition: psapi.c:34
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
struct _SYSTEM_PAGEFILE_INFORMATION * PSYSTEM_PAGEFILE_INFORMATION
UNICODE_STRING PageFileName
Definition: extypes.h:1063
smooth NULL
Definition: ftsmooth.c:416
#define LMEM_FIXED
Definition: winbase.h:349
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
static const WCHAR L[]
Definition: oid.c:1250
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
Iosb Information
Definition: create.c:4377

Referenced by EnumPageFilesA().

◆ EnumProcesses()

BOOL WINAPI EnumProcesses ( DWORD ,
DWORD  ,
DWORD  
)

◆ EnumProcessModules()

BOOL WINAPI EnumProcessModules ( HANDLE  ,
HMODULE ,
DWORD  ,
LPDWORD   
)

Definition at line 542 of file psapi.c.

546 {
548  DWORD NbOfModules, Count;
549  PPEB_LDR_DATA LoaderData;
550  PLIST_ENTRY ListHead, ListEntry;
551  PROCESS_BASIC_INFORMATION ProcInfo;
553 
554  /* Query the process information to get its PEB address */
555  Status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, &ProcInfo, sizeof(ProcInfo), NULL);
556  if (!NT_SUCCESS(Status))
557  {
559  return FALSE;
560  }
561 
562  if (ProcInfo.PebBaseAddress == NULL)
563  {
565  return FALSE;
566  }
567 
568  /* Read loader data address from PEB */
569  if (!ReadProcessMemory(hProcess, &ProcInfo.PebBaseAddress->Ldr, &LoaderData, sizeof(LoaderData), NULL))
570  {
571  return FALSE;
572  }
573 
574  /* Store list head address */
575  ListHead = &LoaderData->InLoadOrderModuleList;
576 
577  /* Read first element in the modules list */
578  if (!ReadProcessMemory(hProcess, &LoaderData->InLoadOrderModuleList.Flink, &ListEntry, sizeof(ListEntry), NULL))
579  {
580  return FALSE;
581  }
582 
583  NbOfModules = cb / sizeof(HMODULE);
584  Count = 0;
585 
586  /* Loop on the modules */
587  while (ListEntry != ListHead)
588  {
589  /* Load module data */
591  CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks),
592  &CurrentModule,
593  sizeof(CurrentModule),
594  NULL))
595  {
596  return FALSE;
597  }
598 
599  /* Check if we can output module, do it if so */
600  if (Count < NbOfModules)
601  {
602  _SEH2_TRY
603  {
604  lphModule[Count] = CurrentModule.DllBase;
605  }
607  {
609  _SEH2_YIELD(return FALSE);
610  }
611  _SEH2_END;
612  }
613 
614  ++Count;
615  if (Count > MAX_MODULES)
616  {
618  return FALSE;
619  }
620 
621  /* Get to next listed module */
622  ListEntry = CurrentModule.InLoadOrderLinks.Flink;
623  }
624 
625  _SEH2_TRY
626  {
627  *lpcbNeeded = Count * sizeof(HMODULE);
628  }
630  {
632  _SEH2_YIELD(return FALSE);
633  }
634  _SEH2_END;
635 
636  return TRUE;
637 }
#define TRUE
Definition: types.h:120
LIST_ENTRY InLoadOrderModuleList
Definition: ldrtypes.h:120
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define ReadProcessMemory(a, b, c, d, e)
Definition: compat.h:415
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PLOADER_MODULE CurrentModule
Definition: mboot.c:66
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
static DWORD cb
Definition: integrity.c:41
Definition: btrfs_drv.h:1780
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
HANDLE HMODULE
Definition: typedefs.h:75
_SEH2_END
Definition: create.c:4424
PPEB_LDR_DATA Ldr
Definition: btrfs_drv.h:1816
#define STATUS_PARTIAL_COPY
Definition: ntstatus.h:181
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define MAX_MODULES
Definition: psapi.c:33

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

◆ GetDeviceDriverBaseNameA()

DWORD WINAPI GetDeviceDriverBaseNameA ( LPVOID  ,
LPSTR  ,
DWORD   
)

Definition at line 645 of file psapi.c.

648 {
649  DWORD Len, LenWithNull;
651 
652  /* Get the associated device driver to the base address */
653  if (!FindDeviceDriver(ImageBase, &Module))
654  {
655  return 0;
656  }
657 
658  /* And copy as much as possible to output buffer.
659  * Try to add 1 to the len, to copy the null char as well.
660  */
661  Len =
662  LenWithNull = strlen(&Module.FullPathName[Module.OffsetToFileName]) + 1;
663  if (Len > nSize)
664  {
665  Len = nSize;
666  }
667 
668  memcpy(lpBaseName, &Module.FullPathName[Module.OffsetToFileName], Len);
669  /* In case we copied null char, remove it from final len */
670  if (Len == LenWithNull)
671  {
672  --Len;
673  }
674 
675  return Len;
676 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
static BOOL NTAPI FindDeviceDriver(IN PVOID ImageBase, OUT PRTL_PROCESS_MODULE_INFORMATION MatchingModule)
Definition: psapi.c:42
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by GetDeviceDriverBaseNameW(), and START_TEST().

◆ GetDeviceDriverBaseNameW()

DWORD WINAPI GetDeviceDriverBaseNameW ( LPVOID  ,
LPWSTR  ,
DWORD   
)

Definition at line 723 of file psapi.c.

726 {
727  DWORD Len;
728  LPSTR BaseName;
729 
730  /* Allocate internal buffer for conversion */
731  BaseName = LocalAlloc(LMEM_FIXED, nSize);
732  if (BaseName == 0)
733  {
734  return 0;
735  }
736 
737  /* Call A API */
738  Len = GetDeviceDriverBaseNameA(ImageBase, BaseName, nSize);
739  if (Len == 0)
740  {
741  LocalFree(BaseName);
742  return 0;
743  }
744 
745  /* And convert output */
746  if (MultiByteToWideChar(CP_ACP, 0, BaseName, (Len < nSize) ? Len + 1 : Len, lpBaseName, nSize) == 0)
747  {
748  LocalFree(BaseName);
749  return 0;
750  }
751 
752  LocalFree(BaseName);
753  return Len;
754 }
#define CP_ACP
Definition: compat.h:99
DWORD WINAPI GetDeviceDriverBaseNameA(LPVOID ImageBase, LPSTR lpBaseName, DWORD nSize)
Definition: psapi.c:645
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
char * LPSTR
Definition: xmlstorage.h:182
#define LMEM_FIXED
Definition: winbase.h:349
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define MultiByteToWideChar
Definition: compat.h:100
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373

◆ GetDeviceDriverFileNameA()

DWORD WINAPI GetDeviceDriverFileNameA ( LPVOID  ,
LPSTR  ,
DWORD   
)

Definition at line 684 of file psapi.c.

687 {
688  DWORD Len, LenWithNull;
690 
691  /* Get the associated device driver to the base address */
692  if (!FindDeviceDriver(ImageBase, &Module))
693  {
694  return 0;
695  }
696 
697  /* And copy as much as possible to output buffer.
698  * Try to add 1 to the len, to copy the null char as well.
699  */
700  Len =
701  LenWithNull = strlen(Module.FullPathName) + 1;
702  if (Len > nSize)
703  {
704  Len = nSize;
705  }
706 
707  memcpy(lpFilename, Module.FullPathName, Len);
708  /* In case we copied null char, remove it from final len */
709  if (Len == LenWithNull)
710  {
711  --Len;
712  }
713 
714  return Len;
715 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
static BOOL NTAPI FindDeviceDriver(IN PVOID ImageBase, OUT PRTL_PROCESS_MODULE_INFORMATION MatchingModule)
Definition: psapi.c:42
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by GetDeviceDriverFileNameW(), and START_TEST().

◆ GetDeviceDriverFileNameW()

DWORD WINAPI GetDeviceDriverFileNameW ( LPVOID  ,
LPWSTR  ,
DWORD   
)

Definition at line 762 of file psapi.c.

765 {
766  DWORD Len;
767  LPSTR FileName;
768 
769  /* Allocate internal buffer for conversion */
771  if (FileName == 0)
772  {
773  return 0;
774  }
775 
776  /* Call A API */
778  if (Len == 0)
779  {
781  return 0;
782  }
783 
784  /* And convert output */
785  if (MultiByteToWideChar(CP_ACP, 0, FileName, (Len < nSize) ? Len + 1 : Len, lpFilename, nSize) == 0)
786  {
788  return 0;
789  }
790 
792  return Len;
793 }
#define CP_ACP
Definition: compat.h:99
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
DWORD WINAPI GetDeviceDriverFileNameA(LPVOID ImageBase, LPSTR lpFilename, DWORD nSize)
Definition: psapi.c:684
char * LPSTR
Definition: xmlstorage.h:182
#define LMEM_FIXED
Definition: winbase.h:349
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
struct _FileName FileName
Definition: fatprocs.h:884
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define MultiByteToWideChar
Definition: compat.h:100
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373

◆ GetMappedFileNameA()

DWORD WINAPI GetMappedFileNameA ( HANDLE  ,
LPVOID  ,
LPSTR  ,
DWORD   
)

Definition at line 801 of file psapi.c.

805 {
806  DWORD Len;
808 
809  DPRINT("GetMappedFileNameA(%p, %p, %p, %lu)\n", hProcess, lpv, lpFilename, nSize);
810 
811  /* Allocate internal buffer for conversion */
812  FileName = LocalAlloc(LMEM_FIXED, nSize * sizeof(WCHAR));
813  if (FileName == NULL)
814  {
815  return 0;
816  }
817 
818  /* Call W API */
820 
821  /* And convert output */
822  if (WideCharToMultiByte(CP_ACP, 0, FileName, (Len < nSize) ? Len + 1 : Len, lpFilename, nSize, NULL, NULL) == 0)
823  {
824  Len = 0;
825  }
826 
828  return Len;
829 }
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define LMEM_FIXED
Definition: winbase.h:349
DWORD WINAPI GetMappedFileNameW(HANDLE hProcess, LPVOID lpv, LPWSTR lpFilename, DWORD nSize)
Definition: psapi.c:837
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
struct _FileName FileName
Definition: fatprocs.h:884
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by test_GetMappedFileName(), and test_GetProcessImageFileName().

◆ GetMappedFileNameW()

DWORD WINAPI GetMappedFileNameW ( HANDLE  ,
LPVOID  ,
LPWSTR  ,
DWORD   
)

Definition at line 837 of file psapi.c.

841 {
842  DWORD Len;
843  SIZE_T OutSize;
845  struct
846  {
848  WCHAR CharBuffer[MAX_PATH];
849  } SectionName;
850 
851  DPRINT("GetMappedFileNameW(%p, %p, %p, %lu)\n", hProcess, lpv, lpFilename, nSize);
852 
853  /* If no buffer, no need to keep going on */
854  if (nSize == 0)
855  {
857  return 0;
858  }
859 
860  /* Query section name */
862  &SectionName, sizeof(SectionName), &OutSize);
863  if (!NT_SUCCESS(Status))
864  {
866  return 0;
867  }
868 
869  /* Prepare to copy file name */
870  Len =
871  OutSize = SectionName.SectionFileName.Length / sizeof(WCHAR);
872  if (OutSize + 1 > nSize)
873  {
874  Len = nSize - 1;
875  OutSize = nSize;
877  }
878  else
879  {
881  }
882 
883  /* Copy, zero and return */
884  memcpy(lpFilename, SectionName.SectionFileName.Buffer, Len * sizeof(WCHAR));
885  lpFilename[Len] = 0;
886 
887  return OutSize;
888 }
#define ERROR_SUCCESS
Definition: deptool.c:10
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
LONG NTSTATUS
Definition: precomp.h:26
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:4284
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
void DPRINT(...)
Definition: polytest.cpp:61
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
#define SetLastError(x)
Definition: compat.h:409
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
ULONG_PTR SIZE_T
Definition: typedefs.h:78
struct _MEMORY_SECTION_NAME MEMORY_SECTION_NAME
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by GetMappedFileNameA(), and test_GetMappedFileName().

◆ GetModuleBaseNameA()

DWORD WINAPI GetModuleBaseNameA ( HANDLE  ,
HMODULE  ,
LPSTR  ,
DWORD   
)

Definition at line 896 of file psapi.c.

900 {
901  DWORD Len;
902  PWSTR BaseName;
903 
904  /* Allocate internal buffer for conversion */
905  BaseName = LocalAlloc(LMEM_FIXED, nSize * sizeof(WCHAR));
906  if (BaseName == NULL)
907  {
908  return 0;
909  }
910 
911  /* Call W API */
913  /* And convert output */
914  if (WideCharToMultiByte(CP_ACP, 0, BaseName, (Len < nSize) ? Len + 1 : Len, lpBaseName, nSize, NULL, NULL) == 0)
915  {
916  Len = 0;
917  }
918 
919  LocalFree(BaseName);
920 
921  return Len;
922 }
#define WideCharToMultiByte
Definition: compat.h:101
uint16_t * PWSTR
Definition: typedefs.h:54
#define CP_ACP
Definition: compat.h:99
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
smooth NULL
Definition: ftsmooth.c:416
DWORD WINAPI GetModuleBaseNameW(HANDLE hProcess, HMODULE hModule, LPWSTR lpBaseName, DWORD nSize)
Definition: psapi.c:930
#define LMEM_FIXED
Definition: winbase.h:349
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
HMODULE hModule
Definition: animate.c:44

Referenced by test_EnumProcessModules(), and test_GetModuleBaseName().

◆ GetModuleBaseNameW()

DWORD WINAPI GetModuleBaseNameW ( HANDLE  ,
HMODULE  ,
LPWSTR  ,
DWORD   
)

Definition at line 930 of file psapi.c.

934 {
935  DWORD Len;
936  LDR_DATA_TABLE_ENTRY Module;
937 
938  /* Get the matching module */
939  if (!FindModule(hProcess, hModule, &Module))
940  {
941  return 0;
942  }
943 
944  /* Get the maximum len we have/can write in given size */
945  Len = Module.BaseDllName.Length + sizeof(UNICODE_NULL);
946  if (nSize * sizeof(WCHAR) < Len)
947  {
948  Len = nSize * sizeof(WCHAR);
949  }
950 
951  /* Read string */
952  if (!ReadProcessMemory(hProcess, (&Module.BaseDllName)->Buffer, lpBaseName, Len, NULL))
953  {
954  return 0;
955  }
956 
957  /* If we are at the end of the string, prepare to override to nullify string */
958  if (Len == Module.BaseDllName.Length + sizeof(UNICODE_NULL))
959  {
960  Len -= sizeof(UNICODE_NULL);
961  }
962 
963  /* Nullify at the end if needed */
964  if (Len >= nSize * sizeof(WCHAR))
965  {
966  if (nSize)
967  {
968  ASSERT(nSize >= sizeof(UNICODE_NULL));
969  lpBaseName[nSize - 1] = UNICODE_NULL;
970  }
971  }
972  /* Otherwise, nullify at last written char */
973  else
974  {
975  ASSERT(Len + sizeof(UNICODE_NULL) <= nSize * sizeof(WCHAR));
976  lpBaseName[Len / sizeof(WCHAR)] = UNICODE_NULL;
977  }
978 
979  return Len / sizeof(WCHAR);
980 }
static BOOL NTAPI FindModule(IN HANDLE hProcess, IN HMODULE hModule OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY Module)
Definition: psapi.c:131
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define ReadProcessMemory(a, b, c, d, e)
Definition: compat.h:415
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: btrfs_drv.h:1780
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:145
HMODULE hModule
Definition: animate.c:44

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

◆ GetModuleFileNameExA()

DWORD WINAPI GetModuleFileNameExA ( HANDLE  ,
HMODULE  ,
LPSTR  ,
DWORD   
)

Definition at line 988 of file psapi.c.

992 {
993  DWORD Len;
994  PWSTR Filename;
995 
996  /* Allocate internal buffer for conversion */
997  Filename = LocalAlloc(LMEM_FIXED, nSize * sizeof(WCHAR));
998  if (Filename == NULL)
999  {
1000  return 0;
1001  }
1002 
1003  /* Call W API */
1005  /* And convert output */
1006  if (WideCharToMultiByte(CP_ACP, 0, Filename, (Len < nSize) ? Len + 1 : Len, lpFilename, nSize, NULL, NULL) == 0)
1007  {
1008  Len = 0;
1009  }
1010 
1012 
1013  return Len;
1014 }
#define WideCharToMultiByte
Definition: compat.h:101
uint16_t * PWSTR
Definition: typedefs.h:54
#define CP_ACP
Definition: compat.h:99
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:925
smooth NULL
Definition: ftsmooth.c:416
#define LMEM_FIXED
Definition: winbase.h:349
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD WINAPI GetModuleFileNameExW(HANDLE hProcess, HMODULE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: psapi.c:1022
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
HMODULE hModule
Definition: animate.c:44

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

◆ GetModuleFileNameExW()

DWORD WINAPI GetModuleFileNameExW ( HANDLE  ,
HMODULE  ,
LPWSTR  ,
DWORD   
)

Definition at line 1022 of file psapi.c.

1026 {
1027  DWORD Len;
1028  LDR_DATA_TABLE_ENTRY Module;
1029 
1030  /* Get the matching module */
1031  if (!FindModule(hProcess, hModule, &Module))
1032  {
1033  return 0;
1034  }
1035 
1036  /* Get the maximum len we have/can write in given size */
1037  Len = Module.FullDllName.Length + sizeof(UNICODE_NULL);
1038  if (nSize * sizeof(WCHAR) < Len)
1039  {
1040  Len = nSize * sizeof(WCHAR);
1041  }
1042 
1043  /* Read string */
1044  if (!ReadProcessMemory(hProcess, (&Module.FullDllName)->Buffer, lpFilename, Len, NULL))
1045  {
1046  return 0;
1047  }
1048 
1049  /* If we are at the end of the string, prepare to override to nullify string */
1050  if (Len == Module.FullDllName.Length + sizeof(UNICODE_NULL))
1051  {
1052  Len -= sizeof(UNICODE_NULL);
1053  }
1054 
1055  /* Nullify at the end if needed */
1056  if (Len >= nSize * sizeof(WCHAR))
1057  {
1058  if (nSize)
1059  {
1060  ASSERT(nSize >= sizeof(UNICODE_NULL));
1061  lpFilename[nSize - 1] = UNICODE_NULL;
1062  }
1063  }
1064  /* Otherwise, nullify at last written char */
1065  else
1066  {
1067  ASSERT(Len + sizeof(UNICODE_NULL) <= nSize * sizeof(WCHAR));
1068  lpFilename[Len / sizeof(WCHAR)] = UNICODE_NULL;
1069  }
1070 
1071  return Len / sizeof(WCHAR);
1072 }
static BOOL NTAPI FindModule(IN HANDLE hProcess, IN HMODULE hModule OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY Module)
Definition: psapi.c:131
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define ReadProcessMemory(a, b, c, d, e)
Definition: compat.h:415
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: btrfs_drv.h:1780
UNICODE_STRING FullDllName
Definition: btrfs_drv.h:1786
HMODULE hModule
Definition: animate.c:44

Referenced by GetModuleFileNameExA().

◆ GetModuleInformation()

BOOL WINAPI GetModuleInformation ( HANDLE  ,
HMODULE  ,
LPMODULEINFO  ,
DWORD   
)

Definition at line 1080 of file psapi.c.

1084 {
1085  MODULEINFO LocalInfo;
1086  LDR_DATA_TABLE_ENTRY Module;
1087 
1088  /* Check output size */
1089  if (cb < sizeof(MODULEINFO))
1090  {
1092  return FALSE;
1093  }
1094 
1095  /* Get the matching module */
1096  if (!FindModule(hProcess, hModule, &Module))
1097  {
1098  return FALSE;
1099  }
1100 
1101  /* Get a local copy first, to check for valid pointer once */
1102  LocalInfo.lpBaseOfDll = hModule;
1103  LocalInfo.SizeOfImage = Module.SizeOfImage;
1104  LocalInfo.EntryPoint = Module.EntryPoint;
1105 
1106  /* Attempt to copy to output */
1107  _SEH2_TRY
1108  {
1109  memcpy(lpmodinfo, &LocalInfo, sizeof(LocalInfo));
1110  }
1112  {
1114  _SEH2_YIELD(return FALSE);
1115  }
1116  _SEH2_END;
1117 
1118  return TRUE;
1119 }
DWORD SizeOfImage
Definition: compat.h:568
#define TRUE
Definition: types.h:120
static BOOL NTAPI FindModule(IN HANDLE hProcess, IN HMODULE hModule OPTIONAL, OUT PLDR_DATA_TABLE_ENTRY Module)
Definition: psapi.c:131
ULONG SizeOfImage
Definition: ldrtypes.h:143
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
_SEH2_TRY
Definition: create.c:4250
LPVOID EntryPoint
Definition: compat.h:569
PVOID EntryPoint
Definition: ntddk_ex.h:203
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
LPVOID lpBaseOfDll
Definition: compat.h:567
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define SetLastError(x)
Definition: compat.h:409
static DWORD cb
Definition: integrity.c:41
Definition: btrfs_drv.h:1780
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
_SEH2_END
Definition: create.c:4424
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
HMODULE hModule
Definition: animate.c:44
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

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

◆ GetPerformanceInfo()

BOOL WINAPI GetPerformanceInfo ( PPERFORMANCE_INFORMATION  ,
DWORD   
)

Definition at line 1410 of file psapi.c.

1412 {
1413  NTSTATUS Status;
1416  SYSTEM_FILECACHE_INFORMATION SystemFileCacheInfo;
1417  PSYSTEM_PROCESS_INFORMATION ProcInfoArray, SystemProcInfo;
1418  DWORD Size = INIT_MEMORY_SIZE, Needed, ProcCount, ThreadsCount, HandleCount;
1419 
1420  /* Validate output buffer */
1421  if (cb < sizeof(PERFORMANCE_INFORMATION))
1422  {
1424  return FALSE;
1425  }
1426 
1427  /* First, gather as many information about the system as possible */
1429  &SystemBasicInfo,
1430  sizeof(SystemBasicInfo),
1431  NULL);
1432  if (!NT_SUCCESS(Status))
1433  {
1435  return FALSE;
1436  }
1437 
1439  &SystemPerfInfo,
1440  sizeof(SystemPerfInfo),
1441  NULL);
1442  if (!NT_SUCCESS(Status))
1443  {
1445  return FALSE;
1446  }
1447 
1449  &SystemFileCacheInfo,
1450  sizeof(SystemFileCacheInfo),
1451  NULL);
1452  if (!NT_SUCCESS(Status))
1453  {
1455  return FALSE;
1456  }
1457 
1458  /* Then loop till we have all the information about processes */
1459  do
1460  {
1461  ProcInfoArray = LocalAlloc(LMEM_FIXED, Size);
1462  if (ProcInfoArray == NULL)
1463  {
1465  return FALSE;
1466  }
1467 
1469  ProcInfoArray,
1470  Size,
1471  &Needed);
1472  if (NT_SUCCESS(Status))
1473  {
1474  break;
1475  }
1476 
1477  LocalFree(ProcInfoArray);
1478 
1479  /* In case we have unexpected status, quit */
1481  {
1483  return FALSE;
1484  }
1485 
1486  /* If needed size is smaller than actual size, guess it's something to add to our current size */
1487  if (Needed <= Size)
1488  {
1489  Size += Needed;
1490  }
1491  /* Otherwise, take it as size to allocate */
1492  else
1493  {
1494  Size = Needed;
1495  }
1496  } while (TRUE);
1497 
1498  /* Start browsing all our entries */
1499  ProcCount = 0;
1500  HandleCount = 0;
1501  ThreadsCount = 0;
1502  SystemProcInfo = ProcInfoArray;
1503  do
1504  {
1505  /* Ensure we really have an entry */
1506  if (Needed < sizeof(SYSTEM_PROCESS_INFORMATION))
1507  {
1508  break;
1509  }
1510 
1511  /* Sum procs, threads and handles */
1512  ++ProcCount;
1513  ThreadsCount += SystemProcInfo->NumberOfThreads;
1514  HandleCount += SystemProcInfo->HandleCount;
1515 
1516  /* If no next entry, then, it's over */
1517  if (SystemProcInfo->NextEntryOffset == 0 || SystemProcInfo->NextEntryOffset > Needed)
1518  {
1519  break;
1520  }
1521 
1522  /* Jump to next entry while keeping accurate bytes left count */
1523  Needed -= SystemProcInfo->NextEntryOffset;
1524  SystemProcInfo = (PSYSTEM_PROCESS_INFORMATION)((ULONG_PTR)SystemProcInfo + SystemProcInfo->NextEntryOffset);
1525  }
1526  while (TRUE);
1527 
1528  LocalFree(ProcInfoArray);
1529 
1530  /* Output data */
1531  pPerformanceInformation->CommitTotal = SystemPerfInfo.CommittedPages;
1532  pPerformanceInformation->CommitLimit = SystemPerfInfo.CommitLimit;
1533  pPerformanceInformation->CommitPeak = SystemPerfInfo.PeakCommitment;
1534  pPerformanceInformation->PhysicalTotal = SystemBasicInfo.NumberOfPhysicalPages;
1535  pPerformanceInformation->PhysicalAvailable = SystemPerfInfo.AvailablePages;
1536  pPerformanceInformation->SystemCache = SystemFileCacheInfo.CurrentSizeIncludingTransitionInPages;
1537  pPerformanceInformation->KernelNonpaged = SystemPerfInfo.NonPagedPoolPages;
1538  pPerformanceInformation->PageSize = SystemBasicInfo.PageSize;
1539  pPerformanceInformation->cb = sizeof(PERFORMANCE_INFORMATION);
1540  pPerformanceInformation->KernelTotal = SystemPerfInfo.PagedPoolPages + SystemPerfInfo.NonPagedPoolPages;
1541  pPerformanceInformation->KernelPaged = SystemPerfInfo.PagedPoolPages;
1542  pPerformanceInformation->HandleCount = HandleCount;
1543  pPerformanceInformation->ProcessCount = ProcCount;
1544  pPerformanceInformation->ThreadCount = ThreadsCount;
1545 
1546  return TRUE;
1547 }
#define INIT_MEMORY_SIZE
Definition: psapi.c:34
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
SIZE_T CurrentSizeIncludingTransitionInPages
Definition: extypes.h:1115
smooth NULL
Definition: ftsmooth.c:416
#define SystemPerformanceInformation
Definition: memtest.h:87
SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo
Definition: perfdata.c:44
#define LMEM_FIXED
Definition: winbase.h:349
struct _PERFORMANCE_INFORMATION PERFORMANCE_INFORMATION
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
SYSTEM_BASIC_INFORMATION SystemBasicInfo
Definition: perfdata.c:45
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
static DWORD cb
Definition: integrity.c:41
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
struct _SYSTEM_PROCESS_INFORMATION * PSYSTEM_PROCESS_INFORMATION
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373

Referenced by test_GetPerformanceInfo().

◆ GetProcessImageFileNameA()

DWORD WINAPI GetProcessImageFileNameA ( HANDLE  ,
LPSTR  ,
DWORD   
)

Definition at line 1232 of file psapi.c.

1235 {
1236  PUNICODE_STRING ImageFileName;
1238  NTSTATUS Status;
1239  DWORD Len;
1240 
1241  /* Allocate string big enough to hold name */
1242  BufferSize = sizeof(UNICODE_STRING) + (nSize * sizeof(WCHAR));
1243  ImageFileName = LocalAlloc(LMEM_FIXED, BufferSize);
1244  if (ImageFileName == NULL)
1245  {
1246  return 0;
1247  }
1248 
1249  /* Query name */
1252  ImageFileName,
1253  BufferSize,
1254  NULL);
1255  /* Len mismatch => buffer too small */
1257  {
1259  }
1260  if (!NT_SUCCESS(Status))
1261  {
1263  LocalFree(ImageFileName);
1264  return 0;
1265  }
1266 
1267  /* Copy name */
1268  Len = WideCharToMultiByte(CP_ACP, 0, ImageFileName->Buffer,
1269  ImageFileName->Length, lpImageFileName, nSize, NULL, NULL);
1270  /* If conversion was successful, don't return len with added \0 */
1271  if (Len != 0)
1272  {
1273  Len -= sizeof(ANSI_NULL);
1274  }
1275 
1276  LocalFree(ImageFileName);
1277  return Len;
1278 }
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
#define ANSI_NULL
smooth NULL
Definition: ftsmooth.c:416
#define LMEM_FIXED
Definition: winbase.h:349
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BufferSize
Definition: classpnp.h:419
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
#define SetLastError(x)
Definition: compat.h:409
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
ULONG_PTR SIZE_T
Definition: typedefs.h:78
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
struct _UNICODE_STRING UNICODE_STRING
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373

Referenced by test_GetProcessImageFileName().

◆ GetProcessImageFileNameW()

DWORD WINAPI GetProcessImageFileNameW ( HANDLE  ,
LPWSTR  ,
DWORD   
)

Definition at line 1179 of file psapi.c.

1182 {
1183  PUNICODE_STRING ImageFileName;
1185  NTSTATUS Status;
1186  DWORD Len;
1187 
1188  /* Allocate string big enough to hold name */
1189  BufferSize = sizeof(UNICODE_STRING) + (nSize * sizeof(WCHAR));
1190  ImageFileName = LocalAlloc(LMEM_FIXED, BufferSize);
1191  if (ImageFileName == NULL)
1192  {
1193  return 0;
1194  }
1195 
1196  /* Query name */
1199  ImageFileName,
1200  BufferSize,
1201  NULL);
1202  /* Len mismatch => buffer too small */
1204  {
1206  }
1207  if (!NT_SUCCESS(Status))
1208  {
1210  LocalFree(ImageFileName);
1211  return 0;
1212  }
1213 
1214  /* Copy name and null-terminate if possible */
1215  memcpy(lpImageFileName, ImageFileName->Buffer, ImageFileName->Length);
1216  Len = ImageFileName->Length / sizeof(WCHAR);
1217  if (Len < nSize)
1218  {
1219  lpImageFileName[Len] = UNICODE_NULL;
1220  }
1221 
1222  LocalFree(ImageFileName);
1223  return Len;
1224 }
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
#define LMEM_FIXED
Definition: winbase.h:349
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BufferSize
Definition: classpnp.h:419
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
#define SetLastError(x)
Definition: compat.h:409
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
ULONG_PTR SIZE_T
Definition: typedefs.h:78
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
struct _UNICODE_STRING UNICODE_STRING
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373

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

◆ GetProcessMemoryInfo()

BOOL WINAPI GetProcessMemoryInfo ( HANDLE  ,
PPROCESS_MEMORY_COUNTERS  ,
DWORD   
)

Definition at line 1555 of file psapi.c.

1558 {
1559  NTSTATUS Status;
1560  VM_COUNTERS_EX Counters;
1561 
1562  /* Validate output size
1563  * It can be either PROCESS_MEMORY_COUNTERS or PROCESS_MEMORY_COUNTERS_EX
1564  */
1565  if (cb < sizeof(PROCESS_MEMORY_COUNTERS))
1566  {
1568  return FALSE;
1569  }
1570 
1571  _SEH2_TRY
1572  {
1573  ppsmemCounters->PeakPagefileUsage = 0;
1574 
1575  /* Query counters */
1578  &Counters,
1579  sizeof(Counters),
1580  NULL);
1581  if (!NT_SUCCESS(Status))
1582  {
1584  _SEH2_YIELD(return FALSE);
1585  }
1586 
1587  /* Properly set cb, according to what we received */
1588  if (cb >= sizeof(PROCESS_MEMORY_COUNTERS_EX))
1589  {
1590  ppsmemCounters->cb = sizeof(PROCESS_MEMORY_COUNTERS_EX);
1591  }
1592  else
1593  {
1594  ppsmemCounters->cb = sizeof(PROCESS_MEMORY_COUNTERS);
1595  }
1596 
1597  /* Output data */
1598  ppsmemCounters->PageFaultCount = Counters.PageFaultCount;
1599  ppsmemCounters->PeakWorkingSetSize = Counters.PeakWorkingSetSize;
1600  ppsmemCounters->WorkingSetSize = Counters.WorkingSetSize;
1601  ppsmemCounters->QuotaPeakPagedPoolUsage = Counters.QuotaPeakPagedPoolUsage;
1602  ppsmemCounters->QuotaPagedPoolUsage = Counters.QuotaPagedPoolUsage;
1603  ppsmemCounters->QuotaPeakNonPagedPoolUsage = Counters.QuotaPeakNonPagedPoolUsage;
1604  ppsmemCounters->QuotaNonPagedPoolUsage = Counters.QuotaNonPagedPoolUsage;
1605  ppsmemCounters->PagefileUsage = Counters.PagefileUsage;
1606  ppsmemCounters->PeakPagefileUsage = Counters.PeakPagefileUsage;
1607  /* And if needed, additional field for _EX version */
1608  if (cb >= sizeof(PROCESS_MEMORY_COUNTERS_EX))
1609  {
1610  ((PPROCESS_MEMORY_COUNTERS_EX)ppsmemCounters)->PrivateUsage = Counters.PrivateUsage;
1611  }
1612  }
1614  {
1616  _SEH2_YIELD(return FALSE);
1617  }
1618  _SEH2_END;
1619 
1620  return TRUE;
1621 }
ULONG PageFaultCount
Definition: pstypes.h:108
#define TRUE
Definition: types.h:120
SIZE_T PeakPagefileUsage
Definition: pstypes.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
SIZE_T WorkingSetSize
Definition: pstypes.h:110
SIZE_T QuotaNonPagedPoolUsage
Definition: pstypes.h:114
_SEH2_TRY
Definition: create.c:4250
struct _PROCESS_MEMORY_COUNTERS_EX PROCESS_MEMORY_COUNTERS_EX
SIZE_T QuotaPeakNonPagedPoolUsage
Definition: pstypes.h:113
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
SIZE_T PrivateUsage
Definition: pstypes.h:117
SIZE_T QuotaPagedPoolUsage
Definition: pstypes.h:112
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
static DWORD cb
Definition: integrity.c:41
struct _PROCESS_MEMORY_COUNTERS_EX * PPROCESS_MEMORY_COUNTERS_EX
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
_SEH2_END
Definition: create.c:4424
struct _PROCESS_MEMORY_COUNTERS PROCESS_MEMORY_COUNTERS
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
SIZE_T PeakWorkingSetSize
Definition: pstypes.h:109
SIZE_T PagefileUsage
Definition: pstypes.h:115
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
SIZE_T QuotaPeakPagedPoolUsage
Definition: pstypes.h:111
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by test_GetProcessMemoryInfo().

◆ GetWsChanges()

BOOL WINAPI GetWsChanges ( HANDLE  ,
PPSAPI_WS_WATCH_INFORMATION  ,
DWORD   
)

Definition at line 1152 of file psapi.c.

1155 {
1156  NTSTATUS Status;
1157 
1158  /* Simply forward the call */
1161  lpWatchInfo,
1162  cb,
1163  NULL);
1164  if(!NT_SUCCESS(Status))
1165  {
1167  return FALSE;
1168  }
1169 
1170  return TRUE;
1171 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
static DWORD cb
Definition: integrity.c:41
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)

Referenced by test_ws_functions().

◆ InitializeProcessForWsWatch()

BOOL WINAPI InitializeProcessForWsWatch ( HANDLE  )

Definition at line 1127 of file psapi.c.

1128 {
1129  NTSTATUS Status;
1130 
1131  /* Simply forward the call */
1134  NULL,
1135  0);
1136  /* In case the function returns this, MS considers the call as a success */
1138  {
1139  return TRUE;
1140  }
1141 
1143  return FALSE;
1144 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define SetLastError(x)
Definition: compat.h:409
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112
#define STATUS_PORT_ALREADY_SET
Definition: ntstatus.h:294

Referenced by test_ws_functions().

◆ QueryWorkingSet()

BOOL WINAPI QueryWorkingSet ( HANDLE  ,
PVOID  ,
DWORD   
)

Definition at line 1629 of file psapi.c.

1632 {
1633  NTSTATUS Status;
1634 
1635  /* Simply forward the call */
1637  NULL,
1639  pv,
1640  cb,
1641  NULL);
1642  if (!NT_SUCCESS(Status))
1643  {
1645  return FALSE;
1646  }
1647 
1648  return TRUE;
1649 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
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:4284
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
static DWORD cb
Definition: integrity.c:41
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)

Referenced by test_ws_functions().