aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf
diff options
context:
space:
mode:
authorMartin KaFai Lau <kafai@fb.com>2018-07-24 11:40:21 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-07-25 00:57:55 -0400
commit5b891af7fca14526b2a87c6f38b004e2df655ef4 (patch)
tree9710ef3659b4eddc8d1ab40ae5c7ddd177387f16 /tools/lib/bpf
parent64bb568488671048d25d7b3ada058bb6c7cb1d5d (diff)
bpf: Replace [u]int32_t and [u]int64_t in libbpf
This patch replaces [u]int32_t and [u]int64_t usage with __[su]32 and __[su]64. The same change goes for [u]int16_t and [u]int8_t. Fixes: 8a138aed4a80 ("bpf: btf: Add BTF support to libbpf") Signed-off-by: Martin KaFai Lau <kafai@fb.com> Acked-by: Yonghong Song <yhs@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r--tools/lib/bpf/btf.c34
-rw-r--r--tools/lib/bpf/btf.h8
-rw-r--r--tools/lib/bpf/libbpf.c12
-rw-r--r--tools/lib/bpf/libbpf.h4
4 files changed, 28 insertions, 30 deletions
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 8c54a4b6f187..b80de80b4584 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -2,7 +2,6 @@
2/* Copyright (c) 2018 Facebook */ 2/* Copyright (c) 2018 Facebook */
3 3
4#include <stdlib.h> 4#include <stdlib.h>
5#include <stdint.h>
6#include <string.h> 5#include <string.h>
7#include <unistd.h> 6#include <unistd.h>
8#include <errno.h> 7#include <errno.h>
@@ -27,13 +26,13 @@ struct btf {
27 struct btf_type **types; 26 struct btf_type **types;
28 const char *strings; 27 const char *strings;
29 void *nohdr_data; 28 void *nohdr_data;
30 uint32_t nr_types; 29 __u32 nr_types;
31 uint32_t types_size; 30 __u32 types_size;
32 uint32_t data_size; 31 __u32 data_size;
33 int fd; 32 int fd;
34}; 33};
35 34
36static const char *btf_name_by_offset(const struct btf *btf, uint32_t offset) 35static const char *btf_name_by_offset(const struct btf *btf, __u32 offset)
37{ 36{
38 if (offset < btf->hdr->str_len) 37 if (offset < btf->hdr->str_len)
39 return &btf->strings[offset]; 38 return &btf->strings[offset];
@@ -45,7 +44,7 @@ static int btf_add_type(struct btf *btf, struct btf_type *t)
45{ 44{
46 if (btf->types_size - btf->nr_types < 2) { 45 if (btf->types_size - btf->nr_types < 2) {
47 struct btf_type **new_types; 46 struct btf_type **new_types;
48 u32 expand_by, new_size; 47 __u32 expand_by, new_size;
49 48
50 if (btf->types_size == BTF_MAX_NR_TYPES) 49 if (btf->types_size == BTF_MAX_NR_TYPES)
51 return -E2BIG; 50 return -E2BIG;
@@ -72,7 +71,7 @@ static int btf_add_type(struct btf *btf, struct btf_type *t)
72static int btf_parse_hdr(struct btf *btf, btf_print_fn_t err_log) 71static int btf_parse_hdr(struct btf *btf, btf_print_fn_t err_log)
73{ 72{
74 const struct btf_header *hdr = btf->hdr; 73 const struct btf_header *hdr = btf->hdr;
75 u32 meta_left; 74 __u32 meta_left;
76 75
77 if (btf->data_size < sizeof(struct btf_header)) { 76 if (btf->data_size < sizeof(struct btf_header)) {
78 elog("BTF header not found\n"); 77 elog("BTF header not found\n");
@@ -151,7 +150,7 @@ static int btf_parse_type_sec(struct btf *btf, btf_print_fn_t err_log)
151 150
152 while (next_type < end_type) { 151 while (next_type < end_type) {
153 struct btf_type *t = next_type; 152 struct btf_type *t = next_type;
154 uint16_t vlen = BTF_INFO_VLEN(t->info); 153 __u16 vlen = BTF_INFO_VLEN(t->info);
155 int err; 154 int err;
156 155
157 next_type += sizeof(*t); 156 next_type += sizeof(*t);
@@ -191,7 +190,7 @@ static int btf_parse_type_sec(struct btf *btf, btf_print_fn_t err_log)
191} 190}
192 191
193static const struct btf_type *btf_type_by_id(const struct btf *btf, 192static const struct btf_type *btf_type_by_id(const struct btf *btf,
194 uint32_t type_id) 193 __u32 type_id)
195{ 194{
196 if (type_id > btf->nr_types) 195 if (type_id > btf->nr_types)
197 return NULL; 196 return NULL;
@@ -209,7 +208,7 @@ static bool btf_type_is_void_or_null(const struct btf_type *t)
209 return !t || btf_type_is_void(t); 208 return !t || btf_type_is_void(t);
210} 209}
211 210
212static int64_t btf_type_size(const struct btf_type *t) 211static __s64 btf_type_size(const struct btf_type *t)
213{ 212{
214 switch (BTF_INFO_KIND(t->info)) { 213 switch (BTF_INFO_KIND(t->info)) {
215 case BTF_KIND_INT: 214 case BTF_KIND_INT:
@@ -226,12 +225,12 @@ static int64_t btf_type_size(const struct btf_type *t)
226 225
227#define MAX_RESOLVE_DEPTH 32 226#define MAX_RESOLVE_DEPTH 32
228 227
229int64_t btf__resolve_size(const struct btf *btf, uint32_t type_id) 228__s64 btf__resolve_size(const struct btf *btf, __u32 type_id)
230{ 229{
231 const struct btf_array *array; 230 const struct btf_array *array;
232 const struct btf_type *t; 231 const struct btf_type *t;
233 uint32_t nelems = 1; 232 __u32 nelems = 1;
234 int64_t size = -1; 233 __s64 size = -1;
235 int i; 234 int i;
236 235
237 t = btf_type_by_id(btf, type_id); 236 t = btf_type_by_id(btf, type_id);
@@ -271,9 +270,9 @@ int64_t btf__resolve_size(const struct btf *btf, uint32_t type_id)
271 return nelems * size; 270 return nelems * size;
272} 271}
273 272
274int32_t btf__find_by_name(const struct btf *btf, const char *type_name) 273__s32 btf__find_by_name(const struct btf *btf, const char *type_name)
275{ 274{
276 uint32_t i; 275 __u32 i;
277 276
278 if (!strcmp(type_name, "void")) 277 if (!strcmp(type_name, "void"))
279 return 0; 278 return 0;
@@ -302,10 +301,9 @@ void btf__free(struct btf *btf)
302 free(btf); 301 free(btf);
303} 302}
304 303
305struct btf *btf__new(uint8_t *data, uint32_t size, 304struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log)
306 btf_print_fn_t err_log)
307{ 305{
308 uint32_t log_buf_size = 0; 306 __u32 log_buf_size = 0;
309 char *log_buf = NULL; 307 char *log_buf = NULL;
310 struct btf *btf; 308 struct btf *btf;
311 int err; 309 int err;
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 74bb344035bb..ed3a84370ccc 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -4,7 +4,7 @@
4#ifndef __BPF_BTF_H 4#ifndef __BPF_BTF_H
5#define __BPF_BTF_H 5#define __BPF_BTF_H
6 6
7#include <stdint.h> 7#include <linux/types.h>
8 8
9#define BTF_ELF_SEC ".BTF" 9#define BTF_ELF_SEC ".BTF"
10 10
@@ -14,9 +14,9 @@ typedef int (*btf_print_fn_t)(const char *, ...)
14 __attribute__((format(printf, 1, 2))); 14 __attribute__((format(printf, 1, 2)));
15 15
16void btf__free(struct btf *btf); 16void btf__free(struct btf *btf);
17struct btf *btf__new(uint8_t *data, uint32_t size, btf_print_fn_t err_log); 17struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log);
18int32_t btf__find_by_name(const struct btf *btf, const char *type_name); 18__s32 btf__find_by_name(const struct btf *btf, const char *type_name);
19int64_t btf__resolve_size(const struct btf *btf, uint32_t type_id); 19__s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
20int btf__fd(const struct btf *btf); 20int btf__fd(const struct btf *btf);
21 21
22#endif 22#endif
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index a1e96b5de5ff..6deb4fe4fffe 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -216,8 +216,8 @@ struct bpf_map {
216 size_t offset; 216 size_t offset;
217 int map_ifindex; 217 int map_ifindex;
218 struct bpf_map_def def; 218 struct bpf_map_def def;
219 uint32_t btf_key_type_id; 219 __u32 btf_key_type_id;
220 uint32_t btf_value_type_id; 220 __u32 btf_value_type_id;
221 void *priv; 221 void *priv;
222 bpf_map_clear_priv_t clear_priv; 222 bpf_map_clear_priv_t clear_priv;
223}; 223};
@@ -1016,8 +1016,8 @@ static int bpf_map_find_btf_info(struct bpf_map *map, const struct btf *btf)
1016{ 1016{
1017 struct bpf_map_def *def = &map->def; 1017 struct bpf_map_def *def = &map->def;
1018 const size_t max_name = 256; 1018 const size_t max_name = 256;
1019 int64_t key_size, value_size; 1019 __s64 key_size, value_size;
1020 int32_t key_id, value_id; 1020 __s32 key_id, value_id;
1021 char name[max_name]; 1021 char name[max_name];
1022 1022
1023 /* Find key type by name from BTF */ 1023 /* Find key type by name from BTF */
@@ -2089,12 +2089,12 @@ const char *bpf_map__name(struct bpf_map *map)
2089 return map ? map->name : NULL; 2089 return map ? map->name : NULL;
2090} 2090}
2091 2091
2092uint32_t bpf_map__btf_key_type_id(const struct bpf_map *map) 2092__u32 bpf_map__btf_key_type_id(const struct bpf_map *map)
2093{ 2093{
2094 return map ? map->btf_key_type_id : 0; 2094 return map ? map->btf_key_type_id : 0;
2095} 2095}
2096 2096
2097uint32_t bpf_map__btf_value_type_id(const struct bpf_map *map) 2097__u32 bpf_map__btf_value_type_id(const struct bpf_map *map)
2098{ 2098{
2099 return map ? map->btf_value_type_id : 0; 2099 return map ? map->btf_value_type_id : 0;
2100} 2100}
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 09976531aa74..b33ae02f7d0e 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -244,8 +244,8 @@ bpf_map__next(struct bpf_map *map, struct bpf_object *obj);
244int bpf_map__fd(struct bpf_map *map); 244int bpf_map__fd(struct bpf_map *map);
245const struct bpf_map_def *bpf_map__def(struct bpf_map *map); 245const struct bpf_map_def *bpf_map__def(struct bpf_map *map);
246const char *bpf_map__name(struct bpf_map *map); 246const char *bpf_map__name(struct bpf_map *map);
247uint32_t bpf_map__btf_key_type_id(const struct bpf_map *map); 247__u32 bpf_map__btf_key_type_id(const struct bpf_map *map);
248uint32_t bpf_map__btf_value_type_id(const struct bpf_map *map); 248__u32 bpf_map__btf_value_type_id(const struct bpf_map *map);
249 249
250typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); 250typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *);
251int bpf_map__set_priv(struct bpf_map *map, void *priv, 251int bpf_map__set_priv(struct bpf_map *map, void *priv,