SYSCALL_MODULE(9)

πŸ’– SYSCALL_MODULE(9) πŸ’–

okay bestie, gather round, because this is a Kernel Developer's Manual page and it's about the SYSCALL_MODULE macro β€” yes, the one that lets you declare a whole new syscall from inside a kernel module. main character energy fr fr πŸ‘‘


✨ NAME ✨

SYSCALL_MODULE β€” the syscall kernel module declaration macro. that's it, that's the vibe πŸŽ€


🌸 SYNOPSIS 🌸

#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/module.h>
#include <sys/sysent.h>

SYSCALL_MODULE(name, int *offset, struct sysent *new_sysent,
    modeventhand_t evh, void *arg);

πŸ¦‹ DESCRIPTION πŸ¦‹

so like. the SYSCALL_MODULE() macro declares a new syscall. that's the whole job. and when it expands, it gives you a kernel module declaration named sys/name. cute, right? ✨

here's the rest of the arguments this macro expects, no gatekeeping:

  • offset β€” a pointer to an int that saves the offset in struct sysent where the syscall gets allocated. now listen: if the location that offset points to holds a non 0 number, that number will be used if possible. but if it holds 0, then a number will be assigned for you. lowkey generous πŸ’…
  • new_sysent β€” a pointer to a structure that specifies the function implementing the syscall, plus how many arguments that function needs (peep <sys/sysent.h> for that).
  • evh β€” a pointer to the kernel module event handler function, and it takes arg as its argument. go read module(9) if you want the full tea πŸ«–
  • arg β€” the argument that gets passed to the callback functions of the evh event handler whenever it's called.

and here's a little bonus fact for you: the syscall number assigned to the module can be retrieved using the modstat(3) and modfind(3) library functions over in libc. also the MACRO SYSCALL_MODULE_HELPER() includes SYSCALL_MODULE() plus a whole bunch of its boilerplate code, so you don't have to hand-write all that 😭 obsessed


🌈 EXAMPLES 🌈

if you want a minimal example of a syscall module, it's literally sitting right here:

/usr/share/examples/kld/syscall/module/syscall.c

go look at it, bestie, it's giving tutorial ✨


πŸ’œ SEE ALSO πŸ’œ

  • module(9)
  • /usr/share/examples/kld/syscall/module/syscall.c

πŸ‘‘ AUTHORS πŸ‘‘

this manual page was written by Alexander Langer <alex@FreeBSD.org>. iconic behavior, we stan πŸ’–


ok that's the whole page, no cap, nothing skipped πŸ’…

so this page came to you from the Debian edition of the manual, dated January 24, 2015, and it's filed under SYSCALL_MODULE(9). mwah, go write a syscall πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from