diff --git a/runtime/src/bpf_helper.cpp b/runtime/src/bpf_helper.cpp index efd94fb8..49285484 100644 --- a/runtime/src/bpf_helper.cpp +++ b/runtime/src/bpf_helper.cpp @@ -103,13 +103,11 @@ thread_local static void (*origin_segv_write_handler)(int, siginfo_t *, static void segv_read_handler(int sig, siginfo_t *siginfo, void *ctx) { - SPDLOG_INFO("segv_handler for probe_read called"); if (status_probe_read == PROBE_STATUS::NOT_RUNNING) { - SPDLOG_INFO("segv_handler for probe_read called 2"); if (origin_segv_read_handler != nullptr) { origin_segv_read_handler(sig, siginfo, ctx); } else { - SPDLOG_INFO("segv_handler for probe_read called 3"); + SPDLOG_ERROR("no origin handler for probe_read"); throw std::runtime_error( "segv_handler for probe_read called"); } @@ -192,7 +190,9 @@ static void segv_write_handler(int sig, siginfo_t *siginfo, void *ctx) if (origin_segv_write_handler) { origin_segv_write_handler(sig, siginfo, ctx); } else { - abort(); + SPDLOG_ERROR("no origin handler for probe_write"); + throw std::runtime_error( + "segv_handler for probe_write called"); } } else if (status_probe_write == PROBE_STATUS::RUNNING_NO_ERROR) { // set status to error diff --git a/runtime/unit-test/test_probe.cpp b/runtime/unit-test/test_probe.cpp index 32544ebd..dab0ef1d 100644 --- a/runtime/unit-test/test_probe.cpp +++ b/runtime/unit-test/test_probe.cpp @@ -1,5 +1,6 @@ #include "catch2/catch_test_macros.hpp" #include "spdlog/spdlog.h" +#include #include #include #include @@ -83,4 +84,27 @@ TEST_CASE("Test Probe read/write size valid or not ") for (size_t i = 0; i < 4; i++) { REQUIRE(dst[i] == src[i]); } +} + + +TEST_CASE("Test origin handler is null") +{ + struct sigaction original_sa, sa; + int dst[4] = { 0 }; + int src[4] = { 1, 2, 3, 4 }; + sa.sa_flags = SA_SIGINFO; + sigemptyset(&sa.sa_mask); + sa.sa_sigaction = nullptr; + if (sigaction(SIGSEGV, &sa, nullptr) < 0) { + REQUIRE(false); + } + uint64_t size = sizeof(src); + + int ret = bpftime_probe_read((uint64_t)(dst), size, (uint64_t)(src), 0, + 0); + REQUIRE(ret == 0); + + sigaction(SIGSEGV, nullptr, &original_sa); + auto handler = original_sa.sa_sigaction; + REQUIRE(handler != nullptr); } \ No newline at end of file