0

So, I need to use the MINIX kernel call sys_vircopy to copy a filled array (of int) from a system call I am writing, back to the calling process.

The current setup is as follows, in the calling process (have omitted anything unimportant):

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

So, as I cannot send an array of int directly over (there is no message type for it), I am trying to send the address of the array in the message.

Then, in my system call:

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?

So here I am trying to use sys_vircopy to then send the address of my array (*results), from the current process (SELF), back to the calling process (who_e), at the address which points to its array (m_in.m1_i1).

However, this does not seem to be working. I feel I must be misunderstanding something about messages, and/or sending addresses from one process to another. Unfortunately though, there is not much documented use of this sys_vircopy function online to help me. Could anyone offer any pointers?

Additionally, I HAVE to use sys_vircopy here.

transiti0nary
  • 493
  • 6
  • 25
  • You can't send an address to a different process. It has no meaning in a different address space. – stark Dec 08 '16 at 11:35
  • Yeah, I thought I was misunderstanding something (I'm new to C and systems programming so bare with me). Do you have any advice as to how to achieve what I'm setting out to do? I know for sure that I need to use `sys_vircopy` – transiti0nary Dec 08 '16 at 11:38
  • Sizeof(int)*num is the number of bytes to send – stark Dec 08 '16 at 11:56
  • Ok, but how do I correctly receive the array, and then send it back, using MINIX `message` and `sys_vircopy`? – transiti0nary Dec 08 '16 at 13:37
  • No need to go both ways. Malloc an array in the kernel, fill it, and copy it out using sys_vircopy, then free it. – stark Dec 08 '16 at 15:45
  • @stark I do understand that much, I'm just struggling to find out how to get the address of the array in the calling process to store the filled array? I know theres a `struct mem_map` for each process inside the `mproc` table, which holds 'virtual address', 'physical address' and 'length' for that process. But I don't understand how to specifically get the address of a user-provided array in the calling process which needs filling. – transiti0nary Dec 09 '16 at 11:14

1 Answers1

0

There are no traces of old D|T|S segments so I guess this is MINIX 3.2 or more recent. You probably need to use memory grants (a.k.a safecopies) which will handle the protection issues, instead on trying to play with lower-level vircopy.

AntoineL
  • 888
  • 4
  • 25