From 9b76d02f264d20e758483da26fefd0037766c669 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Thu, 21 Aug 2014 21:36:34 -0700 Subject: [PATCH] Fixing alloy-sandbox. --- src/alloy/backend/x64/x64_assembler.cc | 6 +++++- tools/alloy-sandbox/alloy-sandbox.cc | 18 +++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/alloy/backend/x64/x64_assembler.cc b/src/alloy/backend/x64/x64_assembler.cc index 17e36025a..a963b39e5 100644 --- a/src/alloy/backend/x64/x64_assembler.cc +++ b/src/alloy/backend/x64/x64_assembler.cc @@ -37,7 +37,11 @@ using alloy::runtime::FunctionInfo; X64Assembler::X64Assembler(X64Backend* backend) : Assembler(backend), x64_backend_(backend) {} -X64Assembler::~X64Assembler() = default; +X64Assembler::~X64Assembler() { + // Emitter must be freed before the allocator. + emitter_.reset(); + allocator_.reset(); +} int X64Assembler::Initialize() { int result = Assembler::Initialize(); diff --git a/tools/alloy-sandbox/alloy-sandbox.cc b/tools/alloy-sandbox/alloy-sandbox.cc index 66afdfdcb..e09030db1 100644 --- a/tools/alloy-sandbox/alloy-sandbox.cc +++ b/tools/alloy-sandbox/alloy-sandbox.cc @@ -26,10 +26,10 @@ using alloy::runtime::Runtime; class ThreadState : public alloy::runtime::ThreadState { public: - ThreadState(Runtime* runtime, uint32_t thread_id, size_t stack_size, - uint64_t thread_state_address, uint64_t thread_stack_address) + ThreadState(Runtime* runtime, uint32_t thread_id, uint64_t stack_address, + size_t stack_size, uint64_t thread_state_address) : alloy::runtime::ThreadState(runtime, thread_id), - stack_address_(thread_stack_address), + stack_address_(stack_address), stack_size_(stack_size), thread_state_address_(thread_state_address) { memset(memory_->Translate(stack_address_), 0, stack_size_); @@ -87,10 +87,10 @@ int main(std::vector& args) { auto frontend = std::make_unique(runtime.get()); std::unique_ptr backend; - // auto backend = - // std::make_unique(runtime.get()); - // auto backend = - // std::make_unique(runtime.get()); + // backend = + // std::make_unique(runtime.get()); + // backend = + // std::make_unique(runtime.get()); runtime->Initialize(std::move(frontend), std::move(backend)); auto module = std::make_unique(runtime.get()); @@ -98,9 +98,9 @@ int main(std::vector& args) { runtime->AddModule(std::move(module)); { - uint64_t thread_state_address = 0; - uint64_t stack_address = memory_size - 1024; uint64_t stack_size = 64 * 1024; + uint64_t stack_address = memory_size - stack_size; + uint64_t thread_state_address = stack_address - 0x1000; auto thread_state = std::make_unique( runtime.get(), 100, stack_address, stack_size, thread_state_address);