From owner-freebsd-hackers Wed Nov 8 12:12: 0 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from lennier.cc.vt.edu (lennier.cc.vt.edu [198.82.161.193]) by hub.freebsd.org (Postfix) with ESMTP id 63B1337B479 for ; Wed, 8 Nov 2000 12:11:55 -0800 (PST) Received: from mail.vt.edu (gkar.cc.vt.edu [198.82.161.190]) by lennier.cc.vt.edu (8.11.0/8.11.0) with ESMTP id eA8KBst22086; Wed, 8 Nov 2000 15:11:54 -0500 (EST) Received: from zathras.cc.vt.edu ([198.82.162.117]) by gkar.cc.vt.edu (Sun Internet Mail Server sims.3.5.2000.03.23.18.03.p10) with ESMTP id <0G3Q0013I2RR8H@gkar.cc.vt.edu>; Wed, 8 Nov 2000 15:11:51 -0500 (EST) Date: Wed, 08 Nov 2000 15:10:56 -0500 From: flaw Subject: RE: system call and SYSCALL macro To: Raymond Law , Terry Lambert Cc: freebsd-hackers Message-id: <3A13684F@zathras.cc.vt.edu> MIME-version: 1.0 X-Mailer: WebMail (Hydra) SMTP v3.61 Content-type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-WebMail-UserID: flaw X-EXP32-SerialNo: 00002964 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I am not using kld to implement my system call. I am just using the old way. But I tried using pointers also. But I am not getting the correct returned values either... >===== Original Message From Terry Lambert ===== >> 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