tools/testing/selftests/bpf/progs/test_sleepable_tracepoints.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/test_sleepable_tracepoints.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/progs/test_sleepable_tracepoints.c
Extension
.c
Size
2414 bytes
Lines
113
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */

#include <vmlinux.h>
#include <asm/unistd.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>
#include <bpf/bpf_helpers.h>

char _license[] SEC("license") = "GPL";

int target_pid;
int prog_triggered;
long err;
char copied_byte;

static int copy_getcwd_arg(char *ubuf)
{
	err = bpf_copy_from_user(&copied_byte, sizeof(copied_byte), ubuf);
	if (err)
		return err;

	prog_triggered = 1;
	return 0;
}

SEC("tp_btf.s/sys_enter")
int BPF_PROG(handle_sys_enter_tp_btf, struct pt_regs *regs, long id)
{
	if ((bpf_get_current_pid_tgid() >> 32) != target_pid ||
	    id != __NR_getcwd)
		return 0;

	return copy_getcwd_arg((void *)PT_REGS_PARM1_SYSCALL(regs));
}

SEC("raw_tp.s/sys_enter")
int BPF_PROG(handle_sys_enter_raw_tp, struct pt_regs *regs, long id)
{
	if ((bpf_get_current_pid_tgid() >> 32) != target_pid ||
	    id != __NR_getcwd)
		return 0;

	return copy_getcwd_arg((void *)PT_REGS_PARM1_CORE_SYSCALL(regs));
}

SEC("tp.s/syscalls/sys_enter_getcwd")
int handle_sys_enter_tp(struct syscall_trace_enter *args)
{
	if ((bpf_get_current_pid_tgid() >> 32) != target_pid)
		return 0;

	return copy_getcwd_arg((void *)args->args[0]);
}

SEC("tp.s/syscalls/sys_exit_getcwd")
int handle_sys_exit_tp(struct syscall_trace_exit *args)
{
	struct pt_regs *regs;

	if ((bpf_get_current_pid_tgid() >> 32) != target_pid)
		return 0;

	regs = (struct pt_regs *)bpf_task_pt_regs(bpf_get_current_task_btf());
	return copy_getcwd_arg((void *)PT_REGS_PARM1_CORE_SYSCALL(regs));
}

SEC("raw_tp.s")
int BPF_PROG(handle_raw_tp_bare, struct pt_regs *regs, long id)
{
	return 0;
}

SEC("tp.s")
int handle_tp_bare(void *ctx)
{
	return 0;
}

SEC("tracepoint.s/syscalls/sys_enter_getcwd")
int handle_sys_enter_tp_alias(struct syscall_trace_enter *args)
{
	return 0;
}

SEC("raw_tracepoint.s/sys_enter")
int BPF_PROG(handle_sys_enter_raw_tp_alias, struct pt_regs *regs, long id)
{
	return 0;
}

Annotation

Implementation Notes