LCOV - code coverage report
Current view: top level - util/sandbox - fd_pkeys.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 21 27 77.8 %
Date: 2026-09-15 04:28:45 Functions: 5 5 100.0 %

          Line data    Source code
       1             : #define _GNU_SOURCE
       2             : #include "fd_pkeys.h"
       3             : #include <errno.h>
       4             : #include <unistd.h>
       5             : #include <sys/mman.h>
       6             : #include <sys/syscall.h>
       7             : 
       8             : #if defined(__x86_64__)
       9             : #ifndef SYS_pkey_mprotect
      10             : #define SYS_pkey_mprotect 329
      11             : #endif
      12             : #ifndef SYS_pkey_alloc
      13             : #define SYS_pkey_alloc 330
      14             : #endif
      15             : #ifndef SYS_pkey_free
      16             : #define SYS_pkey_free 331
      17             : #endif
      18             : #endif
      19             : 
      20             : int
      21             : fd_syscall_pkey_alloc( uint flags,
      22           6 :                        uint access_rights ) {
      23           6 :   return (int)syscall( SYS_pkey_alloc, flags, access_rights );
      24           6 : }
      25             : 
      26             : int
      27             : fd_syscall_pkey_mprotect( void * addr,
      28             :                           ulong  size,
      29             :                           int    prot,
      30           6 :                           int    pkey ) {
      31           6 :   return (int)syscall( SYS_pkey_mprotect, addr, size, prot, pkey );
      32           6 : }
      33             : 
      34             : int
      35           6 : fd_syscall_pkey_free( int pkey ) {
      36           6 :   return (int)syscall( SYS_pkey_free, pkey );
      37           6 : }
      38             : 
      39             : int
      40             : fd_wksp_pkey_install( fd_wksp_t * wksp,
      41           6 :                       int         pkey ) {
      42           6 :   fd_shmem_join_info_t info[1];
      43           6 :   int err = fd_shmem_join_query_by_join( wksp, info );
      44           6 :   if( FD_UNLIKELY( err ) ) {
      45           0 :     FD_LOG_WARNING(( "failed to query shmem join info for wksp (err %i-%s)", err, fd_io_strerror( err ) ));
      46           0 :     return err;
      47           0 :   }
      48           6 :   return fd_shmem_pkey_install( info, pkey );
      49           6 : }
      50             : 
      51             : int
      52             : fd_shmem_pkey_install( fd_shmem_join_info_t const * join_info,
      53           6 :                        int                          pkey ) {
      54           6 :   int prot = PROT_READ;
      55           6 :   if( join_info->mode==FD_SHMEM_JOIN_MODE_READ_WRITE ) prot |= PROT_WRITE;
      56           6 :   if( FD_UNLIKELY( fd_syscall_pkey_mprotect( join_info->shmem, join_info->page_sz * join_info->page_cnt, prot, pkey ) ) ) {
      57           0 :     FD_LOG_WARNING(( "pkey_mprotect failed (err %i-%s)", errno, fd_io_strerror( errno ) ));
      58           0 :     return errno;
      59           0 :   }
      60           6 :   return 0;
      61           6 : }

Generated by: LCOV version 1.14