From 12975426426a750f808028478b2cb03a4a405c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 25 Feb 2015 18:36:11 +0100 Subject: [PATCH] Remove external jmpBuf pointer --- evmjit/libevmjit/Memory.cpp | 27 ++++++++++++++------------- evmjit/libevmjit/Memory.h | 2 +- evmjit/libevmjit/Runtime.h | 1 - evmjit/libevmjit/RuntimeManager.cpp | 13 +------------ evmjit/libevmjit/RuntimeManager.h | 2 -- 5 files changed, 16 insertions(+), 29 deletions(-) diff --git a/evmjit/libevmjit/Memory.cpp b/evmjit/libevmjit/Memory.cpp index 53a40ffc5..4afe84997 100644 --- a/evmjit/libevmjit/Memory.cpp +++ b/evmjit/libevmjit/Memory.cpp @@ -40,9 +40,6 @@ llvm::Function* Memory::getRequireFunc() llvm::Type* resizeArgs[] = {Type::RuntimePtr, Type::WordPtr}; auto resize = llvm::Function::Create(llvm::FunctionType::get(Type::BytePtr, resizeArgs, false), llvm::Function::ExternalLinkage, "mem_resize", getModule()); - llvm::AttrBuilder attrBuilder; - attrBuilder.addAttribute(llvm::Attribute::NoAlias).addAttribute(llvm::Attribute::NoCapture).addAttribute(llvm::Attribute::NonNull).addAttribute(llvm::Attribute::ReadOnly); - resize->setAttributes(llvm::AttributeSet::get(resize->getContext(), 1, attrBuilder)); auto preBB = llvm::BasicBlock::Create(func->getContext(), "Pre", func); auto checkBB = llvm::BasicBlock::Create(func->getContext(), "Check", func); @@ -63,7 +60,7 @@ llvm::Function* Memory::getRequireFunc() auto sizeRequired = m_builder.CreateExtractValue(uaddRes, 0, "sizeReq"); auto overflow1 = m_builder.CreateExtractValue(uaddRes, 1, "overflow1"); auto rtPtr = getRuntimeManager().getRuntimePtr(); - auto sizePtr = m_builder.CreateStructGEP(rtPtr, 4); + auto sizePtr = m_builder.CreateStructGEP(rtPtr, 3); auto currSize = m_builder.CreateLoad(sizePtr, "currSize"); auto tooSmall = m_builder.CreateICmpULE(currSize, sizeRequired, "tooSmall"); auto resizeNeeded = m_builder.CreateOr(tooSmall, overflow1, "resizeNeeded"); @@ -85,7 +82,7 @@ llvm::Function* Memory::getRequireFunc() // Resize m_builder.CreateStore(sizeRequired, sizePtr); auto newData = m_builder.CreateCall2(resize, rt, sizePtr, "newData"); - auto dataPtr = m_builder.CreateStructGEP(rtPtr, 3); + auto dataPtr = m_builder.CreateStructGEP(rtPtr, 2); m_builder.CreateStore(newData, dataPtr); m_builder.CreateBr(returnBB); @@ -96,7 +93,7 @@ llvm::Function* Memory::getRequireFunc() return func; } -llvm::Function* Memory::createFunc(bool _isStore, llvm::Type* _valueType, GasMeter&) +llvm::Function* Memory::createFunc(bool _isStore, llvm::Type* _valueType) { auto isWord = _valueType == Type::Word; @@ -140,7 +137,7 @@ llvm::Function* Memory::getLoadWordFunc() { auto& func = m_loadWord; if (!func) - func = createFunc(false, Type::Word, m_gasMeter); + func = createFunc(false, Type::Word); return func; } @@ -148,7 +145,7 @@ llvm::Function* Memory::getStoreWordFunc() { auto& func = m_storeWord; if (!func) - func = createFunc(true, Type::Word, m_gasMeter); + func = createFunc(true, Type::Word); return func; } @@ -156,7 +153,7 @@ llvm::Function* Memory::getStoreByteFunc() { auto& func = m_storeByte; if (!func) - func = createFunc(true, Type::Byte, m_gasMeter); + func = createFunc(true, Type::Byte); return func; } @@ -183,15 +180,19 @@ void Memory::storeByte(llvm::Value* _addr, llvm::Value* _word) llvm::Value* Memory::getData() { auto rtPtr = getRuntimeManager().getRuntimePtr(); - auto dataPtr = m_builder.CreateStructGEP(rtPtr, 3); - return m_builder.CreateLoad(dataPtr, "data"); + auto dataPtr = m_builder.CreateStructGEP(rtPtr, 2); + auto data = m_builder.CreateLoad(dataPtr, "data"); + assert(data->getType() == Type::BytePtr); + return data; } llvm::Value* Memory::getSize() { auto rtPtr = getRuntimeManager().getRuntimePtr(); - auto sizePtr = m_builder.CreateStructGEP(rtPtr, 4); - return m_builder.CreateLoad(sizePtr, "size"); + auto sizePtr = m_builder.CreateStructGEP(rtPtr, 3); + auto size = m_builder.CreateLoad(sizePtr, "size"); + assert(size->getType() == Type::Word); + return size; } llvm::Value* Memory::getBytePtr(llvm::Value* _index) diff --git a/evmjit/libevmjit/Memory.h b/evmjit/libevmjit/Memory.h index e8edce735..92a8ce126 100644 --- a/evmjit/libevmjit/Memory.h +++ b/evmjit/libevmjit/Memory.h @@ -30,7 +30,7 @@ public: private: GasMeter& m_gasMeter; - llvm::Function* createFunc(bool _isStore, llvm::Type* _type, GasMeter& _gasMeter); + llvm::Function* createFunc(bool _isStore, llvm::Type* _type); llvm::Function* getRequireFunc(); llvm::Function* getLoadWordFunc(); diff --git a/evmjit/libevmjit/Runtime.h b/evmjit/libevmjit/Runtime.h index 69f2788a4..ac2e0acd7 100644 --- a/evmjit/libevmjit/Runtime.h +++ b/evmjit/libevmjit/Runtime.h @@ -25,7 +25,6 @@ public: private: RuntimeData& m_data; ///< Pointer to data. Expected by compiled contract. Env& m_env; ///< Pointer to environment proxy. Expected by compiled contract. - void* m_currJmpBuf = nullptr; ///< Pointer to jump buffer. Expected by compiled contract. byte* m_memoryData = nullptr; i256 m_memorySize; MemoryImpl m_memory; diff --git a/evmjit/libevmjit/RuntimeManager.cpp b/evmjit/libevmjit/RuntimeManager.cpp index 6249dedf9..b267a1c93 100644 --- a/evmjit/libevmjit/RuntimeManager.cpp +++ b/evmjit/libevmjit/RuntimeManager.cpp @@ -50,7 +50,6 @@ llvm::StructType* RuntimeManager::getRuntimeType() { Type::RuntimeDataPtr, // data Type::EnvPtr, // Env* - Type::BytePtr, // jmpbuf Type::BytePtr, // memory data Type::Word, // memory size }; @@ -93,10 +92,6 @@ RuntimeManager::RuntimeManager(llvm::IRBuilder<>& _builder, llvm::Value* _jmpBuf { m_longjmp = llvm::Intrinsic::getDeclaration(getModule(), llvm::Intrinsic::eh_sjlj_longjmp); - // save jmpBuf to be used in helper functions - auto ptr = m_builder.CreateStructGEP(getRuntimePtr(), 2); - m_builder.CreateStore(m_jmpBuf, ptr); - // Unpack data auto rtPtr = getRuntimePtr(); m_dataPtr = m_builder.CreateLoad(m_builder.CreateStructGEP(rtPtr, 0), "data"); @@ -154,7 +149,7 @@ void RuntimeManager::set(RuntimeData::Index _index, llvm::Value* _value) void RuntimeManager::registerReturnData(llvm::Value* _offset, llvm::Value* _size) { - auto memPtr = getBuilder().CreateStructGEP(getRuntimePtr(), 3); + auto memPtr = getBuilder().CreateStructGEP(getRuntimePtr(), 2); auto mem = getBuilder().CreateLoad(memPtr, "memory"); auto idx = m_builder.CreateTrunc(_offset, Type::Size, "idx"); // Never allow memory index be a type bigger than i64 // TODO: Report bug & fix to LLVM auto returnDataPtr = getBuilder().CreateGEP(mem, idx); @@ -225,12 +220,6 @@ llvm::Value* RuntimeManager::getCallDataSize() return getBuilder().CreateZExt(value, Type::Word); } -llvm::Value* RuntimeManager::getJmpBufExt() -{ - auto ptr = getBuilder().CreateStructGEP(getRuntimePtr(), 2); - return getBuilder().CreateLoad(ptr, "jmpBufExt"); -} - llvm::Value* RuntimeManager::getGas() { auto gas = get(RuntimeData::Gas); diff --git a/evmjit/libevmjit/RuntimeManager.h b/evmjit/libevmjit/RuntimeManager.h index a4a7f33d5..94e1eb303 100644 --- a/evmjit/libevmjit/RuntimeManager.h +++ b/evmjit/libevmjit/RuntimeManager.h @@ -31,7 +31,6 @@ public: llvm::Value* getCodeSize(); llvm::Value* getCallDataSize(); llvm::Value* getJmpBuf() { return m_jmpBuf; } - llvm::Value* getJmpBufExt(); void setGas(llvm::Value* _gas); void registerReturnData(llvm::Value* _index, llvm::Value* _size); @@ -40,7 +39,6 @@ public: void exit(ReturnCode _returnCode); void abort(llvm::Value* _jmpBuf); - void abort() { abort(getJmpBufExt()); } void setStack(Stack& _stack) { m_stack = &_stack; }