I created two new syscalls, but when I try to test them I get the following error:
matt@ubuntu:~/test$ gcc test.c
test.c: In function ‘newcall’:
test.c:6:17: error: ‘sys_get_slob_amnt_free’ undeclared (first use in this function)
test.c:6:17: note: each undeclared identifier is reported only once for each function it appears in
matt@ubuntu:~/test$
I also tried this with syscall(sys_get_slob_amnt_free) with the same result.
Here is the test code:
#include <unistd.h>
#include <stdio.h>
unsigned long newcall()
{
return syscall(__NR_get_slob_amnt_free);
}
int main()
{
printf("%d\n", newcall());
return 0;
}
In order to add these I put them in the syscall table (/usr/src/linux-3.0/include/asm-generic/unistd.h)
#define __NR_sendmmsg 269
__SC_COMP(__NR_sendmmsg, sys_ sendmmsg, compat_sys_sendmmsg)
/** my changes here **/
#define __NR_get_slob_amnt_free 270
__SYSCALL(__NR__get_slob_amnt_free, sys_get_slob_amnt_free)
#define __NR_get_slob_amnt_claimed 271)
__SYSCALL(__NR_get_slob_amnt_claimed, sys_get_slob_amnt_claimed)
/** /my changes **/
#undef __NR_syscalls
#define __NR_syscalls 272
And here is the code for the calls themselves (../linux-3.0/mm/slob.c)
asmlinkage unsigned int sys_get_slob_amnt_claimed()
{
return memClaimed;
}
asmlinkage unsigned int sys_get_slob_amnt_free()
{
return memClaimed - memUsed;
}
I'm trying to figure out whether I'm botching the test code (maybe I need to include something more? or link something?) Or if I've overlooked something in adding the syscall in the first place. With the amount of time it takes to recompile the kernel, it would really help me out to know where to start looking.
Admittedly, this is related to a homework assignment. The assignment is about modifying slob.c, which I have a pretty good handle on. I'm just doing this to get a peek at whether the modifications I've made so far are going anywhere. I appreciate any guidance you can give. Thanks!
Edit: Solved (or at least solved enough for me).
Many thanks to bdonlan! Although syscall(270)
didn't do it directly, it jogged my memory--there is another set of relevant numbers that I was neglecting entirely. The file /linux-3.0/arch/x86/kernel/syscall_table_32.c
needed to be modified as well in order to properly add the syscall.
Once I added .long sys_get_slob_amnt_free
and .long sys_get_slob_amnt_claimed
to that file and rebuilt the kernel, I could hit my syscalls by using syscall(###)
where ### is the numbering in syscall_table_32.c (not the numbering in unistd.h). I feel like they should match--but since this is just glorified debug information I think I'll leave that mystery for another time and just call it good.
System call table is an array of function pointers. It is defined in kernel space as variable sys_call_table and it contains pointers to functions which implement system calls.
System calls are sometimes called kernel calls. However, there are times when you want to make a system call explicitly, and for that, the GNU C Library provides the syscall function.
There is another set of relevant numbers that I was needed to add. The file /linux-3.0/arch/x86/kernel/syscall_table_32.c needed to be modified as well in order to properly add the syscall.
Once I added .long sys_get_slob_amnt_free
and .long sys_get_slob_amnt_claimed
to that file and rebuilt the kernel, I could hit my syscalls by using syscall(###) where ### is the numbering in syscall_table_32.c (not the numbering in unistd.h)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With