如何在XV6中将值传递给系统调用函数? [英] How to pass a value into a system call function in XV6?
问题描述
我正在尝试在XV6中创建一个基于优先级的简单调度程序.为此,我还必须创建一个系统调用,该调用将允许进程设置其优先级.我已经完成了创建系统调用所需的一切,如此处和其他地方所述:
I am attempting to create a simple priority based scheduler in XV6. To do this, I also have to create a system call that will allow a process to set its priority. I have done everything required to create the system call as discussed here and elsewhere:
问题是,我在调用函数时不能传递任何变量,或者说,它像没有错一样运行,但是正确的值未在函数内部显示.
The problem is, I cannot pass any variables when I call the function, or rather, it runs like nothing is wrong but the correct values do not show up inside the function.
外部声明(syscall.c):
Extern declaration (syscall.c):
...
extern int sys_setpty(void);
static int (*syscalls[])(void) = {
...
[SYS_setpty] sys_setpty,
};
系统调用向量(syscall.h):
Sys-call Vector (syscall.h):
#define SYS_setpty 22
实施(sysproc.c):
Implementation (sysproc.c):
void
sys_setpty(int pid, int pty)
{
cprintf("function pid: %d \n", pid);
cprintf("function pty: %d \n", pty);
}
(defs.h& user.h):
(defs.h & user.h):
void setpty(int, int);
微距(usys.S):
Macro (usys.S):
SYSCALL(setpty)
函数调用:
setpty(3, 50);
输出:
function pid: 16843009
function pty: 16843009
这些值始终是相同的精确数字:16843009.我已经通过将值分配给pid和pty来检查cprintf是否正常工作.我花了大约6个小时来尝试我能想到的所有可能组合,而且我开始认为没有内置的机制可以通过XV6中的系统调用来传递值.我想念什么吗?预先谢谢你.
The values are always the same exact number: 16843009. I have checked to see if the cprintf is working correctly by assigning values to pid and pty. I have spent about 6 hours trying every possible combination of everything I can think of and I'm starting to think that there is no built in mechanism for passing values via a system call in XV6. Am I missing something? Thank you in advance.
推荐答案
在XV6中无法将参数从用户级函数传递到内核级函数. XV6具有自己的内置函数,用于将参数传递给内核函数.例如,要传入整数,将调用argint()函数.在我用于set-priority函数的实现中,它看起来类似于:
Passing arguments from user-level functions to kernel-level functions cannot be done in XV6. XV6 has its own built-in functions for passing arguments into a kernel function. For instance, to pass in an integer, the argint() function is called. In the implementation that I used for the set-priority function, that would look something like:
argint(0, &pid);
...获取第一个参数,即进程ID,并且:
... to get the first argument which is the Process ID, and:
argint(1, &pty);
...获取第二个参数,它是所需的优先级.来自用户进程的函数调用如下所示:
... to get the second argument which is the desired priority. The function call from the user process looks like this:
setpty(getpid(), priority);
这篇关于如何在XV6中将值传递给系统调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!