How to pass a value into system call XV6

前端 未结 1 1425
情歌与酒
情歌与酒 2021-01-28 16:21

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 va

1条回答
  •  深忆病人
    2021-01-28 17:04

    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);
    

    0 讨论(0)
提交回复
热议问题