Date: Wed, 08 Nov 2000 15:10:56 -0500 From: flaw <flaw@vt.edu> To: Raymond Law <rlaw@vt.edu>, Terry Lambert <tlambert@primenet.com> Cc: freebsd-hackers <freebsd-hackers@FreeBSD.ORG> Subject: RE: system call and SYSCALL macro Message-ID: <3A13684F@zathras.cc.vt.edu>
next in thread | raw e-mail | index | archive | help
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 <tlambert@primenet.com> =====
>> 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?3A13684F>
