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 "../../funk/fd_funk_base.h" 5 : #include "../../ballet/sbpf/fd_sbpf_loader.h" 6 : #include "../fd_flamenco_base.h" 7 : #include "../fd_rwlock.h" 8 : 9 : /* fd_progcache_join_t is a join to a fd_progcache_shmem_t. */ 10 : 11 : struct fd_progcache_join; /* forward declaration */ 12 : typedef struct fd_progcache_join fd_progcache_join_t; 13 : 14 : /* fd_progcache_rec_t is the fixed size header of a program cache entry 15 : object. Entries are either non-executable (e.g. programs that failed 16 : verification) or executable. Non-executable entry objects consist 17 : only of this header struct. Executable entry objects are variable- 18 : sized and contain additional structures past this header (rodata/ROM 19 : segment, control flow metadata, ...). */ 20 : 21 : struct __attribute__((aligned(64))) fd_progcache_rec { 22 : /* Slot number at which this cache entry was created. 23 : Matches the XID's slot number for in-preparation transactions. */ 24 : ulong slot; 25 : 26 : fd_funk_xid_key_pair_t pair; /* Transaction id and record key pair */ 27 : uint map_next; /* Internal use by map */ 28 : uint next_idx; /* Record map index of next record in its transaction */ 29 : uint prev_idx; /* Record map index of previous record in its transaction */ 30 : 31 : uint data_max; /* size of allocation */ 32 : ulong data_gaddr; /* wksp-base relative pointer to data */ 33 : 34 : uint entry_pc; 35 : uint text_cnt; 36 : uint text_off; 37 : uint text_sz; 38 : 39 : uint rodata_sz; 40 : 41 : uint calldests_off; /* offset to sbpf_calldests map */ 42 : uint rodata_off; /* offset to rodata segment */ 43 : 44 : ushort sbpf_version : 8; /* SBPF version, SIMD-0161 */ 45 : ushort executable : 1; /* is this an executable entry? */ 46 : ushort invalidate : 1; /* if ==1, limits visibility of this entry to this slot */ 47 : ushort exists : 1; /* if ==0, record is dead, no longer in map, and awaiting cleanup */ 48 : fd_rwlock_t lock; 49 : }; 50 : 51 : typedef struct fd_progcache_rec fd_progcache_rec_t; 52 : 53 : FD_STATIC_ASSERT( sizeof(fd_progcache_rec_t)==128, layout ); 54 : 55 : FD_PROTOTYPES_BEGIN 56 : 57 : /* Accessors */ 58 : 59 : static inline uchar const * 60 : fd_progcache_rec_rodata( fd_progcache_rec_t const * rec, 61 6354 : fd_wksp_t * wksp ) { 62 6354 : return fd_wksp_laddr_fast( wksp, rec->data_gaddr + rec->rodata_off ); 63 6354 : } 64 : 65 : static inline fd_sbpf_calldests_t const * 66 : fd_progcache_rec_calldests( fd_progcache_rec_t const * rec, 67 6354 : fd_wksp_t * wksp ) { 68 6354 : return fd_sbpf_calldests_join( fd_wksp_laddr_fast( wksp, rec->data_gaddr + rec->calldests_off ) ); 69 6354 : } 70 : 71 : /* Private APIs */ 72 : 73 : /* fd_progcache_rec_{align,footprint} give the params of backing memory 74 : of a progcache_rec object for the given ELF info. If elf_info is 75 : NULL, implies a non-executable cache entry (sizeof(fd_progcache_rec_t)). */ 76 : 77 : FD_FN_CONST static inline ulong 78 71135 : fd_progcache_val_align( void ) { 79 71135 : return fd_sbpf_calldests_align(); 80 71135 : } 81 : 82 : FD_FN_PURE ulong 83 : fd_progcache_val_footprint( fd_sbpf_elf_info_t const * elf_info ); 84 : 85 : void * 86 : fd_progcache_val_alloc( fd_progcache_rec_t * rec, 87 : fd_progcache_join_t * join, 88 : ulong val_align, 89 : ulong val_footprint ); 90 : 91 : void 92 : fd_progcache_val_free( fd_progcache_rec_t * rec, 93 : fd_progcache_join_t * join ); 94 : 95 : fd_progcache_rec_t * 96 : fd_progcache_rec_load( fd_progcache_rec_t * rec, 97 : fd_wksp_t * wksp, 98 : fd_sbpf_elf_info_t const * elf_info, 99 : fd_sbpf_loader_config_t const * config, 100 : ulong load_slot, 101 : fd_features_t const * features, 102 : void const * progdata, 103 : ulong progdata_sz, 104 : void * scratch, 105 : ulong scratch_sz ); 106 : 107 : fd_progcache_rec_t * 108 : fd_progcache_rec_nx( fd_progcache_rec_t * rec ); 109 : 110 : FD_PROTOTYPES_END 111 : 112 : #endif /* HEADER_fd_src_flamenco_progcache_fd_progcache_rec_h */