Skip to content
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
2 changes: 1 addition & 1 deletion core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,

#if WASM_ENABLE_SHARED_MEMORY != 0
if (is_shared_memory) {
memory_inst->is_shared_memory = true;
memory_inst->is_shared_memory = 1;
memory_inst->ref_count = 1;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/common/wasm_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ wasm_memory_init_with_allocator(void *_malloc_func, void *_realloc_func,
static inline bool
is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst)
{
#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
return wasm_runtime_is_bounds_checks_enabled(module_inst);
#else
return true;
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2581,7 +2581,7 @@ wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst_comm)
return module_inst->custom_data;
}

#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
void
wasm_runtime_set_bounds_checks(WASMModuleInstanceCommon *module_inst,
bool enable)
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/common/wasm_runtime_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ wasm_runtime_set_user_data(WASMExecEnv *exec_env, void *user_data);
WASM_RUNTIME_API_EXTERN void *
wasm_runtime_get_user_data(WASMExecEnv *exec_env);

#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
/* See wasm_export.h for description */
WASM_RUNTIME_API_EXTERN void
wasm_runtime_set_bounds_checks(WASMModuleInstanceCommon *module_inst,
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
uint8 value_type;
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
bool disable_bounds_checks = !wasm_runtime_is_bounds_checks_enabled(
(WASMModuleInstanceCommon *)module);
#else
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/interpreter/wasm_interp_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
uint8 opcode, local_type, *global_addr;
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
bool disable_bounds_checks = !wasm_runtime_is_bounds_checks_enabled(
(WASMModuleInstanceCommon *)module);
#else
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/interpreter/wasm_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,

#if WASM_ENABLE_SHARED_MEMORY != 0
if (is_shared_memory) {
memory->is_shared_memory = true;
memory->is_shared_memory = 1;
memory->ref_count = 1;
}
#endif
Expand Down
13 changes: 9 additions & 4 deletions core/iwasm/interpreter/wasm_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ struct WASMMemoryInstance {
/* Module type */
uint32 module_type;

bool is_shared_memory;
/* Whether the memory is shared */
uint8 is_shared_memory;

/* Shared memory flag */
bh_atomic_16_t ref_count; /* 0: non-shared, > 0: reference count */
/* One byte padding */
uint8 __padding__;

/* Reference count of the memory instance:
0: non-shared memory, > 0: shared memory */
bh_atomic_16_t ref_count;

/* Number bytes per page */
uint32 num_bytes_per_page;
Expand Down Expand Up @@ -220,7 +225,7 @@ typedef struct WASMModuleInstanceExtraCommon {
CApiFuncImport *c_api_func_imports;
/* pointer to the exec env currently used */
WASMExecEnv *cur_exec_env;
#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
/* Disable bounds checks or not */
bool disable_bounds_checks;
#endif
Expand Down
16 changes: 13 additions & 3 deletions core/iwasm/libraries/lib-rats/lib_rats_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "lib_rats_common.h"

static int
librats_collect_wrapper(wasm_exec_env_t exec_env, char **evidence_json,
librats_collect_wrapper(wasm_exec_env_t exec_env, uint32_t *evidence_json,
const char *buffer, uint32_t buffer_size)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
Expand Down Expand Up @@ -47,7 +47,7 @@ librats_collect_wrapper(wasm_exec_env_t exec_env, char **evidence_json,
return (int)RATS_ATTESTER_ERR_NO_MEM;
}
bh_memcpy_s(str_ret, json_size, json, json_size);
*((int *)evidence_json) = str_ret_offset;
*evidence_json = str_ret_offset;
free(json);

return 0;
Expand Down Expand Up @@ -96,6 +96,15 @@ librats_parse_evidence_wrapper(wasm_exec_env_t exec_env,
return 0;
}

static void
librats_dispose_evidence_json_wrapper(wasm_exec_env_t exec_env,
uint32_t evidence_json)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);

module_free(evidence_json);
}

/* clang-format off */
#define REG_NATIVE_FUNC(func_name, signature) \
{ #func_name, func_name##_wrapper, signature, NULL }
Expand All @@ -104,7 +113,8 @@ librats_parse_evidence_wrapper(wasm_exec_env_t exec_env,
static NativeSymbol native_symbols_lib_rats[] = {
REG_NATIVE_FUNC(librats_collect, "(**~)i"),
REG_NATIVE_FUNC(librats_verify, "(*~*~)i"),
REG_NATIVE_FUNC(librats_parse_evidence, "(*~*~)i")
REG_NATIVE_FUNC(librats_parse_evidence, "(*~*~)i"),
REG_NATIVE_FUNC(librats_dispose_evidence_json, "(i)")
};

uint32_t
Expand Down
3 changes: 3 additions & 0 deletions core/iwasm/libraries/lib-rats/lib_rats_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ librats_parse_evidence(const char *evidence_json, uint32_t json_size,
evidence_json ? strlen(evidence_json) + 1 : 0, \
evidence, sizeof(rats_sgx_evidence_t))

void
librats_dispose_evidence_json(char *evidence_json);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions product-mini/platforms/nuttx/wamr.mk
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ else
CFLAGS += -DWASM_ENABLE_LIBC_BUILTIN=0
endif

ifeq ($(CONFIG_INTERPRETERS_WAMR_CONFIGUABLE_BOUNDS_CHECKS),y)
CFLAGS += -DWASM_CONFIGUABLE_BOUNDS_CHECKS=1
ifeq ($(CONFIG_INTERPRETERS_WAMR_CONFIGURABLE_BOUNDS_CHECKS),y)
CFLAGS += -DWASM_CONFIGURABLE_BOUNDS_CHECKS=1
else
CFLAGS += -DWASM_CONFIGUABLE_BOUNDS_CHECKS=0
CFLAGS += -DWASM_CONFIGURABLE_BOUNDS_CHECKS=0
endif

ifeq ($(CONFIG_INTERPRETERS_WAMR_LIBC_WASI),y)
Expand Down
8 changes: 4 additions & 4 deletions product-mini/platforms/posix/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ print_help()
#endif
printf(" --repl Start a very simple REPL (read-eval-print-loop) mode\n"
" that runs commands in the form of \"FUNC ARG...\"\n");
#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
printf(" --disable-bounds-checks Disable bounds checks for memory accesses\n");
#endif
#if WASM_ENABLE_LIBC_WASI != 0
Expand Down Expand Up @@ -571,7 +571,7 @@ main(int argc, char *argv[])
#endif
bool is_repl_mode = false;
bool is_xip_file = false;
#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
bool disable_bounds_checks = false;
#endif
#if WASM_ENABLE_LIBC_WASI != 0
Expand Down Expand Up @@ -638,7 +638,7 @@ main(int argc, char *argv[])
else if (!strcmp(argv[0], "--repl")) {
is_repl_mode = true;
}
#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
else if (!strcmp(argv[0], "--disable-bounds-checks")) {
disable_bounds_checks = true;
}
Expand Down Expand Up @@ -886,7 +886,7 @@ main(int argc, char *argv[])
goto fail3;
}

#if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
if (disable_bounds_checks) {
wasm_runtime_set_bounds_checks(wasm_module_inst, false);
}
Expand Down
2 changes: 1 addition & 1 deletion samples/sgx-ra/wasm-app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ main(int argc, char **argv)

err:
if (evidence_json) {
free(evidence_json);
librats_dispose_evidence_json(evidence_json);
}

if (evidence) {
Expand Down