加入新的linux系統調用

來源:互聯網
上載者:User

標籤:cal   標頭檔   white   read   info   簡介   str   ini   linkage   

上一篇詳解了linux系統調用的原理,接下來依據上一篇的原理簡介怎樣建立新的linux系統調用

向核心中加入新的系統調用,須要運行3個步驟:
1. 加入新的核心功能
2. 更新標頭檔unistd.h
3. 針對這個新函數更新系統調用表calls.S


1. 在kernel/sys.c中加入函數:
asmlinkage int sysMul(int a, int b)
{
int c;
c = a*b;
return c;
}


2.在arch/arm/include/asm/unistd.h中加入系統調用編號:加入例如以下

#define __NR_preadv(__NR_SYSCALL_BASE+361)
#define __NR_pwritev (__NR_SYSCALL_BASE+362)
#define __NR_rt_tgsigqueueinfo (__NR_SYSCALL_BASE+363)
#define __NR_perf_event_open (__NR_SYSCALL_BASE+364)
#define __NR_sysMul(__NR_SYSCALL_BASE+365)

備忘:在最後面加入


3.在arch/arm/kernel/calls.S中加入代碼,指向新實現的系統調用函數:

/* 360 */ CALL(sys_inotify_init1)
CALL(sys_preadv)
CALL(sys_pwritev)
CALL(sys_rt_tgsigqueueinfo)
CALL(sys_perf_event_open)

CALL(sysMul)

備忘:必須在最後面加入和unistd.h中的系統調用號一樣


4.又一次編譯核心

make  uImage ARCH=arm  CROSS_COMPILE=arm-linux-


5.把核心複製到tftp檔案夾以下

cp arch/arm/boot/uImage  /tftpboot/

備忘:第5步能夠不用那個是為了通過tftp下載到開發板


6.使用系統調用

#include <stdio.h>
#include <linux/unistd.h>
main()
{

int result;
result = syscall(361,1, 2);//syscall過程 1、把系統調用號mov  r7,  #365  2、使用svc指令  

//syscall(系統調用號。參數1,參數2) 當中參數1和參數2是sysMul的兩個參數
printf("result = ", result);
}


加入新的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.