Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #28878: psutil doesn't build on recent Cygwin
Browse files Browse the repository at this point in the history
psutil's Windows-related modules include some C headers that copy some
Windows function and type declarations that are missing from public
APIs.  However, Cygwin includes the
[http://mingw-w64.org/doku.php/contribute#win32_api_and_runtime win32
API headers from the MinGW project], which are more extensive.

Cygwin recently updated to MinGW-w64 7.0 which added some new structs to
those headers that happen to already be redefined in psutil, so the
psutil Cygwin patch needs to be updated to account for this (it still
works on Cygwin installations using the older win32 headers, but for new
builds this will be a problem).

URL: https://trac.sagemath.org/28878
Reported by: embray
Ticket author(s): Erik Bray
Reviewer(s): Volker Braun
  • Loading branch information
Release Manager committed Dec 28, 2019
2 parents 115dcc6 + 1186b15 commit 7f94183
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions build/pkgs/psutil/patches/cygwin-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ new file mode 100644
index 0000000..e2f9e94
--- /dev/null
+++ b/psutil/_psutil_cygwin.c
@@ -0,0 +1,2025 @@
@@ -0,0 +1,2035 @@
+#define WIN32_LEAN_AND_MEAN
+
+#include <windows.h>
Expand Down Expand Up @@ -1904,8 +1904,18 @@ index 0000000..e2f9e94
+ return NULL;
+
+ num_handles = process->HandleCount;
+ for (i = 0; i < process->NumberOfThreads; i++)
+ for (i = 0; i < process->NumberOfThreads; i++) {
+ // The updated headers in mingw-w64 appear to be using an older version
+ // of this API in which the ContextSwitches member is still called
+ // Reserved3
+#if __MINGW64_VERSION_MAJOR < 7
+ // Using the copy of this struct definition included in psutil
+ ctx_switches += process->Threads[i].ContextSwitches;
+#else
+ // Using the definition from mingw-w64-w32api-headers
+ ctx_switches += process->Threads[i].Reserved3;
+#endif
+ }
+ user_time = (double)process->UserTime.HighPart * 429.4967296 + \
+ (double)process->UserTime.LowPart * 1e-7;
+ kernel_time = (double)process->KernelTime.HighPart * 429.4967296 + \
Expand Down Expand Up @@ -3465,28 +3475,38 @@ index 1bbbf2a..0d50f5b 100644
} KTHREAD_STATE, *PKTHREAD_STATE;


+#ifndef __CYGWIN__
+#ifndef __MINGW64_VERSION_MAJOR
typedef enum _KWAIT_REASON {
Executive = 0,
FreePage = 1,
@@ -168,6 +169,8 @@ typedef struct _CLIENT_ID {
@@ -168,7 +169,10 @@ typedef struct _CLIENT_ID {
HANDLE UniqueThread;
} CLIENT_ID, *PCLIENT_ID;

+#endif
+

+
+#if !defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 7
typedef struct _SYSTEM_THREAD_INFORMATION {
LARGE_INTEGER KernelTime;
@@ -287,6 +290,7 @@ typedef NTSTATUS (NTAPI *_NtSetInformationProcess)(
LARGE_INTEGER UserTime;
@@ -182,6 +186,7 @@ typedef struct _SYSTEM_THREAD_INFORMATION {
ULONG ThreadState;
KWAIT_REASON WaitReason;
} SYSTEM_THREAD_INFORMATION, *PSYSTEM_THREAD_INFORMATION;
+#endif


typedef struct _TEB *PTEB;
@@ -287,6 +292,7 @@ typedef NTSTATUS (NTAPI *_NtSetInformationProcess)(
);


+#ifndef __CYGWIN__
typedef enum _PROCESSINFOCLASS2 {
_ProcessBasicInformation,
ProcessQuotaLimits,
@@ -338,4 +342,6 @@ typedef enum _PROCESSINFOCLASS2 {
@@ -338,4 +344,6 @@ typedef enum _PROCESSINFOCLASS2 {
#define ProcessImageFileName _ProcessImageFileName
#define ProcessBreakOnTermination _ProcessBreakOnTermination

Expand Down

0 comments on commit 7f94183

Please sign in to comment.