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/longjump.h" | 5 #include "vm/longjump.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.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/os.h" | 13 #include "vm/os.h" |
14 | 14 |
15 namespace dart { | 15 namespace dart { |
16 | 16 |
17 jmp_buf* LongJump::Set() { | 17 jmp_buf* LongJump::Set() { |
18 top_ = Isolate::Current()->top_resource(); | 18 top_ = Isolate::Current()->top_resource(); |
19 return &environment_; | 19 return &environment_; |
20 } | 20 } |
21 | 21 |
22 | 22 |
23 bool LongJump::IsSafeToJump() { | |
24 // We do not want to jump past Dart frames. | |
25 Isolate* isolate = Isolate::Current(); | |
26 uword jumpbuf_addr = reinterpret_cast<uword>(this); | |
27 return (isolate->top_exit_frame_info() == NULL || | |
28 jumpbuf_addr < isolate->top_exit_frame_info()); | |
siva
2012/01/31 00:52:34
This code seems to assume that the stack always gr
turnidge
2012/01/31 21:56:31
I also make this assumption in the stack overflow
siva
2012/02/01 19:09:38
Maybe a comment stating that this code assumes the
| |
29 } | |
30 | |
31 | |
23 void LongJump::Jump(int value, const Error& error) { | 32 void LongJump::Jump(int value, const Error& error) { |
24 // A zero is the default return value from setting up a LongJump using Set. | 33 // A zero is the default return value from setting up a LongJump using Set. |
25 ASSERT(value != 0); | 34 ASSERT(value != 0); |
35 ASSERT(IsSafeToJump()); | |
26 | 36 |
27 Isolate* isolate = Isolate::Current(); | 37 Isolate* isolate = Isolate::Current(); |
28 | 38 |
29 // Remember the error in the sticky error of this isolate. | 39 // Remember the error in the sticky error of this isolate. |
30 isolate->object_store()->set_sticky_error(error); | 40 isolate->object_store()->set_sticky_error(error); |
31 | 41 |
32 // Destruct all the active StackResource objects. | 42 // Destruct all the active StackResource objects. |
33 StackResource* current_resource = isolate->top_resource(); | 43 StackResource* current_resource = isolate->top_resource(); |
34 while (current_resource != top_) { | 44 while (current_resource != top_) { |
35 current_resource->~StackResource(); | 45 current_resource->~StackResource(); |
36 current_resource = isolate->top_resource(); | 46 current_resource = isolate->top_resource(); |
37 } | 47 } |
38 longjmp(environment_, value); | 48 longjmp(environment_, value); |
39 UNREACHABLE(); | 49 UNREACHABLE(); |
40 } | 50 } |
41 | 51 |
42 } // namespace dart | 52 } // namespace dart |
OLD | NEW |