LCOV - code coverage report
Current view: top level - flamenco/runtime/program - fd_native_cpi.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 48 0.0 %
Date: 2025-12-04 04:56:06 Functions: 0 2 0.0 %

          Line data    Source code
       1             : #include "fd_native_cpi.h"
       2             : #include "../fd_borrowed_account.h"
       3             : #include "../fd_executor.h"
       4             : #include "../../vm/syscall/fd_vm_syscall.h"
       5             : #include "../../../util/bits/fd_uwide.h"
       6             : 
       7             : int
       8             : fd_native_cpi_native_invoke( fd_exec_instr_ctx_t *             ctx,
       9             :                              fd_pubkey_t const *               native_program_id,
      10             :                              uchar *                           instr_data,
      11             :                              ulong                             instr_data_len,
      12             :                              fd_vm_rust_account_meta_t const * acct_metas,
      13             :                              ulong                             acct_metas_len,
      14             :                              fd_pubkey_t const *               signers,
      15           0 :                              ulong                             signers_cnt ) {
      16             :   /* Set up the instr info */
      17           0 :   fd_instr_info_t *        instr_info = &ctx->runtime->instr.trace[ ctx->runtime->instr.trace_length++ ];
      18           0 :   fd_instruction_account_t instruction_accounts[ FD_INSTR_ACCT_MAX ];
      19           0 :   ulong                    instruction_accounts_cnt;
      20             : 
      21             :   /* Set the stack size */
      22           0 :   instr_info->stack_height = ctx->runtime->instr.stack_sz+1;
      23             : 
      24             :   /* fd_vm_prepare_instruction will handle missing/invalid account case */
      25           0 :   instr_info->program_id = UCHAR_MAX;
      26           0 :   int program_id = fd_runtime_find_index_of_account( ctx->txn_out, native_program_id );
      27           0 :   if( FD_LIKELY( program_id!=-1 ) ) {
      28           0 :     instr_info->program_id = (uchar)program_id;
      29           0 :   }
      30             : 
      31           0 :   fd_pubkey_t instr_acct_keys[ FD_INSTR_ACCT_MAX ];
      32           0 :   uchar       acc_idx_seen[ FD_INSTR_ACCT_MAX ];
      33           0 :   memset( acc_idx_seen, 0, FD_INSTR_ACCT_MAX );
      34             : 
      35           0 :   instr_info->acct_cnt = (ushort)acct_metas_len;
      36           0 :   for( ushort j=0U; j<acct_metas_len; j++ ) {
      37           0 :     fd_vm_rust_account_meta_t const * acct_meta     = &acct_metas[j];
      38           0 :     fd_pubkey_t const *               acct_key      = fd_type_pun_const( acct_meta->pubkey );
      39           0 :     instr_acct_keys[j] = *acct_key;
      40             : 
      41           0 :     int idx_in_txn    = fd_runtime_find_index_of_account( ctx->txn_out, acct_key );
      42           0 :     int idx_in_caller = fd_exec_instr_ctx_find_idx_of_instr_account( ctx, acct_key );
      43             : 
      44           0 :     fd_instr_info_setup_instr_account( instr_info,
      45           0 :                                        acc_idx_seen,
      46           0 :                                        idx_in_txn!=-1 ? (ushort)idx_in_txn : USHORT_MAX,
      47           0 :                                        idx_in_caller!=-1 ? (ushort)idx_in_caller : USHORT_MAX,
      48           0 :                                        j,
      49           0 :                                        acct_meta->is_writable,
      50           0 :                                        acct_meta->is_signer );
      51           0 :   }
      52             : 
      53           0 :   fd_memcpy( instr_info->data, instr_data, instr_data_len );
      54           0 :   instr_info->data_sz = (ushort)instr_data_len;
      55             : 
      56             :   /* https://github.com/anza-xyz/agave/blob/v2.2.6/program-runtime/src/invoke_context.rs#L312-L313 */
      57           0 :   int exec_err = fd_vm_prepare_instruction( instr_info,
      58           0 :                                             ctx,
      59           0 :                                             native_program_id,
      60           0 :                                             instr_acct_keys,
      61           0 :                                             instruction_accounts,
      62           0 :                                             &instruction_accounts_cnt,
      63           0 :                                             signers,
      64           0 :                                             signers_cnt );
      65           0 :   if( FD_UNLIKELY( exec_err!=FD_EXECUTOR_INSTR_SUCCESS ) ) {
      66           0 :     return exec_err;
      67           0 :   }
      68             : 
      69             :   /* https://github.com/anza-xyz/agave/blob/v2.2.6/program-runtime/src/invoke_context.rs#L315-L321 */
      70           0 :   return fd_execute_instr( ctx->runtime, ctx->bank, ctx->txn_in, ctx->txn_out, instr_info );
      71           0 : }
      72             : 
      73             : void
      74             : fd_native_cpi_create_account_meta( fd_pubkey_t const * key, uchar is_signer,
      75           0 :                                    uchar is_writable, fd_vm_rust_account_meta_t * meta ) {
      76           0 :   meta->is_signer = is_signer;
      77           0 :   meta->is_writable = is_writable;
      78           0 :   fd_memcpy( meta->pubkey, key->key, sizeof(fd_pubkey_t) );
      79           0 : }

Generated by: LCOV version 1.14