Page MenuHomeFreeBSD

sysctl(9): Ease exporting struct sizes; Discourage doing that
ClosedPublic

Authored by olce on May 2 2025, 8:29 PM.
Tags
None
Referenced Files
F127293318: D50121.id154937.diff
Sat, Aug 30, 2:07 AM
Unknown Object (File)
Thu, Aug 28, 11:30 PM
Unknown Object (File)
Mon, Aug 25, 1:32 PM
Unknown Object (File)
Fri, Aug 22, 2:43 PM
Unknown Object (File)
Sat, Aug 16, 5:01 AM
Unknown Object (File)
Mon, Aug 11, 8:27 PM
Unknown Object (File)
Sat, Aug 9, 11:14 PM
Unknown Object (File)
Fri, Aug 8, 2:10 PM

Details

Summary

Introduce two helpers, the more general SYSCTL_SIZEOF() and a struct-specific
one SYSCTL_SIZEOF_STRUCT() which prepends 'struct' in the description and in the
use of sizeof() but uses the raw structure name as the knob's name. The size of
the object/structure is exported under 'debug.sizeof'.

Existing knobs under 'debug.sizeof' were all converted to use the helpers.

Add a note before the helpers discouraging the introduction of new leaves for
ad-hoc reasons. List alternative means for developers to obtain the size of
arbitrary kernel structures easily (thanks to markj@ for providing these).

No functional change (intended).

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

olce requested review of this revision.May 2 2025, 8:29 PM

After giving up on D50122 and D50123, this one has less value. However, I still think it would be fine to commit it with some comments near the definitions to say people should avoid adding new uses. Objections?

This revision is now accepted and ready to land.May 5 2025, 6:42 PM
olce retitled this revision from sysctl(9): Add helpers to export the size of an object/structure to sysctl(9): Ease exporting struct sizes; Mark doing that as obsolete.
olce edited the summary of this revision. (Show Details)

Add a note before the new macros that 'debug.sizeof' is considered obsolete and people should not add new leaves to it but instead the listed means to obtain the size of kernel structures.

This revision now requires review to proceed.May 6 2025, 1:06 PM
sys/sys/sysctl.h
937

It's not "obsolete" really, it's just that using this tree for ad-hoc purposes is discouraged. The methods below aren't so good for programmatic checking, and something which looks through data structures in kernel memory might want to use a sizeof node as a seatbelt to check for KBI changes.

Of course, ideally we'd provide proper interfaces for any such applications, but sometimes we're too slow.

olce retitled this revision from sysctl(9): Ease exporting struct sizes; Mark doing that as obsolete to sysctl(9): Ease exporting struct sizes; Discourage doing that.
olce edited the summary of this revision. (Show Details)

Update the note about the debug.sizeof sysctl sub-tree.

olce marked an inline comment as done.May 6 2025, 3:18 PM
olce added inline comments.
sys/sys/sysctl.h
937

Is the new formulation fine?

This revision is now accepted and ready to land.May 6 2025, 5:32 PM
This revision was automatically updated to reflect the committed changes.
olce marked an inline comment as done.