github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/engine/wazevo/wazevoapi/exitcode.go (about) 1 package wazevoapi 2 3 // ExitCode is an exit code of an execution of a function. 4 type ExitCode uint32 5 6 const ( 7 ExitCodeOK ExitCode = iota 8 ExitCodeGrowStack 9 ExitCodeGrowMemory 10 ExitCodeUnreachable 11 ExitCodeMemoryOutOfBounds 12 // ExitCodeCallGoModuleFunction is an exit code for a call to an api.GoModuleFunction. 13 ExitCodeCallGoModuleFunction 14 // ExitCodeCallGoFunction is an exit code for a call to an api.GoFunction. 15 ExitCodeCallGoFunction 16 ExitCodeTableOutOfBounds 17 ExitCodeIndirectCallNullPointer 18 ExitCodeIndirectCallTypeMismatch 19 ExitCodeIntegerDivisionByZero 20 ExitCodeIntegerOverflow 21 ExitCodeInvalidConversionToInteger 22 ExitCodeCheckModuleExitCode 23 ExitCodeCallListenerBefore 24 ExitCodeCallListenerAfter 25 ExitCodeCallGoModuleFunctionWithListener 26 ExitCodeCallGoFunctionWithListener 27 ExitCodeTableGrow 28 ExitCodeRefFunc 29 exitCodeMax 30 ) 31 32 const ExitCodeMask = 0xff 33 34 // String implements fmt.Stringer. 35 func (e ExitCode) String() string { 36 switch e { 37 case ExitCodeOK: 38 return "ok" 39 case ExitCodeGrowStack: 40 return "grow_stack" 41 case ExitCodeCallGoModuleFunction: 42 return "call_go_module_function" 43 case ExitCodeCallGoFunction: 44 return "call_go_function" 45 case ExitCodeUnreachable: 46 return "unreachable" 47 case ExitCodeMemoryOutOfBounds: 48 return "memory_out_of_bounds" 49 case ExitCodeTableOutOfBounds: 50 return "table_out_of_bounds" 51 case ExitCodeIndirectCallNullPointer: 52 return "indirect_call_null_pointer" 53 case ExitCodeIndirectCallTypeMismatch: 54 return "indirect_call_type_mismatch" 55 case ExitCodeIntegerDivisionByZero: 56 return "integer_division_by_zero" 57 case ExitCodeIntegerOverflow: 58 return "integer_overflow" 59 case ExitCodeInvalidConversionToInteger: 60 return "invalid_conversion_to_integer" 61 case ExitCodeCheckModuleExitCode: 62 return "check_module_exit_code" 63 case ExitCodeCallListenerBefore: 64 return "call_listener_before" 65 case ExitCodeCallListenerAfter: 66 return "call_listener_after" 67 case ExitCodeCallGoModuleFunctionWithListener: 68 return "call_go_module_function_with_listener" 69 case ExitCodeCallGoFunctionWithListener: 70 return "call_go_function_with_listener" 71 case ExitCodeGrowMemory: 72 return "grow_memory" 73 case ExitCodeTableGrow: 74 return "table_grow" 75 case ExitCodeRefFunc: 76 return "ref_func" 77 } 78 panic("TODO") 79 } 80 81 func ExitCodeCallGoModuleFunctionWithIndex(index int, withListener bool) ExitCode { 82 if withListener { 83 return ExitCodeCallGoModuleFunctionWithListener | ExitCode(index<<8) 84 } 85 return ExitCodeCallGoModuleFunction | ExitCode(index<<8) 86 } 87 88 func ExitCodeCallGoFunctionWithIndex(index int, withListener bool) ExitCode { 89 if withListener { 90 return ExitCodeCallGoFunctionWithListener | ExitCode(index<<8) 91 } 92 return ExitCodeCallGoFunction | ExitCode(index<<8) 93 } 94 95 func GoFunctionIndexFromExitCode(exitCode ExitCode) int { 96 return int(exitCode >> 8) 97 }