tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c- Extension
.c- Size
- 3239 bytes
- Lines
- 87
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
fcntl.hsys/prctl.htest_progs.hbpf_syscall_macro.skel.h
Detected Declarations
function test_bpf_syscall_macro
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright 2022 Sony Group Corporation */
#define _GNU_SOURCE
#include <fcntl.h>
#include <sys/prctl.h>
#include <test_progs.h>
#include "bpf_syscall_macro.skel.h"
void test_bpf_syscall_macro(void)
{
struct bpf_syscall_macro *skel = NULL;
int err;
int exp_arg1 = 1001;
unsigned long exp_arg2 = 12;
unsigned long exp_arg3 = 13;
unsigned long exp_arg4 = 14;
unsigned long exp_arg5 = 15;
loff_t off_in, off_out;
ssize_t r;
/* check whether it can open program */
skel = bpf_syscall_macro__open();
if (!ASSERT_OK_PTR(skel, "bpf_syscall_macro__open"))
return;
skel->rodata->filter_pid = getpid();
/* check whether it can load program */
err = bpf_syscall_macro__load(skel);
if (!ASSERT_OK(err, "bpf_syscall_macro__load"))
goto cleanup;
/* check whether it can attach kprobe */
err = bpf_syscall_macro__attach(skel);
if (!ASSERT_OK(err, "bpf_syscall_macro__attach"))
goto cleanup;
/* check whether args of syscall are copied correctly */
prctl(exp_arg1, exp_arg2, exp_arg3, exp_arg4, exp_arg5);
ASSERT_EQ(skel->bss->arg1, exp_arg1, "syscall_arg1");
ASSERT_EQ(skel->bss->arg2, exp_arg2, "syscall_arg2");
ASSERT_EQ(skel->bss->arg3, exp_arg3, "syscall_arg3");
/* it cannot copy arg4 when uses PT_REGS_PARM4 on x86_64 */
#ifdef __x86_64__
ASSERT_NEQ(skel->bss->arg4_cx, exp_arg4, "syscall_arg4_from_cx");
#else
ASSERT_EQ(skel->bss->arg4_cx, exp_arg4, "syscall_arg4_from_cx");
#endif
ASSERT_EQ(skel->bss->arg4, exp_arg4, "syscall_arg4");
ASSERT_EQ(skel->bss->arg5, exp_arg5, "syscall_arg5");
/* check whether args of syscall are copied correctly for CORE variants */
ASSERT_EQ(skel->bss->arg1_core, exp_arg1, "syscall_arg1_core_variant");
ASSERT_EQ(skel->bss->arg2_core, exp_arg2, "syscall_arg2_core_variant");
ASSERT_EQ(skel->bss->arg3_core, exp_arg3, "syscall_arg3_core_variant");
/* it cannot copy arg4 when uses PT_REGS_PARM4_CORE on x86_64 */
#ifdef __x86_64__
ASSERT_NEQ(skel->bss->arg4_core_cx, exp_arg4, "syscall_arg4_from_cx_core_variant");
#else
ASSERT_EQ(skel->bss->arg4_core_cx, exp_arg4, "syscall_arg4_from_cx_core_variant");
#endif
ASSERT_EQ(skel->bss->arg4_core, exp_arg4, "syscall_arg4_core_variant");
ASSERT_EQ(skel->bss->arg5_core, exp_arg5, "syscall_arg5_core_variant");
ASSERT_EQ(skel->bss->option_syscall, exp_arg1, "BPF_KPROBE_SYSCALL_option");
ASSERT_EQ(skel->bss->arg2_syscall, exp_arg2, "BPF_KPROBE_SYSCALL_arg2");
ASSERT_EQ(skel->bss->arg3_syscall, exp_arg3, "BPF_KPROBE_SYSCALL_arg3");
ASSERT_EQ(skel->bss->arg4_syscall, exp_arg4, "BPF_KPROBE_SYSCALL_arg4");
ASSERT_EQ(skel->bss->arg5_syscall, exp_arg5, "BPF_KPROBE_SYSCALL_arg5");
r = splice(-42, &off_in, 42, &off_out, 0x12340000, SPLICE_F_NONBLOCK);
err = -errno;
ASSERT_EQ(r, -1, "splice_res");
ASSERT_EQ(err, -EBADF, "splice_err");
ASSERT_EQ(skel->bss->splice_fd_in, -42, "splice_arg1");
ASSERT_EQ(skel->bss->splice_off_in, (__u64)&off_in, "splice_arg2");
ASSERT_EQ(skel->bss->splice_fd_out, 42, "splice_arg3");
ASSERT_EQ(skel->bss->splice_off_out, (__u64)&off_out, "splice_arg4");
ASSERT_EQ(skel->bss->splice_len, 0x12340000, "splice_arg5");
ASSERT_EQ(skel->bss->splice_flags, SPLICE_F_NONBLOCK, "splice_arg6");
cleanup:
bpf_syscall_macro__destroy(skel);
}
Annotation
- Immediate include surface: `fcntl.h`, `sys/prctl.h`, `test_progs.h`, `bpf_syscall_macro.skel.h`.
- Detected declarations: `function test_bpf_syscall_macro`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: core 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.