diff --git a/rust/examples/reactor-hello.rs b/rust/examples/reactor-hello.rs index 3f20a40..ebb2795 100644 --- a/rust/examples/reactor-hello.rs +++ b/rust/examples/reactor-hello.rs @@ -49,5 +49,16 @@ pub async fn main() -> anyhow::Result<()> { f.call(&mut store, &[], &mut []).unwrap(); trace_ctx.shutdown().await; + // call __wasm_call_dtors + // Normally reactors don't emit __wasm_call_dtors, but + // reactor-hello.c.instr.wasm includes it as an example of specifying + // a cleanup function in a reactor. + { + let f = instance + .get_func(&mut store, "__wasm_call_dtors") + .expect("function exists"); + f.call(&mut store, &[], &mut []).unwrap(); + } + Ok(()) } diff --git a/test/constructor-destructor.c b/test/constructor-destructor.c new file mode 100644 index 0000000..12b9e80 --- /dev/null +++ b/test/constructor-destructor.c @@ -0,0 +1,11 @@ +#include + +__attribute__((constructor)) static void constructor(void) { + printf("constructor\n"); +} + +int main(void) {} + +__attribute__((destructor)) static void destructor(void) { + printf("destructor\n"); +} diff --git a/test/constructor-destructor.c.instr.wasm b/test/constructor-destructor.c.instr.wasm new file mode 100644 index 0000000..6e7b9a0 Binary files /dev/null and b/test/constructor-destructor.c.instr.wasm differ diff --git a/test/constructor-destructor.c.wasm b/test/constructor-destructor.c.wasm new file mode 100755 index 0000000..fb97848 Binary files /dev/null and b/test/constructor-destructor.c.wasm differ diff --git a/test/reactor-hello.c b/test/reactor-hello.c index f5f053f..0159a48 100644 --- a/test/reactor-hello.c +++ b/test/reactor-hello.c @@ -1,4 +1,12 @@ #include #define EXPORT_AS(name) __attribute__((export_name(name))) +__attribute__((constructor)) static void constructor(void) { + printf("constructor\n"); +} + EXPORT_AS("hello") void hello(void) { printf("hello world\n"); } + +EXPORT_AS("__wasm_call_dtors") void __wasm_call_dtors(void) { + printf("real destructor\n"); +} diff --git a/test/reactor-hello.c.instr.wasm b/test/reactor-hello.c.instr.wasm index 4fb6fda..4d8fc68 100644 Binary files a/test/reactor-hello.c.instr.wasm and b/test/reactor-hello.c.instr.wasm differ diff --git a/test/reactor-hello.c.wasm b/test/reactor-hello.c.wasm index bb8094e..6014ea6 100755 Binary files a/test/reactor-hello.c.wasm and b/test/reactor-hello.c.wasm differ