HOOK_ESTABLISH(9)

πŸ“¦ in nixpkgs unstable

πŸ’… 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.

⚠️ if cookie is invalid, the result of hook_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