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)
Fri, Dec 20, 7:59 PM
Unknown Object (File)
Thu, Dec 12, 7:07 PM
Unknown Object (File)
Mon, Dec 2, 1:46 AM
Unknown Object (File)
Nov 24 2024, 11:41 PM
Unknown Object (File)
Nov 23 2024, 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
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 Not Applicable
Unit
Tests Not Applicable

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 ↗(On Diff #47061)

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 ↗(On Diff #47061)

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 ↗(On Diff #47061)

I added an explanatory comment here in the committed version.