Making system calls using kernel moduleBuilding system calls in kernel module is more flexible than modifying kernel. When we want to use our system call, just install our kernel modules; and if we don’t need it right away, just remove modules. Modifying kernel is not necessary. (But you still need to modify your kernel for O.S. project one.) FlowStep 0.Download the latest kernel and compile it. Unzip it to /usr/src/ Step 1.Export sys_call_table For sys_call_table, your should extern it in a file such as <top directory to the kernel sources>/arch/x86/kernel/i386_ksyms_32.c. note: sys_call_table is read-only after kernel version 2.6.23. If you really want to try this method using kernel version which is higher than 2.6.23, you will have to modify your current kernel source and recompile it. Firstly, check your compiled kernel version uname –a In x86 32bit vim /usr/src/linux-2.6.x/arch/x86/kernel/ entry_32.S .section .rodata, “a” ?.section .data, “aw” In x86 64bit vim /usr/src/linux-2.6.x/arch/x86/kernel/syscall_64.c line 22: delete the “const” Add to export symbol vim /usr/src/linux-2.6.x/kernel/kallsyms.c extern void *sys_call_table; EXPORT_SYMBOL(sys_call_table); Step 2. Write Your Makefile vim makefile vim myservices.c Step 3.Write Kernel Module Build your own module. You can put it in <top directory to your kernel sources>/drivers/misc/ Include and Define Extern the “sys_call_table” Write your own system call Initialize the kernel module Extern the “sys_call_table” Step 4.Use Kernel Module Compile make Insert the module to kernel insmod ./myservice.ko Remove the module from kernel rmmod myservice List the modules in kernel lsmod User programInstalling your module
If you success building your module, there will be a file named myservice.ko. This file is your kernel module. insmod myservices.ko rmmod myservices Notification
ex: int a; EXPORT_SYMBOL(a); /* in the kernel */
|
|
来自: astrotycoon > 《debug》