LCOV - code coverage report
Current view: top level - flamenco/vm/syscall - fd_vm_syscall.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 84 84 100.0 %
Date: 2026-09-17 04:28:31 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.14