Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Exception Handling for classic interpreter #3096

Merged
merged 16 commits into from
Jan 31, 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
5 changes: 5 additions & 0 deletions build-scripts/config_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ if (WAMR_BUILD_REF_TYPES EQUAL 1)
else ()
message (" Reference types disabled")
endif ()
if (WAMR_BUILD_EXCE_HANDLING EQUAL 1)
add_definitions (-DWASM_ENABLE_EXCE_HANDLING=1)
add_definitions (-DWASM_ENABLE_TAGS=1)
message (" Exception Handling enabled")
endif ()
if (DEFINED WAMR_BH_VPRINTF)
add_definitions (-DBH_VPRINTF=${WAMR_BH_VPRINTF})
endif ()
Expand Down
8 changes: 8 additions & 0 deletions core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,14 @@
#define WASM_ENABLE_REF_TYPES 0
#endif

#ifndef WASM_ENABLE_EXCE_HANDLING
#define WASM_ENABLE_EXCE_HANDLING 0
#endif

#ifndef WASM_ENABLE_TAGS
#define WASM_ENABLE_TAGS 0
#endif

#ifndef WASM_ENABLE_SGX_IPFS
#define WASM_ENABLE_SGX_IPFS 0
#endif
Expand Down
67 changes: 67 additions & 0 deletions core/iwasm/interpreter/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ extern "C" {
#if WASM_ENABLE_BULK_MEMORY != 0
#define SECTION_TYPE_DATACOUNT 12
#endif
#if WASM_ENABLE_TAGS != 0
#define SECTION_TYPE_TAG 13
#endif

#define SUB_SECTION_TYPE_MODULE 0
#define SUB_SECTION_TYPE_FUNC 1
Expand All @@ -74,20 +77,34 @@ extern "C" {
#define IMPORT_KIND_TABLE 1
#define IMPORT_KIND_MEMORY 2
#define IMPORT_KIND_GLOBAL 3
#if WASM_ENABLE_TAGS != 0
#define IMPORT_KIND_TAG 4
#endif

#define EXPORT_KIND_FUNC 0
#define EXPORT_KIND_TABLE 1
#define EXPORT_KIND_MEMORY 2
#define EXPORT_KIND_GLOBAL 3
#if WASM_ENABLE_TAGS != 0
#define EXPORT_KIND_TAG 4
#endif

#define LABEL_TYPE_BLOCK 0
#define LABEL_TYPE_LOOP 1
#define LABEL_TYPE_IF 2
#define LABEL_TYPE_FUNCTION 3
#if WASM_ENABLE_EXCE_HANDLING != 0
#define LABEL_TYPE_TRY 4
#define LABEL_TYPE_CATCH 5
#define LABEL_TYPE_CATCH_ALL 6
#endif

typedef struct WASMModule WASMModule;
typedef struct WASMFunction WASMFunction;
typedef struct WASMGlobal WASMGlobal;
#if WASM_ENABLE_TAGS != 0
typedef struct WASMTag WASMTag;
#endif

typedef union V128 {
int8 i8x16[16];
Expand Down Expand Up @@ -201,6 +218,24 @@ typedef struct WASMFunctionImport {
bool call_conv_wasm_c_api;
} WASMFunctionImport;

#if WASM_ENABLE_TAGS != 0
typedef struct WASMTagImport {
char *module_name;
char *field_name;
uint8 attribute; /* the type of the tag (numerical) */
uint32 type; /* the type of the catch function (numerical)*/
WASMType *tag_type;
void *tag_ptr_linked;

#if WASM_ENABLE_MULTI_MODULE != 0
/* imported tag pointer after linked */
WASMModule *import_module;
WASMTag *import_tag_linked;
uint32 import_tag_index_linked;
#endif
} WASMTagImport;
#endif

typedef struct WASMGlobalImport {
char *module_name;
char *field_name;
Expand All @@ -227,6 +262,9 @@ typedef struct WASMImport {
WASMFunctionImport function;
WASMTableImport table;
WASMMemoryImport memory;
#if WASM_ENABLE_TAGS != 0
WASMTagImport tag;
#endif
WASMGlobalImport global;
struct {
char *module_name;
Expand Down Expand Up @@ -265,6 +303,10 @@ struct WASMFunction {
uint32 const_cell_num;
#endif

#if WASM_ENABLE_EXCE_HANDLING != 0
uint32 exception_handler_count;
#endif

#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 \
|| WASM_ENABLE_WAMR_COMPILER != 0
/* Whether function has opcode memory.grow */
Expand Down Expand Up @@ -294,6 +336,14 @@ struct WASMFunction {
#endif
};

#if WASM_ENABLE_TAGS != 0
struct WASMTag {
uint8 attribute; /* the attribute property of the tag (expected to be 0) */
uint32 type; /* the type of the tag (expected valid inden in type table) */
WASMType *tag_type;
};
#endif

struct WASMGlobal {
uint8 type;
bool is_mutable;
Expand Down Expand Up @@ -420,6 +470,9 @@ struct WASMModule {
uint32 function_count;
uint32 table_count;
uint32 memory_count;
#if WASM_ENABLE_TAGS != 0
uint32 tag_count;
#endif
uint32 global_count;
uint32 export_count;
uint32 table_seg_count;
Expand All @@ -433,18 +486,27 @@ struct WASMModule {
uint32 import_function_count;
uint32 import_table_count;
uint32 import_memory_count;
#if WASM_ENABLE_TAGS != 0
uint32 import_tag_count;
#endif
uint32 import_global_count;

WASMImport *import_functions;
WASMImport *import_tables;
WASMImport *import_memories;
#if WASM_ENABLE_TAGS != 0
WASMImport *import_tags;
#endif
WASMImport *import_globals;

WASMType **types;
WASMImport *imports;
WASMFunction **functions;
WASMTable *tables;
WASMMemory *memories;
#if WASM_ENABLE_TAGS != 0
WASMTag **tags;
#endif
WASMGlobal *globals;
WASMExport *exports;
WASMTableSeg *table_segments;
Expand Down Expand Up @@ -628,6 +690,11 @@ typedef struct WASMBranchBlock {
uint8 *target_addr;
uint32 *frame_sp;
uint32 cell_num;
#if WASM_ENABLE_EXCE_HANDLING != 0
/* in exception handling, label_type needs to be stored to lookup exception
* handlers */
uint8 label_type;
#endif
} WASMBranchBlock;

/**
Expand Down
8 changes: 8 additions & 0 deletions core/iwasm/interpreter/wasm_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ typedef struct WASMInterpFrame {
uint64 time_started;
#endif

#if WASM_ENABLE_EXCE_HANDLING != 0
/* set to true if the callee returns an exception rather than
* result values on the stack
*/
bool exception_raised;
uint32 tag_index;
#endif

#if WASM_ENABLE_FAST_INTERP != 0
/* Return offset of the first return value of current frame,
the callee will put return values here continuously */
Expand Down
Loading
Loading