From 1509d9ad4194163bb7046911526109f7c28e97ca Mon Sep 17 00:00:00 2001 From: Zichang Guo Date: Tue, 16 Jul 2019 19:46:56 +0000 Subject: [PATCH] [vm] initialize sigaction for msan msan didn't recognize instance initialized with memset or bzero. Initialize all the instances. Bug: https://buganizer.corp.google.com/issues/137630695 Change-Id: I0f4adf90cd9d4daa2abe783b1e1ca892bdacb690 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109306 Reviewed-by: Ryan Macnak Commit-Queue: Zichang Guo --- runtime/bin/ffi_test/ffi_test_functions.cc | 4 ++-- runtime/bin/platform_android.cc | 3 +-- runtime/bin/platform_linux.cc | 3 +-- runtime/bin/platform_macos.cc | 3 +-- runtime/bin/process_android.cc | 6 ++---- runtime/bin/process_linux.cc | 6 ++---- runtime/bin/process_macos.cc | 6 ++---- runtime/platform/memory_sanitizer.h | 2 +- runtime/vm/signal_handler_android.cc | 6 ++---- runtime/vm/signal_handler_linux.cc | 4 ++-- runtime/vm/signal_handler_macos.cc | 4 ++-- 11 files changed, 18 insertions(+), 29 deletions(-) diff --git a/runtime/bin/ffi_test/ffi_test_functions.cc b/runtime/bin/ffi_test/ffi_test_functions.cc index 4ec885b0b1e..95b857d8d8f 100644 --- a/runtime/bin/ffi_test/ffi_test_functions.cc +++ b/runtime/bin/ffi_test/ffi_test_functions.cc @@ -704,11 +704,11 @@ void CallbackTestSignalHandler(int) { int ExpectAbort(void (*fn)()) { fprintf(stderr, "**** EXPECT STACKTRACE TO FOLLOW. THIS IS OK. ****\n"); - struct sigaction old_action; + struct sigaction old_action = {}; int result = __sigsetjmp(buf, /*savesigs=*/1); if (result == 0) { // Install signal handler. - struct sigaction handler; + struct sigaction handler = {}; handler.sa_handler = CallbackTestSignalHandler; sigemptyset(&handler.sa_mask); handler.sa_flags = 0; diff --git a/runtime/bin/platform_android.cc b/runtime/bin/platform_android.cc index db61adf8236..f5d1fb4be85 100644 --- a/runtime/bin/platform_android.cc +++ b/runtime/bin/platform_android.cc @@ -40,8 +40,7 @@ bool Platform::Initialize() { // Turn off the signal handler for SIGPIPE as it causes the process // to terminate on writing to a closed pipe. Without the signal // handler error EPIPE is set instead. - struct sigaction act; - bzero(&act, sizeof(act)); + struct sigaction act = {}; act.sa_handler = SIG_IGN; if (sigaction(SIGPIPE, &act, 0) != 0) { perror("Setting signal handler failed"); diff --git a/runtime/bin/platform_linux.cc b/runtime/bin/platform_linux.cc index 1d259ac45f6..2123acb7937 100644 --- a/runtime/bin/platform_linux.cc +++ b/runtime/bin/platform_linux.cc @@ -39,8 +39,7 @@ bool Platform::Initialize() { // Turn off the signal handler for SIGPIPE as it causes the process // to terminate on writing to a closed pipe. Without the signal // handler error EPIPE is set instead. - struct sigaction act; - bzero(&act, sizeof(act)); + struct sigaction act = {}; act.sa_handler = SIG_IGN; if (sigaction(SIGPIPE, &act, 0) != 0) { perror("Setting signal handler failed"); diff --git a/runtime/bin/platform_macos.cc b/runtime/bin/platform_macos.cc index 1a6688c0cae..3e99b5cadf7 100644 --- a/runtime/bin/platform_macos.cc +++ b/runtime/bin/platform_macos.cc @@ -47,8 +47,7 @@ bool Platform::Initialize() { // Turn off the signal handler for SIGPIPE as it causes the process // to terminate on writing to a closed pipe. Without the signal // handler error EPIPE is set instead. - struct sigaction act; - bzero(&act, sizeof(act)); + struct sigaction act = {}; act.sa_handler = SIG_IGN; if (sigaction(SIGPIPE, &act, 0) != 0) { perror("Setting signal handler failed"); diff --git a/runtime/bin/process_android.cc b/runtime/bin/process_android.cc index bbb0afa6606..285a316901c 100644 --- a/runtime/bin/process_android.cc +++ b/runtime/bin/process_android.cc @@ -1006,8 +1006,7 @@ intptr_t Process::SetSignalHandler(intptr_t signal) { handler = handler->next(); } if (listen) { - struct sigaction act; - bzero(&act, sizeof(act)); + struct sigaction act = {}; act.sa_handler = SignalHandler; sigemptyset(&act.sa_mask); for (int i = 0; i < kSignalsCount; i++) { @@ -1052,8 +1051,7 @@ void Process::ClearSignalHandler(intptr_t signal, Dart_Port port) { handler = next; } if (unlisten) { - struct sigaction act; - bzero(&act, sizeof(act)); + struct sigaction act = {}; act.sa_handler = SIG_DFL; VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); } diff --git a/runtime/bin/process_linux.cc b/runtime/bin/process_linux.cc index afc96677948..b487093cdc9 100644 --- a/runtime/bin/process_linux.cc +++ b/runtime/bin/process_linux.cc @@ -1000,8 +1000,7 @@ intptr_t Process::SetSignalHandler(intptr_t signal) { handler = handler->next(); } if (listen) { - struct sigaction act; - bzero(&act, sizeof(act)); + struct sigaction act = {}; act.sa_handler = SignalHandler; sigemptyset(&act.sa_mask); for (int i = 0; i < kSignalsCount; i++) { @@ -1048,8 +1047,7 @@ void Process::ClearSignalHandler(intptr_t signal, Dart_Port port) { handler = next; } if (unlisten) { - struct sigaction act; - bzero(&act, sizeof(act)); + struct sigaction act = {}; act.sa_handler = SIG_DFL; sigaction(signal, &act, NULL); } diff --git a/runtime/bin/process_macos.cc b/runtime/bin/process_macos.cc index 4463855edae..366178c70ae 100644 --- a/runtime/bin/process_macos.cc +++ b/runtime/bin/process_macos.cc @@ -1034,8 +1034,7 @@ intptr_t Process::SetSignalHandler(intptr_t signal) { handler = handler->next(); } if (listen) { - struct sigaction act; - bzero(&act, sizeof(act)); + struct sigaction act = {}; act.sa_handler = SignalHandler; sigemptyset(&act.sa_mask); for (int i = 0; i < kSignalsCount; i++) { @@ -1084,8 +1083,7 @@ void Process::ClearSignalHandler(intptr_t signal, Dart_Port port) { handler = next; } if (unlisten) { - struct sigaction act; - bzero(&act, sizeof(act)); + struct sigaction act = {}; act.sa_handler = SIG_DFL; VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); } diff --git a/runtime/platform/memory_sanitizer.h b/runtime/platform/memory_sanitizer.h index 27cb25d4b40..324d73e37ff 100644 --- a/runtime/platform/memory_sanitizer.h +++ b/runtime/platform/memory_sanitizer.h @@ -11,7 +11,7 @@ // told about areas that are initialized by generated code. #if defined(__has_feature) #if __has_feature(memory_sanitizer) -extern "C" void __msan_unpoison(void*, size_t); +extern "C" void __msan_unpoison(const volatile void*, size_t); #define MSAN_UNPOISON(ptr, len) __msan_unpoison(ptr, len) #define NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory)) #else // __has_feature(memory_sanitizer) diff --git a/runtime/vm/signal_handler_android.cc b/runtime/vm/signal_handler_android.cc index c466ebd596a..f9f6944cd3d 100644 --- a/runtime/vm/signal_handler_android.cc +++ b/runtime/vm/signal_handler_android.cc @@ -95,8 +95,7 @@ uintptr_t SignalHandler::GetLinkRegister(const mcontext_t& mcontext) { } void SignalHandler::InstallImpl(SignalAction action) { - struct sigaction act; - memset(&act, 0, sizeof(act)); + struct sigaction act = {}; act.sa_sigaction = action; sigemptyset(&act.sa_mask); act.sa_flags = SA_RESTART | SA_SIGINFO; @@ -107,8 +106,7 @@ void SignalHandler::InstallImpl(SignalAction action) { void SignalHandler::Remove() { // Ignore future SIGPROF signals because by default SIGPROF will terminate // the process and we may have some signals in flight. - struct sigaction act; - memset(&act, 0, sizeof(act)); + struct sigaction act = {}; act.sa_handler = SIG_IGN; sigemptyset(&act.sa_mask); int r = sigaction(SIGPROF, &act, NULL); diff --git a/runtime/vm/signal_handler_linux.cc b/runtime/vm/signal_handler_linux.cc index 3712901ceab..a9cb30bcec8 100644 --- a/runtime/vm/signal_handler_linux.cc +++ b/runtime/vm/signal_handler_linux.cc @@ -95,7 +95,7 @@ uintptr_t SignalHandler::GetLinkRegister(const mcontext_t& mcontext) { } void SignalHandler::InstallImpl(SignalAction action) { - struct sigaction act; + struct sigaction act = {}; act.sa_handler = NULL; act.sa_sigaction = action; sigemptyset(&act.sa_mask); @@ -107,7 +107,7 @@ void SignalHandler::InstallImpl(SignalAction action) { void SignalHandler::Remove() { // Ignore future SIGPROF signals because by default SIGPROF will terminate // the process and we may have some signals in flight. - struct sigaction act; + struct sigaction act = {}; act.sa_handler = SIG_IGN; sigemptyset(&act.sa_mask); act.sa_flags = 0; diff --git a/runtime/vm/signal_handler_macos.cc b/runtime/vm/signal_handler_macos.cc index 8167b81bbd2..081a947ddb6 100644 --- a/runtime/vm/signal_handler_macos.cc +++ b/runtime/vm/signal_handler_macos.cc @@ -91,7 +91,7 @@ uintptr_t SignalHandler::GetLinkRegister(const mcontext_t& mcontext) { } void SignalHandler::InstallImpl(SignalAction action) { - struct sigaction act; + struct sigaction act = {}; act.sa_handler = NULL; act.sa_sigaction = action; sigemptyset(&act.sa_mask); @@ -103,7 +103,7 @@ void SignalHandler::InstallImpl(SignalAction action) { void SignalHandler::Remove() { // Ignore future SIGPROF signals because by default SIGPROF will terminate // the process and we may have some signals in flight. - struct sigaction act; + struct sigaction act = {}; act.sa_handler = SIG_IGN; sigemptyset(&act.sa_mask); act.sa_flags = 0;