| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/exceptions.h" | 5 #include "vm/exceptions.h" |
| 6 | 6 |
| 7 #include "vm/dart_api_impl.h" | 7 #include "vm/dart_api_impl.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/debugger.h" | 9 #include "vm/debugger.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| 11 #include "vm/object.h" | 11 #include "vm/object.h" |
| 12 #include "vm/object_store.h" | 12 #include "vm/object_store.h" |
| 13 #include "vm/stack_frame.h" | 13 #include "vm/stack_frame.h" |
| 14 #include "vm/stub_code.h" | 14 #include "vm/stub_code.h" |
| 15 #include "vm/symbols.h" | 15 #include "vm/symbols.h" |
| 16 #include "vm/tags.h" |
| 16 | 17 |
| 17 // Allow the use of ASan (AddressSanitizer). This is needed as ASan needs to be | 18 // Allow the use of ASan (AddressSanitizer). This is needed as ASan needs to be |
| 18 // told about areas where the VM does the equivalent of a long-jump. | 19 // told about areas where the VM does the equivalent of a long-jump. |
| 19 #if defined(__has_feature) | 20 #if defined(__has_feature) |
| 20 #if __has_feature(address_sanitizer) | 21 #if __has_feature(address_sanitizer) |
| 21 extern "C" void __asan_unpoison_memory_region(void *, size_t); | 22 extern "C" void __asan_unpoison_memory_region(void *, size_t); |
| 22 #else // __has_feature(address_sanitizer) | 23 #else // __has_feature(address_sanitizer) |
| 23 void __asan_unpoison_memory_region(void* ignore1, size_t ignore2) {} | 24 void __asan_unpoison_memory_region(void* ignore1, size_t ignore2) {} |
| 24 #endif // __has_feature(address_sanitizer) | 25 #endif // __has_feature(address_sanitizer) |
| 25 #else // defined(__has_feature) | 26 #else // defined(__has_feature) |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 static void JumpToExceptionHandler(uword program_counter, | 267 static void JumpToExceptionHandler(uword program_counter, |
| 267 uword stack_pointer, | 268 uword stack_pointer, |
| 268 uword frame_pointer, | 269 uword frame_pointer, |
| 269 const Object& exception_object, | 270 const Object& exception_object, |
| 270 const Object& stacktrace_object) { | 271 const Object& stacktrace_object) { |
| 271 // The no_gc StackResource is unwound through the tear down of | 272 // The no_gc StackResource is unwound through the tear down of |
| 272 // stack resources below. | 273 // stack resources below. |
| 273 NoGCScope no_gc; | 274 NoGCScope no_gc; |
| 274 RawObject* raw_exception = exception_object.raw(); | 275 RawObject* raw_exception = exception_object.raw(); |
| 275 RawObject* raw_stacktrace = stacktrace_object.raw(); | 276 RawObject* raw_stacktrace = stacktrace_object.raw(); |
| 277 Isolate* isolate = Isolate::Current(); |
| 276 | 278 |
| 277 #if defined(USING_SIMULATOR) | 279 #if defined(USING_SIMULATOR) |
| 278 // Unwinding of the C++ frames and destroying of their stack resources is done | 280 // Unwinding of the C++ frames and destroying of their stack resources is done |
| 279 // by the simulator, because the target stack_pointer is a simulated stack | 281 // by the simulator, because the target stack_pointer is a simulated stack |
| 280 // pointer and not the C++ stack pointer. | 282 // pointer and not the C++ stack pointer. |
| 281 | 283 |
| 282 // Continue simulating at the given pc in the given frame after setting up the | 284 // Continue simulating at the given pc in the given frame after setting up the |
| 283 // exception object in the kExceptionObjectReg register and the stacktrace | 285 // exception object in the kExceptionObjectReg register and the stacktrace |
| 284 // object (may be raw null) in the kStackTraceObjectReg register. | 286 // object (may be raw null) in the kStackTraceObjectReg register. |
| 287 isolate->set_vm_tag(VMTag::kScriptTagId); |
| 285 Simulator::Current()->Longjmp(program_counter, stack_pointer, frame_pointer, | 288 Simulator::Current()->Longjmp(program_counter, stack_pointer, frame_pointer, |
| 286 raw_exception, raw_stacktrace); | 289 raw_exception, raw_stacktrace); |
| 287 #else | 290 #else |
| 288 // Prepare for unwinding frames by destroying all the stack resources | 291 // Prepare for unwinding frames by destroying all the stack resources |
| 289 // in the previous frames. | 292 // in the previous frames. |
| 290 Isolate* isolate = Isolate::Current(); | 293 |
| 291 while (isolate->top_resource() != NULL && | 294 while (isolate->top_resource() != NULL && |
| 292 (reinterpret_cast<uword>(isolate->top_resource()) < stack_pointer)) { | 295 (reinterpret_cast<uword>(isolate->top_resource()) < stack_pointer)) { |
| 293 isolate->top_resource()->~StackResource(); | 296 isolate->top_resource()->~StackResource(); |
| 294 } | 297 } |
| 295 | 298 |
| 296 // Call a stub to set up the exception object in kExceptionObjectReg, | 299 // Call a stub to set up the exception object in kExceptionObjectReg, |
| 297 // to set up the stacktrace object in kStackTraceObjectReg, and to | 300 // to set up the stacktrace object in kStackTraceObjectReg, and to |
| 298 // continue execution at the given pc in the given frame. | 301 // continue execution at the given pc in the given frame. |
| 299 typedef void (*ExcpHandler)(uword, uword, uword, RawObject*, RawObject*); | 302 typedef void (*ExcpHandler)(uword, uword, uword, RawObject*, RawObject*); |
| 300 ExcpHandler func = reinterpret_cast<ExcpHandler>( | 303 ExcpHandler func = reinterpret_cast<ExcpHandler>( |
| 301 StubCode::JumpToExceptionHandlerEntryPoint()); | 304 StubCode::JumpToExceptionHandlerEntryPoint()); |
| 302 | 305 |
| 303 // Unpoison the stack before we tear it down in the generated stub code. | 306 // Unpoison the stack before we tear it down in the generated stub code. |
| 304 uword current_sp = reinterpret_cast<uword>(&program_counter) - 1024; | 307 uword current_sp = reinterpret_cast<uword>(&program_counter) - 1024; |
| 305 __asan_unpoison_memory_region(reinterpret_cast<void*>(current_sp), | 308 __asan_unpoison_memory_region(reinterpret_cast<void*>(current_sp), |
| 306 stack_pointer - current_sp); | 309 stack_pointer - current_sp); |
| 310 isolate->set_vm_tag(VMTag::kScriptTagId); |
| 307 func(program_counter, stack_pointer, frame_pointer, | 311 func(program_counter, stack_pointer, frame_pointer, |
| 308 raw_exception, raw_stacktrace); | 312 raw_exception, raw_stacktrace); |
| 309 #endif | 313 #endif |
| 310 UNREACHABLE(); | 314 UNREACHABLE(); |
| 311 } | 315 } |
| 312 | 316 |
| 313 | 317 |
| 314 static RawField* LookupStacktraceField(const Instance& instance) { | 318 static RawField* LookupStacktraceField(const Instance& instance) { |
| 315 if (instance.GetClassId() < kNumPredefinedCids) { | 319 if (instance.GetClassId() < kNumPredefinedCids) { |
| 316 // 'class Error' is not a predefined class. | 320 // 'class Error' is not a predefined class. |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 break; | 710 break; |
| 707 } | 711 } |
| 708 | 712 |
| 709 return DartLibraryCalls::InstanceCreate(library, | 713 return DartLibraryCalls::InstanceCreate(library, |
| 710 *class_name, | 714 *class_name, |
| 711 *constructor_name, | 715 *constructor_name, |
| 712 arguments); | 716 arguments); |
| 713 } | 717 } |
| 714 | 718 |
| 715 } // namespace dart | 719 } // namespace dart |
| OLD | NEW |