| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
/* |
| 3 |
* Define struct user_exit_info which is shared between BPF and userspace parts |
| 4 |
* to communicate exit status and other information. |
| 5 |
* |
| 6 |
* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. |
| 7 |
* Copyright (c) 2022 Tejun Heo <[email protected]> |
| 8 |
* Copyright (c) 2022 David Vernet <[email protected]> |
| 9 |
*/ |
| 10 |
|
| 11 |
#ifndef __USER_EXIT_INFO_BPF_H |
| 12 |
#define __USER_EXIT_INFO_BPF_H |
| 13 |
|
| 14 |
#ifndef LSP |
| 15 |
#include "vmlinux.h" |
| 16 |
#endif |
| 17 |
#include <bpf/bpf_core_read.h> |
| 18 |
|
| 19 |
#include "user_exit_info_common.h" |
| 20 |
|
| 21 |
#define UEI_DEFINE(__name) \ |
| 22 |
char RESIZABLE_ARRAY(data, __name##_dump); \ |
| 23 |
const volatile u32 __name##_dump_len; \ |
| 24 |
struct user_exit_info __name SEC(".data") |
| 25 |
|
| 26 |
#define UEI_RECORD(__uei_name, __ei) ({ \ |
| 27 |
bpf_probe_read_kernel_str(__uei_name.reason, \ |
| 28 |
sizeof(__uei_name.reason), (__ei)->reason); \ |
| 29 |
bpf_probe_read_kernel_str(__uei_name.msg, \ |
| 30 |
sizeof(__uei_name.msg), (__ei)->msg); \ |
| 31 |
bpf_probe_read_kernel_str(__uei_name##_dump, \ |
| 32 |
__uei_name##_dump_len, (__ei)->dump); \ |
| 33 |
if (bpf_core_field_exists((__ei)->exit_code)) \ |
| 34 |
__uei_name.exit_code = (__ei)->exit_code; \ |
| 35 |
/* use __sync to force memory barrier */ \ |
| 36 |
__sync_val_compare_and_swap(&__uei_name.kind, __uei_name.kind, \ |
| 37 |
(__ei)->kind); \ |
| 38 |
}) |
| 39 |
|
| 40 |
#endif /* __USER_EXIT_INFO_BPF_H */ |