diff options
author | John Hodge <tpg@mutabah.net> | 2018-05-13 09:55:13 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-05-13 09:55:13 +0800 |
commit | c7b3036cefcd0dc412cb400455324d7ca8cd518e (patch) | |
tree | c789dec0d4d22cfabd04c65b20d058ace470559b /tools/standalone_miri/main.cpp | |
parent | d3334162fa91fe6fd5d02912d9f82794306e646a (diff) | |
download | mrust-c7b3036cefcd0dc412cb400455324d7ca8cd518e.tar.gz |
Standalone MIRI - memrchr and better null checking
Diffstat (limited to 'tools/standalone_miri/main.cpp')
-rw-r--r-- | tools/standalone_miri/main.cpp | 22 |
1 files changed, 22 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 { |