2021-06-06 23:15:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Patrick Meyer <git@the-space.agency>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Kernel/Devices/KCOVDevice.h>
|
2023-02-24 17:45:37 +00:00
|
|
|
#include <Kernel/Tasks/Thread.h>
|
2021-06-06 23:15:07 +00: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 10:21:31 +00:00
|
|
|
if (Processor::current_in_irq()) [[unlikely]] {
|
2021-06-06 23:15:07 +00:00
|
|
|
// Do not trace in interrupts.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-29 00:01:27 +00:00
|
|
|
auto const* thread = Thread::current();
|
2021-06-06 23:15:07 +00: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 00:01:27 +00:00
|
|
|
auto* kcov_instance = maybe_kcov_instance.value();
|
2021-09-05 22:31:48 +00:00
|
|
|
if (kcov_instance->state() < KCOVInstance::TRACING) [[likely]]
|
2021-06-06 23:15:07 +00:00
|
|
|
return;
|
|
|
|
kcov_instance->buffer_add_pc((u64)__builtin_return_address(0));
|
|
|
|
}
|
|
|
|
}
|