summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2019-05-15 20:35:44 +0800
committerJohn Hodge <tpg@ucc.asn.au>2019-05-15 20:35:44 +0800
commit311b406bf90a8244a39a8eff933c7fce45b9c7f2 (patch)
treee61fe5b49224d4c36aff29fb37307910787cbf0e /tools
parentb9f65d3234026d231b889abded407c4ae1e34286 (diff)
downloadmrust-311b406bf90a8244a39a8eff933c7fce45b9c7f2.tar.gz
standalone_miri - Fiddling for 1.29 support (not working yet)
Diffstat (limited to 'tools')
-rw-r--r--tools/standalone_miri/miri.cpp36
-rw-r--r--tools/standalone_miri/value.cpp32
-rw-r--r--tools/standalone_miri/value.hpp30
3 files changed, 70 insertions, 28 deletions
diff --git a/tools/standalone_miri/miri.cpp b/tools/standalone_miri/miri.cpp
index d5bcb024..4bba4da4 100644
--- a/tools/standalone_miri/miri.cpp
+++ b/tools/standalone_miri/miri.cpp
@@ -1553,7 +1553,9 @@ bool InterpreterThread::call_path(Value& ret, const ::HIR::Path& path, ::std::ve
}
// - No guard page needed
- if( path == ::HIR::SimplePath { "std", {"sys", "imp", "thread", "guard", "init" } } )
+ if( path == ::HIR::SimplePath { "std", {"sys", "imp", "thread", "guard", "init" } }
+ || path == ::HIR::SimplePath { "std", {"sys", "unix", "thread", "guard", "init" } }
+ )
{
ret = Value::with_size(16, false);
ret.write_u64(0, 0);
@@ -1599,7 +1601,7 @@ extern "C" {
#endif
bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, const ::std::string& abi, ::std::vector<Value> args)
{
- if( link_name == "__rust_allocate" )
+ if( link_name == "__rust_allocate" || link_name == "__rust_alloc" )
{
auto size = args.at(0).read_usize(0);
auto align = args.at(1).read_usize(0);
@@ -1609,7 +1611,7 @@ bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, c
// TODO: Use the alignment when making an allocation?
rv = Value::new_pointer(rty, 0, RelocationPtr::new_alloc(Allocation::new_alloc(size)));
}
- else if( link_name == "__rust_reallocate" )
+ else if( link_name == "__rust_reallocate" || link_name == "__rust_realloc" )
{
LOG_ASSERT(args.at(0).allocation, "__rust_reallocate first argument doesn't have an allocation");
auto alloc_ptr = args.at(0).get_relocation(0);
@@ -1757,6 +1759,10 @@ bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, c
rv = Value::new_usize(val);
}
+ else if( link_name == "pthread_self" )
+ {
+ rv = Value::new_i32(0);
+ }
else if( link_name == "pthread_mutex_init" || link_name == "pthread_mutex_lock" || link_name == "pthread_mutex_unlock" || link_name == "pthread_mutex_destroy" )
{
rv = Value::new_i32(0);
@@ -1773,6 +1779,10 @@ bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, c
{
rv = Value::new_i32(0);
}
+ else if( link_name == "pthread_attr_init" || link_name == "pthread_attr_destroy" || link_name == "pthread_getattr_np" )
+ {
+ rv = Value::new_i32(0);
+ }
else if( link_name == "pthread_cond_init" || link_name == "pthread_cond_destroy" )
{
rv = Value::new_i32(0);
@@ -1820,6 +1830,14 @@ bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, c
rv = Value(::HIR::TypeRef(RawType::USize));
rv.write_usize(0, 1);
}
+ else if( link_name == "sigaction" )
+ {
+ rv = Value::new_i32(-1);
+ }
+ else if( link_name == "sigaltstack" ) // POSIX: Set alternate signal stack
+ {
+ rv = Value::new_i32(-1);
+ }
// - `void *memchr(const void *s, int c, size_t n);`
else if( link_name == "memchr" )
{
@@ -2177,6 +2195,18 @@ bool InterpreterThread::call_intrinsic(Value& rv, const ::std::string& name, con
auto lhs = PrimitiveValueVirt::from_value(ty, args.at(0));
auto rhs = PrimitiveValueVirt::from_value(ty, args.at(1));
lhs.get().subtract( rhs.get() );
+ // TODO: Overflowing part
+
+ rv = Value(ty);
+ lhs.get().write_to_value(rv, 0);
+ }
+ else if( name == "overflowing_add" )
+ {
+ const auto& ty = ty_params.tys.at(0);
+
+ auto lhs = PrimitiveValueVirt::from_value(ty, args.at(0));
+ auto rhs = PrimitiveValueVirt::from_value(ty, args.at(1));
+ lhs.get().add( rhs.get() );
rv = Value(ty);
lhs.get().write_to_value(rv, 0);
diff --git a/tools/standalone_miri/value.cpp b/tools/standalone_miri/value.cpp
index 9007eb5c..0b3aa988 100644
--- a/tools/standalone_miri/value.cpp
+++ b/tools/standalone_miri/value.cpp
@@ -13,6 +13,38 @@
#include <algorithm>
#include "debug.hpp"
+FfiLayout FfiLayout::new_const_bytes(size_t s)
+{
+ return FfiLayout {
+ { Range {s, true, false} }
+ };
+}
+bool FfiLayout::is_valid_read(size_t o, size_t s) const
+{
+ for(const auto& r : ranges)
+ {
+ if( o < r.len ) {
+ if( !r.is_valid )
+ return false;
+ if( o + s <= r.len )
+ {
+ s = 0;
+ break;
+ }
+ s -= (r.len - o);
+ o = 0;
+ }
+ else {
+ o -= r.len;
+ }
+ }
+ if( s > 0 )
+ {
+ return false;
+ }
+ return true;
+}
+
AllocationHandle Allocation::new_alloc(size_t size)
{
Allocation* rv = new Allocation();
diff --git a/tools/standalone_miri/value.hpp b/tools/standalone_miri/value.hpp
index 377361ce..e45759a7 100644
--- a/tools/standalone_miri/value.hpp
+++ b/tools/standalone_miri/value.hpp
@@ -30,36 +30,15 @@ struct FfiLayout
};
::std::vector<Range> ranges;
+ static FfiLayout new_const_bytes(size_t s);
+
size_t get_size() const {
size_t rv = 0;
for(const auto& r : ranges)
rv += r.len;
return rv;
}
- bool is_valid_read(size_t o, size_t s) {
- for(const auto& r : ranges)
- {
- if( o < r.len ) {
- if( !r.is_valid )
- return false;
- if( o + s <= r.len )
- {
- s = 0;
- break;
- }
- s -= (r.len - o);
- o = 0;
- }
- else {
- o -= r.len;
- }
- }
- if( s > 0 )
- {
- return false;
- }
- return true;
- }
+ bool is_valid_read(size_t o, size_t s) const;
};
struct FFIPointer
{
@@ -76,7 +55,7 @@ struct FFIPointer
::std::shared_ptr<FfiLayout> layout;
static FFIPointer new_const_bytes(const void* s, size_t size) {
- return FFIPointer { const_cast<void*>(s), "", ::std::shared_ptr<FfiLayout>() };
+ return FFIPointer { const_cast<void*>(s), "", ::std::make_shared<FfiLayout>(FfiLayout::new_const_bytes(size)) };
};
size_t get_size() const {
@@ -268,6 +247,7 @@ class Allocation:
// TODO: Read-only flag?
bool is_freed = false;
public:
+ virtual ~Allocation() {}
static AllocationHandle new_alloc(size_t size);
const uint8_t* data_ptr() const { return reinterpret_cast<const uint8_t*>(this->data.data()); }