blob: f5ca142abf8f5ce7fa4faa4350e4c574f680ce78 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021, Oracle and/or its affiliates. */
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>
char _license[] SEC("license") = "GPL";
unsigned int exception_triggered;
int test_pid;
/* TRACE_EVENT(task_newtask,
* TP_PROTO(struct task_struct *p, u64 clone_flags)
*/
SEC("tp_btf/task_newtask")
int BPF_PROG(trace_task_newtask, struct task_struct *task, u64 clone_flags)
{
int pid = bpf_get_current_pid_tgid() >> 32;
struct callback_head *work;
void *func;
if (test_pid != pid)
return 0;
/* To verify we hit an exception we dereference task->task_works->func.
* If task work has been added,
* - task->task_works is non-NULL; and
* - task->task_works->func is non-NULL also (the callback function
* must be specified for the task work.
*
* However, for a newly-created task, task->task_works is NULLed,
* so we know the exception handler triggered if task_works is
* NULL and func is NULL.
*/
work = task->task_works;
func = work->func;
if (!work && !func)
exception_triggered++;
return 0;
}
|