Browse Source

Use uint64 type for call data size

cl-refactor
Paweł Bylica 10 years ago
parent
commit
9b14522b11
  1. 2
      evmjit/libevmjit-cpp/JitVM.cpp
  2. 7
      evmjit/libevmjit/Compiler.cpp
  3. 2
      evmjit/libevmjit/Runtime.cpp
  4. 3
      evmjit/libevmjit/RuntimeData.h
  5. 19
      evmjit/libevmjit/RuntimeManager.cpp
  6. 1
      evmjit/libevmjit/RuntimeManager.h
  7. 2
      evmjit/libevmjit/Stack.cpp

2
evmjit/libevmjit-cpp/JitVM.cpp

@ -18,7 +18,6 @@ bytesConstRef JitVM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t)
m_data.elems[RuntimeData::Caller] = eth2llvm(fromAddress(_ext.caller));
m_data.elems[RuntimeData::Origin] = eth2llvm(fromAddress(_ext.origin));
m_data.elems[RuntimeData::CallValue] = eth2llvm(_ext.value);
m_data.elems[RuntimeData::CallDataSize] = eth2llvm(_ext.data.size());
m_data.elems[RuntimeData::GasPrice] = eth2llvm(_ext.gasPrice);
m_data.elems[RuntimeData::CoinBase] = eth2llvm(fromAddress(_ext.currentBlock.coinbaseAddress));
m_data.elems[RuntimeData::TimeStamp] = eth2llvm(_ext.currentBlock.timestamp);
@ -28,6 +27,7 @@ bytesConstRef JitVM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t)
m_data.callData = _ext.data.data();
m_data.code = _ext.code.data();
m_data.codeSize = _ext.code.size();
m_data.callDataSize = _ext.data.size();
auto env = reinterpret_cast<Env*>(&_ext);
auto exitCode = m_engine.run(_ext.code, &m_data, env);

7
evmjit/libevmjit/Compiler.cpp

@ -637,7 +637,6 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
case Instruction::CALLER:
case Instruction::ORIGIN:
case Instruction::CALLVALUE:
case Instruction::CALLDATASIZE:
case Instruction::GASPRICE:
case Instruction::COINBASE:
case Instruction::TIMESTAMP:
@ -655,6 +654,10 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
stack.push(_runtimeManager.getCodeSize());
break;
case Instruction::CALLDATASIZE:
stack.push(_runtimeManager.getCallDataSize());
break;
case Instruction::BLOCKHASH:
{
auto number = stack.pop();
@ -686,7 +689,7 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
auto reqBytes = stack.pop();
auto srcPtr = _runtimeManager.getCallData();
auto srcSize = _runtimeManager.get(RuntimeData::CallDataSize);
auto srcSize = _runtimeManager.getCallDataSize();
_memory.copyBytes(srcPtr, srcSize, srcIdx, destMemIdx, reqBytes);
break;

2
evmjit/libevmjit/Runtime.cpp

@ -22,7 +22,7 @@ bytes_ref Runtime::getReturnData() const
{
// TODO: Handle large indexes
auto offset = static_cast<size_t>(m_data.elems[RuntimeData::ReturnDataOffset].a);
auto size = static_cast<size_t>(m_data.elems[RuntimeData::ReturnDataSize].a);
auto size = static_cast<size_t>(m_data.callDataSize);
assert(offset + size <= m_memory.size() || size == 0);
if (offset + size > m_memory.size())

3
evmjit/libevmjit/RuntimeData.h

@ -19,7 +19,6 @@ struct RuntimeData
Caller,
Origin,
CallValue,
CallDataSize,
GasPrice,
CoinBase,
TimeStamp,
@ -30,7 +29,6 @@ struct RuntimeData
_size,
ReturnDataOffset = CallValue, // Reuse 2 fields for return data reference
ReturnDataSize = CallDataSize,
SuicideDestAddress = Address, ///< Suicide balance destination address
};
@ -38,6 +36,7 @@ struct RuntimeData
byte const* callData = nullptr;
byte const* code = nullptr;
uint64_t codeSize = 0;
uint64_t callDataSize = 0;
};
/// VM Environment (ExtVM) opaque type

19
evmjit/libevmjit/RuntimeManager.cpp

@ -25,7 +25,8 @@ llvm::StructType* RuntimeManager::getRuntimeDataType()
llvm::ArrayType::get(Type::Word, RuntimeData::_size), // i256[]
Type::BytePtr, // callData
Type::BytePtr, // code
Type::Size // codeSize
Type::Size, // codeSize
Type::Size // callDataSize
};
type = llvm::StructType::create(elems, "RuntimeData");
}
@ -62,7 +63,6 @@ llvm::Twine getName(RuntimeData::Index _index)
case RuntimeData::Caller: return "caller";
case RuntimeData::Origin: return "origin";
case RuntimeData::CallValue: return "callvalue";
case RuntimeData::CallDataSize: return "calldatasize";
case RuntimeData::GasPrice: return "gasprice";
case RuntimeData::CoinBase: return "coinbase";
case RuntimeData::TimeStamp: return "timestamp";
@ -128,7 +128,11 @@ void RuntimeManager::set(RuntimeData::Index _index, llvm::Value* _value)
void RuntimeManager::registerReturnData(llvm::Value* _offset, llvm::Value* _size)
{
set(RuntimeData::ReturnDataOffset, _offset);
set(RuntimeData::ReturnDataSize, _size);
auto ptr = getBuilder().CreateStructGEP(getDataPtr(), 4);
assert(ptr->getType() == Type::Size->getPointerTo());
assert(_size->getType() == Type::Word);
auto size64 = getBuilder().CreateTrunc(_size, Type::Size);
getBuilder().CreateStore(size64, ptr);
}
void RuntimeManager::registerSuicide(llvm::Value* _balanceAddress)
@ -151,7 +155,6 @@ llvm::Value* RuntimeManager::get(Instruction _inst)
case Instruction::CALLER: return get(RuntimeData::Caller);
case Instruction::ORIGIN: return get(RuntimeData::Origin);
case Instruction::CALLVALUE: return get(RuntimeData::CallValue);
case Instruction::CALLDATASIZE: return get(RuntimeData::CallDataSize);
case Instruction::GASPRICE: return get(RuntimeData::GasPrice);
case Instruction::COINBASE: return get(RuntimeData::CoinBase);
case Instruction::TIMESTAMP: return get(RuntimeData::TimeStamp);
@ -181,6 +184,14 @@ llvm::Value* RuntimeManager::getCodeSize()
return getBuilder().CreateZExt(value, Type::Word);
}
llvm::Value* RuntimeManager::getCallDataSize()
{
auto ptr = getBuilder().CreateStructGEP(getDataPtr(), 4);
auto value = getBuilder().CreateLoad(ptr, "callDataSize");
assert(value->getType() == Type::Size);
return getBuilder().CreateZExt(value, Type::Word);
}
llvm::Value* RuntimeManager::getJmpBuf()
{
auto ptr = getBuilder().CreateStructGEP(getRuntimePtr(), 2, "jmpbufPtr");

1
evmjit/libevmjit/RuntimeManager.h

@ -27,6 +27,7 @@ public:
llvm::Value* getCallData();
llvm::Value* getCode();
llvm::Value* getCodeSize();
llvm::Value* getCallDataSize();
void setGas(llvm::Value* _gas);
void registerReturnData(llvm::Value* _index, llvm::Value* _size);

2
evmjit/libevmjit/Stack.cpp

@ -116,7 +116,7 @@ extern "C"
index = std::numeric_limits<decltype(index)>::max(); // set max to fill with 0 leter
auto data = _rtData->callData;
auto size = _rtData->elems[RuntimeData::CallDataSize].a;
auto size = _rtData->callDataSize;
for (auto i = 0; i < 32; ++i)
{
if (index < size)

Loading…
Cancel
Save