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