diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-01-06 15:28:58 -0800 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-01-06 15:28:58 -0800 |
commit | d7476f05a73a25faf4a4aea1ac9ad7bec9879c33 (patch) | |
tree | 610fb7c2c0d718935cbb957373b0bc97e58f2038 | |
parent | 4b12537e250e6b46c0cd2f48e6d178bc1aae6532 (diff) | |
download | psutil-d7476f05a73a25faf4a4aea1ac9ad7bec9879c33.tar.gz |
get rid of globals.c; move stuff in _psutil_common.c
-rw-r--r-- | psutil/_psutil_aix.c | 5 | ||||
-rw-r--r-- | psutil/_psutil_bsd.c | 6 | ||||
-rw-r--r-- | psutil/_psutil_common.c | 208 | ||||
-rw-r--r-- | psutil/_psutil_common.h | 38 | ||||
-rw-r--r-- | psutil/_psutil_windows.c | 4 | ||||
-rw-r--r-- | psutil/arch/freebsd/specific.c | 1 | ||||
-rw-r--r-- | psutil/arch/netbsd/specific.c | 5 | ||||
-rw-r--r-- | psutil/arch/osx/process_info.c | 2 | ||||
-rw-r--r-- | psutil/arch/windows/cpu.c | 1 | ||||
-rw-r--r-- | psutil/arch/windows/disk.c | 1 | ||||
-rw-r--r-- | psutil/arch/windows/globals.c | 227 | ||||
-rw-r--r-- | psutil/arch/windows/globals.h | 34 | ||||
-rw-r--r-- | psutil/arch/windows/net.c | 2 | ||||
-rw-r--r-- | psutil/arch/windows/process_handles.c | 2 | ||||
-rw-r--r-- | psutil/arch/windows/process_info.c | 3 | ||||
-rw-r--r-- | psutil/arch/windows/process_utils.c | 3 | ||||
-rw-r--r-- | psutil/arch/windows/security.c | 1 | ||||
-rw-r--r-- | psutil/arch/windows/services.c | 3 | ||||
-rw-r--r-- | psutil/arch/windows/socks.c | 3 | ||||
-rwxr-xr-x | setup.py | 1 |
20 files changed, 256 insertions, 294 deletions
diff --git a/psutil/_psutil_aix.c b/psutil/_psutil_aix.c index 9f58f606..d7fcaefc 100644 --- a/psutil/_psutil_aix.c +++ b/psutil/_psutil_aix.c @@ -29,7 +29,6 @@ */ #include <Python.h> - #include <sys/limits.h> #include <sys/proc.h> #include <sys/procfs.h> @@ -51,11 +50,11 @@ #include <libperfstat.h> #include <unistd.h> +#include "_psutil_common.h" +#include "_psutil_posix.h" #include "arch/aix/ifaddrs.h" #include "arch/aix/net_connections.h" #include "arch/aix/common.h" -#include "_psutil_common.h" -#include "_psutil_posix.h" #define TV2DOUBLE(t) (((t).tv_nsec * 0.000000001) + (t).tv_sec) diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c index 94088d73..f58cc72f 100644 --- a/psutil/_psutil_bsd.c +++ b/psutil/_psutil_bsd.c @@ -31,7 +31,7 @@ #include <sys/param.h> #include <sys/sysctl.h> #if !defined(__NetBSD__) -#include <sys/user.h> + #include <sys/user.h> #endif #include <sys/proc.h> #include <sys/file.h> @@ -51,13 +51,10 @@ #include <netinet/tcp_var.h> // for struct xtcpcb #include <netinet/tcp_fsm.h> // for TCP connection states #include <arpa/inet.h> // for inet_ntop() - #include <sys/mount.h> - #include <net/if.h> // net io counters #include <net/if_dl.h> #include <net/route.h> - #include <netinet/in.h> // process open files/connections #include <sys/un.h> @@ -99,7 +96,6 @@ #endif - // convert a timeval struct to a double #define PSUTIL_TV2DOUBLE(t) ((t).tv_sec + (t).tv_usec / 1000000.0) diff --git a/psutil/_psutil_common.c b/psutil/_psutil_common.c index 30633c59..f67088b5 100644 --- a/psutil/_psutil_common.c +++ b/psutil/_psutil_common.c @@ -7,13 +7,8 @@ */ #include <Python.h> -#ifdef PSUTIL_WINDOWS -#include <windows.h> -#endif // !PSUTIL_WINDOWS - #include "_psutil_common.h" - // ==================================================================== // --- Global vars / constants // ==================================================================== @@ -147,3 +142,206 @@ psutil_setup(void) { PSUTIL_TESTING = 1; return 0; } + + +// ==================================================================== +// --- Windows +// ==================================================================== + +#ifdef PSUTIL_WINDOWS +#include <windows.h> + +// Needed to make these globally visible. +int PSUTIL_WINVER; +SYSTEM_INFO PSUTIL_SYSTEM_INFO; + +#define NT_FACILITY_MASK 0xfff +#define NT_FACILITY_SHIFT 16 +#define NT_FACILITY(Status) \ + ((((ULONG)(Status)) >> NT_FACILITY_SHIFT) & NT_FACILITY_MASK) +#define NT_NTWIN32(status) (NT_FACILITY(Status) == FACILITY_WIN32) +#define WIN32_FROM_NTSTATUS(Status) (((ULONG)(Status)) & 0xffff) + + +// A wrapper around GetModuleHandle and GetProcAddress. +PVOID +psutil_GetProcAddress(LPCSTR libname, LPCSTR procname) { + HMODULE mod; + FARPROC addr; + + if ((mod = GetModuleHandleA(libname)) == NULL) { + PyErr_SetFromWindowsErrWithFilename(0, libname); + return NULL; + } + if ((addr = GetProcAddress(mod, procname)) == NULL) { + PyErr_SetFromWindowsErrWithFilename(0, procname); + return NULL; + } + return addr; +} + + +// A wrapper around LoadLibrary and GetProcAddress. +PVOID +psutil_GetProcAddressFromLib(LPCSTR libname, LPCSTR procname) { + HMODULE mod; + FARPROC addr; + + Py_BEGIN_ALLOW_THREADS + mod = LoadLibraryA(libname); + Py_END_ALLOW_THREADS + if (mod == NULL) { + PyErr_SetFromWindowsErrWithFilename(0, libname); + return NULL; + } + if ((addr = GetProcAddress(mod, procname)) == NULL) { + PyErr_SetFromWindowsErrWithFilename(0, procname); + FreeLibrary(mod); + return NULL; + } + // Causes crash. + // FreeLibrary(mod); + return addr; +} + + +/* + * Convert a NTSTATUS value to a Win32 error code and set the proper + * Python exception. + */ +PVOID +psutil_SetFromNTStatusErr(NTSTATUS Status, const char *syscall) { + ULONG err; + char fullmsg[1024]; + + if (NT_NTWIN32(Status)) + err = WIN32_FROM_NTSTATUS(Status); + else + err = RtlNtStatusToDosErrorNoTeb(Status); + // if (GetLastError() != 0) + // err = GetLastError(); + sprintf(fullmsg, "(originated from %s)", syscall); + return PyErr_SetFromWindowsErrWithFilename(err, fullmsg); +} + + +static int +psutil_loadlibs() { + // --- Mandatory + NtQuerySystemInformation = psutil_GetProcAddressFromLib( + "ntdll.dll", "NtQuerySystemInformation"); + if (NtQuerySystemInformation == NULL) + return 1; + NtQueryInformationProcess = psutil_GetProcAddress( + "ntdll.dll", "NtQueryInformationProcess"); + if (! NtQueryInformationProcess) + return 1; + NtSetInformationProcess = psutil_GetProcAddress( + "ntdll.dll", "NtSetInformationProcess"); + if (! NtSetInformationProcess) + return 1; + WinStationQueryInformationW = psutil_GetProcAddressFromLib( + "winsta.dll", "WinStationQueryInformationW"); + if (! WinStationQueryInformationW) + return 1; + NtQueryObject = psutil_GetProcAddressFromLib( + "ntdll.dll", "NtQueryObject"); + if (! NtQueryObject) + return 1; + RtlIpv4AddressToStringA = psutil_GetProcAddressFromLib( + "ntdll.dll", "RtlIpv4AddressToStringA"); + if (! RtlIpv4AddressToStringA) + return 1; + GetExtendedTcpTable = psutil_GetProcAddressFromLib( + "iphlpapi.dll", "GetExtendedTcpTable"); + if (! GetExtendedTcpTable) + return 1; + GetExtendedUdpTable = psutil_GetProcAddressFromLib( + "iphlpapi.dll", "GetExtendedUdpTable"); + if (! GetExtendedUdpTable) + return 1; + RtlGetVersion = psutil_GetProcAddressFromLib( + "ntdll.dll", "RtlGetVersion"); + if (! RtlGetVersion) + return 1; + NtSuspendProcess = psutil_GetProcAddressFromLib( + "ntdll", "NtSuspendProcess"); + if (! NtSuspendProcess) + return 1; + NtResumeProcess = psutil_GetProcAddressFromLib( + "ntdll", "NtResumeProcess"); + if (! NtResumeProcess) + return 1; + NtQueryVirtualMemory = psutil_GetProcAddressFromLib( + "ntdll", "NtQueryVirtualMemory"); + if (! NtQueryVirtualMemory) + return 1; + RtlNtStatusToDosErrorNoTeb = psutil_GetProcAddressFromLib( + "ntdll", "RtlNtStatusToDosErrorNoTeb"); + if (! RtlNtStatusToDosErrorNoTeb) + return 1; + + // --- Optional + // not available on Wine + RtlIpv6AddressToStringA = psutil_GetProcAddressFromLib( + "ntdll.dll", "RtlIpv6AddressToStringA"); + // minimum requirement: Win Vista + GetTickCount64 = psutil_GetProcAddress( + "kernel32", "GetTickCount64"); + // minimum requirement: Win 7 + GetActiveProcessorCount = psutil_GetProcAddress( + "kernel32", "GetActiveProcessorCount"); + // minumum requirement: Win 7 + GetLogicalProcessorInformationEx = psutil_GetProcAddressFromLib( + "kernel32", "GetLogicalProcessorInformationEx"); + + PyErr_Clear(); + return 0; +} + + +static int +psutil_set_winver() { + RTL_OSVERSIONINFOEXW versionInfo; + ULONG maj; + ULONG min; + + versionInfo.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW); + memset(&versionInfo, 0, sizeof(RTL_OSVERSIONINFOEXW)); + RtlGetVersion((PRTL_OSVERSIONINFOW)&versionInfo); + maj = versionInfo.dwMajorVersion; + min = versionInfo.dwMinorVersion; + if (maj == 6 && min == 0) + PSUTIL_WINVER = PSUTIL_WINDOWS_VISTA; // or Server 2008 + else if (maj == 6 && min == 1) + PSUTIL_WINVER = PSUTIL_WINDOWS_7; + else if (maj == 6 && min == 2) + PSUTIL_WINVER = PSUTIL_WINDOWS_8; + else if (maj == 6 && min == 3) + PSUTIL_WINVER = PSUTIL_WINDOWS_8_1; + else if (maj == 10 && min == 0) + PSUTIL_WINVER = PSUTIL_WINDOWS_10; + else + PSUTIL_WINVER = PSUTIL_WINDOWS_NEW; + return 0; +} + + +static int +psutil_load_sysinfo() { + GetSystemInfo(&PSUTIL_SYSTEM_INFO); + return 0; +} + + +int +psutil_load_globals() { + if (psutil_loadlibs() != 0) + return 1; + if (psutil_set_winver() != 0) + return 1; + if (psutil_load_sysinfo() != 0) + return 1; + return 0; +} +#endif // PSUTIL_WINDOWS diff --git a/psutil/_psutil_common.h b/psutil/_psutil_common.h index 8b069d9f..f36e1321 100644 --- a/psutil/_psutil_common.h +++ b/psutil/_psutil_common.h @@ -20,8 +20,8 @@ static const int PSUTIL_CONN_NONE = 128; // ==================================================================== #if PY_MAJOR_VERSION < 3 -PyObject* PyUnicode_DecodeFSDefault(char *s); -PyObject* PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size); + PyObject* PyUnicode_DecodeFSDefault(char *s); + PyObject* PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size); #endif PyObject* PyErr_SetFromOSErrnoWithSyscall(const char *syscall); @@ -39,3 +39,37 @@ PyObject* NoSuchProcess(const char *msg); PyObject* psutil_set_testing(PyObject *self, PyObject *args); void psutil_debug(const char* format, ...); int psutil_setup(void); + +// ==================================================================== +// --- Windows +// ==================================================================== + +#ifdef PSUTIL_WINDOWS + #include <windows.h> + // make it available to any file which includes this module + #include "arch/windows/ntextapi.h" + + extern int PSUTIL_WINVER; + extern SYSTEM_INFO PSUTIL_SYSTEM_INFO; + + #define PSUTIL_WINDOWS_VISTA 60 + #define PSUTIL_WINDOWS_7 61 + #define PSUTIL_WINDOWS_8 62 + #define PSUTIL_WINDOWS_8_1 63 + #define PSUTIL_WINDOWS_10 100 + #define PSUTIL_WINDOWS_NEW MAXLONG + + #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) + #define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) + #define LO_T 1e-7 + #define HI_T 429.4967296 + + #ifndef AF_INET6 + #define AF_INET6 23 + #endif + + int psutil_load_globals(); + PVOID psutil_GetProcAddress(LPCSTR libname, LPCSTR procname); + PVOID psutil_GetProcAddressFromLib(LPCSTR libname, LPCSTR procname); + PVOID psutil_SetFromNTStatusErr(NTSTATUS Status, const char *syscall); +#endif diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index c03324f8..dd336489 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -27,8 +27,7 @@ // Link with Iphlpapi.lib #pragma comment(lib, "IPHLPAPI.lib") -#include "arch/windows/ntextapi.h" -#include "arch/windows/globals.h" +#include "_psutil_common.h" #include "arch/windows/security.h" #include "arch/windows/process_utils.h" #include "arch/windows/process_info.h" @@ -39,7 +38,6 @@ #include "arch/windows/services.h" #include "arch/windows/socks.h" #include "arch/windows/wmi.h" -#include "_psutil_common.h" // Raised by Process.wait(). static PyObject *TimeoutExpired; diff --git a/psutil/arch/freebsd/specific.c b/psutil/arch/freebsd/specific.c index 26b80242..bc267acd 100644 --- a/psutil/arch/freebsd/specific.c +++ b/psutil/arch/freebsd/specific.c @@ -28,6 +28,7 @@ #include "../../_psutil_common.h" #include "../../_psutil_posix.h" + #define PSUTIL_TV2DOUBLE(t) ((t).tv_sec + (t).tv_usec / 1000000.0) #define PSUTIL_BT2MSEC(bt) (bt.sec * 1000 + (((uint64_t) 1000000000 * (uint32_t) \ (bt.frac >> 32) ) >> 32 ) / 1000000) diff --git a/psutil/arch/netbsd/specific.c b/psutil/arch/netbsd/specific.c index 25adffcd..681b2377 100644 --- a/psutil/arch/netbsd/specific.c +++ b/psutil/arch/netbsd/specific.c @@ -31,15 +31,16 @@ #include <sys/socket.h> #include <sys/sched.h> // for CPUSTATES & CP_* #define _KERNEL // for DTYPE_* -#include <sys/file.h> + #include <sys/file.h> #undef _KERNEL #include <sys/disk.h> // struct diskstats #include <netinet/in.h> #include <arpa/inet.h> -#include "specific.h" #include "../../_psutil_common.h" #include "../../_psutil_posix.h" +#include "specific.h" + #define PSUTIL_KPT2DOUBLE(t) (t ## _sec + t ## _usec / 1000000.0) #define PSUTIL_TV2DOUBLE(t) ((t).tv_sec + (t).tv_usec / 1000000.0) diff --git a/psutil/arch/osx/process_info.c b/psutil/arch/osx/process_info.c index d21c048e..9877fd6b 100644 --- a/psutil/arch/osx/process_info.c +++ b/psutil/arch/osx/process_info.c @@ -19,9 +19,9 @@ #include <sys/sysctl.h> #include <libproc.h> -#include "process_info.h" #include "../../_psutil_common.h" #include "../../_psutil_posix.h" +#include "process_info.h" /* * Returns a list of all BSD processes on the system. This routine diff --git a/psutil/arch/windows/cpu.c b/psutil/arch/windows/cpu.c index 6966aa18..9a22e149 100644 --- a/psutil/arch/windows/cpu.c +++ b/psutil/arch/windows/cpu.c @@ -8,7 +8,6 @@ #include <windows.h> #include <PowrProf.h> -#include "globals.h" #include "../../_psutil_common.h" diff --git a/psutil/arch/windows/disk.c b/psutil/arch/windows/disk.c index e927bf2e..45e0ee1e 100644 --- a/psutil/arch/windows/disk.c +++ b/psutil/arch/windows/disk.c @@ -8,7 +8,6 @@ #include <windows.h> #include <tchar.h> -#include "globals.h" #include "../../_psutil_common.h" diff --git a/psutil/arch/windows/globals.c b/psutil/arch/windows/globals.c deleted file mode 100644 index 27d9020c..00000000 --- a/psutil/arch/windows/globals.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * This code is executed on import. It loads private/undocumented - * Windows APIs and sets Windows version constants so that they are - * available globally. - */ - -#include <windows.h> -#include <Python.h> -#include "globals.h" - - -// Needed to make these globally visible. -int PSUTIL_WINVER; -SYSTEM_INFO PSUTIL_SYSTEM_INFO; - -#define NT_FACILITY_MASK 0xfff -#define NT_FACILITY_SHIFT 16 -#define NT_FACILITY(Status) \ - ((((ULONG)(Status)) >> NT_FACILITY_SHIFT) & NT_FACILITY_MASK) -#define NT_NTWIN32(status) (NT_FACILITY(Status) == FACILITY_WIN32) -#define WIN32_FROM_NTSTATUS(Status) (((ULONG)(Status)) & 0xffff) - - -// A wrapper around GetModuleHandle and GetProcAddress. -PVOID -psutil_GetProcAddress(LPCSTR libname, LPCSTR procname) { - HMODULE mod; - FARPROC addr; - - if ((mod = GetModuleHandleA(libname)) == NULL) { - PyErr_SetFromWindowsErrWithFilename(0, libname); - return NULL; - } - if ((addr = GetProcAddress(mod, procname)) == NULL) { - PyErr_SetFromWindowsErrWithFilename(0, procname); - return NULL; - } - return addr; -} - - -// A wrapper around LoadLibrary and GetProcAddress. -PVOID -psutil_GetProcAddressFromLib(LPCSTR libname, LPCSTR procname) { - HMODULE mod; - FARPROC addr; - - Py_BEGIN_ALLOW_THREADS - mod = LoadLibraryA(libname); - Py_END_ALLOW_THREADS - if (mod == NULL) { - PyErr_SetFromWindowsErrWithFilename(0, libname); - return NULL; - } - if ((addr = GetProcAddress(mod, procname)) == NULL) { - PyErr_SetFromWindowsErrWithFilename(0, procname); - FreeLibrary(mod); - return NULL; - } - // Causes crash. - // FreeLibrary(mod); - return addr; -} - - -/* - * Convert a NTSTATUS value to a Win32 error code and set the proper - * Python exception. - */ -PVOID -psutil_SetFromNTStatusErr(NTSTATUS Status, const char *syscall) { - ULONG err; - char fullmsg[1024]; - - if (NT_NTWIN32(Status)) - err = WIN32_FROM_NTSTATUS(Status); - else - err = RtlNtStatusToDosErrorNoTeb(Status); - // if (GetLastError() != 0) - // err = GetLastError(); - sprintf(fullmsg, "(originated from %s)", syscall); - return PyErr_SetFromWindowsErrWithFilename(err, fullmsg); -} - - -static int -psutil_loadlibs() { - /* - * Mandatory. - */ - NtQuerySystemInformation = psutil_GetProcAddressFromLib( - "ntdll.dll", "NtQuerySystemInformation"); - if (NtQuerySystemInformation == NULL) - return 1; - - NtQueryInformationProcess = psutil_GetProcAddress( - "ntdll.dll", "NtQueryInformationProcess"); - if (! NtQueryInformationProcess) - return 1; - - NtSetInformationProcess = psutil_GetProcAddress( - "ntdll.dll", "NtSetInformationProcess"); - if (! NtSetInformationProcess) - return 1; - - WinStationQueryInformationW = psutil_GetProcAddressFromLib( - "winsta.dll", "WinStationQueryInformationW"); - if (! WinStationQueryInformationW) - return 1; - - NtQueryObject = psutil_GetProcAddressFromLib( - "ntdll.dll", "NtQueryObject"); - if (! NtQueryObject) - return 1; - - RtlIpv4AddressToStringA = psutil_GetProcAddressFromLib( - "ntdll.dll", "RtlIpv4AddressToStringA"); - if (! RtlIpv4AddressToStringA) - return 1; - - GetExtendedTcpTable = psutil_GetProcAddressFromLib( - "iphlpapi.dll", "GetExtendedTcpTable"); - if (! GetExtendedTcpTable) - return 1; - - GetExtendedUdpTable = psutil_GetProcAddressFromLib( - "iphlpapi.dll", "GetExtendedUdpTable"); - if (! GetExtendedUdpTable) - return 1; - - RtlGetVersion = psutil_GetProcAddressFromLib( - "ntdll.dll", "RtlGetVersion"); - if (! RtlGetVersion) - return 1; - - NtSuspendProcess = psutil_GetProcAddressFromLib( - "ntdll", "NtSuspendProcess"); - if (! NtSuspendProcess) - return 1; - - NtResumeProcess = psutil_GetProcAddressFromLib( - "ntdll", "NtResumeProcess"); - if (! NtResumeProcess) - return 1; - - NtQueryVirtualMemory = psutil_GetProcAddressFromLib( - "ntdll", "NtQueryVirtualMemory"); - if (! NtQueryVirtualMemory) - return 1; - - RtlNtStatusToDosErrorNoTeb = psutil_GetProcAddressFromLib( - "ntdll", "RtlNtStatusToDosErrorNoTeb"); - if (! RtlNtStatusToDosErrorNoTeb) - return 1; - - /* - * Optional. - */ - // not available on Wine - RtlIpv6AddressToStringA = psutil_GetProcAddressFromLib( - "ntdll.dll", "RtlIpv6AddressToStringA"); - - // minimum requirement: Win Vista - GetTickCount64 = psutil_GetProcAddress( - "kernel32", "GetTickCount64"); - - // minimum requirement: Win 7 - GetActiveProcessorCount = psutil_GetProcAddress( - "kernel32", "GetActiveProcessorCount"); - - // minumum requirement: Win 7 - GetLogicalProcessorInformationEx = psutil_GetProcAddressFromLib( - "kernel32", "GetLogicalProcessorInformationEx"); - - PyErr_Clear(); - return 0; -} - - -static int -psutil_set_winver() { - RTL_OSVERSIONINFOEXW versionInfo; - ULONG maj; - ULONG min; - - versionInfo.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW); - memset(&versionInfo, 0, sizeof(RTL_OSVERSIONINFOEXW)); - RtlGetVersion((PRTL_OSVERSIONINFOW)&versionInfo); - maj = versionInfo.dwMajorVersion; - min = versionInfo.dwMinorVersion; - if (maj == 6 && min == 0) - PSUTIL_WINVER = PSUTIL_WINDOWS_VISTA; // or Server 2008 - else if (maj == 6 && min == 1) - PSUTIL_WINVER = PSUTIL_WINDOWS_7; - else if (maj == 6 && min == 2) - PSUTIL_WINVER = PSUTIL_WINDOWS_8; - else if (maj == 6 && min == 3) - PSUTIL_WINVER = PSUTIL_WINDOWS_8_1; - else if (maj == 10 && min == 0) - PSUTIL_WINVER = PSUTIL_WINDOWS_10; - else - PSUTIL_WINVER = PSUTIL_WINDOWS_NEW; - return 0; -} - - -static int -psutil_load_sysinfo() { - GetSystemInfo(&PSUTIL_SYSTEM_INFO); - return 0; -} - - -int -psutil_load_globals() { - if (psutil_loadlibs() != 0) - return 1; - if (psutil_set_winver() != 0) - return 1; - if (psutil_load_sysinfo() != 0) - return 1; - return 0; -} diff --git a/psutil/arch/windows/globals.h b/psutil/arch/windows/globals.h deleted file mode 100644 index f87a4f8b..00000000 --- a/psutil/arch/windows/globals.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - - * List of constants and objects that are globally available. - */ - -#include <windows.h> -#include "ntextapi.h" // make it available to any file including us - -extern int PSUTIL_WINVER; -extern SYSTEM_INFO PSUTIL_SYSTEM_INFO; - -#define PSUTIL_WINDOWS_VISTA 60 -#define PSUTIL_WINDOWS_7 61 -#define PSUTIL_WINDOWS_8 62 -#define PSUTIL_WINDOWS_8_1 63 -#define PSUTIL_WINDOWS_10 100 -#define PSUTIL_WINDOWS_NEW MAXLONG - -#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) -#define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) -#define LO_T 1e-7 -#define HI_T 429.4967296 - -#ifndef AF_INET6 -#define AF_INET6 23 -#endif - -int psutil_load_globals(); -PVOID psutil_GetProcAddress(LPCSTR libname, LPCSTR procname); -PVOID psutil_GetProcAddressFromLib(LPCSTR libname, LPCSTR procname); -PVOID psutil_SetFromNTStatusErr(NTSTATUS Status, const char *syscall); diff --git a/psutil/arch/windows/net.c b/psutil/arch/windows/net.c index fc083540..f0572d52 100644 --- a/psutil/arch/windows/net.c +++ b/psutil/arch/windows/net.c @@ -12,7 +12,7 @@ #include <wchar.h> #include <ws2tcpip.h> -#include "globals.h" +#include "../../_psutil_common.h" static PIP_ADAPTER_ADDRESSES diff --git a/psutil/arch/windows/process_handles.c b/psutil/arch/windows/process_handles.c index bb1ab42c..71c6bfd9 100644 --- a/psutil/arch/windows/process_handles.c +++ b/psutil/arch/windows/process_handles.c @@ -9,7 +9,7 @@ #include <Psapi.h> // GetMappedFileName() #include <Python.h> -#include "globals.h" +#include "../../_psutil_common.h" #include "process_utils.h" CRITICAL_SECTION g_cs; diff --git a/psutil/arch/windows/process_info.c b/psutil/arch/windows/process_info.c index 14e8cecf..1c5a3c33 100644 --- a/psutil/arch/windows/process_info.c +++ b/psutil/arch/windows/process_info.c @@ -10,10 +10,9 @@ #include <Python.h> #include <windows.h> -#include "globals.h" +#include "../../_psutil_common.h" #include "process_info.h" #include "process_utils.h" -#include "../../_psutil_common.h" #ifndef _WIN64 diff --git a/psutil/arch/windows/process_utils.c b/psutil/arch/windows/process_utils.c index d9997ad0..fd516bea 100644 --- a/psutil/arch/windows/process_utils.c +++ b/psutil/arch/windows/process_utils.c @@ -10,9 +10,8 @@ #include <windows.h> #include <Psapi.h> // EnumProcesses -#include "globals.h" -#include "process_utils.h" #include "../../_psutil_common.h" +#include "process_utils.h" DWORD * diff --git a/psutil/arch/windows/security.c b/psutil/arch/windows/security.c index fa838004..7e400a25 100644 --- a/psutil/arch/windows/security.c +++ b/psutil/arch/windows/security.c @@ -9,6 +9,7 @@ #include <windows.h> #include <Python.h> + #include "../../_psutil_common.h" diff --git a/psutil/arch/windows/services.c b/psutil/arch/windows/services.c index 839cf79e..a91cb8f7 100644 --- a/psutil/arch/windows/services.c +++ b/psutil/arch/windows/services.c @@ -8,8 +8,9 @@ #include <windows.h> #include <Winsvc.h> -#include "services.h" #include "../../_psutil_common.h" +#include "services.h" + // ================================================================== // utils diff --git a/psutil/arch/windows/socks.c b/psutil/arch/windows/socks.c index f46ffaee..b316ddb8 100644 --- a/psutil/arch/windows/socks.c +++ b/psutil/arch/windows/socks.c @@ -11,9 +11,8 @@ #include <windows.h> #include <ws2tcpip.h> -#include "globals.h" -#include "process_utils.h" #include "../../_psutil_common.h" +#include "process_utils.h" #define BYTESWAP_USHORT(x) ((((USHORT)(x) << 8) | ((USHORT)(x) >> 8)) & 0xffff) @@ -150,7 +150,6 @@ if WINDOWS: 'psutil/arch/windows/cpu.c', 'psutil/arch/windows/security.c', 'psutil/arch/windows/services.c', - 'psutil/arch/windows/globals.c', 'psutil/arch/windows/socks.c', 'psutil/arch/windows/wmi.c', ], |