• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/execution/interrupts-scope.h"
6 
7 #include "src/execution/isolate.h"
8 
9 namespace v8 {
10 namespace internal {
11 
InterruptsScope(Isolate * isolate,intptr_t intercept_mask,Mode mode)12 InterruptsScope::InterruptsScope(Isolate* isolate, intptr_t intercept_mask,
13                                  Mode mode)
14     : stack_guard_(isolate->stack_guard()),
15       intercept_mask_(intercept_mask),
16       intercepted_flags_(0),
17       mode_(mode) {
18   if (mode_ != kNoop) stack_guard_->PushInterruptsScope(this);
19 }
20 
Intercept(StackGuard::InterruptFlag flag)21 bool InterruptsScope::Intercept(StackGuard::InterruptFlag flag) {
22   InterruptsScope* last_postpone_scope = nullptr;
23   for (InterruptsScope* current = this; current; current = current->prev_) {
24     // We only consider scopes related to passed flag.
25     if (!(current->intercept_mask_ & flag)) continue;
26     if (current->mode_ == kRunInterrupts) {
27       // If innermost scope is kRunInterrupts scope, prevent interrupt from
28       // being intercepted.
29       break;
30     } else {
31       DCHECK_EQ(current->mode_, kPostponeInterrupts);
32       last_postpone_scope = current;
33     }
34   }
35   // If there is no postpone scope for passed flag then we should not intercept.
36   if (!last_postpone_scope) return false;
37   last_postpone_scope->intercepted_flags_ |= flag;
38   return true;
39 }
40 
41 }  // namespace internal
42 }  // namespace v8
43