Commit 85367030 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

libbpf: Centralize poisoning and poison reallocarray()

Most of libbpf source files already include libbpf_internal.h, so it's a good
place to centralize identifier poisoning. So move kernel integer type
poisoning there. And also add reallocarray to a poison list to prevent
accidental use of it. libbpf_reallocarray() should be used universally
instead.
Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200819013607.3607269-4-andriin@fb.com
parent 7084566a
...@@ -32,9 +32,6 @@ ...@@ -32,9 +32,6 @@
#include "libbpf.h" #include "libbpf.h"
#include "libbpf_internal.h" #include "libbpf_internal.h"
/* make sure libbpf doesn't use kernel-only integer typedefs */
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
/* /*
* When building perf, unistd.h is overridden. __NR_bpf is * When building perf, unistd.h is overridden. __NR_bpf is
* required to be defined explicitly. * required to be defined explicitly.
......
...@@ -8,9 +8,6 @@ ...@@ -8,9 +8,6 @@
#include "libbpf.h" #include "libbpf.h"
#include "libbpf_internal.h" #include "libbpf_internal.h"
/* make sure libbpf doesn't use kernel-only integer typedefs */
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
struct bpf_prog_linfo { struct bpf_prog_linfo {
void *raw_linfo; void *raw_linfo;
void *raw_jited_linfo; void *raw_jited_linfo;
......
...@@ -21,9 +21,6 @@ ...@@ -21,9 +21,6 @@
#include "libbpf_internal.h" #include "libbpf_internal.h"
#include "hashmap.h" #include "hashmap.h"
/* make sure libbpf doesn't use kernel-only integer typedefs */
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
#define BTF_MAX_NR_TYPES 0x7fffffffU #define BTF_MAX_NR_TYPES 0x7fffffffU
#define BTF_MAX_STR_OFFSET 0x7fffffffU #define BTF_MAX_STR_OFFSET 0x7fffffffU
......
...@@ -19,9 +19,6 @@ ...@@ -19,9 +19,6 @@
#include "libbpf.h" #include "libbpf.h"
#include "libbpf_internal.h" #include "libbpf_internal.h"
/* make sure libbpf doesn't use kernel-only integer typedefs */
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
static const char PREFIXES[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t"; static const char PREFIXES[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t";
static const size_t PREFIX_CNT = sizeof(PREFIXES) - 1; static const size_t PREFIX_CNT = sizeof(PREFIXES) - 1;
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
/* make sure libbpf doesn't use kernel-only integer typedefs */ /* make sure libbpf doesn't use kernel-only integer typedefs */
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64 #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
/* prevent accidental re-addition of reallocarray() */
#pragma GCC poison reallocarray
/* start with 4 buckets */ /* start with 4 buckets */
#define HASHMAP_MIN_CAP_BITS 2 #define HASHMAP_MIN_CAP_BITS 2
......
...@@ -55,9 +55,6 @@ ...@@ -55,9 +55,6 @@
#include "libbpf_internal.h" #include "libbpf_internal.h"
#include "hashmap.h" #include "hashmap.h"
/* make sure libbpf doesn't use kernel-only integer typedefs */
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
#ifndef EM_BPF #ifndef EM_BPF
#define EM_BPF 247 #define EM_BPF 247
#endif #endif
......
...@@ -10,6 +10,13 @@ ...@@ -10,6 +10,13 @@
#define __LIBBPF_LIBBPF_INTERNAL_H #define __LIBBPF_LIBBPF_INTERNAL_H
#include <stdlib.h> #include <stdlib.h>
/* make sure libbpf doesn't use kernel-only integer typedefs */
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
/* prevent accidental re-addition of reallocarray() */
#pragma GCC poison reallocarray
#include "libbpf.h" #include "libbpf.h"
#define BTF_INFO_ENC(kind, kind_flag, vlen) \ #define BTF_INFO_ENC(kind, kind_flag, vlen) \
......
...@@ -17,9 +17,6 @@ ...@@ -17,9 +17,6 @@
#include "libbpf.h" #include "libbpf.h"
#include "libbpf_internal.h" #include "libbpf_internal.h"
/* make sure libbpf doesn't use kernel-only integer typedefs */
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
static bool grep(const char *buffer, const char *pattern) static bool grep(const char *buffer, const char *pattern)
{ {
return !!strstr(buffer, pattern); return !!strstr(buffer, pattern);
......
...@@ -15,9 +15,6 @@ ...@@ -15,9 +15,6 @@
#include "libbpf_internal.h" #include "libbpf_internal.h"
#include "nlattr.h" #include "nlattr.h"
/* make sure libbpf doesn't use kernel-only integer typedefs */
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
#ifndef SOL_NETLINK #ifndef SOL_NETLINK
#define SOL_NETLINK 270 #define SOL_NETLINK 270
#endif #endif
......
...@@ -7,14 +7,11 @@ ...@@ -7,14 +7,11 @@
*/ */
#include <errno.h> #include <errno.h>
#include "nlattr.h"
#include "libbpf_internal.h"
#include <linux/rtnetlink.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <linux/rtnetlink.h>
/* make sure libbpf doesn't use kernel-only integer typedefs */ #include "nlattr.h"
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64 #include "libbpf_internal.h"
static uint16_t nla_attr_minlen[LIBBPF_NLA_TYPE_MAX+1] = { static uint16_t nla_attr_minlen[LIBBPF_NLA_TYPE_MAX+1] = {
[LIBBPF_NLA_U8] = sizeof(uint8_t), [LIBBPF_NLA_U8] = sizeof(uint8_t),
......
...@@ -21,9 +21,6 @@ ...@@ -21,9 +21,6 @@
#include "libbpf_internal.h" #include "libbpf_internal.h"
#include "bpf.h" #include "bpf.h"
/* make sure libbpf doesn't use kernel-only integer typedefs */
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
struct ring { struct ring {
ring_buffer_sample_fn sample_cb; ring_buffer_sample_fn sample_cb;
void *ctx; void *ctx;
......
...@@ -32,9 +32,6 @@ ...@@ -32,9 +32,6 @@
#include "libbpf_internal.h" #include "libbpf_internal.h"
#include "xsk.h" #include "xsk.h"
/* make sure libbpf doesn't use kernel-only integer typedefs */
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
#ifndef SOL_XDP #ifndef SOL_XDP
#define SOL_XDP 283 #define SOL_XDP 283
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment