Note that the __NR
indexes are necessary in this application because the _syscall
macro uses the func-name
to construct the __NR
index (getjiffies
-> __NR_getjiffies
). But the result is that you can call your kernel functions using their names, just like any other system call.
Alternatives for user/kernel interactions
System calls are an efficient way of requesting services in the kernel. The biggest problem with them is that it's a standardized interface. It would be difficult to have your new system call added to the kernel, so any additions are likely served through other means. If you have no intent of mainlining your system calls into the public Linux kernel, then system calls are a convenient and efficient way to make kernel services available to user-space.
Another way to make your services visible to user-space is through the /proc file system. The /proc file system is a virtual file system for which you can surface a directory and files to the user, and then provide an interface in the kernel to your new services through a file system interface (read, write, and so on).
Tracing system calls with strace
The Linux kernel provides a useful way to trace the system calls that a process invokes (as well as those signals that the process receives). The utility is called strace
and is executed from the command line, using the application you want to trace as its argument. For example, if you wanted to know which system calls were invoked during the context of the date
command, type the following command:
The result is a rather large dump showing the various system calls that are performed in the context of a date
command call. You'll see the loading of shared libraries, mapping of memory, and -- at the end of the trace -- the emitting of the date information to standard-out:
...
write(1, "Fri Feb 9 23:06:41 MST 2007\n", 29Fri Feb 9 23:06:41 MST 2007) = 29
munmap(0xb747a000, 4096) = 0
exit_group(0) = ?
$
|
This tracing is accomplished in the kernel when the current system call request has a special field set called syscall_trace
, which causes the function do_syscall_trace共8页: 上一页 [1] [2] [3] [4] [5] 6 [7] [8] 下一页