Skip to content

Commit

Permalink
Merge pull request #937 from bytecodealliance/main
Browse files Browse the repository at this point in the history
Merge bytecodealliance:main into wenyongh:main
  • Loading branch information
wenyongh authored Jul 10, 2024
2 parents a2af412 + 1b1ec71 commit e63f941
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/compilation_on_android_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ jobs:
uses: actions/checkout@v4

- name: Set-up OCaml
uses: ocaml/setup-ocaml@v2
uses: ocaml/setup-ocaml@v3
if: matrix.test_option == '$GC_TEST_OPTIONS' || matrix.test_option == '$MEMORY64_TEST_OPTIONS'
with:
ocaml-compiler: 4.13
Expand Down
15 changes: 15 additions & 0 deletions core/iwasm/common/wasm_loader_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ is_valid_value_type(uint8 type)
return false;
}

bool
is_valid_value_type_for_interpreter(uint8 value_type)
{
#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0)
/*
* Note: regardless of WASM_ENABLE_SIMD, our interpreters don't have
* SIMD implemented. It's safer to reject v128, especially for the
* fast interpreter.
*/
if (value_type == VALUE_TYPE_V128)
return false;
#endif
return is_valid_value_type(value_type);
}

bool
is_valid_func_type(const WASMFuncType *func_type)
{
Expand Down
5 changes: 4 additions & 1 deletion core/iwasm/common/wasm_loader_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ wasm_memory_check_flags(const uint8 mem_flag, char *error_buf,
bool
is_valid_value_type(uint8 value_tpye);

bool
is_valid_value_type_for_interpreter(uint8 value_tpye);

bool
is_valid_func_type(const WASMFuncType *func_type);

Expand All @@ -31,4 +34,4 @@ is_indices_overflow(uint32 import, uint32 other, char *error_buf,
}
#endif

#endif /* end of _WASM_LOADER_COMMON_H */
#endif /* end of _WASM_LOADER_COMMON_H */
16 changes: 16 additions & 0 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,22 @@ get_package_type(const uint8 *buf, uint32 size)
return Package_Type_Unknown;
}

PackageType
wasm_runtime_get_file_package_type(const uint8 *buf, uint32 size)
{
return get_package_type(buf, size);
}

PackageType
wasm_runtime_get_module_package_type(WASMModuleCommon *module)
{
if (!module) {
return Package_Type_Unknown;
}

return module->module_type;
}

#if WASM_ENABLE_AOT != 0
static uint8 *
align_ptr(const uint8 *p, uint32 b)
Expand Down
29 changes: 27 additions & 2 deletions core/iwasm/include/wasm_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ typedef struct WASMTableType *wasm_table_type_t;
struct WASMGlobalType;
typedef struct WASMGlobalType *wasm_global_type_t;

#ifndef WASM_MEMORY_T_DEFINED
#define WASM_MEMORY_T_DEFINED
struct WASMMemory;
typedef struct WASMMemory WASMMemoryType;
#endif
typedef WASMMemoryType *wasm_memory_type_t;

typedef struct wasm_import_t {
Expand Down Expand Up @@ -419,6 +422,28 @@ wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info);
WASM_RUNTIME_API_EXTERN package_type_t
get_package_type(const uint8_t *buf, uint32_t size);

/**
* Get the package type of a buffer (same as get_package_type).
*
* @param buf the package buffer
* @param size the package buffer size
*
* @return the package type, return Package_Type_Unknown if the type is unknown
*/
WASM_RUNTIME_API_EXTERN package_type_t
wasm_runtime_get_file_package_type(const uint8_t *buf, uint32_t size);

/**
* Get the package type of a module.
*
* @param module the module
*
* @return the package type, return Package_Type_Unknown if the type is
* unknown
*/
WASM_RUNTIME_API_EXTERN package_type_t
wasm_runtime_get_module_package_type(wasm_module_t module);

/**
* Check whether a file is an AOT XIP (Execution In Place) file
*
Expand Down Expand Up @@ -1202,7 +1227,7 @@ wasm_runtime_validate_native_addr(wasm_module_inst_t module_inst,
void *native_ptr, uint64_t size);

/**
* Convert app address(relative address) to native address(absolute address)
* Convert app address (relative address) to native address (absolute address)
*
* Note that native addresses to module instance memory can be invalidated
* on a memory growth. (Except shared memory, whose native addresses are
Expand All @@ -1218,7 +1243,7 @@ wasm_runtime_addr_app_to_native(wasm_module_inst_t module_inst,
uint64_t app_offset);

/**
* Convert native address(absolute address) to app address(relative address)
* Convert native address (absolute address) to app address (relative address)
*
* @param module_inst the WASM module instance
* @param native_ptr the native address
Expand Down
6 changes: 5 additions & 1 deletion core/iwasm/interpreter/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ typedef struct WASMMemory {
uint32 num_bytes_per_page;
uint32 init_page_count;
uint32 max_page_count;
} WASMMemory, WASMMemoryType;
} WASMMemory;
#ifndef WASM_MEMORY_T_DEFINED
#define WASM_MEMORY_T_DEFINED
typedef struct WASMMemory WASMMemoryType;
#endif

typedef struct WASMTableImport {
char *module_name;
Expand Down
18 changes: 10 additions & 8 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,10 @@ is_packed_type(uint8 type)
static bool
is_byte_a_type(uint8 type)
{
return (is_valid_value_type(type) || (type == VALUE_TYPE_VOID)) ? true
: false;
return (is_valid_value_type_for_interpreter(type)
|| (type == VALUE_TYPE_VOID))
? true
: false;
}

#if WASM_ENABLE_SIMD != 0
Expand Down Expand Up @@ -1443,7 +1445,7 @@ resolve_value_type(const uint8 **p_buf, const uint8 *buf_end,
}
else {
/* type which can be represented by one byte */
if (!is_valid_value_type(type)
if (!is_valid_value_type_for_interpreter(type)
&& !(allow_packed_type && is_packed_type(type))) {
set_error_buf(error_buf, error_buf_size, "type mismatch");
return false;
Expand Down Expand Up @@ -1953,7 +1955,7 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
type->types[param_count + j] = read_uint8(p);
}
for (j = 0; j < param_count + result_count; j++) {
if (!is_valid_value_type(type->types[j])) {
if (!is_valid_value_type_for_interpreter(type->types[j])) {
set_error_buf(error_buf, error_buf_size,
"unknown value type");
return false;
Expand Down Expand Up @@ -3049,7 +3051,7 @@ load_global_import(const uint8 **p_buf, const uint8 *buf_end,
CHECK_BUF(p, p_end, 2);
/* global type */
declare_type = read_uint8(p);
if (!is_valid_value_type(declare_type)) {
if (!is_valid_value_type_for_interpreter(declare_type)) {
set_error_buf(error_buf, error_buf_size, "type mismatch");
return false;
}
Expand Down Expand Up @@ -3766,7 +3768,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
CHECK_BUF(p_code, buf_code_end, 1);
/* 0x7F/0x7E/0x7D/0x7C */
type = read_uint8(p_code);
if (!is_valid_value_type(type)) {
if (!is_valid_value_type_for_interpreter(type)) {
if (type == VALUE_TYPE_V128)
set_error_buf(error_buf, error_buf_size,
"v128 value type requires simd feature");
Expand Down Expand Up @@ -4046,7 +4048,7 @@ load_global_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
CHECK_BUF(p, p_end, 2);
/* global type */
global->type.val_type = read_uint8(p);
if (!is_valid_value_type(global->type.val_type)) {
if (!is_valid_value_type_for_interpreter(global->type.val_type)) {
set_error_buf(error_buf, error_buf_size, "type mismatch");
return false;
}
Expand Down Expand Up @@ -12367,7 +12369,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_GC == 0
CHECK_BUF(p, p_end, 1);
type = read_uint8(p);
if (!is_valid_value_type(type)) {
if (!is_valid_value_type_for_interpreter(type)) {
set_error_buf(error_buf, error_buf_size,
"unknown value type");
goto fail;
Expand Down
9 changes: 5 additions & 4 deletions core/iwasm/interpreter/wasm_mini_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ is_64bit_type(uint8 type)
static bool
is_byte_a_type(uint8 type)
{
return is_valid_value_type(type) || (type == VALUE_TYPE_VOID);
return is_valid_value_type_for_interpreter(type)
|| (type == VALUE_TYPE_VOID);
}

static void
Expand Down Expand Up @@ -568,7 +569,7 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
type->types[param_count + j] = read_uint8(p);
}
for (j = 0; j < param_count + result_count; j++) {
bh_assert(is_valid_value_type(type->types[j]));
bh_assert(is_valid_value_type_for_interpreter(type->types[j]));
}

param_cell_num = wasm_get_cell_num(type->types, param_count);
Expand Down Expand Up @@ -1218,7 +1219,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
CHECK_BUF(p_code, buf_code_end, 1);
/* 0x7F/0x7E/0x7D/0x7C */
type = read_uint8(p_code);
bh_assert(is_valid_value_type(type));
bh_assert(is_valid_value_type_for_interpreter(type));
for (k = 0; k < sub_local_count; k++) {
func->local_types[local_type_index++] = type;
}
Expand Down Expand Up @@ -6828,7 +6829,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,

CHECK_BUF(p, p_end, 1);
ref_type = read_uint8(p);
if (!is_valid_value_type(ref_type)) {
if (!is_valid_value_type_for_interpreter(ref_type)) {
set_error_buf(error_buf, error_buf_size,
"unknown value type");
goto fail;
Expand Down
6 changes: 3 additions & 3 deletions wamr-compiler/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ print_help()
printf(" --enable-dump-call-stack Enable stack trace feature\n");
printf(" --enable-perf-profiling Enable function performance profiling\n");
printf(" --enable-memory-profiling Enable memory usage profiling\n");
printf(" --xip A shorthand of --enalbe-indirect-mode --disable-llvm-intrinsics\n");
printf(" --enable-indirect-mode Enalbe call function through symbol table but not direct call\n");
printf(" --enable-gc Enalbe GC (Garbage Collection) feature\n");
printf(" --xip A shorthand of --enable-indirect-mode --disable-llvm-intrinsics\n");
printf(" --enable-indirect-mode Enable call function through symbol table but not direct call\n");
printf(" --enable-gc Enable GC (Garbage Collection) feature\n");
printf(" --disable-llvm-intrinsics Disable the LLVM built-in intrinsics\n");
printf(" --enable-builtin-intrinsics=<flags>\n");
printf(" Enable the specified built-in intrinsics, it will override the default\n");
Expand Down

0 comments on commit e63f941

Please sign in to comment.