KASSERT(9)
π KASSERT β the kernel expression verification macro π
okay bestie, sit DOWN, because we're talking about KASSERT(9) from the Kernel Developer's Manual (yes, section 9, that's the kernel-dev zone, iykyk). This little macro is the vibe check your kernel runs on itself, and honestly? she's iconic. β¨
β¨ SYNOPSIS β¨
First things first, she only really shows up if you built your kernel like this:
options INVARIANTS
Then you gotta pull in the headers:
#include <sys/param.h>
#include <sys/systm.h>
And the call itself, the moment we've all been waiting for:
KASSERT(expression, msg);
πΈ DESCRIPTION πΈ
So here's the tea. If your kernel was compiled with options INVARIANTS, then KASSERT() takes the expression you handed her and tests it. And if that expression comes back false? She calls panic(9). Like, immediately. And that panic terminates the running system. No soft launch, no gentle exit, just π. She does not do half measures, periodt.
But if your kernel was built without options INVARIANTS? Then KASSERT() is defined to be a no-op. She's literally just standing there, doing nothing, being a chill little ghost. π»
Oh and the second argument, msg? That's a printf(9) format string and its arguments, all wrapped up together in parentheses. Don't forget the parentheses, bestie, that's the whole point. π
ngl, the no-op version is lowkey the most unhinged part β your assertion just evaporates when INVARIANTS isn't set, so don't be out here thinking it's always checking. It is NOT. π
π₯ EXAMPLES π₯
The kernel function vput() must not be called with a NULL pointer. She said what she said. So we assert it, like this:
void
vput(vp)
struct vnode *vp;
{
struct proc *p = curproc;
KASSERT(vp != NULL, ("vput: null vp"));
...
}
See how the message is ("vput: null vp")? Parentheses. Around the whole thing. Because it's a printf(9) format string plus args, remember? Slay. π
π¦ SEE ALSO π¦
π AUTHORS π
This manual page was written by Jonathan M. Bresler <jmb@FreeBSD.org>. Thank you for your service, king. π«Ά
okay and that's the whole page!! this was the KASSERT(9) man page from the Kernel Developer's Manual, brought to you by the Debian crew, dated January 14, 2000 β yes, a vintage. she's been serving since Y2K and she's still booked and busy. πβπ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2000 Jonathan M. Bresler
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms