Repository navigation
Add FileUtilFFM and split Auxv into common/JNA/FFM - #3135
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (13)
✅ Files skipped from review due to trivial changes (7)
🚧 Files skipped from review as they are similar to previous changes (4)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🧰 Additional context used🧠 Learnings (4)📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
📚 Learning: 2026-04-05T05:40:45.797ZApplied to files:
📚 Learning: 2026-04-05T05:39:21.126ZApplied to files:
📚 Learning: 2026-04-06T04:45:51.516ZApplied to files:
🔇 Additional comments (3)
📝 WalkthroughWalkthroughAdds a shared Auxv constants class, FFM-based auxv parsing utilities (FileUtilFFM, AuxvFFM, ForeignFunctions size constants), renames JNA Auxv to AuxvJNA, updates consumers to use the new APIs, adjusts module exports, and adds tests for the FFM helpers. Changes
Sequence Diagram(s)sequenceDiagram
participant CPU as LinuxCentralProcessorFFM
participant AuxvFFM as AuxvFFM
participant FileSys as /proc/self/auxv
participant FileUtil as FileUtilFFM
CPU->>AuxvFFM: queryAuxv()
AuxvFFM->>FileSys: readAllBytes(ProcPath.AUXV)
FileSys-->>AuxvFFM: ByteBuffer(native order)
AuxvFFM->>FileUtil: readNativeLongFromBuffer(buff) -- read key
FileUtil-->>AuxvFFM: native long (key)
AuxvFFM->>FileUtil: readNativeLongFromBuffer(buff) -- read value
FileUtil-->>AuxvFFM: native long (value)
AuxvFFM->>AuxvFFM: store (key -> value) in Map
AuxvFFM-->>CPU: return Map<Integer,Long>
CPU->>CPU: getOrDefault(Auxv.AT_HWCAP, 0L)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java (1)
35-40: Harden auxv parsing against partial/truncated buffers.At Line 35-38, parsing assumes enough bytes are always available for key/value reads. Guarding on pair-size remaining bytes avoids
BufferUnderflowExceptionon malformed or short reads.Proposed refactor
+import oshi.ffm.ForeignFunctions; +import oshi.util.driver.linux.proc.Auxv; ... - int key; - do { - key = (int) FileUtilFFM.readNativeLongFromBuffer(buff); - if (key > 0) { - auxvMap.put(key, FileUtilFFM.readNativeLongFromBuffer(buff)); - } - } while (key > 0); + while (buff.remaining() >= 2 * ForeignFunctions.NATIVE_LONG_SIZE) { + int key = (int) FileUtilFFM.readNativeLongFromBuffer(buff); + long value = FileUtilFFM.readNativeLongFromBuffer(buff); + if (key == Auxv.AT_NULL) { + break; + } + if (key > 0) { + auxvMap.put(key, value); + } + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java` around lines 35 - 40, The auxv parsing loop in AuxvFFM reads key/value pairs without checking remaining bytes and can throw BufferUnderflowException on truncated buffers; before calling FileUtilFFM.readNativeLongFromBuffer for the key (and before reading the value), check buff.remaining() is at least the native long size (or two times that for the full pair) and break or return if not enough data, so auxvMap is only populated from complete key/value pairs and partial reads are safely ignored.oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java (1)
17-23: Consider addingAT_NULLto document auxv terminator semantics.Parsers in
oshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.javaandoshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.javacurrently rely on implicitkey > 0termination. A sharedAT_NULL = 0constant would make this explicit and reduce magic-number coupling.Proposed refactor
public final class Auxv { + /** end of vector */ + public static final int AT_NULL = 0; + /** system page size */ public static final int AT_PAGESZ = 6;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java` around lines 17 - 23, Add a public constant AT_NULL = 0 to Auxv (alongside AT_PAGESZ, AT_HWCAP, AT_CLKTCK) and update the parsing code in AuxvJNA and AuxvFFM to use Auxv.AT_NULL as the explicit terminator instead of relying on a magic "key > 0" check; ensure any loop or condition that currently tests for key > 0 is changed to compare against AT_NULL so the termination semantics are explicit and consistent across implementations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@oshi-core-java25/src/main/java/oshi/ffm/util/FileUtilFFM.java`:
- Around line 39-53: The 32-bit branches of readSizeTFromBuffer and
readPointerFromBuffer return signed ints that sign-extend to negative longs;
update both 4-byte paths to convert to unsigned long using
Integer.toUnsignedLong. Specifically, in readSizeTFromBuffer use
Integer.toUnsignedLong(FileUtil.readIntFromBuffer(buff)) when
ForeignFunctions.NATIVE_SIZE_T_SIZE == 4, and in readPointerFromBuffer return
Integer.toUnsignedLong(buff.getInt()) when ForeignFunctions.NATIVE_POINTER_SIZE
== 4; leave the 8-byte (long) branches unchanged.
---
Nitpick comments:
In `@oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java`:
- Around line 17-23: Add a public constant AT_NULL = 0 to Auxv (alongside
AT_PAGESZ, AT_HWCAP, AT_CLKTCK) and update the parsing code in AuxvJNA and
AuxvFFM to use Auxv.AT_NULL as the explicit terminator instead of relying on a
magic "key > 0" check; ensure any loop or condition that currently tests for key
> 0 is changed to compare against AT_NULL so the termination semantics are
explicit and consistent across implementations.
In `@oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java`:
- Around line 35-40: The auxv parsing loop in AuxvFFM reads key/value pairs
without checking remaining bytes and can throw BufferUnderflowException on
truncated buffers; before calling FileUtilFFM.readNativeLongFromBuffer for the
key (and before reading the value), check buff.remaining() is at least the
native long size (or two times that for the full pair) and break or return if
not enough data, so auxvMap is only populated from complete key/value pairs and
partial reads are safely ignored.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 50c2e2a3-ef97-4e31-a5b6-e512a8fda075
📒 Files selected for processing (12)
oshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.javaoshi-core-java25/src/main/java/module-info.javaoshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.javaoshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.javaoshi-core-java25/src/main/java/oshi/ffm/util/FileUtilFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.javaoshi-core-java25/src/test/java/module-info.testoshi-core-java25/src/test/java/oshi/ffm/util/FileUtilFFMTest.javaoshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.javaoshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.javaoshi-core/src/test/java/oshi/driver/linux/proc/AuxvJNATest.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 25, windows-latest
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 25, macos-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (10)
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Applied to files:
oshi-core-java25/src/test/java/module-info.testoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.javaoshi-core-java25/src/main/java/oshi/ffm/ForeignFunctions.javaoshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.javaoshi-core/src/test/java/oshi/driver/linux/proc/AuxvJNATest.java
📚 Learning: 2026-04-06T04:45:51.516Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.
Applied to files:
oshi-core-java25/src/test/java/module-info.testoshi-core-java25/src/main/java/module-info.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.javaoshi-core/src/test/java/oshi/driver/linux/proc/AuxvJNATest.javaoshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.javaoshi-common/src/main/java/oshi/util/driver/linux/proc/Auxv.java
📚 Learning: 2026-03-29T20:01:01.877Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:01.877Z
Learning: In this repo’s `module-info.java` files, keep exports aligned with which platform implementations are actually supported by the current FFM (Foreign Function & Memory) backend. Do not export FreeBSD, OpenBSD, or Solaris packages (e.g., `oshi.util.platform.unix.freebsd|openbsd|solaris`) in modules where the FFM implementation only supports Windows/macOS/Linux; this asymmetry vs older Java targets (e.g., the java11 module-info that exports all Unix packages) is intentional and should not be flagged as an omission unless the underlying support changes.
Applied to files:
oshi-core-java25/src/main/java/module-info.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.javaoshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
📚 Learning: 2026-04-05T05:39:21.126Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java
📚 Learning: 2026-04-05T05:40:43.357Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:43.357Z
Learning: In OSHI’s Linux FFM implementations (e.g., LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the corresponding JNA udev code, do not require/flag a missing null check around `udev_enumerate_new()`/`enumerateNew()`. Per libudev semantics, `udev_enumerate_new()` returns NULL only if udev itself is broken (e.g., OOM). Since `udev_new()` is already guarded and is the successful prerequisite for enumeration, treating `udev_enumerate_new()` as non-null is consistent with the established pattern; adding a redundant null guard would be inconsistent.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
📚 Learning: 2026-04-05T05:39:18.791Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:18.791Z
Learning: When reviewing OSHI Linux FFM/JNA code that uses libudev, do not flag a missing null check on `udev_enumerate_new()` if `udev_new()` has already been guarded. Per libudev semantics, `udev_enumerate_new()` returns NULL only when the udev context itself is broken (e.g., OOM), so a successful `udev_new()` implies `udev_enumerate_new()` should succeed as well. Therefore, lack of a redundant null guard on `udev_enumerate_new()` is acceptable in this pattern.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.javaoshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.javaoshi-core-java25/src/main/java/oshi/ffm/util/FileUtilFFM.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.
Applied to files:
oshi-core-java25/src/main/java/oshi/ffm/util/FileUtilFFM.java
🔇 Additional comments (2)
oshi-core/src/test/java/oshi/driver/linux/proc/AuxvJNATest.java (1)
23-26: Looks good — test now correctly targets the JNA path.
AuxvJNA.queryAuxv()plus sharedAuxvconstants keeps this aligned with the new split design.oshi-core/src/main/java/oshi/driver/linux/proc/AuxvJNA.java (1)
17-23: Class split/rename is clean and consistent.Javadoc and type naming clearly identify this as the JNA implementation.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3135 +/- ##
============================================
+ Coverage 61.14% 61.82% +0.68%
Complexity 12 12
============================================
Files 39 39
Lines 2329 2329
Branches 407 407
============================================
+ Hits 1424 1440 +16
+ Misses 786 770 -16
Partials 119 119 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add native size constants (NATIVE_LONG_SIZE, NATIVE_SIZE_T_SIZE, NATIVE_POINTER_SIZE) to ForeignFunctions, derived from FFM canonical layouts. Create FileUtilFFM in oshi-core-java25 mirroring the buffer-reading methods from FileUtilJNA (readNativeLongFromBuffer, readSizeTFromBuffer, readPointerFromBuffer) using FFM-derived sizes instead of JNA's Native.LONG_SIZE etc. Use Integer.toUnsignedLong for 32-bit size_t and pointer reads to avoid sign extension of unsigned types. Split Auxv into three parts: - oshi-common: Auxv constants (AT_NULL, AT_PAGESZ, AT_HWCAP, AT_CLKTCK) - oshi-core: AuxvJNA (queryAuxv using FileUtilJNA) - oshi-core-java25: AuxvFFM (queryAuxv using FileUtilFFM) Update LinuxCentralProcessorFFM to use AuxvFFM instead of inline auxv parsing, removing the local AT_HWCAP constant and readNativeLong method. Fix double Auxv.queryAuxv() call in LinuxOperatingSystem static initializer by reusing the map for both USER_HZ and PAGE_SIZE. Use Auxv.AT_NULL as explicit loop terminator in both AuxvJNA and AuxvFFM instead of magic 'key > 0' check.
Adds FFM equivalents for native buffer-reading utilities and splits the Linux auxiliary vector driver into common, JNA, and FFM components.
Native size constants
Adds three constants to
ForeignFunctions, derived from FFM'sLinker.nativeLinker().canonicalLayouts():NATIVE_LONG_SIZE— size of ClongNATIVE_SIZE_T_SIZE— size of Csize_tNATIVE_POINTER_SIZE— size of a native pointerThese replace the use of JNA's
Native.LONG_SIZE,Native.SIZE_T_SIZE, andNative.POINTER_SIZEin FFM code paths.FileUtilFFM
New class
oshi.ffm.util.FileUtilFFMin oshi-core-java25, mirroring the buffer-reading methods fromFileUtilJNA:readNativeLongFromBuffer— reads a Clongfrom aByteBufferreadSizeTFromBuffer— reads a Csize_tfrom aByteBufferreadPointerFromBuffer— reads a native pointer from aByteBufferAuxv split
The Linux auxiliary vector driver (
/proc/self/auxv) is split into three parts:oshi.util.driver.linux.proc.AuxvAT_PAGESZ,AT_HWCAP,AT_CLKTCK)oshi.driver.linux.proc.AuxvJNAqueryAuxv()usingFileUtilJNA.readNativeLongFromBufferoshi.driver.linux.proc.AuxvFFMqueryAuxv()usingFileUtilFFM.readNativeLongFromBufferOther changes
LinuxCentralProcessorFFM.queryHwcap()now delegates toAuxvFFM.queryAuxv()instead of inline parsing, removing the localAT_HWCAPconstant andreadNativeLongmethodLinuxOperatingSystemwhereAuxv.queryAuxv()was called twice in the static initializer (once forUSER_HZ, once forPAGE_SIZE) — now reuses the mapSummary by CodeRabbit
New Features
Refactor
Tests
Documentation