Page MenuHomeFreeBSD

KASSERT: Make runtime optionality optional
ClosedPublic

Authored by cem on Aug 21 2018, 7:37 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 24, 11:41 PM
Unknown Object (File)
Sat, Nov 23, 7:13 AM
Unknown Object (File)
Sep 27 2024, 1:27 PM
Unknown Object (File)
Sep 24 2024, 8:08 PM
Unknown Object (File)
Sep 24 2024, 6:30 PM
Unknown Object (File)
Sep 23 2024, 11:43 PM
Unknown Object (File)
Sep 21 2024, 10:02 PM
Unknown Object (File)
Sep 21 2024, 3:20 AM
Subscribers

Details

Summary

Add an option, KASSERT_PANIC_OPTIONAL, that allows runtime KASSERT() behavior
changes. When this option is not enabled, code that allows KASSERTs to become
optional is not enabled, and all violated assertions cause termination.

The runtime KASSERT behavior was added in r243980.

One important distinction here is that panic has dead2, while kassert_panic
(!KASSERT_PANIC_OPTIONAL) does not. Static analyzers like Coverity understand
dead2 ("attribute((noreturn))"). Without it, KASSERTs went misunderstood,
resulting in many false positives that resulted from violation of program
invariants.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 19018
Build 18654: arc lint + arc unit

Event Timeline

This revision is now accepted and ready to land.Aug 21 2018, 8:31 PM
jhb added inline comments.
sys/sys/systm.h
216

I would perhaps leave panic/vpanic here since we usually group function prototypes in a single place. kassert_panic() is the odd one out, but I don't feel strongly enough to suggest moving kassert_panic() down to here.

sys/sys/systm.h
216

Unfortunately, leaving them in place produced compiler warnings -> Werrors, at least with GCC xtoolchain.

Placing the definition of KASSERT lower requires even more restructuring to the file — the include sys/kpilite.h on line 113/120 invokes KASSERT, for example.

We could move the entire prototype table up, if that seems preferable, but again it's a much bigger change. Or would use some linker magic to have panic define an alias for kassert_panic? But I'm less keen on that.

This revision was automatically updated to reflect the committed changes.

Thanks everyone for reviewing.

sys/sys/systm.h
216

I added an explanatory comment here in the committed version.