From 4afb6ca5c167c8757bddf6dc44dd0f8bce7f8490 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 4 Aug 2019 09:57:47 +0800 Subject: Standalone MIRI - isatty (and move fcntl) --- tools/standalone_miri/miri.cpp | 92 +++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 42 deletions(-) (limited to 'tools') 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))); -- cgit v1.2.3