Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
| 2 | /* Copyright (c) 2018 Facebook */ |
| 3 | #ifndef _UAPI__LINUX_BTF_H__ |
| 4 | #define _UAPI__LINUX_BTF_H__ |
| 5 | |
| 6 | #include <linux/types.h> |
| 7 | |
| 8 | #define BTF_MAGIC 0xeB9F |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 9 | #define BTF_VERSION 1 |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 10 | |
| 11 | struct btf_header { |
| 12 | __u16 magic; |
| 13 | __u8 version; |
| 14 | __u8 flags; |
Martin KaFai Lau | f80442a | 2018-05-22 14:57:18 -0700 | [diff] [blame] | 15 | __u32 hdr_len; |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 16 | |
| 17 | /* All offsets are in bytes relative to the end of this header */ |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 18 | __u32 type_off; /* offset of type section */ |
Martin KaFai Lau | f80442a | 2018-05-22 14:57:18 -0700 | [diff] [blame] | 19 | __u32 type_len; /* length of type section */ |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 20 | __u32 str_off; /* offset of string section */ |
| 21 | __u32 str_len; /* length of string section */ |
| 22 | }; |
| 23 | |
| 24 | /* Max # of type identifier */ |
Martin KaFai Lau | aea2f7b8 | 2018-05-22 14:57:20 -0700 | [diff] [blame] | 25 | #define BTF_MAX_TYPE 0x0000ffff |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 26 | /* Max offset into the string section */ |
Martin KaFai Lau | aea2f7b8 | 2018-05-22 14:57:20 -0700 | [diff] [blame] | 27 | #define BTF_MAX_NAME_OFFSET 0x0000ffff |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 28 | /* Max # of struct/union/enum members or func args */ |
| 29 | #define BTF_MAX_VLEN 0xffff |
| 30 | |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 31 | struct btf_type { |
Martin KaFai Lau | fbcf93e | 2018-04-21 09:48:23 -0700 | [diff] [blame] | 32 | __u32 name_off; |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 33 | /* "info" bits arrangement |
| 34 | * bits 0-15: vlen (e.g. # of struct's members) |
| 35 | * bits 16-23: unused |
Martin KaFai Lau | aea2f7b8 | 2018-05-22 14:57:20 -0700 | [diff] [blame] | 36 | * bits 24-27: kind (e.g. int, ptr, array...etc) |
| 37 | * bits 28-31: unused |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 38 | */ |
| 39 | __u32 info; |
| 40 | /* "size" is used by INT, ENUM, STRUCT and UNION. |
| 41 | * "size" tells the size of the type it is describing. |
| 42 | * |
Martin KaFai Lau | 2667a26 | 2018-11-19 15:29:08 -0800 | [diff] [blame^] | 43 | * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT, |
| 44 | * FUNC and FUNC_PROTO. |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 45 | * "type" is a type_id referring to another type. |
| 46 | */ |
| 47 | union { |
| 48 | __u32 size; |
| 49 | __u32 type; |
| 50 | }; |
| 51 | }; |
| 52 | |
Martin KaFai Lau | aea2f7b8 | 2018-05-22 14:57:20 -0700 | [diff] [blame] | 53 | #define BTF_INFO_KIND(info) (((info) >> 24) & 0x0f) |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 54 | #define BTF_INFO_VLEN(info) ((info) & 0xffff) |
| 55 | |
| 56 | #define BTF_KIND_UNKN 0 /* Unknown */ |
| 57 | #define BTF_KIND_INT 1 /* Integer */ |
| 58 | #define BTF_KIND_PTR 2 /* Pointer */ |
| 59 | #define BTF_KIND_ARRAY 3 /* Array */ |
| 60 | #define BTF_KIND_STRUCT 4 /* Struct */ |
| 61 | #define BTF_KIND_UNION 5 /* Union */ |
| 62 | #define BTF_KIND_ENUM 6 /* Enumeration */ |
| 63 | #define BTF_KIND_FWD 7 /* Forward */ |
| 64 | #define BTF_KIND_TYPEDEF 8 /* Typedef */ |
| 65 | #define BTF_KIND_VOLATILE 9 /* Volatile */ |
| 66 | #define BTF_KIND_CONST 10 /* Const */ |
| 67 | #define BTF_KIND_RESTRICT 11 /* Restrict */ |
Martin KaFai Lau | 2667a26 | 2018-11-19 15:29:08 -0800 | [diff] [blame^] | 68 | #define BTF_KIND_FUNC 12 /* Function */ |
| 69 | #define BTF_KIND_FUNC_PROTO 13 /* Function Proto */ |
| 70 | #define BTF_KIND_MAX 13 |
| 71 | #define NR_BTF_KINDS 14 |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 72 | |
| 73 | /* For some specific BTF_KIND, "struct btf_type" is immediately |
| 74 | * followed by extra data. |
| 75 | */ |
| 76 | |
| 77 | /* BTF_KIND_INT is followed by a u32 and the following |
| 78 | * is the 32 bits arrangement: |
| 79 | */ |
Martin KaFai Lau | aea2f7b8 | 2018-05-22 14:57:20 -0700 | [diff] [blame] | 80 | #define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24) |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 81 | #define BTF_INT_OFFSET(VAL) (((VAL & 0x00ff0000)) >> 16) |
Martin KaFai Lau | 36fc3c8 | 2018-07-19 22:14:31 -0700 | [diff] [blame] | 82 | #define BTF_INT_BITS(VAL) ((VAL) & 0x000000ff) |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 83 | |
| 84 | /* Attributes stored in the BTF_INT_ENCODING */ |
Martin KaFai Lau | aea2f7b8 | 2018-05-22 14:57:20 -0700 | [diff] [blame] | 85 | #define BTF_INT_SIGNED (1 << 0) |
| 86 | #define BTF_INT_CHAR (1 << 1) |
| 87 | #define BTF_INT_BOOL (1 << 2) |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 88 | |
| 89 | /* BTF_KIND_ENUM is followed by multiple "struct btf_enum". |
| 90 | * The exact number of btf_enum is stored in the vlen (of the |
| 91 | * info in "struct btf_type"). |
| 92 | */ |
| 93 | struct btf_enum { |
Martin KaFai Lau | fbcf93e | 2018-04-21 09:48:23 -0700 | [diff] [blame] | 94 | __u32 name_off; |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 95 | __s32 val; |
| 96 | }; |
| 97 | |
| 98 | /* BTF_KIND_ARRAY is followed by one "struct btf_array" */ |
| 99 | struct btf_array { |
| 100 | __u32 type; |
| 101 | __u32 index_type; |
| 102 | __u32 nelems; |
| 103 | }; |
| 104 | |
| 105 | /* BTF_KIND_STRUCT and BTF_KIND_UNION are followed |
| 106 | * by multiple "struct btf_member". The exact number |
| 107 | * of btf_member is stored in the vlen (of the info in |
| 108 | * "struct btf_type"). |
| 109 | */ |
| 110 | struct btf_member { |
Martin KaFai Lau | fbcf93e | 2018-04-21 09:48:23 -0700 | [diff] [blame] | 111 | __u32 name_off; |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 112 | __u32 type; |
| 113 | __u32 offset; /* offset in bits */ |
| 114 | }; |
| 115 | |
Martin KaFai Lau | 2667a26 | 2018-11-19 15:29:08 -0800 | [diff] [blame^] | 116 | /* BTF_KIND_FUNC_PROTO is followed by multiple "struct btf_param". |
| 117 | * The exact number of btf_param is stored in the vlen (of the |
| 118 | * info in "struct btf_type"). |
| 119 | */ |
| 120 | struct btf_param { |
| 121 | __u32 name_off; |
| 122 | __u32 type; |
| 123 | }; |
| 124 | |
Martin KaFai Lau | 69b693f | 2018-04-18 15:55:57 -0700 | [diff] [blame] | 125 | #endif /* _UAPI__LINUX_BTF_H__ */ |