【问题标题】:How to send messages in PM server Minix如何在 PM 服务器 Minix 中发送消息
【发布时间】:2019-09-09 22:34:18
【问题描述】:

所以我试图在 PM 服务器上创建一个新的系统调用。我的问题是,我怎样才能发送某种消息来运行。

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

(...)/servers/ipc/main.c
static struct {
    int type;
    int (*func)(message *);
    int reply;  /* whether the reply action is passed through */
} ipc_calls[] = {
    (...)
    { IPC_MYNEWSIGNAL,  do_something,   1 },
};

但是在 PM 中的 table.c 函数被定义为

(...)/servers/pm/table.c
int (* const call_vec[NR_PM_CALLS])(void) = {
(...)
CALL(PM_GETSYSINFO) = do_getsysinfo
}

如果我尝试通过签名传递函数

int do_something(message *m)

我会得到错误:

Incompatible pointer types: initializing int (*const)(void) with int (message *)

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

【问题讨论】:

  • 如果你需要这个用于 SO :) 我认为你不需要在该数组中注册任何函数。相反,数组mproc[NR_PROCS] 仅用于获取有关进程之间关系的信息,或者您甚至可以在结构mproc 中添加一些字段来跟踪时间:)

标签: c system-calls minix


【解决方案1】:

据我从问题中了解到,您希望在系统调用处理程序中接收参数。我们以 libc 中的库函数clock_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;
}

如您所见,它将参数写入消息结构并传递给 _syscall。好的,现在看看安装在table.c 中的PM_CLOCK_SETTIME 的系统调用处理程序。

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

很明显,参数是一个名为m_in 的全局变量。再搜索一下,发现来自glo.h

/* The parameters of the call are kept here. */
EXTERN message m_in;        /* the incoming message itself is kept here. */

我认为 MINIX 将处理设置和访问全局变量,因此您不需要显式写入它。

看看 7 将参数传递给系统调用 here。要了解如何正确编译内核,请参阅this 帖子。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    • 2013-10-06
    • 2020-12-15
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多