Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

rebased to latest wasm3/main #239

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ wasm_vm_result wasm_vm_load_module(wasm_vm *vm, const char *name, unsigned char
wasm_vm_result wasm_vm_call(wasm_vm *vm, const char *module, const char *name, ...);
wasm_vm_result wasm_vm_call_direct(wasm_vm *vm, wasm_vm_function *func, ...);
uint8_t *wasm_vm_memory(wasm_vm_module *module);
uint32_t wasm_vm_page_size(wasm_vm_module *module);
wasm_vm_result wasm_vm_global(wasm_vm_module *module, const char *name);
wasm_vm_result wasm_vm_malloc(wasm_vm *vm, const char *module, unsigned size);
wasm_vm_result wasm_vm_free(wasm_vm *vm, const char *module, i32 ptr, unsigned size);
Expand Down
9 changes: 5 additions & 4 deletions src/opa.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,11 @@ opa_socket_context parse_opa_socket_eval_result(char *json)
return ret;
}

static size_t get_memory_page_count(size_t size)
static size_t get_memory_page_count(wasm_vm_module *module, size_t size)
{
size_t pages = size / d_m3MemPageSize;
size_t pages = size / wasm_vm_page_size(module);

if (pages * d_m3MemPageSize == size)
if (pages * wasm_vm_page_size(module) == size)
{
return pages;
}
Expand Down Expand Up @@ -781,7 +781,8 @@ opa_socket_context this_cpu_opa_socket_eval(const char *input)
int rest = inputAddr + inputLen - memorySize;
if (rest > 0) // need to grow memory
{
M3Result m3result = ResizeMemory(opa->eval->module->runtime, get_memory_page_count(memorySize + rest));
size_t pageCount = get_memory_page_count(opa->eval->module, memorySize + rest);
M3Result m3result = ResizeMemory(opa->eval->module->runtime, pageCount);
if (m3result)
{
pr_crit("could not grow wasm module memory");
Expand Down
5 changes: 5 additions & 0 deletions src/wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ uint8_t *wasm_vm_memory(wasm_vm_module *module)
return m3_GetMemory(module->runtime, &len, 0);
}

uint32_t wasm_vm_page_size(wasm_vm_module *module)
{
return module->runtime->memory.pageSize;
}

wasm_vm_result wasm_vm_global(wasm_vm_module *module, const char *name)
{
IM3Global g = m3_FindGlobal(module, name);
Expand Down