實驗環境:服務器版Ubuntu,內核版本
●添加系統調用的入口參數
進入解壓得到的內核文件夾linux-2.6.30.6中,在linux-2.6.30.6/arch/x86/include/asm/unistd_32.h文件中增加:
#define __NR_zzr_calculator 335
添加系統調用的入口參數(注意:其中會順序定義入口參數的序號,添加的序號是在原有最大值的基礎上+1)
●在linux-2.6.30.6/arch/x86/kernel/syscall_table_32.S 中添加:.long sys_zzr_calculator/* 335 */
●添加自定義系統響應函數
修改linux-2.6.30.6/kernel/sys.c文件,在文件末尾添加自定義的系統響應函數。函數實現如下:
/* The system call function
Added in by ZZR. */
asmlinkage int sys_zzr_calculator(int *result, int first, int second, char op)
{
switch(op){
case '+': *result = first + second; break;
case '-': *result = first - second; break;
case '*': *result = first * second; break;
case '/':
if(second == 0){
printk("divisor can't be 0.\n");
return -1;
}
*result = first / second; break;
default:
printk("operator is illegal.\n");
return -1;
}
return 0;
}
更多詳情見請繼續閱讀下一頁的精彩內容: http://www.linuxidc.com/Linux/2014-05/102423p2.htm
Linux內核編譯步驟(手動安裝內核) http://www.linuxidc.com/Linux/2013-03/80271.htm
Linux內核編譯錯誤:error: read-only variable '__r2' used as 'asm' output http://www.linuxidc.com/Linux/2012-12/76859.htm
Linux內核編譯與安裝 http://www.linuxidc.com/Linux/2012-10/71689.htm
Linux內核升級及內核編譯 http://www.linuxidc.com/Linux/2012-08/68569.htm
Linux內核編譯與裁剪(ARM版) http://www.linuxidc.com/Linux/2012-07/65196.htm