github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/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 ExitCodeMemoryWait32 30 ExitCodeMemoryWait64 31 ExitCodeMemoryNotify 32 ExitCodeUnalignedAtomic 33 exitCodeMax 34 ) 35 36 const ExitCodeMask = 0xff 37 38 // String implements fmt.Stringer. 39 func (e ExitCode) String() string { 40 switch e { 41 case ExitCodeOK: 42 return "ok" 43 case ExitCodeGrowStack: 44 return "grow_stack" 45 case ExitCodeCallGoModuleFunction: 46 return "call_go_module_function" 47 case ExitCodeCallGoFunction: 48 return "call_go_function" 49 case ExitCodeUnreachable: 50 return "unreachable" 51 case ExitCodeMemoryOutOfBounds: 52 return "memory_out_of_bounds" 53 case ExitCodeUnalignedAtomic: 54 return "unaligned_atomic" 55 case ExitCodeTableOutOfBounds: 56 return "table_out_of_bounds" 57 case ExitCodeIndirectCallNullPointer: 58 return "indirect_call_null_pointer" 59 case ExitCodeIndirectCallTypeMismatch: 60 return "indirect_call_type_mismatch" 61 case ExitCodeIntegerDivisionByZero: 62 return "integer_division_by_zero" 63 case ExitCodeIntegerOverflow: 64 return "integer_overflow" 65 case ExitCodeInvalidConversionToInteger: 66 return "invalid_conversion_to_integer" 67 case ExitCodeCheckModuleExitCode: 68 return "check_module_exit_code" 69 case ExitCodeCallListenerBefore: 70 return "call_listener_before" 71 case ExitCodeCallListenerAfter: 72 return "call_listener_after" 73 case ExitCodeCallGoModuleFunctionWithListener: 74 return "call_go_module_function_with_listener" 75 case ExitCodeCallGoFunctionWithListener: 76 return "call_go_function_with_listener" 77 case ExitCodeGrowMemory: 78 return "grow_memory" 79 case ExitCodeTableGrow: 80 return "table_grow" 81 case ExitCodeRefFunc: 82 return "ref_func" 83 case ExitCodeMemoryWait32: 84 return "memory_wait32" 85 case ExitCodeMemoryWait64: 86 return "memory_wait64" 87 case ExitCodeMemoryNotify: 88 return "memory_notify" 89 } 90 panic("TODO") 91 } 92 93 func ExitCodeCallGoModuleFunctionWithIndex(index int, withListener bool) ExitCode { 94 if withListener { 95 return ExitCodeCallGoModuleFunctionWithListener | ExitCode(index<<8) 96 } 97 return ExitCodeCallGoModuleFunction | ExitCode(index<<8) 98 } 99 100 func ExitCodeCallGoFunctionWithIndex(index int, withListener bool) ExitCode { 101 if withListener { 102 return ExitCodeCallGoFunctionWithListener | ExitCode(index<<8) 103 } 104 return ExitCodeCallGoFunction | ExitCode(index<<8) 105 } 106 107 func GoFunctionIndexFromExitCode(exitCode ExitCode) int { 108 return int(exitCode >> 8) 109 }