HOOK_ESTABLISH(9)
π HOOK_ESTABLISH β the kernel dev manual, bestie edition π
okay so like, this page is from the Kernel Developer's Manual, and it's literally all about adding and removing hooks from a list you specify. it's giving very much "plumbing but make it cute" β¨
πΈ NAME πΈ
hook_establish, hook_disestablish β add or remove a hook from a specified list π«Ά
β¨ SYNOPSIS β¨
#include <sys/types.h>
#include <sys/systm.h>
void *
hook_establish(struct hook_desc_head *head, int tail,
void (*fn)(void *), void *arg);
void
hook_disestablish(struct hook_desc_head *head, void *cookie);
π DESCRIPTION π
so like, hook_establish() adds fn to the list of hooks that dohooks(9) invokes. iconic. π
here's the tea on ordering: if tail is non-zero, the hook goes to the tail of the list denoted by the TAILQ_HEAD pointer head β otherwise it goes to the front. and then dohooks(9) will, at its invocation, call each hook from the front of this list. so front-to-back, bestie, that's the order π
when it gets invoked, your hook function fn gets passed arg as its only argument. that's it. one arg. no cap. π
now, hook_disestablish() removes the hook described by the opaque pointer cookie from the list of hooks denoted by the TAILQ_HEAD pointer head.
β οΈ ifcookieis invalid, the result ofhook_disestablish()is undefined β and not the fun kind of undefined, the "your kernel is gonna have a bad time" kind π so like, don't do that fr fr π
oh and fun fact: the startup and mountroot systems use this API for their implementation. main character energy, honestly π§
β RETURN VALUES β
if it works out (slay π), hook_establish() returns an opaque pointer describing the newly established hook.
otherwise? it returns NULL. π
π SEE ALSO π
and that's the whole vibe, bestie β¨π¦ this lil gem is from the Debian edition of the manual, dated December 12, 2015 β go forth and hook responsibly ππ
π¦ where this page comes from
- nixpkgs unstable: cvs-export
- Copyright (c) 2001 Niklas Hallqvist
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms