Skip to content

Commit

Permalink
flamenco, vm: (syscall err refactor part 2) refactor vm syscall macros
Browse files Browse the repository at this point in the history
  • Loading branch information
ravyu-jump committed Dec 6, 2024
1 parent 49f5f14 commit 9d3fe0c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
3 changes: 0 additions & 3 deletions src/flamenco/vm/fd_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ fd_vm_strerror( int err ) {
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 */

/* VM validate error codes */

case FD_VM_ERR_INVALID_OPCODE: return "INVALID_OPCODE detected an invalid opcode";
Expand Down
12 changes: 6 additions & 6 deletions src/flamenco/vm/fd_vm_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
/* (DEPRECATED) VM syscall error codes. These are only produced by fd_vm_syscall
implementations. */

// #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 */
// #define FD_VM_ERR_ABORT (-119) /* FIXME: description */
// #define FD_VM_ERR_PANIC (-120) /* FIXME: description */
// #define FD_VM_ERR_MEM_OVERLAP (-121) /* 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 */

/* sBPF validation error codes. These are only produced by
fd_vm_validate. FIXME: Consider having fd_vm_validate return
Expand Down
36 changes: 18 additions & 18 deletions src/flamenco/vm/fd_vm_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ FD_PROTOTYPES_BEGIN
/* FD_VM_CU_UPDATE charges the vm cost compute units.
If the vm does not have more than cost cu available, this will cause
the caller to zero out the vm->cu and return with FD_VM_ERR_SIGCOST.
the caller to zero out the vm->cu and return with FD_VM_SYSCALL_ERR_COMPUTE_BUDGET_EXCEEDED.
This macro is robust.
This is meant to be used by syscall implementations and strictly
conforms with the vm-syscall ABI interface.
Note: in Agave a syscall can return success leaving 0 available CUs.
The instruction will fail at the next instruction (e.g., exit).
To reproduce the same behavior, we do not return FD_VM_ERR_SIGCOST
To reproduce the same behavior, we do not return FD_VM_SYSCALL_ERR_COMPUTE_BUDGET_EXCEEDED
when cu == 0.
FD_VM_CU_MEM_UPDATE charges the vm the equivalent of sz bytes of
Expand All @@ -157,7 +157,7 @@ FD_PROTOTYPES_BEGIN
if( FD_UNLIKELY( _cost>_cu ) ) { \
_vm->cu = 0UL; \
FD_VM_ERR_FOR_LOG_INSTR( vm, FD_EXECUTOR_INSTR_ERR_COMPUTE_BUDGET_EXCEEDED ); \
return FD_VM_ERR_SIGCOST; \
return FD_VM_SYSCALL_ERR_COMPUTE_BUDGET_EXCEEDED; \
} \
_vm->cu = _cu - _cost; \
}))
Expand Down Expand Up @@ -533,7 +533,7 @@ static inline void fd_vm_mem_st_8( fd_vm_t const * vm,
If the virtual address range cannot be mapped to the host address
space completely and/or (when applicable) vaddr is not appropriately
aligned, this will cause the caller to return FD_VM_ERR_SIGSEGV.
aligned, this will cause the caller to return FD_VM_SYSCALL_ERR_SEGFAULT.
This macro is robust. This is meant to be used by syscall
implementations and strictly conforms with the vm-syscall ABI
interface.
Expand Down Expand Up @@ -567,15 +567,15 @@ static inline void fd_vm_mem_st_8( fd_vm_t const * vm,
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_SYSCALL_ERR_INVALID_LENGTH ); \
return FD_VM_ERR_SIGSEGV; \
return FD_VM_SYSCALL_ERR_SEGFAULT; \
} \
if( FD_UNLIKELY( (!_haddr) | _is_multi) ) { \
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( _sigbus ) ) { \
FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_SYSCALL_ERR_UNALIGNED_POINTER ); \
return FD_VM_ERR_SIGSEGV; \
return FD_VM_SYSCALL_ERR_SEGFAULT; \
} \
(void const *)_haddr; \
}))
Expand All @@ -602,17 +602,17 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int
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_SYSCALL_ERR_INVALID_LENGTH );
*err = FD_VM_ERR_SIGSEGV;
*err = FD_VM_SYSCALL_ERR_SEGFAULT;
return 0;
}
if( FD_UNLIKELY( (!_haddr) | _is_multi) ) {
FD_VM_ERR_FOR_LOG_EBPF( _vm, FD_VM_ERR_EBPF_ACCESS_VIOLATION );
*err = FD_VM_ERR_SIGSEGV;
*err = FD_VM_SYSCALL_ERR_SEGFAULT;
return 0;
}
if ( FD_UNLIKELY( _sigbus ) ) {
FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_SYSCALL_ERR_UNALIGNED_POINTER );
*err = FD_VM_ERR_SIGSEGV;
*err = FD_VM_SYSCALL_ERR_SEGFAULT;
return 0;
}
return (void *)_haddr;
Expand Down Expand Up @@ -642,15 +642,15 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int
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_SYSCALL_ERR_INVALID_LENGTH ); \
return FD_VM_ERR_SIGSEGV; \
return FD_VM_SYSCALL_ERR_SEGFAULT; \
} \
if( FD_UNLIKELY( (!_haddr) | _is_multi ) ) { \
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( _sigbus ) ) { \
FD_VM_ERR_FOR_LOG_SYSCALL( _vm, FD_VM_SYSCALL_ERR_UNALIGNED_POINTER ); \
return FD_VM_ERR_SIGSEGV; \
return FD_VM_SYSCALL_ERR_SEGFAULT; \
} \
(void *)_haddr; \
}))
Expand All @@ -674,7 +674,7 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int
_out_region_idx = fd_vm_get_input_mem_region_idx( _vm, _offset ); \
if( FD_UNLIKELY( _offset>=vm->input_mem_regions[ _out_region_idx ].vaddr_offset+vm->input_mem_regions[ _out_region_idx ].region_sz ) ) { \
FD_VM_ERR_FOR_LOG_EBPF( vm, FD_VM_ERR_EBPF_ACCESS_VIOLATION ); \
return FD_VM_ERR_SIGSEGV; \
return FD_VM_SYSCALL_ERR_SEGFAULT; \
} \
_out_haddr = (uchar*)_vm->input_mem_regions[ _out_region_idx ].haddr + _offset - _vm->input_mem_regions[ _out_region_idx ].vaddr_offset; \
}))
Expand All @@ -699,7 +699,7 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int
#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_SYSCALL_ERR_INVALID_LENGTH ); \
return FD_VM_ERR_INVAL; \
return FD_VM_SYSCALL_ERR_INVALID_LENGTH; \
} \
void const * haddr = 0UL; \
if ( FD_LIKELY( (ulong)sz > 0UL ) ) { \
Expand All @@ -714,7 +714,7 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int
#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_SYSCALL_ERR_INVALID_LENGTH ); \
return FD_VM_ERR_INVAL; \
return FD_VM_SYSCALL_ERR_INVALID_LENGTH; \
} \
void const * haddr = 0UL; \
if ( FD_LIKELY( (ulong)sz > 0UL ) ) { \
Expand All @@ -726,7 +726,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_SYSCALL_ERR_INVALID_LENGTH ); \
return FD_VM_ERR_INVAL; \
return FD_VM_SYSCALL_ERR_INVALID_LENGTH; \
} \
void * haddr = 0UL; \
if ( FD_LIKELY( (ulong)sz > 0UL ) ) { \
Expand All @@ -740,7 +740,7 @@ FD_VM_MEM_HADDR_ST_( fd_vm_t const *vm, ulong vaddr, ulong align, ulong sz, int
if( FD_UNLIKELY( ((vaddr0> vaddr1) && ((vaddr0-vaddr1)<sz1)) || \
((vaddr1>=vaddr0) && ((vaddr1-vaddr0)<sz0)) ) ) { \
FD_VM_ERR_FOR_LOG_SYSCALL( vm, FD_VM_SYSCALL_ERR_COPY_OVERLAPPING ); \
return FD_VM_ERR_MEM_OVERLAP; \
return FD_VM_SYSCALL_ERR_COPY_OVERLAPPING; \
} \
} while(0)

Expand Down

0 comments on commit 9d3fe0c

Please sign in to comment.