MINIX 2 - 系统调用到内核

时间:2014-11-15 00:54:13

标签: c system-calls minix

我想对内核(getlot和setlot)进行2次系统调用。他们必须在struct proc中读取并设置一些值,这是在内核中。问题是什么?缺少什么?

在/usr/include/minix/callnr.h中我增加了NCALLS并添加了2个定义

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

 #define SETLOT       78
 #define GETLOT       79

在usr / src / mm / 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/mm/proto.h中我添加了两个原型

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

在/usr/src/mm/table.c中我添加到_PROTOTYPE的末尾(int(* call_vec [NCALLS]),(void))

do_setlot,
do_getlot,

在/usr/src/fs/table.c中我添加到了__PROTOTYPE的末尾(int(* call_vec []),(void))

no_sys,
no_sys,

在/usr/include/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以切换PUBLIC void sys_task()

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

在底部,我写了2个定义

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;
}

最后在make 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)

1 个答案:

答案 0 :(得分:0)

我知道这条消息已有数年之久,但是......

do_procsetlot底部有语法错误:

  {
  return EINVAL;
 }

......应该是:

  }
  return EINVAL;
 }

我希望你在2014年的某个时候自己想出来!

BTW,Minix 2编译器完全支持ANSI C,所以你不需要所有的K&amp; Risms。

相关问题