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 654524 : fd_sbpf_syscall_func_t func ) {
8 654524 : if( FD_UNLIKELY( (!syscalls) | (!name) ) ) return FD_VM_ERR_INVAL;
9 :
10 654524 : fd_sbpf_syscalls_t * syscall = fd_sbpf_syscalls_insert( syscalls, (ulong)fd_murmur3_32( name, strlen( name ), 0U ) );
11 654524 : if( FD_UNLIKELY( !syscall ) ) return FD_VM_ERR_INVAL; /* name (or hash of name) already in map */
12 :
13 654524 : syscall->func = func;
14 654524 : syscall->name = name;
15 :
16 654524 : return FD_VM_SUCCESS;
17 654524 : }
18 :
19 : int
20 : fd_vm_syscall_register_slot( fd_sbpf_syscalls_t * syscalls,
21 : ulong slot,
22 : fd_features_t const * features,
23 17198 : uchar is_deploy ) {
24 17198 : if( FD_UNLIKELY( !syscalls ) ) return FD_VM_ERR_INVAL;
25 :
26 17198 : int enable_get_sysvar_syscall = 0;
27 17198 : int enable_get_epoch_stake_syscall = 0;
28 17198 : int enable_sha512_syscall = 0;
29 17198 : int enable_big_mod_exp_syscall = 0;
30 :
31 17198 : if( features ) {
32 9676 : enable_get_sysvar_syscall = FD_FEATURE_ACTIVE( slot, features, get_sysvar_syscall_enabled );
33 9676 : enable_get_epoch_stake_syscall = FD_FEATURE_ACTIVE( slot, features, enable_get_epoch_stake_syscall );
34 9676 : enable_sha512_syscall = FD_FEATURE_ACTIVE( slot, features, enable_sha512_syscall );
35 9676 : enable_big_mod_exp_syscall = FD_FEATURE_ACTIVE( slot, features, enable_big_mod_exp_syscall );
36 :
37 9676 : } else { /* enable ALL */
38 :
39 7522 : enable_get_sysvar_syscall = 1;
40 7522 : enable_get_epoch_stake_syscall = 1;
41 7522 : enable_sha512_syscall = 1;
42 7522 : enable_big_mod_exp_syscall = 1;
43 :
44 7522 : }
45 :
46 17198 : fd_sbpf_syscalls_clear( syscalls );
47 :
48 17198 : ulong syscall_cnt = 0UL;
49 :
50 667829 : # define REGISTER(name,func) do { \
51 667829 : if( FD_UNLIKELY( syscall_cnt>=fd_sbpf_syscalls_key_max() ) ) return FD_VM_ERR_FULL; \
52 667829 : int _err = fd_vm_syscall_register( syscalls, (name), (func) ); \
53 667829 : if( FD_UNLIKELY( _err ) ) return _err; \
54 667829 : syscall_cnt++; \
55 667829 : } 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 17198 : REGISTER( "abort", fd_vm_syscall_abort );
60 17198 : 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 17198 : if ( FD_LIKELY( !is_deploy ) ) {
67 16449 : REGISTER( "sol_alloc_free_", fd_vm_syscall_sol_alloc_free );
68 16449 : }
69 :
70 : /* https://github.com/solana-labs/solana/blob/v1.18.1/sdk/program/src/syscalls/definitions.rs#L39 */
71 :
72 17198 : REGISTER( "sol_log_", fd_vm_syscall_sol_log );
73 17198 : REGISTER( "sol_log_64_", fd_vm_syscall_sol_log_64 );
74 17198 : REGISTER( "sol_log_compute_units_", fd_vm_syscall_sol_log_compute_units );
75 17198 : REGISTER( "sol_log_pubkey", fd_vm_syscall_sol_log_pubkey );
76 17198 : REGISTER( "sol_create_program_address", fd_vm_syscall_sol_create_program_address );
77 17198 : REGISTER( "sol_try_find_program_address", fd_vm_syscall_sol_try_find_program_address );
78 17198 : REGISTER( "sol_sha256", fd_vm_syscall_sol_sha256 );
79 17198 : REGISTER( "sol_keccak256", fd_vm_syscall_sol_keccak256 );
80 17198 : REGISTER( "sol_secp256k1_recover", fd_vm_syscall_sol_secp256k1_recover );
81 :
82 17198 : if( enable_sha512_syscall )
83 7532 : REGISTER( "sol_sha512", fd_vm_syscall_sol_sha512 );
84 :
85 17198 : REGISTER( "sol_get_clock_sysvar", fd_vm_syscall_sol_get_clock_sysvar );
86 17198 : REGISTER( "sol_get_epoch_schedule_sysvar", fd_vm_syscall_sol_get_epoch_schedule_sysvar );
87 :
88 17198 : REGISTER( "sol_get_rent_sysvar", fd_vm_syscall_sol_get_rent_sysvar );
89 :
90 17198 : REGISTER( "sol_get_last_restart_slot", fd_vm_syscall_sol_get_last_restart_slot_sysvar );
91 :
92 17198 : if( enable_get_sysvar_syscall ) {
93 17180 : REGISTER( "sol_get_sysvar", fd_vm_syscall_sol_get_sysvar );
94 17180 : }
95 :
96 17203 : if( enable_get_epoch_stake_syscall ) {
97 17203 : REGISTER( "sol_get_epoch_stake", fd_vm_syscall_sol_get_epoch_stake );
98 17203 : }
99 :
100 17198 : REGISTER( "sol_memcpy_", fd_vm_syscall_sol_memcpy );
101 17198 : REGISTER( "sol_memmove_", fd_vm_syscall_sol_memmove );
102 17198 : REGISTER( "sol_memcmp_", fd_vm_syscall_sol_memcmp );
103 17198 : REGISTER( "sol_memset_", fd_vm_syscall_sol_memset );
104 17198 : REGISTER( "sol_invoke_signed_c", fd_vm_syscall_cpi_c );
105 17198 : REGISTER( "sol_invoke_signed_rust", fd_vm_syscall_cpi_rust );
106 17198 : REGISTER( "sol_set_return_data", fd_vm_syscall_sol_set_return_data );
107 17198 : REGISTER( "sol_get_return_data", fd_vm_syscall_sol_get_return_data );
108 17198 : REGISTER( "sol_log_data", fd_vm_syscall_sol_log_data );
109 17198 : REGISTER( "sol_get_processed_sibling_instruction", fd_vm_syscall_sol_get_processed_sibling_instruction );
110 17198 : REGISTER( "sol_get_stack_height", fd_vm_syscall_sol_get_stack_height );
111 17198 : REGISTER( "sol_get_epoch_rewards_sysvar", fd_vm_syscall_sol_get_epoch_rewards_sysvar );
112 :
113 17198 : REGISTER( "sol_curve_validate_point", fd_vm_syscall_sol_curve_validate_point );
114 17198 : REGISTER( "sol_curve_group_op", fd_vm_syscall_sol_curve_group_op );
115 17198 : REGISTER( "sol_curve_multiscalar_mul", fd_vm_syscall_sol_curve_multiscalar_mul );
116 17198 : REGISTER( "sol_curve_decompress", fd_vm_syscall_sol_curve_decompress );
117 17198 : REGISTER( "sol_curve_pairing_map", fd_vm_syscall_sol_curve_pairing_map );
118 :
119 17198 : REGISTER( "sol_alt_bn128_group_op", fd_vm_syscall_sol_alt_bn128_group_op );
120 17198 : REGISTER( "sol_alt_bn128_compression", fd_vm_syscall_sol_alt_bn128_compression );
121 :
122 17198 : # if FD_HAS_S2NBIGNUM
123 17198 : if( enable_big_mod_exp_syscall )
124 7535 : 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 17198 : REGISTER( "sol_poseidon", fd_vm_syscall_sol_poseidon );
130 :
131 : //REGISTER( "sol_remaining_compute_units", fd_vm_syscall_sol_remaining_compute_units );
132 :
133 17198 : # undef REGISTER
134 :
135 17198 : return FD_VM_SUCCESS;
136 17198 : }
|