Internals - dklibc/dklibc GitHub Wiki

Relatively complex modules: stream, printf, malloc, time. The rest are simple.

_start symbol -- default program entry point (in ELF format) is defined in syscallN.asm. After initialization calls function main

What info we need to know

  • How to make a syscall. For Linux 32-bit x86 syscall is made by int 0x80
  • List of the Linux syscalls. I got it from here
  • List of the standard C functions, POSIX API, standard headers

Kernel headers

POSIX defines:

  • Only symbolic names not values of the constants
  • Only names and type of some structs fields -- exact struct depends on system
  • Only names of some types
So, we need grab system depending info from kernel headers. Look for them here:
  • /usr/src/linux-2.6.x/include
  • /usr/src/linux-2.6.x/arch/x86/include
This ones we need (incomplete list):
  • errno.h -- errno codes (ENOENT, EIO, EINTR...)
  • types.h -- syscall types (size_t, time_t, pid_t, uid_t, gid_t, time_t, dev_t, ... )
  • signal.h -- signal codes (SIGINT, SIGHUP, SIGKILL...) and SIG_SETMASK, SIG_BLOCK, SIG_UNBLOCK
  • fcntl.h -- O_RDONLY, O_WRITE, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND, ...
  • stat.h -- struct stat and macros to test stat mode field: S_ISREG(m), S_ISDIR(m), S_ISCHR(m), S_ISBLK(m), S_ISFIFO(m), S_ISSOCK(m)
  • dirent.h -- dirent struct
Kernel is backward compatible: old syscall versions are supported in new kernels, symbolic constants values don't change. Changes summary:
  • UID and GID were 16-bit, but now are 32-bit. So, 32-bit versions of syscalls getuid, getgid, setuid, setgid, chown, ... are added. But if you are using 16-bit versions on 32-bit system that uses 32-bit id's internally you will get only low 16-bits
  • Large file support is adding: 64-bit offsets. So 64-bit versions of file related syscalls are added. If you are using 32-bit versions -- you will fail to work with large files (that system itself supports)
Conclusion: most of changes are adding new features in form of new syscalls. Can struct, arg or return value of syscall change? You should monitor new version of kernel and adapt your libc.
⚠️ **GitHub.com Fallback** ⚠️