8

System call functions are offered by an OS directly. Some libraries (e.g. the GNU C library) offer functions that wrap the system calls of the OS, but are not offered by the OS directly.

In Linux, can I invoke system call functions in my C code, without a library (e.g. GNU C Library) that isn't offer by the OS directly? Does the OS offer a library for its system calls?

For example, if I want to directly invoke the system call function read() in my C program, which header file should I include? Do I have to use some library?

frogatto
  • 28,539
  • 11
  • 83
  • 129

1 Answers1

6

Yes, you can.

The headers you want are usually in /usr/include/linux.

The lowest-level way to make a syscall is with the INT 0x80 assembler instruction directly, which is of course available to you without any libraries at all.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Borealid
  • 95,191
  • 9
  • 106
  • 122
  • In complement, there is the function `syscall` in or , which calls INT 80 with the syscall id you want and the parameters. – Pierre Emmanuel Lallemant Feb 06 '16 at 22:39
  • Thanks. (1) what is the name of library in /usr/include/linux? (2) Does the concept of "library" not exist in assembly language? Do assembly language has a concept similar to "library" or in place of "library"? –  Feb 06 '16 at 22:58
  • Include directories contain headers, not linkable libraries. The linux directory contains headers with constants for things like syscall numbers. No, assembler doesn't have "libraries" the way you're using the word - the closest thing would be to static link some C code, but you explicitly said you wanted to do this without anything like glibc, which is where the unistd code comes from. – Borealid Feb 07 '16 at 02:02