src/UserSpaceInstrumentation/TrampolineTest.cpp
TEST_F(InstrumentFunctionTest, CheckIntParameters) {
  function_name_ = "CheckIntParameters";
  pid_ = fork();
  CHECK(pid_ != -1);
  if (pid_ == 0) {
    prctl(PR_SET_PDEATHSIG, SIGTERM);

    [[maybe_unused]] volatile uint64_t sum = 0;
    while (true) {
      sum += CheckIntParameters(0, 0, 0, 0, 0, 0, 0, 0);
      // Endless loops without side effects are UB and recent versions of clang optimize
      // it away.
    }
  }
  PrepareInstrumentation("EntryPayloadClobberParameterRegisters", kExitPayloadFunctionName);
  ErrorMessageOr<uint64_t> address_after_prologue_or_error = CreateTrampoline(
      pid_, function_address_, function_code_, trampoline_address_, entry_payload_function_address_,
      return_trampoline_address_, capstone_handle_, relocation_map_);
  EXPECT_THAT(address_after_prologue_or_error, HasNoError());
  ErrorMessageOr<void> result =
      InstrumentFunction(pid_, function_address_, /*function_id=*/42,
                         address_after_prologue_or_error.value(), trampoline_address_);
  EXPECT_THAT(result, HasNoError());
  RestartAndRemoveInstrumentation();
}
// This test and the two tests below check for proper handling of parameters handed to the
// instrumented function. The payload that is called before the instrumented function is executed
// clobbers the respective set of registers. So the Check*Parameter methods can check if the backup
// worked correctly.
This test and the two tests below check for proper handling of parameters handed to the
instrumented function. The payload that is called before the instrumented function is executed
clobbers the respective set of registers. So the Check*Parameter methods can check if the backup
worked correctly.
This test and the two tests below check for proper handling of parameters handed to the instrumented function . The payload that is called before the instrumented function is executed clobbers the respective set of registers . So the Check * Parameter methods can check if the backup worked correctly .
TEST_F(InstrumentFunctionTest, CheckIntParameters) {
  function_name_ = "CheckIntParameters";
  pid_ = fork();
  CHECK(pid_ != -1);
  if (pid_ == 0) {
    prctl(PR_SET_PDEATHSIG, SIGTERM);
    [[maybe_unused]] volatile uint64_t sum = 0;
    while (true) {
      sum += CheckIntParameters(0, 0, 0, 0, 0, 0, 0, 0);
    }
  }
  PrepareInstrumentation("EntryPayloadClobberParameterRegisters", kExitPayloadFunctionName);
  ErrorMessageOr<uint64_t> address_after_prologue_or_error = CreateTrampoline(
      pid_, function_address_, function_code_, trampoline_address_, entry_payload_function_address_,
      return_trampoline_address_, capstone_handle_, relocation_map_);
  EXPECT_THAT(address_after_prologue_or_error, HasNoError());
  ErrorMessageOr<void> result =
      InstrumentFunction(pid_, function_address_, 42,
                         address_after_prologue_or_error.value(), trampoline_address_);
  EXPECT_THAT(result, HasNoError());
  RestartAndRemoveInstrumentation();
}
TEST_F ( InstrumentFunctionTest , CheckIntParameters ) { function_name_ = " " ; pid_ = fork ( ) ; CHECK ( pid_ != -1 ) ; if ( pid_ == 0 ) { prctl ( PR_SET_PDEATHSIG , SIGTERM ) ; [[ maybe_unused ]] volatile uint64_t sum = 0 ; while ( true ) { sum += CheckIntParameters ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ; } } PrepareInstrumentation ( " " , kExitPayloadFunctionName ) ; ErrorMessageOr < uint64_t > address_after_prologue_or_error = CreateTrampoline ( pid_ , function_address_ , function_code_ , trampoline_address_ , entry_payload_function_address_ , return_trampoline_address_ , capstone_handle_ , relocation_map_ ) ; EXPECT_THAT ( address_after_prologue_or_error , HasNoError ( ) ) ; ErrorMessageOr < void > result = InstrumentFunction ( pid_ , function_address_ , 42 , address_after_prologue_or_error . value ( ) , trampoline_address_ ) ; EXPECT_THAT ( result , HasNoError ( ) ) ; RestartAndRemoveInstrumentation ( ) ; }
This test and the two tests below check for proper handling of parameters handed to the
instrumented function.
This test and the two tests below check for proper handling of parameters handed to the instrumented function .
// Endless loops without side effects are UB and recent versions of clang optimize // it away. /*function_id=*/