Skip to content

Commit bcc9df9

Browse files
mtbrandyCommit bot
authored andcommitted
PPC: Make Simulator respect C stack limits as well.
Port 7fb31bd Original commit message: The simulator uses a separate JS stack, exhaustion of the C stack however is not caught by JS limit checks. This change now lowers the limit of the JS stack accordingly on function calls. [email protected], [email protected], [email protected], [email protected] BUG=chromium:522380 LOG=n Review URL: https://codereview.chromium.org/1309303005 Cr-Commit-Position: refs/heads/master@{#30413}
1 parent e276f5d commit bcc9df9

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/ppc/simulator-ppc.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,15 @@ void Simulator::WriteDW(intptr_t addr, int64_t value) {
11061106

11071107

11081108
// Returns the limit of the stack area to enable checking for stack overflows.
1109-
uintptr_t Simulator::StackLimit() const {
1110-
// Leave a safety margin to prevent overrunning the stack when pushing values.
1109+
uintptr_t Simulator::StackLimit(uintptr_t c_limit) const {
1110+
// The simulator uses a separate JS stack. If we have exhausted the C stack,
1111+
// we also drop down the JS limit to reflect the exhaustion on the JS stack.
1112+
if (GetCurrentStackPosition() < c_limit) {
1113+
return reinterpret_cast<uintptr_t>(get_sp());
1114+
}
1115+
1116+
// Otherwise the limit is the JS stack. Leave a safety margin to prevent
1117+
// overrunning the stack when pushing values.
11111118
return reinterpret_cast<uintptr_t>(stack_) + stack_protection_size_;
11121119
}
11131120

@@ -3698,6 +3705,9 @@ void Simulator::Execute() {
36983705

36993706

37003707
void Simulator::CallInternal(byte* entry) {
3708+
// Adjust JS-based stack limit to C-based stack limit.
3709+
isolate_->stack_guard()->AdjustStackLimitForSimulator();
3710+
37013711
// Prepare to execute the code at entry
37023712
#if ABI_USES_FUNCTION_DESCRIPTORS
37033713
// entry is the function descriptor

src/ppc/simulator-ppc.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ class Simulator {
199199
void set_pc(intptr_t value);
200200
intptr_t get_pc() const;
201201

202-
Address get_sp() {
202+
Address get_sp() const {
203203
return reinterpret_cast<Address>(static_cast<intptr_t>(get_register(sp)));
204204
}
205205

206206
// Accessor to the internal simulator stack area.
207-
uintptr_t StackLimit() const;
207+
uintptr_t StackLimit(uintptr_t c_limit) const;
208208

209209
// Executes PPC instructions until the PC reaches end_sim_pc.
210210
void Execute();
@@ -403,15 +403,14 @@ class Simulator {
403403

404404

405405
// The simulator has its own stack. Thus it has a different stack limit from
406-
// the C-based native code. Setting the c_limit to indicate a very small
407-
// stack cause stack overflow errors, since the simulator ignores the input.
408-
// This is unlikely to be an issue in practice, though it might cause testing
409-
// trouble down the line.
406+
// the C-based native code. The JS-based limit normally points near the end of
407+
// the simulator stack. When the C-based limit is exhausted we reflect that by
408+
// lowering the JS-based limit as well, to make stack checks trigger.
410409
class SimulatorStack : public v8::internal::AllStatic {
411410
public:
412411
static inline uintptr_t JsLimitFromCLimit(v8::internal::Isolate* isolate,
413412
uintptr_t c_limit) {
414-
return Simulator::current(isolate)->StackLimit();
413+
return Simulator::current(isolate)->StackLimit(c_limit);
415414
}
416415

417416
static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) {

0 commit comments

Comments
 (0)