'How to use System calls of an OS?

I have a big confusion regarding the system calls in OS. According to the book "operating systems concepts 9th ", it is mentioned (in page 63) that :

Most programmers never see this level of detail, however. Typically, application developers design programs according to an application programming interface (API).

Behind the scenes, the functions that make up an API typically invoke the actual system calls on behalf of the application programmer.

This means that we as programmers don't use the system calls directly. However, I see videos that teach how to use system calls directly, like this one , where it access the read|() and write() system calls. I am confused, please someone explain if the system calls can be used directly or using APIs or using both ??



Solution 1:[1]

Typically, system calls are invoked using some assembly. The C/C++ calls that must invoke system calls (like read() or write()) are compiled to assembly then to binary. The assembly to invoke a system call is really simple. It is some mov instructions to put the arguments in some conventional registers (specified in the ABI of the OS) then the actual syscall instruction.

The syscall instruction makes x86-64 processors jump at the address specified in the STAR64 MSR register. For example, Linux places the address of the first instruction of the file entry_64.s in STAR64.

The read() and write() calls are C/C++ calls in the OS API. They are often named system calls because the API is really just a thin wrapper which makes system calls directly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user123