Skip to content

Commit e75a0bf

Browse files
authored
Merge pull request #1720 from dbwiddis/fix-cache-relationship-groupcount
Add groupCount/groupMasks to CACHE_RELATIONSHIP
2 parents 9b39daf + 79e2aa5 commit e75a0bf

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Features
1010
* [#1696](https://github.com/java-native-access/jna/pull/1696): Add `LARGE_INTEGER.ByValue` to `LARGE_INTEGER` in `WinNT.java` - [@baier233](https://github.com/baier233).
1111
* [#1697](https://github.com/java-native-access/jna/pull/1697): Add WlanApi module - [@eranl](https://github.com/eranl).
1212
* [#1718](https://github.com/java-native-access/jna/pull/1718): Add `Cups` to `c.s.j.p.unix` providing CUPS printing system bindings for destinations, jobs, options, and server configuration - [@dbwiddis](https://github.com/dbwiddis).
13+
* [#1720](https://github.com/java-native-access/jna/pull/1720): Add `groupCount` and `groupMasks` fields to `CACHE_RELATIONSHIP` in `c.s.j.p.win32.WinNT`, matching the updated Windows struct layout - [@dbwiddis](https://github.com/dbwiddis).
1314

1415
Bug Fixes
1516
---------

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

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,7 +3246,7 @@ protected List<Field> getFieldList() {
32463246
/**
32473247
* Describes cache attributes.
32483248
*/
3249-
@FieldOrder({ "level", "associativity", "lineSize", "cacheSize", "type", "reserved", "groupMask" })
3249+
@FieldOrder({ "level", "associativity", "lineSize", "cacheSize", "type", "reserved", "groupCount", "groupMasks" })
32503250
public static class CACHE_RELATIONSHIP extends SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX {
32513251

32523252
/**
@@ -3279,20 +3279,68 @@ public static class CACHE_RELATIONSHIP extends SYSTEM_LOGICAL_PROCESSOR_INFORMAT
32793279
/**
32803280
* This member is reserved.
32813281
*/
3282-
public byte[] reserved = new byte[20];
3282+
public byte[] reserved = new byte[18];
3283+
3284+
/**
3285+
* The number of groups included in the GroupMasks array. This field was
3286+
* introduced in Windows Server 2022 (21H2). On earlier versions, this
3287+
* value is always 0.
3288+
*/
3289+
public short groupCount;
32833290

32843291
/**
32853292
* A {@link GROUP_AFFINITY} structure that specifies a group number and
3286-
* processor affinity within the group.
3293+
* processor affinity within the group. This member is only relevant if
3294+
* {@code groupCount} is 0.
32873295
*/
32883296
public GROUP_AFFINITY groupMask;
32893297

3298+
/**
3299+
* An array of {@link GROUP_AFFINITY} structures that specifies a group
3300+
* number and processor affinity within the group. This member is only
3301+
* relevant if {@code groupCount} is 1 or greater.
3302+
*/
3303+
public GROUP_AFFINITY[] groupMasks = new GROUP_AFFINITY[1];
3304+
32903305
public CACHE_RELATIONSHIP() {
32913306
}
32923307

32933308
public CACHE_RELATIONSHIP(Pointer memory) {
32943309
super(memory);
32953310
}
3311+
3312+
@Override
3313+
public void read() {
3314+
readField("groupCount");
3315+
// In older version of structure this is part of reserved array and has 0 value.
3316+
// Force a minimum array size of 1.
3317+
int actualGroupCount = Math.max(1, groupCount);
3318+
// Resize if needed
3319+
if (actualGroupCount != groupMasks.length) {
3320+
groupMasks = new GROUP_AFFINITY[actualGroupCount];
3321+
}
3322+
super.read();
3323+
// Copy first value from array to older version of structure for compatibility
3324+
groupMask = groupMasks[0];
3325+
}
3326+
3327+
/*
3328+
* The groupMask field is provided as a public instance variable for
3329+
* compatibility. getFieldList is overridden to remove it before comparing
3330+
* against the structure field order.
3331+
*/
3332+
@Override
3333+
protected List<Field> getFieldList() {
3334+
List<Field> fields = new ArrayList<>(super.getFieldList());
3335+
Iterator<Field> fieldIterator = fields.iterator();
3336+
while (fieldIterator.hasNext()) {
3337+
Field field = fieldIterator.next();
3338+
if ("groupMask".equals(field.getName())) {
3339+
fieldIterator.remove();
3340+
}
3341+
}
3342+
return fields;
3343+
}
32963344
}
32973345

32983346
/**

0 commit comments

Comments
 (0)