[vm] Avoid using a generated stub to get the current SP, since generated stubs aren't available during early start up.

Change-Id: Ib0d78965ba5ccb1fa2b084d82b2bb79485b7900f
Reviewed-on: https://dart-review.googlesource.com/12780
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
This commit is contained in:
Ryan Macnak
2017-10-10 22:52:25 +00:00
parent 17cd1a9f90
commit 031069d2bd
5 changed files with 44 additions and 40 deletions
+8 -16
View File
@@ -10,17 +10,23 @@
// Allow the use of ASan (AddressSanitizer). This is needed as ASan needs to be
// told about areas where the VM does the equivalent of a long-jump.
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define USING_ADDRESS_SANITIZER
#endif
#endif
#if defined(USING_ADDRESS_SANITIZER)
extern "C" void __asan_unpoison_memory_region(void*, size_t);
extern "C" void __lsan_register_root_region(const void* p, size_t size);
extern "C" void __lsan_unregister_root_region(const void* p, size_t size);
#define NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
#define ASAN_UNPOISON(ptr, len) __asan_unpoison_memory_region(ptr, len)
#define LSAN_REGISTER_ROOT_REGION(ptr, len) \
__lsan_register_root_region(ptr, len)
#define LSAN_UNREGISTER_ROOT_REGION(ptr, len) \
__lsan_unregister_root_region(ptr, len)
#else // __has_feature(address_sanitizer)
#define NO_SANITIZE_ADDRESS
#define ASAN_UNPOISON(ptr, len) \
do { \
} while (false && (ptr) == 0 && (len) == 0)
@@ -30,20 +36,6 @@ extern "C" void __lsan_unregister_root_region(const void* p, size_t size);
#define LSAN_UNREGISTER_ROOT_REGION(ptr, len) \
do { \
} while (false && (ptr) == 0 && (len) == 0)
#endif // __has_feature(address_sanitizer)
#else // defined(__has_feature)
#define ASAN_UNPOISON(ptr, len) \
do { \
} while (false && (ptr) == 0 && (len) == 0)
#define LSAN_REGISTER_ROOT_REGION(ptr, len) \
do { \
} while (false && (ptr) == 0 && (len) == 0)
#define LSAN_UNREGISTER_ROOT_REGION(ptr, len) \
do { \
} while (false && (ptr) == 0 && (len) == 0)
#endif // defined(__has_feature)
#endif // defined(USING_ADDRESS_SANITIZER)
#endif // RUNTIME_PLATFORM_ADDRESS_SANITIZER_H_
+1
View File
@@ -19,6 +19,7 @@ platform_sources = [
"hashmap.h",
"inttypes_support_win.h",
"memory_sanitizer.h",
"safe_stack.h",
"signal_blocker.h",
"text_buffer.cc",
"text_buffer.h",
+22
View File
@@ -0,0 +1,22 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef RUNTIME_PLATFORM_SAFE_STACK_H_
#define RUNTIME_PLATFORM_SAFE_STACK_H_
#include "platform/globals.h"
#if defined(__has_feature)
#if __has_feature(safe_stack)
#define USING_SAFE_STACK
#endif
#endif
#if defined(USING_SAFE_STACK)
#define NO_SANITIZE_SAFE_STACK __attribute__((no_sanitize("safe-stack")))
#else
#define NO_SANITIZE_SAFE_STACK
#endif
#endif // RUNTIME_PLATFORM_SAFE_STACK_H_
+10 -23
View File
@@ -4,6 +4,8 @@
#include "vm/thread.h"
#include "platform/address_sanitizer.h"
#include "platform/safe_stack.h"
#include "vm/compiler_stats.h"
#include "vm/dart_api_state.h"
#include "vm/growable_array.h"
@@ -414,30 +416,15 @@ void Thread::ClearStackLimit() {
SetStackLimit(~static_cast<uword>(0));
}
/* static */
// Disable AdressSanitizer and SafeStack transformation on this function. In
// particular, taking the address of a local gives an address on the stack
// instead of an address in the shadow memory (AddressSanitizer) or the safe
// stack (SafeStack).
NO_SANITIZE_ADDRESS
NO_SANITIZE_SAFE_STACK
uword Thread::GetCurrentStackPointer() {
#if !defined(TARGET_ARCH_DBC)
// Since AddressSanitizer's detect_stack_use_after_return instruments the
// C++ code to give out fake stack addresses, we call a stub in that case.
ASSERT(StubCode::GetCStackPointer_entry() != NULL);
uword (*func)() = reinterpret_cast<uword (*)()>(
StubCode::GetCStackPointer_entry()->EntryPoint());
#else
uword (*func)() = NULL;
#endif
// But for performance (and to support simulators), we normally use a local.
#if defined(__has_feature)
#if __has_feature(address_sanitizer) || __has_feature(safe_stack)
uword current_sp = func();
return current_sp;
#else
uword stack_allocated_local_address = reinterpret_cast<uword>(&func);
return stack_allocated_local_address;
#endif
#else
uword stack_allocated_local_address = reinterpret_cast<uword>(&func);
return stack_allocated_local_address;
#endif
uword stack_allocated_local = reinterpret_cast<uword>(&stack_allocated_local);
return stack_allocated_local;
}
void Thread::ScheduleInterrupts(uword interrupt_bits) {
+3 -1
View File
@@ -204,7 +204,9 @@ class Thread : public BaseThread {
void ClearStackLimit();
// Returns the current C++ stack pointer. Equivalent taking the address of a
// stack allocated local, but plays well with AddressSanitizer.
// stack allocated local, but plays well with AddressSanitizer and SafeStack.
// Accurate enough for stack overflow checks but not accurate enough for
// alignment checks.
static uword GetCurrentStackPointer();
// Access to the current stack limit for generated code. This may be