summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2019-08-04 17:23:12 +0800
committerJohn Hodge <tpg@ucc.asn.au>2019-08-04 17:23:12 +0800
commit6c6fd331a7bb415abd723f29cb9014dac25d50cf (patch)
tree2351ca2820c575c846b9160bfe8fd62ecbac47b6 /tools
parente88271aae2b141124f45879664afc3d839f4194e (diff)
downloadmrust-6c6fd331a7bb415abd723f29cb9014dac25d50cf.tar.gz
Standalone MIRI - Properly tagged FFI pointers
Diffstat (limited to 'tools')
-rw-r--r--tools/standalone_miri/main.cpp7
-rw-r--r--tools/standalone_miri/miri.cpp21
-rw-r--r--tools/standalone_miri/value.hpp4
3 files changed, 21 insertions, 11 deletions
diff --git a/tools/standalone_miri/main.cpp b/tools/standalone_miri/main.cpp
index ad5a978e..4da6c7fc 100644
--- a/tools/standalone_miri/main.cpp
+++ b/tools/standalone_miri/main.cpp
@@ -74,12 +74,13 @@ int main(int argc, const char* argv[])
// Create argc/argv based on input arguments
auto argv_alloc = Allocation::new_alloc((1 + opts.args.size()) * POINTER_SIZE, "argv");
argv_alloc->write_usize(0 * POINTER_SIZE, Allocation::PTR_BASE);
- argv_alloc->relocations.push_back({ 0 * POINTER_SIZE, RelocationPtr::new_ffi(FFIPointer::new_const_bytes(opts.infile.c_str(), opts.infile.size() + 1)) });
+ argv_alloc->relocations.push_back({ 0 * POINTER_SIZE, RelocationPtr::new_ffi(FFIPointer::new_const_bytes("argv0", opts.infile.c_str(), opts.infile.size() + 1)) });
for(size_t i = 0; i < opts.args.size(); i ++)
{
argv_alloc->write_usize((1 + i) * POINTER_SIZE, Allocation::PTR_BASE);
- argv_alloc->relocations.push_back({ (1 + i) * POINTER_SIZE, RelocationPtr::new_ffi(FFIPointer::new_const_bytes(opts.args[0], ::std::strlen(opts.args[0]) + 1)) });
+ argv_alloc->relocations.push_back({ (1 + i) * POINTER_SIZE, RelocationPtr::new_ffi(FFIPointer::new_const_bytes("argv", opts.args[i], ::std::strlen(opts.args[i]) + 1)) });
}
+ LOG_DEBUG("argv_alloc = " << *argv_alloc);
// Construct argc/argv values
auto val_argc = Value::new_isize(1 + opts.args.size());
@@ -90,7 +91,7 @@ int main(int argc, const char* argv[])
try
{
InterpreterThread root_thread(tree);
-
+
::std::vector<Value> args;
args.push_back(::std::move(val_argc));
args.push_back(::std::move(val_argv));
diff --git a/tools/standalone_miri/miri.cpp b/tools/standalone_miri/miri.cpp
index 04dc13ba..e9d6d150 100644
--- a/tools/standalone_miri/miri.cpp
+++ b/tools/standalone_miri/miri.cpp
@@ -522,7 +522,7 @@ struct MirHelpers
TU_ARM(c, Bytes, ce) {
ty = ::HIR::TypeRef(RawType::U8).wrap(TypeWrapper::Ty::Slice, 0).wrap(TypeWrapper::Ty::Borrow, 0);
Value val = Value(ty);
- val.write_ptr(0, Allocation::PTR_BASE + 0, RelocationPtr::new_ffi(FFIPointer::new_const_bytes(ce.data(), ce.size())));
+ val.write_ptr(0, Allocation::PTR_BASE + 0, RelocationPtr::new_ffi(FFIPointer::new_const_bytes("Constant::Bytes", ce.data(), ce.size())));
val.write_usize(POINTER_SIZE, ce.size());
LOG_DEBUG(c << " = " << val);
return val;
@@ -1035,7 +1035,14 @@ bool InterpreterThread::step_one(Value& out_thread_result)
case ::MIR::eBinOp::LE: {
LOG_ASSERT(ty_l == ty_r, "BinOp type mismatch - " << ty_l << " != " << ty_r);
int res = 0;
+
// TODO: Handle comparison of the relocations too
+ // - If both sides have a relocation:
+ // > EQ/NE always valid
+ // > others require the same relocation
+ // - If one side has a relocation:
+ // > EQ/NE only allow zero on the non-reloc side
+ // > others are invalid?
//const auto& alloc_l = v_l.m_value ? v_l.m_value->allocation : v_l.m_alloc;
//const auto& alloc_r = v_r.m_value ? v_r.m_value->allocation : v_r.m_alloc;
@@ -2171,7 +2178,7 @@ bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, c
}
else if( link_name == "__errno_location" )
{
- rv = Value::new_ffiptr(FFIPointer::new_const_bytes(&errno, sizeof(errno)));
+ rv = Value::new_ffiptr(FFIPointer::new_const_bytes("errno", &errno, sizeof(errno)));
}
else if( link_name == "syscall" )
{
@@ -2258,7 +2265,7 @@ bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, c
if( ret_ptr )
{
LOG_DEBUG("= \"" << ret_ptr << "\"");
- rv = Value::new_ffiptr(FFIPointer::new_const_bytes(ret_ptr, strlen(ret_ptr)+1));
+ rv = Value::new_ffiptr(FFIPointer::new_const_bytes("getenv", ret_ptr, strlen(ret_ptr)+1));
}
else
{
@@ -2660,19 +2667,21 @@ bool InterpreterThread::call_intrinsic(Value& rv, const RcString& name, const ::
size_t ent_count = args.at(2).read_usize(0);
size_t ent_size = ty_params.tys.at(0).get_size();
auto byte_count = ent_count * ent_size;
+ LOG_DEBUG("`copy_nonoverlapping`: byte_count=" << byte_count);
// A count of zero doesn't need to do any of the checks (TODO: Validate this rule)
if( byte_count > 0 )
{
- // TODO: is this inefficient?
- auto src_val = args.at(0).read_pointer_valref_mut(0, byte_count).read_value(0, byte_count);
+ auto src_vr = args.at(0).read_pointer_valref_mut(0, byte_count);
auto dst_vr = args.at(1).read_pointer_valref_mut(0, byte_count);
-
auto& dst_alloc = dst_vr.m_alloc;
LOG_ASSERT(dst_alloc, "Destination of copy* must be a memory allocation");
LOG_ASSERT(dst_alloc.is_alloc(), "Destination of copy* must be a memory allocation");
+ // TODO: is this inefficient?
+ auto src_val = src_vr.read_value(0, byte_count);
+ LOG_DEBUG("src_val = " << src_val);
dst_alloc.alloc().write_value(dst_vr.m_offset, ::std::move(src_val));
}
}
diff --git a/tools/standalone_miri/value.hpp b/tools/standalone_miri/value.hpp
index ec8f1899..f4ac2d36 100644
--- a/tools/standalone_miri/value.hpp
+++ b/tools/standalone_miri/value.hpp
@@ -56,8 +56,8 @@ struct FFIPointer
const char* tag_name;
::std::shared_ptr<FfiLayout> layout;
- static FFIPointer new_const_bytes(const void* s, size_t size) {
- return FFIPointer { const_cast<void*>(s), "", ::std::make_shared<FfiLayout>(FfiLayout::new_const_bytes(size)) };
+ static FFIPointer new_const_bytes(const char* name, const void* s, size_t size) {
+ return FFIPointer { const_cast<void*>(s), name, ::std::make_shared<FfiLayout>(FfiLayout::new_const_bytes(size)) };
};
size_t get_size() const {