]> git.lizzy.rs Git - rust.git/blobdiff - src/shims/foreign_items/posix/macos.rs
avoid using unchecked casts or arithmetic
[rust.git] / src / shims / foreign_items / posix / macos.rs
index 8cfe959c3938ffd611f0fcba377cb9ea954fc6ee..34661fb2383c308ca29fa270338efcb290619904 100644 (file)
@@ -19,26 +19,48 @@ fn emulate_foreign_item_by_name(
             }
 
             // File related shims
+
+            // The only reason this is not in the `posix` module is because the `linux` item has a
+            // different name.
             "close$NOCANCEL" => {
                 let result = this.close(args[0])?;
                 this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
             }
 
             "stat$INODE64" => {
-                let result = this.stat(args[0], args[1])?;
+                let result = this.macos_stat(args[0], args[1])?;
                 this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
             }
 
             "lstat$INODE64" => {
-                let result = this.lstat(args[0], args[1])?;
+                let result = this.macos_lstat(args[0], args[1])?;
                 this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
             }
 
             "fstat$INODE64" => {
-                let result = this.fstat(args[0], args[1])?;
+                let result = this.macos_fstat(args[0], args[1])?;
+                this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
+            }
+
+            // The only reason this is not in the `posix` module is because the `linux` item has a
+            // different name.
+            "opendir$INODE64" => {
+                let result = this.opendir(args[0])?;
+                this.write_scalar(result, dest)?;
+            }
+
+            // The `linux` module has a parallel foreign item, `readdir64_r`, which uses a
+            // different struct layout.
+            "readdir_r$INODE64" => {
+                let result = this.macos_readdir_r(args[0], args[1], args[2])?;
                 this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
             }
 
+            // Environment related shims
+            "_NSGetEnviron" => {
+                this.write_scalar(this.machine.env_vars.environ.unwrap().ptr, dest)?;
+            }
+
             // Time related shims
             "gettimeofday" => {
                 let result = this.gettimeofday(args[0], args[1])?;
@@ -75,7 +97,7 @@ fn emulate_foreign_item_by_name(
             "SecRandomCopyBytes" => {
                 let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
                 let ptr = this.read_scalar(args[2])?.not_undef()?;
-                this.gen_random(ptr, len as usize)?;
+                this.gen_random(ptr, len)?;
                 this.write_null(dest)?;
             }