Commit graph

151248 commits

Author SHA1 Message Date
Dominik Stolz
12fbabd27f Do not call getpid wrapper after fork in tests
The test calls libc::getpid() in the pre_exec hook and asserts that the returned value is different from the PID of the parent.
However, libc::getpid() returns the wrong value.
Before version 2.25, glibc caches the PID of the current process with the goal of avoiding additional syscalls.
The cached value is only updated when the wrapper functions for fork or clone are called.
In PR #81825 we switch to directly using the clone3 syscall.
Thus, the cache is not updated and getpid returns the PID of the parent.
source: https://man7.org/linux/man-pages/man2/getpid.2.html#NOTES
2021-08-01 09:45:00 +02:00
Dominik Stolz
c3321d3eb3 Add tracking issue and link to man-page 2021-07-21 10:49:11 +02:00
Dominik Stolz
619fd96868 Add PidFd type and seal traits
Improve docs

Split do_fork into two

Make do_fork unsafe

Add target attribute to create_pidfd field in Command

Add method to get create_pidfd value
2021-07-21 10:49:11 +02:00
Josh Triplett
ef03de2e6a Typo fix
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
2021-07-21 10:49:11 +02:00
Aaron Hill
694be09b7b Add Linux-specific pidfd process extensions
Background:

Over the last year, pidfd support was added to the Linux kernel. This
allows interacting with other processes. In particular, this allows
waiting on a child process with a timeout in a race-free way, bypassing
all of the awful signal-handler tricks that are usually required.

Pidfds can be obtained for a child process (as well as any other
process) via the `pidfd_open` syscall. Unfortunately, this requires
several conditions to hold in order to be race-free (i.e. the pid is not
reused).
Per `man pidfd_open`:

```
· the disposition of SIGCHLD has not been explicitly set to SIG_IGN
 (see sigaction(2));

· the SA_NOCLDWAIT flag was not specified while establishing a han‐
 dler for SIGCHLD or while setting the disposition of that signal to
 SIG_DFL (see sigaction(2)); and

· the zombie process was not reaped elsewhere in the program (e.g.,
 either by an asynchronously executed signal handler or by wait(2)
 or similar in another thread).

If any of these conditions does not hold, then the child process
(along with a PID file descriptor that refers to it) should instead
be created using clone(2) with the CLONE_PIDFD flag.
```

Sadly, these conditions are impossible to guarantee once any libraries
are used. For example, C code runnng in a different thread could call
`wait()`, which is impossible to detect from Rust code trying to open a
pidfd.

While pid reuse issues should (hopefully) be rare in practice, we can do
better. By passing the `CLONE_PIDFD` flag to `clone()` or `clone3()`, we
can obtain a pidfd for the child process in a guaranteed race-free
manner.

This PR:

This PR adds Linux-specific process extension methods to allow obtaining
pidfds for processes spawned via the standard `Command` API. Other than
being made available to user code, the standard library does not make
use of these pidfds in any way. In particular, the implementation of
`Child::wait` is completely unchanged.

Two Linux-specific helper methods are added: `CommandExt::create_pidfd`
and `ChildExt::pidfd`. These methods are intended to serve as a building
block for libraries to build higher-level abstractions - in particular,
waiting on a process with a timeout.

I've included a basic test, which verifies that pidfds are created iff
the `create_pidfd` method is used. This test is somewhat special - it
should always succeed on systems with the `clone3` system call
available, and always fail on systems without `clone3` available. I'm
not sure how to best ensure this programatically.

This PR relies on the newer `clone3` system call to pass the `CLONE_FD`,
rather than the older `clone` system call. `clone3` was added to Linux
in the same release as pidfds, so this shouldn't unnecessarily limit the
kernel versions that this code supports.

Unresolved questions:
* What should the name of the feature gate be for these newly added
  methods?
* Should the `pidfd` method distinguish between an error occurring
  and `create_pidfd` not being called?
2021-07-21 10:49:11 +02:00
bors
9f2e753b2f Auto merge of #86965 - sexxi-goose:rfc2229-improve-lint, r=nikomatsakis,lqd
Improves migrations lint for RFC2229

This PR improves the current disjoint capture migration lint by providing more information on why drop order or auto trait implementation for a closure is impacted by the use of the new feature.

The drop order migration lint will now look something like this:
```
error: changes to closure capture in Rust 2021 will affect drop order
  --> $DIR/significant_drop.rs:163:21
   |
LL |             let c = || {
   |                     ^^
...
LL |                 tuple.0;
   |                 ------- in Rust 2018, closure captures all of `tuple`, but in Rust 2021, it only captures `tuple.0`
...
LL |         }
   |         - in Rust 2018, `tuple` would be dropped here, but in Rust 2021, only `tuple.0` would be dropped here alongside the closure
```

The auto trait migration lint will now look something like this:
```
error: changes to closure capture in Rust 2021 will affect `Send` trait implementation for closure
  --> $DIR/auto_traits.rs:14:19
   |
LL |     thread::spawn(move || unsafe {
   |                   ^^^^^^^^^^^^^^ in Rust 2018, this closure would implement `Send` as `fptr` implements `Send`, but in Rust 2021, this closure would no longer implement `Send` as `fptr.0` does not implement `Send`
...
LL |         *fptr.0 = 20;
   |         ------- in Rust 2018, closure captures all of `fptr`, but in Rust 2021, it only captures `fptr.0`
```

r? `@nikomatsakis`

Closes https://github.com/rust-lang/project-rfc-2229/issues/54
2021-07-11 03:50:28 +00:00
bors
99f8efec46 Auto merge of #86416 - Amanieu:asm_clobber_only, r=nagisa
Add clobber-only register classes for asm!

These are needed to properly express a function call ABI using a clobber
list, even though we don't support passing actual values into/out of
these registers.
2021-07-11 01:06:58 +00:00
bors
dfd7b8d03f Auto merge of #85953 - inquisitivecrystal:weak-linkat-in-fs-hardlink, r=joshtriplett
Fix linker error

Currently, `fs::hard_link` determines whether platforms have `linkat` based on the OS, and uses `link` if they don't. However, this heuristic does not work well if a platform provides `linkat` on newer versions but not on older ones. On old MacOS, this currently causes a linking error.

This commit fixes `fs::hard_link` by telling it to use `weak!` on macOS. This means that, on  that operating system, we now check for `linkat` at runtime and use `link` if it is not available.

Fixes #80804.

`@rustbot` label T-libs-impl
2021-07-10 21:42:40 +00:00
Aris Merchant
5999a5fbdc Make tests pass on old macos
On old macos systems, `fs::hard_link()` will follow symlinks.
This changes the test `symlink_hard_link` to exit early on
these systems, so that tests can pass.
2021-07-10 12:59:25 -07:00
Aris Merchant
fd0cb0cdc2 Change weak! and linkat! to macros 2.0
`weak!` is needed in a test in another module. With macros
1.0, importing `weak!` would require reordering module
declarations in `std/src/lib.rs`, which is a bit too
evil.
2021-07-10 12:55:09 -07:00
bors
432e145bd5 Auto merge of #86873 - nikic:opaque-ptrs, r=nagisa
Improve opaque pointers support

Opaque pointers are coming, and rustc is not ready.

This adds partial support by passing an explicit load type to LLVM. Two issues I've encountered:
 * The necessary type was not available at the point where non-temporal copies were generated. I've pushed the code for that upwards out of the memcpy implementation and moved the position of a cast to make do with the types we have available. (I'm not sure that cast is needed at all, but have retained it in the interest of conservativeness.)
 * The `PlaceRef::project_deref()` function used during debuginfo generation seems to be buggy in some way -- though I haven't figured out specifically what it does wrong. Replacing it with `load_operand().deref()` did the trick, but I don't really know what I'm doing here.
2021-07-10 19:01:41 +00:00
bors
a31431fce7 Auto merge of #87029 - JohnTitor:rollup-0yapv7z, r=JohnTitor
Rollup of 5 pull requests

Successful merges:

 - #87006 (Revert the revert of renaming traits::VTable to ImplSource)
 - #87011 (avoid reentrant lock acquire when ThreadIds run out)
 - #87013 (Fix several ICEs related to malformed `#[repr(...)]` attributes)
 - #87020 (remove const_raw_ptr_to_usize_cast feature)
 - #87028 (Fix type: `'satic` -> `'static`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-10 16:41:26 +00:00
Yuki Okushi
36b142f5c1
Rollup merge of #87028 - aDotInTheVoid:patch-1, r=petrochenkov
Fix type: `'satic` -> `'static`

Pointed out on discord: https://discord.com/channels/273534239310479360/490356824420122645/863434443170250793

~~The fact that this compiles is probably a bug.~~ Nope it's `#![feature(in_band_lifetimes)]` (Thanks to [floppy](https://discord.com/channels/273534239310479360/490356824420122645/863437381671059486)

~~[The docs](https://doc.rust-lang.org/stable/nightly-rustc/rustc_mir/transform/inline/struct.Inliner.html#method.check_codegen_attributes) seem to indicate rust thinks this function is generic over the lifetime `'satic`~~ This is because of `in_band_lifetimes`
2021-07-11 01:15:43 +09:00
Yuki Okushi
ad2a0fc93f
Rollup merge of #87020 - RalfJung:const_raw_ptr_to_usize_cast, r=oli-obk
remove const_raw_ptr_to_usize_cast feature

This feature currently has the strange status of "const-only `unsafe`", which was an experiment that we no longer think is a good idea. We need to find better ways to enable things like "messing with the low bits of a pointer" during CTFE.

r? `@oli-obk`
2021-07-11 01:15:42 +09:00
Yuki Okushi
945458d472
Rollup merge of #87013 - FabianWolff:issue-83921, r=estebank
Fix several ICEs related to malformed `#[repr(...)]` attributes

This PR fixes #83921. #83921 actually contains two related but distinct issues (one of them incorrectly reported as a duplicate in https://github.com/rust-lang/rust/issues/83921#issuecomment-814640734):

In the first, a call to `delay_span_bug` leads to an ICE when compiling with `-Zunpretty=everybody_loops` (and some other pretty-printing modes), because the corresponding error is emitted in a later pass, which does not run when only pretty-printing is requested.

The second issue is about parsing `#[repr(...)]` attributes. Currently, all of the following cause an ICE when applied to a struct/enum:
```rust
#[repr(packed())]
#[repr(align)]
#[repr(align(2, 4))]
#[repr(align())]
#[repr(i8())]
#[repr(u32(42))]
#[repr(i64 = 2)]
```
I have fixed this by expanding the well-formedness checks in `find_repr_attrs()`.
2021-07-11 01:15:41 +09:00
Yuki Okushi
0ca5fc2e33
Rollup merge of #87011 - RalfJung:thread-id-supply-shortage, r=nagisa
avoid reentrant lock acquire when ThreadIds run out

Discovered by `@bjorn3`
2021-07-11 01:15:40 +09:00
Yuki Okushi
632f84f4cb
Rollup merge of #87006 - ptrojahn:implsource_vtable, r=jonas-schievink
Revert the revert of renaming traits::VTable to ImplSource

As #72114 and #73055 were merged so closely together I think this
accidentally happened while rebasing
2021-07-11 01:15:39 +09:00
Amanieu d'Antras
d2a1d048d9 Add AArch64 z* registers as aliases for v* registers 2021-07-10 17:29:07 +02:00
Amanieu d'Antras
e1c3f5e017 Add clobber-only register classes for asm!
These are needed to properly express a function call ABI using a clobber
list, even though we don't support passing actual values into/out of
these registers.
2021-07-10 17:29:00 +02:00
Nixon Enraght-Moony
293fa8f39a Fix typo: satic -> static 2021-07-10 16:20:53 +01:00
bors
3982eb35ca Auto merge of #81360 - Aaron1011:trait-caller-loc, r=nagisa
Support forwarding caller location through trait object method call

Since PR #69251, the `#[track_caller]` attribute has been supported on
traits. However, it only has an effect on direct (monomorphized) method
calls. Calling a `#[track_caller]` method on a trait object will *not*
propagate caller location information - instead, `Location::caller()` will
return the location of the method definition.

This PR forwards caller location information when `#[track_caller]` is
present on the method definition in the trait. This is possible because
`#[track_caller]` in this position is 'inherited' by any impls of that
trait, so all implementations will have the same ABI.

This PR does *not* change the behavior in the case where
`#[track_caller]` is present only on the impl of a trait.
While all implementations of the method might have an explicit
`#[track_caller]`, we cannot know this at codegen time, since other
crates may have impls of the trait. Therefore, we keep the current
behavior of not forwarding the caller location, ensuring that all
implementations of the trait will have the correct ABI.

See the modified test for examples of how this works
2021-07-10 14:11:39 +00:00
Ralf Jung
dbc2b55baf rename variable 2021-07-10 14:14:09 +02:00
Ralf Jung
f5094aa5d6 remove duplicate test 2021-07-10 13:48:53 +02:00
Ralf Jung
fb010c9004 bless missing tests 2021-07-10 13:03:35 +02:00
Ralf Jung
5f0dd6db94 remove const_raw_ptr_to_usize_cast feature 2021-07-10 12:08:58 +02:00
Ralf Jung
2750d3ac6a avoid reentrant lock acquire when ThreadIds run out 2021-07-10 11:54:38 +02:00
Aris Merchant
5022c0638d Update docs for fs::hard_link 2021-07-09 23:24:36 -07:00
Aris Merchant
dc38d87505 Fix linker error
This makes `fs::hard_link` use weak! for some platforms,
thereby preventing a linker error.
2021-07-09 23:24:36 -07:00
bors
a84d1b21ae Auto merge of #86987 - lcnr:const-default-eval-bound, r=oli-obk
only check cg defaults wf once instantiated

the previous fixmes here didn't make too much sense as I didn't yet fully understand the code further below.
That code only runs if the predicates using our generic param default are fully concrete after substituting our default, which never happens if our default is generic.

r? `@oli-obk` `@BoxyUwU`
2021-07-10 06:01:04 +00:00
bors
8eae2eb1d3 Auto merge of #86968 - inquisitivecrystal:missing-docs-v2, r=oli-obk
Remove `missing_docs` lint on private 2.0 macros

798baebde1/compiler/rustc_lint/src/builtin.rs (L573-L584)

This code is the source of #57569. The problem is subtle, so let me point it out. This code makes the mistake of assuming that all of the macros in `krate.exported_macros` are exported.

...Yeah. For some historical reason, all `macro` macros are marked as exported, regardless of whether they actually are, which is dreadfully confusing. It would be more accurate to say that `exported_macros` currently contains only macros that have paths.

This PR renames `exported_macros` to `importable_macros`, since these macros can be imported with `use` while others cannot. It also fixes the code above to no longer lint on private `macro` macros, since the `missing_docs` lint should only appear on exported items.

Fixes #57569.
2021-07-10 03:32:42 +00:00
bors
8d9d4c87d6 Auto merge of #86419 - ricobbe:raw-dylib-stdcall, r=petrochenkov
Add support for raw-dylib with stdcall, fastcall functions

Next stage of work for #58713: allow `extern "stdcall"` and `extern "fastcall"` with `#[link(kind = "raw-dylib")]`.

I've deliberately omitted support for vectorcall, as that doesn't currently work, and I wanted to get this out for review.  (I haven't really investigated the vectorcall failure much yet, but at first (very cursory) glance it appears that the problem is elsewhere.)
2021-07-09 23:24:21 +00:00
bors
240ff4c4a0 Auto merge of #85263 - Smittyvb:thir-unsafeck-union-field, r=oli-obk
Check for union field accesses in THIR unsafeck

see also #85259, #83129, https://github.com/rust-lang/project-thir-unsafeck/issues/7

r? `@LeSeulArtichaut`
2021-07-09 20:56:07 +00:00
Nikita Popov
2ce1addeba Don't access pointer element type for nontemporal store
Simply shift the bitcast from the store to the load, so that
we can use the destination type. I'm not sure the bitcast is
really necessary, but keeping it for now.
2021-07-09 22:15:05 +02:00
Nikita Popov
208173f8e9 Fix project_deref() implementation
I'm not really sure what is wrong here, but I was getting load
type mismatches in the debuginfo code (which is the only place
using this function).

Replacing the project_deref() implementation with a generic
load_operand + deref did the trick.
2021-07-09 22:14:44 +02:00
Nikita Popov
4560efe46c Pass type when creating load
This makes load generation compatible with opaque pointers.

The generation of nontemporal copies still accesses the pointer
element type, as fixing this requires more movement.
2021-07-09 22:14:44 +02:00
Fabian Wolff
a7bfd35966 Enhance well-formedness checks for #[repr(...)] attributes 2021-07-09 22:03:48 +02:00
Nikita Popov
33e9a6b565 Pass type when creating atomic load
Instead of determining it from the pointer type, explicitly pass
the type to load.
2021-07-09 22:00:19 +02:00
Smitty
b86ed4a425 panic when trying to destructure union as enum 2021-07-09 15:22:12 -04:00
Richard Cobbe
a867dd4c7e Add support for raw-dylib with stdcall, fastcall functions on i686-pc-windows-msvc. 2021-07-09 12:04:54 -07:00
bors
3eff244fc7 Auto merge of #85832 - kornelski:raw_arg, r=yaahc
Unescaped command-line arguments for Windows

Some Windows commands, expecially `cmd.exe /c`, have unusual quoting requirements which are incompatible with default rules assumed for `.arg()`.

This adds `.unquoted_arg()` to `Command` via Windows `CommandExt` trait.

Fixes #29494
2021-07-09 18:15:20 +00:00
Smitty
df3e003378 Don't stub out part of test 2021-07-09 13:51:30 -04:00
Smitty
74d0d74dae Check for union field accesses in THIR unsafeck 2021-07-09 13:51:28 -04:00
Roxane
08c616741c Ensure deterministic ordering for diagnostics 2021-07-09 13:32:30 -04:00
Paul Trojahn
5cf954f932 Revert the revert of renaming traits::VTable to ImplSource
As #72114 and #73055 were merged so closely together I think this
accidentally happened while rebasing
2021-07-09 18:26:28 +02:00
bors
619c27a539 Auto merge of #87003 - m-ou-se:rollup-x7mhv3v, r=m-ou-se
Rollup of 5 pull requests

Successful merges:

 - #86855 (Fix comments about unique borrows)
 - #86881 (Inline implementation of lookup_line)
 - #86937 (Change linked tracking issue for more_qualified_paths)
 - #86994 (Update the comment on `lower_expr_try`)
 - #87000 (Use #[track_caller] in const panic diagnostics.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-09 15:34:16 +00:00
Mara Bos
2152c145d3
Rollup merge of #87000 - m-ou-se:const-panic-track-caller, r=oli-obk
Use #[track_caller] in const panic diagnostics.

This change stops const panic diagnostics from reporting inside #[track_caller] functions by skipping over them.
2021-07-09 16:20:36 +02:00
Mara Bos
98f35589f7
Rollup merge of #86994 - scottmcm:fix_expr_try_comment, r=petrochenkov
Update the comment on `lower_expr_try`

I'd updated the ones inside the method, but not its doc comment.
2021-07-09 16:20:35 +02:00
Mara Bos
07b9dae6a2
Rollup merge of #86937 - rylev:tracking-more-qualified-paths, r=nagisa
Change linked tracking issue for more_qualified_paths

This updates the linked tracking issue for the `more_qualified_paths` feature from the implementation PR #80080 to an actual tracking issue #86935.
2021-07-09 16:20:33 +02:00
Mara Bos
ad10107600
Rollup merge of #86881 - tmiasko:lookup-line, r=nagisa
Inline implementation of lookup_line

to avoid unnecessary conversions from `Option<usize>` to `isize` and back.
2021-07-09 16:20:32 +02:00
Mara Bos
e920ef8785
Rollup merge of #86855 - LeSeulArtichaut:patch-1, r=davidtwco
Fix comments about unique borrows
2021-07-09 16:20:32 +02:00