LCOV - code coverage report
Current view: top level - discof/exec - fd_exec_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 69 0.0 %
Date: 2025-03-20 12:08:36 Functions: 0 8 0.0 %

          Line data    Source code
       1             : #define _GNU_SOURCE
       2             : 
       3             : #include "../../disco/tiles.h"
       4             : #include "generated/fd_exec_tile_seccomp.h"
       5             : 
       6             : struct fd_exec_tile_ctx {
       7             :   ulong  replay_exec_in_idx;
       8             :   ulong  tile_cnt;
       9             :   ulong  tile_idx;
      10             : 
      11             :   fd_wksp_t * replay_in_mem;
      12             :   ulong       replay_in_chunk0;
      13             :   ulong       replay_in_wmark;
      14             : 
      15             :   fd_txn_p_t txn; /* current txn */
      16             : };
      17             : typedef struct fd_exec_tile_ctx fd_exec_tile_ctx_t;
      18             : 
      19             : FD_FN_CONST static inline ulong
      20           0 : scratch_align( void ) {
      21           0 :   return 128UL;
      22           0 : }
      23             : 
      24             : FD_FN_PURE static inline ulong
      25           0 : scratch_footprint( fd_topo_tile_t const * tile FD_PARAM_UNUSED ) {
      26             :   /* clang-format off */
      27           0 :   ulong l = FD_LAYOUT_INIT;
      28           0 :   l       = FD_LAYOUT_APPEND( l, alignof(fd_exec_tile_ctx_t), sizeof(fd_exec_tile_ctx_t) );
      29           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
      30             :   /* clang-format on */
      31           0 : }
      32             : 
      33             : static void
      34             : during_frag( fd_exec_tile_ctx_t * ctx,
      35             :              ulong                in_idx,
      36             :              ulong                seq FD_PARAM_UNUSED,
      37             :              ulong                sig FD_PARAM_UNUSED,
      38             :              ulong                chunk,
      39             :              ulong                sz,
      40           0 :              ulong                ctl FD_PARAM_UNUSED ) {
      41             : 
      42           0 :   if( FD_UNLIKELY( in_idx == ctx->replay_exec_in_idx ) ) {
      43           0 :     if( FD_UNLIKELY( chunk < ctx->replay_in_chunk0 || chunk > ctx->replay_in_wmark ) ) {
      44           0 :       FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]",
      45           0 :                     chunk,
      46           0 :                     sz,
      47           0 :                     ctx->replay_in_chunk0,
      48           0 :                     ctx->replay_in_wmark ));
      49           0 :     }
      50           0 :     uchar * txn = fd_chunk_to_laddr( ctx->replay_in_mem, chunk );
      51           0 :     fd_memcpy( &ctx->txn, txn, sz );
      52           0 :     FD_LOG_HEXDUMP_DEBUG(( "exec tile recieved txn: ", txn, sz ));
      53           0 :   }
      54           0 : }
      55             : 
      56             : static void
      57             : after_frag( fd_exec_tile_ctx_t * ctx FD_PARAM_UNUSED,
      58             :             ulong                in_idx FD_PARAM_UNUSED,
      59             :             ulong                seq,
      60             :             ulong                sig,
      61             :             ulong                sz,
      62             :             ulong                tsorig,
      63             :             ulong                tspub,
      64           0 :             fd_stem_context_t *  stem ) {
      65           0 :   (void)seq;
      66           0 :   (void)sig;
      67           0 :   (void)sz;
      68           0 :   (void)tsorig;
      69           0 :   (void)tspub;
      70           0 :   (void)stem;
      71           0 : }
      72             : 
      73             : static void
      74             : privileged_init( fd_topo_t *      topo FD_PARAM_UNUSED,
      75           0 :                  fd_topo_tile_t * tile FD_PARAM_UNUSED ) {
      76           0 : }
      77             : 
      78             : static void
      79             : unprivileged_init( fd_topo_t *      topo,
      80           0 :                    fd_topo_tile_t * tile ) {
      81           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
      82             : 
      83           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
      84           0 :   fd_exec_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_exec_tile_ctx_t), sizeof(fd_exec_tile_ctx_t) );
      85             : 
      86           0 :   ctx->tile_cnt = fd_topo_tile_name_cnt( topo, tile->name );
      87           0 :   ctx->tile_idx = tile->kind_id;
      88             : 
      89           0 :   ctx->replay_exec_in_idx = fd_topo_find_tile_in_link( topo, tile, "replay_exec", ctx->tile_idx );
      90           0 :   FD_TEST( ctx->replay_exec_in_idx != ULONG_MAX );
      91           0 :   fd_topo_link_t * replay_exec_in_link = &topo->links[tile->in_link_id[ctx->replay_exec_in_idx]];
      92           0 :   ctx->replay_in_mem = topo->workspaces[topo->objs[replay_exec_in_link->dcache_obj_id].wksp_id].wksp;
      93           0 :   ctx->replay_in_chunk0 = fd_dcache_compact_chunk0( ctx->replay_in_mem, replay_exec_in_link->dcache );
      94           0 :   ctx->replay_in_wmark  = fd_dcache_compact_wmark( ctx->replay_in_mem,
      95           0 :                                                    replay_exec_in_link->dcache,
      96           0 :                                                    replay_exec_in_link->mtu );
      97             : 
      98           0 :   FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
      99           0 : }
     100             : 
     101             : static ulong
     102             : populate_allowed_seccomp( fd_topo_t const *      topo,
     103             :                           fd_topo_tile_t const * tile,
     104             :                           ulong                  out_cnt,
     105           0 :                           struct sock_filter *   out ) {
     106           0 :   (void)topo;
     107           0 :   (void)tile;
     108             : 
     109           0 :   populate_sock_filter_policy_fd_exec_tile( out_cnt, out, (uint)fd_log_private_logfile_fd() );
     110           0 :   return sock_filter_policy_fd_exec_tile_instr_cnt;
     111           0 : }
     112             : 
     113             : static ulong
     114             : populate_allowed_fds( fd_topo_t const *      topo,
     115             :                       fd_topo_tile_t const * tile,
     116             :                       ulong                  out_fds_cnt,
     117           0 :                       int *                  out_fds ) {
     118           0 :   (void)topo;
     119           0 :   (void)tile;
     120             : 
     121           0 :   if( FD_UNLIKELY( out_fds_cnt<2UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
     122             : 
     123           0 :   ulong out_cnt = 0UL;
     124           0 :   out_fds[ out_cnt++ ] = 2; /* stderr */
     125           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
     126           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
     127           0 :   return out_cnt;
     128           0 : }
     129             : 
     130             : 
     131           0 : #define STEM_BURST (1UL)
     132             : 
     133           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_exec_tile_ctx_t
     134           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_exec_tile_ctx_t)
     135             : 
     136           0 : #define STEM_CALLBACK_DURING_FRAG during_frag
     137           0 : #define STEM_CALLBACK_AFTER_FRAG  after_frag
     138             : 
     139             : #include "../../disco/stem/fd_stem.c"
     140             : 
     141             : fd_topo_run_tile_t fd_tile_execor = {
     142             :     .name                     = "exec",
     143             :     .loose_footprint          = 0UL,
     144             :     .populate_allowed_seccomp = populate_allowed_seccomp,
     145             :     .populate_allowed_fds     = populate_allowed_fds,
     146             :     .scratch_align            = scratch_align,
     147             :     .scratch_footprint        = scratch_footprint,
     148             :     .privileged_init          = privileged_init,
     149             :     .unprivileged_init        = unprivileged_init,
     150             :     .run                      = stem_run,
     151             : };

Generated by: LCOV version 1.14