11#include  "fd_sbpf_loader.h" 
22#include  "fd_sbpf_instr.h" 
33#include  "fd_sbpf_opcodes.h" 
4- #include  "../../util/fd_util .h" 
4+ #include  "../elf/fd_elf64 .h" 
55#include  "../../util/bits/fd_sat.h" 
66#include  "../murmur3/fd_murmur3.h" 
77
@@ -127,18 +127,17 @@ fd_sbpf_program_align( void ) {
127127  return  alignof( fd_sbpf_program_t  );
128128}
129129
130+ static  inline  ulong 
131+ fd_sbpf_program_calldests_max ( fd_sbpf_elf_info_t  const  *  info  ) {
132+   if ( fd_sbpf_enable_stricter_elf_headers_enabled ( info -> sbpf_version  ) ) return  0UL ;
133+   return  info -> text_cnt ;
134+ }
135+ 
130136ulong 
131137fd_sbpf_program_footprint ( fd_sbpf_elf_info_t  const  *  info  ) {
132-   FD_COMPILER_UNPREDICTABLE ( info  ); /* Make this appear as FD_FN_PURE (e.g. footprint might depened on info contents in future) */ 
133-   if ( FD_UNLIKELY ( fd_sbpf_enable_stricter_elf_headers_enabled ( info -> sbpf_version  ) ) ) {
134-     /* SBPF v3+ no longer neeeds calldests bitmap */ 
135-     return  FD_LAYOUT_FINI ( FD_LAYOUT_APPEND ( FD_LAYOUT_INIT ,
136-       alignof(fd_sbpf_program_t ), sizeof (fd_sbpf_program_t ) ),
137-       alignof(fd_sbpf_program_t ) );
138-   }
139138  return  FD_LAYOUT_FINI ( FD_LAYOUT_APPEND ( FD_LAYOUT_APPEND ( FD_LAYOUT_INIT ,
140139    alignof(fd_sbpf_program_t ), sizeof (fd_sbpf_program_t ) ),
141-     fd_sbpf_calldests_align (), fd_sbpf_calldests_footprint ( info -> text_cnt  ) ),   /* calldests bitmap */ 
140+     fd_sbpf_calldests_align (), fd_sbpf_calldests_footprint ( fd_sbpf_program_calldests_max (  info  ) ) ), 
142141    alignof(fd_sbpf_program_t ) );
143142}
144143
@@ -183,19 +182,13 @@ fd_sbpf_program_new( void *                     prog_mem,
183182  };
184183
185184  /* If the text section is empty, then we do not need a calldests map. */ 
186-   ulong  pc_max  =  elf_info -> text_cnt ;
187-   if ( FD_UNLIKELY ( fd_sbpf_enable_stricter_elf_headers_enabled ( elf_info -> sbpf_version  ) ||  pc_max == 0UL  ) ) {
188-     /* No calldests map in SBPF v3+ or if text_cnt is 0. */ 
189-     prog -> calldests_shmem  =  NULL ;
190-     prog -> calldests        =  NULL ;
191-   } else  {
192-     /* Initialize calldests map. */ 
193-     prog -> calldests_shmem  =  fd_sbpf_calldests_new (
194-           FD_SCRATCH_ALLOC_APPEND ( laddr , fd_sbpf_calldests_align (),
195-                                           fd_sbpf_calldests_footprint ( pc_max  ) ),
196-           pc_max  );
197-     prog -> calldests  =  fd_sbpf_calldests_join ( prog -> calldests_shmem  );
198-   }
185+   ulong  calldests_max  =  fd_sbpf_program_calldests_max ( elf_info  );
186+   /* Initialize calldests map. */ 
187+   prog -> calldests_shmem  =  fd_sbpf_calldests_new (
188+         FD_SCRATCH_ALLOC_APPEND ( laddr , fd_sbpf_calldests_align (),
189+                                         fd_sbpf_calldests_footprint ( calldests_max  ) ),
190+         fd_sbpf_calldests_footprint ( calldests_max  ) );
191+   prog -> calldests  =  fd_sbpf_calldests_join ( prog -> calldests_shmem  );
199192
200193  return  prog ;
201194}
@@ -215,7 +208,7 @@ fd_sbpf_program_delete( fd_sbpf_program_t * mem ) {
215208
216209struct  fd_sbpf_loader  {
217210  /* External objects */ 
218-   ulong  *               calldests ; /* owned by program. NULL if text_cnt = 0 or SBPF v3+  */ 
211+   ulong  *               calldests ; /* owned by program */ 
219212  fd_sbpf_syscalls_t  *  syscalls ;  /* owned by caller */ 
220213};
221214typedef  struct  fd_sbpf_loader  fd_sbpf_loader_t ;
@@ -361,9 +354,7 @@ fd_sbpf_register_function_hashed_legacy( fd_sbpf_loader_t *  loader,
361354     make sure that target_pc <= text_cnt, otherwise the insertion is 
362355     UB. It's fine to skip inserting these entries because the calldests 
363356     are write-only in the SBPF loader and only queried from the VM. */ 
364-   if ( FD_LIKELY ( !is_entrypoint  && 
365-                   loader -> calldests  && 
366-                   fd_sbpf_calldests_valid_idx ( loader -> calldests , target_pc  ) ) ) {
357+   if ( FD_LIKELY ( !is_entrypoint  ) ) {
367358    fd_sbpf_calldests_insert ( loader -> calldests , target_pc  );
368359  }
369360
0 commit comments