Commit 2a50797d authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[runtime] Reset the current context when leaving the runtime in the CEntryStub

This CL introduces a Context::kInvalidContext sentinel value to make clear that
no context is active. We silently accept smi 0 (= nullptr) as a non-set context
which usually was the default value making it hard to ensure whether this
happened on purpose or not.


Change-Id: I5c35616f26b0b64c1cd976563a6eeb0ce474927d
Reviewed-on: https://chromium-review.googlesource.com/790291Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49778}
parent faffab96
......@@ -1218,7 +1218,6 @@ int TurboAssembler::ActivationFrameAlignment() {
#endif // V8_HOST_ARCH_ARM
}
void MacroAssembler::LeaveExitFrame(bool save_doubles, Register argument_count,
bool argument_count_is_length) {
ConstantPoolUnavailableScope constant_pool_unavailable(this);
......@@ -1244,6 +1243,7 @@ void MacroAssembler::LeaveExitFrame(bool save_doubles, Register argument_count,
Operand(ExternalReference(IsolateAddressId::kContextAddress, isolate())));
ldr(cp, MemOperand(scratch));
#ifdef DEBUG
mov(r3, Operand(Context::kInvalidContext));
mov(scratch,
Operand(ExternalReference(IsolateAddressId::kContextAddress, isolate())));
str(r3, MemOperand(scratch));
......
......@@ -415,7 +415,7 @@ void CEntryStub::Generate(MacroAssembler* masm) {
__ Peek(argc, 2 * kPointerSize);
__ Peek(target, 3 * kPointerSize);
__ LeaveExitFrame(save_doubles(), x10);
__ LeaveExitFrame(save_doubles(), x10, x9);
DCHECK(jssp.Is(__ StackPointer()));
if (!argv_in_register()) {
// Drop the remaining stack slots and return from the stub.
......@@ -1218,7 +1218,7 @@ static void CallApiFunctionAndReturn(MacroAssembler* masm,
__ Peek(x21, (spill_offset + 2) * kXRegSize);
__ Peek(x22, (spill_offset + 3) * kXRegSize);
__ LeaveExitFrame(false, x1);
__ LeaveExitFrame(false, x1, x5);
// Check if the function scheduled an exception.
__ Mov(x5, ExternalReference::scheduled_exception_address(isolate));
......
......@@ -2638,7 +2638,8 @@ void MacroAssembler::EnterExitFrame(bool save_doubles, const Register& scratch,
// Leave the current exit frame.
void MacroAssembler::LeaveExitFrame(bool restore_doubles,
const Register& scratch) {
const Register& scratch,
const Register& scratch2) {
DCHECK(csp.Is(StackPointer()));
if (restore_doubles) {
......@@ -2652,9 +2653,10 @@ void MacroAssembler::LeaveExitFrame(bool restore_doubles,
if (emit_debug_code()) {
// Also emit debug code to clear the cp in the top frame.
Mov(scratch2, Operand(Context::kInvalidContext));
Mov(scratch, Operand(ExternalReference(IsolateAddressId::kContextAddress,
isolate())));
Str(xzr, MemOperand(scratch));
Str(scratch2, MemOperand(scratch));
}
// Clear the frame pointer from the top frame.
Mov(scratch, Operand(ExternalReference(IsolateAddressId::kCEntryFPAddress,
......
......@@ -1992,7 +1992,8 @@ class MacroAssembler : public TurboAssembler {
// * The stack pointer is reset to jssp.
//
// The stack pointer must be csp on entry.
void LeaveExitFrame(bool save_doubles, const Register& scratch);
void LeaveExitFrame(bool save_doubles, const Register& scratch,
const Register& scratch2);
// Load the global proxy from the current context.
void LoadGlobalProxy(Register dst) {
......
......@@ -175,7 +175,9 @@ Node* CodeStubAssembler::SelectSmiConstant(Node* condition, Smi* true_value,
MachineRepresentation::kTaggedSigned);
}
Node* CodeStubAssembler::NoContextConstant() { return SmiConstant(0); }
Node* CodeStubAssembler::NoContextConstant() {
return SmiConstant(Context::kNoContext);
}
#define HEAP_CONSTANT_ACCESSOR(rootIndexName, rootAccessorName, name) \
compiler::TNode<std::remove_reference<decltype( \
......
......@@ -566,6 +566,9 @@ class Context: public FixedArray {
static const int FIRST_FUNCTION_MAP_INDEX = SLOPPY_FUNCTION_MAP_INDEX;
static const int LAST_FUNCTION_MAP_INDEX = CLASS_FUNCTION_MAP_INDEX;
static const int kNoContext = 0;
static const int kInvalidContext = 1;
void ResetErrorsThrown();
void IncrementErrorsThrown();
int GetErrorsThrown();
......
......@@ -738,7 +738,8 @@ void MacroAssembler::LeaveExitFrameEpilogue() {
isolate());
mov(esi, Operand::StaticVariable(context_address));
#ifdef DEBUG
mov(Operand::StaticVariable(context_address), Immediate(0));
mov(Operand::StaticVariable(context_address),
Immediate(Context::kInvalidContext));
#endif
// Clear the top frame.
......
......@@ -2548,7 +2548,7 @@ void MacroAssembler::LeaveExitFrameEpilogue() {
Operand context_operand = ExternalOperand(context_address);
movp(rsi, context_operand);
#ifdef DEBUG
movp(context_operand, Immediate(0));
movp(context_operand, Immediate(Context::kInvalidContext));
#endif
// Clear the top frame.
......
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