LCOV - code coverage report
Current view: top level - waltz/quic/log - fd_quic_log.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 173 0.0 %
Date: 2026-03-19 18:19:27 Functions: 0 8 0.0 %

          Line data    Source code
       1             : #include "fd_quic_log_tx.h"
       2             : #include "../../../tango/dcache/fd_dcache.h"
       3             : 
       4             : /* fd_quic_log_buf API ************************************************/
       5             : 
       6             : FD_FN_CONST ulong
       7           0 : fd_quic_log_buf_align( void ) {
       8           0 :   return FD_QUIC_LOG_BUF_ALIGN;
       9           0 : }
      10             : 
      11             : FD_FN_CONST ulong
      12           0 : fd_quic_log_buf_footprint( ulong depth ) {
      13           0 :   if( FD_UNLIKELY( depth>INT_MAX ) ) return 0UL;
      14           0 :   depth = fd_ulong_max( depth, FD_MCACHE_BLOCK );
      15             : 
      16           0 :   ulong mcache_footprint = fd_mcache_footprint( depth, 0 );
      17           0 :   ulong req_data_sz      = fd_dcache_req_data_sz( FD_QUIC_LOG_MTU, depth, 1, 1 );
      18           0 :   ulong dcache_footprint = fd_dcache_footprint( req_data_sz, 0UL );
      19             : 
      20           0 :   if( FD_UNLIKELY( !mcache_footprint ) ) return 0UL;
      21           0 :   if( FD_UNLIKELY( !req_data_sz      ) ) return 0UL;
      22           0 :   if( FD_UNLIKELY( !dcache_footprint ) ) return 0UL;
      23             : 
      24           0 :   if( FD_UNLIKELY( mcache_footprint > INT_MAX ) ) return 0UL;
      25           0 :   if( FD_UNLIKELY( dcache_footprint > INT_MAX ) ) return 0UL;
      26             : 
      27             :   /* Keep this in sync with FD_QUIC_LOG_BUF_FOOTPRINT */
      28           0 :   ulong l = FD_LAYOUT_INIT;
      29           0 :   l = FD_LAYOUT_APPEND( l, FD_QUIC_LOG_BUF_ALIGN, sizeof(fd_quic_log_buf_t) );
      30           0 :   l = FD_LAYOUT_APPEND( l, FD_MCACHE_ALIGN,      mcache_footprint           );
      31           0 :   l = FD_LAYOUT_APPEND( l, FD_DCACHE_ALIGN,      dcache_footprint           );
      32           0 :   l = FD_LAYOUT_FINI( l, FD_QUIC_LOG_BUF_ALIGN );
      33           0 :   return l;
      34           0 : }
      35             : 
      36             : void *
      37             : fd_quic_log_buf_new( void * shmlog,
      38           0 :                      ulong  depth ) {
      39             : 
      40           0 :   depth = fd_ulong_max( depth, FD_MCACHE_BLOCK );
      41           0 :   if( FD_UNLIKELY( !shmlog ) ) {
      42           0 :     FD_LOG_WARNING(( "NULL shmlog" ));
      43           0 :     return NULL;
      44           0 :   }
      45           0 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shmlog, FD_QUIC_LOG_BUF_ALIGN ) ) ) {
      46           0 :     FD_LOG_WARNING(( "misaligned shmlog" ));
      47           0 :     return NULL;
      48           0 :   }
      49           0 :   ulong sz = fd_quic_log_buf_footprint( depth );
      50           0 :   if( FD_UNLIKELY( !sz ) ) {
      51           0 :     FD_LOG_WARNING(( "invalid footprint for depth %lu", depth ));
      52           0 :     return NULL;
      53           0 :   }
      54           0 :   fd_memset( shmlog, 0, sz );
      55             : 
      56             :   /* Keep this in sync with FD_QUIC_LOG_BUF_FOOTPRINT */
      57           0 :   ulong mcache_footprint = fd_mcache_footprint( depth, 0 );
      58           0 :   ulong req_data_sz      = fd_dcache_req_data_sz( FD_QUIC_LOG_MTU, depth, 1, 1 );
      59           0 :   ulong dcache_footprint = fd_dcache_footprint( req_data_sz, 0UL );
      60           0 :   FD_SCRATCH_ALLOC_INIT( l, shmlog );
      61           0 :   fd_quic_log_buf_t * log       = FD_SCRATCH_ALLOC_APPEND( l, FD_QUIC_LOG_BUF_ALIGN, sizeof(fd_quic_log_buf_t) );
      62           0 :   void *             mcache_mem = FD_SCRATCH_ALLOC_APPEND( l, FD_MCACHE_ALIGN,       mcache_footprint          );
      63           0 :   void *             dcache_mem = FD_SCRATCH_ALLOC_APPEND( l, FD_DCACHE_ALIGN,       dcache_footprint          );
      64           0 :   FD_SCRATCH_ALLOC_FINI( l, FD_QUIC_LOG_BUF_ALIGN );
      65             : 
      66           0 :   ulong            seq0   = 0UL;
      67           0 :   fd_frag_meta_t * mcache = fd_mcache_join( fd_mcache_new( mcache_mem, depth, 0UL, seq0 ) );
      68           0 :   void *           dcache = fd_dcache_join( fd_dcache_new( dcache_mem, req_data_sz, 0UL ) );
      69           0 :   if( FD_UNLIKELY( !mcache ) ) return NULL;
      70           0 :   if( FD_UNLIKELY( !dcache ) ) return NULL;
      71           0 :   fd_mcache_seq_laddr( mcache )[0] = seq0;
      72             : 
      73           0 :   uint chunk0 = (uint)fd_dcache_compact_chunk0( log, dcache );
      74           0 :   uint wmark  = (uint)fd_dcache_compact_wmark ( log, dcache, FD_QUIC_LOG_MTU );
      75           0 :   uint chunk1 = (uint)fd_dcache_compact_chunk1( log, dcache );
      76             : 
      77           0 :   *log = (fd_quic_log_buf_t) {
      78           0 :     .abi = {
      79           0 :       .magic      = 0UL,
      80           0 :       .mcache_off = (uint)( (ulong)mcache_mem - (ulong)log ),
      81           0 :       .chunk0     = chunk0,
      82           0 :       .chunk1     = chunk1
      83           0 :     },
      84           0 :     .dcache_off = (uint)( (ulong)dcache_mem - (ulong)log ),
      85           0 :     .chunk0     = chunk0,
      86           0 :     .wmark      = wmark,
      87           0 :   };
      88             : 
      89           0 :   FD_COMPILER_MFENCE();
      90           0 :   log->magic = FD_QUIC_LOG_BUF_MAGIC;
      91           0 :   FD_COMPILER_MFENCE();
      92           0 :   log->abi.magic = FD_QUIC_LOG_MAGIC;
      93           0 :   FD_COMPILER_MFENCE();
      94             : 
      95           0 :   return shmlog;
      96           0 : }
      97             : 
      98             : void *
      99           0 : fd_quic_log_buf_delete( void * shmlog ) {
     100           0 :   if( FD_UNLIKELY( !shmlog ) ) {
     101           0 :     FD_LOG_WARNING(( "NULL shmlog" ));
     102           0 :     return NULL;
     103           0 :   }
     104           0 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shmlog, FD_QUIC_LOG_BUF_ALIGN ) ) ) {
     105           0 :     FD_LOG_WARNING(( "misaligned shmlog" ));
     106           0 :     return NULL;
     107           0 :   }
     108             : 
     109           0 :   fd_quic_log_buf_t * log = shmlog;
     110           0 :   if( FD_UNLIKELY( log->magic!=FD_QUIC_LOG_BUF_MAGIC ) ) {
     111           0 :     FD_LOG_WARNING(( "bad magic" ));
     112           0 :   }
     113             : 
     114           0 :   void * mcache_mem = (void *)( (ulong)log + log->abi.mcache_off );
     115           0 :   fd_mcache_delete( mcache_mem );
     116             : 
     117           0 :   void * dcache_mem = (void *)( (ulong)log + log->dcache_off );
     118           0 :   fd_dcache_delete( dcache_mem );
     119             : 
     120           0 :   log->abi.magic = 0UL;
     121           0 :   FD_COMPILER_MFENCE();
     122           0 :   log->magic = 0UL;
     123           0 :   FD_COMPILER_MFENCE();
     124           0 :   return log;
     125           0 : }
     126             : 
     127             : /* fd_quic_log_tx API *************************************************/
     128             : 
     129             : fd_quic_log_tx_t *
     130             : fd_quic_log_tx_join( fd_quic_log_tx_t * tx,
     131           0 :                      void *             shmlog ) {
     132             : 
     133           0 :   if( FD_UNLIKELY( !shmlog ) ) {
     134           0 :     FD_LOG_WARNING(( "NULL shmlog" ));
     135           0 :     return NULL;
     136           0 :   }
     137           0 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shmlog, FD_QUIC_LOG_BUF_ALIGN ) ) ) {
     138           0 :     FD_LOG_WARNING(( "misaligned shmlog" ));
     139           0 :     return NULL;
     140           0 :   }
     141             : 
     142           0 :   fd_quic_log_buf_t * log = shmlog;
     143           0 :   if( FD_UNLIKELY( log->magic != FD_QUIC_LOG_BUF_MAGIC ) ) {
     144           0 :     FD_LOG_WARNING(( "bad magic" ));
     145           0 :     return NULL;
     146           0 :   }
     147             : 
     148           0 :   fd_frag_meta_t * mcache = fd_mcache_join( (void *)( (ulong)log + log->abi.mcache_off ) );
     149           0 :   if( FD_UNLIKELY( !mcache ) ) return NULL;
     150           0 :   void *           dcache = fd_dcache_join( (void *)( (ulong)log + log->dcache_off     ) );
     151           0 :   if( FD_UNLIKELY( !dcache ) ) return NULL;
     152             : 
     153           0 :   ulong * mcache_seq = fd_mcache_seq_laddr( mcache );
     154             : 
     155           0 :   *tx = (fd_quic_log_tx_t) {
     156           0 :     .mcache     = mcache,
     157           0 :     .mcache_seq = mcache_seq,
     158           0 :     .base       = shmlog,
     159           0 :     .depth      = fd_mcache_depth( mcache ),
     160           0 :     .seq        = mcache_seq[0],
     161           0 :     .chunk      = log->chunk0,
     162           0 :     .chunk0     = log->chunk0,
     163           0 :     .wmark      = log->wmark,
     164           0 :   };
     165           0 :   return tx;
     166           0 : }
     167             : 
     168             : void *
     169           0 : fd_quic_log_tx_leave( fd_quic_log_tx_t * log ) {
     170           0 :   if( FD_UNLIKELY( !log ) ) {
     171           0 :     FD_LOG_WARNING(( "NULL log" ));
     172           0 :     return NULL;
     173           0 :   }
     174           0 :   fd_quic_log_tx_seq_update( log );
     175           0 :   memset( log, 0, sizeof(fd_quic_log_tx_t) );
     176           0 :   return log;
     177           0 : }
     178             : 
     179             : /* fd_quic_log_rx API *************************************************/
     180             : 
     181             : fd_quic_log_rx_t *
     182             : fd_quic_log_rx_join( fd_quic_log_rx_t * rx,
     183           0 :                      void *             shmlog ) {
     184             : 
     185           0 :   if( FD_UNLIKELY( !shmlog ) ) {
     186           0 :     FD_LOG_WARNING(( "NULL shmlog" ));
     187           0 :     return NULL;
     188           0 :   }
     189           0 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shmlog, FD_QUIC_LOG_ALIGN ) ) ) {
     190           0 :     FD_LOG_WARNING(( "misaligned shmlog" ));
     191           0 :     return NULL;
     192           0 :   }
     193             : 
     194           0 :   fd_quic_log_abi_t * abi = shmlog;
     195           0 :   if( FD_UNLIKELY( abi->magic != FD_QUIC_LOG_MAGIC ) ) {
     196           0 :     FD_LOG_WARNING(( "bad magic" ));
     197           0 :     return NULL;
     198           0 :   }
     199             : 
     200           0 :   fd_frag_meta_t * mcache = fd_mcache_join( (void *)( (ulong)shmlog + abi->mcache_off ) );
     201           0 :   if( FD_UNLIKELY( !mcache ) ) return NULL;
     202           0 :   ulong const * mcache_seq = fd_mcache_seq_laddr_const( mcache );
     203             : 
     204           0 :   void * base = shmlog;
     205           0 :   ulong  seq  = fd_mcache_seq_query( mcache_seq );
     206             : 
     207           0 :   *rx = (fd_quic_log_rx_t) {
     208           0 :     .mcache        = mcache,
     209           0 :     .mcache_seq    = mcache_seq,
     210           0 :     .base          = base,
     211           0 :     .data_lo_laddr = (ulong)fd_chunk_to_laddr_const( base, abi->chunk0 ),
     212           0 :     .data_hi_laddr = (ulong)fd_chunk_to_laddr_const( base, abi->chunk1 ),
     213           0 :     .depth         = fd_mcache_depth( mcache ),
     214           0 :     .seq           = seq
     215           0 :   };
     216           0 :   return rx;
     217           0 : }
     218             : 
     219             : void *
     220           0 : fd_quic_log_rx_leave( fd_quic_log_rx_t * log ) {
     221           0 :   if( FD_UNLIKELY( !log ) ) {
     222           0 :     FD_LOG_WARNING(( "NULL log" ));
     223           0 :     return NULL;
     224           0 :   }
     225           0 :   memset( log, 0, sizeof(fd_quic_log_rx_t) );
     226           0 :   return log;
     227           0 : }

Generated by: LCOV version 1.14