Skip to content

openbsd: add missing HW_* sysctl constants - #5371

Merged
tgross35 merged 1 commit into
rust-lang:mainfrom
amrfti:main
Aug 5, 2026
Merged

openbsd: add missing HW_* sysctl constants#5371
tgross35 merged 1 commit into
rust-lang:mainfrom
amrfti:main

Conversation

@amrfti

@amrfti amrfti commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Adds missing HW_* sysctl constants.
The constants are defined in:
https://cvsweb.openbsd.org/annotate/src/sys/sys/sysctl.h

@rustbot label +stable-nominated

@rustbot

rustbot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in a NetBSD-like module

cc @semarie

Some changes occurred in an OpenBSD module

cc @semarie

@rustbot rustbot added O-bsd O-unix S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Aug 4, 2026
@semarie

semarie commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Do you really need all of these constants ? or it is just for completeness ?
As OpenBSD tends to deprecate and remove unneeded values across versions (and rust forbid this), I would prefer to expose only what it is really need to avoid future incompatibilities.

Additionallly, HW_MAXID would be unwanted (as the value will change very often).

Thanks.

@amrfti

amrfti commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

The only one I personally needed was HW_PHYSMEM64. The rest I added just for completeness. I still think some of the others should be added even if I didn't need them.

GuillaumeGomez/sysinfo#1318 for example needs several of these to gain support for OpenBSD.

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add these to src/new/openbsd/sys/sysctl.h instead? We're trying to slowly reorganize. (feel free to move the existing HW_NCPUONLINE as well)

Also I suppose this list should ideally be restricted a bit based on @semarie's concerns

View changes since this review

@rustbot

rustbot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@tgross35

tgross35 commented Aug 4, 2026

Copy link
Copy Markdown
Member

As OpenBSD tends to deprecate and remove unneeded values across versions (and rust forbid this), I would prefer to expose only what it is really need to avoid future incompatibilities.

For what it's worth, I have no problem removing constants after a few releases if they are removed upstream. Or gating on the target_env version once we have that.

With that in mind I don't think the situation should be too different than anything written in C out-of-tree?

@amrfti

amrfti commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Moving to src/new/openbsd/sys/sysctl.h I can do. I'm just not sure what all should be added/not added.

My use case was I need to write an OpenBSD fallback case for The Tor Project's Arti where we fetch the amount of system RAM using the sysinfo crate [1]. sysinfo doesn't support OpenBSD so I attempted to inline the libc calls myself but HW_PHYSMEM64 was missing. So all I need is that constant, but if sysinfo were to have OpenBSD support written... it would probably need many of these constants and others. I don't have an exhaustive list as I haven't attempted it.

Not familiar with best practices on bindings so I don't know how to decide what should{, not} be added, my instinct was a complete list.

@semarie

semarie commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

From the list, it could make sense to have:

  • HW_BATTERY
    • HW_BATTERY_CHARGEMODE
    • HW_BATTERY_CHARGESTART
    • HW_BATTERY_CHARGESTOP
  • HW_BYTEORDER
  • HW_CPUSPEED
  • HW_DISKCOUNT
  • HW_DISKNAMES
  • HW_DISKSTATS
  • HW_MACHINE
  • HW_MODEL
  • HW_NCPUFOUND
  • HW_PAGESIZE
  • HW_PERFPOLICY
  • HW_PHYSMEM (unsure as it is deprecated in favor of HW_PHYSMEM64)
  • HW_PHYSMEM64
  • HW_POWER
  • HW_PRODUCT
  • HW_SENSORS
  • HW_SERIALNO
  • HW_SETPERF
  • HW_UCOMNAMES
  • HW_USERMEM (unsure as it is deprecated in favor of HW_USERMEM64)
  • HW_USERMEM64
  • HW_UUID
  • HW_VENDOR
  • HW_VERSION

Thanks.

@rustbot

This comment has been minimized.

Move OpenBSD HW_* sysctl constants into sys/sysctl.rs and add some
missing definitions from sys/sysctl.h.

Ref: https://github.com/openbsd/src/blob/544119925528153b873297bc630370abacfd5a7f/sys/sys/sysctl.h
@amrfti

amrfti commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@semarie semarie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! And thanks @semarie for reviewing

View changes since this review

@tgross35
tgross35 added this pull request to the merge queue Aug 5, 2026
Merged via the queue into rust-lang:main with commit d0c9b0f Aug 5, 2026
57 checks passed
@tgross35 tgross35 mentioned this pull request Sep 4, 2026
@tgross35 tgross35 removed the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Sep 4, 2026
@tgross35 tgross35 added the stable-applied This PR has been cherry-picked to libc's stable release branch label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-bsd O-unix stable-applied This PR has been cherry-picked to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants