@@ -322,25 +322,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
322322 "`getcwd` is only available for the UNIX target family"
323323 ) ;
324324
325- if this. machine . communicate {
326- let buf = this. read_scalar ( & buf_op) ?. check_init ( ) ?;
327- let size = this. read_scalar ( & size_op) ?. to_machine_usize ( & * this. tcx ) ?;
328- // If we cannot get the current directory, we return null
329- match env:: current_dir ( ) {
330- Ok ( cwd) => {
331- if this. write_path_to_c_str ( & cwd, buf, size) ?. 0 {
332- return Ok ( buf) ;
325+ match this. machine . isolated_op {
326+ IsolatedOp :: Allow => {
327+ let buf = this. read_scalar ( & buf_op) ?. check_init ( ) ?;
328+ let size = this. read_scalar ( & size_op) ?. to_machine_usize ( & * this. tcx ) ?;
329+ // If we cannot get the current directory, we return null
330+ match env:: current_dir ( ) {
331+ Ok ( cwd) => {
332+ if this. write_path_to_c_str ( & cwd, buf, size) ?. 0 {
333+ return Ok ( buf) ;
334+ }
335+ let erange = this. eval_libc ( "ERANGE" ) ?;
336+ this. set_last_error ( erange) ?;
333337 }
334- let erange = this. eval_libc ( "ERANGE" ) ?;
335- this. set_last_error ( erange) ?;
338+ Err ( e) => this. set_last_error_from_io_error ( e) ?,
336339 }
337- Err ( e) => this. set_last_error_from_io_error ( e) ?,
338340 }
339- } else {
340- // Return a dummy error in isolation mode, after printing a warning about it.
341- this. report_dummy_in_isolation ( "getcwd" ) ;
342- let err = Error :: new ( ErrorKind :: NotFound , "dummy error in isolation mode" ) ;
343- this . set_last_error_from_io_error ( err ) ? ;
341+ IsolatedOp :: Reject ( reject_with ) => {
342+ let err = Error :: new ( ErrorKind :: NotFound , "rejected due to isolation" ) ;
343+ this. set_last_error_from_io_error ( err ) ? ;
344+ this . report_rejected_op ( "getcwd" , reject_with ) ;
345+ }
344346 }
345347 Ok ( Scalar :: null_ptr ( & * this. tcx ) )
346348 }
@@ -353,22 +355,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
353355 ) -> InterpResult < ' tcx , u32 > {
354356 let this = self . eval_context_mut ( ) ;
355357 this. assert_target_os ( "windows" , "GetCurrentDirectoryW" ) ;
356-
357- if this. machine . communicate {
358- let size = u64:: from ( this. read_scalar ( size_op) ?. to_u32 ( ) ?) ;
359- let buf = this. read_scalar ( buf_op) ?. check_init ( ) ?;
360-
361- // If we cannot get the current directory, we return 0
362- match env:: current_dir ( ) {
363- Ok ( cwd) =>
364- return Ok ( windows_check_buffer_size ( this. write_path_to_wide_str ( & cwd, buf, size) ?) ) ,
365- Err ( e) => this. set_last_error_from_io_error ( e) ?,
358+
359+ match this. machine . isolated_op {
360+ IsolatedOp :: Allow => {
361+ let size = u64:: from ( this. read_scalar ( size_op) ?. to_u32 ( ) ?) ;
362+ let buf = this. read_scalar ( buf_op) ?. check_init ( ) ?;
363+
364+ // If we cannot get the current directory, we return 0
365+ match env:: current_dir ( ) {
366+ Ok ( cwd) =>
367+ return Ok ( windows_check_buffer_size ( this. write_path_to_wide_str ( & cwd, buf, size) ?) ) ,
368+ Err ( e) => this. set_last_error_from_io_error ( e) ?,
369+ }
370+ }
371+ IsolatedOp :: Reject ( reject_with) => {
372+ let err = Error :: new ( ErrorKind :: NotFound , "rejected due to isolation" ) ;
373+ this. set_last_error_from_io_error ( err) ?;
374+ this. report_rejected_op ( "GetCurrentDirectoryW" , reject_with) ;
366375 }
367- } else {
368- // Return a dummy error in isolation mode, after printing a warning about it.
369- this. report_dummy_in_isolation ( "GetCurrentDirectoryW" ) ;
370- let err = Error :: new ( ErrorKind :: NotFound , "dummy error in isolation mode" ) ;
371- this. set_last_error_from_io_error ( err) ?;
372376 }
373377 Ok ( 0 )
374378 }
@@ -381,23 +385,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
381385 "`getcwd` is only available for the UNIX target family"
382386 ) ;
383387
384- if this. machine . communicate {
385- let path = this. read_path_from_c_str ( this. read_scalar ( path_op) ?. check_init ( ) ?) ?;
388+ match this. machine . isolated_op {
389+ IsolatedOp :: Allow => {
390+ let path = this. read_path_from_c_str ( this. read_scalar ( path_op) ?. check_init ( ) ?) ?;
386391
387- match env:: set_current_dir ( path) {
388- Ok ( ( ) ) => Ok ( 0 ) ,
389- Err ( e) => {
390- this. set_last_error_from_io_error ( e) ?;
391- Ok ( -1 )
392+ match env:: set_current_dir ( path) {
393+ Ok ( ( ) ) => Ok ( 0 ) ,
394+ Err ( e) => {
395+ this. set_last_error_from_io_error ( e) ?;
396+ Ok ( -1 )
397+ }
392398 }
393399 }
394- } else {
395- // Return a dummy error in isolation mode, after printing a warning about it.
396- this. report_dummy_in_isolation ( "chdir" ) ;
397- let err = Error :: new ( ErrorKind :: NotFound , "dummy error in isolation mode" ) ;
398- this. set_last_error_from_io_error ( err) ?;
400+ IsolatedOp :: Reject ( reject_with) => {
401+ let err = Error :: new ( ErrorKind :: NotFound , "rejected due to isolation" ) ;
402+ this. set_last_error_from_io_error ( err) ?;
403+ this. report_rejected_op ( "chdir" , reject_with) ;
399404
400- Ok ( -1 )
405+ Ok ( -1 )
406+ }
401407 }
402408 }
403409
@@ -411,22 +417,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
411417 let this = self . eval_context_mut ( ) ;
412418 this. assert_target_os ( "windows" , "SetCurrentDirectoryW" ) ;
413419
414- if this. machine . communicate {
415- let path = this. read_path_from_wide_str ( this. read_scalar ( path_op) ?. check_init ( ) ?) ?;
420+ match this. machine . isolated_op {
421+ IsolatedOp :: Allow => {
422+ let path = this. read_path_from_wide_str ( this. read_scalar ( path_op) ?. check_init ( ) ?) ?;
416423
417- match env:: set_current_dir ( path) {
418- Ok ( ( ) ) => Ok ( 1 ) ,
419- Err ( e) => {
420- this. set_last_error_from_io_error ( e) ?;
421- Ok ( 0 )
424+ match env:: set_current_dir ( path) {
425+ Ok ( ( ) ) => Ok ( 1 ) ,
426+ Err ( e) => {
427+ this. set_last_error_from_io_error ( e) ?;
428+ Ok ( 0 )
429+ }
422430 }
423431 }
424- } else {
425- // Return a dummy error in isolation mode, after printing a warning about it.
426- this. report_dummy_in_isolation ( "SetCurrentDirectoryW" ) ;
427- let err = Error :: new ( ErrorKind :: NotFound , "dummy error in isolation mode" ) ;
428- this. set_last_error_from_io_error ( err) ?;
429- Ok ( 0 )
432+ IsolatedOp :: Reject ( reject_with) => {
433+ let err = Error :: new ( ErrorKind :: NotFound , "rejected due to isolation" ) ;
434+ this. set_last_error_from_io_error ( err) ?;
435+ this. report_rejected_op ( "SetCurrentDirectoryW" , reject_with) ;
436+
437+ Ok ( 0 )
438+ }
430439 }
431440 }
432441
0 commit comments