]> git.lizzy.rs Git - rust.git/blobdiff - src/shims/windows/dlsym.rs
pass clippy::cast_possible_truncation
[rust.git] / src / shims / windows / dlsym.rs
index 5583e3a25895fee22c3b4a3e663dd89d8e91aa0b..eab5f99c8785170a055b3557515cc5a0375e4e9a 100644 (file)
@@ -15,9 +15,10 @@ pub enum Dlsym {
 impl Dlsym {
     // Returns an error for unsupported symbols, and None if this symbol
     // should become a NULL pointer (pretend it does not exist).
-    pub fn from_str(name: &str) -> InterpResult<'static, Option<Dlsym>> {
+    pub fn from_str<'tcx>(name: &str) -> InterpResult<'tcx, Option<Dlsym>> {
         Ok(match name {
             "GetSystemTimePreciseAsFileTime" => None,
+            "SetThreadDescription" => None,
             "NtWriteFile" => Some(Dlsym::NtWriteFile),
             _ => throw_unsup_format!("unsupported Windows dlsym: {}", name),
         })
@@ -30,11 +31,12 @@ fn call_dlsym(
         &mut self,
         dlsym: Dlsym,
         abi: Abi,
-        args: &[OpTy<'tcx, Tag>],
-        ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
+        args: &[OpTy<'tcx, Provenance>],
+        dest: &PlaceTy<'tcx, Provenance>,
+        ret: Option<mir::BasicBlock>,
     ) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
-        let (dest, ret) = ret.expect("we don't support any diverging dlsym");
+        let ret = ret.expect("we don't support any diverging dlsym");
         assert!(this.tcx.sess.target.os == "windows");
 
         this.check_abi(abi, Abi::System { unwind: false })?;
@@ -75,12 +77,15 @@ fn call_dlsym(
                     use std::io::{self, Write};
 
                     let buf_cont = this.read_bytes_ptr(buf, Size::from_bytes(u64::from(n)))?;
-                    let res = if handle == -11 {
+                    let res = if this.machine.mute_stdout_stderr {
+                        Ok(buf_cont.len())
+                    } else if handle == -11 {
                         io::stdout().write(buf_cont)
                     } else {
                         io::stderr().write(buf_cont)
                     };
-                    res.ok().map(|n| n as u32)
+                    // We write at most `n` bytes, which is a `u32`, so we cannot have written more than that.
+                    res.ok().map(|n| u32::try_from(n).unwrap())
                 } else {
                     throw_unsup_format!(
                         "on Windows, writing to anything except stdout/stderr is not supported"
@@ -98,7 +103,7 @@ fn call_dlsym(
                 // Return whether this was a success. >= 0 is success.
                 // For the error code we arbitrarily pick 0xC0000185, STATUS_IO_DEVICE_ERROR.
                 this.write_scalar(
-                    Scalar::from_i32(if written.is_some() { 0 } else { 0xC0000185u32 as i32 }),
+                    Scalar::from_u32(if written.is_some() { 0 } else { 0xC0000185u32 }),
                     dest,
                 )?;
             }