summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2019-08-04 09:57:47 +0800
committerJohn Hodge <tpg@ucc.asn.au>2019-08-04 09:57:47 +0800
commit4afb6ca5c167c8757bddf6dc44dd0f8bce7f8490 (patch)
treeddf5ae92487743e3cc77eab7ece32e015634f7ec /tools
parent1cae9e657932e999d525c45ccaef325705319975 (diff)
downloadmrust-4afb6ca5c167c8757bddf6dc44dd0f8bce7f8490.tar.gz
Standalone MIRI - isatty (and move fcntl)
Diffstat (limited to 'tools')
-rw-r--r--tools/standalone_miri/miri.cpp92
1 files changed, 50 insertions, 42 deletions
diff --git a/tools/standalone_miri/miri.cpp b/tools/standalone_miri/miri.cpp
index 8d9f31ed..2131ffe6 100644
--- a/tools/standalone_miri/miri.cpp
+++ b/tools/standalone_miri/miri.cpp
@@ -1940,6 +1940,56 @@ bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, c
// TODO: Ensure that this FD is from the set known by the FFI layer
close(fd);
}
+ else if( link_name == "isatty" )
+ {
+ auto fd = args.at(0).read_i32(0);
+ LOG_DEBUG("isatty(" << fd << ")");
+ int rv_i = isatty(fd);
+ LOG_DEBUG("= " << rv_i);
+ rv = Value::new_i32(rv_i);
+ }
+ else if( link_name == "fcntl" )
+ {
+ // `fcntl` has custom handling for the third argument, as some are pointers
+ int fd = args.at(0).read_i32(0);
+ int command = args.at(1).read_i32(0);
+
+ int rv_i;
+ const char* name;
+ switch(command)
+ {
+ // - No argument
+ case F_GETFD: name = "F_GETFD"; if(0)
+ ;
+ {
+ LOG_DEBUG("fcntl(" << fd << ", " << name << ")");
+ rv_i = fcntl(fd, command);
+ } break;
+ // - Integer arguments
+ case F_DUPFD: name = "F_DUPFD"; if(0)
+ case F_DUPFD_CLOEXEC: name = "F_DUPFD_CLOEXEC"; if(0)
+ case F_SETFD: name = "F_SETFD"; if(0)
+ ;
+ {
+ int arg = args.at(2).read_i32(0);
+ LOG_DEBUG("fcntl(" << fd << ", " << name << ", " << arg << ")");
+ rv_i = fcntl(fd, command, arg);
+ } break;
+ default:
+ if( args.size() > 2 )
+ {
+ LOG_TODO("fnctl(..., " << command << ", " << args[2] << ")");
+ }
+ else
+ {
+ LOG_TODO("fnctl(..., " << command << ")");
+ }
+ }
+
+ LOG_DEBUG("= " << rv_i);
+ rv = Value(::HIR::TypeRef(RawType::I32));
+ rv.write_i32(0, rv_i);
+ }
else if( link_name == "sysconf" )
{
auto name = args.at(0).read_i32(0);
@@ -2043,48 +2093,6 @@ bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, c
rv = Value(::HIR::TypeRef(RawType::I32));
rv.write_i32(0, rv_i);
}
- else if( link_name == "fcntl" )
- {
- // `fcntl` has custom handling for the third argument, as some are pointers
- int fd = args.at(0).read_i32(0);
- int command = args.at(1).read_i32(0);
-
- int rv_i;
- const char* name;
- switch(command)
- {
- // - No argument
- case F_GETFD: name = "F_GETFD"; if(0)
- ;
- {
- LOG_DEBUG("fcntl(" << fd << ", " << name << ")");
- rv_i = fcntl(fd, command);
- } break;
- // - Integer arguments
- case F_DUPFD: name = "F_DUPFD"; if(0)
- case F_DUPFD_CLOEXEC: name = "F_DUPFD_CLOEXEC"; if(0)
- case F_SETFD: name = "F_SETFD"; if(0)
- ;
- {
- int arg = args.at(2).read_i32(0);
- LOG_DEBUG("fcntl(" << fd << ", " << name << ", " << arg << ")");
- rv_i = fcntl(fd, command, arg);
- } break;
- default:
- if( args.size() > 2 )
- {
- LOG_TODO("fnctl(..., " << command << ", " << args[2] << ")");
- }
- else
- {
- LOG_TODO("fnctl(..., " << command << ")");
- }
- }
-
- LOG_DEBUG("= " << rv_i);
- rv = Value(::HIR::TypeRef(RawType::I32));
- rv.write_i32(0, rv_i);
- }
else if( link_name == "__errno_location" )
{
rv = Value::new_ffiptr(FFIPointer::new_const_bytes(&errno, sizeof(errno)));