@@ -9,7 +9,6 @@ use crate::*;
9
9
10
10
pub struct FileHandle {
11
11
file : File ,
12
- flag : i32 ,
13
12
}
14
13
15
14
pub struct FileHandler {
@@ -79,13 +78,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
79
78
}
80
79
let o_cloexec = this. eval_libc_i32 ( "O_CLOEXEC" ) ?;
81
80
if flag & o_cloexec != 0 {
82
- // This flag is a noop for now because `std` already sets it.
81
+ // We do not need to do anything for this flag because `std` already sets it.
82
+ // (Technically we do not support *not* setting this flag, but we ignore that.)
83
83
mirror |= o_cloexec;
84
84
}
85
85
// If `flag` is not equal to `mirror`, there is an unsupported option enabled in `flag`,
86
86
// then we throw an error.
87
87
if flag != mirror {
88
- throw_unsup_format ! ( "unsupported flags {:#x}" , flag) ;
88
+ throw_unsup_format ! ( "unsupported flags {:#x}" , flag & !mirror ) ;
89
89
}
90
90
91
91
let path_bytes = this
@@ -97,7 +97,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
97
97
let fd = options. open ( path) . map ( |file| {
98
98
let mut fh = & mut this. machine . file_handler ;
99
99
fh. low += 1 ;
100
- fh. handles . insert ( fh. low , FileHandle { file, flag } ) ;
100
+ fh. handles . insert ( fh. low , FileHandle { file } ) ;
101
101
fh. low
102
102
} ) ;
103
103
@@ -108,7 +108,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
108
108
& mut self ,
109
109
fd_op : OpTy < ' tcx , Tag > ,
110
110
cmd_op : OpTy < ' tcx , Tag > ,
111
- _arg_op : Option < OpTy < ' tcx , Tag > > ,
111
+ _arg1_op : Option < OpTy < ' tcx , Tag > > ,
112
112
) -> InterpResult < ' tcx , i32 > {
113
113
let this = self . eval_context_mut ( ) ;
114
114
@@ -120,7 +120,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
120
120
let cmd = this. read_scalar ( cmd_op) ?. to_i32 ( ) ?;
121
121
// We only support getting the flags for a descriptor
122
122
if cmd == this. eval_libc_i32 ( "F_GETFD" ) ? {
123
- this. get_handle_and ( fd, |handle| Ok ( handle. flag ) )
123
+ // Currently this is the only flag that `F_GETFD` returns. It is OK to just return the
124
+ // `FD_CLOEXEC` value without checking if the flag is set for the file because `std`
125
+ // always sets this flag when opening a file. However we still need to check that the
126
+ // file itself is open.
127
+ this. get_handle_and ( fd, |_| Ok ( 0 ) ) ?;
128
+ this. eval_libc_i32 ( "FD_CLOEXEC" )
124
129
} else {
125
130
throw_unsup_format ! ( "The {:#x} command is not supported for `fcntl`)" , cmd) ;
126
131
}
0 commit comments