243 lines
7.0 KiB
Diff
243 lines
7.0 KiB
Diff
From 221ae3655cdbbd49f288299bbd09996d930a5ce4 Mon Sep 17 00:00:00 2001
|
|
From: Manuel Naranjo <naranjo.manuel@gmail.com>
|
|
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 <ws2tcpip.h>
|
|
#endif
|
|
+#if defined(__MINGW32__)
|
|
+#include <Wincrypt.h>
|
|
+#endif
|
|
+#include <winternl.h>
|
|
#include <iphlpapi.h>
|
|
#include <wtsapi32.h>
|
|
#include <Winsvc.h>
|
|
@@ -33,14 +37,14 @@
|
|
#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"
|
|
-#include "arch/windows/services.h"
|
|
-
|
|
-#ifdef __MINGW32__
|
|
-#include "arch/windows/glpi.h"
|
|
+#else
|
|
+#include <winternl.h>
|
|
+#include <ws2tcpip.h>
|
|
#endif
|
|
-
|
|
+#include "arch/windows/services.h"
|
|
|
|
/*
|
|
* ============================================================================
|
|
@@ -85,54 +89,8 @@ typedef struct _DISK_PERFORMANCE_WIN_2008 {
|
|
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;
|
|
@@ -145,11 +103,12 @@ typedef struct _MIB_UDP6TABLE_OWNER_PID {
|
|
MIB_UDP6ROW_OWNER_PID table[ANY_SIZE];
|
|
} MIB_UDP6TABLE_OWNER_PID, *PMIB_UDP6TABLE_OWNER_PID;
|
|
#endif
|
|
+#endif
|
|
|
|
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/glpi.h b/psutil/arch/windows/glpi.h
|
|
index 6f98483..f51080b 100644
|
|
--- a/psutil/arch/windows/glpi.h
|
|
+++ b/psutil/arch/windows/glpi.h
|
|
@@ -1,5 +1,5 @@
|
|
-// mingw headers are missing this
|
|
-
|
|
+#if !defined(__GLPI_H__) && !defined(USING_MSYS)
|
|
+#define __GLPI_H__
|
|
typedef enum _LOGICAL_PROCESSOR_RELATIONSHIP {
|
|
RelationProcessorCore,
|
|
RelationNumaNode,
|
|
@@ -38,4 +38,5 @@ typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION {
|
|
|
|
WINBASEAPI WINBOOL WINAPI
|
|
GetLogicalProcessorInformation(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer,
|
|
- PDWORD ReturnedLength);
|
|
\ No newline at end of file
|
|
+ PDWORD ReturnedLength);
|
|
+#endif // __GLPI_H__
|
|
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 @@ typedef enum _KTHREAD_STATE {
|
|
MaximumThreadState
|
|
} KTHREAD_STATE, *PKTHREAD_STATE;
|
|
|
|
-
|
|
+#ifndef __MINGW32__
|
|
typedef enum _KWAIT_REASON {
|
|
Executive = 0,
|
|
FreePage = 1,
|
|
@@ -162,12 +162,11 @@ typedef enum _KWAIT_REASON {
|
|
MaximumWaitReason = 37
|
|
} KWAIT_REASON, *PKWAIT_REASON;
|
|
|
|
-
|
|
typedef struct _CLIENT_ID {
|
|
HANDLE UniqueProcess;
|
|
HANDLE UniqueThread;
|
|
} CLIENT_ID, *PCLIENT_ID;
|
|
-
|
|
+#endif
|
|
|
|
typedef struct _SYSTEM_THREAD_INFORMATION {
|
|
LARGE_INTEGER KernelTime;
|
|
@@ -286,7 +285,7 @@ typedef NTSTATUS (NTAPI *_NtSetInformationProcess)(
|
|
DWORD ProcessInformationLength
|
|
);
|
|
|
|
-
|
|
+#ifndef __MINGW32__
|
|
typedef enum _PROCESSINFOCLASS2 {
|
|
_ProcessBasicInformation,
|
|
ProcessQuotaLimits,
|
|
@@ -334,11 +333,18 @@ typedef enum _PROCESSINFOCLASS2 {
|
|
MaxProcessInfoClass
|
|
} PROCESSINFOCLASS2;
|
|
|
|
-
|
|
#define PROCESSINFOCLASS PROCESSINFOCLASS2
|
|
#define ProcessBasicInformation _ProcessBasicInformation
|
|
#define ProcessWow64Information _ProcessWow64Information
|
|
#define ProcessDebugPort _ProcessDebugPort
|
|
#define ProcessImageFileName _ProcessImageFileName
|
|
|
|
+#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
|
|
|