diff --git a/src/flamenco/runtime/tests/fd_exec_instr_test.c b/src/flamenco/runtime/tests/fd_exec_instr_test.c index a2309eca95..eb9f79c6a8 100644 --- a/src/flamenco/runtime/tests/fd_exec_instr_test.c +++ b/src/flamenco/runtime/tests/fd_exec_instr_test.c @@ -1806,10 +1806,10 @@ fd_exec_vm_syscall_test_run( fd_exec_instr_test_runner_t * runner, access violations in Agave. The agave_access_violation_mask bitset sets the error codes that are expected to be access violations in Agave. */ if( is_cpi && - ( syscall_err == FD_VM_ERR_SYSCALL_TOO_MANY_SIGNERS || - syscall_err == FD_VM_ERR_SYSCALL_INSTRUCTION_TOO_LARGE || - syscall_err == FD_VM_ERR_SYSCALL_MAX_INSTRUCTION_ACCOUNTS_EXCEEDED || - syscall_err == FD_VM_ERR_SYSCALL_MAX_INSTRUCTION_ACCOUNT_INFOS_EXCEEDED ) ) { + ( syscall_err == FD_VM_SYSCALL_ERR_TOO_MANY_SIGNERS || + syscall_err == FD_VM_SYSCALL_ERR_INSTRUCTION_TOO_LARGE || + syscall_err == FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_ACCOUNTS_EXCEEDED || + syscall_err == FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_ACCOUNT_INFOS_EXCEEDED ) ) { /* FD performs pre-flight checks that manifest as access violations in Agave */ vm->instr_ctx->txn_ctx->exec_err = FD_VM_ERR_EBPF_ACCESS_VIOLATION; diff --git a/src/flamenco/vm/fd_vm.c b/src/flamenco/vm/fd_vm.c index ac12e77f0a..c6af6b3859 100644 --- a/src/flamenco/vm/fd_vm.c +++ b/src/flamenco/vm/fd_vm.c @@ -13,30 +13,37 @@ fd_vm_syscall_strerror( int err ) { switch( err ) { - case FD_VM_ERR_SYSCALL_INVALID_STRING: return "invalid utf-8 sequence"; // truncated - case FD_VM_ERR_SYSCALL_ABORT: return "SBF program panicked"; - case FD_VM_ERR_SYSCALL_PANIC: return "SBF program Panicked in..."; // truncated - case FD_VM_ERR_SYSCALL_INVOKE_CONTEXT_BORROW_FAILED: return "Cannot borrow invoke context"; - case FD_VM_ERR_SYSCALL_MALFORMED_SIGNER_SEED: return "Malformed signer seed"; // truncated - case FD_VM_ERR_SYSCALL_BAD_SEEDS: return "Could not create program address with signer seeds"; // truncated - case FD_VM_ERR_SYSCALL_PROGRAM_NOT_SUPPORTED: return "Program not supported by inner instructions"; // truncated - case FD_VM_ERR_SYSCALL_UNALIGNED_POINTER: return "Unaligned pointer"; - case FD_VM_ERR_SYSCALL_TOO_MANY_SIGNERS: return "Too many signers"; - case FD_VM_ERR_SYSCALL_INSTRUCTION_TOO_LARGE: return "Instruction passed to inner instruction is too large"; // truncated - case FD_VM_ERR_SYSCALL_TOO_MANY_ACCOUNTS: return "Too many accounts passed to inner instruction"; - case FD_VM_ERR_SYSCALL_COPY_OVERLAPPING: return "Overlapping copy"; - case FD_VM_ERR_SYSCALL_RETURN_DATA_TOO_LARGE: return "Return data too large"; // truncated - case FD_VM_ERR_SYSCALL_TOO_MANY_SLICES: return "Hashing too many sequences"; - case FD_VM_ERR_SYSCALL_INVALID_LENGTH: return "InvalidLength"; - case FD_VM_ERR_SYSCALL_MAX_INSTRUCTION_DATA_LEN_EXCEEDED: return "Invoked an instruction with data that is too large"; // truncated - case FD_VM_ERR_SYSCALL_MAX_INSTRUCTION_ACCOUNTS_EXCEEDED: return "Invoked an instruction with too many accounts"; // truncated - case FD_VM_ERR_SYSCALL_MAX_INSTRUCTION_ACCOUNT_INFOS_EXCEEDED: return "Invoked an instruction with too many account info's"; // truncated - case FD_VM_ERR_SYSCALL_INVALID_ATTRIBUTE: return "InvalidAttribute"; - case FD_VM_ERR_SYSCALL_INVALID_POINTER: return "Invalid pointer"; - case FD_VM_ERR_SYSCALL_ARITHMETIC_OVERFLOW: return "Arithmetic overflow"; - - case FD_VM_ERR_SYSCALL_POSEIDON_INVALID_PARAMS: return "Syscall error: Invalid parameters."; - case FD_VM_ERR_SYSCALL_POSEIDON_INVALID_ENDIANNESS: return "Syscall error: Invalid endianness."; + case FD_VM_SYSCALL_ERR_INVALID_STRING: return "invalid utf-8 sequence"; // truncated + case FD_VM_SYSCALL_ERR_ABORT: return "SBF program panicked"; + case FD_VM_SYSCALL_ERR_PANIC: return "SBF program Panicked in..."; // truncated + case FD_VM_SYSCALL_ERR_INVOKE_CONTEXT_BORROW_FAILED: return "Cannot borrow invoke context"; + case FD_VM_SYSCALL_ERR_MALFORMED_SIGNER_SEED: return "Malformed signer seed"; // truncated + case FD_VM_SYSCALL_ERR_BAD_SEEDS: return "Could not create program address with signer seeds"; // truncated + case FD_VM_SYSCALL_ERR_PROGRAM_NOT_SUPPORTED: return "Program not supported by inner instructions"; // truncated + case FD_VM_SYSCALL_ERR_UNALIGNED_POINTER: return "Unaligned pointer"; + case FD_VM_SYSCALL_ERR_TOO_MANY_SIGNERS: return "Too many signers"; + case FD_VM_SYSCALL_ERR_INSTRUCTION_TOO_LARGE: return "Instruction passed to inner instruction is too large"; // truncated + case FD_VM_SYSCALL_ERR_TOO_MANY_ACCOUNTS: return "Too many accounts passed to inner instruction"; + case FD_VM_SYSCALL_ERR_COPY_OVERLAPPING: return "Overlapping copy"; + case FD_VM_SYSCALL_ERR_RETURN_DATA_TOO_LARGE: return "Return data too large"; // truncated + case FD_VM_SYSCALL_ERR_TOO_MANY_SLICES: return "Hashing too many sequences"; + case FD_VM_SYSCALL_ERR_INVALID_LENGTH: return "InvalidLength"; + case FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_DATA_LEN_EXCEEDED: return "Invoked an instruction with data that is too large"; // truncated + case FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_ACCOUNTS_EXCEEDED: return "Invoked an instruction with too many accounts"; // truncated + case FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_ACCOUNT_INFOS_EXCEEDED: return "Invoked an instruction with too many account info's"; // truncated + case FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE: return "InvalidAttribute"; + case FD_VM_SYSCALL_ERR_INVALID_POINTER: return "Invalid pointer"; + case FD_VM_SYSCALL_ERR_ARITHMETIC_OVERFLOW: return "Arithmetic overflow"; + + case FD_VM_SYSCALL_ERR_INSTR_ERR: return "Instruction error"; + case FD_VM_SYSCALL_ERR_INVALID_PDA: return "Invalid PDA"; + case FD_VM_SYSCALL_ERR_COMPUTE_BUDGET_EXCEEDED: return "Compute budget exceeded"; + case FD_VM_SYSCALL_ERR_SEGFAULT: return "Segmentation fault"; + case FD_VM_SYSCALL_ERR_OUTSIDE_RUNTIME: return "Syscall executed outside runtime"; + + + case FD_VM_SYSCALL_ERR_POSEIDON_INVALID_PARAMS: return "Syscall error: Invalid parameters."; + case FD_VM_SYSCALL_ERR_POSEIDON_INVALID_ENDIANNESS: return "Syscall error: Invalid endianness."; default: break; } @@ -100,27 +107,22 @@ fd_vm_strerror( int err ) { /* VM exec error codes */ - case FD_VM_ERR_SIGTEXT: return "SIGTEXT illegal program counter"; - case FD_VM_ERR_SIGSPLIT: return "SIGSPLIT split multiword instruction"; - case FD_VM_ERR_SIGCALL: return "unsupported BPF instruction"; - case FD_VM_ERR_SIGSTACK: return "SIGSTACK call depth limit exceeded"; - case FD_VM_ERR_SIGILL: return "SIGILL illegal instruction"; - case FD_VM_ERR_SIGSEGV: return "SIGSEGV illegal memory address"; - case FD_VM_ERR_SIGBUS: return "SIGBUS misaligned memory address"; - case FD_VM_ERR_SIGRDONLY: return "SIGRDONLY illegal write"; - case FD_VM_ERR_SIGCOST: return "SIGCOST compute unit limit exceeded"; - case FD_VM_ERR_SIGFPE: return "SIGFPE division by zero"; - case FD_VM_ERR_SIGFPE_OF: return "SIGFPE division overflow"; - - /* VM syscall error codes */ - /* https://github.com/anza-xyz/agave/blob/v2.0.6/programs/bpf_loader/src/syscalls/mod.rs#L81 */ - - case FD_VM_ERR_ABORT: return "SBF program panicked"; - case FD_VM_ERR_PANIC: return "PANIC"; /* FIXME: description */ + case FD_VM_ERR_SIGTEXT: return "SIGTEXT illegal program counter"; + case FD_VM_ERR_SIGSPLIT: return "SIGSPLIT split multiword instruction"; + case FD_VM_ERR_SIGCALL: return "unsupported BPF instruction"; + case FD_VM_ERR_SIGSTACK: return "SIGSTACK call depth limit exceeded"; + case FD_VM_ERR_SIGILL: return "SIGILL illegal instruction"; + case FD_VM_ERR_SIGSEGV: return "SIGSEGV illegal memory address"; + case FD_VM_ERR_SIGBUS: return "SIGBUS misaligned memory address"; + case FD_VM_ERR_SIGRDONLY: return "SIGRDONLY illegal write"; + case FD_VM_ERR_SIGCOST: return "SIGCOST compute unit limit exceeded"; + case FD_VM_ERR_SIGFPE: return "SIGFPE division by zero"; + case FD_VM_ERR_SIGFPE_OF: return "SIGFPE division overflow"; + case FD_VM_ERR_SIGSYSCALL: return "SIGSYSCALL syscall error"; + case FD_VM_ERR_SIGABORT: return "SIGABORT abort error"; + + /* (Deprecated) Syscall errors */ case FD_VM_ERR_MEM_OVERLAP: return "MEM_OVERLAP"; /* FIXME: description */ - case FD_VM_ERR_INSTR_ERR: return "INSTR_ERR"; /* FIXME: description */ - case FD_VM_ERR_RETURN_DATA_TOO_LARGE: return "RETURN_DATA_TOO_LARGE"; /* FIXME: description */ - case FD_VM_ERR_INVOKE_CONTEXT_BORROW_FAILED: return "INVOKE_CONTEXT_BORROW_FAILED"; /* FIXME: description */ /* VM validate error codes */ diff --git a/src/flamenco/vm/fd_vm_base.h b/src/flamenco/vm/fd_vm_base.h index 74efa08b13..1319364d1a 100644 --- a/src/flamenco/vm/fd_vm_base.h +++ b/src/flamenco/vm/fd_vm_base.h @@ -38,26 +38,22 @@ #define FD_VM_ERR_SIGSEGV (-13) /* illegal memory address (e.g. read/write to an address not backed by any memory) */ #define FD_VM_ERR_SIGBUS (-14) /* misaligned memory address (e.g. read/write to an address with inappropriate alignment) */ #define FD_VM_ERR_SIGRDONLY (-15) /* illegal write (e.g. write to a read only address) */ -#define FD_VM_ERR_SIGCOST (-16) /* compute unit limit exceeded (syscalls that exceed their budget should use this too) */ -#define FD_VM_ERR_INVALID_PDA (-17) /* the computed pda was not a valid ed25519 point */ +#define FD_VM_ERR_SIGCOST (-16) /* compute unit limit exceeded */ +// #define FD_VM_ERR_INVALID_PDA (-17) /* (deprecated, moved to syscall error) the computed pda was not a valid ed25519 point */ #define FD_VM_ERR_SIGFPE (-18) /* divide by zero */ -#define FD_VM_ERR_SIGFPE_OF (-118)/* divide overflow */ +#define FD_VM_ERR_SIGFPE_OF (-19) /* divide overflow */ +#define FD_VM_ERR_SIGSYSCALL (-20) /* Generic syscall error */ +#define FD_VM_ERR_SIGABORT (-21) /* Generic abort error (used in JIT) */ -/* FIXME: Are these exact matches to Solana? If so, provide link, if - not, document and refine name / consolidate further. */ +/* (DEPRECATED) VM syscall error codes. These are only produced by fd_vm_syscall + implementations. */ -/* VM syscall error codes. These are only produced by fd_vm_syscall - implementations. FIXME: Consider having syscalls return standard - error codes and then provide detail like this through an info arg. - FIXME: Are these exact matches to Solana? If so, provide link? If - not document and refine names / consolidate further. */ - -#define FD_VM_ERR_ABORT (-19) /* FIXME: description */ -#define FD_VM_ERR_PANIC (-20) /* FIXME: description */ -#define FD_VM_ERR_MEM_OVERLAP (-21) /* FIXME: description */ -#define FD_VM_ERR_INSTR_ERR (-22) /* FIXME: description */ -#define FD_VM_ERR_INVOKE_CONTEXT_BORROW_FAILED (-23) /* FIXME: description */ -#define FD_VM_ERR_RETURN_DATA_TOO_LARGE (-24) /* FIXME: description */ +// #define FD_VM_ERR_ABORT (-119) /* FIXME: description PENDING SYSVAR SYSCALL */ +// #define FD_VM_ERR_PANIC (-120) /* FIXME: description PENDING TESTS refactor */ +#define FD_VM_ERR_MEM_OVERLAP (-121) /* FIXME: description PENDING FD_VM_MEM_CHECK_NON_OVERLAPPING refactor */ +// #define FD_VM_ERR_INSTR_ERR (-22) /* FIXME: description DONE */ +// #define FD_VM_ERR_INVOKE_CONTEXT_BORROW_FAILED (-23) /* FIXME: description DONE (unused) */ +// #define FD_VM_ERR_RETURN_DATA_TOO_LARGE (-24) /* FIXME: description DONE */ /* sBPF validation error codes. These are only produced by fd_vm_validate. FIXME: Consider having fd_vm_validate return @@ -83,31 +79,38 @@ /* Syscall Errors https://github.com/anza-xyz/agave/blob/v2.0.7/programs/bpf_loader/src/syscalls/mod.rs#L81 */ -#define FD_VM_ERR_SYSCALL_INVALID_STRING (-1) -#define FD_VM_ERR_SYSCALL_ABORT (-2) -#define FD_VM_ERR_SYSCALL_PANIC (-3) -#define FD_VM_ERR_SYSCALL_INVOKE_CONTEXT_BORROW_FAILED (-4) -#define FD_VM_ERR_SYSCALL_MALFORMED_SIGNER_SEED (-5) -#define FD_VM_ERR_SYSCALL_BAD_SEEDS (-6) -#define FD_VM_ERR_SYSCALL_PROGRAM_NOT_SUPPORTED (-7) -#define FD_VM_ERR_SYSCALL_UNALIGNED_POINTER (-8) -#define FD_VM_ERR_SYSCALL_TOO_MANY_SIGNERS (-9) -#define FD_VM_ERR_SYSCALL_INSTRUCTION_TOO_LARGE (-10) -#define FD_VM_ERR_SYSCALL_TOO_MANY_ACCOUNTS (-11) -#define FD_VM_ERR_SYSCALL_COPY_OVERLAPPING (-12) -#define FD_VM_ERR_SYSCALL_RETURN_DATA_TOO_LARGE (-13) -#define FD_VM_ERR_SYSCALL_TOO_MANY_SLICES (-14) -#define FD_VM_ERR_SYSCALL_INVALID_LENGTH (-15) -#define FD_VM_ERR_SYSCALL_MAX_INSTRUCTION_DATA_LEN_EXCEEDED (-16) -#define FD_VM_ERR_SYSCALL_MAX_INSTRUCTION_ACCOUNTS_EXCEEDED (-17) -#define FD_VM_ERR_SYSCALL_MAX_INSTRUCTION_ACCOUNT_INFOS_EXCEEDED (-18) -#define FD_VM_ERR_SYSCALL_INVALID_ATTRIBUTE (-19) -#define FD_VM_ERR_SYSCALL_INVALID_POINTER (-20) -#define FD_VM_ERR_SYSCALL_ARITHMETIC_OVERFLOW (-21) +#define FD_VM_SYSCALL_ERR_INVALID_STRING (-1) +#define FD_VM_SYSCALL_ERR_ABORT (-2) +#define FD_VM_SYSCALL_ERR_PANIC (-3) +#define FD_VM_SYSCALL_ERR_INVOKE_CONTEXT_BORROW_FAILED (-4) +#define FD_VM_SYSCALL_ERR_MALFORMED_SIGNER_SEED (-5) +#define FD_VM_SYSCALL_ERR_BAD_SEEDS (-6) +#define FD_VM_SYSCALL_ERR_PROGRAM_NOT_SUPPORTED (-7) +#define FD_VM_SYSCALL_ERR_UNALIGNED_POINTER (-8) +#define FD_VM_SYSCALL_ERR_TOO_MANY_SIGNERS (-9) +#define FD_VM_SYSCALL_ERR_INSTRUCTION_TOO_LARGE (-10) +#define FD_VM_SYSCALL_ERR_TOO_MANY_ACCOUNTS (-11) +#define FD_VM_SYSCALL_ERR_COPY_OVERLAPPING (-12) +#define FD_VM_SYSCALL_ERR_RETURN_DATA_TOO_LARGE (-13) +#define FD_VM_SYSCALL_ERR_TOO_MANY_SLICES (-14) +#define FD_VM_SYSCALL_ERR_INVALID_LENGTH (-15) +#define FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_DATA_LEN_EXCEEDED (-16) +#define FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_ACCOUNTS_EXCEEDED (-17) +#define FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_ACCOUNT_INFOS_EXCEEDED (-18) +#define FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE (-19) +#define FD_VM_SYSCALL_ERR_INVALID_POINTER (-20) +#define FD_VM_SYSCALL_ERR_ARITHMETIC_OVERFLOW (-21) + +/* These syscall errors are unique to Firedancer and do not have an Agave equivalent. */ +#define FD_VM_SYSCALL_ERR_INSTR_ERR (-22) +#define FD_VM_SYSCALL_ERR_INVALID_PDA (-23) /* the computed pda was not a valid ed25519 point */ +#define FD_VM_SYSCALL_ERR_COMPUTE_BUDGET_EXCEEDED (-24) /* compute unit limit exceeded in syscall */ +#define FD_VM_SYSCALL_ERR_SEGFAULT (-25) /* illegal memory address (e.g. read/write to an address not backed by any memory) in syscall */ +#define FD_VM_SYSCALL_ERR_OUTSIDE_RUNTIME (-26) /* syscall called with vm not running in solana runtime */ /* Poseidon returns custom errors for some reason */ -#define FD_VM_ERR_SYSCALL_POSEIDON_INVALID_PARAMS (1) -#define FD_VM_ERR_SYSCALL_POSEIDON_INVALID_ENDIANNESS (2) +#define FD_VM_SYSCALL_ERR_POSEIDON_INVALID_PARAMS (1) +#define FD_VM_SYSCALL_ERR_POSEIDON_INVALID_ENDIANNESS (2) /* EbpfError https://github.com/solana-labs/rbpf/blob/v0.8.5/src/error.rs#L17 */ diff --git a/src/flamenco/vm/fd_vm_private.h b/src/flamenco/vm/fd_vm_private.h index 78f56e663a..a8efda2b3a 100644 --- a/src/flamenco/vm/fd_vm_private.h +++ b/src/flamenco/vm/fd_vm_private.h @@ -566,7 +566,7 @@ static inline void fd_vm_mem_st_8( fd_vm_t const * vm, ulong _haddr = fd_vm_mem_haddr( vm, _vaddr, (sz), _vm->region_haddr, _vm->region_ld_sz, 0, 0UL, &_is_multi ); \ int _sigbus = fd_vm_is_check_align_enabled( vm ) & (!fd_ulong_is_aligned( _haddr, (align) )); \ if ( FD_UNLIKELY( sz > LONG_MAX ) ) { \ - FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_ERR_SYSCALL_INVALID_LENGTH ); \ + FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_SYSCALL_ERR_INVALID_LENGTH ); \ return FD_VM_ERR_SIGSEGV; \ } \ if( FD_UNLIKELY( (!_haddr) | _is_multi) ) { \ @@ -574,7 +574,7 @@ static inline void fd_vm_mem_st_8( fd_vm_t const * vm, return FD_VM_ERR_SIGSEGV; \ } \ if ( FD_UNLIKELY( _sigbus ) ) { \ - FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_ERR_SYSCALL_UNALIGNED_POINTER ); \ + FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_SYSCALL_ERR_UNALIGNED_POINTER ); \ return FD_VM_ERR_SIGSEGV; \ } \ (void const *)_haddr; \ @@ -601,7 +601,7 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int ulong _haddr = fd_vm_mem_haddr( vm, _vaddr, (sz), _vm->region_haddr, _vm->region_st_sz, 1, 0UL, &_is_multi ); int _sigbus = fd_vm_is_check_align_enabled( vm ) & (!fd_ulong_is_aligned( _haddr, (align) )); if ( FD_UNLIKELY( sz > LONG_MAX ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_ERR_SYSCALL_INVALID_LENGTH ); + FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_SYSCALL_ERR_INVALID_LENGTH ); *err = FD_VM_ERR_SIGSEGV; return 0; } @@ -611,7 +611,7 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int return 0; } if ( FD_UNLIKELY( _sigbus ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_ERR_SYSCALL_UNALIGNED_POINTER ); + FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_SYSCALL_ERR_UNALIGNED_POINTER ); *err = FD_VM_ERR_SIGSEGV; return 0; } @@ -641,7 +641,7 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int ulong _haddr = fd_vm_mem_haddr( vm, _vaddr, (sz), _vm->region_haddr, _vm->region_st_sz, 0, 0UL, &_is_multi ); \ int _sigbus = fd_vm_is_check_align_enabled( vm ) & (!fd_ulong_is_aligned( _haddr, (align) )); \ if ( FD_UNLIKELY( sz > LONG_MAX ) ) { \ - FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_ERR_SYSCALL_INVALID_LENGTH ); \ + FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_SYSCALL_ERR_INVALID_LENGTH ); \ return FD_VM_ERR_SIGSEGV; \ } \ if( FD_UNLIKELY( (!_haddr) | _is_multi ) ) { \ @@ -649,7 +649,7 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int return FD_VM_ERR_SIGSEGV; \ } \ if ( FD_UNLIKELY( _sigbus ) ) { \ - FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_ERR_SYSCALL_UNALIGNED_POINTER ); \ + FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_SYSCALL_ERR_UNALIGNED_POINTER ); \ return FD_VM_ERR_SIGSEGV; \ } \ (void *)_haddr; \ @@ -698,7 +698,7 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int LONG_MAX. */ #define FD_VM_MEM_SLICE_HADDR_LD( vm, vaddr, align, sz ) (__extension__({ \ if ( FD_UNLIKELY( sz > LONG_MAX ) ) { \ - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_INVALID_LENGTH ); \ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_LENGTH ); \ return FD_VM_ERR_INVAL; \ } \ void const * haddr = 0UL; \ @@ -713,7 +713,7 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int loads with no size bounding support. */ #define FD_VM_MEM_SLICE_HADDR_LD_SZ_UNCHECKED( vm, vaddr, align ) (__extension__({ \ if ( FD_UNLIKELY( sz > LONG_MAX ) ) { \ - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_INVALID_LENGTH ); \ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_LENGTH ); \ return FD_VM_ERR_INVAL; \ } \ void const * haddr = 0UL; \ @@ -725,7 +725,7 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int #define FD_VM_MEM_SLICE_HADDR_ST( vm, vaddr, align, sz ) (__extension__({ \ if ( FD_UNLIKELY( sz > LONG_MAX ) ) { \ - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_INVALID_LENGTH ); \ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_LENGTH ); \ return FD_VM_ERR_INVAL; \ } \ void * haddr = 0UL; \ @@ -739,7 +739,7 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int #define FD_VM_MEM_CHECK_NON_OVERLAPPING( vm, vaddr0, sz0, vaddr1, sz1 ) do { \ if( FD_UNLIKELY( ((vaddr0> vaddr1) && ((vaddr0-vaddr1)=vaddr0) && ((vaddr1-vaddr0)vm_fault: //| mov edi, FD_VM_ERR_ABORT //| jmp ->longjmp - dasm_put(Dst, 534, FD_VM_ERR_ABORT); + dasm_put(Dst, 534, FD_VM_ERR_SIGABORT); #line 536 "fd_jit_compiler.dasc" /* JIT entrypoint from C code */ diff --git a/src/flamenco/vm/jit/fd_jit_compiler.dasc b/src/flamenco/vm/jit/fd_jit_compiler.dasc index 5c129e28bc..ec0e15a339 100644 --- a/src/flamenco/vm/jit/fd_jit_compiler.dasc +++ b/src/flamenco/vm/jit/fd_jit_compiler.dasc @@ -531,7 +531,7 @@ fd_jit_compile( struct dasm_State ** Dst, /* Exception handlers */ |->vm_fault: - | mov edi, FD_VM_ERR_ABORT + | mov edi, FD_VM_ERR_SIGABORT | jmp ->longjmp /* JIT entrypoint from C code */ diff --git a/src/flamenco/vm/syscall/fd_vm_syscall.h b/src/flamenco/vm/syscall/fd_vm_syscall.h index 36fe171b6d..85e30e5518 100644 --- a/src/flamenco/vm/syscall/fd_vm_syscall.h +++ b/src/flamenco/vm/syscall/fd_vm_syscall.h @@ -58,7 +58,7 @@ When a syscall implementation returns FD_VM_SUCCESS, *_r0 should hold the application return error value it wants to place in r0. - When an syscall implementation returns FD_VM_ERR, the syscall is + When an syscall implementation returns FD_VM_SYSCALL_ERR*, the syscall is considered to have faulted the VM. It ideally should not have set *_r0 (or changed any vm state, except vm->cu, though that often isn't practical). @@ -107,7 +107,7 @@ FD_PROTOTYPES_BEGIN Return: - FD_VM_ERR_ABORT: *_ret unchanged. vm->cu unchanged. + FD_VM_SYSCALL_ERR_ABORT: *_ret unchanged. vm->cu unchanged. FIXME: SHOULD THIS BE NAMED "SOL_ABORT"? */ @@ -129,10 +129,9 @@ FD_VM_SYSCALL_DECL( abort ); FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged. vm->cu==0. - FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu - decremented and vm->cu>0. + FD_VM_SYSCALL_ERR_INVALID_STRING: Bad filepath string - FD_VM_ERR_PANIC: *_ret unchanged. *_ret unchanged. vm->cu + FD_VM_SYSCALL_ERR_PANIC: *_ret unchanged. *_ret unchanged. vm->cu decremented and vm->cu>0. */ FD_VM_SYSCALL_DECL( sol_panic ); @@ -153,8 +152,7 @@ FD_VM_SYSCALL_DECL( sol_panic ); FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged. vm->cu==0. - FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu - decremented and vm->cu>0. + FD_VM_SYSCALL_ERR_INVALID_STRING: bad message string. *_ret=1. FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0. @@ -204,7 +202,7 @@ FD_VM_SYSCALL_DECL( sol_log_64 ); FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged. vm->cu==0. - FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu + FD_VM_SYSCALL_ERR_SEGFAULT: bad address range. *_ret unchanged. vm->cu decremented and vm->cu>0. FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0. @@ -262,7 +260,7 @@ FD_VM_SYSCALL_DECL( sol_log_compute_units ); FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged. vm->cu==0. - FD_VM_ERR_SIGSEGV: bad address range. *_ret unchanged. vm->cu + FD_VM_SYSCALL_ERR_SEGFAULT: bad address range. *_ret unchanged. vm->cu decremented and vm->cu>0. FD_VM_SUCCESS: success. *_ret=0. vm->cu decremented and vm->cu>0. @@ -331,7 +329,7 @@ FD_VM_SYSCALL_DECL( sol_alloc_free ); FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged. vm->cu==0. - FD_VM_ERR_MEM_OVERLAP: address ranges for src and dst overlap + FD_VM_SYSCALL_ERR_COPY_OVERLAPPING: address ranges for src and dst overlap (either partially or fully). Empty address ranges are considered to never overlap (FIXME: CHECK THIS IS DESIRED). *_ret unchanged. vm->cu decremented and vm->cu>0. FIXME: CONSIDER USING A DIFFERENT @@ -445,7 +443,7 @@ FD_VM_SYSCALL_DECL( sol_memmove ); Return: - FD_VM_ERR_SIGCALL: the VM is not running within the Solana runtime. + FD_VM_SYSCALL_ERR_OUTSIDE_RUNTIME: the VM is not running within the Solana runtime. *_ret unchanged. vm->cu unchanged. FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged. @@ -493,7 +491,7 @@ FD_VM_SYSCALL_DECL( sol_get_last_restart_slot_sysvar ); FD_VM_ERR_SIGSEGV: bad sysvar_id_vaddr, bad out_vaddr, requested slice outside of sysvar data buffer. _ret unchanged. vm->cu unchanged. - FD_VM_ERR_ABORT: offset+sz overflow. *_ret unchanged. + FD_VM_SYSCALL_ERR_ABORT: offset+sz overflow. *_ret unchanged. FD_VM_SUCCESS: success. vm->cu decremented and vm->cu>0. - *_ret = 2 if sysvar id is not in {clock,schedule,rewards,rent,slot hashes,stake history,last restart slot} @@ -576,13 +574,13 @@ FD_VM_SYSCALL_DECL( sol_get_stack_height ); Return: - FD_VM_ERR_SIGCALL: the VM is not running within the Solana runtime. + FD_VM_SYSCALL_ERR_OUTSIDE_RUNTIME: the VM is not running within the Solana runtime. *_ret unchanged. vm->cu unchanged. FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged. vm->cu==0. - FD_VM_ERR_MEM_OVERLAP: dst and program_id address ranges overlap. + FD_VM_SYSCALL_ERR_COPY_OVERLAPPING: dst and program_id address ranges overlap. *_ret unchanged. vm->cu decremented and vm->cu>0. (FIXME: ERR CODE) (FIXME: overlap currently checked against the acutal amount copied into dst which is <=dst_max ... DOUBLE CHECK THIS AGAINST @@ -619,11 +617,13 @@ FD_VM_SYSCALL_DECL( sol_get_return_data ); r5 - ignored Return: + FD_VM_SYSCALL_ERR_OUTSIDE_RUNTIME: the VM is not running within the Solana runtime. + *_ret unchanged. vm->cu unchanged. FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged. vm->cu decremented and vm->cu>0. - FD_VM_ERR_RETURN_DATA_TOO_LARGE: src_sz too large. *_ret + FD_VM_SYSCALL_ERR_RETURN_DATA_TOO_LARGE: src_sz too large. *_ret unchanged. vm->cu decremented and vm->cu>0. FD_VM_ERR_PERM: bad address range for src. *_ret unchanged. @@ -662,8 +662,8 @@ FD_VM_SYSCALL_DECL( sol_get_processed_sibling_instruction ); FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged. Compute budget decremented. - FD_VM_ERR_PERM: seed_cnt and/or seed[i].sz too large (FIXME: USE - DIFFERENT ERR CODE), bad address range for program_id, seed, + FD_VM_SYSCALL_ERR_BAD_SEEDS: seed_cnt and/or seed[i].sz too large, + bad address range for program_id, seed, seed[i].mem and/or out (including 8-byte alignment for seed if the VM has check_align set). *_ret unchanged. Compute budget decremented. @@ -696,8 +696,8 @@ FD_VM_SYSCALL_DECL( sol_create_program_address ); FD_VM_ERR_SIGCOST: insufficient compute budget. *_ret unchanged. Compute budget decremented. - FD_VM_ERR_PERM: seed_cnt and/or seed[i].sz too large (FIXME: USE - DIFFERENT ERR CODE), bad address range for program_id, seed, + FD_VM_SYSCALL_ERR_BAD_SEEDS: seed_cnt and/or seed[i].sz too large, + bad address range for program_id, seed, seed[i].mem, out and/or bump_seed (including 8-byte alignment for seed if the VM has check_align set). *_ret unchanged. Compute budget decremented. diff --git a/src/flamenco/vm/syscall/fd_vm_syscall_cpi.c b/src/flamenco/vm/syscall/fd_vm_syscall_cpi.c index 9decb333e9..3ec43dc0b7 100644 --- a/src/flamenco/vm/syscall/fd_vm_syscall_cpi.c +++ b/src/flamenco/vm/syscall/fd_vm_syscall_cpi.c @@ -416,12 +416,12 @@ fd_vm_syscall_cpi_check_instruction( fd_vm_t const * vm, if( FD_UNLIKELY( data_sz > FD_CPI_MAX_INSTRUCTION_DATA_LEN ) ) { FD_LOG_WARNING(( "cpi: data too long (%#lx)", data_sz )); // SyscallError::MaxInstructionDataLenExceeded - return FD_VM_ERR_SYSCALL_MAX_INSTRUCTION_DATA_LEN_EXCEEDED; + return FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_DATA_LEN_EXCEEDED; } if( FD_UNLIKELY( acct_cnt > FD_CPI_MAX_INSTRUCTION_ACCOUNTS ) ) { FD_LOG_WARNING(( "cpi: too many accounts (%#lx)", acct_cnt )); // SyscallError::MaxInstructionAccountsExceeded - return FD_VM_ERR_SYSCALL_MAX_INSTRUCTION_ACCOUNTS_EXCEEDED; + return FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_ACCOUNTS_EXCEEDED; } } else { // https://github.com/solana-labs/solana/blob/dbf06e258ae418097049e845035d7d5502fe1327/programs/bpf_loader/src/syscalls/cpi.rs#L1114 @@ -429,7 +429,7 @@ fd_vm_syscall_cpi_check_instruction( fd_vm_t const * vm, if ( FD_UNLIKELY( tot_sz > FD_VM_MAX_CPI_INSTRUCTION_SIZE ) ) { FD_LOG_WARNING(( "cpi: instruction too long (%#lx)", tot_sz )); // SyscallError::InstructionTooLarge - return FD_VM_ERR_SYSCALL_INSTRUCTION_TOO_LARGE; + return FD_VM_SYSCALL_ERR_INSTRUCTION_TOO_LARGE; } } diff --git a/src/flamenco/vm/syscall/fd_vm_syscall_cpi_common.c b/src/flamenco/vm/syscall/fd_vm_syscall_cpi_common.c index 0d3caa9d06..59b869d35f 100644 --- a/src/flamenco/vm/syscall/fd_vm_syscall_cpi_common.c +++ b/src/flamenco/vm/syscall/fd_vm_syscall_cpi_common.c @@ -613,8 +613,8 @@ VM_SYSCALL_CPI_ENTRYPOINT( void * _vm, /* Right after translating, Agave checks against MAX_SIGNERS: https://github.com/solana-labs/solana/blob/dbf06e258ae418097049e845035d7d5502fe1327/programs/bpf_loader/src/syscalls/cpi.rs#L602 */ if( FD_UNLIKELY( signers_seeds_cnt > FD_CPI_MAX_SIGNER_CNT ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_TOO_MANY_SIGNERS ); - return FD_VM_ERR_SYSCALL_TOO_MANY_SIGNERS; + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_TOO_MANY_SIGNERS ); + return FD_VM_SYSCALL_ERR_TOO_MANY_SIGNERS; } for( ulong i=0UL; iinstr_ctx->slot_ctx, data, VM_SYSCALL_CPI_INSTR_DATA_LEN( cpi_instruction ) ) ) ) { - return FD_VM_ERR_PERM; + /* https://github.com/solana-labs/solana/blob/2afde1b028ed4593da5b6c735729d8994c4bfac6/programs/bpf_loader/src/syscalls/cpi.rs#L1054 */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_PROGRAM_NOT_SUPPORTED ); + return FD_VM_SYSCALL_ERR_PROGRAM_NOT_SUPPORTED; } /* Instruction checks ***********************************************/ @@ -691,8 +693,8 @@ VM_SYSCALL_CPI_ENTRYPOINT( void * _vm, https://github.com/anza-xyz/agave/blob/v2.1.0/programs/bpf_loader/src/syscalls/cpi.rs#L805-L814 */ ulong acc_info_total_sz = fd_ulong_sat_mul( acct_info_cnt, VM_SYSCALL_CPI_ACC_INFO_SIZE ); if( FD_UNLIKELY( vm->direct_mapping && fd_ulong_sat_add( acct_infos_va, acc_info_total_sz ) >= FD_VM_MEM_MAP_INPUT_REGION_START ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_INVALID_POINTER ); - return FD_VM_ERR_SYSCALL_INVALID_POINTER; + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_POINTER ); + return FD_VM_SYSCALL_ERR_INVALID_POINTER; } /* This is the equivalent of translate_slice in translate_account_infos: @@ -703,16 +705,16 @@ VM_SYSCALL_CPI_ENTRYPOINT( void * _vm, https://github.com/anza-xyz/agave/blob/838c1952595809a31520ff1603a13f2c9123aa51/programs/bpf_loader/src/syscalls/cpi.rs#L822 */ if( FD_FEATURE_ACTIVE( vm->instr_ctx->slot_ctx, loosen_cpi_size_restriction ) ) { if( FD_UNLIKELY( acct_info_cnt > get_cpi_max_account_infos( vm->instr_ctx->slot_ctx ) ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_MAX_INSTRUCTION_ACCOUNT_INFOS_EXCEEDED ); - return FD_VM_ERR_SYSCALL_MAX_INSTRUCTION_ACCOUNT_INFOS_EXCEEDED; + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_ACCOUNT_INFOS_EXCEEDED ); + return FD_VM_SYSCALL_ERR_MAX_INSTRUCTION_ACCOUNT_INFOS_EXCEEDED; } } else { ulong adjusted_len = fd_ulong_sat_mul( acct_info_cnt, sizeof( fd_pubkey_t ) ); if ( FD_UNLIKELY( adjusted_len > FD_VM_MAX_CPI_INSTRUCTION_SIZE ) ) { /* "Cap the number of account_infos a caller can pass to approximate maximum that accounts that could be passed in an instruction" */ - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_TOO_MANY_ACCOUNTS ); - return FD_VM_ERR_SYSCALL_TOO_MANY_ACCOUNTS; + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_TOO_MANY_ACCOUNTS ); + return FD_VM_SYSCALL_ERR_TOO_MANY_ACCOUNTS; } } @@ -728,11 +730,11 @@ VM_SYSCALL_CPI_ENTRYPOINT( void * _vm, ulong caller_lamports_l = 0UL; err = fd_instr_info_sum_account_lamports( vm->instr_ctx->instr, &caller_lamports_h, &caller_lamports_l ); - if ( FD_UNLIKELY( err ) ) return FD_VM_ERR_INSTR_ERR; + if ( FD_UNLIKELY( err ) ) return FD_VM_SYSCALL_ERR_INSTR_ERR; if( caller_lamports_h != vm->instr_ctx->instr->starting_lamports_h || caller_lamports_l != vm->instr_ctx->instr->starting_lamports_l ) { - return FD_VM_ERR_INSTR_ERR; + return FD_VM_SYSCALL_ERR_INSTR_ERR; } /* Set the transaction compute meter to be the same as the VM's compute meter, diff --git a/src/flamenco/vm/syscall/fd_vm_syscall_crypto.c b/src/flamenco/vm/syscall/fd_vm_syscall_crypto.c index d8f1fc6359..83fd468ef1 100644 --- a/src/flamenco/vm/syscall/fd_vm_syscall_crypto.c +++ b/src/flamenco/vm/syscall/fd_vm_syscall_crypto.c @@ -44,8 +44,8 @@ fd_vm_syscall_sol_alt_bn128_group_op( void * _vm, break; default: - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_INVALID_ATTRIBUTE ); - return FD_VM_ERR_INVAL; /* SyscallError::InvalidAttribute */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE ); + return FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE; /* SyscallError::InvalidAttribute */ } /* https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1551 */ @@ -125,8 +125,8 @@ fd_vm_syscall_sol_alt_bn128_compression( void * _vm, break; default: - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_INVALID_ATTRIBUTE ); - return FD_VM_ERR_INVAL; /* SyscallError::InvalidAttribute */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE ); + return FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE; /* SyscallError::InvalidAttribute */ } cost = fd_ulong_sat_add( cost, FD_VM_SYSCALL_BASE_COST ); @@ -207,8 +207,8 @@ fd_vm_syscall_sol_poseidon( void * _vm, /* https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1688 */ if( FD_UNLIKELY( params!=0UL ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_POSEIDON_INVALID_PARAMS ); - return FD_VM_ERR_INVAL; /* PoseidonSyscallError::InvalidParameters */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_POSEIDON_INVALID_PARAMS ); + return FD_VM_SYSCALL_ERR_POSEIDON_INVALID_PARAMS; /* PoseidonSyscallError::InvalidParameters */ } /* https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1689 */ @@ -217,8 +217,8 @@ fd_vm_syscall_sol_poseidon( void * _vm, endianness!=0UL /* Big endian */ && endianness!=1UL /* Little endian */ ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_POSEIDON_INVALID_ENDIANNESS ); - return FD_VM_ERR_INVAL; /* PoseidonSyscallError::InvalidEndianness */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_POSEIDON_INVALID_ENDIANNESS ); + return FD_VM_SYSCALL_ERR_POSEIDON_INVALID_ENDIANNESS; /* PoseidonSyscallError::InvalidEndianness */ } /* https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1691-L1698 */ @@ -227,8 +227,8 @@ fd_vm_syscall_sol_poseidon( void * _vm, /* Max msg_sz = 47 - 3 + 20 = 64 < 127 => we can use printf */ fd_log_collector_printf_dangerous_max_127( vm->instr_ctx, "Poseidon hashing %lu sequences is not supported", vals_len ); - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_INVALID_LENGTH ); - return FD_VM_ERR_INVAL; /* SyscallError::InvalidLength */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_LENGTH ); + return FD_VM_SYSCALL_ERR_INVALID_LENGTH; /* SyscallError::InvalidLength */ } /* https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1700-L1707 @@ -246,7 +246,7 @@ fd_vm_syscall_sol_poseidon( void * _vm, /* The following can never happen, left as comment for completeness. if( FD_UNLIKELY( cost == ULONG_MAX ) ) { fd_vm_log_append_printf( vm, "Overflow while calculating the compute cost" ); - return FD_VM_ERR_INVAL; // SyscallError::ArithmeticOverflow + return FD_VM_SYSCALL_ERR_ARITHMETIC_OVERFLOW; // SyscallError::ArithmeticOverflow } */ diff --git a/src/flamenco/vm/syscall/fd_vm_syscall_curve.c b/src/flamenco/vm/syscall/fd_vm_syscall_curve.c index ad7b81839e..792afea69d 100644 --- a/src/flamenco/vm/syscall/fd_vm_syscall_curve.c +++ b/src/flamenco/vm/syscall/fd_vm_syscall_curve.c @@ -35,8 +35,8 @@ fd_vm_syscall_sol_curve_validate_point( /**/ void * _vm, default: /* https://github.com/anza-xyz/agave/blob/5b3390b99a6e7665439c623062c1a1dda2803524/programs/bpf_loader/src/syscalls/mod.rs#L919-L928 */ if( FD_FEATURE_ACTIVE( (vm->instr_ctx->slot_ctx), abort_on_invalid_curve ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_INVALID_ATTRIBUTE ); - return FD_VM_ERR_INVAL; /* SyscallError::InvalidAttribute */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE ); + return FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE; /* SyscallError::InvalidAttribute */ } } @@ -227,7 +227,7 @@ fd_vm_syscall_sol_curve_group_op( void * _vm, default: /* COV: this can never happen because of the previous switch */ - return FD_VM_ERR_INVAL; /* SyscallError::InvalidAttribute */ + return FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE; /* SyscallError::InvalidAttribute */ } soft_error: @@ -240,8 +240,8 @@ fd_vm_syscall_sol_curve_group_op( void * _vm, invalid_error: /* https://github.com/anza-xyz/agave/blob/5b3390b99a6e7665439c623062c1a1dda2803524/programs/bpf_loader/src/syscalls/mod.rs#L1135-L1156 */ if( FD_FEATURE_ACTIVE( (vm->instr_ctx->slot_ctx), abort_on_invalid_curve ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_INVALID_ATTRIBUTE ); - return FD_VM_ERR_INVAL; /* SyscallError::InvalidAttribute */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE ); + return FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE; /* SyscallError::InvalidAttribute */ } *_ret = 1UL; return FD_VM_SUCCESS; @@ -352,8 +352,8 @@ fd_vm_syscall_sol_curve_multiscalar_mul( void * _vm, /* https://github.com/anza-xyz/agave/blob/v1.18.8/programs/bpf_loader/src/syscalls/mod.rs#L1143-L1151 */ if( FD_UNLIKELY( points_len > 512 ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_INVALID_LENGTH ); - return FD_VM_ERR_INVAL; /* SyscallError::InvalidLength */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_LENGTH ); + return FD_VM_SYSCALL_ERR_INVALID_LENGTH; /* SyscallError::InvalidLength */ } /* Note: we don't strictly follow the Rust implementation, but instead combine @@ -375,8 +375,8 @@ fd_vm_syscall_sol_curve_multiscalar_mul( void * _vm, default: /* https://github.com/anza-xyz/agave/blob/5b3390b99a6e7665439c623062c1a1dda2803524/programs/bpf_loader/src/syscalls/mod.rs#L1262-L1271 */ if( FD_FEATURE_ACTIVE( (vm->instr_ctx->slot_ctx), abort_on_invalid_curve ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_INVALID_ATTRIBUTE ); - return FD_VM_ERR_INVAL; /* SyscallError::InvalidAttribute */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE ); + return FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE; /* SyscallError::InvalidAttribute */ } goto soft_error; } @@ -436,7 +436,7 @@ fd_vm_syscall_sol_curve_multiscalar_mul( void * _vm, default: /* COV: this can never happen because of the previous switch */ - return FD_VM_ERR_INVAL; /* SyscallError::InvalidAttribute */ + return FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE; /* SyscallError::InvalidAttribute */ } soft_error: diff --git a/src/flamenco/vm/syscall/fd_vm_syscall_hash.c b/src/flamenco/vm/syscall/fd_vm_syscall_hash.c index 58845a63f7..c8b4f3379d 100644 --- a/src/flamenco/vm/syscall/fd_vm_syscall_hash.c +++ b/src/flamenco/vm/syscall/fd_vm_syscall_hash.c @@ -40,8 +40,8 @@ fd_vm_syscall_sol_sha256( /**/ void * _vm, fd_log_collector_printf_dangerous_max_127( vm->instr_ctx, "%s Hashing %lu sequences in one syscall is over the limit %lu", "Sha256", vals_len, FD_VM_SHA256_MAX_SLICES ); - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_TOO_MANY_SLICES ); - return FD_VM_ERR_INVAL; /* SyscallError::TooManySlices */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_TOO_MANY_SLICES ); + return FD_VM_SYSCALL_ERR_TOO_MANY_SLICES; /* SyscallError::TooManySlices */ } /* https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1922 */ @@ -97,8 +97,8 @@ fd_vm_syscall_sol_blake3( /**/ void * _vm, fd_log_collector_printf_dangerous_max_127( vm->instr_ctx, "%s Hashing %lu sequences in one syscall is over the limit %lu", "Blake3", vals_len, FD_VM_SHA256_MAX_SLICES ); - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_TOO_MANY_SLICES ); - return FD_VM_ERR_INVAL; /* SyscallError::TooManySlices */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_TOO_MANY_SLICES ); + return FD_VM_SYSCALL_ERR_TOO_MANY_SLICES; /* SyscallError::TooManySlices */ } /* https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1922 */ @@ -154,8 +154,8 @@ fd_vm_syscall_sol_keccak256( /**/ void * _vm, fd_log_collector_printf_dangerous_max_127( vm->instr_ctx, "%s Hashing %lu sequences in one syscall is over the limit %lu", "Keccak256", vals_len, FD_VM_SHA256_MAX_SLICES ); - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_TOO_MANY_SLICES ); - return FD_VM_ERR_INVAL; /* SyscallError::TooManySlices */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_TOO_MANY_SLICES ); + return FD_VM_SYSCALL_ERR_TOO_MANY_SLICES; /* SyscallError::TooManySlices */ } /* https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1922 */ diff --git a/src/flamenco/vm/syscall/fd_vm_syscall_pda.c b/src/flamenco/vm/syscall/fd_vm_syscall_pda.c index e52fbd5ccc..6c4611cb87 100644 --- a/src/flamenco/vm/syscall/fd_vm_syscall_pda.c +++ b/src/flamenco/vm/syscall/fd_vm_syscall_pda.c @@ -13,7 +13,7 @@ - an optional bump seed - out, the address in host address space where the PDA will be written to -If the derived PDA was not a valid ed25519 point, then this function will return FD_VM_ERR_INVALID_PDA. +If the derived PDA was not a valid ed25519 point, then this function will return FD_VM_SYSCALL_ERR_INVALID_PDA. The derivation can also fail because of an out-of-bounds memory access, or an invalid seed list. */ @@ -33,8 +33,8 @@ fd_vm_derive_pda( fd_vm_t * vm, also can't rely on just the second check because we need execution to halt. https://github.com/anza-xyz/agave/blob/v2.1.0/programs/bpf_loader/src/syscalls/mod.rs#L728-L730 */ if( FD_UNLIKELY( seeds_cnt>FD_VM_PDA_SEEDS_MAX ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_BAD_SEEDS ); - return FD_VM_ERR_INVAL; + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_BAD_SEEDS ); + return FD_VM_SYSCALL_ERR_BAD_SEEDS; } /* This check does NOT halt execution within `fd_vm_syscall_sol_try_find_program_address`. This means @@ -42,7 +42,7 @@ fd_vm_derive_pda( fd_vm_t * vm, this same check below will be hit 255 times and deduct that many CUs. Very strange... https://github.com/anza-xyz/agave/blob/v2.1.0/sdk/pubkey/src/lib.rs#L725-L727 */ if( FD_UNLIKELY( seeds_cnt+( !!bump_seed )>FD_VM_PDA_SEEDS_MAX ) ) { - return FD_VM_ERR_INVALID_PDA; + return FD_VM_SYSCALL_ERR_INVALID_PDA; } fd_sha256_init( vm->sha ); @@ -77,7 +77,7 @@ fd_vm_derive_pda( fd_vm_t * vm, /* A PDA is valid if it is not a valid ed25519 curve point. In most cases the user will have derived the PDA off-chain, or the PDA is a known signer. */ if( FD_UNLIKELY( fd_ed25519_point_validate( out->key ) ) ) { - return FD_VM_ERR_INVALID_PDA; + return FD_VM_SYSCALL_ERR_INVALID_PDA; } return FD_VM_SUCCESS; @@ -102,8 +102,8 @@ fd_vm_translate_and_check_program_address_inputs( fd_vm_t * vm, /* This is a preflight check that is performed in Agave before deriving PDAs but after checking the seeds vaddr. https://github.com/anza-xyz/agave/blob/v2.1.0/programs/bpf_loader/src/syscalls/mod.rs#L728-L730 */ if( FD_UNLIKELY( seeds_cnt>FD_VM_PDA_SEEDS_MAX ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_BAD_SEEDS ); - return FD_VM_ERR_INVAL; + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_BAD_SEEDS ); + return FD_VM_SYSCALL_ERR_BAD_SEEDS; } for( ulong i=0UL; iFD_VM_PDA_SEED_MEM_MAX ) ) { - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_BAD_SEEDS ); - return FD_VM_ERR_INVAL; + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_BAD_SEEDS ); + return FD_VM_SYSCALL_ERR_BAD_SEEDS; } void const * seed_haddr = FD_VM_MEM_SLICE_HADDR_LD( vm, untranslated_seeds[i].addr, FD_VM_ALIGN_RUST_U8, seed_sz ); out_seed_haddrs[ i ] = seed_haddr; @@ -189,7 +189,7 @@ fd_vm_syscall_sol_create_program_address( /**/ void * _vm, /* Place 1 in r0 and successfully exit if we failed to derive a PDA https://github.com/anza-xyz/agave/blob/v2.0.8/programs/bpf_loader/src/syscalls/mod.rs#L753 */ - if ( FD_LIKELY( err == FD_VM_ERR_INVALID_PDA ) ) { + if ( FD_LIKELY( err == FD_VM_SYSCALL_ERR_INVALID_PDA ) ) { *_ret = 1UL; return FD_VM_SUCCESS; } @@ -281,7 +281,7 @@ fd_vm_syscall_sol_try_find_program_address( void * _vm, *_ret = 0UL; return FD_VM_SUCCESS; - } else if( FD_UNLIKELY( err!=FD_VM_ERR_INVALID_PDA ) ) { + } else if( FD_UNLIKELY( err!=FD_VM_SYSCALL_ERR_INVALID_PDA ) ) { return err; } diff --git a/src/flamenco/vm/syscall/fd_vm_syscall_runtime.c b/src/flamenco/vm/syscall/fd_vm_syscall_runtime.c index 3262249041..81ea608e78 100644 --- a/src/flamenco/vm/syscall/fd_vm_syscall_runtime.c +++ b/src/flamenco/vm/syscall/fd_vm_syscall_runtime.c @@ -28,7 +28,7 @@ fd_vm_syscall_sol_get_clock_sysvar( /**/ void * _vm, a non-crashing way. */ fd_exec_instr_ctx_t const * instr_ctx = vm->instr_ctx; - if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_ERR_SIGCALL; + if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_SYSCALL_ERR_OUTSIDE_RUNTIME; FD_VM_CU_UPDATE( vm, fd_ulong_sat_add( FD_VM_SYSVAR_BASE_COST, FD_SOL_SYSVAR_CLOCK_FOOTPRINT ) ); @@ -64,7 +64,7 @@ fd_vm_syscall_sol_get_epoch_schedule_sysvar( /**/ void * _vm, a non-crashing way for the time being. */ fd_exec_instr_ctx_t const * instr_ctx = vm->instr_ctx; - if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_ERR_SIGCALL; + if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_SYSCALL_ERR_OUTSIDE_RUNTIME; FD_VM_CU_UPDATE( vm, fd_ulong_sat_add( FD_VM_SYSVAR_BASE_COST, FD_EPOCH_SCHEDULE_FOOTPRINT ) ); @@ -100,7 +100,7 @@ fd_vm_syscall_sol_get_fees_sysvar( /**/ void * _vm, a non-crashing way for the time being. */ fd_exec_instr_ctx_t const * instr_ctx = vm->instr_ctx; - if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_ERR_SIGCALL; + if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_SYSCALL_ERR_OUTSIDE_RUNTIME; FD_VM_CU_UPDATE( vm, fd_ulong_sat_add( FD_VM_SYSVAR_BASE_COST, FD_SYSVAR_FEES_FOOTPRINT ) ); @@ -136,7 +136,7 @@ fd_vm_syscall_sol_get_rent_sysvar( /**/ void * _vm, a non-crashing way for the time being. */ fd_exec_instr_ctx_t const * instr_ctx = vm->instr_ctx; - if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_ERR_SIGCALL; + if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_SYSCALL_ERR_OUTSIDE_RUNTIME; FD_VM_CU_UPDATE( vm, fd_ulong_sat_add( FD_VM_SYSVAR_BASE_COST, FD_RENT_FOOTPRINT ) ); @@ -170,7 +170,7 @@ fd_vm_syscall_sol_get_last_restart_slot_sysvar( /**/ void * _vm, fd_sol_sysvar_last_restart_slot_t * out = FD_VM_MEM_HADDR_ST( vm, out_vaddr, FD_VM_ALIGN_RUST_SYSVAR_LAST_RESTART_SLOT, FD_SOL_SYSVAR_LAST_RESTART_SLOT_FOOTPRINT ); if( FD_UNLIKELY( fd_sysvar_last_restart_slot_read( out, vm->instr_ctx->slot_ctx ) == NULL ) ) { - return FD_VM_ERR_ABORT; + return FD_VM_SYSCALL_ERR_ABORT; } *_ret = 0UL; @@ -204,7 +204,7 @@ fd_vm_syscall_sol_get_sysvar( /**/ void * _vm, int err = fd_int_if( __builtin_uaddl_overflow( offset, sz, &offset_length ), FD_EXECUTOR_INSTR_ERR_ARITHMETIC_OVERFLOW, FD_EXECUTOR_INSTR_SUCCESS ); if( FD_UNLIKELY( err ) ) { FD_VM_ERR_FOR_LOG_INSTR( vm, err ); - return FD_VM_ERR_ABORT; + return FD_VM_SYSCALL_ERR_ABORT; } /* https://github.com/anza-xyz/agave/blob/v2.1.0/programs/bpf_loader/src/syscalls/sysvar.rs#L210-L213 @@ -313,8 +313,14 @@ fd_vm_syscall_sol_get_return_data( /**/ void * _vm, FD_VM_CU_UPDATE( vm, FD_VM_SYSCALL_BASE_COST ); + /* FIXME: In the original version of this code, there was an FD_TEST + to check if the VM was attached to an instruction context (that + would have crashed anyway because of pointer chasing). If the VM + is being run outside the Solana runtime, it should never invoke + this syscall in the first place. So we treat this as a SIGCALL in + a non-crashing way for the time being. */ fd_exec_instr_ctx_t const * instr_ctx = vm->instr_ctx; - if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_ERR_SIGCALL; + if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_SYSCALL_ERR_OUTSIDE_RUNTIME; fd_txn_return_data_t const * return_data = &instr_ctx->txn_ctx->return_data; ulong return_data_sz = return_data->len; @@ -354,19 +360,24 @@ fd_vm_syscall_sol_set_return_data( /**/ void * _vm, /* https://github.com/anza-xyz/agave/blob/v2.0.8/programs/bpf_loader/src/syscalls/mod.rs#L1297 */ fd_vm_t * vm = (fd_vm_t *)_vm; + /* FIXME: In the original version of this code, there was an FD_TEST + to check if the VM was attached to an instruction context (that + would have crashed anyway because of pointer chasing). If the VM + is being run outside the Solana runtime, it should never invoke + this syscall in the first place. So we treat this as a SIGCALL in + a non-crashing way for the time being. */ fd_exec_instr_ctx_t const * instr_ctx = vm->instr_ctx; - if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_ERR_SIGCALL; + if( FD_UNLIKELY( !instr_ctx ) ) return FD_VM_SYSCALL_ERR_OUTSIDE_RUNTIME; FD_VM_CU_UPDATE( vm, fd_ulong_sat_add( FD_VM_SYSCALL_BASE_COST, src_sz / FD_VM_CPI_BYTES_PER_UNIT ) ); /* https://github.com/anza-xyz/agave/blob/v2.0.8/programs/bpf_loader/src/syscalls/mod.rs#L1316 */ if( FD_UNLIKELY( src_sz>FD_VM_RETURN_DATA_MAX ) ) { /* TODO: this is a bit annoying, we may want to unify return codes... - - FD_VM_ERR_SYSCALL_RETURN_DATA_TOO_LARGE is Agave's return code, - also used for logging - - FD_VM_ERR_RETURN_DATA_TOO_LARGE is Firedancer return code */ - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_RETURN_DATA_TOO_LARGE ); - return FD_VM_ERR_RETURN_DATA_TOO_LARGE; + - FD_VM_SYSCALL_ERR_RETURN_DATA_TOO_LARGE is Agave's return code, + also used for logging */ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_RETURN_DATA_TOO_LARGE ); + return FD_VM_SYSCALL_ERR_RETURN_DATA_TOO_LARGE; } /* src_sz == 0 is ok */ diff --git a/src/flamenco/vm/syscall/fd_vm_syscall_util.c b/src/flamenco/vm/syscall/fd_vm_syscall_util.c index b83e4ab95f..5f5cbb2394 100644 --- a/src/flamenco/vm/syscall/fd_vm_syscall_util.c +++ b/src/flamenco/vm/syscall/fd_vm_syscall_util.c @@ -20,8 +20,8 @@ fd_vm_syscall_abort( FD_PARAM_UNUSED void * _vm, FD_PARAM_UNUSED ulong * _ret ) { /* https://github.com/anza-xyz/agave/blob/v2.0.6/programs/bpf_loader/src/syscalls/mod.rs#L630 */ fd_vm_t * vm = (fd_vm_t *)_vm; - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_ABORT ); - return FD_VM_ERR_ABORT; + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_ABORT ); + return FD_VM_SYSCALL_ERR_ABORT; } /* FD_TRANSLATE_STRING returns a read only pointer to the host address of @@ -34,8 +34,8 @@ fd_vm_syscall_abort( FD_PARAM_UNUSED void * _vm, #define FD_TRANSLATE_STRING( vm, vaddr, msg_sz ) (__extension__({ \ char const * msg = FD_VM_MEM_SLICE_HADDR_LD( vm, vaddr, FD_VM_ALIGN_RUST_U8, msg_sz ); \ if( FD_UNLIKELY( !fd_utf8_verify( msg, msg_sz ) ) ) { \ - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_INVALID_STRING ); \ - return FD_VM_ERR_SYSCALL_INVALID_STRING; \ + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_INVALID_STRING ); \ + return FD_VM_SYSCALL_ERR_INVALID_STRING; \ } \ msg; \ })) @@ -66,8 +66,8 @@ fd_vm_syscall_sol_panic( /**/ void * _vm, (void)line; (void)column; - FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_ERR_SYSCALL_PANIC ); - return FD_VM_ERR_PANIC; + FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_PANIC ); + return FD_VM_SYSCALL_ERR_PANIC; } int @@ -84,7 +84,8 @@ fd_vm_syscall_sol_log( /**/ void * _vm, FD_VM_CU_UPDATE( vm, fd_ulong_max( msg_sz, FD_VM_SYSCALL_BASE_COST ) ); - /* Note: when msg_sz==0, msg can be undefined. fd_log_collector_program_log() handles it. */ + /* Note: when msg_sz==0, msg can be undefined. fd_log_collector_program_log() handles it. + FIXME: Macro invocation in function invocation? */ fd_log_collector_program_log( vm->instr_ctx, FD_TRANSLATE_STRING( vm, msg_vaddr, msg_sz ), msg_sz ); *_ret = 0UL; @@ -153,7 +154,7 @@ fd_vm_syscall_sol_log_pubkey( /**/ void * _vm, char msg[ FD_BASE58_ENCODED_32_SZ ]; ulong msg_sz; if( FD_UNLIKELY( fd_base58_encode_32( pubkey, &msg_sz, msg )==NULL ) ) { - return FD_VM_ERR_INVAL; + return FD_VM_SYSCALL_ERR_INVALID_STRING; } fd_log_collector_program_log( vm->instr_ctx, msg, msg_sz ); @@ -381,7 +382,7 @@ fd_vm_memmove( fd_vm_t * vm, FD_VM_MEM_HADDR_AND_REGION_IDX_FROM_INPUT_REGION_CHECKED( vm, dst_offset, dst_region_idx, dst_haddr ); if( FD_UNLIKELY( !vm->input_mem_regions[ dst_region_idx ].is_writable ) ) { FD_VM_ERR_FOR_LOG_EBPF( vm, FD_VM_ERR_EBPF_ACCESS_VIOLATION ); - return FD_VM_ERR_SIGSEGV; + return FD_VM_SYSCALL_ERR_SEGFAULT; } if( FD_UNLIKELY( reverse ) ) { /* Bytes remaining between region begin and current position (+ 1 for inclusive region beginning). */ @@ -471,7 +472,7 @@ fd_vm_memmove( fd_vm_t * vm, dst_haddr = (uchar*)vm->input_mem_regions[ dst_region_idx ].haddr + vm->input_mem_regions[ dst_region_idx ].region_sz - 1UL; } else { FD_VM_ERR_FOR_LOG_EBPF( vm, FD_VM_ERR_EBPF_ACCESS_VIOLATION ); - return FD_VM_ERR_SIGSEGV; + return FD_VM_SYSCALL_ERR_SEGFAULT; } dst_bytes_rem_in_cur_region = vm->input_mem_regions[ dst_region_idx ].region_sz; } @@ -488,7 +489,7 @@ fd_vm_memmove( fd_vm_t * vm, src_haddr = (uchar*)vm->input_mem_regions[ src_region_idx ].haddr + vm->input_mem_regions[ src_region_idx ].region_sz - 1UL; } else { FD_VM_ERR_FOR_LOG_EBPF( vm, FD_VM_ERR_EBPF_ACCESS_VIOLATION ); - return FD_VM_ERR_SIGSEGV; + return FD_VM_SYSCALL_ERR_SEGFAULT; } src_bytes_rem_in_cur_region = vm->input_mem_regions[ src_region_idx ].region_sz; } @@ -694,7 +695,7 @@ fd_vm_syscall_sol_memcmp( /**/ void * _vm, an access violation. */ if( FD_UNLIKELY( m0_region!=4UL || ++m0_region_idx>=vm->input_mem_regions_cnt ) ) { FD_VM_ERR_FOR_LOG_EBPF( vm, FD_VM_ERR_EBPF_ACCESS_VIOLATION ); - return FD_VM_ERR_SIGSEGV; + return FD_VM_SYSCALL_ERR_SEGFAULT; } /* Otherwise, query the next input region. */ m0_haddr = (uchar*)vm->input_mem_regions[ m0_region_idx ].haddr; @@ -704,7 +705,7 @@ fd_vm_syscall_sol_memcmp( /**/ void * _vm, if( FD_UNLIKELY( !m1_bytes_in_cur_region ) ) { if( FD_UNLIKELY( m1_region!=4UL || ++m1_region_idx>=vm->input_mem_regions_cnt ) ) { FD_VM_ERR_FOR_LOG_EBPF( vm, FD_VM_ERR_EBPF_ACCESS_VIOLATION ); - return FD_VM_ERR_SIGSEGV; + return FD_VM_SYSCALL_ERR_SEGFAULT; } m1_haddr = (uchar*)vm->input_mem_regions[ m1_region_idx ].haddr; m1_idx = 0UL; @@ -766,7 +767,7 @@ fd_vm_syscall_sol_memset( /**/ void * _vm, fd_memset( haddr, b, bytes_to_set ); if( FD_UNLIKELY( bytes_to_set0 ) ) { FD_VM_ERR_FOR_LOG_EBPF( vm, FD_VM_ERR_EBPF_ACCESS_VIOLATION ); - return FD_VM_ERR_SIGSEGV; + return FD_VM_SYSCALL_ERR_SEGFAULT; } } return FD_VM_SUCCESS; diff --git a/src/flamenco/vm/syscall/test_vm_syscall_curve.c b/src/flamenco/vm/syscall/test_vm_syscall_curve.c index 754420c3b3..3d73846899 100644 --- a/src/flamenco/vm/syscall/test_vm_syscall_curve.c +++ b/src/flamenco/vm/syscall/test_vm_syscall_curve.c @@ -120,7 +120,7 @@ main( int argc, 0UL, // point_cnt result_point_vaddr, 0UL, // ret_code - FD_VM_ERR_SIGSEGV, // syscall_ret + FD_VM_SYSCALL_ERR_SEGFAULT, // syscall_ret expected_result_host_ptr ) ); @@ -134,7 +134,7 @@ main( int argc, 513UL, // point_cnt result_point_vaddr, 0UL, // ret_code - FD_VM_ERR_INVAL, // syscall_ret + FD_VM_SYSCALL_ERR_INVALID_LENGTH, // syscall_ret expected_result_host_ptr ) ); @@ -148,7 +148,7 @@ main( int argc, 2UL, // point_cnt result_point_vaddr, 0UL, // ret_code - FD_VM_ERR_INVAL, // syscall_ret + FD_VM_SYSCALL_ERR_INVALID_ATTRIBUTE, // syscall_ret expected_result_host_ptr ) ); diff --git a/src/flamenco/vm/syscall/test_vm_syscalls.c b/src/flamenco/vm/syscall/test_vm_syscalls.c index f20b83545d..236c542f60 100644 --- a/src/flamenco/vm/syscall/test_vm_syscalls.c +++ b/src/flamenco/vm/syscall/test_vm_syscalls.c @@ -266,7 +266,7 @@ main( int argc, 0UL, 0UL, 100UL, - 0UL, FD_VM_ERR_SIGSEGV ); + 0UL, FD_VM_SYSCALL_ERR_SEGFAULT ); test_vm_syscall_toggle_direct_mapping( vm, 1 ); /* enable direct mapping */ @@ -293,7 +293,7 @@ main( int argc, 0UL, 0UL, 100UL, - 0UL, FD_VM_ERR_SIGSEGV ); + 0UL, FD_VM_SYSCALL_ERR_SEGFAULT ); test_vm_syscall_sol_memset( "test_vm_syscall_sol_memset: memset across multiple input mem regions", vm, @@ -318,7 +318,7 @@ main( int argc, (ulong)&input + 50UL, 1UL, 800UL, - 0UL, FD_VM_ERR_EBPF_ACCESS_VIOLATION ); + 0UL, FD_VM_SYSCALL_ERR_SEGFAULT ); input_mem_regions[2].is_writable=1; @@ -351,7 +351,7 @@ main( int argc, (ulong)&vm->heap[0], (ulong)&vm->rodata[0], 100UL, - 0UL, FD_VM_ERR_SIGSEGV ); + 0UL, FD_VM_SYSCALL_ERR_SEGFAULT ); // test we cannot copy more than the available size from the read-only region test_vm_syscall_sol_memcpy( "test_vm_syscall_sol_memcpy: memcpy from read only region to heap region", @@ -361,7 +361,7 @@ main( int argc, (ulong)&vm->rodata[0], (ulong)&vm->heap[0], rodata_sz + 1UL, - 0UL, FD_VM_ERR_SIGSEGV ); + 0UL, FD_VM_SYSCALL_ERR_SEGFAULT ); // test we cannot copy overlapping regions in heap where src is before dst test_vm_syscall_sol_memcpy( "test_vm_syscall_sol_memcpy: memcpy overlapping regions in heap - src before dst", @@ -371,7 +371,7 @@ main( int argc, (ulong)&vm->heap[0], (ulong)&vm->heap[10], 100UL, - 0UL, FD_VM_ERR_MEM_OVERLAP ); + 0UL, FD_VM_SYSCALL_ERR_COPY_OVERLAPPING ); // test we cannot copy overlapping regions in heap where src is after dst test_vm_syscall_sol_memcpy( "test_vm_syscall_sol_memcpy: memcpy overlapping regions in heap - src after dst", @@ -381,7 +381,7 @@ main( int argc, (ulong)&vm->heap[10], (ulong)&vm->heap[0], 100UL, - 0UL, FD_VM_ERR_MEM_OVERLAP ); + 0UL, FD_VM_SYSCALL_ERR_COPY_OVERLAPPING ); test_vm_syscall_toggle_direct_mapping( vm, 1 ); /* enable direct mapping */ @@ -412,7 +412,7 @@ main( int argc, (ulong)&vm->heap[0], (ulong)&vm->rodata[0], 100UL, - 0UL, FD_VM_ERR_SIGSEGV ); + 0UL, FD_VM_SYSCALL_ERR_SEGFAULT ); // test we cannot copy more than the available size from the read-only region test_vm_syscall_sol_memcpy( "test_vm_syscall_sol_memcpy: memcpy from read only region to heap region", @@ -422,7 +422,7 @@ main( int argc, (ulong)&vm->rodata[0], (ulong)&vm->heap[0], rodata_sz + 1UL, - 0UL, FD_VM_ERR_SIGSEGV ); + 0UL, FD_VM_SYSCALL_ERR_SEGFAULT ); // test we cannot copy overlapping regions in heap where src is before dst test_vm_syscall_sol_memcpy( "test_vm_syscall_sol_memcpy: memcpy overlapping regions in heap - src before dst", @@ -432,7 +432,7 @@ main( int argc, (ulong)&vm->heap[0], (ulong)&vm->heap[10], 100UL, - 0UL, FD_VM_ERR_MEM_OVERLAP ); + 0UL, FD_VM_SYSCALL_ERR_COPY_OVERLAPPING ); // test we cannot copy overlapping regions in heap where src is after dst test_vm_syscall_sol_memcpy( "test_vm_syscall_sol_memcpy: memcpy overlapping regions in heap - src after dst", @@ -442,7 +442,7 @@ main( int argc, (ulong)&vm->heap[10], (ulong)&vm->heap[0], 100UL, - 0UL, FD_VM_ERR_MEM_OVERLAP ); + 0UL, FD_VM_SYSCALL_ERR_COPY_OVERLAPPING ); test_vm_syscall_sol_memcpy( "test_vm_syscall_sol_memcpy: memcpy in input (single region)", vm, @@ -460,7 +460,7 @@ main( int argc, vm->input_mem_regions[0].haddr + 80UL, vm->input_mem_regions[0].haddr + 120UL, 50UL, - 0UL, FD_VM_ERR_MEM_OVERLAP ); + 0UL, FD_VM_SYSCALL_ERR_COPY_OVERLAPPING ); test_vm_syscall_sol_memcpy( "test_vm_syscall_sol_memcpy: memcpy in input multiple regions", vm, @@ -478,7 +478,7 @@ main( int argc, vm->input_mem_regions[0].haddr + 50UL, vm->input_mem_regions[0].haddr + 450UL, 500UL, - 0UL, FD_VM_ERR_MEM_OVERLAP ); + 0UL, FD_VM_SYSCALL_ERR_COPY_OVERLAPPING ); test_vm_syscall_toggle_direct_mapping( vm, 0 ); /* disable direct mapping */ @@ -521,7 +521,7 @@ main( int argc, (ulong)&vm->heap[0], (ulong)&vm->rodata[0], 100UL, - 0UL, FD_VM_ERR_SIGSEGV ); + 0UL, FD_VM_SYSCALL_ERR_SEGFAULT ); test_vm_syscall_toggle_direct_mapping( vm, 1 ); /* enable direct mapping */ @@ -563,7 +563,7 @@ main( int argc, (ulong)&vm->heap[0], (ulong)&vm->rodata[0], 100UL, - 0UL, FD_VM_ERR_SIGSEGV ); + 0UL, FD_VM_SYSCALL_ERR_SEGFAULT ); test_vm_syscall_sol_memmove( "test_vm_syscall_sol_memmove: memmove in input (single region)", @@ -636,7 +636,7 @@ main( int argc, (ulong)&vm->rodata[100], (ulong)&vm->rodata[200], 100UL, - 0UL, FD_VM_ERR_SIGSEGV ); + 0UL, FD_VM_SYSCALL_ERR_SEGFAULT ); memset( (void*)input_mem_regions[0].haddr, 0xFF, 400UL ); test_vm_syscall_sol_memcmp( "test_vm_syscall_sol_memcmp: memcmp input region equal", diff --git a/src/flamenco/vm/test_vm_base.c b/src/flamenco/vm/test_vm_base.c index 988616372f..3fe638cb8c 100644 --- a/src/flamenco/vm/test_vm_base.c +++ b/src/flamenco/vm/test_vm_base.c @@ -28,15 +28,10 @@ FD_STATIC_ASSERT( FD_VM_ERR_SIGSEGV ==-13, vm_err ); FD_STATIC_ASSERT( FD_VM_ERR_SIGBUS ==-14, vm_err ); FD_STATIC_ASSERT( FD_VM_ERR_SIGRDONLY ==-15, vm_err ); FD_STATIC_ASSERT( FD_VM_ERR_SIGCOST ==-16, vm_err ); -FD_STATIC_ASSERT( FD_VM_ERR_INVALID_PDA ==-17, vm_err ); FD_STATIC_ASSERT( FD_VM_ERR_SIGFPE ==-18, vm_err ); - -FD_STATIC_ASSERT( FD_VM_ERR_ABORT ==-19, vm_err ); -FD_STATIC_ASSERT( FD_VM_ERR_PANIC ==-20, vm_err ); -FD_STATIC_ASSERT( FD_VM_ERR_MEM_OVERLAP ==-21, vm_err ); -FD_STATIC_ASSERT( FD_VM_ERR_INSTR_ERR ==-22, vm_err ); -FD_STATIC_ASSERT( FD_VM_ERR_INVOKE_CONTEXT_BORROW_FAILED==-23, vm_err ); -FD_STATIC_ASSERT( FD_VM_ERR_RETURN_DATA_TOO_LARGE ==-24, vm_err ); +FD_STATIC_ASSERT( FD_VM_ERR_SIGFPE_OF ==-19, vm_err ); +FD_STATIC_ASSERT( FD_VM_ERR_SIGSYSCALL ==-20, vm_err ); +FD_STATIC_ASSERT( FD_VM_ERR_SIGABORT ==-21, vm_err ); FD_STATIC_ASSERT( FD_VM_ERR_INVALID_OPCODE ==-25, vm_err ); FD_STATIC_ASSERT( FD_VM_ERR_INVALID_SRC_REG ==-26, vm_err ); @@ -153,13 +148,6 @@ main( int argc, TEST( FD_VM_ERR_SIGRDONLY ); TEST( FD_VM_ERR_SIGCOST ); - TEST( FD_VM_ERR_ABORT ); - TEST( FD_VM_ERR_PANIC ); - TEST( FD_VM_ERR_MEM_OVERLAP ); - TEST( FD_VM_ERR_INSTR_ERR ); - TEST( FD_VM_ERR_INVOKE_CONTEXT_BORROW_FAILED ); - TEST( FD_VM_ERR_RETURN_DATA_TOO_LARGE ); - TEST( FD_VM_ERR_INVALID_OPCODE ); TEST( FD_VM_ERR_INVALID_SRC_REG ); TEST( FD_VM_ERR_INVALID_DST_REG );