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

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_racesan_fd_racesan_h
       2             : #define HEADER_fd_src_flamenco_racesan_fd_racesan_h
       3             : 
       4             : /* fd_racesan.h provides test utils for deterministically simulating
       5             :    data races.  Practically just a mechanism to inject callbacks into
       6             :    instrumented production code (with appropriate compiler hacks to
       7             :    invalidate registers/locals).
       8             : 
       9             :    See README.md for usage. */
      10             : 
      11             : #include "fd_racesan_base.h"
      12             : 
      13             : /* FD_RACESAN_HOOKS_MAX is the max number of active racesan hooks */
      14             : 
      15           0 : #define FD_RACESAN_HOOKS_LG_MAX (7)
      16             : #define FD_RACESAN_HOOKS_MAX    (1UL<<FD_RACESAN_HOOKS_LG_MAX) /* 128 */
      17             : 
      18             : typedef void
      19             : fd_racesan_hook_fn_t( void * ctx,
      20             :                       ulong  name_hash );
      21             : 
      22             : struct fd_racesan_hook_map {
      23             :   ulong                  name_hash;
      24             :   fd_racesan_hook_fn_t * hook;
      25             : };
      26             : 
      27             : typedef struct fd_racesan_hook_map fd_racesan_hook_map_t;
      28             : 
      29             : struct fd_racesan {
      30             :   void * hook_ctx;
      31             : 
      32             :   fd_racesan_hook_fn_t * default_hook;
      33             :   fd_racesan_hook_map_t  hook_map[ FD_RACESAN_HOOKS_MAX ];
      34             : };
      35             : 
      36             : typedef struct fd_racesan fd_racesan_t;
      37             : 
      38             : FD_PROTOTYPES_BEGIN
      39             : 
      40             : fd_racesan_t *
      41             : fd_racesan_new( fd_racesan_t * obj,
      42             :                 void *         ctx );
      43             : 
      44             : void *
      45             : fd_racesan_delete( fd_racesan_t * obj );
      46             : 
      47             : /* fd_racesan_inject injects a callback into an fd_racesan_hook trace
      48             :    point.  Useful for fault injection. */
      49             : 
      50             : void
      51             : fd_racesan_inject( fd_racesan_t *      obj,
      52             :                    char const *        hook,
      53             :                    fd_racesan_hook_fn_t * callback );
      54             : 
      55             : /* fd_racesan_inject_default injects a default callback that's called
      56             :    by any fd_racesan_hook trace points. */
      57             : 
      58             : void
      59             : fd_racesan_inject_default( fd_racesan_t *      obj,
      60             :                            fd_racesan_hook_fn_t * callback );
      61             : 
      62             : void
      63             : fd_racesan_enter( fd_racesan_t * racesan );
      64             : 
      65             : void
      66             : fd_racesan_exit( void );
      67             : 
      68             : FD_PROTOTYPES_END
      69             : 
      70             : static inline void
      71           0 : fd_racesan_private_cleanup( int * unused ) {
      72           0 :   (void)unused;
      73           0 :   fd_racesan_exit();
      74           0 : }
      75             : 
      76             : #define FD_RACESAN_INJECT_BEGIN( _rs )        \
      77             :   do {                                        \
      78             :     fd_racesan_t * __rs = (_rs);              \
      79             :     fd_racesan_enter( __rs );                 \
      80             :     __attribute__((cleanup(fd_racesan_private_cleanup))) int __dummy; \
      81             :     do {                                      \
      82             : 
      83             : #define FD_RACESAN_INJECT_END \
      84             :     } while(0); \
      85             :   } while(0)
      86             : 
      87             : #endif /* HEADER_fd_src_flamenco_racesan_fd_racesan_h */

Generated by: LCOV version 1.14