How are system calls from man 2 invoked?

wlnirvana

By system calls, I mean functions like man 2 brk, not the 0x80 interrupt.

If I understand this thread correctly, a compiled C program never DIRECTLY invokes system calls. It can only invoke library calls, which might be dynamically linked from glibc.

However, man 3 brk returns No manual entry for brk in section 3. So I guess one of the following has to happen for the brk to be executed properly:

  1. My understanding above is wrong. Programs can invoke system calls without glibc support. But how is brk linked into the program then?
  2. There is indeed a glibc wrapper for the system call brk. Then which brk is included when I #include <unistd.h>? The glibc one or the system call one? If it is the glibc one, why is it not documented in man 3? Where can I find a complete list of available library calls?
ilkkachu

For most of the system calls with man pages in section 2, the man pages actually describe the C library wrappers. The exceptions are usually mentioned explicitly, like gettid that @Sergei Kurenkov refer's to in their answer:

NOTES Glibc does not provide a wrapper for this system call; call it using syscall(2).

Similarly with pivot_root (which isn't that useful for general applications), tgkill (which performs the low-level function of pthread_kill). Then there's readdir, where the actual system call is somewhat different from the library function:

DESCRIPTION This is not the function you are interested in. Look at readdir(3) for the POSIX conforming C library interface. This page documents the bare kernel system call interface, which is superseded by getdents(2).

Note that there has to be some sort of wrapper. Function calls are made using the C calling conventions, which is different from the calling convention of the kernel interface. Usual function calls are made with the call assembly instruction (or similar), kernel calls with syscall or int 0x80 (and that's not counting stuff like gettimeofday or getpid in the vdso). The compiler doesn't (need to) know which function calls map to an an actual kernel call.

Even with the "usual" system calls, the C library wrapper acts slightly differently from the bare system call: The system calls return the error codes as varying negative values (if you look at the Linux kernel code, you'll see a lot of returns like return -EPERM;). The C library wrapper turns all such return values to -1, and moves the actual error code to errno.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to test system calls from the rake task

From Dev

In terms of call-return behaviour, how are the fork() and exec() system calls different from other system calls?

From Dev

How to trace system calls in FreeBSD from source code?

From Java

How to prevent calls to System.exit() from terminating the JVM?

From Dev

How does the Implementation of System Calls and Interrupts differ from each other?

From Dev

How to access a PSDrive from System.IO.File calls?

From Dev

Setting up man-db crashes system with Bad system calls

From Dev

How can other libraries be invoked from chaincode?

From Dev

How to cancel activity that is invoked asynchronously from the Workflow?

From Dev

How to pass function to be invoked in Pyside2?

From Dev

spring mock mvc tests with api being invoked from external system

From Dev

How to list system calls and library calls in Unix?

From Java

When and how are system calls interrupted?

From Java

Why do some Linux system calls have two man pages?

From

How to catch runtime error from a function invoked from a waitgroup?

From Dev

C: Suppress system calls from binary

From Dev

Calling C system calls from JNI

From Dev

How to tell where Powershell events handlers are invoked from?

From Dev

How to find which Method methods are invoked from and variables are declared within

From Java

How to tell whether current bash script was invoked from call script

From Java

How to programatically add variables to the Shell from which some code was invoked?

From Java

Is there a way to know how the user invoked a program from bash?

From Dev

How to detect whether triger is invoked from insert or update call?

From Dev

how to pass variables from GDB to invoked python interpeter

From Dev

How to skip a method in a rails model when invoked from different controllers

From Dev

How to get the base address of the text segment of the binary invoked from shell?

From Dev

How to prevent object from being reinitialized everytime it is invoked? - Dart / Flutter

From Dev

How to set instance property from a callback function invoked by the instance?

From Dev

How to skip Yeoman generator step when invoked from node script

Related Related

  1. 1

    How to test system calls from the rake task

  2. 2

    In terms of call-return behaviour, how are the fork() and exec() system calls different from other system calls?

  3. 3

    How to trace system calls in FreeBSD from source code?

  4. 4

    How to prevent calls to System.exit() from terminating the JVM?

  5. 5

    How does the Implementation of System Calls and Interrupts differ from each other?

  6. 6

    How to access a PSDrive from System.IO.File calls?

  7. 7

    Setting up man-db crashes system with Bad system calls

  8. 8

    How can other libraries be invoked from chaincode?

  9. 9

    How to cancel activity that is invoked asynchronously from the Workflow?

  10. 10

    How to pass function to be invoked in Pyside2?

  11. 11

    spring mock mvc tests with api being invoked from external system

  12. 12

    How to list system calls and library calls in Unix?

  13. 13

    When and how are system calls interrupted?

  14. 14

    Why do some Linux system calls have two man pages?

  15. 15

    How to catch runtime error from a function invoked from a waitgroup?

  16. 16

    C: Suppress system calls from binary

  17. 17

    Calling C system calls from JNI

  18. 18

    How to tell where Powershell events handlers are invoked from?

  19. 19

    How to find which Method methods are invoked from and variables are declared within

  20. 20

    How to tell whether current bash script was invoked from call script

  21. 21

    How to programatically add variables to the Shell from which some code was invoked?

  22. 22

    Is there a way to know how the user invoked a program from bash?

  23. 23

    How to detect whether triger is invoked from insert or update call?

  24. 24

    how to pass variables from GDB to invoked python interpeter

  25. 25

    How to skip a method in a rails model when invoked from different controllers

  26. 26

    How to get the base address of the text segment of the binary invoked from shell?

  27. 27

    How to prevent object from being reinitialized everytime it is invoked? - Dart / Flutter

  28. 28

    How to set instance property from a callback function invoked by the instance?

  29. 29

    How to skip Yeoman generator step when invoked from node script

HotTag

Archive