MODSTAT(2)

πŸ’– MODSTAT(2) β€” the modstat system call, bestie edition πŸ’–

okay so you wanna know what's going on inside a kernel module? not just that it exists, but like... its whole deal? that's modstat, and she is literally the group chat gossip of the kernel world ✨. this one lives in the System Calls Manual, and she is that girl.


✨ NAME ✨

modstat β€” get status of kernel module

no cap, that's the whole vibe: you ask, she tells you. πŸŽ€


πŸ“š LIBRARY πŸ“š

Standard C Library (libc, -lc)


🌸 SYNOPSIS 🌸

#include <sys/param.h>
#include <sys/module.h>

int
modstat(int modid, struct module_stat *stat);

πŸ’… DESCRIPTION πŸ’…

so basically, the modstat() system call writes the info for the kernel module referred to by modid into stat. that's it. that's the whole thing. she takes the module id, she fills in the struct, she moves on with her day 🫢.

and here's the struct you're filling, looking all iconic:

struct module_stat {
        int         version;        /* set to sizeof(module_stat) */
        char        name[MAXMODNAME];
        int         refs;
        int         id;
        modspecific_t data;
};
typedef union modspecific {
        int         intval;
        u_int       uintval;
        long        longval;
        u_long      ulongval;
} modspecific_t;

and now let's go field by field because every single one matters, fr fr:

  • version β€” this field is set to the size of the structure mentioned above by the code calling modstat(), and not modstat() itself. like, you set it, bestie. she does not do it for you. the audacity? no, the responsibility πŸ’…
  • name β€” The name of the module referred to by modid.
  • refs β€” The number of modules referenced by modid.
  • id β€” The id of the module specified in modid.
  • data β€” Module specific data.

πŸ”₯ RETURN VALUES πŸ”₯

The modstat() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

0 = slay. -1 = not slay, go read errno 😭


πŸ’€ ERRORS πŸ’€

The information for the module referred to by modid is filled into the structure pointed to by stat unless one of these little drama bombs happens:

  • [ENOENT] β€” The module was not found (probably not loaded). she's not ghosting you, she genuinely could not find her πŸ™ˆ
  • [EINVAL] β€” The version specified in the version field of stat is not the proper version. You would need to rebuild world, the kernel, or your application, if this error occurs, given that you did properly fill in the version field. yeah. that's a whole rebuild. sorry bestie πŸ’€
  • [EFAULT] β€” There was a problem copying one, some, or all of the fields into stat in the copyout(9) function.
not me casually having three separate ways to fail. but like, respectfully, the error messages are giving ✨clarity✨ so we move.

πŸ¦‹ SEE ALSO πŸ¦‹

the whole friend group honestly, go say hi πŸ‘‘


πŸ‘‘ HISTORY πŸ‘‘

The kld interface first appeared in FreeBSD 3.0.

old money. vintage. iconic. she's been here since before you were born and she still eats every time 🌈


and that's the tea, bestie β€” this page is from Debian, dated July 15, 2008, and it's MODSTAT(2), so go forth and check your modules, you absolute main character πŸŽ€πŸ’–βœ¨

πŸ“¦ where this page comes from