【问题标题】:MINIX 2 - syscall to kernelMINIX 2 - 系统调用内核
【发布时间】:2014-11-15 00:54:13
【问题描述】:

我想对内核进行 2 次系统调用(getlot 和 setlot)。他们必须在内核中的 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)

【问题讨论】:

    标签: c system-calls minix


    【解决方案1】:

    我知道这条消息已有多年历史了,但是...

    do_procsetlot 底部有语法错误:

      {
      return EINVAL;
     }
    

    ...应该是:

      }
      return EINVAL;
     }
    

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

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

    【讨论】:

    • 是的,我在 2014 年发现了这个错误,但花了很多时间。
    猜你喜欢
    • 2020-02-22
    • 1970-01-01
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 2010-09-20
    • 2019-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多