lib: launch: implement passing args and environment variables to new tasks
This commit is contained in:
59
lib/liblaunch/stack.c
Normal file
59
lib/liblaunch/stack.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "stack.h"
|
||||
|
||||
#include <mango/log.h>
|
||||
#include <string.h>
|
||||
|
||||
void stack_writer_init(
|
||||
struct stack_writer *w,
|
||||
virt_addr_t local_sp,
|
||||
virt_addr_t remote_sp)
|
||||
{
|
||||
memset(w, 0x0, sizeof *w);
|
||||
|
||||
w->w_local_sp = local_sp;
|
||||
w->w_remote_sp = remote_sp;
|
||||
}
|
||||
|
||||
void *stack_writer_put_string(
|
||||
struct stack_writer *w,
|
||||
const char *s,
|
||||
virt_addr_t *out_remote)
|
||||
{
|
||||
size_t len = strlen(s);
|
||||
|
||||
w->w_local_sp -= (len + 1);
|
||||
w->w_remote_sp -= (len + 1);
|
||||
|
||||
char *local_ptr = (char *)w->w_local_sp;
|
||||
virt_addr_t remote_ptr = w->w_remote_sp;
|
||||
|
||||
memcpy(local_ptr, s, len);
|
||||
local_ptr[len] = '\0';
|
||||
|
||||
if (out_remote) {
|
||||
*out_remote = remote_ptr;
|
||||
}
|
||||
|
||||
return local_ptr;
|
||||
}
|
||||
|
||||
void *stack_writer_put(
|
||||
struct stack_writer *w,
|
||||
const void *p,
|
||||
size_t len,
|
||||
virt_addr_t *out_remote)
|
||||
{
|
||||
w->w_local_sp -= len;
|
||||
w->w_remote_sp -= len;
|
||||
|
||||
void *local_ptr = (char *)w->w_local_sp;
|
||||
virt_addr_t remote_ptr = w->w_remote_sp;
|
||||
|
||||
memset(local_ptr, 0x0, len);
|
||||
|
||||
if (out_remote) {
|
||||
*out_remote = remote_ptr;
|
||||
}
|
||||
|
||||
return local_ptr;
|
||||
}
|
||||
Reference in New Issue
Block a user