Presentation is loading. Please wait.

Presentation is loading. Please wait.

Build Linux Kernel, Add a New System Call to Linux Young Chi-Min

Similar presentations


Presentation on theme: "Build Linux Kernel, Add a New System Call to Linux Young Chi-Min"— Presentation transcript:

1 Build Linux Kernel, Add a New System Call to Linux Young Chi-Min s9256029@cs.nchu.edu.tw s9256029@cs.nchu.edu.tw

2 Compile your own Linux kernel Get the source The Linux Kernel Archives - http://www.kernel.orghttp://www.kernel.org - ftp://linux.cis.nctu.edu.tw/kernel/( 交大資科 )ftp://linux.cis.nctu.edu.tw/kernel/ - http://ftp.nsysu.edu.tw/Linux/Kernel/linux/kernel/http://ftp.nsysu.edu.tw/Linux/Kernel/linux/kernel/ ( 中山大學 )

3 Compile your own Linux kernel Steps: 1 Get the kernel source from ftp 2 Installing the kernel source code - kernel source is put in /usr/src - #cd /usr/src - #tar xvzf linux-2.4.x.tar.gz 3 make mroproper (Cleanup /usr/src/linux/ 目錄所有.o 的 object file, dependencies and kernel’s.config)

4 Compile your own Linux kernel Steps: 4 Setup the kernel configuration make config or menuconfig or xconfig 5 #make dep 6 #make clean 7 #make bzImage 8 #make modules 9 #make modules_install (Modules will be installed in /lib/modules/2.4.x) 10 #make install

5 Compile your own Linux kernel Edit Bootloader Configuration File -- /etc/lilo.conf # lilo ( 完成 ) timeout=50 default ….. image=/boot/vmlinuz-2.4.18 label=linux-2.4.18 read-only root=/dev/

6 Add a New System Call Edit : /usr/src/linux/include/asm/unistd.h #define __NR_exit 1 #define __NR_fork 2 … … #define __NR_lremovexattr 236 #define __NR_fremovexattr 237 #define __NR_hello 239 add #defines for you new system calls at the end

7 Add a New System Call Edit the file : /usr/src/linux/arch/i386/kernel/entry.S.data ENTRY(sys_call_table).long SYMBOL_NAME(sys_ni_syscall) /* 0.long SYMBOL_NAME(sys_exit).long SYMBOL_NAME(sys_fork) ….long SYMBOL_NAME(sys_ni_syscall).long SYMBOL_NAME(sys_hello).rept NR_syscalls-(.-sys_call_table)/4.long SYMBOL_NAME(sys_ni_syscall).endr

8 Add a New System Call  Definition your source code files (hello.c and hello.h)  About Header file Machine architecture independent system calls and functions are kept under linux/include/linux Machine architecture independent ones are kept under linux/include/asm

9 Add a New System Call Modify the Makefile in the directory you placed your.c file so that your code gets compiled and linked in properly Modify the Makefile line to have a.o of your source code For example. Adding hello.o O_OBJS += …. Hello.o

10 Add a New System Call Example : hello.c and hello.h hello.h(assuming hello.h is under linux/include/linux) #ifndef __LINUX_HELLO_H #define __LINUX_HELLO_H #include #endif

11 Add a New System Call hello.c hello.c (system call implementation) #include Asmlinkage int sys_hello(){ printk(KERN_ALERT “hello\n”); //KERN_EMERG return 0; }

12 Add a New System Call User application App.c #include _syscall0(int, hello); Int main(){ hello(); return 0; } p.s if compiler error mv /usr/include/linux /usr/include/linux.bak mv /usr/iinclude/asm /usr/include/asm.bak ln –s /usr/src/linux/include/linux /usr/include/linux ln –s /usr/src/linux/include/asm /usr/include/asm

13 Add a New System Call There are some macros defined for this in The format is “_syscallN(return type, function name,arg1 type,arg1 name…)” where “N” is the number of parameters. For example : _syscall1(int, hello, int, a)

14 Add a New System Call printk int printk(const char *fmt , …); ( printk() 的參數使用類似於 printf(). 此外,訊息前頭可以利用巨集來指定訊息的重要性 ( 稱為訊息層級 ) 。) example : printk(KERN_ALERT “hello”); 使用 printk() 輸出的訊息會先存在 log 日誌中, 系統會根據訊息層級來決定要不要將訊息寫到 console 只有高於 log 層級, 才會送到將訊息送到 console 利用 syslog() system call long sys_syslog(int type, char *buf, int len);

15 Reference http://fossil.wpi.edu/docs/howto_add_systemc all.html http://fossil.wpi.edu/docs/howto_add_systemc all.html http://pages.cpsc.ucalgary.ca/~csus/help/linu x_sys_call_howto.html http://pages.cpsc.ucalgary.ca/~csus/help/linu x_sys_call_howto.html http://appsrv.cse.cuhk.edu.hk/~csc3150/tutno te/note1/syscall.html http://appsrv.cse.cuhk.edu.hk/~csc3150/tutno te/note1/syscall.html http://www.study-area.org/


Download ppt "Build Linux Kernel, Add a New System Call to Linux Young Chi-Min"

Similar presentations


Ads by Google