wa-lang.org/wazero@v1.0.2/imports/wasi_snapshot_preview1/proc.go (about) 1 package wasi_snapshot_preview1 2 3 import ( 4 "context" 5 6 "wa-lang.org/wazero/api" 7 "wa-lang.org/wazero/internal/wasm" 8 "wa-lang.org/wazero/sys" 9 ) 10 11 const ( 12 functionProcExit = "proc_exit" 13 functionProcRaise = "proc_raise" 14 ) 15 16 // procExit is the WASI function named functionProcExit that terminates the 17 // execution of the module with an exit code. The only successful exit code is 18 // zero. 19 // 20 // # Parameters 21 // 22 // - exitCode: exit code. 23 // 24 // See https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#proc_exit 25 var procExit = &wasm.HostFunc{ 26 ExportNames: []string{functionProcExit}, 27 Name: functionProcExit, 28 ParamTypes: []api.ValueType{i32}, 29 ParamNames: []string{"rval"}, 30 Code: &wasm.Code{ 31 IsHostFunction: true, 32 GoFunc: wasiFunc(procExitFn), 33 }, 34 } 35 36 func procExitFn(ctx context.Context, mod api.Module, params []uint64) Errno { 37 exitCode := uint32(params[0]) 38 39 // Ensure other callers see the exit code. 40 _ = mod.CloseWithExitCode(ctx, exitCode) 41 42 // Prevent any code from executing after this function. For example, LLVM 43 // inserts unreachable instructions after calls to exit. 44 // See: https://github.com/emscripten-core/emscripten/issues/12322 45 panic(sys.NewExitError(mod.Name(), exitCode)) 46 } 47 48 // procRaise is stubbed and will never be supported, as it was removed. 49 // 50 // See https://github.com/WebAssembly/WASI/pull/136 51 var procRaise = stubFunction(functionProcRaise, []wasm.ValueType{i32}, []string{"sig"})