Skip to content

Commit eb3f595

Browse files
iamkafaiborkmann
authored andcommitted
bpf: btf: Validate type reference
After collecting all btf_type in the first pass in an earlier patch, the second pass (in this patch) can validate the reference types (e.g. the referring type does exist and it does not refer to itself). While checking the reference type, it also gathers other information (e.g. the size of an array). This info will be useful in checking the struct's members in a later patch. They will also be useful in doing pretty print later. Signed-off-by: Martin KaFai Lau <kafai@fb.com> Acked-by: Alexei Starovoitov <ast@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 69b693f commit eb3f595

2 files changed

Lines changed: 702 additions & 1 deletion

File tree

‎include/linux/btf.h‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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;
10+
struct btf_type;
11+
12+
/* Figure out the size of a type_id. If type_id is a modifier
13+
* (e.g. const), it will be resolved to find out the type with size.
14+
*
15+
* For example:
16+
* In describing "const void *", type_id is "const" and "const"
17+
* refers to "void *". The return type will be "void *".
18+
*
19+
* If type_id is a simple "int", then return type will be "int".
20+
*
21+
* @btf: struct btf object
22+
* @type_id: Find out the size of type_id. The type_id of the return
23+
* type is set to *type_id.
24+
* @ret_size: It can be NULL. If not NULL, the size of the return
25+
* type is set to *ret_size.
26+
* Return: The btf_type (resolved to another type with size info if needed).
27+
* NULL is returned if type_id itself does not have size info
28+
* (e.g. void) or it cannot be resolved to another type that
29+
* has size info.
30+
* *type_id and *ret_size will not be changed in the
31+
* NULL return case.
32+
*/
33+
const struct btf_type *btf_type_id_size(const struct btf *btf,
34+
u32 *type_id,
35+
u32 *ret_size);
36+
37+
#endif

0 commit comments

Comments
 (0)