The Gaudi Framework  master (37c0b60a)
Win32PsApi.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 //====================================================================
12 // Win32PsApi.h
13 //--------------------------------------------------------------------
14 //
15 // Package : System (The LHCb System service)
16 //
17 // Description: Definition of Systems internals for WIN32
18 // This file is NOT meant to be used outside this
19 // sub-package!
20 //
21 // Author : M.Frank
22 // Created : 13/11/00
23 // Changes :
24 //====================================================================
25 #ifndef GAUDI_SYSTEM_WIN32PSAPI_H
26 #define GAUDI_SYSTEM_WIN32PSAPI_H
27 #ifdef _WIN32
28 typedef struct _MODULEINFO {
29  LPVOID lpBaseOfDll;
30  DWORD SizeOfImage;
31  LPVOID EntryPoint;
32 } MODULEINFO, *LPMODULEINFO;
33 typedef struct _PSAPI_WS_WATCH_INFORMATION {
34  LPVOID FaultingPc;
35  LPVOID FaultingVa;
36 } PSAPI_WS_WATCH_INFORMATION, *PPSAPI_WS_WATCH_INFORMATION;
37 typedef struct _PROCESS_MEMORY_COUNTERS {
38  DWORD cb;
39  DWORD PageFaultCount;
40  DWORD PeakWorkingSetSize;
41  DWORD WorkingSetSize;
42  DWORD QuotaPeakPagedPoolUsage;
43  DWORD QuotaPagedPoolUsage;
44  DWORD QuotaPeakNonPagedPoolUsage;
45  DWORD QuotaNonPagedPoolUsage;
46  DWORD PagefileUsage;
47  DWORD PeakPagefileUsage;
48 } PROCESS_MEMORY_COUNTERS;
49 typedef PROCESS_MEMORY_COUNTERS* PPROCESS_MEMORY_COUNTERS;
50 
51 class PsApiFunctions {
52 public:
53  bool m_isValid;
54  BOOL( WINAPI* EnumProcesses )( DWORD* lpidProcess, DWORD cb, DWORD* cbNeeded );
55  BOOL( WINAPI* EnumProcessModules )( HANDLE hProcess, HINSTANCE* lphModule, DWORD cb, LPDWORD lpcbNeeded );
56  DWORD( WINAPI* GetModuleBaseNameA )( HANDLE hProcess, HINSTANCE hModule, LPSTR lpBaseName, DWORD nSize );
57  DWORD( WINAPI* GetModuleFileNameExA )( HANDLE hProcess, HINSTANCE hModule, LPSTR lpFilename, DWORD nSize );
58  BOOL( WINAPI* GetModuleInformation )( HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb );
59  BOOL( WINAPI* EmptyWorkingSet )( HANDLE hProcess );
60  BOOL( WINAPI* QueryWorkingSet )( HANDLE hProcess, PVOID pv, DWORD cb );
61  BOOL( WINAPI* InitializeProcessForWsWatch )( HANDLE hProcess );
62  BOOL( WINAPI* GetWsChanges )( HANDLE hProcess, PPSAPI_WS_WATCH_INFORMATION lpWatchInfo, DWORD cb );
63  DWORD( WINAPI* GetMappedFileNameA )( HANDLE hProcess, LPVOID lpv, LPSTR lpFilename, DWORD nSize );
64  BOOL( WINAPI* EnumDeviceDrivers )( LPVOID* lpImageBase, DWORD cb, LPDWORD lpcbNeeded );
65  DWORD( WINAPI* GetDeviceDriverBaseNameA )( LPVOID ImageBase, LPSTR lpBaseName, DWORD nSize );
66  DWORD( WINAPI* GetDeviceDriverFileNameA )( LPVOID ImageBase, LPSTR lpFilename, DWORD nSize );
67  BOOL( WINAPI* GetProcessMemoryInfo )( HANDLE Process, PPROCESS_MEMORY_COUNTERS ppsmemCounters, DWORD cb );
68  void load( HINSTANCE handle, const char* name, void** pFunction ) {
69  *pFunction = (void*)::GetProcAddress( handle, name );
70  if ( 0 == *pFunction ) m_isValid = false;
71  }
72  bool isValid() const { return m_isValid; }
73  PsApiFunctions() {
74  m_isValid = true;
75  HINSTANCE mh = ::LoadLibrary( "PSAPI.DLL" );
76  if ( 0 == mh ) {
77  m_isValid = false;
78  } else {
79  load( mh, "EnumProcesses", (void**)&EnumProcesses );
80  load( mh, "EnumProcessModules", (void**)&EnumProcessModules );
81  load( mh, "GetModuleBaseNameA", (void**)&GetModuleBaseNameA );
82  load( mh, "GetModuleFileNameExA", (void**)&GetModuleFileNameExA );
83  load( mh, "GetModuleInformation", (void**)&GetModuleInformation );
84  load( mh, "EmptyWorkingSet", (void**)&EmptyWorkingSet );
85  load( mh, "QueryWorkingSet", (void**)&QueryWorkingSet );
86  load( mh, "InitializeProcessForWsWatch", (void**)&InitializeProcessForWsWatch );
87  load( mh, "GetWsChanges", (void**)&GetWsChanges );
88  load( mh, "GetMappedFileNameA", (void**)&GetMappedFileNameA );
89  load( mh, "EnumDeviceDrivers", (void**)&EnumDeviceDrivers );
90  load( mh, "GetDeviceDriverBaseNameA", (void**)&GetDeviceDriverBaseNameA );
91  load( mh, "GetDeviceDriverFileNameA", (void**)&GetDeviceDriverFileNameA );
92  load( mh, "GetProcessMemoryInfo", (void**)&GetProcessMemoryInfo );
93  }
94  }
95 };
96 #endif
97 
98 #endif // GAUDI_SYSTEM_WIN32PSAPI_H
System::EntryPoint
unsigned long(* EntryPoint)(const unsigned long iid, void **ppvObject)
Definition of the "generic" DLL entry point function.
Definition: System.h:45
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77