LCOV - code coverage report
Current view: top level - flamenco/progcache - fd_progcache_rec.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 15 24 62.5 %
Date: 2025-10-27 04:40:00 Functions: 3 565 0.5 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_progcache_fd_progcache_rec_h
       2             : #define HEADER_fd_src_flamenco_progcache_fd_progcache_rec_h
       3             : 
       4             : #include "../fd_flamenco_base.h"
       5             : #include "../../ballet/sbpf/fd_sbpf_loader.h"
       6             : 
       7             : /* fd_progcache_rec_t is the fixed size header of a program cache entry
       8             :    object.  Entries are either non-executable (e.g. programs that failed
       9             :    verification) or executable.  Non-executable entry objects consist
      10             :    only of this header struct.  Executable entry objects are variable-
      11             :    sized and contain additional structures past this header (rodata/ROM
      12             :    segment, control flow metadata, ...). */
      13             : 
      14             : struct fd_progcache_rec {
      15             :   /* Slot number at which this cache entry was created.
      16             :      Matches the XID's slot number for in-preparation transactions. */
      17             :   ulong slot;
      18             : 
      19             :   uint entry_pc;
      20             :   uint text_cnt;
      21             :   uint text_off;
      22             :   uint text_sz;
      23             : 
      24             :   uint rodata_sz;
      25             : 
      26             :   uint calldests_off;  /* offset to sbpf_calldests map */
      27             :   uint rodata_off;     /* offset to rodata segment */
      28             : 
      29             :   /* SBPF version, SIMD-0161 */
      30             :   uchar sbpf_version;
      31             : 
      32             :   uint executable : 1;  /* is this an executable entry? */
      33             :   uint invalidate : 1;  /* if ==1, limits visibility of this entry to this slot */
      34             : };
      35             : 
      36             : typedef struct fd_progcache_rec fd_progcache_rec_t;
      37             : 
      38             : FD_PROTOTYPES_BEGIN
      39             : 
      40             : /* Accessors */
      41             : 
      42             : static inline uchar const *
      43           0 : fd_progcache_rec_rodata( fd_progcache_rec_t const * rec ) {
      44           0 :   return (uchar const *)rec + rec->rodata_off;
      45           0 : }
      46             : 
      47             : static inline fd_sbpf_calldests_t const *
      48           0 : fd_progcache_rec_calldests( fd_progcache_rec_t const * rec ) {
      49           0 :   return fd_sbpf_calldests_join( (void *)( (ulong)rec + rec->calldests_off ) );
      50           0 : }
      51             : 
      52             : /* Private APIs */
      53             : 
      54             : /* fd_progcache_rec_{align,footprint} give the params of backing memory
      55             :    of a progcache_rec object for the given ELF info.  If elf_info is
      56             :    NULL, implies a non-executable cache entry (sizeof(fd_progcache_rec_t)). */
      57             : 
      58             : FD_FN_CONST static inline ulong
      59         300 : fd_progcache_rec_align( void ) {
      60         300 :   return alignof(fd_progcache_rec_t);
      61         300 : }
      62             : 
      63             : FD_FN_PURE FD_FN_UNUSED static ulong
      64          66 : fd_progcache_rec_footprint( fd_sbpf_elf_info_t const * elf_info ) {
      65          66 :   if( !elf_info ) return sizeof(fd_progcache_rec_t); /* non-executable */
      66             : 
      67          39 :   int   has_calldests = !fd_sbpf_enable_stricter_elf_headers_enabled( elf_info->sbpf_version );
      68          39 :   ulong pc_max        = fd_ulong_max( 1UL, elf_info->text_cnt );
      69             : 
      70          39 :   ulong l = FD_LAYOUT_INIT;
      71          39 :   l = FD_LAYOUT_APPEND( l, alignof(fd_progcache_rec_t), sizeof(fd_progcache_rec_t) );
      72          39 :   if( has_calldests ) {
      73          39 :     l = FD_LAYOUT_APPEND( l, fd_sbpf_calldests_align(), fd_sbpf_calldests_footprint( pc_max ) );
      74          39 :   }
      75          39 :   l = FD_LAYOUT_APPEND( l, 8UL, elf_info->bin_sz );
      76          39 :   return FD_LAYOUT_FINI( l, fd_progcache_rec_align() );
      77          66 : }
      78             : 
      79             : /* fd_progcache_rec_new creates a new excutable progcache_rec object.
      80             :    mem points to a memory region matching fd_progcache_rec_{align,
      81             :    footprint}.   Loads and verifies the given program data and returns
      82             :    the newly created executable object on success.  On failure, returns
      83             :    NULL (the caller may call fd_progcache_rec_new_nx instead). */
      84             : 
      85             : fd_progcache_rec_t *
      86             : fd_progcache_rec_new( void *                          mem,
      87             :                       fd_sbpf_elf_info_t const *      elf_info,
      88             :                       fd_sbpf_loader_config_t const * config,
      89             :                       ulong                           load_slot,
      90             :                       fd_features_t const *           features,
      91             :                       void const *                    progdata,
      92             :                       ulong                           progdata_sz,
      93             :                       void *                          scratch,
      94             :                       ulong                           scratch_sz );
      95             : 
      96             : /* fd_progcache_rec_new_nx creates a non-executable program_cache
      97             :    object.  fd_progcache_rec_t[1] is suitable for mem. */
      98             : 
      99             : fd_progcache_rec_t *
     100             : fd_progcache_rec_new_nx( void * mem,
     101             :                          ulong  load_slot );
     102             : 
     103             : /* fd_progcache_rec_delete destroys a progcache_rec object and returns
     104             :    the backing memory region to the caller. */
     105             : 
     106             : static inline void *
     107           0 : fd_progcache_rec_delete( fd_progcache_rec_t * rec ) {
     108           0 :   return rec;
     109           0 : }
     110             : 
     111             : FD_PROTOTYPES_END
     112             : 
     113             : #endif /* HEADER_fd_src_flamenco_progcache_fd_progcache_rec_h */

Generated by: LCOV version 1.14