summaryrefslogtreecommitdiff
path: root/wasm2c/wasm-rt-exceptions-impl.c
diff options
context:
space:
mode:
authorShravan Narayan <shravanrn@gmail.com>2023-04-29 15:37:23 -0400
committerShravan Narayan <shravanrn@gmail.com>2023-05-02 14:27:21 -0400
commit5abbeaab97eb802acccf866d9c8cc021c1f7e570 (patch)
tree54380ba2ead12f36b1cf7b16aa2f68d2617fc9ef /wasm2c/wasm-rt-exceptions-impl.c
parent4d9a1475a744ab78e7fbc3dc60bf7038dad6119d (diff)
downloadwabt-5abbeaab97eb802acccf866d9c8cc021c1f7e570.tar.gz
wabt-5abbeaab97eb802acccf866d9c8cc021c1f7e570.tar.bz2
wabt-5abbeaab97eb802acccf866d9c8cc021c1f7e570.zip
wasm2c: Enable exceptions and simd according to command line flags
Diffstat (limited to 'wasm2c/wasm-rt-exceptions-impl.c')
-rw-r--r--wasm2c/wasm-rt-exceptions-impl.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/wasm2c/wasm-rt-exceptions-impl.c b/wasm2c/wasm-rt-exceptions-impl.c
new file mode 100644
index 00000000..8eee492e
--- /dev/null
+++ b/wasm2c/wasm-rt-exceptions-impl.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2018 WebAssembly Community Group participants
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "wasm-rt.h"
+
+#include "wasm-rt-exceptions.h"
+
+#include <string.h>
+
+#define MAX_EXCEPTION_SIZE 256
+
+static WASM_RT_THREAD_LOCAL wasm_rt_tag_t g_active_exception_tag;
+static WASM_RT_THREAD_LOCAL uint8_t g_active_exception[MAX_EXCEPTION_SIZE];
+static WASM_RT_THREAD_LOCAL uint32_t g_active_exception_size;
+
+static WASM_RT_THREAD_LOCAL wasm_rt_jmp_buf* g_unwind_target;
+
+void wasm_rt_load_exception(const wasm_rt_tag_t tag,
+ uint32_t size,
+ const void* values) {
+ if (size > MAX_EXCEPTION_SIZE) {
+ wasm_rt_trap(WASM_RT_TRAP_EXHAUSTION);
+ }
+
+ g_active_exception_tag = tag;
+ g_active_exception_size = size;
+
+ if (size) {
+ memcpy(g_active_exception, values, size);
+ }
+}
+
+WASM_RT_NO_RETURN void wasm_rt_throw(void) {
+ WASM_RT_LONGJMP(*g_unwind_target, WASM_RT_TRAP_UNCAUGHT_EXCEPTION);
+}
+
+WASM_RT_UNWIND_TARGET* wasm_rt_get_unwind_target(void) {
+ return g_unwind_target;
+}
+
+void wasm_rt_set_unwind_target(WASM_RT_UNWIND_TARGET* target) {
+ g_unwind_target = target;
+}
+
+wasm_rt_tag_t wasm_rt_exception_tag(void) {
+ return g_active_exception_tag;
+}
+
+uint32_t wasm_rt_exception_size(void) {
+ return g_active_exception_size;
+}
+
+void* wasm_rt_exception(void) {
+ return g_active_exception;
+}