unistd.h question

Hi guys so I am told that unistd.h contains the declaration of all system calls on a linux system but when reading through it,

All I can see is #define macros

followed by __SYSCALL()

why so many defines and in this context what do they do?

also what is __SYSCALL()? is it a function?

thanks
macros can BE functions.

I think syscall is a *calling convention* macro that can be used to tell the compiler HOW to call a c++ or C function. It has to do with how it handles the stack and registers in assembly language and you use different ones when trying to expose your code to other lanugages so they can call it correctly.

System calls are not normal function calls. They are initiated by an interrupt and transfer control to the operating system. The operation you want is passed as a code number. So that's what all the macros are. The C functions are wrappers that set up the given system call.
adam2016 wrote:
I am told that unistd.h contains the declaration of all system calls on a linux system
tpb wrote:
They are initiated by an interrupt

Make sure you guys aren't not looking at outdated materials, the "interrupt" business is legacy even for for 32-bit days, and only barely kinda sometimes works in 64-bit.

There's a good summary here: https://blog.packagecloud.io/eng/2016/04/05/the-definitive-guide-to-linux-system-calls/
Last edited on
Topic archived. No new replies allowed.