From fd830e7b278063c93c57028b9469875fb36718a6 Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Tue, 7 Dec 2021 17:25:28 +0000 Subject: [PATCH] Code comment changes from code review Co-authored-by: Ralf Jung --- src/shims/posix/sync.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/shims/posix/sync.rs b/src/shims/posix/sync.rs index 1d0483e49d51..ea940df1c6e8 100644 --- a/src/shims/posix/sync.rs +++ b/src/shims/posix/sync.rs @@ -367,6 +367,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // Destroying an uninit pthread_mutexattr is UB, so check to make sure it's not uninit. mutexattr_get_kind(this, attr_op)?.check_init()?; + // To catch double-destroys, we de-initialize the mutexattr. // This is technically not right and might lead to false positives. For example, the below // code is *likely* sound, even assuming uninit numbers are UB, but miri with // -Zmiri-check-number-validity complains @@ -376,6 +377,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // libc::pthread_mutexattr_destroy(x.as_mut_ptr()); // x.assume_init(); // + // However, the way libstd uses the pthread APIs works in our favor here, so we can get away with this. // This can always be revisited to have some external state to catch double-destroys // but not complain about the above code. See https://github.com/rust-lang/miri/pull/1933