1. 程式人生 > >Linux核心2.6.34.14新增系統呼叫及編譯方法(CentOS-6.4-x86_64)

Linux核心2.6.34.14新增系統呼叫及編譯方法(CentOS-6.4-x86_64)

<?xml version="1.0" encoding="UTF-8"?>
//我新增系統呼叫步驟,僅供參考,尤其是系統呼叫的實現部分,建議大家自己寫,除了我這種好像還可以用sys_open系列來寫

#define 核心版本 linux-2.6.34.14
#define 作業系統 CentOS-6.4-x86_64

int main()
{

  下載核心並解壓到任意位置

  if ( 你當前的系統是x86_32系統 ) {
32位系統的步驟()
  } else if ( 你當前的系統是x86_64系統 ){
64位系統的步驟()
  } else {
//???
  }

  共同操作1()
  共同操作2()
//共同操作3()		//make install似乎已經完成了該步驟
reboot } 32位系統的步驟(){ 解壓後在linux-2.6.34.14/arch/x86/kernel中的syscall_table_32.S檔案中, 新增一行 .long sys_filecopy 然後進入linux-2.6.34.14/arch/x86/include/asm資料夾,開啟unistd_32.h,將 #define NR_syscalls 338 改為 #define NR_syscalls 339 然後加上一行: #define __NR_filecopy 338 } 64位系統的步驟(){ 然後開啟linux-2.6.34.14/arch/x86/include/asm/unistd_64.h,加上下面兩行:
#define __NR_filecopy 300 __SYSCALL(__NR_filecopy, sys_filecopy) 再開啟linux-2.6.34.14/include/linux/syscalls.h新增宣告: asmlinkage long sys_filecopy( char *in , char *out ); } 共同操作1(){ 再開啟linux-2.6.34.14/kernel下的sys.c並在末尾插入如下程式碼: asmlinkage long sys_filecopy( char *in , char *out ) {
struct file* filpin = NULL; struct file* filpout = NULL; constint BUF_SIZE = 2048; char buf[BUF_SIZE]; int num; mm_segment_t oldfs; oldfs = get_fs(); set_fs(get_ds()); filpin = filp_open(in, O_RDONLY, 0); filpout = filp_open(out, O_CREAT|O_WRONLY, 0644); printk( "<0>""start writing in kernel !...\n" ); do{ num = vfs_read( filpin , buf , BUF_SIZE , &filpin->f_pos ); vfs_write( filpout , buf , num , &filpout->f_pos ); }while( num == BUF_SIZE ); filp_close( filpin , NULL ); filp_close( filpout , NULL ); printk( "<0>""done writing in kernel !...\n" ); set_fs(oldfs); return 0; } } 共同操作2(){ 開啟終端,cd到linux-2.6.34.14目錄下,輸入以下命令: make xconfig // 使用Qt的圖形介面進行配置 make -j4 bzImage // j for jobs,現在主流的雙核心四執行緒處理器 make -j4 modules // 使用該選項可以讓四個核心同時以超過90%的使用率工作 make modules_install make install } //以下已經無需執行 共同操作3(){ if ( 你使用的是基於Debian的系統 ) // 如ubuntu和Mint mkinitramfs -o /boot/initrd-2.6.34.14.img 2.6.34.14 else if ( 你是用的是基於RedHat的系統 ) // 如CentOS和Fedora mkinitrd -v /boot/initramfs-2.6.34.14.img 2.6.34.14 else //??? 在grub.conf內新增 title CentOS (2.6.34.14) root (hd0,8) kernel /vmlinuz-2.6.34.14 ro root=LABEL=/ rhgb quiet initrd /initramfs-2.6.34.14.img }