From dbf8751cd71c63f71cfe94db9a7cd1728063abc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Thu, 11 Aug 2022 18:14:34 +0200 Subject: [PATCH] Drop definition of PSAPI_WORKING_SET_EX_BLOCK, move functions to PSAPI_WORKING_SET_EX_INFORMATION, adjust function names The definition of PSAPI_WORKING_SET_EX_BLOCK was not correct. The outer definition is a UNION with two members: - ULONG_PTR Flags and - another anonymous union holding two bitfield definitions It effectively defines a union with 3 defintions. The bitfield definition differs between 32bit and 64bit. The 32bit version defines data elements filling exactly the 32bits a single ULONG_PTR can hold. The 64bit version adds an additional 32bit reserved element, which agains fill the full size a single ULONG_PTR can hold on 64bit. The two bitfield definitions both map to ULONG_PTR, so PSAPI_WORKING_SET_EX_BLOCK is basicly just a ULONG_PTR with C syntactic sugar for decoding. The PSAPI_WORKING_SET_EX_BLOCK is only used in PSAPI_WORKING_SET_EX_INFORMATION and given that the union definition of PSAPI_WORKING_SET_EX_BLOCK is syntactic sugar, we can drop the definition and integrate the decoding logic directly into PSAPI_WORKING_SET_EX_INFORMATION. ----------------------------------------------------------------------- typedef struct _PSAPI_WORKING_SET_EX_INFORMATION { PVOID VirtualAddress; PSAPI_WORKING_SET_EX_BLOCK VirtualAttributes; } PSAPI_WORKING_SET_EX_INFORMATION, *PPSAPI_WORKING_SET_EX_INFORMATION; typedef union _PSAPI_WORKING_SET_EX_BLOCK { ULONG_PTR Flags; union { struct { ULONG_PTR Valid : 1; ULONG_PTR ShareCount : 3; ULONG_PTR Win32Protection : 11; ULONG_PTR Shared : 1; ULONG_PTR Node : 6; ULONG_PTR Locked : 1; ULONG_PTR LargePage : 1; ULONG_PTR Reserved : 7; ULONG_PTR Bad : 1; #if defined(_WIN64) ULONG_PTR ReservedUlong : 32; #endif }; struct { ULONG_PTR Valid : 1; // Valid = 0 in this format. ULONG_PTR Reserved0 : 14; ULONG_PTR Shared : 1; ULONG_PTR Reserved1 : 15; ULONG_PTR Bad : 1; #if defined(_WIN64) ULONG_PTR ReservedUlong : 32; #endif } Invalid; }; } PSAPI_WORKING_SET_EX_BLOCK, *PPSAPI_WORKING_SET_EX_BLOCK; --- .../src/com/sun/jna/platform/win32/Psapi.java | 59 +++++++++---------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Psapi.java b/contrib/platform/src/com/sun/jna/platform/win32/Psapi.java index 4bfc4483a4..e5b99d4bbc 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Psapi.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Psapi.java @@ -335,78 +335,80 @@ class PERFORMANCE_INFORMATION extends Structure { public DWORD ThreadCount; } - @FieldOrder({"Flags", "Data"}) - class PSAPI_WORKING_SET_EX_BLOCK extends Structure implements ByReference { - public ULONG_PTR Flags; - public ULONG_PTR[] Data = new ULONG_PTR[Native.POINTER_SIZE == 8 ? 1 : 2]; - private long innerValue; + @FieldOrder({"VirtualAddress", "VirtualAttributes"}) + class PSAPI_WORKING_SET_EX_INFORMATION extends Structure { - @Override - public void read() { - super.read(); - innerValue = this.Data[0].longValue(); - } + public Pointer VirtualAddress; + public ULONG_PTR VirtualAttributes; /** - * If this bit is 1, the subsequent members are valid; otherwise they should be ignored. + * If this bit is 1, the subsequent members are valid; otherwise they + * should be ignored. */ - public boolean Valid() { + public boolean isValid() { return getBitFieldValue(1, 0) == 1; } /** - * The number of processes that share this page. The maximum value of this member is 7. + * The number of processes that share this page. The maximum value of + * this member is 7. */ - public int ShareCount() { + public int getShareCount() { return getBitFieldValue(3, 1); } /** - * The memory protection attributes of the page. For a list of values see below. - * @see Memory Protection Constants. + * The memory protection attributes of the page. For a list of values + * see below. + * + * @see + * Memory + * Protection Constants. */ - public int Win32Protection() { + public int getWin32Protection() { return getBitFieldValue(11, 3 + 1); } /** * If this bit is 1, the page can be shared. */ - public boolean Shared() { + public boolean isShared() { return getBitFieldValue(1, 11 + 3 + 1) == 1; } /** * The NUMA node. The maximum value of this member is 63. */ - public int Node() { + public int getNode() { return getBitFieldValue(6, 1 + 11 + 3 + 1); } /** * If this bit is 1, the virtual page is locked in physical memory. */ - public boolean Locked() { + public boolean isLocked() { return getBitFieldValue(1, 6 + 1 + 11 + 3 + 1) == 1; } /** * If this bit is 1, the page is a large page. */ - public boolean LargePage() { + public boolean isLargePage() { return getBitFieldValue(1, 1 + 6 + 1 + 11 + 3 + 1) == 1; } /** * If this bit is 1, the page is has been reported as bad. */ - public boolean Bad() { - return getBitFieldValue(1,1 + 1 + 1 + 6 + 1 + 11 + 3 + 1) == 1; + public boolean isBad() { + return getBitFieldValue(1, 1 + 1 + 1 + 6 + 1 + 11 + 3 + 1) == 1; } /** - * Returns innerValue after shifting the value rightShiftAmount, and applying a Bit Mask of size maskLength. Example,
+ * Returns innerValue after shifting the value rightShiftAmount, and + * applying a Bit Mask of size maskLength. Example,
* innerValue = 0011
getBitFieldValue(2, 1) = 0011 >> 1 & 11 = 01 + * * @param maskLength Size of the Bit Mask * @param rightShiftAmount Amount to Shift innerValue to the right by * @return innerValue with the mask and shift applied. @@ -417,14 +419,7 @@ private int getBitFieldValue(final int maskLength, final int rightShiftAmount) { for (int l = 0; l < maskLength; l++) { bitMask |= 1 << l; } - return (int) ((innerValue >>> rightShiftAmount) & bitMask); + return (int) ((VirtualAttributes.longValue() >>> rightShiftAmount) & bitMask); } } - - - @FieldOrder({"VirtualAddress", "VirtualAttributes"}) - class PSAPI_WORKING_SET_EX_INFORMATION extends Structure { - public Pointer VirtualAddress; - public PSAPI_WORKING_SET_EX_BLOCK VirtualAttributes; - } }