kcov: initial implementation

Implement a device (/dev/kcov) that exposes coverage info for the
kernel. This will be especially useful for coverage-based fuzzing (e.g.
syzkaller).

Exclude a lot of functions which would crash/otherwise interfere in the
coverage, including only processing coverage callbacks when not handling
an irq.
This commit is contained in:
Matheus
2026-10-06 11:05:58 -03:00
parent 111a8696d8
commit e4a4896b4b
14 changed files with 581 additions and 25 deletions
+9
View File
@@ -57,6 +57,10 @@ thread_t *sched_newthread(void *ip, size_t kstacksize, int nice, proc_t *proc, v
}
void sched_destroythread(thread_t *thread) {
#ifdef KCOV_ENABLED
if (thread->kcov)
kcov_release(thread->kcov);
#endif
mm_unmap(thread->kernelstack, thread->kernelstacksize, 0);
arch_extracontext_free(&thread->extracontext);
slab_free(thread_cache, thread);
@@ -101,6 +105,11 @@ __attribute__((noreturn)) void sched_threadexit() {
PROC_RELEASE(proc);
}
#ifdef KCOV_ENABLED
if (current_thread()->kcov)
kcov_set_mode(KCOV_MODE_DISABLED);
#endif
interrupt_set(false);
arch_context_saveandcall(threadexit_internal, current_cpu()->schedulerstack, NULL);
__builtin_unreachable();