Adding a new System Call

Adding a new System Call - system calls as empty functions...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Adding a new System Call You will need two new system calls and also export the sys_call_table. We explain here how to add a simple system call. You can see a tutorial in how to do this in: http://macboypro.wordpress.com/2009/05/15/adding-a- Here is a summary of the steps.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Adding a new System Call 1. Edit /usr/src/linux- 3.0/kernel/sys.c and add the following code at the end of the file. SYSCALL_DEFINE1(myhello, const char __user *, msg) { printk(KERN_EMERG "Calling sys_myhello\n"); int i = 0; char ch; do { get_user(ch, msg + i); i++; printk(KERN_EMERG "%c", ch); } while (ch != 0);
Background image of page 2
Adding a new System Call This system call will take a single parameter msg that will be printed in /var/log/syslog The loop will copy character by character the message passsed as parameter to print it in the log file. Also, the last few lines exports the sys_call_table so it can be accessed by the loadable modules. For your project we recommend to implement the new
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: system calls as empty functions and then intercept them in your loadable module so you dont need to have to recompile the kernel every single time you do a modification. Adding a new System Call 2. In /usr/src/linux-3.0/arch/x86/include/asm/unistd_32.h add the new myhello call. Find the right place for this call. Also increase NR_syscalls #define __NR_myhello 347 #ifdef __KERNEL__ #define NR_syscalls 348 Adding a new System Call 3. In /usr/src/linux-3.0/arch/x86/include/asm/syscalls.h find the X86_32 section and add: /* X86_32 only */ #ifdef CONFIG_X86_32 /* X86_32 only */ /* kernel/sys.c */ asmlinkage int sys_myhello(); Adding a new System Call 4. In /usr/src/linux-3.0/arch/x86/kernel/syscall_table_32.S add at the end: .long sys_clock_adjtime .long sys_syncfs .long sys_sendmmsg /* 345 */ .long sys_setns .long sys_myhello...
View Full Document

This note was uploaded on 01/30/2012 for the course CS 354 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 6

Adding a new System Call - system calls as empty functions...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online