syscall returns value -1

I'm trying to add a simple syscall addition in the kernel and after compilation and reboot the syscall is returning -1. May I know what is the issue here?

I have added this to syscalls.master:

Code:
441     MSTD    BSD     { int test(int x, int y); }

Checked added lines in sysproto.h and added the functions in kern_event.c source file after this kernel is compiled and server is rebooted

Now I wrote a simple program to check how the syscall works but it's returning -1 for all values.

Code:
#include<unistd.h>
#include<stdio.h>

int main()
{
        int b;
        b=syscall(441,4,5);
        printf("The addition is %d\n\n\n",b);
        return 0;
}
Can anybody help me and tell me where I might have gone wrong?

Thanks

BR
Saurabh
 
From syscall(2):
Code:
RETURN VALUES
     The return values are defined by the system call being invoked.  In gen-
     eral, a 0 return value indicates success.  [b]A -1 return value indicates an
     error, and an error code is stored in errno.[/b]
 
What version of FreeBSD (obviously not 9... as 441 is taken)? Did you add an entry in syscalls.c? Need to see your actual syscall code test() routine. Not a very good name for a routine.

Does test() look like:

Code:
int test(td, uap)
struct thread *td;
struct test_args *uap;
{
...
}

You should study the code behind some very simple syscall, like setuid(). I'm guessing you aren't handling correctly the actual syscall interface in the kernel and how to get arguments from user space.
 
Hey...
Thanks for the reply

Test looks like this. I have included it in sys_pipe.c. Is it necessary to put the code in syscalls.c?

Code:
int     sys_test(struct thread *p, struct test_args *q)
{
        int a;
        a=q->x+q->y;
        return a;
}

The version is FreeBSD 9.0-RELEASE FreeBSD 9.0-RELEASE #2:
I have changed the syscall number to 180. I am confused at every level. Can u you tell me why it is giving an error code?

Thanks

Best regards
Saurabh
 
In syscalls.master:

Code:
441     STD    BSD     { int sys_test(int x, int y); }

but then the code for sys_test() needs different than what you wrote.
Look at the code for setuid() and getpid() or getuid().

You are probably getting an error because you are returning a which is probably non-zero. The way that syscalls work is that if you return 0, that means no error, and if you return non-zero, that is the error code (stored in errno).

Instead try:

Code:
td->td_retval[0] = a;
return(0);
 
Back
Top