【原創】Linux 增加系統調用

來源:互聯網
上載者:User

標籤:

首先將核心檔案移至/usr/src/下並解壓。

過程參考http://www.cnblogs.com/kavs/p/4607371.html

然後。。開始增加系統調用。。

sudo gedit /usr/src/linux-4.0.6/kernel/sys.c

插入標頭檔 #include <linux/linkage.h>

   1: /* 
   2: *leemo‘s own define task 
   3: */ 
   4: asmlinkage int sys_leemohello(char * buf){ 
   5:     printk(KERN_EMERG"===this is leemo‘s work ====="); 
   6:     printk(KERN_EMERG"==2012221107110095 leemo",buf); 
   7:     return 1; 
   8: }

sudo gedit /usr/src/linux-4.0.6/arch/x86/syscalls/syscall_32.tbl

記住增加的系統號 如上面的359

sudo gedit /usr/src/linux-4.0.6/arch/x86/include/asm/syscalls.h

 

編譯核心。。。。過程參考http://www.cnblogs.com/kavs/p/4607371.html

編譯完成後重啟。

編寫測試代碼

1、先建個檔案夾mkdir leemotest

2、建立測試代碼sudo gedit testleemohello.c 鍵入代碼:

   1: #include <stdio.h>
   2: int main()
   3: {
   4:     int rs;
   5:     char * buf="leemo";
   6:     rs=syscall(359,buf);
   7:     printf("%d %s \n",rs,buf);
   8:     if(rs==1){
   9:         printf("system call is success!\n");
  10:     }
  11:     else
  12:         printf("sorry,failed!\n");
  13:     return 0;
  14: }

編譯測試代碼:

gcc testleemohello.c -o testleemohello

運行測試代碼:

./testleemohello

結果:

接著輸入dmesg

 

調用完成。

【原創】Linux 增加系統調用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.