C 如何在PM server Minix中发送消息

C 如何在PM server Minix中发送消息,c,system-calls,minix,C,System Calls,Minix,所以我尝试在PM服务器上创建一个新的系统调用。我的问题是,我如何才能向职能部门发送某种信息 在IPC服务器中,我所要做的就是将我的系统调用添加到列表中,因为那里的所有函数都定义为(*func)(message*) 但在表c中的PM中,函数定义为 (...)/servers/pm/table.c int (* const call_vec[NR_PM_CALLS])(void) = { (...) CALL(PM_GETSYSINFO) = do_getsysinfo } 如果我尝试传递带有签名

所以我尝试在PM服务器上创建一个新的系统调用。我的问题是,我如何才能向职能部门发送某种信息

在IPC服务器中,我所要做的就是将我的系统调用添加到列表中,因为那里的所有函数都定义为(*func)(message*)

但在表c中的PM中,函数定义为

(...)/servers/pm/table.c
int (* const call_vec[NR_PM_CALLS])(void) = {
(...)
CALL(PM_GETSYSINFO) = do_getsysinfo
}
如果我尝试传递带有签名的函数

int do_something(message *m)
我将得到一个错误:

不兼容的指针类型:使用int(消息*)初始化int(*const)(void)


如果需要接收某种信息,在PM服务器上创建信号的正确方法是什么?

据我从问题中了解,您希望在syscall处理程序中接收参数。让我们以libc中的库函数
clock\u settime
为例

int clock_settime(clockid_t clock_id, const struct timespec *ts)
{
  message m;

  memset(&m, 0, sizeof(m));
  m.m_lc_pm_time.clk_id = clock_id;
  m.m_lc_pm_time.now = 1; /* set time immediately. don't use adjtime() method. */
  m.m_lc_pm_time.sec = ts->tv_sec;
  m.m_lc_pm_time.nsec = ts->tv_nsec;

  if (_syscall(PM_PROC_NR, PM_CLOCK_SETTIME, &m) < 0)
    return -1;

  return 0;
}
很明显,该参数是一个名为
m_的全局变量。再多搜索一点,就会发现它来自
glo.h

/* The parameters of the call are kept here. */
EXTERN message m_in;        /* the incoming message itself is kept here. */
我假设MINIX将处理设置和访问全局变量,因此您不需要显式地写入它

查看将参数传递给系统调用的点7。要了解如何正确编译内核,请参阅post。

如果您需要它:)我认为您不需要在该数组中注册任何函数。相反,只需要数组
mproc[NR_PROCS]
来获取进程之间关系的信息,或者您甚至可以在结构
mproc
中添加一些字段来跟踪时间:)
int do_gettime()
{
  clock_t ticks, realtime, clock;
  time_t boottime;
  int s;

  if ( (s=getuptime(&ticks, &realtime, &boottime)) != OK)
    panic("do_time couldn't get uptime: %d", s);

  switch (m_in.m_lc_pm_time.clk_id) {
    case CLOCK_REALTIME:
        clock = realtime;
        break;
    case CLOCK_MONOTONIC:
        clock = ticks;
        break;
    default:
        return EINVAL; /* invalid/unsupported clock_id */
  }

  mp->mp_reply.m_pm_lc_time.sec = boottime + (clock / system_hz);
  mp->mp_reply.m_pm_lc_time.nsec =
    (uint32_t) ((clock % system_hz) * 1000000000ULL / system_hz);

  return(OK);
}
/* The parameters of the call are kept here. */
EXTERN message m_in;        /* the incoming message itself is kept here. */