Skip to content

Commit dbf8751

Browse files
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;
1 parent d4ccd5c commit dbf8751

File tree

1 file changed

+27
-32
lines changed
  • contrib/platform/src/com/sun/jna/platform/win32

1 file changed

+27
-32
lines changed

contrib/platform/src/com/sun/jna/platform/win32/Psapi.java

+27-32
Original file line numberDiff line numberDiff line change
@@ -335,78 +335,80 @@ class PERFORMANCE_INFORMATION extends Structure {
335335
public DWORD ThreadCount;
336336
}
337337

338-
@FieldOrder({"Flags", "Data"})
339-
class PSAPI_WORKING_SET_EX_BLOCK extends Structure implements ByReference {
340-
public ULONG_PTR Flags;
341-
public ULONG_PTR[] Data = new ULONG_PTR[Native.POINTER_SIZE == 8 ? 1 : 2];
342-
private long innerValue;
338+
@FieldOrder({"VirtualAddress", "VirtualAttributes"})
339+
class PSAPI_WORKING_SET_EX_INFORMATION extends Structure {
343340

344-
@Override
345-
public void read() {
346-
super.read();
347-
innerValue = this.Data[0].longValue();
348-
}
341+
public Pointer VirtualAddress;
342+
public ULONG_PTR VirtualAttributes;
349343

350344
/**
351-
* If this bit is 1, the subsequent members are valid; otherwise they should be ignored.
345+
* If this bit is 1, the subsequent members are valid; otherwise they
346+
* should be ignored.
352347
*/
353-
public boolean Valid() {
348+
public boolean isValid() {
354349
return getBitFieldValue(1, 0) == 1;
355350
}
356351

357352
/**
358-
* The number of processes that share this page. The maximum value of this member is 7.
353+
* The number of processes that share this page. The maximum value of
354+
* this member is 7.
359355
*/
360-
public int ShareCount() {
356+
public int getShareCount() {
361357
return getBitFieldValue(3, 1);
362358
}
363359

364360
/**
365-
* The memory protection attributes of the page. For a list of values see below.
366-
* @see <a href="https://docs.microsoft.com/en-us/windows/desktop/Memory/memory-protection-constants">Memory Protection Constants</a>.
361+
* The memory protection attributes of the page. For a list of values
362+
* see below.
363+
*
364+
* @see
365+
* <a href="https://docs.microsoft.com/en-us/windows/desktop/Memory/memory-protection-constants">Memory
366+
* Protection Constants</a>.
367367
*/
368-
public int Win32Protection() {
368+
public int getWin32Protection() {
369369
return getBitFieldValue(11, 3 + 1);
370370
}
371371

372372
/**
373373
* If this bit is 1, the page can be shared.
374374
*/
375-
public boolean Shared() {
375+
public boolean isShared() {
376376
return getBitFieldValue(1, 11 + 3 + 1) == 1;
377377
}
378378

379379
/**
380380
* The NUMA node. The maximum value of this member is 63.
381381
*/
382-
public int Node() {
382+
public int getNode() {
383383
return getBitFieldValue(6, 1 + 11 + 3 + 1);
384384
}
385385

386386
/**
387387
* If this bit is 1, the virtual page is locked in physical memory.
388388
*/
389-
public boolean Locked() {
389+
public boolean isLocked() {
390390
return getBitFieldValue(1, 6 + 1 + 11 + 3 + 1) == 1;
391391
}
392392

393393
/**
394394
* If this bit is 1, the page is a large page.
395395
*/
396-
public boolean LargePage() {
396+
public boolean isLargePage() {
397397
return getBitFieldValue(1, 1 + 6 + 1 + 11 + 3 + 1) == 1;
398398
}
399399

400400
/**
401401
* If this bit is 1, the page is has been reported as bad.
402402
*/
403-
public boolean Bad() {
404-
return getBitFieldValue(1,1 + 1 + 1 + 6 + 1 + 11 + 3 + 1) == 1;
403+
public boolean isBad() {
404+
return getBitFieldValue(1, 1 + 1 + 1 + 6 + 1 + 11 + 3 + 1) == 1;
405405
}
406406

407407
/**
408-
* Returns innerValue after shifting the value rightShiftAmount, and applying a Bit Mask of size maskLength. Example, <br/>
408+
* Returns innerValue after shifting the value rightShiftAmount, and
409+
* applying a Bit Mask of size maskLength. Example, <br/>
409410
* innerValue = 0011<br/> getBitFieldValue(2, 1) = 0011 >> 1 & 11 = 01
411+
*
410412
* @param maskLength Size of the Bit Mask
411413
* @param rightShiftAmount Amount to Shift innerValue to the right by
412414
* @return innerValue with the mask and shift applied.
@@ -417,14 +419,7 @@ private int getBitFieldValue(final int maskLength, final int rightShiftAmount) {
417419
for (int l = 0; l < maskLength; l++) {
418420
bitMask |= 1 << l;
419421
}
420-
return (int) ((innerValue >>> rightShiftAmount) & bitMask);
422+
return (int) ((VirtualAttributes.longValue() >>> rightShiftAmount) & bitMask);
421423
}
422424
}
423-
424-
425-
@FieldOrder({"VirtualAddress", "VirtualAttributes"})
426-
class PSAPI_WORKING_SET_EX_INFORMATION extends Structure {
427-
public Pointer VirtualAddress;
428-
public PSAPI_WORKING_SET_EX_BLOCK VirtualAttributes;
429-
}
430425
}

0 commit comments

Comments
 (0)