]> git.lizzy.rs Git - rust.git/blobdiff - src/shims/mod.rs
Add getpid shim
[rust.git] / src / shims / mod.rs
index 83bc6b6ae1bab05d2a9e134fd1f2ff175c3337fd..cdffe2f65b4fce56391b7d059c6ea554782c693c 100644 (file)
@@ -1,7 +1,7 @@
 mod backtrace;
 pub mod foreign_items;
 pub mod intrinsics;
-pub mod posix;
+pub mod unix;
 pub mod windows;
 
 pub mod dlsym;
@@ -28,16 +28,17 @@ fn find_mir_or_eval_fn(
         instance: ty::Instance<'tcx>,
         abi: Abi,
         args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
         unwind: StackPopUnwind,
     ) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> {
         let this = self.eval_context_mut();
-        trace!("eval_fn_call: {:#?}, {:?}", instance, ret.map(|p| p.0));
+        trace!("eval_fn_call: {:#?}, {:?}", instance, dest);
 
         // There are some more lang items we want to hook that CTFE does not hook (yet).
         if this.tcx.lang_items().align_offset_fn() == Some(instance.def.def_id()) {
-            let &[ref ptr, ref align] = check_arg_count(args)?;
-            if this.align_offset(ptr, align, ret, unwind)? {
+            let [ptr, align] = check_arg_count(args)?;
+            if this.align_offset(ptr, align, dest, ret, unwind)? {
                 return Ok(None);
             }
         }
@@ -50,7 +51,7 @@ fn find_mir_or_eval_fn(
             // to run extra MIR), and Ok(Some(body)) if we found MIR to run for the
             // foreign function
             // Any needed call to `goto_block` will be performed by `emulate_foreign_item`.
-            return this.emulate_foreign_item(instance.def_id(), abi, args, ret, unwind);
+            return this.emulate_foreign_item(instance.def_id(), abi, args, dest, ret, unwind);
         }
 
         // Otherwise, load the MIR.
@@ -63,11 +64,12 @@ fn align_offset(
         &mut self,
         ptr_op: &OpTy<'tcx, Tag>,
         align_op: &OpTy<'tcx, Tag>,
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        dest: &PlaceTy<'tcx, Tag>,
+        ret: Option<mir::BasicBlock>,
         unwind: StackPopUnwind,
     ) -> InterpResult<'tcx, bool> {
         let this = self.eval_context_mut();
-        let (dest, ret) = ret.unwrap();
+        let ret = ret.unwrap();
 
         if this.machine.check_alignment != AlignmentCheck::Symbolic {
             // Just use actual implementation.
@@ -83,10 +85,9 @@ fn align_offset(
         }
 
         let ptr = this.read_pointer(ptr_op)?;
-        if let Ok(ptr) = ptr.into_pointer_or_addr() {
+        if let Ok((alloc_id, _offset, _)) = this.ptr_try_get_alloc_id(ptr) {
             // Only do anything if we can identify the allocation this goes to.
-            let (_, cur_align) =
-                this.get_alloc_size_and_align(ptr.provenance.alloc_id, AllocCheck::MaybeDead)?;
+            let (_, cur_align) = this.get_alloc_size_and_align(alloc_id, AllocCheck::MaybeDead)?;
             if cur_align.bytes() >= req_align {
                 // If the allocation alignment is at least the required alignment we use the
                 // real implementation.