Why do some Linux system calls not have a wrapper, but are documented as if they do?

josh :

Let's look at the gettid system call as an example:
http://man7.org/linux/man-pages/man2/gettid.2.html

I know gettid is not implemented in libc and I need to make a system call directly in order to use it (syscall(SYS_gettid)). I have verified this myself with this C code:

#include <stdio.h>
#include <sys/types.h>

int main(){

 pid_t a = gettid();
 return 0;
}

which doesn't link and gives this warning when compiling: warning: implicit declaration of function 'gettid'; did you mean 'getline'.

Now my question is, why has the Linux documentation documented it as if this function actually exists?

SYNOPSIS 

   #include <sys/types.h>

       pid_t gettid(void);

They have no example of how to make a direct system call and instead they have the above code snippet which doesn't exist and can't be used. Is there something I'm missing?

S.S. Anne :

The syscall doesn't have a wrapper in the GNU C library (before 2.30), this is just a prototype of how the function would look if it did.

As noted in the man page:

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

Here's an example of the gettid wrapper:

#define _GNU_SOURCE
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>

pid_t gettid(void)
{
    pid_t tid = (pid_t)syscall(SYS_gettid);
    return tid;
}

As you can see, this is the same prototype as described in the man-page. The prototype in the man-page is just for reference, so you can create a wrapper around the system call if you (or the libc developers) so choose.

If you're just starting to learn C, I suggest you stop trying to understand system calls and their wrappers in the C library until you have more experience in the language. The difference will then be clear.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Why do some Linux system calls have two man pages?

From Dev

Why do some system users have /usr/bin/false as their shell?

From Dev

Why do some Linux files have a 'd' suffix?

From Dev

Why do system calls use a different stack?

From Dev

Why do some primitives have byte-codes and some do not?

From Dev

Why do some laptops not have a GPU slot?

From Dev

Why do some routers not have a WAN port?

From Dev

Why do some of functions have pass

From Java

Why do x86-64 Linux system calls modify RCX, and what does the value mean?

From Dev

Why do x86-64 Linux system calls work with 6 registers set?

From Dev

why do they have a system string and standard string

From Dev

Why do some linux binaries need to be recompiled?

From Dev

Why do some some files in /etc have a numeric prefix?

From Dev

Why do some function calls fail to work without a type application?

From Dev

Why do Linux/POSIX have lchown but not lchmod?

From Dev

Why do Linux distributions have different performance?

From Dev

When do Linux system calls trigger a segfault vs returning EFAULT?

From Dev

Why do MacOS use absolute memory locations for system calls?

From Dev

Why do some array parameters have a comma after opening parentheses?

From Dev

Why do some clojure functions have dots at the end or beginning of their names?

From Dev

In python, why do you have (seemingly) to import some libraries twice?

From

Why do some websites have ?utf8=✓ in their title?

From Dev

Why do some AWS services require the requestor to have IAM policies?

From Dev

TortoiseGit: Why do some of my branches not have revision numbers?

From Java

Why do some built-in Python functions only have pass?

From Dev

Why do some regex commands have opposite intepretations of '\' with various characters?

From Dev

Why do I have some trouble with fwrite() and fread()?

From Java

Why some stacktrace do not have line number in java

From Dev

Why do some rows in csv file have an invalid format?

Related Related

  1. 1

    Why do some Linux system calls have two man pages?

  2. 2

    Why do some system users have /usr/bin/false as their shell?

  3. 3

    Why do some Linux files have a 'd' suffix?

  4. 4

    Why do system calls use a different stack?

  5. 5

    Why do some primitives have byte-codes and some do not?

  6. 6

    Why do some laptops not have a GPU slot?

  7. 7

    Why do some routers not have a WAN port?

  8. 8

    Why do some of functions have pass

  9. 9

    Why do x86-64 Linux system calls modify RCX, and what does the value mean?

  10. 10

    Why do x86-64 Linux system calls work with 6 registers set?

  11. 11

    why do they have a system string and standard string

  12. 12

    Why do some linux binaries need to be recompiled?

  13. 13

    Why do some some files in /etc have a numeric prefix?

  14. 14

    Why do some function calls fail to work without a type application?

  15. 15

    Why do Linux/POSIX have lchown but not lchmod?

  16. 16

    Why do Linux distributions have different performance?

  17. 17

    When do Linux system calls trigger a segfault vs returning EFAULT?

  18. 18

    Why do MacOS use absolute memory locations for system calls?

  19. 19

    Why do some array parameters have a comma after opening parentheses?

  20. 20

    Why do some clojure functions have dots at the end or beginning of their names?

  21. 21

    In python, why do you have (seemingly) to import some libraries twice?

  22. 22

    Why do some websites have ?utf8=✓ in their title?

  23. 23

    Why do some AWS services require the requestor to have IAM policies?

  24. 24

    TortoiseGit: Why do some of my branches not have revision numbers?

  25. 25

    Why do some built-in Python functions only have pass?

  26. 26

    Why do some regex commands have opposite intepretations of '\' with various characters?

  27. 27

    Why do I have some trouble with fwrite() and fread()?

  28. 28

    Why some stacktrace do not have line number in java

  29. 29

    Why do some rows in csv file have an invalid format?

HotTag

Archive