一个现在有点想法的IT民工
分类: LINUX
2007-08-22 10:42:29
How to define your own sysall?
Three steps:(for arm)
(i)In calls.S:
/* 256 */
.long SYMBOL_NAME(sys_readhwproc)
note:the filename and the syscall_number could be not the same as above in other architectures.
(ii)In unistd.h:
#define __NR_readhwproc
(__NR_SYSCALL_BASE+256)
note:syscall_number must be the same as above.
(iii)In sys.c:
add corresponding function:
asmlinkage long sys_readhwproc(void)
{
current->hwproc=“hello, I am hardwareprocess!”;
printk(“’%s’\n”,current->hwproc);
return 0;
}
Before testing this syscall, the following two must be specified:
(1)The relation of C lib and syscall:
(2)Two ways of using syscall directly, not through glibc:
(i) #define __NR_readhwproc (__NR_SYSCALL_BASE+226)
int main()
{
…
syscall(__NR_readhwproc);/**:if there is some params,put them behind the function name and devided by comma.*/
…
}
(ii)Using _syscalln(n is the number of parameters pssed to syscalls.)
#define __NR_readhwproc (__NR_SYSCALL_BASE+226)
_syscall0(long,readhwproc);
int main()
{
…
readhwproc();
…
}
pay attention: sys_calls can be used by both user process and kernelprocess. when using it,it's neccessary for you to include some head files, pay attention that the macro "#define __KERNEL_SYSCALLS__" is needed,it is usually definded in the same file as "#define __NR_readhwproc (__NR_SYSCALL_BASE+226)
_syscall0(long,readhwproc); "