@@ -21,7 +21,7 @@ pub(crate) enum FlockOp {
21
21
Unlock ,
22
22
}
23
23
24
- /// Represents an open file descriptor .
24
+ /// Represents an open file description .
25
25
pub trait FileDescription : std:: fmt:: Debug + Any {
26
26
fn name ( & self ) -> & ' static str ;
27
27
@@ -303,7 +303,7 @@ pub struct FdTable {
303
303
304
304
impl VisitProvenance for FdTable {
305
305
fn visit_provenance ( & self , _visit : & mut VisitWith < ' _ > ) {
306
- // All our FileDescriptor do not have any tags.
306
+ // All our FileDescription instances do not have any tags.
307
307
}
308
308
}
309
309
@@ -337,18 +337,18 @@ impl FdTable {
337
337
}
338
338
339
339
pub fn insert ( & mut self , fd_ref : FileDescriptionRef ) -> i32 {
340
- self . insert_ref_with_min_fd ( fd_ref, 0 )
340
+ self . insert_with_min_num ( fd_ref, 0 )
341
341
}
342
342
343
- /// Insert a file description, giving it a file descriptor that is at least `min_fd `.
344
- fn insert_ref_with_min_fd ( & mut self , file_handle : FileDescriptionRef , min_fd : i32 ) -> i32 {
343
+ /// Insert a file description, giving it a file descriptor that is at least `min_fd_num `.
344
+ fn insert_with_min_num ( & mut self , file_handle : FileDescriptionRef , min_fd_num : i32 ) -> i32 {
345
345
// Find the lowest unused FD, starting from min_fd. If the first such unused FD is in
346
346
// between used FDs, the find_map combinator will return it. If the first such unused FD
347
347
// is after all other used FDs, the find_map combinator will return None, and we will use
348
348
// the FD following the greatest FD thus far.
349
349
let candidate_new_fd =
350
- self . fds . range ( min_fd ..) . zip ( min_fd ..) . find_map ( |( ( fd , _fh ) , counter) | {
351
- if * fd != counter {
350
+ self . fds . range ( min_fd_num ..) . zip ( min_fd_num ..) . find_map ( |( ( fd_num , _fd ) , counter) | {
351
+ if * fd_num != counter {
352
352
// There was a gap in the fds stored, return the first unused one
353
353
// (note that this relies on BTreeMap iterating in key order)
354
354
Some ( counter)
@@ -357,61 +357,61 @@ impl FdTable {
357
357
None
358
358
}
359
359
} ) ;
360
- let new_fd = candidate_new_fd. unwrap_or_else ( || {
360
+ let new_fd_num = candidate_new_fd. unwrap_or_else ( || {
361
361
// find_map ran out of BTreeMap entries before finding a free fd, use one plus the
362
362
// maximum fd in the map
363
- self . fds . last_key_value ( ) . map ( |( fd , _) | fd . strict_add ( 1 ) ) . unwrap_or ( min_fd )
363
+ self . fds . last_key_value ( ) . map ( |( fd_num , _) | fd_num . strict_add ( 1 ) ) . unwrap_or ( min_fd_num )
364
364
} ) ;
365
365
366
- self . fds . try_insert ( new_fd , file_handle) . unwrap ( ) ;
367
- new_fd
366
+ self . fds . try_insert ( new_fd_num , file_handle) . unwrap ( ) ;
367
+ new_fd_num
368
368
}
369
369
370
- pub fn get ( & self , fd : i32 ) -> Option < FileDescriptionRef > {
371
- let fd = self . fds . get ( & fd ) ?;
370
+ pub fn get ( & self , fd_num : i32 ) -> Option < FileDescriptionRef > {
371
+ let fd = self . fds . get ( & fd_num ) ?;
372
372
Some ( fd. clone ( ) )
373
373
}
374
374
375
- pub fn remove ( & mut self , fd : i32 ) -> Option < FileDescriptionRef > {
376
- self . fds . remove ( & fd )
375
+ pub fn remove ( & mut self , fd_num : i32 ) -> Option < FileDescriptionRef > {
376
+ self . fds . remove ( & fd_num )
377
377
}
378
378
379
- pub fn is_fd ( & self , fd : i32 ) -> bool {
380
- self . fds . contains_key ( & fd )
379
+ pub fn is_fd_num ( & self , fd_num : i32 ) -> bool {
380
+ self . fds . contains_key ( & fd_num )
381
381
}
382
382
}
383
383
384
384
impl < ' tcx > EvalContextExt < ' tcx > for crate :: MiriInterpCx < ' tcx > { }
385
385
pub trait EvalContextExt < ' tcx > : crate :: MiriInterpCxExt < ' tcx > {
386
- fn dup ( & mut self , old_fd : i32 ) -> InterpResult < ' tcx , Scalar > {
386
+ fn dup ( & mut self , old_fd_num : i32 ) -> InterpResult < ' tcx , Scalar > {
387
387
let this = self . eval_context_mut ( ) ;
388
388
389
- let Some ( dup_fd ) = this. machine . fds . get ( old_fd ) else {
389
+ let Some ( fd ) = this. machine . fds . get ( old_fd_num ) else {
390
390
return Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ?) ) ;
391
391
} ;
392
- Ok ( Scalar :: from_i32 ( this. machine . fds . insert_ref_with_min_fd ( dup_fd , 0 ) ) )
392
+ Ok ( Scalar :: from_i32 ( this. machine . fds . insert ( fd ) ) )
393
393
}
394
394
395
- fn dup2 ( & mut self , old_fd : i32 , new_fd : i32 ) -> InterpResult < ' tcx , Scalar > {
395
+ fn dup2 ( & mut self , old_fd_num : i32 , new_fd_num : i32 ) -> InterpResult < ' tcx , Scalar > {
396
396
let this = self . eval_context_mut ( ) ;
397
397
398
- let Some ( dup_fd ) = this. machine . fds . get ( old_fd ) else {
398
+ let Some ( fd ) = this. machine . fds . get ( old_fd_num ) else {
399
399
return Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ?) ) ;
400
400
} ;
401
- if new_fd != old_fd {
401
+ if new_fd_num != old_fd_num {
402
402
// Close new_fd if it is previously opened.
403
403
// If old_fd and new_fd point to the same description, then `dup_fd` ensures we keep the underlying file description alive.
404
- if let Some ( file_description ) = this. machine . fds . fds . insert ( new_fd , dup_fd ) {
404
+ if let Some ( old_new_fd ) = this. machine . fds . fds . insert ( new_fd_num , fd ) {
405
405
// Ignore close error (not interpreter's) according to dup2() doc.
406
- file_description . close ( this. machine . communicate ( ) , this) ?. ok ( ) ;
406
+ old_new_fd . close ( this. machine . communicate ( ) , this) ?. ok ( ) ;
407
407
}
408
408
}
409
- Ok ( Scalar :: from_i32 ( new_fd ) )
409
+ Ok ( Scalar :: from_i32 ( new_fd_num ) )
410
410
}
411
411
412
- fn flock ( & mut self , fd : i32 , op : i32 ) -> InterpResult < ' tcx , Scalar > {
412
+ fn flock ( & mut self , fd_num : i32 , op : i32 ) -> InterpResult < ' tcx , Scalar > {
413
413
let this = self . eval_context_mut ( ) ;
414
- let Some ( file_descriptor ) = this. machine . fds . get ( fd ) else {
414
+ let Some ( fd ) = this. machine . fds . get ( fd_num ) else {
415
415
return Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ?) ) ;
416
416
} ;
417
417
@@ -436,8 +436,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
436
436
throw_unsup_format ! ( "unsupported flags {:#x}" , op) ;
437
437
} ;
438
438
439
- let result = file_descriptor . flock ( this. machine . communicate ( ) , parsed_op) ?;
440
- drop ( file_descriptor ) ;
439
+ let result = fd . flock ( this. machine . communicate ( ) , parsed_op) ?;
440
+ drop ( fd ) ;
441
441
// return `0` if flock is successful
442
442
let result = result. map ( |( ) | 0i32 ) ;
443
443
Ok ( Scalar :: from_i32 ( this. try_unwrap_io_result ( result) ?) )
@@ -452,7 +452,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
452
452
args. len( )
453
453
) ;
454
454
}
455
- let fd = this. read_scalar ( & args[ 0 ] ) ?. to_i32 ( ) ?;
455
+ let fd_num = this. read_scalar ( & args[ 0 ] ) ?. to_i32 ( ) ?;
456
456
let cmd = this. read_scalar ( & args[ 1 ] ) ?. to_i32 ( ) ?;
457
457
458
458
// We only support getting the flags for a descriptor.
@@ -461,7 +461,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
461
461
// `FD_CLOEXEC` value without checking if the flag is set for the file because `std`
462
462
// always sets this flag when opening a file. However we still need to check that the
463
463
// file itself is open.
464
- Ok ( Scalar :: from_i32 ( if this. machine . fds . is_fd ( fd ) {
464
+ Ok ( Scalar :: from_i32 ( if this. machine . fds . is_fd_num ( fd_num ) {
465
465
this. eval_libc_i32 ( "FD_CLOEXEC" )
466
466
} else {
467
467
this. fd_not_found ( ) ?
@@ -481,9 +481,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
481
481
}
482
482
let start = this. read_scalar ( & args[ 2 ] ) ?. to_i32 ( ) ?;
483
483
484
- match this. machine . fds . get ( fd) {
485
- Some ( dup_fd) =>
486
- Ok ( Scalar :: from_i32 ( this. machine . fds . insert_ref_with_min_fd ( dup_fd, start) ) ) ,
484
+ match this. machine . fds . get ( fd_num) {
485
+ Some ( fd) => Ok ( Scalar :: from_i32 ( this. machine . fds . insert_with_min_num ( fd, start) ) ) ,
487
486
None => Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ?) ) ,
488
487
}
489
488
} else if this. tcx . sess . target . os == "macos" && cmd == this. eval_libc_i32 ( "F_FULLFSYNC" ) {
@@ -494,7 +493,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
494
493
return Ok ( Scalar :: from_i32 ( -1 ) ) ;
495
494
}
496
495
497
- this. ffullsync_fd ( fd )
496
+ this. ffullsync_fd ( fd_num )
498
497
} else {
499
498
throw_unsup_format ! ( "the {:#x} command is not supported for `fcntl`)" , cmd) ;
500
499
}
@@ -503,12 +502,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
503
502
fn close ( & mut self , fd_op : & OpTy < ' tcx > ) -> InterpResult < ' tcx , Scalar > {
504
503
let this = self . eval_context_mut ( ) ;
505
504
506
- let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
505
+ let fd_num = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
507
506
508
- let Some ( file_description ) = this. machine . fds . remove ( fd ) else {
507
+ let Some ( fd ) = this. machine . fds . remove ( fd_num ) else {
509
508
return Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ?) ) ;
510
509
} ;
511
- let result = file_description . close ( this. machine . communicate ( ) , this) ?;
510
+ let result = fd . close ( this. machine . communicate ( ) , this) ?;
512
511
// return `0` if close is successful
513
512
let result = result. map ( |( ) | 0i32 ) ;
514
513
Ok ( Scalar :: from_i32 ( this. try_unwrap_io_result ( result) ?) )
@@ -532,16 +531,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
532
531
/// and keeps the cursor unchanged.
533
532
fn read (
534
533
& mut self ,
535
- fd : i32 ,
534
+ fd_num : i32 ,
536
535
buf : Pointer ,
537
536
count : u64 ,
538
537
offset : Option < i128 > ,
539
538
) -> InterpResult < ' tcx , Scalar > {
540
539
let this = self . eval_context_mut ( ) ;
541
540
542
- // Isolation check is done via `FileDescriptor ` trait.
541
+ // Isolation check is done via `FileDescription ` trait.
543
542
544
- trace ! ( "Reading from FD {}, size {}" , fd , count) ;
543
+ trace ! ( "Reading from FD {}, size {}" , fd_num , count) ;
545
544
546
545
// Check that the *entire* buffer is actually valid memory.
547
546
this. check_ptr_access ( buf, Size :: from_bytes ( count) , CheckInAllocMsg :: MemoryAccessTest ) ?;
@@ -554,7 +553,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
554
553
let communicate = this. machine . communicate ( ) ;
555
554
556
555
// We temporarily dup the FD to be able to retain mutable access to `this`.
557
- let Some ( fd) = this. machine . fds . get ( fd ) else {
556
+ let Some ( fd) = this. machine . fds . get ( fd_num ) else {
558
557
trace ! ( "read: FD not found" ) ;
559
558
return Ok ( Scalar :: from_target_isize ( this. fd_not_found ( ) ?, this) ) ;
560
559
} ;
@@ -597,14 +596,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
597
596
598
597
fn write (
599
598
& mut self ,
600
- fd : i32 ,
599
+ fd_num : i32 ,
601
600
buf : Pointer ,
602
601
count : u64 ,
603
602
offset : Option < i128 > ,
604
603
) -> InterpResult < ' tcx , Scalar > {
605
604
let this = self . eval_context_mut ( ) ;
606
605
607
- // Isolation check is done via `FileDescriptor ` trait.
606
+ // Isolation check is done via `FileDescription ` trait.
608
607
609
608
// Check that the *entire* buffer is actually valid memory.
610
609
this. check_ptr_access ( buf, Size :: from_bytes ( count) , CheckInAllocMsg :: MemoryAccessTest ) ?;
@@ -618,7 +617,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
618
617
619
618
let bytes = this. read_bytes_ptr_strip_provenance ( buf, Size :: from_bytes ( count) ) ?. to_owned ( ) ;
620
619
// We temporarily dup the FD to be able to retain mutable access to `this`.
621
- let Some ( fd) = this. machine . fds . get ( fd ) else {
620
+ let Some ( fd) = this. machine . fds . get ( fd_num ) else {
622
621
return Ok ( Scalar :: from_target_isize ( this. fd_not_found ( ) ?, this) ) ;
623
622
} ;
624
623
0 commit comments