Commit Graph

2300 Commits

Author SHA1 Message Date
Vytautas Astrauskas
53aa5a1113 Remove unnecessary stack overflow handler stub for sgx. 2020-04-02 16:29:09 -07:00
Vytautas Astrauskas
1c1bd957d5 Remove unnecessary intermediate pointer cast in Thread::new. 2020-04-02 07:15:45 -07:00
Vytautas Astrauskas
ec8275c364 Remove stack overflow handler stub for wasm. 2020-04-02 07:15:12 -07:00
lzutao
89bc23643b Use unrolled loop 2020-04-02 02:43:23 +00:00
Lzu Tao
041e1704fc use of wmemchr for faster searching in [u16] 2020-04-02 02:41:38 +00:00
Vytautas Astrauskas
baa6d557a7 In Thread::new, add a comment that a panic could cause a memory leak. 2020-04-01 12:46:14 -07:00
Vytautas Astrauskas
5382347064 Use Box::into_raw instead of ManuallyDrop in Thread::new. 2020-03-31 18:02:08 -07:00
Dylan DPC
8993358e77 Rollup merge of #70081 - lcnr:issue68387, r=varkor
add `unused_braces` lint

Add the lint `unused_braces` which is warn by default.

`unused_parens` is also extended and now checks anon consts.

closes #68387

r? @varkor
2020-04-01 00:27:20 +02:00
Vytautas Astrauskas
753bc7ddf8 Inline start_thread into its callers. 2020-03-31 15:15:14 -07:00
Vytautas Astrauskas
64e5327b6e Fix double-free and undefined behaviour in libstd::syn::unix::Thread::new. 2020-03-31 12:24:08 -07:00
Bastian Kauschke
21c5ccab10 fix internal lint fallout 2020-03-31 19:01:48 +02:00
Mazdak Farrokhzad
976f8d59dd Rollup merge of #70613 - matthiaskrgr:cl5ppy_squashed, r=Centril
more clippy fixes

* use is_empty() instead of len comparison (clippy::len_zero)
* use if let instead of while let loop that never loops (clippy::never_loop)
* remove redundant returns (clippy::needless_return)
* remove redundant closures (clippy::redundant_closure)
* use if let instead of match and wildcard pattern (clippy::single_match)
* don't repeat field names redundantly (clippy::redundant_field_names)

r? @Centril
2020-03-31 15:59:52 +02:00
Matthias Krüger
08f2904dfa more clippy fixes
use is_empty() instead of len comparison (clippy::len_zero)
use if let instead of while let loop that never loops (clippy::never_loop)
remove redundant returns (clippy::needless_return)
remove redundant closures (clippy::redundant_closure)
use if let instead of match and wildcard pattern (clippy::single_match)
don't repeat field names redundantly (clippy::redundant_field_names)
2020-03-31 15:20:05 +02:00
Alex Crichton
ab2998bac3 std: Fix over-aligned allocations on wasm32-wasi
The wasm32-wasi target delegates its malloc implementation to the
functions in wasi-libc, but the invocation of `aligned_alloc` was
incorrect by passing the number of bytes requested first rather than the
alignment. This commit swaps the order of these two arguments to ensure
that we allocate over-aligned memory correctly.
2020-03-30 12:30:06 -07:00
Dylan DPC
47ffca296a Rollup merge of #70479 - RalfJung:win-env, r=Mark-Simulacrum
avoid creating unnecessary reference in Windows Env iterator

Discovered in https://github.com/rust-lang/miri/pull/1225: the Windows `Env` iterator violates Stacked Borrows by creating an `&u16`, turning it into a raw pointer, and then accessing memory outside the range of that type.

There is no need to create a reference here in the first place, so the fix is trivial.
Cc @JOE1994
Cc https://github.com/rust-lang/unsafe-code-guidelines/issues/134
2020-03-30 16:24:44 +02:00
Stefan Lankes
9f6b96e461 move the definition of thread priorities to hermit-abi 2020-03-30 07:39:57 +02:00
Stefan Lankes
6c80bdb388 reorder imports to pass the format check 2020-03-30 07:17:00 +02:00
Stefan Lankes
412083469e minor changes to pass the format check 2020-03-30 07:05:35 +02:00
Stefan Lankes
415aff0516 move OS constants to platform crate 2020-03-30 06:49:17 +02:00
Dylan DPC
be8d896a4e Rollup merge of #70510 - RalfJung:bool-vs-boolean, r=Mark-Simulacrum
fix TryEnterCriticalSection return type

Source: https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-tryentercriticalsection
Fixes https://github.com/rust-lang/rust/issues/70504
2020-03-29 01:32:23 +01:00
Dylan DPC
d584f5a386 Rollup merge of #69937 - TyPR124:osstr_ascii, r=dtolnay
ASCII methods on OsStr

Would close #69566

I don't know enough about encodings to know if this is a valid change, however the comment on the issue suggests it could be.

This does two things:

1. Makes ASCII methods available on OsStr

2. Makes it possible to obtain a `&mut OsStr`. This is necessary to actually use `OsStr::make_ascii_*case` methods since they modify the underlying value. As far as I can tell, the only way to modify a `&mut OsStr` is via the methods I just added.

My original hope was to have these methods on `OsStrExt` for Windows, since the standard library already assumes `make_ascii_uppercase` is valid in Windows (see the change I made to windows/process.rs). If it is found these are not valid changes on non-Windows platforms, I can move the methods to the ext trait instead.
2020-03-29 01:32:17 +01:00
TyPR124
235700fea0 use make_ascii_uppercase in windows/process.rs 2020-03-28 18:34:49 -04:00
TyPR124
cc584d5166 ascii methods on osstr 2020-03-28 18:34:48 -04:00
Ralf Jung
38c8ba33ef fix TryEnterCriticalSection return type 2020-03-28 21:10:11 +01:00
Ralf Jung
2a1e61e2d6 avoid creating unnecessary reference in Windows Env iterator 2020-03-27 16:34:15 +01:00
bors
6c19a10e24 Auto merge of #68404 - Amanieu:llvm-asm, r=estebank
Rename asm! to llvm_asm!

As per https://github.com/rust-lang/rfcs/pull/2843, this PR renames `asm!` to `llvm_asm!`. It also renames the compiler's internal `InlineAsm` data structures to `LlvmInlineAsm` in preparation for the new `asm!` functionality specified in https://github.com/rust-lang/rfcs/pull/2850.

This PR doesn't actually deprecate `asm!` yet, it just makes it redirect to `llvm_asm!`. This is necessary because we first need to update the submodules (in particular stdarch) to use `llvm_asm!`.
2020-03-27 03:27:09 +00:00
Dylan DPC
c0369c4523 Rollup merge of #70048 - TyPR124:mutable_osstr, r=dtolnay
Allow obtaining &mut OsStr

```rust
impl DerefMut for OsString {...}              // type Target = OsStr
impl IndexMut<RangeFull> for OsString {...}   // type Output = OsStr
```

---

This change is pulled out of #69937 per @dtolnay

This implements `DerefMut for OsString` to allow obtaining a `&mut OsStr`. This also implements `IndexMut for OsString`, which is used by `DerefMut`. This pattern is the same as is used by `Deref`.

This is necessary to for methods like `make_ascii_lowercase` which need to mutate the underlying value.
2020-03-27 01:23:51 +01:00
Amanieu d'Antras
d162d096dd Rename asm! to llvm_asm!
asm! is left as a wrapper around llvm_asm! to maintain compatibility.
2020-03-26 15:49:22 +00:00
Mazdak Farrokhzad
675bdf6d6d Rollup merge of #70207 - hatoo:macos-getentropy, r=dtolnay
Use getentropy(2) on macos

resolves #70179
2020-03-23 04:26:07 +01:00
Dylan DPC
276b54e9c9 Rollup merge of #69955 - alexcrichton:stderr-infallible, r=sfackler
Fix abort-on-eprintln during process shutdown

This commit fixes an issue where if `eprintln!` is used in a TLS
destructor it can accidentally cause the process to abort. TLS
destructors are executed after `main` returns on the main thread, and at
this point we've also deinitialized global `Lazy` values like those
which store the `Stderr` and `Stdout` internals. This means that despite
handling TLS not being accessible in `eprintln!`, we will fail due to
not being able to call `stderr()`. This means that we'll double-panic
quickly because panicking also attempt to write to stderr.

The fix here is to reimplement the global stderr handle to avoid the
need for destruction. This avoids the need for `Lazy` as well as the
hidden panic inside of the `stderr` function.

Overall this should improve the robustness of printing errors and/or
panics in weird situations, since the `stderr` accessor should be
infallible in more situations.
2020-03-21 13:06:38 +01:00
hatoo
61ef72fe49 Use getentropy(2) on macos 2020-03-21 14:56:33 +09:00
Alex Crichton
5edaa7eefd Fix abort-on-eprintln during process shutdown
This commit fixes an issue where if `eprintln!` is used in a TLS
destructor it can accidentally cause the process to abort. TLS
destructors are executed after `main` returns on the main thread, and at
this point we've also deinitialized global `Lazy` values like those
which store the `Stderr` and `Stdout` internals. This means that despite
handling TLS not being accessible in `eprintln!`, we will fail due to
not being able to call `stderr()`. This means that we'll double-panic
quickly because panicking also attempt to write to stderr.

The fix here is to reimplement the global stderr handle to avoid the
need for destruction. This avoids the need for `Lazy` as well as the
hidden panic inside of the `stderr` function.

Overall this should improve the robustness of printing errors and/or
panics in weird situations, since the `stderr` accessor should be
infallible in more situations.
2020-03-20 07:34:56 -07:00
TyPR124
45416cd91a add comment about maintaining OsStr encoding 2020-03-20 09:00:53 -04:00
Stefan Lankes
57b7203047 add basic IP support in HermitCore
- add initial version to support sockets
- use TcpStream as test case
- HermitCore uses smoltcp as IP stack for pure Rust applications
- further functionalities (e.g. UDP support) will be added step by step
2020-03-19 08:34:22 +01:00
Stefan Lankes
c6435759b5 add basic support of OsStrExt for HermitCore
this patch increases the compatibility to other operating systems
2020-03-19 08:01:45 +01:00
Mazdak Farrokhzad
4c3a5a5da6 Rollup merge of #69969 - iximeow:sigstack-guard-page, r=cuviper
unix: Set a guard page at the end of signal stacks

This mitigates possible issues when signal stacks overflow, which could
manifest as segfaults or in unlucky circumstances possible clobbering of
other memory values as stack overflows tend to enable.

I went ahead and made a PR for this because it's a pretty small change, though if I should open an issue/RFC for this and discuss there first I'll happily do so. I've also added some example programs that demonstrate the uncomfortably clobber-happy behavior we currently have, and the segfaults that could/should result instead, [here](https://github.com/iximeow/jubilant-train).
2020-03-19 06:57:37 +01:00
TyPR124
e4a65e83e7 make safety comments more explicit 2020-03-16 16:22:49 -04:00
TyPR124
16712ede62 corrections on safety comments 2020-03-16 16:18:35 -04:00
TyPR124
cce8ee8bf7 remove #[inline] for consistency in windows/os_str 2020-03-16 16:15:13 -04:00
TyPR124
21975a1aaa add comments about safety 2020-03-16 16:12:54 -04:00
TyPR124
ef2957de13 allowing getting &mut OsStr from OsString 2020-03-16 13:13:07 -04:00
Dylan DPC
957241fcf9 Rollup merge of #69858 - da-x:windows-precise-time, r=Dylan-DPC
std: on Windows, use GetSystemTimePreciseAsFileTime if it is available

This implements #67266.
2020-03-16 01:30:28 +01:00
Yuki Okushi
5d90154886 Rollup merge of #69403 - LeSeulArtichaut:copy-ioslice, r=sfackler
Implement `Copy` for `IoSlice`

Resolves #69395

r? @sfackler
2020-03-14 04:03:20 +09:00
iximeow
28eeea630f fix formatting 2020-03-12 22:21:36 -07:00
iximeow
0ca2ed3646 return a pointer to the end of the valid part of the sigstack, no further
also unmap the whole thing when cleaning up, rather than leaving a spare
page floating around.
2020-03-12 21:17:10 -07:00
iximeow
041d97f4fd unix: Set a guard page at the end of signal stacks
This mitigates possible issues when signal stacks overflow, which could
manifest as segfaults or in unlucky circumstances possible clobbering of
other memory values as stack overflows tend to enable.
2020-03-12 20:32:02 -07:00
Dan Aloni
0605abe3bb Use GetSystemTimePreciseAsFileTime if it is available 2020-03-09 18:23:23 +02:00
Josh Stone
676b9bc477 unix: Don't override existing SIGSEGV/BUS handlers
Although `stack_overflow::init` runs very early in the process, even
before `main`, there may already be signal handlers installed for things
like the address sanitizer. In that case, just leave it alone, and don't
bother trying to allocate our own signal stacks either.
2020-03-08 18:44:12 -07:00
Matthias Krüger
136ad015b6 fix various typos 2020-03-06 15:19:31 +01:00
Matthias Krüger
c2bbe3349f Const items have by default a static lifetime, there's no need to annotate it. (clippy::redundant_static_lifetimes) 2020-03-05 16:38:24 +01:00