-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pthreads synchronization primitives: detect mutex/rwlock/... being moved to a different location #3749
Comments
The macOS |
Would this be possible to do by storing the original address in memory with This doesn't have the benefit of simplifying the code, but might be a less invasive change. |
Some scheme like that could work, but it doesn't seem worth the effort to me. (Also not sure what your comment about provenance is meant to say.) Probably the least invasive version of this is to store just the |
regarding provenance comment: I wasn't sure if how miri represents type in the machine's memory might conflict with the expected layout for a type. Like if we added that extra field that stores the original address the type layout would have changed. And I remembered that provenance already does something similar, if I understand correctly, where it doesn't just store the address that a pointer holds, but also provenance information. I was basically trying to prove to myself that adding metadata to a type is fine. If there already exists such a map, then yes, storing the metadata to it is probably the simplest way, yes. I will need to read the code more to understand what needs to happen but from your commends and some initial reading I think I could give this a shot if there is interest. Thanks for the answers! |
There are several misconceptions here about how Miri works: there are no types in memory, only raw bytes. And we can never add more fields or anything like that, |
I have some code for this but before I send anything stupid for review I have 2 questions:
|
What I imagined was lazy initialization: there's a flag in the
That should not be needed, |
For the initial PR, it's probably best to only convert one of the primitives, like mutex. :) |
This can't be closed yet. The above mentioned commit only implements the move detection for mutexes. |
Ah, good point. I moved the macos version of this into a separate issue: #3859. |
detect when pthread_rwlock_t is moved For some implementations of pthreads, the address of pthread_rwlock_t (or its fields) is used to identify the lock. That means that if the contents of a pthread_rwlock_t are moved in memory, effectively a new lock object is created, which is completely independted from the original. Thus we want to detect when when such objects are moved and show an error. see also #3749 for more context
I think condvar is the only one that's missing now, right? |
Yes. I started to prepare a PR a few days ago, but then life got a bit busy. I need to add a test and polish it a bit. |
detect when pthread_cond_t is moved Closes #3749
tl;dr: It might be allowed by the posix standard to move synchornization objects after initialization, when a flag in the I was reading the POSIX spec and in section
So it seems to me that it is possible, under certain conditions, to move the mutex after you initialize it. Setting the "process-shared attribute" is done through |
The docs you quote still say
so I don't think this allows moving them anywhere else? But anyway we don't support this flag. |
pthread's synchronization primitives must not be moved to a different location once they were initialized. However, Miri does currently not catch that kind of UB. We probably want a fundamentally different implementation of these primitives to detect such bugs -- instead of storing data in the memory that is occupied by
pthread_mutex_t
et al, we use the address of thepthread_mutex_t
as the key into some table for managing the lock.This would also avoid having to figure out which "offsets" inside
pthread_mutex_t
to use on which OS to do what... we'd entirely stop caring about the layout ofpthread_mutex_t
. So this is a better way to achieve FreeBSD support for the pthread primitives as well.The text was updated successfully, but these errors were encountered: