From 221ae3655cdbbd49f288299bbd09996d930a5ce4 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Thu, 23 Jun 2016 18:15:39 -0300 Subject: [PATCH 2/2] [msys] Fixes for msys2 Fixes for building the lib in an msys environment with mingw32 mingw64 should work as well. --- psutil/_psutil_windows.c | 65 +++++++---------------------------- psutil/arch/windows/glpi.h | 7 ++-- psutil/arch/windows/ntextapi.h | 16 ++++++--- psutil/arch/windows/process_handles.h | 2 ++ psutil/arch/windows/services.c | 12 +++++++ 5 files changed, 41 insertions(+), 61 deletions(-) diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index ebc4368..98c01df 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -21,6 +21,10 @@ #if (_WIN32_WINNT >= 0x0600) // Windows Vista and above #include #endif +#if defined(__MINGW32__) +#include +#endif +#include #include #include #include @@ -34,8 +38,13 @@ #include "arch/windows/security.h" #include "arch/windows/process_info.h" #include "arch/windows/process_handles.h" +#ifndef __MINGW32__ #include "arch/windows/ntextapi.h" #include "arch/windows/inet_ntop.h" +#else +#include +#include +#endif #include "arch/windows/services.h" @@ -87,54 +96,8 @@ WCHAR StorageManagerName[8]; } DISK_PERFORMANCE_WIN_2008; -// --- network connections mingw32 support -#ifndef _IPRTRMIB_H -#if (_WIN32_WINNT < 0x0600) // Windows XP -typedef struct _MIB_TCP6ROW_OWNER_PID { - UCHAR ucLocalAddr[16]; - DWORD dwLocalScopeId; - DWORD dwLocalPort; - UCHAR ucRemoteAddr[16]; - DWORD dwRemoteScopeId; - DWORD dwRemotePort; - DWORD dwState; - DWORD dwOwningPid; -} MIB_TCP6ROW_OWNER_PID, *PMIB_TCP6ROW_OWNER_PID; - -typedef struct _MIB_TCP6TABLE_OWNER_PID { - DWORD dwNumEntries; - MIB_TCP6ROW_OWNER_PID table[ANY_SIZE]; -} MIB_TCP6TABLE_OWNER_PID, *PMIB_TCP6TABLE_OWNER_PID; -#endif -#endif - -#ifndef __IPHLPAPI_H__ -typedef struct in6_addr { - union { - UCHAR Byte[16]; - USHORT Word[8]; - } u; -} IN6_ADDR, *PIN6_ADDR, FAR *LPIN6_ADDR; - -typedef enum _UDP_TABLE_CLASS { - UDP_TABLE_BASIC, - UDP_TABLE_OWNER_PID, - UDP_TABLE_OWNER_MODULE -} UDP_TABLE_CLASS, *PUDP_TABLE_CLASS; - -typedef struct _MIB_UDPROW_OWNER_PID { - DWORD dwLocalAddr; - DWORD dwLocalPort; - DWORD dwOwningPid; -} MIB_UDPROW_OWNER_PID, *PMIB_UDPROW_OWNER_PID; - -typedef struct _MIB_UDPTABLE_OWNER_PID { - DWORD dwNumEntries; - MIB_UDPROW_OWNER_PID table[ANY_SIZE]; -} MIB_UDPTABLE_OWNER_PID, *PMIB_UDPTABLE_OWNER_PID; -#endif - #if (_WIN32_WINNT < 0x0600) // Windows XP +#if (!defined(__MINGW32__)) typedef struct _MIB_UDP6ROW_OWNER_PID { UCHAR ucLocalAddr[16]; DWORD dwLocalScopeId; @@ -147,6 +110,7 @@ MIB_UDP6ROW_OWNER_PID table[ANY_SIZE]; } MIB_UDP6TABLE_OWNER_PID, *PMIB_UDP6TABLE_OWNER_PID; #endif +#endif typedef struct _PROCESSOR_POWER_INFORMATION { ULONG Number; @@ -161,7 +125,7 @@ PIP_ADAPTER_ADDRESSES psutil_get_nic_addresses() { // allocate a 15 KB buffer to start with - int outBufLen = 15000; + ULONG outBufLen = 15000; DWORD dwRetVal = 0; ULONG attempts = 0; PIP_ADAPTER_ADDRESSES pAddresses = NULL; diff --git a/psutil/arch/windows/ntextapi.h b/psutil/arch/windows/ntextapi.h index 74adce2..df1f436 100644 --- a/psutil/arch/windows/ntextapi.h +++ b/psutil/arch/windows/ntextapi.h @@ -120,7 +120,7 @@ MaximumThreadState } KTHREAD_STATE, *PKTHREAD_STATE; - +#ifndef __MINGW32__ typedef enum _KWAIT_REASON { Executive = 0, FreePage = 1, @@ -170,6 +170,7 @@ #define CLIENT_ID CLIENT_ID2 #define PCLIENT_ID PCLIENT_ID2 +#endif typedef struct _SYSTEM_THREAD_INFORMATION2 { LARGE_INTEGER KernelTime; @@ -290,7 +291,7 @@ DWORD ProcessInformationLength ); - +#ifndef __MINGW32__ typedef enum _PROCESSINFOCLASS2 { _ProcessBasicInformation, ProcessQuotaLimits, @@ -342,4 +343,12 @@ #define ProcessImageFileName _ProcessImageFileName #define ProcessBreakOnTermination _ProcessBreakOnTermination +#else +// values from https://msdn.microsoft.com/en-us/library/windows/desktop/ms684280(v=vs.85).aspx +#define ProcessBasicInformation 0 +#define ProcessWow64Information 26 +#define ProcessDebugPort 7 +#define ProcessImageFileName 27 +#endif + #endif // __NTEXTAPI_H__ diff --git a/psutil/arch/windows/process_handles.h b/psutil/arch/windows/process_handles.h index ea5fbdb..583e3ff 100644 --- a/psutil/arch/windows/process_handles.h +++ b/psutil/arch/windows/process_handles.h @@ -75,6 +75,7 @@ typedef enum _POOL_TYPE { NonPagedPoolCacheAlignedMustS } POOL_TYPE, *PPOOL_TYPE; +#if !defined(__MINGW32__) typedef struct _OBJECT_TYPE_INFORMATION { UNICODE_STRING Name; ULONG TotalNumberOfObjects; @@ -99,6 +100,7 @@ typedef struct _OBJECT_TYPE_INFORMATION { ULONG PagedPoolUsage; ULONG NonPagedPoolUsage; } OBJECT_TYPE_INFORMATION, *POBJECT_TYPE_INFORMATION; +#endif // __MINGW32__ PVOID GetLibraryProcAddress(PSTR LibraryName, PSTR ProcName); VOID psutil_get_open_files_init(BOOL threaded); diff --git a/psutil/arch/windows/services.c b/psutil/arch/windows/services.c index ddfe30e..8c279f0 100644 --- a/psutil/arch/windows/services.c +++ b/psutil/arch/windows/services.c @@ -10,6 +10,18 @@ #include "services.h" +#ifdef __MINGW32__ +#if !defined(_UNICODE) && !defined(_MBCS) +#define _tcslen(x) strlen(x) +#elif defined(_UNICODE) +#define _tclsen(x) wcslen(x) +#elif defined(_MBCS) +#define _tclsen(x) strlen(x) +#else +#error "Invalid value" +#endif +#endif //__MINGW32__ + // ================================================================== // utils -- 2.7.2