KLDSYM(2)

πŸ’– KLDSYM πŸ’–

okay bestie, section 2 of the manual, kldsym β€” say it with me, it's a system call, we're in the syscall girlies now πŸ’…


✨ NAME ✨

kldsym β€” look up address by symbol name in a KLD


🫢 LIBRARY 🫢

Standard C Library (libc, -lc)

no cap, it's right there in libc, you don't need anything extra


🌸 SYNOPSIS 🌸

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

int
kldsym(int fileid, int cmd, void *data);

πŸ‘‘ DESCRIPTION πŸ‘‘

so the kldsym() system call is the one you call when you're like "hey, what's the address of this symbol?" β€” it returns the address of the symbol specified in data, inside the module specified by fileid. ✨

and here's the cute part: if fileid is 0, all the loaded modules get searched. every single one. she's thorough like that πŸ’…

right now, the only cmd that's actually implemented is KLDSYM_LOOKUP. that's it. that's the whole menu. periodt.


πŸŽ€ the data argument πŸŽ€

data is a pointer to this structure, exactly this one:

struct kld_sym_lookup {
    int         version;        /* sizeof(struct kld_sym_lookup) */
    char        *symname;       /* Symbol name we are looking up */
    u_long      symvalue;
    size_t      symsize;
};

okay so here's the vibe of each member πŸ¦‹

  • version β€” you set this one, bestie. and you set it to sizeof(struct kld_sym_lookup). don't get creative with it.
  • the next two members, version and symname, are specified by the user. (yes, the page says version again β€” I'm just telling you what she said πŸ™ˆ)
  • symvalue and symsize β€” these two get filled in for you by kldsym(). symvalue holds the address associated with symname, and symsize holds the size of the data it points to. respectively. iconic. πŸ’–

so you bring the name, she brings the address and the size. it's giving collaborative. it's giving teamwork. 🌈


πŸ”₯ RETURN VALUES πŸ”₯

  • returns the value 0 if successful β€” slay πŸ’…
  • otherwise the value -1 is returned and the global variable errno is set to indicate the error. (she'll tell you what went wrong, just read the vibe check) 😭

πŸ’€ ERRORS πŸ’€

the kldsym() system call will fail if:

  • [EINVAL] β€” Invalid value in data->version or cmd. 🚩
  • [ENOENT] β€” The fileid argument is invalid, or the specified symbol could not be found. she looked. she really looked. it's not there. 🫠

🌟 SEE ALSO 🌟

kldfind(2), kldfirstmod(2), kldload(2), kldnext(2), kldunload(2), modfind(2), modnext(2), modstat(2), kld(4)

the whole friend group fr fr, go read them all 🫢


πŸ“œ HISTORY πŸ“œ

The kldsym() system call first appeared in FreeBSD 3.0. she's been around a minute, she's a legend, she's an icon, and she is the moment πŸ‘‘


kdl moment: set version to sizeof(struct kld_sym_lookup) before you call, or you're gonna have a bad time. no cap. πŸ’€

and that's the whole page, bestie!! πŸ’– this one came from the Debian crew, dated October 17, 2016, and yeah it lives at KLDSYM(2) β€” section 2, system calls, exactly where she belongs. go forth and look up some symbols, i'm obsessed with you πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from