0

I am trying to pass the address of an int[] to a system call. However messages only have fields for char pointers.

I have tried converting the int pointer to a char pointer and back again but the results in the array are not correct.

int pidarray[j];
m.m1_p3 = (char*)pidarray;

Also I tried to store the address of the array as an integer and pass it through a message integer field.

int pidarray[j];
m.m1_i3 = &pidarray;

EDIT:

This will be a system call of my creation, aimed at filling an array with pids and copying the data back to the process hence why I need to pass the address of the array. I call the system call a so,

_syscall(PM_PROC_NR, GETCHILDPIDS, &m);

It fills an array and attempts to copy it back to memory space owned by the calling process. This is done as:

sys_vircopy(SELF, (vir_bytes) &test, who_e,(vir_bytes) m_in.m1_i3, sizeof(test));

where test is a int[].

How can I send the address of a int[] in this format?

calmcalmuncle
  • 143
  • 1
  • 2
  • 16

1 Answers1

1

In C, arrays are decayed into pointers, in particular when passed as arguments.

So just handle that as a pointer. You may need to change the interface of your new system call (e.g. perhaps give it a pointer and a size, or have a convention saying that pidarray should be 0 terminated).

BTW, it smells like your system call is useless. You can do all that on Linux in user-land, thru existing syscalls(2) using /proc/ (see proc(5)...).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547