]> git.lizzy.rs Git - rust.git/blobdiff - src/shims/foreign_items/posix/linux.rs
avoid using unchecked casts or arithmetic
[rust.git] / src / shims / foreign_items / posix / linux.rs
index 098d05663543e2cd4b4fbb50fd0bc551f47cfa90..023fee4ca7b1eef68bc37bed701bb41680e52751 100644 (file)
@@ -18,12 +18,29 @@ fn emulate_foreign_item_by_name(
                 this.write_scalar(errno_place.to_ref().to_scalar()?, dest)?;
             }
 
-            // File related shims
+            // File related shims (but also see "syscall" below for statx)
+
+            // The only reason this is not in the `posix` module is because the `macos` item has a
+            // different name.
             "close" => {
                 let result = this.close(args[0])?;
                 this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
             }
 
+            // The only reason this is not in the `posix` module is because the `macos` item has a
+            // different name.
+            "opendir" => {
+                let result = this.opendir(args[0])?;
+                this.write_scalar(result, dest)?;
+            }
+
+            // The `macos` module has a parallel foreign item, `readdir_r`, which uses a different
+            // struct layout.
+            "readdir64_r" => {
+                let result = this.linux_readdir64_r(args[0], args[1], args[2])?;
+                this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
+            }
+
             // Time related shims
 
             // This is a POSIX function but it has only been tested on linux.
@@ -56,6 +73,8 @@ fn emulate_foreign_item_by_name(
                         // so skip over it.
                         getrandom(this, &args[1..], dest)?;
                     }
+                    // `statx` is used by `libstd` to retrieve metadata information on `linux`
+                    // instead of using `stat`,`lstat` or `fstat` as on `macos`.
                     id if id == sys_statx => {
                         // The first argument is the syscall id,
                         // so skip over it.
@@ -82,7 +101,7 @@ fn emulate_foreign_item_by_name(
     }
 }
 
-// Shims the linux 'getrandom()' syscall.
+// Shims the linux `getrandom` syscall.
 fn getrandom<'tcx>(
     this: &mut MiriEvalContext<'_, 'tcx>,
     args: &[OpTy<'tcx, Tag>],
@@ -95,7 +114,7 @@ fn getrandom<'tcx>(
     // neither of which have any effect on our current PRNG.
     let _flags = this.read_scalar(args[2])?.to_i32()?;
 
-    this.gen_random(ptr, len as usize)?;
+    this.gen_random(ptr, len)?;
     this.write_scalar(Scalar::from_uint(len, dest.layout.size), dest)?;
     Ok(())
 }