2021-06-07 02:15:07 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Patrick Meyer <git@the-space.agency>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Kernel/Devices/KCOVDevice.h>
|
2023-02-24 20:45:37 +03:00
|
|
|
#include <Kernel/Tasks/Thread.h>
|
2021-06-07 02:15:07 +03:00
|
|
|
|
|
|
|
extern bool g_in_early_boot;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
void __sanitizer_cov_trace_pc(void);
|
|
|
|
void __sanitizer_cov_trace_pc(void)
|
|
|
|
{
|
|
|
|
if (g_in_early_boot) [[unlikely]]
|
|
|
|
return;
|
|
|
|
|
2021-08-22 13:21:31 +03:00
|
|
|
if (Processor::current_in_irq()) [[unlikely]] {
|
2021-06-07 02:15:07 +03:00
|
|
|
// Do not trace in interrupts.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-29 03:01:27 +03:00
|
|
|
auto const* thread = Thread::current();
|
2021-06-07 02:15:07 +03:00
|
|
|
auto tid = thread->tid();
|
|
|
|
auto maybe_kcov_instance = KCOVDevice::thread_instance->get(tid);
|
|
|
|
if (!maybe_kcov_instance.has_value()) [[likely]] {
|
|
|
|
// not traced
|
|
|
|
return;
|
|
|
|
}
|
2021-12-29 03:01:27 +03:00
|
|
|
auto* kcov_instance = maybe_kcov_instance.value();
|
2021-09-06 01:31:48 +03:00
|
|
|
if (kcov_instance->state() < KCOVInstance::TRACING) [[likely]]
|
2021-06-07 02:15:07 +03:00
|
|
|
return;
|
|
|
|
kcov_instance->buffer_add_pc((u64)__builtin_return_address(0));
|
|
|
|
}
|
|
|
|
}
|