Line data Source code
1 : #include "fd_vm_syscall.h"
2 : #include "../../../ballet/murmur3/fd_murmur3.h"
3 :
4 : int
5 : fd_vm_syscall_register( fd_sbpf_syscalls_t * syscalls,
6 : char const * name,
7 675837 : fd_sbpf_syscall_func_t func ) {
8 675837 : if( FD_UNLIKELY( (!syscalls) | (!name) ) ) return FD_VM_ERR_INVAL;
9 :
10 675837 : fd_sbpf_syscalls_t * syscall = fd_sbpf_syscalls_insert( syscalls, (ulong)fd_murmur3_32( name, strlen( name ), 0U ) );
11 675837 : if( FD_UNLIKELY( !syscall ) ) return FD_VM_ERR_INVAL; /* name (or hash of name) already in map */
12 :
13 675837 : syscall->func = func;
14 675837 : syscall->name = name;
15 :
16 675837 : return FD_VM_SUCCESS;
17 675837 : }
18 :
19 : int
20 : fd_vm_syscall_register_slot( fd_sbpf_syscalls_t * syscalls,
21 : ulong slot,
22 : fd_features_t const * features,
23 17701 : uchar is_deploy ) {
24 17701 : if( FD_UNLIKELY( !syscalls ) ) return FD_VM_ERR_INVAL;
25 :
26 17701 : int enable_get_sysvar_syscall = 0;
27 17701 : int enable_get_epoch_stake_syscall = 0;
28 17701 : int enable_sha512_syscall = 0;
29 17701 : int enable_big_mod_exp_syscall = 0;
30 :
31 17701 : if( features ) {
32 10192 : enable_get_sysvar_syscall = FD_FEATURE_ACTIVE( slot, features, get_sysvar_syscall_enabled );
33 10192 : enable_get_epoch_stake_syscall = FD_FEATURE_ACTIVE( slot, features, enable_get_epoch_stake_syscall );
34 10192 : enable_sha512_syscall = FD_FEATURE_ACTIVE( slot, features, enable_sha512_syscall );
35 10192 : enable_big_mod_exp_syscall = FD_FEATURE_ACTIVE( slot, features, enable_big_mod_exp_syscall );
36 :
37 10192 : } else { /* enable ALL */
38 :
39 7509 : enable_get_sysvar_syscall = 1;
40 7509 : enable_get_epoch_stake_syscall = 1;
41 7509 : enable_sha512_syscall = 1;
42 7509 : enable_big_mod_exp_syscall = 1;
43 :
44 7509 : }
45 :
46 17701 : fd_sbpf_syscalls_clear( syscalls );
47 :
48 17701 : ulong syscall_cnt = 0UL;
49 :
50 687158 : # define REGISTER(name,func) do { \
51 687158 : if( FD_UNLIKELY( syscall_cnt>=fd_sbpf_syscalls_key_max() ) ) return FD_VM_ERR_FULL; \
52 687158 : int _err = fd_vm_syscall_register( syscalls, (name), (func) ); \
53 687158 : if( FD_UNLIKELY( _err ) ) return _err; \
54 687158 : syscall_cnt++; \
55 687158 : } while(0)
56 :
57 : /* https://github.com/anza-xyz/agave/blob/v2.2.20/programs/bpf_loader/src/syscalls/mod.rs#L392-L396 */
58 :
59 17701 : REGISTER( "abort", fd_vm_syscall_abort );
60 17701 : REGISTER( "sol_panic_", fd_vm_syscall_sol_panic );
61 :
62 : /* As of the activation of disable_deploy_of_alloc_free_syscall, which is activated on all networks,
63 : programs can no longer be deployed which use the sol_alloc_free_ syscall.
64 :
65 : https://github.com/anza-xyz/agave/blob/d6041c002bbcf1526de4e38bc18fa6e781c380e7/programs/bpf_loader/src/syscalls/mod.rs#L429 */
66 17701 : if ( FD_LIKELY( !is_deploy ) ) {
67 16987 : REGISTER( "sol_alloc_free_", fd_vm_syscall_sol_alloc_free );
68 16987 : }
69 :
70 : /* https://github.com/solana-labs/solana/blob/v1.18.1/sdk/program/src/syscalls/definitions.rs#L39 */
71 :
72 17701 : REGISTER( "sol_log_", fd_vm_syscall_sol_log );
73 17701 : REGISTER( "sol_log_64_", fd_vm_syscall_sol_log_64 );
74 17701 : REGISTER( "sol_log_compute_units_", fd_vm_syscall_sol_log_compute_units );
75 17701 : REGISTER( "sol_log_pubkey", fd_vm_syscall_sol_log_pubkey );
76 17701 : REGISTER( "sol_create_program_address", fd_vm_syscall_sol_create_program_address );
77 17701 : REGISTER( "sol_try_find_program_address", fd_vm_syscall_sol_try_find_program_address );
78 17701 : REGISTER( "sol_sha256", fd_vm_syscall_sol_sha256 );
79 17701 : REGISTER( "sol_keccak256", fd_vm_syscall_sol_keccak256 );
80 17701 : REGISTER( "sol_secp256k1_recover", fd_vm_syscall_sol_secp256k1_recover );
81 :
82 17701 : if( enable_sha512_syscall )
83 7654 : REGISTER( "sol_sha512", fd_vm_syscall_sol_sha512 );
84 :
85 17701 : REGISTER( "sol_get_clock_sysvar", fd_vm_syscall_sol_get_clock_sysvar );
86 17701 : REGISTER( "sol_get_epoch_schedule_sysvar", fd_vm_syscall_sol_get_epoch_schedule_sysvar );
87 :
88 17701 : REGISTER( "sol_get_rent_sysvar", fd_vm_syscall_sol_get_rent_sysvar );
89 :
90 17701 : REGISTER( "sol_get_last_restart_slot", fd_vm_syscall_sol_get_last_restart_slot_sysvar );
91 :
92 17712 : if( enable_get_sysvar_syscall ) {
93 17712 : REGISTER( "sol_get_sysvar", fd_vm_syscall_sol_get_sysvar );
94 17712 : }
95 :
96 17719 : if( enable_get_epoch_stake_syscall ) {
97 17719 : REGISTER( "sol_get_epoch_stake", fd_vm_syscall_sol_get_epoch_stake );
98 17719 : }
99 :
100 17701 : REGISTER( "sol_memcpy_", fd_vm_syscall_sol_memcpy );
101 17701 : REGISTER( "sol_memmove_", fd_vm_syscall_sol_memmove );
102 17701 : REGISTER( "sol_memcmp_", fd_vm_syscall_sol_memcmp );
103 17701 : REGISTER( "sol_memset_", fd_vm_syscall_sol_memset );
104 17701 : REGISTER( "sol_invoke_signed_c", fd_vm_syscall_cpi_c );
105 17701 : REGISTER( "sol_invoke_signed_rust", fd_vm_syscall_cpi_rust );
106 17701 : REGISTER( "sol_set_return_data", fd_vm_syscall_sol_set_return_data );
107 17701 : REGISTER( "sol_get_return_data", fd_vm_syscall_sol_get_return_data );
108 17701 : REGISTER( "sol_log_data", fd_vm_syscall_sol_log_data );
109 17701 : REGISTER( "sol_get_processed_sibling_instruction", fd_vm_syscall_sol_get_processed_sibling_instruction );
110 17701 : REGISTER( "sol_get_stack_height", fd_vm_syscall_sol_get_stack_height );
111 17701 : REGISTER( "sol_get_epoch_rewards_sysvar", fd_vm_syscall_sol_get_epoch_rewards_sysvar );
112 :
113 17701 : REGISTER( "sol_curve_validate_point", fd_vm_syscall_sol_curve_validate_point );
114 17701 : REGISTER( "sol_curve_group_op", fd_vm_syscall_sol_curve_group_op );
115 17701 : REGISTER( "sol_curve_multiscalar_mul", fd_vm_syscall_sol_curve_multiscalar_mul );
116 17701 : REGISTER( "sol_curve_decompress", fd_vm_syscall_sol_curve_decompress );
117 17701 : REGISTER( "sol_curve_pairing_map", fd_vm_syscall_sol_curve_pairing_map );
118 :
119 17701 : REGISTER( "sol_alt_bn128_group_op", fd_vm_syscall_sol_alt_bn128_group_op );
120 17701 : REGISTER( "sol_alt_bn128_compression", fd_vm_syscall_sol_alt_bn128_compression );
121 :
122 17701 : # if FD_HAS_S2NBIGNUM
123 17701 : if( enable_big_mod_exp_syscall )
124 7551 : REGISTER( "sol_big_mod_exp", fd_vm_syscall_sol_big_mod_exp );
125 : # else
126 : (void)enable_big_mod_exp_syscall;
127 : # endif
128 :
129 17701 : REGISTER( "sol_poseidon", fd_vm_syscall_sol_poseidon );
130 :
131 : //REGISTER( "sol_remaining_compute_units", fd_vm_syscall_sol_remaining_compute_units );
132 :
133 17701 : # undef REGISTER
134 :
135 17701 : return FD_VM_SUCCESS;
136 17701 : }
|