LCOV - code coverage report
Current view: top level - util/racesan - fd_racesan.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 49 0.0 %
Date: 2025-10-13 04:42:14 Functions: 0 7 0.0 %

          Line data    Source code
       1             : #include "fd_racesan.h"
       2             : #include "fd_racesan_target.h"
       3             : #include "../../util/log/fd_log.h"
       4             : 
       5             : #define MAP_NAME        hook_map
       6           0 : #define MAP_T           fd_racesan_hook_map_t
       7           0 : #define MAP_LG_SLOT_CNT FD_RACESAN_HOOKS_LG_MAX
       8           0 : #define MAP_KEY         name_hash
       9             : #define MAP_MEMOIZE     0
      10           0 : #define MAP_KEY_HASH(k) (uint)(k)
      11             : #include "../../util/tmpl/fd_map.c"
      12             : 
      13             : FD_TL fd_racesan_t * fd_racesan_g = NULL;
      14             : 
      15             : fd_racesan_t *
      16             : fd_racesan_new( fd_racesan_t * racesan,
      17           0 :                 void *         ctx ) {
      18           0 :   if( FD_UNLIKELY( !racesan ) ) {
      19           0 :     FD_LOG_WARNING(( "NULL racesan" ));
      20           0 :     return NULL;
      21           0 :   }
      22           0 :   racesan->hook_ctx     = ctx;
      23           0 :   racesan->default_hook = NULL;
      24           0 :   hook_map_new( racesan->hook_map );
      25           0 :   return racesan;
      26           0 : }
      27             : 
      28             : void *
      29           0 : fd_racesan_delete( fd_racesan_t * racesan ) {
      30           0 :   (void)racesan;
      31           0 :   return racesan;
      32           0 : }
      33             : 
      34             : void
      35             : fd_racesan_inject( fd_racesan_t *         racesan,
      36             :                    char const *           name,
      37           0 :                    fd_racesan_hook_fn_t * fn ) {
      38           0 :   ulong name_len  = strlen( name );
      39           0 :   ulong name_hash = fd_racesan_strhash( name, name_len );
      40           0 :   fd_racesan_hook_map_t * entry = hook_map_insert( racesan->hook_map, name_hash );
      41           0 :   if( FD_UNLIKELY( !entry ) ) FD_LOG_ERR(( "fd_racesan_inject failed: hook for %s already exists", name ));
      42           0 :   entry->hook = fn;
      43           0 : }
      44             : 
      45             : void
      46             : fd_racesan_inject_default( fd_racesan_t *      racesan,
      47           0 :                            fd_racesan_hook_fn_t * callback ) {
      48           0 :   racesan->default_hook = callback;
      49           0 : }
      50             : 
      51             : void
      52           0 : fd_racesan_enter( fd_racesan_t * racesan ) {
      53           0 :   if( FD_UNLIKELY( fd_racesan_g ) ) {
      54           0 :     FD_LOG_CRIT(( "Failed to enter racesan context: already activated" ));
      55           0 :   }
      56           0 :   fd_racesan_g = racesan;
      57           0 : }
      58             : 
      59             : void
      60           0 : fd_racesan_exit( void ) {
      61           0 :   fd_racesan_g = NULL;
      62           0 : }
      63             : 
      64             : void
      65             : fd_racesan_hook_private( ulong        name_hash,
      66             :                          char const * file,
      67           0 :                          int          line ) {
      68           0 :   fd_racesan_t * racesan = fd_racesan_g;
      69           0 :   if( FD_UNLIKELY( !racesan ) ) return;
      70             : 
      71           0 :   fd_racesan_hook_map_t const * entry = hook_map_query_const( racesan->hook_map, name_hash, NULL );
      72           0 :   if( entry ) {
      73           0 :     entry->hook( racesan->hook_ctx, name_hash );
      74           0 :   }
      75             : 
      76           0 :   if( racesan->default_hook ) {
      77           0 :     racesan->default_hook( racesan->hook_ctx, name_hash );
      78           0 :   }
      79             : 
      80           0 :   (void)file; (void)line;
      81           0 : }

Generated by: LCOV version 1.14