0

I am reading the source code to understand sysctl in FreeBSD.

It looks like the most important function

int __sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen);

is not defined in lib/libc/gen/sysctl.c.

I tried to grep over FreeBSD's source code but I failed to find the defintion of __sysctl.

Where is it defined?

  • libc's __sysctl is a system call wrapper written in a few lines of assembly language, generated during the compilation of libc. Did you want to see that source, or the source in the kernel that handles that system call? – Mark Plotnick Jul 20 '16 at 14:37
  • @MarkPlotnick I want to understand how sysctl works. I couldn't find any in-depth explanation online so I decided to read the source code. – Mateusz Piotrowski Jul 20 '16 at 14:40
  • 1
    /usr/src/sys/kern/kern_sysctl.c or svnweb.freebsd.org/base/head/sys/kern/kern_sysctl.c?view=markup – Mark Plotnick Jul 20 '16 at 14:54
0

Here's what I've learnt:

  • __syscall is not defined in any C source file;

    According to Mark Plotnick:

    libc's __sysctl is a system call wrapper written in a few lines of assembly language, generated during the compilation of libc [1].

  • The system calls' entry point is here in kern_sysctl.c [2]. The system calls are called sys_foo() in the kernel.

Links

  1. Configuration file for generating syscalls.
  2. The kern_sysctl.c source.

Thanks to edje, Ed Schouten (@EdSchouten), @FreeBSDHelp and Mark Plotnick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.