about summary refs log tree commit diff
path: root/src/libstd/sys
AgeCommit message (Collapse)AuthorLines
2020-04-09Rollup merge of #67705 - lzutao:wmemchr, r=wesleywiserMazdak Farrokhzad-2/+46
Use unrolled loop for searching NULL in [u16] on Windows
2020-04-08Rollup merge of #70134 - hermitcore:osstrext, r=dtolnayDylan DPC-0/+53
add basic support of OsStrExt for HermitCore - this patch increases the compatibility to other operating systems - in principle `ffi.rs` is derived from `src/libstd/sys/unix/ext/ffi.rs`
2020-04-06Forward OsStr::clone_into to the inner VecJosh Stone-0/+4
Despite OS differences, they're all just `Vec<u8>` inside, so we can just forward `clone_into` calls to that optimized implementation.
2020-04-06Rollup merge of #70808 - hermitcore:tls, r=dtolnayMazdak Farrokhzad-44/+48
Simplify dtor registration for HermitCore by using a list of destructors The implementation is similar to the macOS version and doesn't depend on additional OS support
2020-04-06Rollup merge of #70553 - hermitcore:abi, r=dtolnayMazdak Farrokhzad-33/+3
move OS constants to platform crate to reduce platform specific constants move O_RDONLY etc. and the definition of thread priorities to hermit-abi
2020-04-05Simplify dtor registration for HermitCore by using a list of destructorsStefan Lankes-44/+48
The implementation is similiar to macOS solution doesn't depend on additional OS support
2020-04-05Stop importing integer modules in libstdLinus Färnstrand-1/+0
2020-04-04Merge branch 'master' into abiStefan Lankes-87/+156
2020-04-04Auto merge of #70136 - hermitcore:network_tcp, r=dtolnaybors-87/+156
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 - in principle, the current PR is a revision of #69404
2020-04-04Merge branch 'master' into abiStefan Lankes-71/+63
2020-04-03Rollup merge of #70597 - vakaras:thread_new_double_free_bug_fix, r=AmanieuMazdak Farrokhzad-66/+59
Fix double-free and undefined behaviour in libstd::syn::unix::Thread::new While working on concurrency support for Miri, I found that the `libstd::syn::unix::Thread::new` method has two potential problems: double-free and undefined behaviour. **Double-free** could occur if the following events happened (credit for pointing this out goes to @RalfJung): 1. The call to `pthread_create` successfully launched a new thread that executed to completion and deallocated `p`. 2. The call to `pthread_attr_destroy` returned a non-zero value causing the `assert_eq!` to panic. 3. Since `mem::forget(p)` was not yet executed, the destructor of `p` would be executed and cause a double-free. As far as I understand, this code also violates the stacked-borrows aliasing rules and thus would result in **undefined behaviour** if these rules were adopted. The problem is that the ownership of `p` is passed to the newly created thread before the call to `mem::forget`. Since the call to `mem::forget` is still a call, it counts as a use of `p` and triggers UB. This pull request changes the code to use `mem::ManuallyDrop` instead of `mem::forget`. As a consequence, in case of a panic, `p` would be potentially leaked, which while undesirable is probably better than double-free or undefined behaviour.
2020-04-03Delete unnecessary stub stack overflow handler for cloudabi.Vytautas Astrauskas-13/+1
2020-04-03Delete unnecessary stub stack overflow handler for hermit.Vytautas Astrauskas-12/+0
2020-04-02Remove unnecessary stack overflow handler stub for sgx.Vytautas Astrauskas-8/+0
2020-04-02Remove unnecessary intermediate pointer cast in Thread::new.Vytautas Astrauskas-1/+1
2020-04-02Remove stack overflow handler stub for wasm.Vytautas Astrauskas-8/+0
2020-04-02Use unrolled looplzutao-9/+43
2020-04-02use of wmemchr for faster searching in [u16]Lzu Tao-2/+12
2020-04-01In Thread::new, add a comment that a panic could cause a memory leak.Vytautas Astrauskas-5/+14
2020-03-31Use Box::into_raw instead of ManuallyDrop in Thread::new.Vytautas Astrauskas-36/+20
2020-04-01Rollup merge of #70081 - lcnr:issue68387, r=varkorDylan DPC-3/+2
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-03-31Inline start_thread into its callers.Vytautas Astrauskas-15/+30
2020-03-31Fix double-free and undefined behaviour in libstd::syn::unix::Thread::new.Vytautas Astrauskas-18/+43
2020-03-31fix internal lint falloutBastian Kauschke-3/+2
2020-03-31Rollup merge of #70613 - matthiaskrgr:cl5ppy_squashed, r=CentrilMazdak Farrokhzad-1/+1
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-31more clippy fixesMatthias Krüger-1/+1
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-30std: Fix over-aligned allocations on wasm32-wasiAlex Crichton-1/+1
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-30Rollup merge of #70479 - RalfJung:win-env, r=Mark-SimulacrumDylan DPC-1/+1
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-30move the definition of thread priorities to hermit-abiStefan Lankes-24/+1
2020-03-30reorder imports to pass the format checkStefan Lankes-1/+1
2020-03-30minor changes to pass the format checkStefan Lankes-2/+1
2020-03-30move OS constants to platform crateStefan Lankes-8/+2
2020-03-29Rollup merge of #70510 - RalfJung:bool-vs-boolean, r=Mark-SimulacrumDylan DPC-1/+1
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-29Rollup merge of #69937 - TyPR124:osstr_ascii, r=dtolnayDylan DPC-5/+34
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-28use make_ascii_uppercase in windows/process.rsTyPR124-5/+4
2020-03-28ascii methods on osstrTyPR124-0/+30
2020-03-28fix TryEnterCriticalSection return typeRalf Jung-1/+1
2020-03-27avoid creating unnecessary reference in Windows Env iteratorRalf Jung-1/+1
2020-03-27Auto merge of #68404 - Amanieu:llvm-asm, r=estebankbors-4/+4
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-27Rollup merge of #70048 - TyPR124:mutable_osstr, r=dtolnayDylan DPC-0/+12
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-26Rename asm! to llvm_asm!Amanieu d'Antras-4/+4
asm! is left as a wrapper around llvm_asm! to maintain compatibility.
2020-03-23Rollup merge of #70207 - hatoo:macos-getentropy, r=dtolnayMazdak Farrokhzad-0/+37
Use getentropy(2) on macos resolves #70179
2020-03-21Rollup merge of #69955 - alexcrichton:stderr-infallible, r=sfacklerDylan DPC-19/+19
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-21Use getentropy(2) on macoshatoo-0/+37
2020-03-20Fix abort-on-eprintln during process shutdownAlex Crichton-19/+19
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-20add comment about maintaining OsStr encodingTyPR124-0/+2
2020-03-19add basic IP support in HermitCoreStefan Lankes-87/+156
- 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-19add basic support of OsStrExt for HermitCoreStefan Lankes-0/+53
this patch increases the compatibility to other operating systems
2020-03-19Rollup merge of #69969 - iximeow:sigstack-guard-page, r=cuviperMazdak Farrokhzad-5/+18
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-16make safety comments more explicitTyPR124-4/+4