about summary refs log tree commit diff
path: root/src/tools/miri
AgeCommit message (Collapse)AuthorLines
2024-10-14Auto merge of #3973 - RalfJung:os-unfair-lock, r=RalfJungbors-122/+297
ensure that a macOS os_unfair_lock that is moved while being held is not implicitly unlocked Fixes https://github.com/rust-lang/miri/issues/3859 We mark an os_unfair_lock that is moved while being held as "poisoned", which means it is not considered forever locked. That's not quite what the real implementation does, but allowing arbitrary moves-while-locked would likely expose a ton of implementation details, so hopefully this is good enough.
2024-10-14ensure that a macOS os_unfair_lock that is moved while being held is not ↵Ralf Jung-59/+178
implicitly unlocked
2024-10-14move lazy_sync helper methods to be with InterpCxRalf Jung-79/+103
2024-10-14De-duplicate and move `adjust_nan` to `InterpCx`Eduardo Sánchez Muñoz-4/+0
2024-10-14Auto merge of #3968 - YohDeadfall:variadic-arg-helper, r=RalfJungbors-84/+85
Added a variadic argument helper `@RalfJung,` as you wished (:
2024-10-14add test ensuring a moved mutex deadlocksRalf Jung-0/+32
2024-10-14Added a variadic argument helperYoh Deadfall-84/+85
2024-10-14Avoid some needless monomorphizationsOli Scherer-10/+7
2024-10-14pick more clear names for the typesRalf Jung-22/+19
2024-10-14turns out relaxed accesses suffice hereRalf Jung-2/+2
2024-10-14make lazy_sync_get_data also take a closure to initialize if neededRalf Jung-51/+32
2024-10-14Windows InitOnce: also store ID outside addressable memoryRalf Jung-165/+114
2024-10-14macOS os_unfair_lock: also store ID outside addressable memoryRalf Jung-49/+42
2024-10-14pthread_cond: also store ID outside addressable memoryRalf Jung-172/+109
2024-10-14pthread_rwlock: also store ID outside addressable memoryRalf Jung-135/+112
2024-10-14pthread_mutex: store mutex ID outside adressable memory, so it can be trustedRalf Jung-127/+181
2024-10-14clippyRalf Jung-0/+2
2024-10-14Merge from rustcRalf Jung-7/+154
2024-10-14Preparing for merge from rustcRalf Jung-1/+1
2024-10-14Rollup merge of #131593 - RalfJung:alloc-no-clone, r=saethlinMatthias Krüger-4/+12
miri: avoid cloning AllocExtra We shouldn't be cloning Miri allocations, so make `AllocExtra::clone` panic instead, and adjust the one case where we *do* clone (the leak check) to avoid cloning. This is in preparation for https://github.com/rust-lang/miri/pull/3966 where I am adding something to `AllocExtra` that cannot (easily) be cloned. r? ``@saethlin``
2024-10-13Auto merge of #3957 - YohDeadfall:macos-thread-name, r=RalfJungbors-61/+191
Fixed get/set thread name implementations for macOS and FreeBSD So, the story of fixing `pthread_getname_np` and `pthread_setname_np` continues, but this time I fixed the macOS implementation. ### [`pthread_getname_np`](https://github.com/apple-oss-distributions/libpthread/blob/c032e0b076700a0a47db75528a282b8d3a06531a/src/pthread.c#L1160-L1175) The function never fails except for an invalid thread. Miri never verifies thread identifiers and uses them as indices when accessing a vector of threads. Therefore, the only possible result is `0` and a possibly trimmed output. ```c int pthread_getname_np(pthread_t thread, char *threadname, size_t len) { if (thread == pthread_self()) { strlcpy(threadname, thread->pthread_name, len); return 0; } if (!_pthread_validate_thread_and_list_lock(thread)) { return ESRCH; } strlcpy(threadname, thread->pthread_name, len); _pthread_lock_unlock(&_pthread_list_lock); return 0; } ``` #### [`strcpy`](https://www.man7.org/linux/man-pages/man7/strlcpy.7.html) ``` strlcpy(3bsd) strlcat(3bsd) Copy and catenate the input string into a destination string. If the destination buffer, limited by its size, isn't large enough to hold the copy, the resulting string is truncated (but it is guaranteed to be null-terminated). They return the length of the total string they tried to create. ``` ### [`pthread_setname_np`](https://github.com/apple-oss-distributions/libpthread/blob/c032e0b076700a0a47db75528a282b8d3a06531a/src/pthread.c#L1178-L1200) ```c pthread_setname_np(const char *name) { int res; pthread_t self = pthread_self(); size_t len = 0; if (name != NULL) { len = strlen(name); } _pthread_validate_signature(self); res = __proc_info(5, getpid(), 2, (uint64_t)0, (void*)name, (int)len); if (res == 0) { if (len > 0) { strlcpy(self->pthread_name, name, MAXTHREADNAMESIZE); } else { bzero(self->pthread_name, MAXTHREADNAMESIZE); } } return res; } ``` Where `5` is [`PROC_INFO_CALL_SETCONTROL`](https://github.com/apple-oss-distributions/xnu/blob/8d741a5de7ff4191bf97d57b9f54c2f6d4a15585/bsd/sys/proc_info_private.h#L274), and `2` is [`PROC_INFO_CALL_SETCONTROL`](https://github.com/apple-oss-distributions/xnu/blob/8d741a5de7ff4191bf97d57b9f54c2f6d4a15585/bsd/sys/proc_info.h#L821). And `__proc_info` is a syscall handled by the XNU kernel by [`proc_info_internal`](https://github.com/apple-oss-distributions/xnu/blob/8d741a5de7ff4191bf97d57b9f54c2f6d4a15585/bsd/kern/proc_info.c#L300-L314): ```c int proc_info_internal(int callnum, int pid, uint32_t flags, uint64_t ext_id, int flavor, uint64_t arg, user_addr_t buffer, uint32_t buffersize, int32_t * retval) { switch (callnum) { // ... case PROC_INFO_CALL_SETCONTROL: return proc_setcontrol(pid, flavor, arg, buffer, buffersize, retval); ``` And the actual logic from [`proc_setcontrol`](https://github.com/apple-oss-distributions/xnu/blob/8d741a5de7ff4191bf97d57b9f54c2f6d4a15585/bsd/kern/proc_info.c#L3218-L3227): ```c case PROC_SELFSET_THREADNAME: { /* * This is a bit ugly, as it copies the name into the kernel, and then * invokes bsd_setthreadname again to copy it into the uthread name * buffer. Hopefully this isn't such a hot codepath that an additional * MAXTHREADNAMESIZE copy is a big issue. */ if (buffersize > (MAXTHREADNAMESIZE - 1)) { return ENAMETOOLONG; } ``` Unrelated to the current pull request, but perhaps, there's a very ugly thing in the kernel/libc because the last thing happening in `PROC_SELFSET_THREADNAME` is `bsd_setthreadname` which sets the name in the user space. But we just saw that `pthread_setname_np` sets the name in the user space too. Guess, I need to open a ticket in one of Apple's repositories at least to clarify that :D
2024-10-13rework threadname test for more consistencyRalf Jung-62/+122
2024-10-12Stabilize `const_option`Trevor Gross-1/+0
This makes the following API stable in const contexts: impl<T> Option<T> { pub const fn as_mut(&mut self) -> Option<&mut T>; pub const fn expect(self, msg: &str) -> T; pub const fn unwrap(self) -> T; pub const unsafe fn unwrap_unchecked(self) -> T; pub const fn take(&mut self) -> Option<T>; pub const fn replace(&mut self, value: T) -> Option<T>; } impl<T> Option<&T> { pub const fn copied(self) -> Option<T> where T: Copy; } impl<T> Option<&mut T> { pub const fn copied(self) -> Option<T> where T: Copy; } impl<T, E> Option<Result<T, E>> { pub const fn transpose(self) -> Result<Option<T>, E> } impl<T> Option<Option<T>> { pub const fn flatten(self) -> Option<T>; } The following functions make use of the unstable `const_precise_live_drops` feature: - `expect` - `unwrap` - `unwrap_unchecked` - `transpose` - `flatten` Fixes: <https://github.com/rust-lang/rust/issues/67441>
2024-10-12Fixed get thread name behavior for FreeBSDYoh Deadfall-8/+10
2024-10-12Fixed pthread get/set name for macOSYoh Deadfall-23/+91
2024-10-12miri: avoid cloning AllocExtraRalf Jung-4/+12
2024-10-11intrinsics.fmuladdf{16,32,64,128}: expose llvm.fmuladd.* semanticsJed Brown-0/+93
Add intrinsics `fmuladd{f16,f32,f64,f128}`. This computes `(a * b) + c`, to be fused if the code generator determines that (i) the target instruction set has support for a fused operation, and (ii) that the fused operation is more efficient than the equivalent, separate pair of `mul` and `add` instructions. https://llvm.org/docs/LangRef.html#llvm-fmuladd-intrinsic MIRI support is included for f32 and f64. The codegen_cranelift uses the `fma` function from libc, which is a correct implementation, but without the desired performance semantic. I think this requires an update to cranelift to expose a suitable instruction in its IR. I have not tested with codegen_gcc, but it should behave the same way (using `fma` from libc).
2024-10-11simplify Tree Borrows write-during-2phase exampleRalf Jung-13/+15
2024-10-11rename RcBox in other places tooJonathan Dönszelmann-2/+2
2024-10-10Auto merge of #3960 - tiif:smallchange, r=RalfJungbors-25/+68
Pipe minor changes: diagnostics, flag support and comments This PR: - Add the exact syscall names to the blocking not supported diagnostic - Added support for ``pipe2`` ``O_NONBLOCK`` - Fix minor comment error in ``tests/pass-dep/libc/libc-epoll-blocking.rs`` Fixes #3912
2024-10-10add libc-pipe test to CI for freebsd, solarishRalf Jung-4/+4
2024-10-10Pipe minor changes: diagnostics, flag support and commentstiif-21/+64
2024-10-10Auto merge of #3950 - RalfJung:handle_unsupported_foreign_item, ↵bors-69/+3
r=RalfJung,saethlin,oli-obk remove -Zmiri-panic-on-unsupported flag Fixes https://github.com/rust-lang/miri/issues/3952, see that issue for discussion.
2024-10-10remove -Zmiri-panic-on-unsupported flagRalf Jung-42/+2
2024-10-10remove handle_unsupported_foreign_item helperRalf Jung-36/+10
2024-10-10Auto merge of #3956 - RalfJung:epoll-ready-list, r=RalfJungbors-4/+5
epoll: rename blocking_epoll_callback since it is not just called after unblocking `@tiif` does `return_ready_list` seem like a reasonable name?
2024-10-10epoll event adding: no need to join, there's no old clock hereRalf Jung-1/+1
2024-10-10Auto merge of #3959 - JakeRoggenbuck:fix-spelling-in-readme, r=saethlinbors-2/+2
Fix spelling in README Great project! I was reading some docs and found these that I think are spelling errors.
2024-10-09syscall/eventfd2: add supportFrank Rehwinkel-29/+21
2024-10-09syscall/eventfd2: add failing testFrank Rehwinkel-0/+29
The shim syscall logic doesn't support ID 290, SYS_eventfd2.
2024-10-09Auto merge of #3946 - FrankReh:fix-over-synchronization-of-epoll, r=RalfJungbors-11/+128
Fix over synchronization of epoll Fixes #3944. The clock used by epoll is now per event generated, rather than by the `epoll's` ready_list. The same epoll tests that existed before are unchanged and still pass. Also the `tokio` test case we had worked on last week still passes with this change. This change does beg the question of how the epoll event states should change. Perhaps rather than expose public crate bool fields, so setters should be provided that include a clock parameter or an optional clock parameter. Also should all the epoll event possibilities have their clock sync tested the way these commit lay out testing. In this first go around, only the pipe's EPOLLIN is tested. The EPOLLOUT might deserve testing too, as would the eventfd. Any future source of epoll events would also fit into that category.
2024-10-09epoll: change clock to be per eventFrank Rehwinkel-28/+41
2024-10-09Auto merge of #3953 - YohDeadfall:glibc-thread-name, r=RalfJungbors-24/+80
Fixed pthread_getname_np impl for glibc The behavior of `glibc` differs a bit different for `pthread_getname_np` from other implementations. It requires the buffer to be at least 16 bytes wide without exception. [Docs](https://www.man7.org/linux/man-pages/man3/pthread_setname_np.3.html): ``` The pthread_getname_np() function can be used to retrieve the name of the thread. The thread argument specifies the thread whose name is to be retrieved. The buffer name is used to return the thread name; size specifies the number of bytes available in name. The buffer specified by name should be at least 16 characters in length. The returned thread name in the output buffer will be null terminated. ``` [Source](https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_getname.c;hb=dff8da6b3e89b986bb7f6b1ec18cf65d5972e307#l37): ```c int __pthread_getname_np (pthread_t th, char *buf, size_t len) { const struct pthread *pd = (const struct pthread *) th; /* Unfortunately the kernel headers do not export the TASK_COMM_LEN macro. So we have to define it here. */ #define TASK_COMM_LEN 16 if (len < TASK_COMM_LEN) return ERANGE; ```
2024-10-09Fixed pthread_getname_np impl for glibcYoh Deadfall-24/+80
2024-10-09epoll: rename blocking_epoll_callback since it is not just called after ↵Ralf Jung-4/+5
unblocking
2024-10-09explain the review bot useRalf Jung-0/+8
2024-10-08epoll: test case showing too much clock syncFrank Rehwinkel-0/+104
2024-10-08fix behavior of release_clock()Ralf Jung-30/+90
2024-10-07Fix spelling in READMEJake-2/+2
2024-10-07bump rustc_tools_util versionRalf Jung-4/+4