From f3cffbdf169e37df82792042fb5c3b1d210b0916 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 30 Jan 2023 18:34:55 +0100 Subject: [PATCH 1/2] src: use uint32_t for process initialization flags enum Refs: https://github.com/nodejs/node/pull/45221 --- src/node.cc | 5 ++++- src/node.h | 11 ++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/node.cc b/src/node.cc index c5b6c2b8444499..4108390db67041 100644 --- a/src/node.cc +++ b/src/node.cc @@ -432,6 +432,9 @@ void ResetSignalHandlers() { } static std::atomic init_process_flags = 0; +static_assert( + std::is_same_v, + uint32_t>); static void PlatformInit(ProcessInitializationFlags::Flags flags) { // init_process_flags is accessed in ResetStdio(), @@ -1057,7 +1060,7 @@ std::unique_ptr InitializeOncePerProcess( } void TearDownOncePerProcess() { - const uint64_t flags = init_process_flags.load(); + const uint32_t flags = init_process_flags.load(); ResetStdio(); if (!(flags & ProcessInitializationFlags::kNoDefaultSignalHandling)) { ResetSignalHandlers(); diff --git a/src/node.h b/src/node.h index 561af155561923..ca7b100311071b 100644 --- a/src/node.h +++ b/src/node.h @@ -227,10 +227,8 @@ class Environment; class MultiIsolatePlatform; class InitializationResultImpl; -namespace ProcessFlags { -// TODO(addaleax): Switch to uint32_t to match std::atomic -// init_process_flags in node.cc -enum Flags : uint64_t { +namespace ProcessInitializationFlags { +enum Flags : uint32_t { kNoFlags = 0, // Enable stdio inheritance, which is disabled by default. // This flag is also implied by kNoStdioInitialization. @@ -270,9 +268,8 @@ enum Flags : uint64_t { kNoParseGlobalDebugVariables | kNoAdjustResourceLimits | kNoUseLargePages | kNoPrintHelpOrVersionOutput, }; -} // namespace ProcessFlags -// TODO(addaleax): Make this the canonical name, as it is more descriptive. -namespace ProcessInitializationFlags = ProcessFlags; +} // namespace ProcessInitializationFlags +namespace ProcessFlags = ProcessInitializationFlags; // Legacy alias. class NODE_EXTERN InitializationResult { public: From c259b3b3aecfa43af4db190b78094690f2faeef4 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 31 Jan 2023 17:35:25 +0100 Subject: [PATCH 2/2] fixup! src: use uint32_t for process initialization flags enum --- src/node.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/node.cc b/src/node.cc index 4108390db67041..d10e73d78b4fc6 100644 --- a/src/node.cc +++ b/src/node.cc @@ -431,6 +431,9 @@ void ResetSignalHandlers() { #endif // __POSIX__ } +// We use uint32_t since that can be accessed as a lock-free atomic +// variable on all platforms that we support, which we require in +// order for its value to be usable inside signal handlers. static std::atomic init_process_flags = 0; static_assert( std::is_same_v,