LCOV - code coverage report
Current view: top level - flamenco/vm/syscall - fd_vm_cpi.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 2 2 100.0 %
Date: 2024-11-13 11:58:15 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_vm_syscall_fd_vm_cpi_h
       2             : #define HEADER_fd_src_flamenco_vm_syscall_fd_vm_cpi_h
       3             : 
       4             : #ifndef HEADER_fd_src_flamenco_vm_syscall_fd_vm_syscall_h
       5             : #error "Do not include this directly; use fd_vm_syscall.h"
       6             : #endif
       7             : 
       8             : /* fd_vm_cpi contains type definitions for the cross-program-invocation
       9             :    (CPI) API.  These types are passed from the virtual machine to the
      10             :    CPI syscall handlers and are thus untrusted.  Addresses are in VM
      11             :    address space.  Struct parameter offsets and sizes match exactly.
      12             :    Structs also have alignment requirements in VM address space.  These
      13             :    alignments are provided as const macros.  Since we cannot guarantee
      14             :    that a type is aligned in host address space even when aligned in VM
      15             :    address space (FIXME: HMMM ... THAT DOESN'T SOUND RIGHT), all structs
      16             :    support unaligned access (i.e. alignof(type)==1UL).
      17             : 
      18             :    Unfortunately, the Solana protocol provides this API twice:
      19             :    In a C-style ABI and in Rust ABI. */
      20             : 
      21             : #define FD_VM_RC_REFCELL_ALIGN (8UL)
      22             : 
      23             : struct __attribute__((packed)) fd_vm_rc_refcell_vec {
      24             :   ulong strong;
      25             :   ulong weak;
      26             :   ulong borrow;
      27             :   ulong addr;
      28             :   ulong len;
      29             : };
      30             : typedef struct fd_vm_rc_refcell_vec fd_vm_rc_refcell_vec_t;
      31             : 
      32             : struct __attribute__((packed)) fd_vm_rc_refcell {
      33             :   ulong strong;
      34             :   ulong weak;
      35             :   ulong borrow;
      36             :   ulong addr;
      37             : };
      38             : typedef struct fd_vm_rc_refcell fd_vm_rc_refcell_t;
      39             : 
      40             : /* Structs fd_vm_c_{...}_t are part of the C ABI for the cross-program
      41             :    invocation syscall API. */
      42             : 
      43             : #define FD_VM_C_INSTRUCTION_ALIGN (8UL)
      44             : #define FD_VM_C_INSTRUCTION_SIZE  (40UL)
      45             : 
      46             : struct __attribute__((packed)) fd_vm_c_instruction {
      47             :   ulong  program_id_addr;
      48             :   ulong  accounts_addr;
      49             :   ulong  accounts_len;
      50             :   ulong  data_addr;
      51             :   ulong  data_len;
      52             : };
      53             : 
      54             : typedef struct fd_vm_c_instruction fd_vm_c_instruction_t;
      55             : 
      56             : #define FD_VM_C_ACCOUNT_META_ALIGN (8UL)
      57             : #define FD_VM_C_ACCOUNT_META_SIZE  (16UL)
      58             : struct fd_vm_c_account_meta {
      59             :   ulong pubkey_addr;
      60             :   uchar is_writable;
      61             :   uchar is_signer;
      62             : };
      63             : 
      64             : typedef struct fd_vm_c_account_meta fd_vm_c_account_meta_t;
      65             : 
      66             : /* Solana stores pubkey within account meta struct and is used to check if 
      67             :    instructions are too large. 
      68             :    https://github.com/solana-labs/solana/blob/9f6ef2fe629d59d93d227d4561d8f7d5a2fd5f2f/sdk/program/src/instruction.rs#L548 */
      69             : struct fd_vm_sol_account_meta {
      70             :   fd_pubkey_t pubkey;
      71             :   uchar is_signer;
      72             :   uchar is_writable;
      73             : };
      74             : 
      75             : typedef struct fd_vm_sol_account_meta fd_vm_sol_account_meta_t;
      76             : 
      77             : #define FD_VM_C_ACCOUNT_INFO_ALIGN (8UL)
      78             : #define FD_VM_C_ACCOUNT_INFO_SIZE  (56UL)
      79             : 
      80             : struct fd_vm_c_account_info {
      81             :   ulong pubkey_addr;
      82             :   ulong lamports_addr;
      83             :   ulong data_sz;
      84             :   ulong data_addr;
      85             :   ulong owner_addr;
      86             :   ulong rent_epoch;
      87             :   uchar is_signer;
      88             :   uchar is_writable;
      89             :   uchar executable;
      90             : };
      91             : 
      92             : typedef struct fd_vm_c_account_info fd_vm_c_account_info_t;
      93             : 
      94             : /* Structs fd_vm_rust_{...}_t are part of the Rust ABI for the
      95             :    cross-program-invocation syscall API. */
      96             : 
      97             : /* fd_vm_rust_vec_t is Rust type Vec<_> using the default allocator. */
      98             : 
      99             : #define FD_VM_RUST_VEC_ALIGN (8UL)
     100             : #define FD_VM_RUST_VEC_SIZE  (24UL)
     101             : 
     102             : struct __attribute__((packed)) fd_vm_rust_vec {
     103             :   ulong addr;
     104             :   ulong cap;
     105             :   ulong len;
     106             : };
     107             : 
     108             : typedef struct fd_vm_rust_vec fd_vm_rust_vec_t;
     109             : 
     110             : #define FD_VM_RUST_RC_ALIGN (8UL)
     111             : 
     112             : #define FD_VM_RUST_INSTRUCTION_ALIGN (8UL)
     113             : #define FD_VM_RUST_INSTRUCTION_SIZE  (80UL)
     114             : 
     115             : struct __attribute__((packed)) fd_vm_rust_instruction {
     116             :   fd_vm_rust_vec_t accounts;    /* points to fd_vm_rust_account_meta_t */
     117             :   fd_vm_rust_vec_t data;        /* points to bytes */
     118             :   uchar            pubkey[32];
     119             : };
     120             : 
     121             : typedef struct fd_vm_rust_instruction fd_vm_rust_instruction_t;
     122             : 
     123         258 : #define FD_VM_RUST_ACCOUNT_META_SIZE  (34UL)
     124         642 : #define FD_VM_RUST_ACCOUNT_META_ALIGN (1UL)
     125             : 
     126             : struct __attribute__((packed)) fd_vm_rust_account_meta {
     127             :   uchar pubkey[32];
     128             :   uchar is_signer;
     129             :   uchar is_writable;
     130             : };
     131             : 
     132             : typedef struct fd_vm_rust_account_meta fd_vm_rust_account_meta_t;
     133             : 
     134             : #define FD_VM_RUST_ACCOUNT_INFO_ALIGN (8UL)
     135             : #define FD_VM_RUST_ACCOUNT_INFO_SIZE  (48UL)
     136             : 
     137             : struct __attribute__((packed)) fd_vm_rust_account_info {
     138             :   ulong pubkey_addr;          /* points to uchar[32] */
     139             :   ulong lamports_box_addr;    /* points to Rc with embedded RefCell which points to u64 */
     140             :   ulong data_box_addr;        /* points to Rc with embedded RefCell which contains slice which points to bytes */
     141             :   ulong owner_addr;           /* points to uchar[32] */
     142             :   ulong rent_epoch;
     143             :   uchar is_signer;
     144             :   uchar is_writable;
     145             :   uchar executable;
     146             :   uchar _padding_0[5];
     147             : };
     148             : 
     149             : typedef struct fd_vm_rust_account_info fd_vm_rust_account_info_t;
     150             : 
     151             : #endif /* HEADER_fd_src_flamenco_vm_syscall_fd_vm_cpi_h */

Generated by: LCOV version 1.14