libc_shared_globals: add a constexpr ctor
Having a constexpr constructor should guarantee that the static
`globals` variable in __libc_shared_globals is initialized statically
(as opposed to dynamically), which is important because
__libc_shared_globals is called very early (before the linker has
relocated itself). With the constructor, though, the fields can safely
have in-line default initializers.
Bug: none
Test: bionic unit tests
Change-Id: Icde821557369625734a4d85d7ff55428bad5c247
diff --git a/libc/private/bionic_fdsan.h b/libc/private/bionic_fdsan.h
index de14cf8..f403d08 100644
--- a/libc/private/bionic_fdsan.h
+++ b/libc/private/bionic_fdsan.h
@@ -39,21 +39,23 @@
#include <sys/user.h>
struct FdEntry {
- _Atomic(uint64_t) close_tag;
+ _Atomic(uint64_t) close_tag = 0;
};
struct FdTableOverflow {
- size_t len;
+ size_t len = 0;
FdEntry entries[0];
};
template <size_t inline_fds>
struct FdTableImpl {
- uint32_t version; // currently 0, and hopefully it'll stay that way.
- _Atomic(android_fdsan_error_level) error_level;
+ constexpr FdTableImpl() {}
+
+ uint32_t version = 0; // currently 0, and hopefully it'll stay that way.
+ _Atomic(android_fdsan_error_level) error_level = ANDROID_FDSAN_ERROR_LEVEL_DISABLED;
FdEntry entries[inline_fds];
- _Atomic(FdTableOverflow*) overflow;
+ _Atomic(FdTableOverflow*) overflow = nullptr;
FdEntry* at(size_t idx);
};