Skip to content

OpenBSD FFM port: add sysctl FFM bindings and utility - #3334

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:openbsd-ffm
Jun 4, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:openbsd-ffm

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add OpenBsdLibcFunctions with FFM downcall bindings for sysctl(int[] mib, ...), getthrid(), and getrlimit()
  • Add OpenBsdSysctlUtilFFM wrapping the raw sysctl binding with convenience methods for int/long/String/struct/buffer results, plus command-line fallbacks
  • Tests gated to @EnabledOnOs(OS.OPENBSD) covering both native and command-line paths

This is the low-level foundation for the OpenBSD FFM port — no consumers yet, just the bindings and utilities that later PRs will wire into platform classes.

Key differences from FreeBSD

  • No sysctlbyname — everything goes through sysctl(int[] mib, ...)
  • getthrid() returns int directly (no out-pointer like FreeBSD's thr_self)
  • RLIMIT_NOFILE = 8 (same as FreeBSD)

Test plan

  • CI passes on OpenBSD 7.9 VM (live sysctl + getthrid + getrlimit tests)
  • Tests skipped cleanly on other platforms (@EnabledOnOs(OS.OPENBSD))
  • Full project compiles on all platforms

Refs #3332

Summary by CodeRabbit

  • New Features

    • Added OpenBSD platform support with system utilities for retrieving configuration information (sysctl, resource limits, thread IDs).
  • Tests

    • Added comprehensive test coverage for OpenBSD system utilities.

Add OpenBsdLibcFunctions with FFM downcall bindings for:
- sysctl(int[] mib, ...) — the int-MIB form (no sysctlbyname on OpenBSD)
- getthrid() — returns calling thread's kernel ID
- getrlimit() — resource limit queries (RLIMIT_NOFILE = 8)

Add OpenBsdSysctlUtilFFM wrapping the raw sysctl binding with
convenience methods for int/long/String/struct/buffer results, plus
command-line fallbacks matching the JNA version's API.

Tests are gated to @EnabledOnOs(OS.OPENBSD) and exercise both the
native sysctl calls and the command-line fallbacks.
@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request introduces comprehensive OpenBSD support for Java Foreign Function & Memory (FFM) operations. It adds low-level libc bindings for sysctl, getthrid, and getrlimit system calls via OpenBsdLibcFunctions, a thread-safe high-level utility wrapper in OpenBsdSysctlUtilFFM with multiple API variants, updates module exports, and provides full test coverage validating both layers.

Changes

OpenBSD FFM System Integration

Layer / File(s) Summary
OpenBSD libc FFM bindings and layouts
oshi-core-ffm/src/main/java/oshi/ffm/unix/openbsd/OpenBsdLibcFunctions.java, oshi-core-ffm/src/main/java/oshi/ffm/unix/openbsd/package-info.java
OpenBsdLibcFunctions defines FFM layouts for size_t and struct rlimit, downcall MethodHandles for sysctl, getthrid, and getrlimit resolved via LINKER.defaultLookup(), public wrapper methods invoking downcalls and propagating exceptions, and VarHandle-based accessors for reading soft/hard limits from struct memory.
OpenBSD sysctl utility wrappers
oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/openbsd/OpenBsdSysctlUtilFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/openbsd/package-info.java
OpenBsdSysctlUtilFFM provides overloaded sysctl methods for int, long, and String results, caller-provided struct population, and auto-allocated segments, all allocating confined arenas, querying sizes, and invoking a shared internal sysctlMib helper that captures errno via call-state and logs warnings on failure. Command-line sysctl(String, ...) variants execute sysctl -n and parse output.
Module export and test infrastructure
oshi-core-ffm/src/main/java/module-info.java, oshi-core-ffm/src/test/java/module-info.test
Module descriptor exports oshi.ffm.util.platform.unix.openbsd package; test module opens the same package to org.junit.platform.commons for reflective test access.
OpenBSD FFM test coverage
oshi-core-ffm/src/test/java/oshi/ffm/util/platform/unix/openbsd/OpenBsdSysctlUtilFFMTest.java
OpenBsdSysctlUtilFFMTest validates default fallback for invalid MIBs, hardware info retrieval (page size, CPU count), platform identity strings (ostype, osrelease, machine), struct buffer calls, command-line sysctl variants, getrlimit soft/hard limit validation, and getthrid thread ID assertion.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A rabbit hops through OpenBSD's FFM,
Where native sysctl calls now swim,
getthrid bounds, rlimit gleams,
With threads and limits in safe memory streams! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'OpenBSD FFM port: add sysctl FFM bindings and utility' clearly and concisely summarizes the main changes: adding FFM-based sysctl bindings and utilities for OpenBSD support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.82%. Comparing base (1726691) to head (a218ad3).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3334      +/-   ##
============================================
+ Coverage     69.53%   75.82%   +6.29%     
+ Complexity     2262       76    -2186     
============================================
  Files           461      461              
  Lines         17819    17819              
  Branches       2898     2898              
============================================
+ Hits          12390    13511    +1121     
+ Misses         3890     2667    -1223     
- Partials       1539     1641     +102     
Flag Coverage Δ
freebsd 32.49% <ø> (ø)
linux 36.99% <ø> (ø)
macos 37.30% <ø> (-0.01%) ⬇️
windows 44.36% <ø> (+8.64%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis

dbwiddis commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

@dbwiddis
dbwiddis merged commit 9792697 into oshi:master Jun 4, 2026
19 checks passed
@dbwiddis
dbwiddis deleted the openbsd-ffm branch June 4, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant