2016-02-19 36 views
0

我想在FreeBSD上添加新的系統調用。我的系統調用的代碼是:在FreeBSD 10.1上添加新的系統調用

#include <sys/types.h> 
#include <sys/param.h> 
#include <sys/systm.h> 
#include <sys/kernel.h> 
#include <sys/proc.h> 
#include <sys/mount.h> 
#include <sys/sysproto.h> 

int Sum(int a, int b); 

int 
Sum(a,b) 
{ 
    int c; 
    c = a + b; 
    return (0); 
} 

但是,當我重新編譯內核,我有一個錯誤:

enter image description here

有什麼不對?你可以幫我嗎?

非常感謝。

+0

我的代碼是否正確? – user3228884

+0

你能編輯你的問題,包括代碼和錯誤作爲純文本,而不是包括截圖? – ajshort

+0

@ajshort是的,我改變它:) – user3228884

回答

4

下面是我用我的示例系統調用setkey取得兩個無符號整數的方法。 我說我的系統調用/kern/syscalls.master

546 AUE_NULL STD { int setkey(unsigned int k0, unsigned int k1);} 

然後我做了

cd /usr/src 
sudo make -C /sys/kern/ sysent 

接下來年底,我加入了文件/ SYS/conf目錄/文件

kern/sys_setkey.c  standard 

我的sys_setkey.c如下

#include <sys/sysproto.h> 
#include <sys/proc.h> 

//required for printf 
#include <sys/types.h> 
#include <sys/systm.h> 

#ifndef _SYS_SYSPROTO_H_ 
struct setkey_args { 
    unsigned int k0; 
    unsigned int k1; 
}; 
#endif 
/* ARGSUSED */ 
int sys_setkey(struct thread *td, struct setkey_args *args) 
{ 
    printf("Hello, Kernel!\n"); 
    return 0; 
} 

另外,我加入系統調用/kern/capabilities.conf

## 
## Allow associating SHA1 key with user 
## 
setkey 

最後,雖然在/ usr/SRC/I運行的命令

sudo make -j8 kernel 
sudo reboot 

這是運行的程序系統調用

#include <sys/syscall.h> 
#include <unistd.h> 
#include <stdio.h> 
int main(){ 
//syscall takes syscall.master offset,and the system call arguments 
printf("out = %d\n",syscall(546,1,1)); 
return 0; 
} 
0

請仔細閱讀this

我想,你已經不包含在覈心的makefile sys_Sum功能(注意,在你的代碼文件,您提供,函數名是Sum和錯誤有請致電sys_Sum。我希望,這只是你的代碼中的一個錯字,功能名稱是sys_Sum)。

+0

我輸入我的系統調用名稱在usr/src/sys/conf --->文件......這是真的嗎?如果沒有,我應該更改的make文件目錄在哪裏? – user3228884

+0

我正在談論名稱爲'Makefile'的文件。如果您不熟悉makefile,請閱讀一些關於它的教程(開始 - https://en.wikipedia.org/wiki/Makefile) –

相關問題