rename BPF_FD_TO_INT() macro to BPF_FD_TO_U32() am: 38fb4300fb

Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/1514873

Change-Id: I3c4f2d978724eda11659b7d71238dfaa6c0d5350
This commit is contained in:
Maciej Żenczykowski 2020-12-01 02:41:26 +00:00 committed by Automerger Merge Worker
commit f0010f5901

View file

@ -29,11 +29,11 @@
#ifdef BPF_FD_JUST_USE_INT
#define BPF_FD_TYPE int
#define BPF_FD_TO_INT(x) static_cast<__u32>(x)
#define BPF_FD_TO_U32(x) static_cast<__u32>(x)
#else
#include <android-base/unique_fd.h>
#define BPF_FD_TYPE base::unique_fd&
#define BPF_FD_TO_INT(x) static_cast<__u32>((x).get())
#define BPF_FD_TO_U32(x) static_cast<__u32>((x).get())
#endif
#define ptr_to_u64(x) ((uint64_t)(uintptr_t)(x))
@ -84,7 +84,7 @@ inline int createMap(bpf_map_type map_type, uint32_t key_size, uint32_t value_si
inline int writeToMapEntry(const BPF_FD_TYPE map_fd, const void* key, const void* value,
uint64_t flags) {
return bpf(BPF_MAP_UPDATE_ELEM, {
.map_fd = BPF_FD_TO_INT(map_fd),
.map_fd = BPF_FD_TO_U32(map_fd),
.key = ptr_to_u64(key),
.value = ptr_to_u64(value),
.flags = flags,
@ -93,7 +93,7 @@ inline int writeToMapEntry(const BPF_FD_TYPE map_fd, const void* key, const void
inline int findMapEntry(const BPF_FD_TYPE map_fd, const void* key, void* value) {
return bpf(BPF_MAP_LOOKUP_ELEM, {
.map_fd = BPF_FD_TO_INT(map_fd),
.map_fd = BPF_FD_TO_U32(map_fd),
.key = ptr_to_u64(key),
.value = ptr_to_u64(value),
});
@ -101,14 +101,14 @@ inline int findMapEntry(const BPF_FD_TYPE map_fd, const void* key, void* value)
inline int deleteMapEntry(const BPF_FD_TYPE map_fd, const void* key) {
return bpf(BPF_MAP_DELETE_ELEM, {
.map_fd = BPF_FD_TO_INT(map_fd),
.map_fd = BPF_FD_TO_U32(map_fd),
.key = ptr_to_u64(key),
});
}
inline int getNextMapKey(const BPF_FD_TYPE map_fd, const void* key, void* next_key) {
return bpf(BPF_MAP_GET_NEXT_KEY, {
.map_fd = BPF_FD_TO_INT(map_fd),
.map_fd = BPF_FD_TO_U32(map_fd),
.key = ptr_to_u64(key),
.next_key = ptr_to_u64(next_key),
});
@ -121,7 +121,7 @@ inline int getFirstMapKey(const BPF_FD_TYPE map_fd, void* firstKey) {
inline int bpfFdPin(const BPF_FD_TYPE map_fd, const char* pathname) {
return bpf(BPF_OBJ_PIN, {
.pathname = ptr_to_u64(pathname),
.bpf_fd = BPF_FD_TO_INT(map_fd),
.bpf_fd = BPF_FD_TO_U32(map_fd),
});
}
@ -155,15 +155,15 @@ inline int retrieveProgram(const char* pathname) {
inline int attachProgram(bpf_attach_type type, const BPF_FD_TYPE prog_fd,
const BPF_FD_TYPE cg_fd) {
return bpf(BPF_PROG_ATTACH, {
.target_fd = BPF_FD_TO_INT(cg_fd),
.attach_bpf_fd = BPF_FD_TO_INT(prog_fd),
.target_fd = BPF_FD_TO_U32(cg_fd),
.attach_bpf_fd = BPF_FD_TO_U32(prog_fd),
.attach_type = type,
});
}
inline int detachProgram(bpf_attach_type type, const BPF_FD_TYPE cg_fd) {
return bpf(BPF_PROG_DETACH, {
.target_fd = BPF_FD_TO_INT(cg_fd),
.target_fd = BPF_FD_TO_U32(cg_fd),
.attach_type = type,
});
}