|
90 | 90 | wasm_runtime_propagate_exception_from_import( |
91 | 91 | WASMModuleInstanceCommon *parent, WASMModuleInstanceCommon *sub_module) |
92 | 92 | { |
93 | | - static const char exception_prefix[] = "Exception: "; |
| 93 | + static const uint32 exception_prefix_len = sizeof("Exception: ") - 1; |
| 94 | + static const char memory_oob_exception[] = "out of bounds memory access"; |
| 95 | + char exception_buf[EXCEPTION_BUF_LEN] = { 0 }; |
94 | 96 | const char *message = NULL; |
| 97 | + bool has_exception = false; |
95 | 98 |
|
96 | 99 | if (!parent || !sub_module) |
97 | 100 | return; |
98 | 101 |
|
99 | | - message = wasm_get_exception(sub_module); |
100 | | - if (message && message[0] != '\0') { |
101 | | - if (!strncmp(message, exception_prefix, sizeof(exception_prefix) - 1)) { |
102 | | - message += sizeof(exception_prefix) - 1; |
| 102 | + switch (sub_module->module_type) { |
| 103 | +#if WASM_ENABLE_INTERP != 0 |
| 104 | + case Wasm_Module_Bytecode: |
| 105 | + has_exception = wasm_copy_exception( |
| 106 | + (WASMModuleInstance *)sub_module, exception_buf); |
| 107 | + break; |
| 108 | +#endif |
| 109 | +#if WASM_ENABLE_AOT != 0 |
| 110 | + case Wasm_Module_AoT: |
| 111 | + has_exception = aot_copy_exception((AOTModuleInstance *)sub_module, |
| 112 | + exception_buf); |
| 113 | + break; |
| 114 | +#endif |
| 115 | + default: |
| 116 | + return; |
| 117 | + } |
| 118 | + |
| 119 | + if (has_exception) { |
| 120 | + message = exception_buf; |
| 121 | + if (strlen(message) >= exception_prefix_len) { |
| 122 | + message += exception_prefix_len; |
| 123 | + } |
| 124 | + else { |
| 125 | + LOG_WARNING("sub-module exception format unexpected: %s", message); |
| 126 | + return; |
| 127 | + } |
| 128 | + |
| 129 | + if (strcmp(message, memory_oob_exception) != 0) { |
| 130 | + LOG_WARNING("skip propagating non-memory-OOB exception: %s", |
| 131 | + message); |
| 132 | + return; |
| 133 | + } |
| 134 | + |
| 135 | + switch (parent->module_type) { |
| 136 | +#if WASM_ENABLE_INTERP != 0 |
| 137 | + case Wasm_Module_Bytecode: |
| 138 | + wasm_set_exception((WASMModuleInstance *)parent, message); |
| 139 | + break; |
| 140 | +#endif |
| 141 | +#if WASM_ENABLE_AOT != 0 |
| 142 | + case Wasm_Module_AoT: |
| 143 | + aot_set_exception((AOTModuleInstance *)parent, message); |
| 144 | + break; |
| 145 | +#endif |
| 146 | + default: |
| 147 | + break; |
103 | 148 | } |
104 | 149 |
|
105 | | - wasm_set_exception(parent, message); |
106 | | - wasm_set_exception(sub_module, NULL); |
| 150 | + switch (sub_module->module_type) { |
| 151 | +#if WASM_ENABLE_INTERP != 0 |
| 152 | + case Wasm_Module_Bytecode: |
| 153 | + wasm_set_exception((WASMModuleInstance *)sub_module, NULL); |
| 154 | + break; |
| 155 | +#endif |
| 156 | +#if WASM_ENABLE_AOT != 0 |
| 157 | + case Wasm_Module_AoT: |
| 158 | + aot_set_exception((AOTModuleInstance *)sub_module, NULL); |
| 159 | + break; |
| 160 | +#endif |
| 161 | + default: |
| 162 | + break; |
| 163 | + } |
107 | 164 | } |
108 | 165 | } |
109 | 166 |
|
@@ -275,8 +332,8 @@ runtime_signal_handler(void *sig_addr) |
275 | 332 | && jmpbuf_node->module_inst |
276 | 333 | != (WASMModuleInstanceCommon *)module_inst) { |
277 | 334 | wasm_runtime_propagate_exception_from_import( |
278 | | - (WASMModuleInstance *)jmpbuf_node->module_inst, |
279 | | - module_inst); |
| 335 | + (WASMModuleInstanceCommon *)jmpbuf_node->module_inst, |
| 336 | + (WASMModuleInstanceCommon *)module_inst); |
280 | 337 | } |
281 | 338 | #endif |
282 | 339 | os_longjmp(jmpbuf_node->jmpbuf, 1); |
|
0 commit comments