2017-02-14 71 views
2

我是FreeBSD的初學者。我在VM上安裝了FreeBSD-11.0-RELEASE-amd64。我想添加第一個用於計算兩個值之和的新系統調用。 但我的功能有錯誤! mykern.c在FreeBSD-11上添加一個新的系統調用來計算兩個值的總和

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

    struct myargs { 
     unsigned int k0; 
     unsigned int k1; 
}; 

int sys_func(struct thread *td, struct myargs *uap); 

int sys_func (struct thread *td, struct myargs *uap) 
{ 
    unsigned int a,b,c; 
    a = uap->k0; 
    b = uap->k1; 
    c = a + b; 
    printf("%u + %u = %u\n",a,b,c); 
    return (0); 
} 

Errro!

usr/src/sys/kern/mykern.c:17:5: error: conflicting types for 'sys_func' int sys_func(struct thread *td, struct myargs *uap)

/usr/src/sys/sys/sysproto.h:2180:5: note: previous declaration is here int sys_func(struct thread *, struct func_args *);

,我讀了https://wiki.freebsd.org/AddingSyscalls

After adding an entry to sys/kern/syscalls.master, you must regenerate the generated files in sys/kern and sys/sys: 
$ make -C sys/kern/ sysent 
mv -f init_sysent.c init_sysent.c.bak 
mv -f syscalls.c syscalls.c.bak 
mv -f systrace_args.c systrace_args.c.bak 
mv -f ../sys/syscall.h ../sys/syscall.h.bak 
mv -f ../sys/syscall.mk ../sys/syscall.mk.bak 
mv -f ../sys/sysproto.h ../sys/sysproto.h.bak 
sh makesyscalls.sh syscalls.master 

一部分我檢查sysproto.h文件,並在其中:

struct func_args { 
char uap_l_[PADL_(struct myargs *)]; struct myargs * uap; char uap_r_[PADR_(struct myargs *)]; 
}; 



sys_func(struct thread *, struct func_args*); 

什麼是func_args? 有沒有解決方法?

+0

您可能會在FreeBSD IRC頻道或郵件列表中獲得更多支持。 –

回答

0

我編輯了我的代碼,所以沒有錯誤。 我希望這會對其他人有用。

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

#ifndef _SYS_SYSPROTO_H_ 
    struct func_args { 
     unsigned int k0; 
     unsigned int k1; 
}; 
#endif 


int sys_func (struct thread *td, struct func_args *uap) 
{ 
    unsigned int a,b,c; 
    a = uap->k0; 
    b = uap->k1; 
    c = a + b; 
    printf("%u + %u = %u\n",a,b,c); 
    return (0); 
} 
+0

cmps111?我被困在同一件事上 – MarksCode

相關問題