Implement file system API and add shutdown functionality for desktop builds
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "wasm_runner.h"
|
||||
#include "nova64_fs.h"
|
||||
#include "nova64_internal.h"
|
||||
#include "wasm_export.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
struct wasm_runner_instance {
|
||||
void *native_instance;
|
||||
@@ -9,8 +11,40 @@ struct wasm_runner_instance {
|
||||
wasm_runner_instance_t *next;
|
||||
};
|
||||
|
||||
char error_buf[128];
|
||||
uint32_t stack_size = 8092, heap_size = 8092;
|
||||
|
||||
bool wasm_runner_initialize(void) {
|
||||
|
||||
wasm_runtime_init();
|
||||
nova64_log("WASM runtime initialized successfully.\n");
|
||||
|
||||
const char *module_file = "SYS:/init.wasm";
|
||||
int32_t file_size = nova64_get_file_size(module_file);
|
||||
if (file_size <= 0) {
|
||||
nova64_log("Failed to determine WASM module size.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned char *buffer = malloc((size_t)file_size);
|
||||
if (!buffer) {
|
||||
nova64_log("Failed to allocate WASM module buffer.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!nova64_read_file_to_buffer(module_file, buffer, (size_t)file_size)) {
|
||||
nova64_log("Failed to read WASM module into buffer.\n");
|
||||
free(buffer);
|
||||
return false;
|
||||
}
|
||||
|
||||
wasm_module_t module = wasm_runtime_load(buffer, (uint32_t)file_size,
|
||||
error_buf, sizeof(error_buf));
|
||||
|
||||
wasm_module_inst_t module_inst = wasm_runtime_instantiate(
|
||||
module, stack_size, heap_size, error_buf, sizeof(error_buf));
|
||||
|
||||
wasm_exec_env_t exec_env = wasm_runtime_create_exec_env(module_inst, stack_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user