arch/riscv/kernel/tests/kprobes/test-kprobes.c
Source file repositories/reference/linux-study-clean/arch/riscv/kernel/tests/kprobes/test-kprobes.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/kernel/tests/kprobes/test-kprobes.c- Extension
.c- Size
- 1252 bytes
- Lines
- 60
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/kprobes.hkunit/test.htest-kprobes.h
Detected Declarations
function kprobe_dummy_handlerfunction test_kprobe_riscv
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
#include <linux/kernel.h>
#include <linux/kprobes.h>
#include <kunit/test.h>
#include "test-kprobes.h"
static int kprobe_dummy_handler(struct kprobe *kp, struct pt_regs *regs)
{
return 0;
}
static void test_kprobe_riscv(struct kunit *test)
{
unsigned int num_kprobe = 0;
long (*func)(void);
struct kprobe *kp;
int i;
while (test_kprobes_addresses[num_kprobe])
num_kprobe++;
kp = kzalloc_objs(*kp, num_kprobe);
KUNIT_EXPECT_TRUE(test, kp);
if (!kp)
return;
for (i = 0; i < num_kprobe; ++i) {
kp[i].addr = test_kprobes_addresses[i];
kp[i].pre_handler = kprobe_dummy_handler;
KUNIT_EXPECT_EQ(test, 0, register_kprobe(&kp[i]));
}
for (i = 0;; ++i) {
func = test_kprobes_functions[i];
if (!func)
break;
KUNIT_EXPECT_EQ_MSG(test, KPROBE_TEST_MAGIC, func(), "function %d broken", i);
}
for (i = 0; i < num_kprobe; ++i)
unregister_kprobe(&kp[i]);
kfree(kp);
}
static struct kunit_case kprobes_testcases[] = {
KUNIT_CASE(test_kprobe_riscv),
{}
};
static struct kunit_suite kprobes_test_suite = {
.name = "kprobes_riscv",
.test_cases = kprobes_testcases,
};
kunit_test_suites(&kprobes_test_suite);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("KUnit test for riscv kprobes");
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/kprobes.h`, `kunit/test.h`, `test-kprobes.h`.
- Detected declarations: `function kprobe_dummy_handler`, `function test_kprobe_riscv`.
- Atlas domain: Architecture Layer / arch/riscv.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.