Add instance context memory

This commit is contained in:
Brandon Fish 2019-02-10 14:24:36 -06:00
parent 0cfe864fe6
commit 7ef472dae2
4 changed files with 19 additions and 5 deletions

View File

@ -428,8 +428,16 @@ pub unsafe extern "C" fn wasmer_imports_set_import_func(
// };
}
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_instance_context_memory(instance: *mut wasmer_instance_context_t) {}
pub extern "C" fn wasmer_instance_context_memory(
ctx: *mut wasmer_instance_context_t,
memory_idx: uint32_t,
) -> *const wasmer_memory_t {
let mut ctx = unsafe { Box::from_raw(ctx as *mut Ctx) };
let memory = ctx.memory(0);
memory as *const Memory as *const wasmer_memory_t
}
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]

View File

@ -4,10 +4,14 @@
#include <stdint.h>
static print_str_called = false;
static memory_len = 0;
void print_str(int32_t ptr, int32_t len, wasmer_instance_context_t *ctx) {
printf("In print_str\n");
wasmer_memory_t *memory = wasmer_instance_context_memory(ctx, 0);
uint32_t mem_len = wasmer_memory_length(memory);
printf("In print_str, memory len: %d\n", mem_len);
print_str_called = true;
memory_len = mem_len;
}
int main()
@ -38,7 +42,7 @@ int main()
assert(call_result == WASMER_CALL_OK);
assert(print_str_called);
assert(memory_len == 17);
printf("Destroy instance\n");
wasmer_instance_destroy(instance);

View File

@ -104,7 +104,8 @@ wasmer_call_result_t wasmer_instance_call(wasmer_instance_t *instance,
wasmer_value_t *results,
int results_len);
void wasmer_instance_context_memory(wasmer_instance_context_t *instance);
const wasmer_memory_t *wasmer_instance_context_memory(wasmer_instance_context_t *ctx,
uint32_t memory_idx);
void wasmer_instance_destroy(wasmer_instance_t *instance);

View File

@ -104,7 +104,8 @@ wasmer_call_result_t wasmer_instance_call(wasmer_instance_t *instance,
wasmer_value_t *results,
int results_len);
void wasmer_instance_context_memory(wasmer_instance_context_t *instance);
const wasmer_memory_t *wasmer_instance_context_memory(wasmer_instance_context_t *ctx,
uint32_t memory_idx);
void wasmer_instance_destroy(wasmer_instance_t *instance);