英文:
value not ignored "(argaddr(0, &fva)"
问题
抱歉,以下是翻译好的部分:
我想要添加 xv6 页面表功能。然而,出现了一些关于 argaddr
和 argint
的错误。为什么?
实验参考链接:xv6 页面表
int sys_pgaccess(void){
uint64 fva;
int pnum;
uint64 abits;
int res = 0;
pte_t* pte_addr;
pte_t pte;
if(argaddr(0, &fva) < 0) {
return -1;
}
if(argint(1, &pnum) < 0) {
return -1;
}
kernel/sysproc.c: 在函数‘sys_pgaccess’中:
kernel/sysproc.c:105:6: 错误:应该忽略 void 值
105 | if(argaddr(0, &fva) < 0) {
| ^~~~~~~~~~~~~~~~
kernel/sysproc.c:108:6: 错误:应该忽略 void 值
108 | if(argint(1, &pnum) < 0) {
| ^~~~~~~~~~~~~~~~
我是初学者,所以我查看了 argaddr
等函数的代码,但无法理解它。
英文:
I am looking to add xv6 page table functionality. However, for some reason I am getting errors with argaddr
and argint
. Why?
Lab reference: xv6 page table
int sys_pgaccess(void){
uint64 fva;
int pnum;
uint64 abits;
int res = 0;
pte_t* pte_addr;
pte_t pte;
if(argaddr(0, &fva) < 0) {
return -1;
}
if(argint(1, &pnum) < 0) {
return -1;
}
kernel/sysproc.c: In function 'sys_pgaccess':
kernel/sysproc.c:105:6: error: void value not ignored as it ought to be
105 | if(argaddr(0, &fva) < 0) {
| ^~~~~~~~~~~~~~~~
kernel/sysproc.c:108:6: error: void value not ignored as it ought to be
108 | if(argint(1, &pnum) < 0) {
| ^~~~~~~~~~~~~~~~
I am a beginner so I looked at the code for argaddr
, etc., but could not understand it.
答案1
得分: 4
The compiler is telling you that argaddr
and argint
are void functions, and do not return a value.
You cannot compare nothing with an integer.
Looking at kernel/syscall.c from mit-pdos/xv6-riscv, we can see the RISC-V function definitions:
// Fetch the nth 32-bit system call argument.
void
argint(int n, int *ip)
{
*ip = argraw(n);
}
// Retrieve an argument as a pointer.
// Doesn't check for legality, since
// copyin/copyout will do that.
void
argaddr(int n, uint64 *ip)
{
*ip = argraw(n);
}
The contents of the lab linked deal with RISC-V.
It appears you should simply remove the conditionals:
int sys_pgaccess(void)
{
uint64 fva;
int pnum;
/* ... */
argaddr(0, &fva);
argint(1, &pnum);
/* ... */
}
For completeness, the x86 versions of these functions do return values, so you may have read the wrong documentation.
syscall.c from the no longer maintained mit-pdos/xv6-public contains the x86 definitions:
// Fetch the int at addr from the current process.
int
fetchint(uint addr, int *ip)
{
struct proc *curproc = myproc();
if(addr >= curproc->sz || addr+4 > curproc->sz)
return -1;
*ip = *(int*)(addr);
return 0;
}
// Fetch the nth 32-bit system call argument.
int
argint(int n, int *ip)
{
return fetchint((myproc()->tf->esp) + 4 + 4*n, ip);
}
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size bytes. Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
int i;
struct proc *curproc = myproc();
if(argint(n, &i) < 0)
return -1;
if(size < 0 || (uint)i >= curproc->sz || (uint)i+size > curproc->sz)
return -1;
*pp = (char*)i;
return 0;
}
英文:
The compiler is telling you that argaddr
and argint
are void functions, and do not return a value.
You cannot compare nothing with an integer.
Looking at kernel/syscall.c from mit-pdos/xv6-riscv, we can see the RISC-V function definitions:
// Fetch the nth 32-bit system call argument.
void
argint(int n, int *ip)
{
*ip = argraw(n);
}
// Retrieve an argument as a pointer.
// Doesn't check for legality, since
// copyin/copyout will do that.
void
argaddr(int n, uint64 *ip)
{
*ip = argraw(n);
}
The contents of the lab linked deal with RISC-V.
It appears you should simply remove the conditionals:
int sys_pgaccess(void)
{
uint64 fva;
int pnum;
/* ... */
argaddr(0, &fva);
argint(1, &pnum);
/* ... */
}
For completeness, the x86 versions of these functions do return values, so you may have read the wrong documentation.
syscall.c from the no longer maintained mit-pdos/xv6-public contains the x86 definitions:
// Fetch the int at addr from the current process.
int
fetchint(uint addr, int *ip)
{
struct proc *curproc = myproc();
if(addr >= curproc->sz || addr+4 > curproc->sz)
return -1;
*ip = *(int*)(addr);
return 0;
}
// Fetch the nth 32-bit system call argument.
int
argint(int n, int *ip)
{
return fetchint((myproc()->tf->esp) + 4 + 4*n, ip);
}
// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size bytes. Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
int i;
struct proc *curproc = myproc();
if(argint(n, &i) < 0)
return -1;
if(size < 0 || (uint)i >= curproc->sz || (uint)i+size > curproc->sz)
return -1;
*pp = (char*)i;
return 0;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论