From 0b1ca4a9ef76eee090e947cb7ed5ede568a78c5d Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Wed, 16 Sep 2015 10:12:41 -0500 Subject: [PATCH] src: Add ABORT macro Windows 8+ compiled in Release mode exits with code 0xC0000409 when abort() is called. This prevents us from being able to reliably verify an abort exit code (3) on windows. PR-URL: https://github.com/nodejs/node/pull/2776 Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Colin Ihrig Reviewed-By: Brian White Reviewed-by: Trevor Norris --- src/cares_wrap.cc | 4 ++-- src/fs_event_wrap.cc | 2 +- src/node.cc | 12 ++++++------ src/node_crypto.cc | 4 ++-- src/node_crypto_bio.cc | 2 +- src/spawn_sync.cc | 4 ++-- src/stream_wrap.cc | 2 +- src/tls_wrap.cc | 2 +- src/tty_wrap.cc | 2 +- src/udp_wrap.cc | 4 ++-- src/util.h | 11 +++++++++-- 11 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 4ef5e01e77058a..b3181da135bb4e 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -1067,7 +1067,7 @@ static void GetAddrInfo(const FunctionCallbackInfo& args) { break; default: CHECK(0 && "bad address family"); - abort(); + ABORT(); } GetAddrInfoReqWrap* req_wrap = new GetAddrInfoReqWrap(env, req_wrap_obj); @@ -1193,7 +1193,7 @@ static void SetServers(const FunctionCallbackInfo& args) { break; default: CHECK(0 && "Bad address family."); - abort(); + ABORT(); } if (err) diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 0d0096cab733f5..7768f94459c16a 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -146,7 +146,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, event_string = env->change_string(); } else { CHECK(0 && "bad fs events flag"); - abort(); + ABORT(); } Local argv[] = { diff --git a/src/node.cc b/src/node.cc index f763f67b368f05..cb32bcb7989fec 100644 --- a/src/node.cc +++ b/src/node.cc @@ -918,7 +918,7 @@ void SetupDomainUse(const FunctionCallbackInfo& args) { if (!tick_callback_function->IsFunction()) { fprintf(stderr, "process._tickDomainCallback assigned to non-function\n"); - abort(); + ABORT(); } process_object->Set(env->tick_callback_string(), tick_callback_function); @@ -1526,7 +1526,7 @@ void GetActiveHandles(const FunctionCallbackInfo& args) { static void Abort(const FunctionCallbackInfo& args) { - abort(); + ABORT(); } @@ -2146,14 +2146,14 @@ static void OnFatalError(const char* location, const char* message) { fprintf(stderr, "FATAL ERROR: %s\n", message); } fflush(stderr); - abort(); + ABORT(); } NO_RETURN void FatalError(const char* location, const char* message) { OnFatalError(location, message); // to suppress compiler warning - abort(); + ABORT(); } @@ -3555,9 +3555,9 @@ inline void PlatformInit() { // Anything but EBADF means something is seriously wrong. We don't // have to special-case EINTR, fstat() is not interruptible. if (errno != EBADF) - abort(); + ABORT(); if (fd != open("/dev/null", O_RDWR)) - abort(); + ABORT(); } CHECK_EQ(err, 0); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 40f065e6871a9c..cb5ef574a17a9a 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -182,7 +182,7 @@ static void crypto_lock_init(void) { for (i = 0; i < n; i++) if (uv_mutex_init(locks + i)) - abort(); + ABORT(); } @@ -3466,7 +3466,7 @@ void SignBase::CheckThrow(SignBase::Error error) { case kSignPublicKey: return env()->ThrowError("PEM_read_bio_PUBKEY failed"); default: - abort(); + ABORT(); } } diff --git a/src/node_crypto_bio.cc b/src/node_crypto_bio.cc index c28e118c3ba123..ca0d0ba97ecfef 100644 --- a/src/node_crypto_bio.cc +++ b/src/node_crypto_bio.cc @@ -172,7 +172,7 @@ long NodeBIO::Ctrl(BIO* bio, int cmd, long num, void* ptr) { break; case BIO_C_SET_BUF_MEM: CHECK(0 && "Can't use SET_BUF_MEM_PTR with NodeBIO"); - abort(); + ABORT(); break; case BIO_C_GET_BUF_MEM_PTR: CHECK(0 && "Can't use GET_BUF_MEM_PTR with NodeBIO"); diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 144af3e747db63..62fadb4396ce19 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -485,7 +485,7 @@ void SyncProcessRunner::TryInitializeAndRunLoop(Local options) { r = uv_run(uv_loop_, UV_RUN_DEFAULT); if (r < 0) // We can't handle uv_run failure. - abort(); + ABORT(); // If we get here the process should have exited. CHECK_GE(exit_status_, 0); @@ -508,7 +508,7 @@ void SyncProcessRunner::CloseHandlesAndDeleteLoop() { // callbacks called. int r = uv_run(uv_loop_, UV_RUN_DEFAULT); if (r < 0) - abort(); + ABORT(); CHECK_EQ(uv_loop_close(uv_loop_), 0); delete uv_loop_; diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index cd9b2c9064fb52..120e2c4d502b30 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -179,7 +179,7 @@ static Local AcceptHandle(Environment* env, StreamWrap* parent) { handle = wrap->UVHandle(); if (uv_accept(parent->stream(), reinterpret_cast(handle))) - abort(); + ABORT(); return scope.Escape(wrap_obj); } diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index b466afb152459a..fc00893b77f84f 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -152,7 +152,7 @@ void TLSWrap::InitSSL() { SSL_set_connect_state(ssl_); } else { // Unexpected - abort(); + ABORT(); } // Initialize ring for queud clear data diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 76a2472f8a5a85..a78d2311456c7c 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -72,7 +72,7 @@ void TTYWrap::GuessHandleType(const FunctionCallbackInfo& args) { case UV_NAMED_PIPE: type = "PIPE"; break; case UV_UNKNOWN_HANDLE: type = "UNKNOWN"; break; default: - abort(); + ABORT(); } args.GetReturnValue().Set(OneByteString(env->isolate(), type)); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 4c0d38dfb25eeb..dff2235f9f5ad0 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -166,7 +166,7 @@ void UDPWrap::DoBind(const FunctionCallbackInfo& args, int family) { break; default: CHECK(0 && "unexpected address family"); - abort(); + ABORT(); } if (err == 0) { @@ -278,7 +278,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo& args, int family) { break; default: CHECK(0 && "unexpected address family"); - abort(); + ABORT(); } if (err == 0) { diff --git a/src/util.h b/src/util.h index 24c633e286eb71..eb743b62462f25 100644 --- a/src/util.h +++ b/src/util.h @@ -18,11 +18,18 @@ namespace node { TypeName(const TypeName&) = delete; \ TypeName(TypeName&&) = delete +// Windows 8+ does not like abort() in Release mode +#ifdef _WIN32 +#define ABORT() raise(SIGABRT) +#else +#define ABORT() abort() +#endif + #if defined(NDEBUG) # define ASSERT(expression) # define CHECK(expression) \ do { \ - if (!(expression)) abort(); \ + if (!(expression)) ABORT(); \ } while (0) #else # define ASSERT(expression) assert(expression) @@ -43,7 +50,7 @@ namespace node { #define CHECK_LT(a, b) CHECK((a) < (b)) #define CHECK_NE(a, b) CHECK((a) != (b)) -#define UNREACHABLE() abort() +#define UNREACHABLE() ABORT() // TAILQ-style intrusive list node. template