Reviewers: Jakob,

Message:
PTAL

Description:
v8::TryCatch now works correctly with ASAN's UseAfterReturn mode enabled.

BUG=chromium:369962
LOG=N

Please review this at https://codereview.chromium.org/273383003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+34, -5 lines):
  M include/v8.h
  M src/api.cc
  M src/base/macros.h
  M src/isolate.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index e089b41818f12d2109f4fde96647806d16045d12..e56e42be957b75d459b63fa387d539c89dffcec4 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -5076,6 +5076,8 @@ class V8_EXPORT TryCatch {
   void SetCaptureMessage(bool value);

  private:
+  TryCatch* DesanitizedThis();
+
   // Make it hard to create heap-allocated TryCatch blocks.
   TryCatch(const TryCatch&);
   void operator=(const TryCatch&);
@@ -5087,6 +5089,7 @@ class V8_EXPORT TryCatch {
   void* exception_;
   void* message_obj_;
   void* message_script_;
+  void* asan_fake_stack_handle_;
   int message_start_pos_;
   int message_end_pos_;
   bool is_verbose_ : 1;
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 7f1276dee8e634fb9fafc6ef093596f9fc18e389..3079a79d34ee17a674df0df323e9bcc46e259055 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6,6 +6,9 @@

 #include <string.h>  // For memcpy, strlen.
 #include <cmath>  // For isnan.
+#ifdef ASAN_BUILD
+#include <sanitizer/asan_interface.h>
+#endif  // ASAN_BUILD
 #include "../include/v8-debug.h"
 #include "../include/v8-profiler.h"
 #include "../include/v8-testing.h"
@@ -1819,6 +1822,16 @@ v8::TryCatch::~TryCatch() {
 }


+v8::TryCatch* v8::TryCatch::DesanitizedThis() {
+#ifdef ASAN_BUILD
+  return TRY_CATCH_FROM_ADDRESS(
+ __asan_addr_is_in_fake_stack(asan_fake_stack_handle_, this, NULL, NULL));
+#else
+  return this;
+#endif
+}
+
+
 bool v8::TryCatch::HasCaught() const {
   return !reinterpret_cast<i::Object*>(exception_)->IsTheHole();
 }
@@ -1893,6 +1906,11 @@ void v8::TryCatch::Reset() {
   message_script_ = the_hole;
   message_start_pos_ = 0;
   message_end_pos_ = 0;
+#ifdef ASAN_BUILD
+  asan_fake_stack_handle_ = __asan_get_current_fake_stack();
+#else
+  asan_fake_stack_handle_ = 0;
+#endif
 }


Index: src/base/macros.h
diff --git a/src/base/macros.h b/src/base/macros.h
index b99f01b230c52db6c11e90a49c608919ae6ccfab..5b3e90bc7d23699c1a0650f6ecfd94639b60dc50 100644
--- a/src/base/macros.h
+++ b/src/base/macros.h
@@ -54,15 +54,22 @@
 #define MUST_USE_RESULT V8_WARN_UNUSED_RESULT


-// Define DISABLE_ASAN macros.
+// Define ASAN_BUILD macros.
+#ifdef ASAN_BUILD
+#error "ASAN_BUILD macros must not be defined."
+#endif
+
 #if defined(__has_feature)
 #if __has_feature(address_sanitizer)
-#define DISABLE_ASAN __attribute__((no_sanitize_address))
+#define ASAN_BUILD 1
 #endif
 #endif


-#ifndef DISABLE_ASAN
+// Define DISABLE_ASAN macros.
+#ifdef ASAN_BUILD
+#define DISABLE_ASAN __attribute__((no_sanitize_address))
+#else
 #define DISABLE_ASAN
 #endif

Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 06df1f67c25bc380097c2cc8ca471105ec65b071..898f43c166fa11a1907e4fabef6c64823fe3dbf5 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -272,13 +272,14 @@ void Isolate::RegisterTryCatchHandler(v8::TryCatch* that) {
   // JS stack.  When running without the simulator, the address
   // returned will be the address of the C++ try catch handler itself.
   Address address = reinterpret_cast<Address>(
- SimulatorStack::RegisterCTryCatch(reinterpret_cast<uintptr_t>(that)));
+      SimulatorStack::RegisterCTryCatch(reinterpret_cast<uintptr_t>(
+          that->DesanitizedThis())));
   thread_local_top()->set_try_catch_handler_address(address);
 }


 void Isolate::UnregisterTryCatchHandler(v8::TryCatch* that) {
-  ASSERT(thread_local_top()->TryCatchHandler() == that);
+  ASSERT(thread_local_top()->TryCatchHandler() == that->DesanitizedThis());
   thread_local_top()->set_try_catch_handler_address(
       reinterpret_cast<Address>(that->next_));
   thread_local_top()->catcher_ = NULL;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to