views:

64

answers:

2

hello guys, still working on this system call!!!

i have added a system call to a kernel, compiled and the OS is running off it.

now i am getting syntax error on the compilation of my test application.

testmycall.h

#include<linux/unistd.h>

#define __NR_mycall 244

_syscall1(long, mycall, int, i)

testmycall.c

#include<stdio.h>

#include "testmycall.h"

int main(int argc, char *argv[])

{

    printf("%d\n", mycall(15));

}

here is the error

stef@ubuntu:~$ gcc -o testmycall testmycall.c
In file included from testmycall.c:3:
testmycall.h:7: error: expected ‘)’ before ‘mycall’
stef@ubuntu:~$ gcc -o testmycall testmycall.c
In file included from testmycall.c:3:
testmycall.h:7: error: expected declaration specifiers or ‘...’ before ‘mycall’
testmycall.h:7: error: expected declaration specifiers or ‘...’ before ‘i’
testmycall.c: In function ‘_syscall1’:
testmycall.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
testmycall.h:7: error: parameter name omitted
testmycall.h:7: error: parameter name omitted
testmycall.c:11: error: expected ‘{’ at end of input
stef@ubuntu

i have added in the syscall instead of _syscall1

now i get this error

stef@ubuntu:~$ gcc -o testmycall testmycall.c
testmycall.c: In function ‘syscall’:
testmycall.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
testmycall.c:11: error: expected ‘{’ 

this is the app, any ideas why???

+2  A: 

I believe the _syscallN() macros were removed from the kernel headers around 2.6.18 or so.

The (not especially helpful) error messages from gcc are due to _syscall1 not being defined at all - you get the same errors if you write:

any_old_rubbish_here(long, mycall, int, i)

The syscall() function should work. man syscall for details.

Matthew Slattery
added a new error, from the compile for syscall()
molleman
+1  A: 

The _syscall macros are obsolete and should not be used, instead use syscall, eg.

#define _GNU_SOURCE
#include <unistd.h>
...

printf("%d\n", syscall(__NR_mycall, 15));

Here's my test program:

#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>

#define __NR_mycall 244

int main(int argc, char **argv)
{
    printf("%d\n", syscall(__NR_mycall,15));
    return 0;
}
Hasturkun
same error as above for this
molleman
@molleman: I've added a test program that compiles for me
Hasturkun
cheers man, this compiles for me, it must have been to do with the header file, dont really understand why though
molleman
getting -1 printed to the console? is that a problem with my system call
molleman
the system call should add 10 to the number supplied
molleman
@molleman: You should be using whatever number your syscall has been allocated, I simply used the value you supplied. you should also check `errno` for errors on failue
Hasturkun
my error is bad address,
molleman
i have set #define __NR_mycall 244__SYSCALL(__NR_mycall, sys_mycall) in unistd.h /usr/src/linux/include/asm-generic/unistd.h
molleman
i am using this http://tldp.org/HOWTO/html_single/Implement-Sys-Call-Linux-2.6-i386/ but modified for x86 arch, but im still lost
molleman
i dont know if i am modifying the correct files in the kernel
molleman
@molleman: Is `244` really not already occupied? ie. did you define it as the previous maximum system call number? (in my case `244` is ` __NR_get_thread_area`) I also note this tutorial seems to be somewhat old.
Hasturkun
my problem is i dont know which unistd.h file i have to edit with the new system call and number
molleman
@molleman: You need to edit the `unistd.h` file in the kernel you are compiling (for your platform, if i386 then `include/asm-i386/unistd.h`), and use the same value as that. You might want to open a new question if you need further assistance
Hasturkun
@Hasturkun ok i will do it if i dont understand the problem after this question. i have mine in include/asm-generic/unistd.h , now this file goes up to 244,(my 243 is #define __NR_recvmmsg 243__SYSCALL(__NR_recvmmsg, sys_recvmmsg)) there are other unistd.h that are in folders such as arch/cris/include/asm and arch/frv/include/asm and arch/h8300/include/asm and arch/m32r/include/asm all of these have 244 as getthreadarea. but i have no idea which one to modify, im feeling lost at the moment, i running the latest linux kernel from ubuntu.
molleman
how you do the code comments
molleman
@molleman: use backticks for code comments. anyway, as I said, you need to edit the unistd.h file matching your target compilation platform, in your case you are probably running either on i386/i486/i686 or x86_64. run `uname -m` to find out.
Hasturkun
my version is , i686, what folder would that correspond to in the `arch folder, none of them say i686
molleman
@molleman: that would be i386
Hasturkun
which is x86???
molleman
@molleman: I don't really understand your last question. in any case, if you need help with the kernel modification, I suggest you ask in a separate question
Hasturkun
cheers got it done, going to post my solution
molleman