Martin KaFai Lau | eb3f595 | 2018-04-18 15:55:58 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* Copyright (c) 2018 Facebook */ |
| 3 | |
| 4 | #ifndef _LINUX_BTF_H |
| 5 | #define _LINUX_BTF_H 1 |
| 6 | |
| 7 | #include <linux/types.h> |
| 8 | |
| 9 | struct btf; |
Yonghong Song | ffa0c1c | 2018-12-15 22:13:52 -0800 | [diff] [blame] | 10 | struct btf_member; |
Martin KaFai Lau | eb3f595 | 2018-04-18 15:55:58 -0700 | [diff] [blame] | 11 | struct btf_type; |
Martin KaFai Lau | f56a653 | 2018-04-18 15:56:01 -0700 | [diff] [blame] | 12 | union bpf_attr; |
Martin KaFai Lau | eb3f595 | 2018-04-18 15:55:58 -0700 | [diff] [blame] | 13 | |
Martin KaFai Lau | 60197cf | 2018-04-18 15:56:02 -0700 | [diff] [blame] | 14 | extern const struct file_operations btf_fops; |
| 15 | |
Martin KaFai Lau | f56a653 | 2018-04-18 15:56:01 -0700 | [diff] [blame] | 16 | void btf_put(struct btf *btf); |
| 17 | int btf_new_fd(const union bpf_attr *attr); |
| 18 | struct btf *btf_get_by_fd(int fd); |
Martin KaFai Lau | 60197cf | 2018-04-18 15:56:02 -0700 | [diff] [blame] | 19 | int btf_get_info_by_fd(const struct btf *btf, |
| 20 | const union bpf_attr *attr, |
| 21 | union bpf_attr __user *uattr); |
Martin KaFai Lau | eb3f595 | 2018-04-18 15:55:58 -0700 | [diff] [blame] | 22 | /* Figure out the size of a type_id. If type_id is a modifier |
| 23 | * (e.g. const), it will be resolved to find out the type with size. |
| 24 | * |
| 25 | * For example: |
| 26 | * In describing "const void *", type_id is "const" and "const" |
| 27 | * refers to "void *". The return type will be "void *". |
| 28 | * |
| 29 | * If type_id is a simple "int", then return type will be "int". |
| 30 | * |
| 31 | * @btf: struct btf object |
| 32 | * @type_id: Find out the size of type_id. The type_id of the return |
| 33 | * type is set to *type_id. |
| 34 | * @ret_size: It can be NULL. If not NULL, the size of the return |
| 35 | * type is set to *ret_size. |
| 36 | * Return: The btf_type (resolved to another type with size info if needed). |
| 37 | * NULL is returned if type_id itself does not have size info |
| 38 | * (e.g. void) or it cannot be resolved to another type that |
| 39 | * has size info. |
| 40 | * *type_id and *ret_size will not be changed in the |
| 41 | * NULL return case. |
| 42 | */ |
| 43 | const struct btf_type *btf_type_id_size(const struct btf *btf, |
| 44 | u32 *type_id, |
| 45 | u32 *ret_size); |
Martin KaFai Lau | b00b8da | 2018-04-18 15:56:00 -0700 | [diff] [blame] | 46 | void btf_type_seq_show(const struct btf *btf, u32 type_id, void *obj, |
| 47 | struct seq_file *m); |
Martin KaFai Lau | 78958fc | 2018-05-04 14:49:51 -0700 | [diff] [blame] | 48 | int btf_get_fd_by_id(u32 id); |
| 49 | u32 btf_id(const struct btf *btf); |
Yonghong Song | ffa0c1c | 2018-12-15 22:13:52 -0800 | [diff] [blame] | 50 | bool btf_member_is_reg_int(const struct btf *btf, const struct btf_type *s, |
| 51 | const struct btf_member *m, |
| 52 | u32 expected_offset, u32 expected_size); |
Alexei Starovoitov | d83525c | 2019-01-31 15:40:04 -0800 | [diff] [blame] | 53 | int btf_find_spin_lock(const struct btf *btf, const struct btf_type *t); |
Daniel Borkmann | 2824ecb | 2019-04-09 23:20:10 +0200 | [diff] [blame^] | 54 | bool btf_type_is_void(const struct btf_type *t); |
Yonghong Song | f6161a8 | 2018-11-20 14:08:20 -0800 | [diff] [blame] | 55 | |
| 56 | #ifdef CONFIG_BPF_SYSCALL |
Yonghong Song | 838e969 | 2018-11-19 15:29:11 -0800 | [diff] [blame] | 57 | const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id); |
| 58 | const char *btf_name_by_offset(const struct btf *btf, u32 offset); |
Yonghong Song | f6161a8 | 2018-11-20 14:08:20 -0800 | [diff] [blame] | 59 | #else |
| 60 | static inline const struct btf_type *btf_type_by_id(const struct btf *btf, |
| 61 | u32 type_id) |
| 62 | { |
| 63 | return NULL; |
| 64 | } |
| 65 | static inline const char *btf_name_by_offset(const struct btf *btf, |
| 66 | u32 offset) |
| 67 | { |
| 68 | return NULL; |
| 69 | } |
| 70 | #endif |
Martin KaFai Lau | eb3f595 | 2018-04-18 15:55:58 -0700 | [diff] [blame] | 71 | |
| 72 | #endif |