about summary refs log tree commit diff
path: root/library/std/src/sys
AgeCommit message (Collapse)AuthorLines
2022-01-31Rollup merge of #93504 - solid-rs:fix-kmc-solid-stack-size, r=nagisaEric Huss-1/+2
kmc-solid: Increase the default stack size This PR increases the default minimum stack size on the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets to 64KiB (Arm) and 128KiB (AArch64). This value was chosen as a middle ground between supporting a relatively complex program (e.g., an application using a full-fledged off-the-shelf web server framework) with no additional configuration and minimizing resource consumption for the embedded platform that doesn't support lazily-allocated pages nor over-commitment (i.e., wasted stack spaces are wasted physical memory). If the need arises, the users can always set the `RUST_MIN_STACK` environmental variable to override the default stack size or use the platform API directly.
2022-01-31kmc-solid: Increase the default stack sizeTomoaki Kawada-1/+2
2022-01-31Rollup merge of #93494 - solid-rs:fix-kmc-solid-spawned-task-priority, ↵Matthias Krüger-5/+2
r=Mark-Simulacrum kmc-solid: Inherit the calling task's base priority in `Thread::new` This PR fixes the initial priority calculation of spawned threads on the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. Fixes a spawned task (an RTOS object on top of which threads are implemented for this target; unrelated to async tasks) getting an unexpectedly higher priority if it's spawned by a task whose priority is temporarily boosted by a priority-protection mutex.
2022-01-31Rollup merge of #93471 - cuviper:direntry-file_type-stat, r=the8472Matthias Krüger-2/+2
unix: Use metadata for `DirEntry::file_type` fallback When `DirEntry::file_type` fails to match a known `d_type`, we should fall back to `DirEntry::metadata` instead of a bare `lstat`, because this is faster and more reliable on targets with `fstatat`.
2022-01-31kmc-solid: Inherit the calling task's base priority in `Thread::new`Tomoaki Kawada-5/+2
Fixes a spawned task getting an unexpectedly higher priority if it's spawned by a task whose priority is temporarily boosted by a priority- protection mutex.
2022-01-29unix: Use metadata for `DirEntry::file_type` fallbackJosh Stone-2/+2
When `DirEntry::file_type` fails to match a known `d_type`, we should fall back to `DirEntry::metadata` instead of a bare `lstat`, because this is faster and more reliable on targets with `fstatat`.
2022-01-30Rollup merge of #93459 - tavianator:dirent-copy-only-reclen, r=cuviperMatthias Krüger-2/+10
fs: Don't copy d_name from struct dirent The dirent returned from readdir() is only guaranteed to be valid for d_reclen bytes on common platforms. Since we copy the name separately anyway, we can copy everything except d_name into DirEntry::entry. Fixes #93384.
2022-01-29fs: Don't copy d_name from struct direntTavian Barnes-2/+10
The dirent returned from readdir() is only guaranteed to be valid for d_reclen bytes on common platforms. Since we copy the name separately anyway, we can copy everything except d_name into DirEntry::entry. Fixes #93384.
2022-01-29Rollup merge of #93410 - solid-rs:feat-kmc-solid-net-dup, r=dtolnayMatthias Krüger-1/+4
kmc-solid: Implement `net::FileDesc::duplicate` This PR implements `std::sys::solid::net::FileDesc::duplicate`, which was accidentally left out when this target was added by #86191.
2022-01-29Auto merge of #93351 - anp:fuchsia-remove-dir-all, r=tmandrybors-2/+0
Bump libc and fix remove_dir_all on Fuchsia after CVE fix With the previous `is_dir` impl, we would attempt to unlink a directory in the None branch, but Fuchsia supports returning ENOTEMPTY from unlinkat() without the AT_REMOVEDIR flag because we don't currently differentiate unlinking files and directories by default. On the Fuchsia side I've opened https://fxbug.dev/92273 to discuss whether this is the correct behavior, but it doesn't seem like addressing the error code is necessary to make our tests happy. Depends on https://github.com/rust-lang/libc/pull/2654 since we apparently haven't needed to reference DT_UNKNOWN before this.
2022-01-28Fix remove_dir_all on Fuchsia after CVE fix.Adam Perry-2/+0
With the previous `is_dir` impl, we would attempt to unlink a directory in the None branch, but Fuchsia supports returning ENOTEMPTY from unlinkat() without the AT_REMOVEDIR flag because we don't currently differentiate unlinking files and directories by default. On the Fuchsia side I've opened https://fxbug.dev/92273 to discuss whether this is the correct behavior, but it doesn't seem like addressing the error code is necessary to make our tests happy. Updates std's libc crate to include DT_UNKNOWN for Fuchsia.
2022-01-28wasi: enable TcpListener and TcpStreamHarald Hoyer-13/+57
With the addition of `sock_accept()` to snapshot1, simple networking via a passed `TcpListener` is possible. This patch implements the basics to make a simple server work. Signed-off-by: Harald Hoyer <harald@profian.com>
2022-01-28wasi: update to wasi 0.11.0Harald Hoyer-24/+29
To make use of `sock_accept()`, update the wasi crate to `0.11.0`. Signed-off-by: Harald Hoyer <harald@profian.com>
2022-01-28kmc-solid: Implement `FileDesc::duplicate`Tomoaki Kawada-1/+4
2022-01-26Rollup merge of #92778 - tavianator:linux-readdir-no-r, r=joshtriplettMatthias Krüger-36/+58
fs: Use readdir() instead of readdir_r() on Linux and Android See #40021 for more details. Fixes #86649. Fixes #34668.
2022-01-25make Windows abort_internal Miri-compatibleRalf Jung-0/+1
2022-01-25Rollup merge of #88794 - sunfishcode:sunfishcode/try-clone, r=joshtriplettMatthias Krüger-91/+11
Add a `try_clone()` function to `OwnedFd`. As suggested in #88564. This adds a `try_clone()` to `OwnedFd` by refactoring the code out of the existing `File`/`Socket` code. r? ``@joshtriplett``
2022-01-24Rollup merge of #93152 - ivmarkov:master, r=m-ou-seMatthias Krüger-3/+7
Fix STD compilation for the ESP-IDF target (regression from CVE-2022-21658) Commit https://github.com/rust-lang/rust/commit/54e22eb7dbb615bd44355028d3fd867aa93c0972 broke the compilation of STD for the ESP-IDF embedded "unix-like" Tier 3 target, because the fix for [CVE-2022-21658](https://blog.rust-lang.org/2022/01/20/Rust-1.58.1.html) uses [libc flags](https://github.com/esp-rs/esp-idf-svc/runs/4892221554?check_suite_focus=true) which are not supported on the ESP-IDF platform. This PR simply redirects the ESP-IDF compilation to the "classic" implementation, similar to REDOX. This should be safe because: * Neither of the two filesystems supported by ESP-IDF (spiffs and fatfs) support [symlinks](https://github.com/natevw/fatfs/blob/master/README.md) in the first place * There is no notion of fs permissions at all, as the ESP-IDF is an embedded platform that does not have the notion of users, groups, etc. * Similarly, ESP-IDF has just one "process" - the firmware itself - which contains the user code and the "OS" fused together and running with all permissions
2022-01-22Rollup merge of #92828 - Amanieu:unwind-abort, r=dtolnayMatthias Krüger-1/+6
Print a helpful message if unwinding aborts when it reaches a nounwind function This is implemented by routing `TerminatorKind::Abort` back through the panic handler, but with a special flag in the `PanicInfo` which indicates that the panic handler should *not* attempt to unwind the stack and should instead abort immediately. This is useful for the planned change in https://github.com/rust-lang/lang-team/issues/97 which would make `Drop` impls `nounwind` by default. ### Code ```rust #![feature(c_unwind)] fn panic() { panic!() } extern "C" fn nounwind() { panic(); } fn main() { nounwind(); } ``` ### Before ``` $ ./test thread 'main' panicked at 'explicit panic', test.rs:4:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Illegal instruction (core dumped) ``` ### After ``` $ ./test thread 'main' panicked at 'explicit panic', test.rs:4:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread 'main' panicked at 'panic in a function that cannot unwind', test.rs:7:1 stack backtrace: 0: 0x556f8f86ec9b - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdccefe11a6ac4396 1: 0x556f8f88ac6c - core::fmt::write::he152b28c41466ebb 2: 0x556f8f85d6e2 - std::io::Write::write_fmt::h0c261480ab86f3d3 3: 0x556f8f8654fa - std::panicking::default_hook::{{closure}}::h5d7346f3ff7f6c1b 4: 0x556f8f86512b - std::panicking::default_hook::hd85803a1376cac7f 5: 0x556f8f865a91 - std::panicking::rust_panic_with_hook::h4dc1c5a3036257ac 6: 0x556f8f86f079 - std::panicking::begin_panic_handler::{{closure}}::hdda1d83c7a9d34d2 7: 0x556f8f86edc4 - std::sys_common::backtrace::__rust_end_short_backtrace::h5b70ed0cce71e95f 8: 0x556f8f865592 - rust_begin_unwind 9: 0x556f8f85a764 - core::panicking::panic_no_unwind::h2606ab3d78c87899 10: 0x556f8f85b910 - test::nounwind::hade6c7ee65050347 11: 0x556f8f85b936 - test::main::hdc6e02cb36343525 12: 0x556f8f85b7e3 - core::ops::function::FnOnce::call_once::h4d02663acfc7597f 13: 0x556f8f85b739 - std::sys_common::backtrace::__rust_begin_short_backtrace::h071d40135adb0101 14: 0x556f8f85c149 - std::rt::lang_start::{{closure}}::h70dbfbf38b685e93 15: 0x556f8f85c791 - std::rt::lang_start_internal::h798f1c0268d525aa 16: 0x556f8f85c131 - std::rt::lang_start::h476a7ee0a0bb663f 17: 0x556f8f85b963 - main 18: 0x7f64c0822b25 - __libc_start_main 19: 0x556f8f85ae8e - _start 20: 0x0 - <unknown> thread panicked while panicking. aborting. Aborted (core dumped) ```
2022-01-21Rollup merge of #92586 - esp-rs:bugfix/allocation-alignment-espidf, r=yaahcMatthias Krüger-2/+8
Set the allocation MIN_ALIGN for espidf to 4. Closes https://github.com/esp-rs/rust/issues/99. cc: `@ivmarkov`
2022-01-21Old versions of Android generate SIGSEGV from libc::abortAmanieu d'Antras-1/+6
2022-01-21fs: Use readdir() instead of readdir_r() on AndroidTavian Barnes-0/+10
Bionic also guarantees that readdir() is thread-safe enough.
2022-01-21fs: Use readdir() instead of readdir_r() on LinuxTavian Barnes-13/+30
readdir() is preferred over readdir_r() on Linux and many other platforms because it more gracefully supports long file names. Both glibc and musl (and presumably all other Linux libc implementations) guarantee that readdir() is thread-safe as long as a single DIR* is not accessed concurrently, which is enough to make a readdir()-based implementation of ReadDir safe. This implementation is already used for some other OSes including Fuchsia, Redox, and Solaris. See #40021 for more details. Fixes #86649. Fixes #34668.
2022-01-21fs: Implement more ReadDir methods in terms of name_cstr()Tavian Barnes-23/+18
2022-01-21Fix STD compilation for the ESP-IDF targetivmarkov-3/+7
2022-01-20Fix compilation for a few tier 2 targetsHans Kratz-8/+5
2022-01-19Fix CVE-2022-21658 for WASIAlex Crichton-8/+63
2022-01-19Fix CVE-2022-21658 for UNIX-likeHans Kratz-13/+281
2022-01-19Fix CVE-2022-21658 for WindowsChris Denton-27/+419
2022-01-13Set the allocation MIN_ALIGN for espidf to 4.Scott Mabin-2/+8
2022-01-05Rollup merge of #92517 - ChrisDenton:explicit-path, r=dtolnayMatthias Krüger-33/+37
Explicitly pass `PATH` to the Windows exe resolver This allows for testing different `PATH`s without using the actual environment.
2022-01-04Rollup merge of #91754 - Patrick-Poitras:rm-4byte-minimum-stdio-windows, ↵Matthias Krüger-18/+54
r=Mark-Simulacrum Modifications to `std::io::Stdin` on Windows so that there is no longer a 4-byte buffer minimum in read(). This is an attempted fix of issue #91722, where a too-small buffer was passed to the read function of stdio on Windows. This caused an error to be returned when `read_to_end` or `read_to_string` were called. Both delegate to `std::io::default_read_to_end`, which creates a buffer that is of length >0, and forwards it to `std::io::Stdin::read()`. The latter method returns an error if the length of the buffer is less than 4, as there might not be enough space to allocate a UTF-16 character. This creates a problem when the buffer length is in `0 < N < 4`, causing the bug. The current modification creates an internal buffer, much like the one used for the write functions I'd also like to acknowledge the help of ``@agausmann`` and ``@hkratz`` in detecting and isolating the bug, and for suggestions that made the fix possible. Couple disclaimers: - Firstly, I didn't know where to put code to replicate the bug found in the issue. It would probably be wise to add that case to the testing suite, but I'm afraid that I don't know _where_ that test should be added. - Secondly, the code is fairly fundamental to IO operations, so my fears are that this may cause some undesired side effects ~or performance loss in benchmarks.~ The testing suite runs on my computer, and it does fix the issue noted in #91722. - Thirdly, I left the "surrogate" field in the Stdin struct, but from a cursory glance, it seems to be serving the same purpose for other functions. Perhaps merging the two would be appropriate. Finally, this is my first pull request to the rust language, and as such some things may be weird/unidiomatic/plain out bad. If there are any obvious improvements I could do to the code, or any other suggestions, I would appreciate them. Edit: Closes #91722
2022-01-03Explicitly pass `PATH` to the Windows exe resolverChris Denton-33/+37
2021-12-28Fix windows buildXuanwo-0/+9
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-28Add try_reserve for OsStringXuanwo-0/+11
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-23Rollup merge of #92208 - ChrisDenton:win-bat-cmd, r=dtolnayMatthias Krüger-0/+16
Quote bat script command line Fixes #91991 [`CreateProcessW`](https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw#parameters) should only be used to run exe files but it does have some (undocumented) special handling for files with `.bat` and `.cmd` extensions. Essentially those magic extensions will cause the parameters to be automatically rewritten. Example pseudo Rust code (note that `CreateProcess` starts with an optional application name followed by the application arguments): ```rust // These arguments... CreateProcess(None, `@"foo.bat` "hello world""`@,` ...); // ...are rewritten as CreateProcess(Some(r"C:\Windows\System32\cmd.exe"), `@""foo.bat` "hello world"""`@,` ...); ``` However, when setting the first parameter (the application name) as we now do, it will omit the extra level of quotes around the arguments: ```rust // These arguments... CreateProcess(Some("foo.bat"), `@"foo.bat` "hello world""`@,` ...); // ...are rewritten as CreateProcess(Some(r"C:\Windows\System32\cmd.exe"), `@"foo.bat` "hello world""`@,` ...); ``` This means the arguments won't be passed to the script as intended. Note that running batch files this way is undocumented but people have relied on this so we probably shouldn't break it.
2021-12-23Rollup merge of #92117 - solid-rs:fix-kmc-solid-read-buf, r=yaahcMatthias Krüger-1/+27
kmc-solid: Add `std::sys::solid::fs::File::read_buf` This PR adds `std::sys::solid::fs::File::read_buf` to catch up with the changes introduced by #81156 and fix the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets..
2021-12-22Fix testsChris Denton-0/+4
2021-12-21kmc-solid: Add `std::sys::solid::fs::File::read_buf`Tomoaki Kawada-1/+27
Catching up with commit 3b263ceb5cb89b6d53b5a03b47ec447c3a7f7765
2021-12-16Revert "socket ancillary data implementation for dragonflybsd."David CARLIER-2/+2
2021-12-16Quote bat script command lineChris Denton-0/+16
2021-12-15Modifications to buffer UTF-16 internally so that there is no longer a ↵PFPoitras-18/+54
4-byte buffer minimum. Include suggestions from @agausmann and @Mark-Simulacrum.
2021-12-15Rollup merge of #91916 - steffahn:fix-typos, r=dtolnayMatthias Krüger-14/+14
Fix a bunch of typos I hope that none of these files is not supposed to be modified. FYI, I opened separate PRs for typos in submodules, in the respective repositories * https://github.com/rust-lang/stdarch/pull/1267 * https://github.com/rust-lang/backtrace-rs/pull/455
2021-12-14Fix a bunch of typosFrank Steffahn-14/+14
2021-12-12Address review feedbackAmanieu d'Antras-1/+1
2021-12-12Stabilize asm! and global_asm!Amanieu d'Antras-8/+11
They are also removed from the prelude as per the decision in https://github.com/rust-lang/rust/issues/87228. stdarch and compiler-builtins are updated to work with the new, stable asm! and global_asm! macros.
2021-12-11Rollup merge of #91553 - devnexen:anc_data_dfbsd, r=yaahcMatthias Krüger-2/+2
socket ancillary data implementation for dragonflybsd.
2021-12-09Auto merge of #81156 - DrMeepster:read_buf, r=joshtriplettbors-13/+78
Implement most of RFC 2930, providing the ReadBuf abstraction This replaces the `Initializer` abstraction for permitting reading into uninitialized buffers, closing #42788. This leaves several APIs described in the RFC out of scope for the initial implementation: * read_buf_vectored * `ReadBufs` Closes #42788, by removing the relevant APIs.
2021-12-09Rollup merge of #89999 - talagrand:GetTempPath2, r=m-ou-seMatthias Krüger-1/+7
Update std::env::temp_dir to use GetTempPath2 on Windows when available. As a security measure, Windows 11 introduces a new temporary directory API, GetTempPath2. When the calling process is running as SYSTEM, a separate temporary directory will be returned inaccessible to non-SYSTEM processes. For non-SYSTEM processes the behavior will be the same as before. This can help mitigate against attacks such as this one: https://medium.com/csis-techblog/cve-2020-1088-yet-another-arbitrary-delete-eop-a00b97d8c3e2 Compatibility risk: Software which relies on temporary files to communicate between SYSTEM and non-SYSTEM processes may be affected by this change. In many cases, such patterns may be vulnerable to the very attacks the new API was introduced to harden against. I'm unclear on the Rust project's tolerance for such change-of-behavior in the standard library. If anything, this PR is meant to raise awareness of the issue and hopefully start the conversation. How tested: Taking the example code from the documentation and running it through psexec (from SysInternals) on Win10 and Win11. On Win10: C:\test>psexec -s C:\test\main.exe <...> Temporary directory: C:\WINDOWS\TEMP\ On Win11: C:\test>psexec -s C:\test\main.exe <...> Temporary directory: C:\Windows\SystemTemp\
2021-12-05socket ancillary data implementation for dragonflybsd.David Carlier-2/+2