Commit ee78c7d7 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] [interpreter] Fix deallocation of InterpretedFrameImpl

We were passing a pointer to an object allocated as
{InterpretedFrameImpl} in an {std::unique_ptr<InterpretedFrame>}.
The default deleter then called {delete ptr;} on a ptr of type
{InterpretedFrame*}, even though that object was allocated as
{InterpretedFrameImpl}. This error might caught by validators.
Fix this by passing a custom deleter on the unique_ptr.

R=ahaas@chromium.org, ulan@chromium.org

Bug: v8:7231
Change-Id: Ia18114236384813c4878319209ae4535fda56c41
Reviewed-on: https://chromium-review.googlesource.com/834510Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50226}
parent bf691e79
...@@ -9,15 +9,11 @@ ...@@ -9,15 +9,11 @@
#include "src/frames.h" #include "src/frames.h"
#include "src/isolate.h" #include "src/isolate.h"
#include "src/objects.h" #include "src/objects.h"
#include "src/wasm/wasm-interpreter.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
// Forward declaration:
namespace wasm {
class InterpretedFrame;
}
class FrameInspector { class FrameInspector {
public: public:
FrameInspector(StandardFrame* frame, int inlined_frame_index, FrameInspector(StandardFrame* frame, int inlined_frame_index,
...@@ -61,7 +57,7 @@ class FrameInspector { ...@@ -61,7 +57,7 @@ class FrameInspector {
StandardFrame* frame_; StandardFrame* frame_;
std::unique_ptr<DeoptimizedFrameInfo> deoptimized_frame_; std::unique_ptr<DeoptimizedFrameInfo> deoptimized_frame_;
std::unique_ptr<wasm::InterpretedFrame> wasm_interpreted_frame_; wasm::WasmInterpreter::FramePtr wasm_interpreted_frame_;
Isolate* isolate_; Isolate* isolate_;
Handle<Script> script_; Handle<Script> script_;
Handle<Object> receiver_; Handle<Object> receiver_;
......
...@@ -373,8 +373,8 @@ class InterpreterHandle { ...@@ -373,8 +373,8 @@ class InterpreterHandle {
return stack; return stack;
} }
std::unique_ptr<wasm::InterpretedFrame> GetInterpretedFrame( WasmInterpreter::FramePtr GetInterpretedFrame(Address frame_pointer,
Address frame_pointer, int idx) { int idx) {
DCHECK_EQ(1, interpreter()->GetThreadCount()); DCHECK_EQ(1, interpreter()->GetThreadCount());
WasmInterpreter::Thread* thread = interpreter()->GetThread(0); WasmInterpreter::Thread* thread = interpreter()->GetThread(0);
...@@ -790,7 +790,7 @@ std::vector<std::pair<uint32_t, int>> WasmDebugInfo::GetInterpretedStack( ...@@ -790,7 +790,7 @@ std::vector<std::pair<uint32_t, int>> WasmDebugInfo::GetInterpretedStack(
return GetInterpreterHandle(this)->GetInterpretedStack(frame_pointer); return GetInterpreterHandle(this)->GetInterpretedStack(frame_pointer);
} }
std::unique_ptr<wasm::InterpretedFrame> WasmDebugInfo::GetInterpretedFrame( wasm::WasmInterpreter::FramePtr WasmDebugInfo::GetInterpretedFrame(
Address frame_pointer, int idx) { Address frame_pointer, int idx) {
return GetInterpreterHandle(this)->GetInterpretedFrame(frame_pointer, idx); return GetInterpreterHandle(this)->GetInterpretedFrame(frame_pointer, idx);
} }
......
...@@ -2770,11 +2770,10 @@ pc_t WasmInterpreter::Thread::GetBreakpointPc() { ...@@ -2770,11 +2770,10 @@ pc_t WasmInterpreter::Thread::GetBreakpointPc() {
int WasmInterpreter::Thread::GetFrameCount() { int WasmInterpreter::Thread::GetFrameCount() {
return ToImpl(this)->GetFrameCount(); return ToImpl(this)->GetFrameCount();
} }
std::unique_ptr<InterpretedFrame> WasmInterpreter::Thread::GetFrame(int index) { WasmInterpreter::FramePtr WasmInterpreter::Thread::GetFrame(int index) {
DCHECK_LE(0, index); DCHECK_LE(0, index);
DCHECK_GT(GetFrameCount(), index); DCHECK_GT(GetFrameCount(), index);
return std::unique_ptr<InterpretedFrame>( return FramePtr(ToFrame(new InterpretedFrameImpl(ToImpl(this), index)));
ToFrame(new InterpretedFrameImpl(ToImpl(this), index)));
} }
WasmValue WasmInterpreter::Thread::GetReturnValue(int index) { WasmValue WasmInterpreter::Thread::GetReturnValue(int index) {
return ToImpl(this)->GetReturnValue(index); return ToImpl(this)->GetReturnValue(index);
...@@ -2935,6 +2934,9 @@ WasmValue InterpretedFrame::GetLocalValue(int index) const { ...@@ -2935,6 +2934,9 @@ WasmValue InterpretedFrame::GetLocalValue(int index) const {
WasmValue InterpretedFrame::GetStackValue(int index) const { WasmValue InterpretedFrame::GetStackValue(int index) const {
return ToImpl(this)->GetStackValue(index); return ToImpl(this)->GetStackValue(index);
} }
void InterpretedFrame::Deleter::operator()(InterpretedFrame* ptr) {
delete ToImpl(ptr);
}
//============================================================================ //============================================================================
// Public API of the heap objects scope. // Public API of the heap objects scope.
......
...@@ -71,6 +71,12 @@ class InterpretedFrame { ...@@ -71,6 +71,12 @@ class InterpretedFrame {
WasmValue GetLocalValue(int index) const; WasmValue GetLocalValue(int index) const;
WasmValue GetStackValue(int index) const; WasmValue GetStackValue(int index) const;
// Deleter struct to delete the underlying InterpretedFrameImpl without
// violating language specifications.
struct Deleter {
void operator()(InterpretedFrame* ptr);
};
private: private:
friend class WasmInterpreter; friend class WasmInterpreter;
// Don't instante InterpretedFrames; they will be allocated as // Don't instante InterpretedFrames; they will be allocated as
...@@ -113,6 +119,8 @@ class V8_EXPORT_PRIVATE WasmInterpreter { ...@@ -113,6 +119,8 @@ class V8_EXPORT_PRIVATE WasmInterpreter {
AfterCall = 1 << 1 AfterCall = 1 << 1
}; };
using FramePtr = std::unique_ptr<InterpretedFrame, InterpretedFrame::Deleter>;
// Representation of a thread in the interpreter. // Representation of a thread in the interpreter.
class V8_EXPORT_PRIVATE Thread { class V8_EXPORT_PRIVATE Thread {
// Don't instante Threads; they will be allocated as ThreadImpl in the // Don't instante Threads; they will be allocated as ThreadImpl in the
...@@ -139,7 +147,7 @@ class V8_EXPORT_PRIVATE WasmInterpreter { ...@@ -139,7 +147,7 @@ class V8_EXPORT_PRIVATE WasmInterpreter {
// TODO(clemensh): Make this uint32_t. // TODO(clemensh): Make this uint32_t.
int GetFrameCount(); int GetFrameCount();
// The InterpretedFrame is only valid as long as the Thread is paused. // The InterpretedFrame is only valid as long as the Thread is paused.
std::unique_ptr<InterpretedFrame> GetFrame(int index); FramePtr GetFrame(int index);
WasmValue GetReturnValue(int index = 0); WasmValue GetReturnValue(int index = 0);
TrapReason GetTrapReason(); TrapReason GetTrapReason();
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "src/objects.h" #include "src/objects.h"
#include "src/objects/script.h" #include "src/objects/script.h"
#include "src/wasm/decoder.h" #include "src/wasm/decoder.h"
#include "src/wasm/wasm-interpreter.h"
#include "src/wasm/wasm-limits.h" #include "src/wasm/wasm-limits.h"
#include "src/heap/heap.h" #include "src/heap/heap.h"
...@@ -25,7 +26,6 @@ namespace wasm { ...@@ -25,7 +26,6 @@ namespace wasm {
class InterpretedFrame; class InterpretedFrame;
class NativeModule; class NativeModule;
class WasmCode; class WasmCode;
class WasmInterpreter;
struct WasmModule; struct WasmModule;
class SignatureMap; class SignatureMap;
typedef Address GlobalHandleAddress; typedef Address GlobalHandleAddress;
...@@ -631,8 +631,8 @@ class WasmDebugInfo : public FixedArray { ...@@ -631,8 +631,8 @@ class WasmDebugInfo : public FixedArray {
std::vector<std::pair<uint32_t, int>> GetInterpretedStack( std::vector<std::pair<uint32_t, int>> GetInterpretedStack(
Address frame_pointer); Address frame_pointer);
std::unique_ptr<wasm::InterpretedFrame> GetInterpretedFrame( wasm::WasmInterpreter::FramePtr GetInterpretedFrame(Address frame_pointer,
Address frame_pointer, int frame_index); int frame_index);
// Unwind the interpreted stack belonging to the passed interpreter entry // Unwind the interpreted stack belonging to the passed interpreter entry
// frame. // 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