forked from haiwan/sledge
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
4 years ago
|
#pragma once
|
||
|
|
||
|
#include <assert.h>
|
||
|
#include <stddef.h>
|
||
|
#include <stdint.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
#include "sandbox_types.h"
|
||
|
|
||
|
/**
|
||
|
* Takes the arguments from the sandbox struct and writes them into the WebAssembly linear memory
|
||
|
*/
|
||
|
static inline void
|
||
|
sandbox_setup_arguments(struct sandbox *sandbox)
|
||
|
{
|
||
|
assert(sandbox != NULL);
|
||
|
int32_t argument_count = module_get_argument_count(sandbox->module);
|
||
|
|
||
|
/* whatever gregor has, to be able to pass arguments to a module! */
|
||
|
sandbox->arguments_offset = local_sandbox_context_cache.linear_memory_size;
|
||
|
assert(local_sandbox_context_cache.linear_memory_start == sandbox->linear_memory_start);
|
||
|
expand_memory();
|
||
|
|
||
|
int32_t *array_ptr = (int32_t *)worker_thread_get_memory_ptr_void(sandbox->arguments_offset,
|
||
|
argument_count * sizeof(int32_t));
|
||
|
int32_t string_off = sandbox->arguments_offset + (argument_count * sizeof(int32_t));
|
||
|
|
||
|
for (int i = 0; i < argument_count; i++) {
|
||
|
char * arg = (char *)sandbox->arguments + (i * MODULE_MAX_ARGUMENT_SIZE);
|
||
|
size_t str_sz = strlen(arg) + 1;
|
||
|
|
||
|
array_ptr[i] = string_off;
|
||
|
/* why get_memory_ptr_for_runtime?? */
|
||
|
strncpy(get_memory_ptr_for_runtime(string_off, str_sz), arg, strlen(arg));
|
||
|
|
||
|
string_off += str_sz;
|
||
|
}
|
||
|
stub_init(string_off);
|
||
|
}
|