LCOV - code coverage report
Current view: top level - util/sandbox - fd_pkeys.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 3 27 11.1 %
Date: 2026-05-18 08:34:01 Functions: 1 5 20.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           3 :                        uint access_rights ) {
      23           3 :   return (int)syscall( SYS_pkey_alloc, flags, access_rights );
      24           3 : }
      25             : 
      26             : int
      27             : fd_syscall_pkey_mprotect( void * addr,
      28             :                           ulong  size,
      29             :                           int    prot,
      30           0 :                           int    pkey ) {
      31           0 :   return (int)syscall( SYS_pkey_mprotect, addr, size, prot, pkey );
      32           0 : }
      33             : 
      34             : int
      35           0 : fd_syscall_pkey_free( int pkey ) {
      36           0 :   return (int)syscall( SYS_pkey_free, pkey );
      37           0 : }
      38             : 
      39             : int
      40             : fd_wksp_pkey_install( fd_wksp_t * wksp,
      41           0 :                       int         pkey ) {
      42           0 :   fd_shmem_join_info_t info[1];
      43           0 :   int err = fd_shmem_join_query_by_join( wksp, info );
      44           0 :   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           0 :   return fd_shmem_pkey_install( info, pkey );
      49           0 : }
      50             : 
      51             : int
      52             : fd_shmem_pkey_install( fd_shmem_join_info_t const * join_info,
      53           0 :                        int                          pkey ) {
      54           0 :   int prot = PROT_READ;
      55           0 :   if( join_info->mode==FD_SHMEM_JOIN_MODE_READ_WRITE ) prot |= PROT_WRITE;
      56           0 :   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           0 :   return 0;
      61           0 : }

Generated by: LCOV version 1.14