System Call Implementation
The actual implementation of a system call in Linux does not need to be concerned with the behavior of the system call handler.
The hard work lies in designing and implementing the system call; registering it with the kernel is simple.
The kernel provides two methods for performing the requisite checks and the desired copy to and from user-space.
For writing into user-space, the method copy_to_user()
is provided. It takes three parameters. The first is the destination memory address in the process’s address space. The second is the source pointer in kernel-space. Finally, the third argument is the size in bytes of the data to copy.
For reading from user-space, the method copy_from_user()
reads from the second parameter into the first parameter the number of bytes specified in the third parameter.