LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_borrowed_account.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 33 55 60.0 %
Date: 2024-11-13 11:58:15 Functions: 3 5 60.0 %

          Line data    Source code
       1             : #include "fd_borrowed_account.h"
       2             : #include "fd_acc_mgr.h"
       3             : 
       4             : fd_borrowed_account_t *
       5     4928817 : fd_borrowed_account_init( void * ptr ) {
       6     4928817 :   if( FD_UNLIKELY( !ptr ) ) {
       7           0 :     FD_LOG_WARNING(( "NULL ptr" ));
       8           0 :     return NULL;
       9           0 :   }
      10             : 
      11     4928817 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)ptr, alignof(fd_borrowed_account_t) ) ) ) {
      12           0 :     FD_LOG_WARNING(( "misaligned ptr" ));
      13           0 :     return NULL;
      14           0 :   }
      15             : 
      16     4928817 :   memset(ptr, 0, FD_BORROWED_ACCOUNT_FOOTPRINT);
      17             : 
      18     4928817 :   fd_borrowed_account_t * ret = (fd_borrowed_account_t *)ptr;
      19     4928817 :   ret->starting_dlen     = ULONG_MAX;
      20     4928817 :   ret->starting_lamports = ULONG_MAX;
      21             : 
      22     4928817 :   FD_COMPILER_MFENCE();
      23     4928817 :   ret->magic = FD_BORROWED_ACCOUNT_MAGIC;
      24     4928817 :   FD_COMPILER_MFENCE();
      25             : 
      26     4928817 :   return ret;
      27     4928817 : }
      28             : 
      29             : void
      30             : fd_borrowed_account_resize( fd_borrowed_account_t * borrowed_account,
      31        2838 :                             ulong                   dlen ) {
      32             :   
      33             :   /* Because the memory for an account is preallocated for the transaction
      34             :      up to the max account size, we only need to zero out bytes (for the case
      35             :      where the account grew) and update the account dlen. */
      36             :     
      37        2838 :     ulong old_sz    = borrowed_account->meta->dlen; 
      38        2838 :     ulong new_sz    = dlen;
      39        2838 :     ulong memset_sz = fd_ulong_sat_sub( new_sz, old_sz );
      40        2838 :     fd_memset( borrowed_account->data+old_sz, 0, memset_sz );
      41             : 
      42        2838 :     borrowed_account->meta->dlen = dlen;
      43        2838 : }
      44             : 
      45             : fd_borrowed_account_t *
      46             : fd_borrowed_account_make_modifiable( fd_borrowed_account_t * borrowed_account,
      47       31443 :                                      void *                  buf ) {
      48       31443 :   uchar * new_raw_data = (uchar *)buf;
      49       31443 :   if( borrowed_account->data != NULL ) {
      50           0 :     FD_LOG_ERR(( "borrowed account is already modifiable" ));
      51           0 :   }
      52             : 
      53       31443 :   ulong dlen = ( borrowed_account->const_meta != NULL ) ? borrowed_account->const_meta->dlen : 0;
      54             : 
      55       31443 :   if( borrowed_account->const_meta != NULL ) {
      56       25608 :     fd_memcpy( new_raw_data, (uchar *)borrowed_account->const_meta, sizeof(fd_account_meta_t)+dlen );
      57       25608 :   } else {
      58             :     /* Account did not exist, set up metadata */
      59        5835 :     fd_account_meta_init( (fd_account_meta_t *)new_raw_data );
      60        5835 :   }
      61             : 
      62       31443 :   borrowed_account->const_meta = borrowed_account->meta = (fd_account_meta_t *)new_raw_data;
      63       31443 :   borrowed_account->const_data = borrowed_account->data = new_raw_data + sizeof(fd_account_meta_t);
      64       31443 :   borrowed_account->meta->dlen = dlen;
      65             : 
      66       31443 :   return borrowed_account;
      67       31443 : }
      68             : 
      69             : void *
      70           0 : fd_borrowed_account_restore( fd_borrowed_account_t * borrowed_account ) {
      71           0 :   fd_account_meta_t * meta = borrowed_account->meta;
      72           0 :   uint is_changed = meta != borrowed_account->orig_meta;
      73             : 
      74           0 :   borrowed_account->const_meta = borrowed_account->orig_meta;
      75           0 :   borrowed_account->const_data = borrowed_account->orig_data;
      76           0 :   borrowed_account->const_rec = borrowed_account->orig_rec;
      77             : 
      78           0 :   if( is_changed ) {
      79           0 :     return meta;
      80           0 :   }
      81             : 
      82           0 :   return NULL;
      83           0 : }
      84             : 
      85             : void *
      86           0 : fd_borrowed_account_destroy( fd_borrowed_account_t * borrowed_account ) {
      87           0 :   return borrowed_account->meta;
      88           0 : }

Generated by: LCOV version 1.14