Syscall vs System Call Wrappers, portability

107 Views Asked by At

So i'm struggling with the concept of syscall() and portability. I have heard that using a system call wrapper is more portable then just making a system call but why? I get that portability refers to my codes ability to be run on different systems or platforms but I dont understand why system call wrappers are more portable then syscall()?

1

There are 1 best solutions below

0
Joseph Sible-Reinstate Monica On

Not every architecture has every syscall. For example, RISC-V doesn't have rmdir. If you use the wrapper function, then the libc will call its replacement (unlinkat with AT_REMOVEDIR) for you automatically instead. But if you tried to use a raw syscall, it just wouldn't work.

There's differences between operating systems, too. One extreme example is OpenBSD: there, dynamically linked programs aren't allowed to make raw syscalls at all, for security reasons. The only thing that works there is the wrapper functions.