summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2018-05-13 09:55:13 +0800
committerJohn Hodge <tpg@mutabah.net>2018-05-13 09:55:13 +0800
commitc7b3036cefcd0dc412cb400455324d7ca8cd518e (patch)
treec789dec0d4d22cfabd04c65b20d058ace470559b /tools
parentd3334162fa91fe6fd5d02912d9f82794306e646a (diff)
downloadmrust-c7b3036cefcd0dc412cb400455324d7ca8cd518e.tar.gz
Standalone MIRI - memrchr and better null checking
Diffstat (limited to 'tools')
-rw-r--r--tools/standalone_miri/main.cpp22
-rw-r--r--tools/standalone_miri/value.cpp3
2 files changed, 25 insertions, 0 deletions
diff --git a/tools/standalone_miri/main.cpp b/tools/standalone_miri/main.cpp
index 16cfd972..4ee503d3 100644
--- a/tools/standalone_miri/main.cpp
+++ b/tools/standalone_miri/main.cpp
@@ -1857,6 +1857,28 @@ Value MIRI_Invoke_Extern(ModuleTree& modtree, ThreadState& thread, const ::std::
}
return rv;
}
+ else if( link_name == "memrchr" )
+ {
+ auto ptr_alloc = args.at(0).get_relocation(0);
+ auto c = args.at(1).read_i32(0);
+ auto n = args.at(2).read_usize(0);
+ const void* ptr = args.at(0).read_pointer_const(0, n);
+
+ const void* ret = memrchr(ptr, c, n);
+
+ auto rv = Value(::HIR::TypeRef(RawType::USize));
+ rv.create_allocation();
+ if( ret )
+ {
+ rv.write_usize(0, args.at(0).read_usize(0) + ( static_cast<const uint8_t*>(ret) - static_cast<const uint8_t*>(ptr) ));
+ rv.allocation.alloc().relocations.push_back({ 0, ptr_alloc });
+ }
+ else
+ {
+ rv.write_usize(0, 0);
+ }
+ return rv;
+ }
// Allocators!
else
{
diff --git a/tools/standalone_miri/value.cpp b/tools/standalone_miri/value.cpp
index 468425e9..db352019 100644
--- a/tools/standalone_miri/value.cpp
+++ b/tools/standalone_miri/value.cpp
@@ -169,6 +169,9 @@ void* ValueCommon::read_pointer_unsafe(size_t rd_ofs, size_t req_valid, size_t&
if( ofs != 0 ) {
LOG_FATAL("Read a non-zero offset with no relocation");
}
+ if( req_valid > 0 ) {
+ LOG_ERROR("Attempting to read a null pointer");
+ }
out_is_mut = false;
out_size = 0;
return nullptr;