3

When a process requires actions that require kernel mode, it uses a system call. So, how are the results returned to the process?

3

NOTE: ALL THE BELOW INFORMATION IS FROM THE REFERENCED SITE


From this link, I found the below information.

A system call is an interface between a user-space application and a service that the kernel provides. Because the service is provided in the kernel, a direct call cannot be performed; instead, you must use a process of crossing the user-space/kernel boundary.

Using the system call

Let's look at what's necessary to use them from a user-space application. There are two ways that you can use new kernel system calls. The first is a convenience method (not something that you'd probably want to do in production code), and the second is the traditional method that requires a bit more work. With the first method, you call your new functions as identified by their index through the syscall function. With the syscall function, you can call a system call by specifying its call index and a set of arguments. For example, the short application shown below calls your sys_getjiffies using its index.

#include <linux/unistd.h>
#include <sys/syscall.h>

#define __NR_getjiffies     320

int main()
{
  long jiffies;

  jiffies = syscall( __NR_getjiffies );

  printf( "Current jiffies is %lx\n", jiffies );

  return 0;
}

As you can see, the syscall function includes as its first argument the index of the system call table to use. Had there been any arguments to pass, these would be provided after the call index. Most system calls include a SYS_ symbolic constant to specify their mapping to the _NR indexes. For example, you invoke the index __NR_getpid with syscall as:

syscall( SYS_getpid )

The syscall function is architecture specific but uses a mechanism to transfer control to the kernel. The argument is based on a mapping of _NR indexes to SYS symbols provided by /usr/include/bits/syscall.h (defined when the libc is built). Never reference this file directly; instead use /usr/include/sys/syscall.h.

  • The link that I referred has all the information. You can find most of your queries answered there. :) – Ramesh Mar 27 '14 at 3:53
  • Also helpful are the syscall manpages. A system calls response code is returned via an architecture-defined register (eax on x86). For system calls that return a lot of data, the arguments that you pass include an address where the data should be put. Your process can then just look at that same address once the system call returns. – Steven D Mar 27 '14 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.