blob: 972265f328717b8286edc2fc93c9d2a54ed394f8 [file] [log] [blame]
Martin KaFai Lau69b693f2018-04-18 15:55:57 -07001/* 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 Lau69b693f2018-04-18 15:55:57 -07009#define BTF_VERSION 1
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070010
11struct btf_header {
12 __u16 magic;
13 __u8 version;
14 __u8 flags;
Martin KaFai Lauf80442a2018-05-22 14:57:18 -070015 __u32 hdr_len;
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070016
17 /* All offsets are in bytes relative to the end of this header */
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070018 __u32 type_off; /* offset of type section */
Martin KaFai Lauf80442a2018-05-22 14:57:18 -070019 __u32 type_len; /* length of type section */
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070020 __u32 str_off; /* offset of string section */
21 __u32 str_len; /* length of string section */
22};
23
24/* Max # of type identifier */
Martin KaFai Lauaea2f7b82018-05-22 14:57:20 -070025#define BTF_MAX_TYPE 0x0000ffff
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070026/* Max offset into the string section */
Martin KaFai Lauaea2f7b82018-05-22 14:57:20 -070027#define BTF_MAX_NAME_OFFSET 0x0000ffff
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070028/* Max # of struct/union/enum members or func args */
29#define BTF_MAX_VLEN 0xffff
30
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070031struct btf_type {
Martin KaFai Laufbcf93e2018-04-21 09:48:23 -070032 __u32 name_off;
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070033 /* "info" bits arrangement
34 * bits 0-15: vlen (e.g. # of struct's members)
35 * bits 16-23: unused
Martin KaFai Lauaea2f7b82018-05-22 14:57:20 -070036 * bits 24-27: kind (e.g. int, ptr, array...etc)
37 * bits 28-31: unused
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070038 */
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 *
43 * "type" is used by PTR, TYPEDEF, VOLATILE, CONST and RESTRICT.
44 * "type" is a type_id referring to another type.
45 */
46 union {
47 __u32 size;
48 __u32 type;
49 };
50};
51
Martin KaFai Lauaea2f7b82018-05-22 14:57:20 -070052#define BTF_INFO_KIND(info) (((info) >> 24) & 0x0f)
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070053#define BTF_INFO_VLEN(info) ((info) & 0xffff)
54
55#define BTF_KIND_UNKN 0 /* Unknown */
56#define BTF_KIND_INT 1 /* Integer */
57#define BTF_KIND_PTR 2 /* Pointer */
58#define BTF_KIND_ARRAY 3 /* Array */
59#define BTF_KIND_STRUCT 4 /* Struct */
60#define BTF_KIND_UNION 5 /* Union */
61#define BTF_KIND_ENUM 6 /* Enumeration */
62#define BTF_KIND_FWD 7 /* Forward */
63#define BTF_KIND_TYPEDEF 8 /* Typedef */
64#define BTF_KIND_VOLATILE 9 /* Volatile */
65#define BTF_KIND_CONST 10 /* Const */
66#define BTF_KIND_RESTRICT 11 /* Restrict */
67#define BTF_KIND_MAX 11
68#define NR_BTF_KINDS 12
69
70/* For some specific BTF_KIND, "struct btf_type" is immediately
71 * followed by extra data.
72 */
73
74/* BTF_KIND_INT is followed by a u32 and the following
75 * is the 32 bits arrangement:
76 */
Martin KaFai Lauaea2f7b82018-05-22 14:57:20 -070077#define BTF_INT_ENCODING(VAL) (((VAL) & 0x0f000000) >> 24)
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070078#define BTF_INT_OFFSET(VAL) (((VAL & 0x00ff0000)) >> 16)
Martin KaFai Lau36fc3c82018-07-19 22:14:31 -070079#define BTF_INT_BITS(VAL) ((VAL) & 0x000000ff)
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070080
81/* Attributes stored in the BTF_INT_ENCODING */
Martin KaFai Lauaea2f7b82018-05-22 14:57:20 -070082#define BTF_INT_SIGNED (1 << 0)
83#define BTF_INT_CHAR (1 << 1)
84#define BTF_INT_BOOL (1 << 2)
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070085
86/* BTF_KIND_ENUM is followed by multiple "struct btf_enum".
87 * The exact number of btf_enum is stored in the vlen (of the
88 * info in "struct btf_type").
89 */
90struct btf_enum {
Martin KaFai Laufbcf93e2018-04-21 09:48:23 -070091 __u32 name_off;
Martin KaFai Lau69b693f2018-04-18 15:55:57 -070092 __s32 val;
93};
94
95/* BTF_KIND_ARRAY is followed by one "struct btf_array" */
96struct btf_array {
97 __u32 type;
98 __u32 index_type;
99 __u32 nelems;
100};
101
102/* BTF_KIND_STRUCT and BTF_KIND_UNION are followed
103 * by multiple "struct btf_member". The exact number
104 * of btf_member is stored in the vlen (of the info in
105 * "struct btf_type").
106 */
107struct btf_member {
Martin KaFai Laufbcf93e2018-04-21 09:48:23 -0700108 __u32 name_off;
Martin KaFai Lau69b693f2018-04-18 15:55:57 -0700109 __u32 type;
110 __u32 offset; /* offset in bits */
111};
112
113#endif /* _UAPI__LINUX_BTF_H__ */