Date: Wed, 8 Nov 2000 20:05:12 +0000 (GMT) From: Terry Lambert <tlambert@primenet.com> To: rlaw@vt.edu (Raymond Law) Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: system call and SYSCALL macro Message-ID: <200011082005.NAA24535@usr08.primenet.com> In-Reply-To: <4.3.0.20001106131527.00df0cc0@mail.vt.edu> from "Raymond Law" at Nov 06, 2000 01:16:51 PM
next in thread | previous in thread | raw e-mail | index | archive | help
> I just try to add a simple system call for testing: > > int my_call(int x, int y) { > return (x + y); > } > > In my user program: > > int main(int argc, char ** argv) { > int x = 3; > int y = 8; > int z = 0; > z = syscall(SYS_my_call, x, y); > printf("%i + %i = %i\n", x, y, z); > return 0; > } > > But it prints: > > 3 + 8 = -1 > > Can you give me some idea what I did wrong and what I should do? Also, can > you tell me how to use the SYSCALL macro because I am not familiar with > macros at all? Thanks in advance. Change this to: int my_call(int x, int y, int *result) { *result = x + y; return( 0); } int main( int ac, char **av) { int x = 3; int y = 8; int z = 0; if( syscall(SYS_my_call, x, y, &z) != 0) { perror("system call failed!"); exit( 1); } printf("%i + %i = %i\n", x, y, z); return 0; } --- Since you aren't checking for failure of your system call, you are confusing a failure of the call with an incorrect result. I suspect you will see the error "ENOENT", meaning that your system call has not been loaded into the kernel, and had its function pointer inserted into sysent[ SYS_my_call]. Look at the KLD documentation and examples on how to load system calls into the kernel. see also "kldstat", which should tell you where your system call was loaded (i.e. it will give you the value you need to pass as "SYS_my_call" to syscall(2) for things to work). Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200011082005.NAA24535>