From 141adeb4933bf3ffe1d4a69f51f6055765fdae86 Mon Sep 17 00:00:00 2001 From: Mohsen Zohrevandi Date: Tue, 21 Jul 2020 11:08:37 -0700 Subject: Fix sync_once_cell_does_not_leak_partially_constructed_boxes Spinning multiple threads in this test causes a deadlock in SGX where thread scheduling is not preemptive. --- src/libstd/lazy.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/lazy.rs b/src/libstd/lazy.rs index 86e1cfae582..1705a4f77c5 100644 --- a/src/libstd/lazy.rs +++ b/src/libstd/lazy.rs @@ -827,6 +827,8 @@ mod tests { tx.send(msg).unwrap(); break; } + #[cfg(target_env = "sgx")] + crate::thread::yield_now(); } }); } -- cgit 1.4.1-3-g733a5 From 7a5d3abfb1aa3a38e0b3b3508c760fc8e712226c Mon Sep 17 00:00:00 2001 From: Tomasz Miąsko Date: Mon, 6 Jul 2020 00:00:00 +0000 Subject: Avoid writes without any data in `Write::write_all_vectored` Previously, when non-empty sequence of empty IoSlices have been provided to `Write::write_all_vectored`, the buffers would be written as is with `Write::write_vectored` and subsequently the return value `Ok(0)` would be misinterpreted as an error. Avoid writes without any data by advancing the buffers first. This matches the documented behaviour of `Write::write_all_vectored` and is analogous to what happens in `Write::write_all`. --- src/libstd/io/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 797318d95b7..9eb54c2cc00 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -251,7 +251,6 @@ use crate::cmp; use crate::fmt; -use crate::mem; use crate::memchr; use crate::ops::{Deref, DerefMut}; use crate::ptr; @@ -1435,12 +1434,15 @@ pub trait Write { /// ``` #[unstable(feature = "write_all_vectored", issue = "70436")] fn write_all_vectored(&mut self, mut bufs: &mut [IoSlice<'_>]) -> Result<()> { + // Guarantee that bufs is empty if it contains no data, + // to avoid calling write_vectored if there is no data to be written. + bufs = IoSlice::advance(bufs, 0); while !bufs.is_empty() { match self.write_vectored(bufs) { Ok(0) => { return Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer")); } - Ok(n) => bufs = IoSlice::advance(mem::take(&mut bufs), n), + Ok(n) => bufs = IoSlice::advance(bufs, n), Err(ref e) if e.kind() == ErrorKind::Interrupted => {} Err(e) => return Err(e), } @@ -2958,6 +2960,7 @@ mod tests { #[rustfmt::skip] // Becomes unreadable otherwise. let tests: Vec<(_, &'static [u8])> = vec![ (vec![], &[]), + (vec![IoSlice::new(&[]), IoSlice::new(&[])], &[]), (vec![IoSlice::new(&[1])], &[1]), (vec![IoSlice::new(&[1, 2])], &[1, 2]), (vec![IoSlice::new(&[1, 2, 3])], &[1, 2, 3]), -- cgit 1.4.1-3-g733a5