2014-11-15 55 views
2

我想让2个系统调用到内核(getlot和setlot)。他们必须在内核中的struct proc中读取和设置一些值。问题是什么?什么不见​​了?MINIX 2 - 系统调用内核

在/usr/include/minix/callnr.h我增加NCALLS并添加2限定

#define NCALLS  80 /* number of system calls allowed */ 

#define SETLOT  78 
#define GETLOT  79 

在USR/SRC /毫米/ main.c中

PUBLIC void do_setlot() 
{ 
    message msg; 
    msg = mm_in; 
    _taskcall(SYSTASK, SYS_SETLOT), &msg); 
} 

PUBLIC void do_getlot() 
{ 
    message msg; 
    msg = mm_in; 
    _taskcall(SYSTASK, SYS_GETLOT, &msg); 
} 

在/ usr/SRC /毫米/ proto.h我加入两个原型

_PROTOTYPE(void do_setlot, (void)); 
_PROTOTYPE(void do_getlot, (void)); 

在我加入到_PROTOTYPE的端/usr/src/mm/table.c(INT(* call_vec [NCALLS]),(无效))

do_setlot, 
do_getlot, 

在/usr/src/fs/table.c我添加到末尾of_PROTOTYPE(INT(* call_vec []),(无效))

no_sys, 
no_sys, 

在/ usr /包括/ MINIX/com.h我创建2个SYS_xxx限定

# define SYS_SETLOT 22 
# define SYS_GETLOT 23 

在/usr/src/kernel/system.c我写

FORWARD _PROTOTYPE(int do_procsetlot, (message *m_ptr)); 
FORWARD _PROTOTYPE(int do_procgetlot, (message *m_ptr)); 

然后加入SYS_xxx在公共无效sys_task()

case SYS_SETLOT: r = do_procsetlot(&m); break; 
case SYS_GETLOT: r = do_procgetlot(&m); break; 

,并在底部我写了2个definions

PRIVATE int do_procsetlot(m_ptr) 
register message *m_ptr; 
{ 
    pid_t prid; 
    int i; 
    int tickets; 
    prid = m_ptr->m1_i1; 
    tickets = m_ptr->m1_i2; 

    if(tickets > LOT_MAX) 
    return EINVAL; 
    if(tickets < LOT_MIN) 
    return EINVAL; 
    for(i = 0 ; i <NR_PROCS; i++) 
    { 
    if(proc[i].p_pid == prid) 
    { 
     proc[i].tickets_number = tickets; 
     return 0; 
    } 
    { 
    return EINVAL; 
} 


PRIVATE int do_procgetlot(m_ptr) 
register message *m_ptr; 
{ 
    int i; 
    pid_t prid; 
    prid = m_ptr->m1_i1; 

    for(i = 0 ; i< NR_PROCS; i++) 
    { 
    if(proc[i].p_pid == prid) 
     return proc[i].tickets_number; 
    } 
return EINVAL; 
} 

最终使后切换hdboot我得到错误:

exec cc -c -I/usr/include main.c 
exec cc -c -I/usr/include proc.c 
exec cc -c -I/usr/include system.c 
"system.c", line 1260: static not expected 
make in /usr/src/kernel: Exit code 1 

线1260是

PRIVATE int do_procgetlot(m_ptr) 

回答

0

我知道这消息是岁,但...

您在do_procsetlot底部有一个语法错误:

{ 
    return EINVAL; 
} 

...应该是:

} 
    return EINVAL; 
} 

我希望你在2014年有一段时间了解自己!

顺便说一句,Minix 2编译器完全支持ANSI C,所以你不应该需要所有的K & Risms。

+0

是的,我在2014年发现这个错误,但花了很多时间。 –