【问题标题】:Minix - Copying Data from Address of System Call back to Calling ProcessMinix - 将数据从系统调用地址复制回调用进程
【发布时间】:2016-12-08 11:32:10
【问题描述】:

所以,我需要使用 MINIX 内核调用 sys_vircopy 从我正在编写的系统调用中复制一个填充数组(int),返回到调用进程。

当前设置如下,在调用过程中(省略了不重要的部分):

int *results = malloc(...); // allocate required mem
message m;

m.m1_i1 = *results; 
// is this the correct way to send the address of the array via a message?

_syscall(..., MYSYSCALL, &m); // syscall to relevant server

因此,由于我无法直接发送 int 数组(没有消息类型),我试图在消息中发送数组的地址。

然后,在我的系统调用中:

int nelements;
int *results = &m_in.m1_i1;
// is this the correct way to receive the array at the address in the message?

// Some code here filling the array

sys_vircopy(SELF, *results, who_e, m_in.m1_i1, sizeof(int) * nelements);
// is this the correct way to send the address of the filled array...
// ...back to the address holding the array in the calling process?

所以在这里我尝试使用sys_vircopy 然后将我的数组的地址(*results)从当前进程(SELF)发送回调用进程(who_e),在指向其数组的地址 (m_in.m1_i1)。

但是,这似乎不起作用。我觉得我一定对消息有误解,和/或将地址从一个进程发送到另一个进程。不幸的是,没有太多记录使用此sys_vircopy 功能在线帮助我。有没有人可以指点一下?

另外,我必须在这里使用sys_vircopy

【问题讨论】:

  • 您不能将地址发送到其他进程。它在不同的地址空间中没有任何意义。
  • 是的,我以为我误解了一些东西(我是 C 和系统编程的新手,对我来说太简单了)。你对如何实现我的目标有什么建议吗?我确定我需要使用sys_vircopy
  • Sizeof(int)*num 是要发送的字节数
  • 好的,但是如何正确接收数组,然后使用 MINIX messagesys_vircopy 将其发回?
  • 不需要双向。在内核中 malloc 一个数组,填充它,然后使用 sys_vircopy 将其复制出来,然后释放它。

标签: c arrays system-calls minix


【解决方案1】:

没有旧的D|T|S 段的痕迹,所以我猜这是MINIX 3.2 或更新版本。您可能需要使用memory grants(又名safecopies)来处理保护问题,而不是尝试使用较低级别的vircopy

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 2015-12-07
    • 2020-02-22
    • 2016-01-13
    相关资源
    最近更新 更多