Skip to content

Commit e31b8b3

Browse files
committed
add _NSGetEnviron foreign function for macos
1 parent 6eccc80 commit e31b8b3

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/machine.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,21 @@ impl<'tcx> MemoryExtra<'tcx> {
110110
pub fn init_extern_statics<'mir>(
111111
this: &mut MiriEvalContext<'mir, 'tcx>,
112112
) -> InterpResult<'tcx> {
113-
match this.tcx.sess.target.target.target_os.as_str() {
114-
"linux" => {
115-
// "__cxa_thread_atexit_impl"
116-
// This should be all-zero, pointer-sized.
117-
let layout = this.layout_of(this.tcx.types.usize)?;
118-
let place = this.allocate(layout, MiriMemoryKind::Machine.into());
119-
this.write_scalar(Scalar::from_machine_usize(0, &*this.tcx), place.into())?;
120-
this.memory
121-
.extra
122-
.extern_statics
123-
.insert(Symbol::intern("__cxa_thread_atexit_impl"), place.ptr.assert_ptr().alloc_id)
124-
.unwrap_none();
125-
113+
let target_os = this.tcx.sess.target.target.target_os.as_str();
114+
match target_os {
115+
"linux" | "macos" => {
116+
if target_os == "linux" {
117+
// "__cxa_thread_atexit_impl"
118+
// This should be all-zero, pointer-sized.
119+
let layout = this.layout_of(this.tcx.types.usize)?;
120+
let place = this.allocate(layout, MiriMemoryKind::Machine.into());
121+
this.write_scalar(Scalar::from_machine_usize(0, &*this.tcx), place.into())?;
122+
this.memory
123+
.extra
124+
.extern_statics
125+
.insert(Symbol::intern("__cxa_thread_atexit_impl"), place.ptr.assert_ptr().alloc_id)
126+
.unwrap_none();
127+
}
126128
// "environ"
127129
let layout = this.layout_of(this.tcx.types.usize)?;
128130
let place = this.allocate(layout, MiriMemoryKind::Machine.into());

src/shims/foreign_items/posix/macos.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
4141
let result = this.macos_fstat(args[0], args[1])?;
4242
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
4343
}
44-
44+
// Environment related shims
45+
"_NSGetEnviron" => {
46+
this.write_scalar(this.memory.extra.environ.unwrap().ptr, dest)?;
47+
}
4548
// The only reason this is not in the `posix` module is because the `linux` item has a
4649
// different name.
4750
"opendir$INODE64" => {

0 commit comments

Comments
 (0)