liberty/support/specpriv-profile/api.cpp
// -------- Portable method to load an unsafe pointer -----
Portable method to load an unsafe pointer
Portable method to load an unsafe pointer
static bool __prof_safe_load(void *ptr, uint64_t *value_out, unsigned size_bytes)
  {
    pid_t result = fork();
    assert( result >= 0 && "fork() failed");
    if( result == 0 )
    {
      __prof_unsafe_load(ptr,size_bytes);
      _exit(0);
    }
    int status = ~0;
    waitpid(result, &status, 0);
    if( status == 0 )
    {
      *value_out = __prof_unsafe_load(ptr,size_bytes);
      return true;
    }
    else
    {
      return false;
    }
  }
static bool __prof_safe_load ( void * ptr , uint64_t * value_out , unsigned size_bytes ) { pid_t result = fork ( ) ; assert ( result >= 0 && " " ) ; if ( result == 0 ) { __prof_unsafe_load ( ptr , size_bytes ) ; _exit ( 0 ) ; } int status = ~ 0 ; waitpid ( result , & status , 0 ) ; if ( status == 0 ) { * value_out = __prof_unsafe_load ( ptr , size_bytes ) ; return true ; } else { return false ; } }
Portable method to load an unsafe pointer
Portable method to load an unsafe pointer
// I am the child process // No segfault: return a successful exit code. // I am the parent process // The child was able to perform this load // without segfaulting. // The child experienced a segfault while // performing this load.