How to pass a value into system call XV6

余生颓废 提交于 2020-01-06 05:21:53

问题


I am attempting to create a system call that will increment a number that was added to the cpu struct. However I believe that a sys call has to be void so how can I pass in a value when calling it for example.

incrementNum(3);


回答1:


Xv6 has its own functions for passing arguments from user space to kernel space (system call). You can use argint() to retrieve integer arguments in your system call and argstr() to retrieve string arguments.

Passing arguments can be done the traditional way but for retrieving the arguments, you must use these methods. In your case:

In syscall.c :

extern int incrementNum(int);

static int (*syscalls[])(void) = {
...
[SYS_incrementNum]  sys_incrementNum,
};

In syscall.h

#define SYS_incrementNum 22

In user.h

int incrementNum(int);

In Usys.S

SYSCALL(incrementNum);

In sysproc.c (where you want to retrieve the argument)

int 
sys_incrementNum(int num)
{
    argint(0,&num); //retrieving first argument
    cprintf("%d - Inside system call!",num);
}

Calling the system call can now be done via:

incrementNum(3);


来源:https://stackoverflow.com/questions/46870509/how-to-pass-a-value-into-system-call-xv6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!