Search code examples
pointerscompiler-errorssystem-callsincompatibletypeerrorxv6

Incompatible pointer type adding system call xv6 -- using consistent return type, defined in sysfunc.h


This is my first question so constructive criticism is welcome :)

I'm struggling to add a system call to xv6. I've done this before, but I've never run into this specific error. The error I'm getting:

kernel/syscall.c:106:16: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
 [SYS_getpinfo] sys_getpinfo,

I googled around a little and it looks like the problem should either be that I didn't define my system call somewhere I should have (usually sysfunc.h), or I used a different return type in one of the definitions. The thing is, I've checked and re-checked the return types, and added the system call literally everywhere I can think of, and I'm still getting this error.

I'm wondering if there's a way to just cast the pointer type? Anyways, if you have any idea why this is still happening, or how to fix it, I'd really appreciate it.

Here's everywhere I've defined my system call:

sysproc.c:

int sys_getpinfo(struct pstat* p){
    //implementation
}

sysfunc.h:

int sys_getpinfo(struct pstat*);

user.h:

int getpinfo(struct pstat*);

usys.S:

SYSCALL(getpinfo)

syscall.c:

[SYS_getpinfo] sys_getpinfo,

syscall.h:

#define SYS_getpinfo 22

Thanks for reading!


Solution

  • The syscalls static array is defined as follows (in syscall.c):

    static int (*syscalls[])(void) = {
    

    This means that all function pointers added to this array should return a int type and shouldn't expect parameters.

    The new sys function you implemented doesn't match the above because you have defined it so it expects a parameter of a struct pointer.

    Fix the function so it won't receive any parameters. If you do need a parameter from the user space for the system call implementation, you should make user space push it to its user stack and fetch it from there in the sys_getpinfo wrapper. Please see this question for more information on how.