1
Fork 0
Commit graph

267648 commits

Author SHA1 Message Date
Ralf Jung
5e6170b97f Preparing for merge from rustc 2024-10-14 17:04:30 +02:00
bors
15f0242c74 Auto merge of #3957 - YohDeadfall:macos-thread-name, r=RalfJung
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`](c032e0b076/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`](c032e0b076/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`](8d741a5de7/bsd/sys/proc_info_private.h (L274)), and `2` is [`PROC_INFO_CALL_SETCONTROL`](8d741a5de7/bsd/sys/proc_info.h (L821)). And `__proc_info` is a syscall handled by the XNU kernel by [`proc_info_internal`](8d741a5de7/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`](8d741a5de7/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-13 07:15:09 +00:00
Ralf Jung
b2b0d240a2 rework threadname test for more consistency 2024-10-13 09:13:33 +02:00
Yoh Deadfall
a495a79db9 Fixed get thread name behavior for FreeBSD 2024-10-12 21:39:30 +03:00
Yoh Deadfall
56c0612003 Fixed pthread get/set name for macOS 2024-10-12 21:38:54 +03:00
bors
2eda6a4e6e Auto merge of #3964 - RalfJung:write-during-2phase, r=RalfJung
simplify Tree Borrows write-during-2phase example
2024-10-11 10:41:15 +00:00
Ralf Jung
ccdea3ee36 simplify Tree Borrows write-during-2phase example 2024-10-11 12:39:51 +02:00
bors
256d63f444 Auto merge of #3960 - tiif:smallchange, r=RalfJung
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-10 20:09:42 +00:00
Ralf Jung
1df7a0ffb7 add libc-pipe test to CI for freebsd, solarish 2024-10-10 22:07:56 +02:00
tiif
37698a9bf1 Pipe minor changes: diagnostics, flag support and comments 2024-10-10 22:07:32 +02:00
bors
e58a40612c Auto merge of #3950 - RalfJung:handle_unsupported_foreign_item, 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-10 17:17:33 +00:00
Ralf Jung
9e2688c5f5 remove -Zmiri-panic-on-unsupported flag 2024-10-10 08:33:23 +02:00
Ralf Jung
7e21dce98c remove handle_unsupported_foreign_item helper 2024-10-10 08:33:07 +02:00
bors
c7bfc44516 Auto merge of #3956 - RalfJung:epoll-ready-list, r=RalfJung
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-10 06:21:22 +00:00
bors
66fda4a846 Auto merge of #3961 - RalfJung:event-release-clock-join, r=RalfJung
epoll event adding: no need to join, there's no old clock here
2024-10-10 05:54:58 +00:00
Ralf Jung
eb76079911 epoll event adding: no need to join, there's no old clock here 2024-10-10 07:53:16 +02:00
bors
faf8c14300 Auto merge of #3959 - JakeRoggenbuck:fix-spelling-in-readme, r=saethlin
Fix spelling in README

Great project! I was reading some docs and found these that I think are spelling errors.
2024-10-10 00:34:47 +00:00
bors
26ce30d5ed Auto merge of #3937 - FrankReh:syscall-eventfd2, r=RalfJung
syscall eventfd2

Add plumbing so syscall of SYS_eventfd2 can take advantage of the eventfd support already built into Miri.
2024-10-09 21:04:07 +00:00
Frank Rehwinkel
2675f14bef syscall/eventfd2: add support 2024-10-09 15:56:38 -04:00
Frank Rehwinkel
f04d1f64e2 syscall/eventfd2: add failing test
The shim syscall logic doesn't support ID 290, SYS_eventfd2.
2024-10-09 15:34:33 -04:00
bors
5cdee0781f Auto merge of #3946 - FrankReh:fix-over-synchronization-of-epoll, r=RalfJung
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-09 16:43:06 +00:00
Frank Rehwinkel
4560606602 epoll: change clock to be per event 2024-10-09 12:26:22 -04:00
bors
8e8dd57ac2 Auto merge of #3953 - YohDeadfall:glibc-thread-name, r=RalfJung
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-09 15:56:10 +00:00
Yoh Deadfall
f64c9c6416 Fixed pthread_getname_np impl for glibc 2024-10-09 18:47:14 +03:00
Ralf Jung
7a9a9cba3f epoll: rename blocking_epoll_callback since it is not just called after unblocking 2024-10-09 16:20:39 +02:00
bors
87058a4990 Auto merge of #3955 - RalfJung:review-bot, r=RalfJung
CONTRIBUTING.md: explain the review bot use
2024-10-09 12:21:58 +00:00
Ralf Jung
f90c97c915 explain the review bot use 2024-10-09 14:20:02 +02:00
Frank Rehwinkel
6f854ce343 epoll: test case showing too much clock sync 2024-10-08 21:35:46 -04:00
bors
edc5c1ec1c Auto merge of #3951 - RalfJung:release-clock, r=RalfJung
fix behavior of release_clock()

Fixes https://github.com/rust-lang/miri/issues/3947

Thanks to `@FrankReh` for noticing this and suggesting the right approach for the fix!
2024-10-08 13:14:49 +00:00
Ralf Jung
4e9554d893 fix behavior of release_clock() 2024-10-08 15:13:14 +02:00
Jake
0130edd302 Fix spelling in README 2024-10-07 13:06:23 -07:00
bors
ee491b39f6 Auto merge of #3949 - RalfJung:rustc_tools_util, r=RalfJung
bump rustc_tools_util version

Fixes https://github.com/rust-lang/miri/issues/3845 by incorporating https://github.com/rust-lang/rust-clippy/pull/13329
2024-10-07 17:59:38 +00:00
Ralf Jung
bf2d46dedb bump rustc_tools_util version 2024-10-07 19:57:40 +02:00
bors
c5f3c60be0 Auto merge of #3936 - YohDeadfall:rust-analyzer-conf, r=RalfJung
Added rust-analyzer instructions for Helix

That pull request adds information on how to configure Helix to use `rust-analyzer`, and moves the existing configuration to the `src/etc` directory as it's in the `rust` repository. Not adding instructions for other IDE because there's a link leading to the how-to for `rustc`.
2024-10-06 06:28:53 +00:00
Ralf Jung
6f84740b54 tweak the hint 2024-10-06 08:27:13 +02:00
Yoh Deadfall
35eb2da229 Added rust-analyzer instructions for Helix 2024-10-05 18:38:38 +03:00
bors
58e0fba93f Auto merge of #3945 - RalfJung:pthread_attr_t, r=RalfJung
avoid pthread_attr_t in tests

We don't support `pthread_attr_init` so the code here is actually technically wrong (passing attributes to `pthread_create` that were not initialized properly). It's also unnecessary, we can just pass a null pointer for the attributes to indicate "default attributes please".
2024-10-05 15:23:38 +00:00
Ralf Jung
885ec88f93 avoid pthread_attr_t in tests 2024-10-05 17:21:17 +02:00
bors
3b418b1485 Auto merge of #3940 - rust-lang:refutable_slice, r=RalfJung
Prefer refutable slice patterns over len check + index op

Just something I noticed while reviewing other PRs

We do it for shim arguments almost everywhere, but when the size is not statically known, we didn't use the helpers as they rely on array ops. But we can avoid a len check followed by several index ops by just using a refutable slice pattern with `let else`.

The pattern is so common, it seems almost worth a dedicated macro
2024-10-05 09:39:25 +00:00
bors
eb97047cc6 Auto merge of #3943 - RalfJung:pthread-mutex-reentrant, r=RalfJung
pthread mutex: better error in reentrant-locking-UB

Also test reentrant locking of PTHREAD_MUTEX_INITIALIZER
2024-10-05 08:49:15 +00:00
Ralf Jung
155380523c pthread mutex: better error in reentrant-locking-UB, also test PTHREAD_MUTEX_INITIALIZER 2024-10-05 10:46:14 +02:00
Oli Scherer
f46e1624cb Prefer refutable slice patterns over len check + index op 2024-10-04 20:23:59 +02:00
bors
f7400c390b Auto merge of #3895 - TDecking:gfni, r=RalfJung
Implement LLVM x86 gfni intrinsics
2024-10-04 15:09:21 +00:00
Tobias Decking
d00b754721
Implement LLVM x86 gfni intrinsics 2024-10-04 16:40:09 +02:00
bors
6602a2382d Auto merge of #3938 - rust-lang:rustup-2024-10-04, r=RalfJung
Automatic Rustup
2024-10-04 08:14:06 +00:00
Ralf Jung
dc88a6a788 clippy 2024-10-04 10:12:05 +02:00
The Miri Cronjob Bot
7014ae87df Merge from rustc 2024-10-04 05:07:56 +00:00
The Miri Cronjob Bot
d19bd66a4e Preparing for merge from rustc 2024-10-04 05:00:12 +00:00
bors
7067e4aee4 Auto merge of #131191 - nnethercote:lattice_op, r=lcnr
Merge `glb` and `lub` modules

Tons of code is duplicated across them, and it's easy to factor that out.

r? `@lcnr`
2024-10-04 01:20:08 +00:00
bors
e1e3cac26d Auto merge of #131215 - matthiaskrgr:rollup-i021ef7, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #131024 (Don't give method suggestions when method probe fails due to bad implementation of `Deref`)
 - #131112 (TransmuteFrom: Gracefully handle unnormalized types and normalization errors)
 - #131176 (.gitignore files for nix)
 - #131183 (Refactoring to `OpaqueTyOrigin`)
 - #131187 (Avoid ICE in coverage builds with bad `#[coverage(..)]` attributes)
 - #131192 (Handle `rustc_query_impl` cases of `rustc::potential_query_instability` lint)
 - #131197 (Avoid emptiness check in `PeekMut::pop`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-03 22:32:04 +00:00