From owner-freebsd-hackers Wed Nov 8 12: 5:40 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from smtp04.primenet.com (smtp04.primenet.com [206.165.6.134]) by hub.freebsd.org (Postfix) with ESMTP id A9B9137B479 for ; Wed, 8 Nov 2000 12:05:37 -0800 (PST) Received: (from daemon@localhost) by smtp04.primenet.com (8.9.3/8.9.3) id NAA14215; Wed, 8 Nov 2000 13:02:10 -0700 (MST) Received: from usr08.primenet.com(206.165.6.208) via SMTP by smtp04.primenet.com, id smtpdAAAdZaiGB; Wed Nov 8 13:01:54 2000 Received: (from tlambert@localhost) by usr08.primenet.com (8.8.5/8.8.5) id NAA24535; Wed, 8 Nov 2000 13:05:12 -0700 (MST) From: Terry Lambert Message-Id: <200011082005.NAA24535@usr08.primenet.com> Subject: Re: system call and SYSCALL macro To: rlaw@vt.edu (Raymond Law) Date: Wed, 8 Nov 2000 20:05:12 +0000 (GMT) Cc: freebsd-hackers@FreeBSD.ORG In-Reply-To: <4.3.0.20001106131527.00df0cc0@mail.vt.edu> from "Raymond Law" at Nov 06, 2000 01:16:51 PM X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > 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