about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2023-03-27Allow access to `OsStr` bytesEd Page-7/+21
`OsStr` has historically kept its implementation details private out of concern for locking us into a specific encoding on Windows. This is an alternative to #95290 which proposed specifying the encoding on Windows. Instead, this only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines rules for safely interacting with it At minimum, this can greatly simplify the `os_str_bytes` crate and every arg parser that interacts with `OsStr` directly (which is most of those that support invalid UTF-8).
2023-03-27socket ancillary data implementation for FreeBSD (from 13 and above).David CARLIER-0/+11
introducing new build config as well.
2023-03-24Rollup merge of #109368 - hermitcore:typo, r=cuviperMatthias Krüger-1/+1
fix typo in the creation of OpenOption for RustyHermit Due to this typo we have to build a workaround for issue hermitcore/libhermit-rs#191. RustyHermit is a tier 3 platform and backward compatibility does not have to be guaranteed.
2023-03-22Check the presence of linkat() on Solaris (not available in version 10, ↵Daniel Laügt-5/+6
available in version 11)
2023-03-21Rollup merge of #96391 - ChrisDenton:command-non-verbatim, r=joshtriplettMatthias Krüger-38/+62
Windows: make `Command` prefer non-verbatim paths When spawning Commands, the path we use can end up being queried using `env::current_exe` (or the equivalent in other languages). Not all applications handle these paths properly therefore we should have a stronger preference for non-verbatim paths when spawning processes.
2023-03-21Rollup merge of #108326 - tmiasko:read-buf, r=thomccnils-24/+136
Implement read_buf for a few more types Implement read_buf for TcpStream, Stdin, StdinLock, ChildStdout, ChildStderr (and internally for AnonPipe, Handle, Socket), so that it skips buffer initialization. The other provided methods like read_to_string and read_to_end are implemented in terms of read_buf and so benefit from the optimization as well. This commit also implements read_vectored and is_read_vectored where applicable.
2023-03-21Auto merge of #108262 - ChrisDenton:libntdll, r=Mark-Simulacrumbors-47/+40
Distribute libntdll.a with windows-gnu toolchains This allows the OS loader to load essential functions (e.g. read/write file) at load time instead of lazily doing so at runtime. r? libs
2023-03-19fix typo in the creation of OpenOptionStefan Lankes-1/+1
Due to this typo we have to build a workaround for issue hermitcore/libhermit-rs#191. RustyHermit is a tier 3 platform and backward compatibility does not have to be guaranteed.
2023-03-19Rollup merge of #108798 - devsnek:panic-pal-exception, r=workingjubileeDylan DPC-0/+9
move default backtrace setting to sys another PAL exception. moves the default backtrace setting to sys.
2023-03-17reviewGus Caplan-2/+2
2023-03-17move default backtrace setting to sysGus Caplan-0/+9
2023-03-17Modify code style as per commentsNagaChaitanya Vellanki-7/+5
2023-03-16run rustfmt on changesNagaChaitanya Vellanki-1/+1
2023-03-16fallback to lstat when stat fails on WindowsNagaChaitanya Vellanki-1/+13
2023-03-14Use getentropy() instead of /dev/urandom on EmscriptenKleis Auke Wolthuizen-2/+3
`/dev/urandom` is usually available on Emscripten, except when using the special `NODERAWFS` filesystem backend, which replaces all normal filesystem access with direct Node.js operations. Since this filesystem backend directly access the filesystem on the OS, it is not recommended to depend on `/dev/urandom`, especially when trying to run the Wasm binary on OSes that are not Unix-based. This can be considered a non-functional change, since Emscripten implements `/dev/urandom` in the same way as `getentropy()` when not linking with `-sNODERAWFS`.
2023-03-13Rollup merge of #108507 - hermitcore:new, r=m-ou-seMatthias Krüger-4/+3
use `as_ptr` to determine the address of atomics The PR #107736 renamed atomic `as_mut_ptr` to `as_ptr`. Consequently, the futex implementation of the tier-3 platform `RutyHermit` has to use this new interface. In addition, this PR removes also an unused import.
2023-03-10Moved thread_local implementation to sys::commonAyush Singh-315/+717
This allows removing all the platform-dependent code from `library/std/src/thread/local.rs` and `library/std/src/thread/mod.rs` Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-03-10Split __thread_local_inner macroAyush Singh-194/+316
Split the __thread_local_inner macro to make it more readable. Also move everything to crate::sys::common::thread_local. Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-03-10Move __thread_local_inner to sysAyush Singh-0/+194
Move __thread_local_inner macro in crate::thread::local to crate::sys. Currently, the tidy check does not fail for `library/std/src/thread/local.rs` even though it contains platform specific code. This is beacause target_family did not exist at the time the tidy checks were written [1]. [1]: https://github.com/rust-lang/rust/pull/105861#discussion_r1125841678 Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-03-08rand: freebsd update, using getrandom.David CARLIER-4/+18
supported since the 12th release, while 11.4 is EOL since 2021.
2023-03-06Implement read_buf for a few more typesTomasz Miąsko-24/+136
Implement read_buf for TcpStream, Stdin, StdinLock, ChildStdout, ChildStderr (and internally for AnonPipe, Handle, Socket), so that it skips buffer initialization. The other provided methods like read_to_string and read_to_end are implemented in terms of read_buf and so benefit from the optimization as well. This commit also implements read_vectored and is_read_vectored where applicable.
2023-03-04Auto merge of #89518 - a1phyr:unix_file_vectored_at, r=workingjubileebors-3/+189
Add vectored positioned I/O on Unix Add methods for vectored I/O with an offset on `File` for `unix` under `#![feature(unix_file_vectored_at)]`. The new methods are wrappers around `preadv` and `pwritev`. Tracking issue: #89517
2023-03-03Use weak linkage for `preadv` and `pwritev` on MacOS and iOSBenoît du Garreau-8/+18
2023-03-03Match unmatched backticks in library/est31-2/+2
2023-03-02Use weak linkage on AndroidBenoît du Garreau-4/+96
2023-03-02Auto merge of #106673 - flba-eb:add_qnx_nto_stdlib, r=workingjubileebors-29/+228
Add support for QNX Neutrino to standard library This change: - adds standard library support for QNX Neutrino (7.1). - upgrades `libc` to version `0.2.139` which supports QNX Neutrino `@gh-tr` ⚠️ Backtraces on QNX require https://github.com/rust-lang/backtrace-rs/pull/507 which is not yet merged! (But everything else works without these changes) ⚠️ Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
2023-02-28Retry to spawn/fork up to 3 times when it failed because of an interruptionFlorian Bartels-2/+64
2023-02-28Add QNX Neutrino support to libstdFlorian Bartels-28/+165
Co-authored-by: gh-tr <troach@qnx.com>
2023-02-27Rollup merge of #107110 - strega-nil:mbtwc-wctmb, r=ChrisDentonMatthias Krüger-29/+77
[stdio][windows] Use MBTWC and WCTMB `MultiByteToWideChar` and `WideCharToMultiByte` are extremely well optimized, and therefore should probably be used when we know we can (specifically in the Windows stdio stuff). Fixes #107092
2023-02-27Add vectored positioned I/O on UnixBenoît du Garreau-3/+87
2023-02-27use `as_ptr` to determine the address of atomicsStefan Lankes-3/+3
2023-02-26remove unused importsStefan Lankes-1/+0
2023-02-26std: use random HashMap keys on Hermitjoboet-2/+17
2023-02-25Auto merge of #107405 - hermitcore:bsd, r=bjorn3bors-461/+501
add support of RustyHermit's BSD socket layer RustyHermit is a tier 3 platform and publishes a new kernel interface. The new version supports a common BSD socket layer. By supporting this interface, the implementation of `std` can be harmonized to other operating systems. In `sys_common/mod.rs` we remove only a special case for RustyHermit. All changes are done in the RustyHermit specific directories. To realize this socket layer, the handling of file descriptors is also harmonized to other operating systems.
2023-02-25[stdio][windows] Use MBTWC and WCTMBNicole Mazzuca-29/+77
2023-02-24remove code duplicationsStefan Lankes-1/+56
2023-02-24move IO traits to std/src/os/hermitStefan Lankes-367/+12
By moving the IO traits, the RustyHermit support is harmonized to of other operating systems.
2023-02-24add support of RustyHermit's BSD socket layerStefan Lankes-455/+795
RustHermit publishs a new kernel interface and supports a common BSD socket layer. By supporting this interface, the implementation can be harmonized to other operating systems. To realize this socket layer, the handling of file descriptors is also harmonized to other operating systems.
2023-02-23Fix `is_terminal`'s handling of long paths on Windows.Dan Gohman-19/+21
As reported in sunfishcode/is-terminal#18, there are situations where `GetFileInformationByHandleEx` can write a file name length that is longer than the provided buffer. To avoid deferencing memory past the end of the buffer, use a bounds-checked function to form a slice to the buffer and handle the out-of-bounds case. This ports the fix from sunfishcode/is-terminal#19 to std's `is_terminal` implementation.
2023-02-23Rollup merge of #108218 - ChrisDenton:cmd-escape, r=cuviperMatthias Krüger-1/+10
Windows: Quote more batch file arguments Make sure to always quote batch file arguments that contain command prompt special characters. Additionally add `/d` command line parameter to disable any autorun scripts that may change the way variable expansion works. This makes it more consistent across systems and may help avoid surprises. ## Background Info [`CreateProcess`](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) with the `lpApplicationName` set can only be used to run `.exe` files and not script files such as `.bat`. However, for historical reasons, we do have special handling so that `.bat` files will be correctly run with `cmd.exe` as the application. In Windows, command line arguments are passed as a single string (not an array). Applications can parse this string however they like but most follow the standard MSVC C/C++ convention. But `cmd.exe` uses different argument parsing rules to other Windows programs (because it emulates old DOS). This PR aims to help smooth over some of the differences. r? libs
2023-02-22Quote more batch file argumentsChris Denton-1/+10
Make sure to quote batch file arguments that contain command prompt special characters. Additionally add `/d` command line parameter to disable any commands that may change the way variable expansion works.
2023-02-21Remove unused FileDesc::get_cloexecTomasz Miąsko-5/+0
2023-02-20Distribute libntdll.a with windows-gnu toolchainsChris Denton-47/+40
This allows loading some essential functions (e.g. read/write file) at load time instead of lazily.
2023-02-19Use custom implementation of read_buf in Read for &'a FileDescTomasz Miąsko-0/+4
This allows to skip an unnecessary buffer initialization.
2023-02-18Auto merge of #107329 - joboet:optimize_lazylock, r=m-ou-sebors-0/+11
Optimize `LazyLock` size The initialization function was unnecessarily stored separately from the data to be initialized. Since both cannot exist at the same time, a `union` can be used, with the `Once` acting as discriminant. This unfortunately requires some extra methods on `Once` so that `Drop` can be implemented correctly and efficiently. `@rustbot` label +T-libs +A-atomic
2023-02-16std: replace generic thread parker with explicit no-op parkerjoboet-0/+16
2023-02-16Rollup merge of #106372 - joboet:solid_id_parking, r=m-ou-seDylan DPC-74/+39
Use id-based thread parking on SOLID By using the [`slp_tsk`/`wup_tsk`](https://cs.uwaterloo.ca/~brecht/courses/702/Possible-Readings/embedded/uITRON-4.0-specification.pdf) system functions instead of an event-flag structure, `Parker` becomes cheaper to construct and SOLID can share the implementation used by NetBSD and SGX. ping ``@kawadakk`` r? ``@m-ou-se`` ``@rustbot`` label +T-libs
2023-02-14Revert to using `RtlGenRandom`Chris Denton-103/+31
This is required due to `BCryptGenRandom` failing to load the necessary dll on some systems.
2023-02-13Rollup merge of #107985 - alesito85:master, r=ChrisDentonMatthias Krüger-1/+6
Added another error to be processed in fallback This pull request addresses the problem of Rust not being able to read file/directory metadata because the current user doesn't have permission to read the file and are thus inaccessible. One particular example is `System Volume Information`. But any example can be made by having a file/directory, which the current user can't access even though the system does allow to view the metadata, which is handled by the fallback. The fallback exists to get the metadata but it was limited to one error type. Having added ERROR_ACCESS_DENIED per Chris Denton's suggestion, file/directory properties are now properly read. Solution suggested by Chris Denton https://github.com/nushell/nushell/issues/6857#issuecomment-1426847135
2023-02-13Add another error to Windows file open fallbackalesito85-1/+6
Added another error to be processed in fallback Solution suggested by Chris Denton https://github.com/nushell/nushell/issues/6857#issuecomment-1426847135