]> git.lizzy.rs Git - rust.git/blobdiff - src/shims/foreign_items/posix.rs
move remaining shims
[rust.git] / src / shims / foreign_items / posix.rs
index 2ec8b9d7a6011ab015916bdccae3257986d19b6d..f524e4df291eeb669125ccbde8094fa881d20102 100644 (file)
@@ -266,6 +266,62 @@ fn emulate_foreign_item_by_name(
                 this.write_null(dest)?;
             }
 
+            // Some things needed for `sys::thread` initialization to go through.
+            | "signal"
+            | "sigaction"
+            | "sigaltstack"
+            => {
+                this.write_scalar(Scalar::from_int(0, dest.layout.size), dest)?;
+            }
+
+            "sysconf" => {
+                let name = this.read_scalar(args[0])?.to_i32()?;
+
+                trace!("sysconf() called with name {}", name);
+                // TODO: Cache the sysconf integers via Miri's global cache.
+                let paths = &[
+                    (&["libc", "_SC_PAGESIZE"], Scalar::from_int(PAGE_SIZE, dest.layout.size)),
+                    (&["libc", "_SC_GETPW_R_SIZE_MAX"], Scalar::from_int(-1, dest.layout.size)),
+                    (
+                        &["libc", "_SC_NPROCESSORS_ONLN"],
+                        Scalar::from_int(NUM_CPUS, dest.layout.size),
+                    ),
+                ];
+                let mut result = None;
+                for &(path, path_value) in paths {
+                    if let Some(val) = this.eval_path_scalar(path)? {
+                        let val = val.to_i32()?;
+                        if val == name {
+                            result = Some(path_value);
+                            break;
+                        }
+                    }
+                }
+                if let Some(result) = result {
+                    this.write_scalar(result, dest)?;
+                } else {
+                    throw_unsup_format!("Unimplemented sysconf name: {}", name)
+                }
+            }
+
+            "isatty" => {
+                this.write_null(dest)?;
+            }
+
+            "posix_fadvise" => {
+                // fadvise is only informational, we can ignore it.
+                this.write_null(dest)?;
+            }
+
+            "mmap" => {
+                // This is a horrible hack, but since the guard page mechanism calls mmap and expects a particular return value, we just give it that value.
+                let addr = this.read_scalar(args[0])?.not_undef()?;
+                this.write_scalar(addr, dest)?;
+            }
+
+            "mprotect" => {
+                this.write_null(dest)?;
+            }
 
             _ => {
                 match this.tcx.sess.target.target.target_os.to_lowercase().as_str() {