about summary refs log tree commit diff
path: root/library/std/src/os
AgeCommit message (Collapse)AuthorLines
2021-10-30Replace `std::os::raw::c_ssize_t` with `std::os::raw::c_ptrdiff_t`Thom Chiovoloni-2/+2
2021-10-23Rollup merge of #88300 - ijackson:exitstatusext-methods, r=yaahcMatthias Krüger-4/+4
Stabilise unix_process_wait_more, extra ExitStatusExt methods This stabilises the feature `unix_process_wait_more`. Tracking issue #80695, FCP needed. This was implemented in #79982 and merged in January.
2021-10-22Apply suggestions from code reviewJane Lusby-4/+4
2021-10-15Auto merge of #85379 - mdaverde:uds-abstract, r=joshtriplettbors-4/+416
Add abstract namespace support for Unix domain sockets Hello! The other day I wanted to mess around with UDS in Rust and found that abstract namespaces ([unix(7)](https://man7.org/linux/man-pages/man7/unix.7.html)) on Linux still needed development. I took the approach of adding `_addr` specific public functions to reduce conflicts. Feature name: `unix_socket_abstract` Tracking issue: #85410 Further context: #42048 ## Non-platform specific additions `UnixListener::bind_addr(&SocketAddr) -> Result<UnixListener>` `UnixStream::connect_addr(&SocketAddr) -> Result<()>` `UnixDatagram::bind_addr(&SocketAddr) -> Result<UnixDatagram>` `UnixDatagram::connect_addr(&SocketAddr) -> Result<()>` `UnixDatagram::send_to_addr(&self, &[u8], &SocketAddr) -> Result<usize>` ## Platform-specific (Linux) additions `SocketAddr::from_abstract_namespace(&[u8]) -> SocketAddr` `SockerAddr::as_abstract_namespace() -> Option<&[u8]>` ## Example ```rust #![feature(unix_socket_abstract)] use std::os::unix::net::{UnixListener, SocketAddr}; fn main() -> std::io::Result<()> { let addr = SocketAddr::from_abstract_namespace(b"namespace")?; // Linux only let listener = match UnixListener::bind_addr(&addr) { Ok(sock) => sock, Err(err) => { println!("Couldn't bind: {:?}", err); return Err(err); } }; Ok(()) } ``` ## Further Details The main inspiration for the implementation came from the [nix-rust](https://github.com/nix-rust/nix/blob/master/src/sys/socket/addr.rs#L558) crate but there are also other [historical](https://github.com/rust-lang/rust/commit/c4db0685b181f12c4285dac3d932f1859bba74f5) [attempts](https://github.com/tormol/uds/blob/master/src/addr.rs#L324) with similar approaches. A comment I did have was with this change, we now allow a `SocketAddr` to be constructed explicitly rather than just used almost as a handle for the return of `peer_addr` and `local_addr`. We could consider adding other explicit constructors (e.g. `SocketAddr::from_pathname`, `SockerAddr::from_unnamed`). Cheers!
2021-10-12Rollup merge of #89797 - jkugelman:must-use-is_condition-tests, r=joshtriplettthe8472-0/+1
Add #[must_use] to is_condition tests I threw in `std::path::Path::has_root` for funsies. A continuation of #89718. Parent issue: #89692 r? ```@joshtriplett```
2021-10-12Rollup merge of #89778 - jkugelman:must-use-as_type-conversions, r=joshtriplettthe8472-0/+1
Add #[must_use] to as_type conversions Clippy missed these: ```rust alloc::string::String fn as_mut_str(&mut self) -> &mut str; core::mem::NonNull<T> unsafe fn as_uninit_mut<'a>(&mut self) -> &'a MaybeUninit<T>; str unsafe fn as_bytes_mut(&mut self) -> &mut [u8]; str fn as_mut_ptr(&mut self) -> *mut u8; ``` Parent issue: #89692 r? ````@joshtriplett````
2021-10-11Add #[must_use] to is_condition testsJohn Kugelman-0/+1
A continuation of #89718.
2021-10-11Add #[must_use] to as_type conversionsJohn Kugelman-0/+1
2021-10-10integrate I/O safety changesMilan-7/+6
2021-10-10cross-platform doctestsMilan Landaverde-13/+49
2021-10-10moves use ptr within from_abstract_namespace fnMilan Landaverde-2/+2
2021-10-10Update tracking issue in stability refsMilan Landaverde-7/+7
2021-10-10rustfmtMilan Landaverde-6/+25
2021-10-10Add abstract namespace support for Unix domain socketsMilan Landaverde-5/+363
2021-10-10Add #[must_use] to core and std constructorsJohn Kugelman-0/+1
2021-10-05Apply suggestions from code reviewJane Lusby-4/+4
2021-10-05Document the valid values for `HandleOrNull` and `HandleOrInvalid`.Dan Gohman-0/+8
2021-10-05Fix compilation on WASI, which doesn't yet support `dup`.Dan Gohman-0/+10
2021-10-05Suppress some cfg from being shown in the stdlib docsWim Looman-0/+8
2021-09-28Add SOLID targetsTomoaki Kawada-0/+173
SOLID[1] is an embedded development platform provided by Kyoto Microcomputer Co., Ltd. This commit introduces a basic Tier 3 support for SOLID. # New Targets The following targets are added: - `aarch64-kmc-solid_asp3` - `armv7a-kmc-solid_asp3-eabi` - `armv7a-kmc-solid_asp3-eabihf` SOLID's target software system can be divided into two parts: an RTOS kernel, which is responsible for threading and synchronization, and Core Services, which provides filesystems, networking, and other things. The RTOS kernel is a μITRON4.0[2][3]-derived kernel based on the open-source TOPPERS RTOS kernels[4]. For uniprocessor systems (more precisely, systems where only one processor core is allocated for SOLID), this will be the TOPPERS/ASP3 kernel. As μITRON is traditionally only specified at the source-code level, the ABI is unique to each implementation, which is why `asp3` is included in the target names. More targets could be added later, as we support other base kernels (there are at least three at the point of writing) and are interested in supporting other processor architectures in the future. # C Compiler Although SOLID provides its own supported C/C++ build toolchain, GNU Arm Embedded Toolchain seems to work for the purpose of building Rust. # Unresolved Questions A μITRON4 kernel can support `Thread::unpark` natively, but it's not used by this commit's implementation because the underlying kernel feature is also used to implement `Condvar`, and it's unclear whether `std` should guarantee that parking tokens are not clobbered by other synchronization primitives. # Unsupported or Unimplemented Features Most features are implemented. The following features are not implemented due to the lack of native support: - `fs::File::{file_attr, truncate, duplicate, set_permissions}` - `fs::{symlink, link, canonicalize}` - Process creation - Command-line arguments Backtrace generation is not really a good fit for embedded targets, so it's intentionally left unimplemented. Unwinding is functional, however. ## Dynamic Linking Dynamic linking is not supported. The target platform supports dynamic linking, but enabling this in Rust causes several problems. - The linker invocation used to build the shared object of `std` is too long for the platform-provided linker to handle. - A linker script with specific requirements is required for the compiled shared object to be actually loadable. As such, we decided to disable dynamic linking for now. Regardless, the users can try to create shared objects by manually invoking the linker. ## Executable Building an executable is not supported as the notion of "executable files" isn't well-defined for these targets. [1] https://solid.kmckk.com/SOLID/ [2] http://ertl.jp/ITRON/SPEC/mitron4-e.html [3] https://en.wikipedia.org/wiki/ITRON_project [4] https://toppers.jp/
2021-09-21Rollup merge of #89114 - dequbed:c-char, r=yaahcthe8472-1/+1
Fixes a technicality regarding the size of C's `char` type Specifically, ISO/IEC 9899:2018 — better known as "C18" — (and at least C11, C99 and C89) do not specify the size of `byte` in bits. Section 3.6 defines "byte" as "addressable unit of data storage" while section 6.2.5 ("Types") only defines "char" as "large enough to store any member of the basic execution set" giving it a lower bound of 7 bit (since there are 96 characters in the basic execution set). With section 6.5.3.4 paragraph 4 "When sizeof is applied to an operant that has type char […] the result is 1" you could read this as the size of `char` in bits being defined as exactly the same as the number of bits in a byte but it's also valid to read that as an exception. In general implementations take `char` as the smallest unit of addressable memory, which for modern byte-addressed architectures is overwhelmingly 8 bits to the point of this convention being completely cemented into just about all of our software. So is any of this actually relevant at all? I hope not. I sincerely hope that this never, ever comes up. But if for some reason a poor rustacean is having to interface with C code running on a Cray X1 that in 2003 is still doing word-addressed memory with 64-bit chars and they trust the docs here blindly it will blow up in her face. And I'll be truly sorry for her to have to deal with … all of that.
2021-09-20Auto merge of #88321 - glaubitz:m68k-linux, r=wesleywiserbors-0/+1
Add initial support for m68k This patch series adds initial support for m68k making use of the new M68k backend introduced with LLVM-13. Additional changes will be needed to be able to actually use the backend for this target.
2021-09-20Fix a technicality regarding the size of C's `char` typeNadja Reitzenstein-1/+1
Specifically, ISO/IEC 9899:2018 — better known as "C18" — (and at least C11, C99 and C89) do not specify the size of `byte` in bits. Section 3.6 defines "byte" as "addressable unit of data storage" while section 6.2.5 ("Types") only defines "char" as "large enough to store any member of the basic execution set" giving it a lower bound of 7 bit (since there are 96 characters in the basic execution set). With section 6.5.3.4 paragraph 4 "When sizeof is applied to an operant that has type char […] the result is 1" you could read this as the size of `char` in bits being defined as exactly the same as the number of bits in a byte but it's also valid to read that as an exception. In general implementations take `char` as the smallest unit of addressable memory, which for modern byte-addressed architectures is overwhelmingly 8 bits to the point of this convention being completely cemented into just about all of our software. So is any of this actually relevant at all? I hope not. I sincerely hope that this never, ever comes up. But if for some reason a poor rustacean is having to interface with C code running on a Cray X1 that in 2003 is still doing word-addressed memory with 64-bit words and they trust the docs here blindly it will blow up in her face. And I'll be truly sorry for her to have to deal with … all of that.
2021-09-19Rollup merge of #89051 - schctl:master, r=jyn514Yuki Okushi-15/+60
Add intra-doc links and small changes to `std::os` to be more consistent I believe that a few items in `std::os` should be linked. I've also added a basic example in `std::os::windows`.
2021-09-17modify std::os docs to be more consistentSachin Cherian-15/+60
> add intra doc links > add a usage example for the os::windows module
2021-09-17Rollup merge of #88953 - joshtriplett:chown, r=dtolnayGuillaume Gomez-0/+70
Add chown functions to std::os::unix::fs to change the owner and group of files This is a straightforward wrapper that uses the existing helpers for C string handling and errno handling. Having this available is convenient for UNIX utility programs written in Rust, and avoids having to call unsafe functions like `libc::chown` directly and handle errors manually, in a program that may otherwise be entirely safe code. In addition, these functions provide a more Rustic interface by accepting appropriate traits and using `None` rather than `-1`.
2021-09-17libstd: Add m68k for raw type definitions on LinuxJohn Paul Adrian Glaubitz-0/+1
2021-09-15Add tracking issue for unix_chownJosh Triplett-3/+3
2021-09-14Add chown functions to std::os::unix::fs to change the owner and group of filesJosh Triplett-0/+70
This is a straightforward wrapper that uses the existing helpers for C string handling and errno handling. Having this available is convenient for UNIX utility programs written in Rust, and avoids having to call unsafe functions like `libc::chown` directly and handle errors manually, in a program that may otherwise be entirely safe code. In addition, these functions provide a more Rustic interface by accepting appropriate traits and using `None` rather than `-1`.
2021-09-13Move fortanix module position in std::os reexports for alpha sortGuillaume Gomez-20/+34
2021-09-13Remove usage of cfg_if in std/src/os/mod.rsGuillaume Gomez-31/+71
2021-09-13Simplify std::os module reexports to fix rustdoc linking issuesGuillaume Gomez-109/+74
2021-09-09Fix Windows compilation errors.Dan Gohman-11/+6
2021-09-09Fix another Windows compilation error.Dan Gohman-1/+1
2021-09-09Fix more Windows compilation errors.Dan Gohman-5/+16
2021-09-09Fix assertion failures in `OwnedHandle` with `windows_subsystem`.Dan Gohman-40/+72
As discussed in #88576, raw handle values in Windows can be null, such as in `windows_subsystem` mode, or when consoles are detached from a process. So, don't use `NonNull` to hold them, don't assert that they're not null, and remove `OwnedHandle`'s `repr(transparent)`. Introduce a new `HandleOrNull` type, similar to `HandleOrInvalid`, to cover the FFI use case.
2021-09-09Fix Windows compilation errors.Dan Gohman-3/+11
2021-09-09Add a `try_clone()` function to `OwnedFd`.Dan Gohman-0/+110
As suggested in #88564. This adds a `try_clone()` to `OwnedFd` by refactoring the code out of the existing `File`/`Socket` code.
2021-09-04Document when to use Windows' `symlink_dir` vs. `symlink_file`Chris Denton-2/+20
It was previously unclear which should be used when.
2021-09-02Rollup merge of #88177 - joshtriplett:stabilize-chroot, r=m-ou-seMara Bos-2/+1
Stabilize std::os::unix::fs::chroot I've verified that this works as documented, and I've tested it in (a nightly build of) production software as a replacement for an unsafe call to `libc::chroot`. It's been available in nightly for a few releases. I think it's ready to stabilize. --- Tracking issue: https://github.com/rust-lang/rust/issues/84715
2021-08-25Reference tracking issueThom Chiovoloni-2/+2
2021-08-25Add `c_size_t` and `c_ssize_t` to `std::os::raw`.Thom Chiovoloni-0/+14
2021-08-24Stabilise unix_process_await_more, extra ExitStatusExt methodsIan Jackson-4/+4
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-23Rollup merge of #88230 - steffahn:a_an, r=oli-obkMara Bos-3/+3
Fix typos “a”→“an” Fix typos in comments; found using a regex to find some easy instance of incorrect usage of a vs. an. While automation was used to find these, every change was checked manually. Changes in submodules get separate PRs: * https://github.com/rust-lang/stdarch/pull/1201 * https://github.com/rust-lang/cargo/pull/9821 * https://github.com/rust-lang/miri/pull/1874 * https://github.com/rust-lang/rls/pull/1746 * https://github.com/rust-analyzer/rust-analyzer/pull/9984 _folks @ rust-analyzer are fast at merging…_ * https://github.com/rust-analyzer/rust-analyzer/pull/9985 * https://github.com/rust-analyzer/rust-analyzer/pull/9987 * https://github.com/rust-analyzer/rust-analyzer/pull/9989 _For `clippy`, I don’t know if the changes should better better be moved to a PR to the original repo._ <hr> This has some overlap with #88226, but neither is a strict superset of the other. If you want multiple commits, I can split it up; in that case, make sure to suggest a criterion for splitting.
2021-08-22Remove redundant conversions.Dan Gohman-2/+2
2021-08-22Fix typos “a”→“an”Frank Steffahn-3/+3
2021-08-21Implement `AsFd` etc. for `UnixListener`.Dan Gohman-1/+25
Implement `AsFd`, `From<OwnedFd>`, and `Into<OwnedFd>` for `UnixListener`. This is a follow-up to #87329.
2021-08-19Stabilize std::os::unix::fs::chrootJosh Triplett-2/+1
2021-08-19Fix doc test failures on Windows.Dan Gohman-1/+7
2021-08-19Factor out a common `RawFd`/`AsRawFd`/etc for Unix and WASI.Dan Gohman-490/+286