Passing data to a thread
Hi, I'm trying to pass some data to a newly created thread. Since l4_thread_ex_regs only accepts an instruction pointer, but no data pointer, it seems impossible to me to use a parameterized function such as:
thread1_func(void *data) { /* Read the data ... */ }
So far, my efforts are: 1. I've tried filling the stack allocated to each newly created thread with
thread_stack = malloc(8 << 10); thread_stack[0] = my_data; but then I'm not able to pop the data from the stack in thread1_func.
2. I've tried using IPC: The main thread which is creating the new threads sends the data to the destination thread. I'm using l4_ipc_send in the main thread and l4_ipc_receive in thread1_func just like in your utcb-ipc example. It works great, but unfortunately the call of l4_ipc_send leads to an _immediate_ execution of thread1_func (timeouts: L4_IPC_NEVER), so my scheduling policy is not respected. So how can I pass data to a thread in a way that is equivalent to passing arguments to functions? Best regards, Valentin
On Tue Sep 02, 2014 at 16:31:33 +0200, Valentin Hauner wrote:
I'm trying to pass some data to a newly created thread. Since l4_thread_ex_regs only accepts an instruction pointer, but no data pointer, it seems impossible to me to use a parameterized function such as:
thread1_func(void *data) { /* Read the data ... */ }
So far, my efforts are:
1. I've tried filling the stack allocated to each newly created thread with
thread_stack = malloc(8 << 10); thread_stack[0] = my_data; but then I'm not able to pop the data from the stack in thread1_func.
2. I've tried using IPC: The main thread which is creating the new threads sends the data to the destination thread. I'm using l4_ipc_send in the main thread and l4_ipc_receive in thread1_func just like in your utcb-ipc example. It works great, but unfortunately the call of l4_ipc_send leads to an _immediate_ execution of thread1_func (timeouts: L4_IPC_NEVER), so my scheduling policy is not respected.
So how can I pass data to a thread in a way that is equivalent to passing arguments to functions?
For that we need to know the calling convention of functions. For x86-32, the arguments are passed via the stack. So you'd do it like this: l4_umword_t stack[2000]; stack[1999] = (l4_umword_t)my_data; stack[1998] = 0; And use &stack[1998] as an initial stack pointer for the thread. On ARM the setup can be the same, however, arguments are passed in registers, so you'll have a small asm stub for getting the argument from the stack to the register before calling the thread function. The same for x86-64. Adam -- Adam adam@os.inf.tu-dresden.de Lackorzynski http://os.inf.tu-dresden.de/~adam/
Hi, On 09/03/2014 12:45 AM, Adam Lackorzynski wrote:
For that we need to know the calling convention of functions. For x86-32, the arguments are passed via the stack. So you'd do it like this:
l4_umword_t stack[2000]; stack[1999] = (l4_umword_t)my_data; stack[1998] = 0;
And use &stack[1998] as an initial stack pointer for the thread.
On ARM the setup can be the same, however, arguments are passed in registers, so you'll have a small asm stub for getting the argument from the stack to the register before calling the thread function. The same for x86-64.
Thanks, it works great. Usage is very simple with:
void thread_func(l4_umword_t data);
Best regards, Valentin
participants (2)
-
Adam Lackorzynski -
Valentin Hauner