Chinaunix首页 | 论坛 | 博客
  • 博客访问: 62040
  • 博文数量: 23
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 245
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-22 18:45
个人简介

一个现在有点想法的IT民工

文章分类
文章存档

2015年(1)

2014年(6)

2011年(4)

2010年(5)

2008年(1)

2007年(6)

我的朋友

分类: 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); "

阅读(694) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~