Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
@bsat: Procedure I used to add system call, Can you spot me what is wrong in this?
•The directory/file naming convention may include either i386 (older versions) or x86, or x64 as welll as suffixes _32 or _64.
•Add new call to syscall table
◦gedit /usr/src/mylinux/arch/x86/kernel/syscall_table_32.S &
◦Add “.long sys_test_call” to the bottom of the file. Pay attention to use of spaces and TABs as white space in this and all other files that you are going to edit.
•Add new call to unistd.h
◦gedit /usr/src/mylinux/include/asm-generic/unistd.h &
◦Find and Increment NR_syscalls by one, i.e. if the number was 242, it should be now 243
◦Just above that line there should be a line contaning __NR_XXXX 241 that was one less than the original value of NR_syscalls.
Insert an additional entry shown below. If the last define is number in this section was 241 then use 242, which is one less than NR_syscalls.
/* test_call/. HOMEWORK only */
#define __NR_test_call 242
__SYSCALL(__NR_test_call, sys_test_call)
•Add new call prototype to syscalls.h
◦gedit /usr/src/mylinux/include/linux/syscalls.h &
◦Add at the end of the file asmlinkage long sys_test_call(unsigned short);
•Add test_call to core-y in Makefile
◦gedit /usr/src/mylinux/Makefile &
◦Search for core-y to find the line “core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/”
◦Add “test_call/” to the end of the line
•Create a new directory for the call
◦mkdir test_call
◦cd test_call
•Create a new file in the test_call directory.
◦gedit /usr/src/mylinux/test_call/test_call.c &
◦Enter the following text
/*----------Start of test_call.c----------*/#include <linux/linkage.h>
#include <linux/kernel.h>
asmlinkage long sys_test_call(unsigned short n)
{
unsigned short i;
for (i=0; i<n; i++)
printk(KERN_EMERG "Kernel Hello World! by <insert your name here>\n");
return n;
}
/*-----------End of test_call.c-----------*/◦Save file as test_call.c in the test_call directory
•Create a Makefile in the test_call directory.
◦gedit /usr/src/mylinux/test_call/Makefile &
◦Enter the following text
########## Start of Makefile ##########
obj-y := test_call.o
########## End of Makefile ##########◦Save file as Makefile in the test_call directory
I am following the above procedure for adding a system call to kernel, Can you say me what is the error in the above procedure,
I am doing it on Ubuntu 10.04.2
I am following the above procedure for adding a system call to kernel, Can you say me what is the error in the above procedure,
I am doing it on Ubuntu 10.04.2
You need to tell us what error you are getting when you do this. Does the kernel compile with no warnings? Does the test code succeed? How do you know its not working?
/*----------Start of test_call_run.c----------*/
#include <stdio.h>
#include <unistd.h> // to use syscall
// Reminding that sys_test_call function is filed under the system call 242
#define __NR_test_call 242
// Calling a macro to define a system call with N parameters that returns a long
long test_call()
{
return( syscall(__NR_test_call, 3) );
}
int main()
{
long status = test_call();
printf("Our test system call was called and returned status %ld\n", status);
return(0);
}
/*-----------End of test_call_run.c-----------*/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.