Commit 217b4cd6 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

Check for the termination request in STACK_CHECK

Bug: v8:9877
Change-Id: I55cedfd2748f00f989172d804eec735aa6c19365
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2742618Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73290}
parent 16175b15
...@@ -2188,13 +2188,21 @@ class StackLimitCheck { ...@@ -2188,13 +2188,21 @@ class StackLimitCheck {
Isolate* isolate_; Isolate* isolate_;
}; };
#define STACK_CHECK(isolate, result_value) \ // This macro may be used in context that disallows JS execution.
do { \ // That is why it checks only for a stack overflow and termination.
StackLimitCheck stack_check(isolate); \ #define STACK_CHECK(isolate, result_value) \
if (stack_check.HasOverflowed()) { \ do { \
isolate->StackOverflow(); \ StackLimitCheck stack_check(isolate); \
return result_value; \ if (stack_check.InterruptRequested()) { \
} \ if (stack_check.HasOverflowed()) { \
isolate->StackOverflow(); \
return result_value; \
} \
if (isolate->stack_guard()->HasTerminationRequest()) { \
isolate->TerminateExecution(); \
return result_value; \
} \
} \
} while (false) } while (false)
class StackTraceFailureMessage { class StackTraceFailureMessage {
......
...@@ -21832,7 +21832,6 @@ class RequestInterruptTestWithMathAbs ...@@ -21832,7 +21832,6 @@ class RequestInterruptTestWithMathAbs
} }
}; };
TEST(RequestInterruptTestWithFunctionCall) { TEST(RequestInterruptTestWithFunctionCall) {
RequestInterruptTestWithFunctionCall().RunTest(); RequestInterruptTestWithFunctionCall().RunTest();
} }
...@@ -21862,7 +21861,6 @@ TEST(RequestInterruptTestWithMathAbs) { ...@@ -21862,7 +21861,6 @@ TEST(RequestInterruptTestWithMathAbs) {
RequestInterruptTestWithMathAbs().RunTest(); RequestInterruptTestWithMathAbs().RunTest();
} }
class RequestMultipleInterrupts : public RequestInterruptTestBase { class RequestMultipleInterrupts : public RequestInterruptTestBase {
public: public:
RequestMultipleInterrupts() : i_thread(this), counter_(0) {} RequestMultipleInterrupts() : i_thread(this), counter_(0) {}
...@@ -25159,10 +25157,10 @@ THREADED_TEST(ReceiverConversionForAccessors) { ...@@ -25159,10 +25157,10 @@ THREADED_TEST(ReceiverConversionForAccessors) {
CHECK(CompileRun("acc.call(undefined) == 42")->BooleanValue(isolate)); CHECK(CompileRun("acc.call(undefined) == 42")->BooleanValue(isolate));
} }
class FutexInterruptionThread : public v8::base::Thread { class TerminateExecutionThread : public v8::base::Thread {
public: public:
explicit FutexInterruptionThread(v8::Isolate* isolate) explicit TerminateExecutionThread(v8::Isolate* isolate)
: Thread(Options("FutexInterruptionThread")), isolate_(isolate) {} : Thread(Options("TerminateExecutionThread")), isolate_(isolate) {}
void Run() override { void Run() override {
// Wait a bit before terminating. // Wait a bit before terminating.
...@@ -25174,14 +25172,13 @@ class FutexInterruptionThread : public v8::base::Thread { ...@@ -25174,14 +25172,13 @@ class FutexInterruptionThread : public v8::base::Thread {
v8::Isolate* isolate_; v8::Isolate* isolate_;
}; };
TEST(FutexInterruption) { TEST(FutexInterruption) {
i::FLAG_harmony_sharedarraybuffer = true; i::FLAG_harmony_sharedarraybuffer = true;
v8::Isolate* isolate = CcTest::isolate(); v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate); v8::HandleScope scope(isolate);
LocalContext env; LocalContext env;
FutexInterruptionThread timeout_thread(isolate); TerminateExecutionThread timeout_thread(isolate);
v8::TryCatch try_catch(CcTest::isolate()); v8::TryCatch try_catch(CcTest::isolate());
CHECK(timeout_thread.Start()); CHECK(timeout_thread.Start());
...@@ -25194,6 +25191,28 @@ TEST(FutexInterruption) { ...@@ -25194,6 +25191,28 @@ TEST(FutexInterruption) {
timeout_thread.Join(); timeout_thread.Join();
} }
TEST(StackCheckTermination) {
v8::Isolate* isolate = CcTest::isolate();
i::Isolate* i_isolate = CcTest::i_isolate();
v8::HandleScope scope(isolate);
LocalContext env;
TerminateExecutionThread timeout_thread(isolate);
v8::TryCatch try_catch(isolate);
CHECK(timeout_thread.Start());
auto should_continue = [i_isolate]() {
using StackLimitCheck = i::StackLimitCheck;
STACK_CHECK(i_isolate, false);
return true;
};
while (should_continue()) {
}
if (i_isolate->has_pending_exception()) i_isolate->ReportPendingMessages();
CHECK(try_catch.HasTerminated());
timeout_thread.Join();
}
static int nb_uncaught_exception_callback_calls = 0; static int nb_uncaught_exception_callback_calls = 0;
...@@ -5541,39 +5541,44 @@ TEST(TerminateOnResumeFromMicrotask) { ...@@ -5541,39 +5541,44 @@ TEST(TerminateOnResumeFromMicrotask) {
class FutexInterruptionThread : public v8::base::Thread { class FutexInterruptionThread : public v8::base::Thread {
public: public:
FutexInterruptionThread(v8::Isolate* isolate, v8::base::Semaphore* sem) FutexInterruptionThread(v8::Isolate* isolate, v8::base::Semaphore* enter,
v8::base::Semaphore* exit)
: Thread(Options("FutexInterruptionThread")), : Thread(Options("FutexInterruptionThread")),
isolate_(isolate), isolate_(isolate),
sem_(sem) {} enter_(enter),
exit_(exit) {}
void Run() override { void Run() override {
// Wait a bit before terminating. enter_->Wait();
v8::base::OS::Sleep(v8::base::TimeDelta::FromMilliseconds(100));
sem_->Wait();
v8::debug::SetTerminateOnResume(isolate_); v8::debug::SetTerminateOnResume(isolate_);
exit_->Signal();
} }
private: private:
v8::Isolate* isolate_; v8::Isolate* isolate_;
v8::base::Semaphore* sem_; v8::base::Semaphore* enter_;
v8::base::Semaphore* exit_;
}; };
namespace { namespace {
class SemaphoreTriggerOnBreak : public v8::debug::DebugDelegate { class SemaphoreTriggerOnBreak : public v8::debug::DebugDelegate {
public: public:
SemaphoreTriggerOnBreak() : sem_(0) {} SemaphoreTriggerOnBreak() : enter_(0), exit_(0) {}
void BreakProgramRequested(v8::Local<v8::Context> paused_context, void BreakProgramRequested(v8::Local<v8::Context> paused_context,
const std::vector<v8::debug::BreakpointId>& const std::vector<v8::debug::BreakpointId>&
inspector_break_points_hit) override { inspector_break_points_hit) override {
break_count_++; break_count_++;
sem_.Signal(); enter_.Signal();
exit_.Wait();
} }
v8::base::Semaphore* semaphore() { return &sem_; } v8::base::Semaphore* enter() { return &enter_; }
v8::base::Semaphore* exit() { return &exit_; }
int break_count() const { return break_count_; } int break_count() const { return break_count_; }
private: private:
v8::base::Semaphore sem_; v8::base::Semaphore enter_;
v8::base::Semaphore exit_;
int break_count_ = 0; int break_count_ = 0;
}; };
} // anonymous namespace } // anonymous namespace
...@@ -5586,8 +5591,8 @@ TEST(TerminateOnResumeFromOtherThread) { ...@@ -5586,8 +5591,8 @@ TEST(TerminateOnResumeFromOtherThread) {
SemaphoreTriggerOnBreak delegate; SemaphoreTriggerOnBreak delegate;
v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate); v8::debug::SetDebugDelegate(env->GetIsolate(), &delegate);
FutexInterruptionThread timeout_thread(env->GetIsolate(), FutexInterruptionThread timeout_thread(env->GetIsolate(), delegate.enter(),
delegate.semaphore()); delegate.exit());
CHECK(timeout_thread.Start()); CHECK(timeout_thread.Start());
v8::Local<v8::Context> context = env.local(); v8::Local<v8::Context> context = env.local();
...@@ -5618,7 +5623,7 @@ namespace { ...@@ -5618,7 +5623,7 @@ namespace {
class InterruptionBreakRightNow : public v8::base::Thread { class InterruptionBreakRightNow : public v8::base::Thread {
public: public:
explicit InterruptionBreakRightNow(v8::Isolate* isolate) explicit InterruptionBreakRightNow(v8::Isolate* isolate)
: Thread(Options("FutexInterruptionThread")), isolate_(isolate) {} : Thread(Options("InterruptionBreakRightNow")), isolate_(isolate) {}
void Run() override { void Run() override {
// Wait a bit before terminating. // Wait a bit before terminating.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment