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