From a262bd3d1e5ab896eb03683378750f682ac232a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= <maze@google.com>
Date: Fri, 6 Oct 2023 14:36:01 -0700
Subject: [PATCH] type safety for bool shared
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4883eab734f47522fec718f0709475f7e6dd0a53
---
 staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h | 2 +-
 staticlibs/native/bpf_headers/include/bpf/bpf_map_def.h | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h b/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h
index 9583e805a4..323b0d604f 100644
--- a/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h
+++ b/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h
@@ -213,7 +213,7 @@ static void (*bpf_ringbuf_submit_unsafe)(const void* data, __u64 flags) = (void*
         .max_kver = (maxkver),                                              \
         .selinux_context = (selinux),                                       \
         .pin_subdir = (pindir),                                             \
-        .shared = (share),                                                  \
+        .shared = (share).shared,                                           \
         .ignore_on_eng = (ignore_eng),                                      \
         .ignore_on_user = (ignore_user),                                    \
         .ignore_on_userdebug = (ignore_userdebug),                          \
diff --git a/staticlibs/native/bpf_headers/include/bpf/bpf_map_def.h b/staticlibs/native/bpf_headers/include/bpf/bpf_map_def.h
index 7474346c7e..0a7439c6c1 100644
--- a/staticlibs/native/bpf_headers/include/bpf/bpf_map_def.h
+++ b/staticlibs/native/bpf_headers/include/bpf/bpf_map_def.h
@@ -115,9 +115,10 @@ _Static_assert(__alignof__(unsigned long long) == 8, "__alignof__ unsigned long
 //_Static_assert(_Alignof(unsigned long long) == 8, "_Alignof unsigned long long != 8");
 
 
-// constants for passing in to 'bool shared' (for maps)
-static const bool PRIVATE = false;
-static const bool SHARED = true;
+// for maps:
+struct shared_bool { bool shared; };
+#define PRIVATE ((struct shared_bool){ .shared = false })
+#define SHARED ((struct shared_bool){ .shared = true })
 
 // constants for passing in to 'bool optional' (for programs)
 static const bool MANDATORY = false;
-- 
GitLab