]> git.lizzy.rs Git - rust.git/commitdiff
add `_NSGetEnviron` foreign function for macos
authorChristian Poveda <git@christianpoveda.xyz>
Sat, 7 Mar 2020 14:39:44 +0000 (09:39 -0500)
committerChristian Poveda <git@christianpoveda.xyz>
Sat, 7 Mar 2020 15:06:20 +0000 (10:06 -0500)
src/machine.rs
src/shims/foreign_items/posix/macos.rs

index 188001c170abffc74c12c7f49b469439b82695d8..5a50a76dfb9f8e2e1f3f6dbeac3b72ceaecea3c8 100644 (file)
@@ -110,19 +110,21 @@ pub fn new(rng: StdRng, stacked_borrows: bool, tracked_pointer_tag: Option<PtrId
     pub fn init_extern_statics<'mir>(
         this: &mut MiriEvalContext<'mir, 'tcx>,
     ) -> InterpResult<'tcx> {
-        match this.tcx.sess.target.target.target_os.as_str() {
-            "linux" => {
-                // "__cxa_thread_atexit_impl"
-                // This should be all-zero, pointer-sized.
-                let layout = this.layout_of(this.tcx.types.usize)?;
-                let place = this.allocate(layout, MiriMemoryKind::Machine.into());
-                this.write_scalar(Scalar::from_machine_usize(0, &*this.tcx), place.into())?;
-                this.memory
-                    .extra
-                    .extern_statics
-                    .insert(Symbol::intern("__cxa_thread_atexit_impl"), place.ptr.assert_ptr().alloc_id)
-                    .unwrap_none();
-
+        let target_os = this.tcx.sess.target.target.target_os.as_str();
+        match target_os {
+            "linux" | "macos" => {
+                if target_os == "linux" {
+                    // "__cxa_thread_atexit_impl"
+                    // This should be all-zero, pointer-sized.
+                    let layout = this.layout_of(this.tcx.types.usize)?;
+                    let place = this.allocate(layout, MiriMemoryKind::Machine.into());
+                    this.write_scalar(Scalar::from_machine_usize(0, &*this.tcx), place.into())?;
+                    this.memory
+                        .extra
+                        .extern_statics
+                        .insert(Symbol::intern("__cxa_thread_atexit_impl"), place.ptr.assert_ptr().alloc_id)
+                        .unwrap_none();
+                }
                 // "environ"
                 let layout = this.layout_of(this.tcx.types.usize)?;
                 let place = this.allocate(layout, MiriMemoryKind::Machine.into());
index cb6cd9ba44b40a8f89c90ec97e4b8163c683a901..d167191279ebcf840b49a2514b426a6a24b0ce94 100644 (file)
@@ -41,7 +41,10 @@ fn emulate_foreign_item_by_name(
                 let result = this.macos_fstat(args[0], args[1])?;
                 this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
             }
-
+            // Environment related shims
+            "_NSGetEnviron" => {
+                this.write_scalar(this.memory.extra.environ.unwrap().ptr, dest)?;
+            }
             // The only reason this is not in the `posix` module is because the `linux` item has a
             // different name.
             "opendir$INODE64" => {