logoalt Hacker News

leni536today at 9:09 AM1 replyview on HN

> In an ideal world, there would be a header-only C library provided by the Linux kernel; we would include that file and be done with it. As it turns out, there is no such file, and interfacing with syscalls is complicated.

Isn't that nolibc.h?


Replies

adrian_btoday at 9:29 AM

Nolibc, which is incorporated in the Linux kernel sources (under "tools"), contains generic wrappers for the Linux syscalls and a set of simplified implementations for the most frequently needed libc functions.

It is useful for very small executables or for some embedded applications.

It is not useful for someone who would want to use the Linux syscalls directly from another programming language than C, bypassing glibc or other libc implementations, except by providing models of generic wrappers for the Linux syscalls.

It also does not satisfy the requirement of the parent article, because it does not contain a table of syscalls that could be used for separate compilations.

Nolibc implements its functions like this:

  long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  {
   return my_syscall3(__NR_ioctl, fd, cmd, arg);
  }
where the syscall numbers like "__NR_ioctl" are collected from the Linux kernel headers, because nolibc is compiled in the kernel source tree.

As explained in the parent article, there is no unique "__NR_ioctl" in the kernel sources. The C headers that are active during each compilation are selected or generated automatically based on the target architecture and on a few other configuration options, so searching for the applicable "__NR_ioctl" can be tedious, hence the value of the parent article and of a couple of other places mentioned by other posters, where syscall tables can be found.