about summary refs log tree commit diff
path: root/src/libstd/sys
AgeCommit message (Collapse)AuthorLines
2016-02-14Rollup merge of #31589 - reem:remove-unnecessary-poison-bounds, r=sfacklerManish Goregaokar-4/+7
None
2016-02-13std: Deprecate all std::os::*::raw typesAlex Crichton-109/+114
This commit is an implementation of [RFC 1415][rfc] which deprecates all types in the `std::os::*::raw` modules. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1415-trim-std-os.md Many of the types in these modules don't actually have a canonical platform representation, for example the definition of `stat` on 32-bit Linux will change depending on whether C code is compiled with LFS support or not. Unfortunately the current types in `std::os::*::raw` are billed as "compatible with C", which in light of this means it isn't really possible. To make matters worse, platforms like Android sometimes define these types as *smaller* than the way they're actually represented in the `stat` structure itself. This means that when methods like `DirEntry::ino` are called on Android the result may be truncated as we're tied to returning a `ino_t` type, not the underlying type. The commit here incorporates two backwards-compatible components: * Deprecate all `raw` types that aren't in `std::os::raw` * Expand the `std::os::*::fs::MetadataExt` trait on all platforms for method accessors of all fields. The fields now returned widened types which are the same across platforms (consistency across platforms is not required, however, it's just convenient). and two also backwards-incompatible components: * Change the definition of all `std::os::*::raw` type aliases to correspond to the newly widened types that are being returned on each platform. * Change the definition of `std::os::*::raw::stat` on Linux to match the LFS definitions rather than the standard ones. The breaking changes here will specifically break code that assumes that `libc` and `std` agree on the definition of `std::os::*::raw` types, or that the `std` types are faithful representations of the types in C. An [audit] has been performed of crates.io to determine the fallout which was determined two be minimal, with the two found cases of breakage having been fixed now. [audit]: https://github.com/rust-lang/rfcs/pull/1415#issuecomment-180645582 --- Ok, so after all that, we're finally able to support LFS on Linux! This commit then simultaneously starts using `stat64` and friends on Linux to ensure that we can open >4GB files on 32-bit Linux. Yay! Closes #28978 Closes #30050 Closes #31549
2016-02-13Fixes #28528Paul Dicker-58/+72
Fix `read_link` to also be able to read the target of junctions on Windows. Also the path returned should not include a NT namespace, and there were some problems with permissions.
2016-02-13Auto merge of #31557 - retep998:house-directory, r=alexcrichtonbors-2/+2
This is the simple solution. I know @nodakai was working on a more complex solution that overhauled the `fill_utf16_buf` stuff. r? @alexcrichton
2016-02-11Remove unnecessary bounds on Error and Display implementations for ↵Jonathan Reem-4/+7
TryLockError and PoisonError.
2016-02-12Auto merge of #31123 - alexcrichton:who-doesnt-want-two-build-systems, r=brsonbors-2/+9
This series of commits adds the initial implementation of a new build system for the compiler and standard library based on Cargo. The high-level architecture now looks like: 1. The `./configure` script is run with `--enable-rustbuild` and other standard configuration options. 2. A `Makefile` is generate which proxies commands to the new build system. 3. The new build system has a Python script entry point which manages downloading both a Rust and Cargo nightly. This initial script also manages building the build system itself (which is written in Rust). 4. The build system, written in rust and called `bootstrap`, architects how to call `cargo` and manages building all native libraries and such. One might reasonably ask "why rewrite the build system?", which is a good question! The Rust project has used Makefiles for as long as I can remember at least, and while ugly and difficult to use are undeniably robust as they contain years worth of tweaking and tuning for working on as many platforms in as many situation as possible. The rationale behind this PR, however is: * The makefiles are impenetrable to all but a few people on this planet. This means that contributions to the build system are almost nonexistent, and furthermore if a build system change is needed it's incredibly difficult to figure out how to do so. This hindrance prevents us from doing some "perhaps fancier" things we may wish to do in make. * Our build system, while portable, is unfortunately not infinitely portable everywhere. For example the recently-introduced MSVC target is quite unlikely to have `make` installed by default (e.g. it requires building inside of an MSYS2 shell currently). Conversely, the portability of make comes at a cost of crazy and weird hacks to work around all sorts of versions of software everywhere, especially when it comes to the configure script and makefiles. By rewriting this logic in one of the most robust platforms there is, Rust, we get to assuage all of these worries for free! * There's a standard tool to build Rust crates, Cargo, but the standard library and compiler don't use it. This means that they cannot benefit easily from the crates.io ecosystem, nor can the ecosystem benefit from a standard way to build this repository itself. Moving to Cargo should help assuage both of these needs. This has the added benefit of making the compiler more approachable for newbies as working on the compiler will just happen to be working on a large Cargo project, all the same standard tools and tricks will apply. * There's a huge amount of portability information in the main distribution, for example around cross compiling, compiling on new OSes, etc. Pushing this logic into standard crates (like `gcc`) enables the community to immediately benefit from new build logic. Despite these benefits, it's going to be a long road to actually replace our current build system. This PR is just the beginning and doesn't implement the full suite of functionality as the current one, but there are many more to follow! The current implementation strategy hopes to look like: 1. Land a second build system in-tree that can be itereated on an and contributed to. This will not be used just yet in terms of gating new commits to the repo. 2. Over time, bring the second build system to feature parity with the old build system, start setting up CI for both build systems. 3. At some point in the future, switch the default to the new build system, but keep the old one around. 4. At some further point in the future, delete the entire old build system. --- Alright, so with all that out of the way, here's some more info on this PR itself. The inital build system here is contained in the `src/bootstrap` directory and just adds the necessary minimum bits to bootstrap the compiler itself. There is currently no support for building documentation, running tests, or installing, but the implemented support is: * Compiling LLVM with `cmake` instead of `./configure` + `make`. The LLVM project is removing their autotools build system, so we'd have to make this transition eventually anyway. * Compiling compiler-rt with `cmake` as well (for the same rationale as above). * Adding `Cargo.toml` to map out the dependency graph to all crates, and also adding `build.rs` files where appropriate. For example `alloc_jemalloc` has a script to build jemalloc, `flate` has a script to build `miniz.c`, `std` will build `libbacktrace`, etc. * Orchestrating all the calls to `cargo` to build the standard distribution, following the normal bootstrapping process. This also tracks dependencies between steps to ensure cross-compilation targets happen as well. * Configuration is intended to eventually be done through a `config.toml` file, so support is implemented for this. The most likely vector of configuration for now, however, is likely through `config.mk` (what `./configure` emits), so the build system currently parses this information. There's still quite a few steps left to do, and I'll open up some follow-up issues (as well as a tracking issue) for this migration, but hopefully this is a great start to get going! This PR is currently tested on all the Windows/Linux/OSX triples for x86\_64 and x86, but more portability is always welcome! --- Future functionality left to implement * [ ] Re-verify that multi-host builds work * [ ] Verify android build works * [ ] Verify iOS build work (mostly compiler-rt) * [ ] Verify sha256 and ideally gpg of downloaded nightly compiler and nightly rustc * [ ] Implement testing -- this is a huge bullet point with lots of sub-bullets * [ ] Build and generate documentation (plus the various tools we have in-tree) * [ ] Move various src/etc scripts into Rust -- not sure how this interacts with `make` build system * [ ] Implement `make install` - like testing this is also quite massive * [x] Deduplicate version information with makefiles
2016-02-11bootstrap: Add directives to not double-link libsAlex Crichton-2/+9
Have all Cargo-built crates pass `--cfg cargobuild` and then add appropriate `#[cfg]` definitions to all crates to avoid linking anything if this is passed. This should help allow libstd to compile with both the makefiles and with Cargo.
2016-02-11Fix usage of GetUserProfileDirectoryW in env::home_dirPeter Atashian-2/+2
Signed-off-by: Peter Atashian <retep998@gmail.com>
2016-02-11Auto merge of #31532 - tomaka:fix-emscripten, r=brsonbors-2/+2
Before this PR: > test result: FAILED. 2039 passed; 327 failed; 2 ignored; 0 measured After: > test result: FAILED. 2232 passed; 134 failed; 2 ignored; 0 measured r? @brson
2016-02-10std: Move constant back to where it needs to beAlex Crichton-2/+2
Lost track of this during the std::process refactorings
2016-02-10std: Use macros from libc instead of locallyAlex Crichton-24/+3
Helps cut down on #[cfg]!
2016-02-10std: Implement CommandExt::execAlex Crichton-2/+40
This commit implements the `exec` function proposed in [RFC 1359][rfc] which is a function on the `CommandExt` trait to execute all parts of a `Command::spawn` without the `fork` on Unix. More details on the function itself can be found in the comments in the commit. [rfc]: https://github.com/rust-lang/rfcs/pull/1359 cc #31398
2016-02-10std: Push process stdio setup in std::sysAlex Crichton-282/+396
Most of this is platform-specific anyway, and we generally have to jump through fewer hoops to do the equivalent operation on Windows. One benefit for Windows today is that this new structure avoids an extra `DuplicateHandle` when creating pipes. For Unix, however, the behavior should be the same. Note that this is just a pure refactoring, no functionality was added or removed.
2016-02-10std: Lift out Windows' CreateProcess lock a bitAlex Crichton-13/+20
The function `CreateProcess` is not itself unsafe to call from many threads, the article in question is pointing out that handles can be inherited by unintended child processes. This is basically the same race as the standard Unix open-then-set-cloexec race. Since the intention of the lock is to protect children from inheriting unintended handles, the lock is now lifted out to before the creation of the child I/O handles (which will all be inheritable). This will ensure that we only have one process in Rust at least creating inheritable handles at a time, preventing unintended inheritance to children.
2016-02-10std: Rename Stdio::None to Stdio::NullAlex Crichton-15/+12
This better reflects what it's actually doing as we don't actually have an option for "leave this I/O slot as an empty hole".
2016-02-10std: Push Child's exit status to sys::processAlex Crichton-25/+25
On Unix we have to be careful to not call `waitpid` twice, but we don't have to be careful on Windows due to the way process handles work there. As a result the cached `Option<ExitStatus>` is only necessary on Unix, and it's also just an implementation detail of the Unix module. At the same time. also update some code in `kill` on Unix to avoid a wonky waitpid with WNOHANG. This was added in 0e190b9a to solve #13124, but the `signal(0)` method is not supported any more so there's no need to for this workaround. I believe that this is no longer necessary as it's not really doing anything.
2016-02-10std: Implement CommandExt::before_execAlex Crichton-2/+51
This is a Unix-specific function which adds the ability to register a closure to run pre-exec to configure the child process as required (note that these closures are run post-fork). cc #31398
2016-02-10std: Refactor process spawning on UnixAlex Crichton-167/+163
* Build up the argp/envp pointers while the `Command` is being constructed rather than only when `spawn` is called. This will allow better sharing of code between fork/exec paths. * Rename `child_after_fork` to `exec` and have it only perform the exec half of the spawning. This also means the return type has changed to `io::Error` rather than `!` to represent errors that happen.
2016-02-10Fix half of emscripten's failing testsPierre Krieger-2/+2
2016-02-08Auto merge of #31468 - pitdicker:fs_tests_cleanup, r=alexcrichtonbors-2/+22
See #29412
2016-02-07Don't let `remove_dir_all` recursively remove a symlinkPaul Dicker-2/+22
See #29412
2016-02-06Auto merge of #30629 - brson:emscripten-upstream, r=alexcrichtonbors-13/+28
Here's another go at adding emscripten support. This needs to wait again on new [libc definitions](https://github.com/rust-lang-nursery/libc/pull/122) landing. To get the libc definitions right I had to add support for i686-unknown-linux-musl, which are very similar to emscripten's, which are derived from arm/musl. This branch additionally removes the makefile dependency on the `EMSCRIPTEN` environment variable by not building the unused compiler-rt. Again, this is not sufficient for actually compiling to asmjs since it needs additional LLVM patches. r? @alexcrichton
2016-02-06Add support for i686-unknown-linux-muslBrian Anderson-2/+2
2016-02-06Add the asmjs-unknown-emscripten triple. Add cfgs to libs.Brian Anderson-11/+26
Backtraces, and the compilation of libbacktrace for asmjs, are disabled. This port doesn't use jemalloc so, like pnacl, it disables jemalloc *for all targets* in the configure file. It disables stack protection.
2016-02-06Auto merge of #31417 - alexcrichton:cloexec-all-the-things, r=brsonbors-42/+184
These commits finish up closing out https://github.com/rust-lang/rust/issues/24237 by filling out all locations we create new file descriptors with variants that atomically create the file descriptor and set CLOEXEC where possible. Previous support for doing this in `File::open` was added in #27971 and support for `try_clone` was added in #27980. This commit fills out: * `Socket::new` now passes `SOCK_CLOEXEC` * `Socket::accept` now uses `accept4` * `pipe2` is used instead of `pipe` Unfortunately most of this support is Linux-specific, and most of it is post-2.6.18 (our oldest supported version), so all of the detection here is done dynamically. It looks like OSX does not have equivalent variants for these functions, so there's nothing more we can do there. Support for BSDs can be added over time if they also have these functions. Closes #24237
2016-02-06Auto merge of #31333 - lambda:31273-abort-on-stack-overflow, r=brsonbors-17/+21
Abort on stack overflow instead of re-raising SIGSEGV We use guard pages that cause the process to abort to protect against undefined behavior in the event of stack overflow. We have a handler that catches segfaults, prints out an error message if the segfault was due to a stack overflow, then unregisters itself and returns to allow the signal to be re-raised and kill the process. This caused some confusion, as it was unexpected that safe code would be able to cause a segfault, while it's easy to overflow the stack in safe code. To avoid this confusion, when we detect a segfault in the guard page, abort instead of the previous behavior of re-raising SIGSEGV. To test this, we need to adapt the tests for segfault to actually check the exit status. Doing so revealed that the existing test for segfault behavior was actually invalid; LLVM optimizes the explicit null pointer reference down to an illegal instruction, so the program aborts with SIGILL instead of SIGSEGV and the test didn't actually trigger the signal handler at all. Use a C helper function to get a null pointer that LLVM can't optimize away, so we get our segfault instead. This is a [breaking-change] if anyone is relying on the exact signal raised to kill a process on stack overflow. Closes #31273
2016-02-05Abort on stack overflow instead of re-raising SIGSEGVBrian Campbell-17/+21
We use guard pages that cause the process to abort to protect against undefined behavior in the event of stack overflow. We have a handler that catches segfaults, prints out an error message if the segfault was due to a stack overflow, then unregisters itself and returns to allow the signal to be re-raised and kill the process. This caused some confusion, as it was unexpected that safe code would be able to cause a segfault, while it's easy to overflow the stack in safe code. To avoid this confusion, when we detect a segfault in the guard page, abort instead of the previous behavior of re-raising the SIGSEGV. To test this, we need to adapt the tests for segfault to actually check the exit status. Doing so revealed that the existing test for segfault behavior was actually invalid; LLVM optimizes the explicit null pointer reference down to an illegal instruction, so the program aborts with SIGILL instead of SIGSEGV and the test didn't actually trigger the signal handler at all. Use a C helper function to get a null pointer that LLVM can't optimize away, so we get our segfault instead. This is a [breaking-change] if anyone is relying on the exact signal raised to kill a process on stack overflow. Closes #31273
2016-02-05std: Try to use pipe2 on Linux for pipesAlex Crichton-2/+21
This commit attempts to use the `pipe2` syscall on Linux to atomically set the CLOEXEC flag for pipes created. Unfortunately this was added in 2.6.27 so we have to dynamically determine whether we can use it or not. This commit also updates the `fds-are-cloexec.rs` test to test stdio handles for spawned processes as well.
2016-02-05std: Add support for accept4 on LinuxAlex Crichton-4/+28
This is necessary to atomically accept a socket and set the CLOEXEC flag at the same time. Support only appeared in Linux 2.6.28 so we have to dynamically determine which syscall we're supposed to call in this case.
2016-02-05std: Add a helper for symbols that may not existAlex Crichton-27/+86
Right now we only attempt to call one symbol which my not exist everywhere, __pthread_get_minstack, but this pattern will come up more often as we start to bind newer functionality of systems like Linux. Take a similar strategy as the Windows implementation where we use `dlopen` to lookup whether a symbol exists or not.
2016-02-05std: Atomically set CLOEXEC for sockets if possibleAlex Crichton-0/+23
This commit adds support for creating sockets with the `SOCK_CLOEXEC` flag. Support for this flag was added in Linux 2.6.27, however, and support does not exist on platforms other than Linux. For this reason we still have the same fallback as before but just special case Linux if we can.
2016-02-05std: When duplicating fds, skip extra set_cloexecAlex Crichton-6/+15
Similar to the previous commit, if `F_DUPFD_CLOEXEC` succeeds then there's no need for us to then call `set_cloexec` on platforms other than Linux. The bug mentioned of kernels not actually setting the `CLOEXEC` flag has only been repored on Linux, not elsewhere.
2016-02-05std: Only have extra set_cloexec for files on LinuxAlex Crichton-4/+12
On Linux we have to do this for binary compatibility with 2.6.18, but for other OSes (e.g. OSX/BSDs/etc) they all support this flag so we don't need to pass it.
2016-02-04std: Expose SystemTime accessors on fs::MetadataAlex Crichton-8/+109
These accessors are used to get at the last modification, last access, and creation time of the underlying file. Currently not all platforms provide the creation time, so that currently returns `Option`.
2016-02-04Auto merge of #31360 - pitdicker:fs_tests_cleanup, r=alexcrichtonbors-126/+87
- use `symlink_file` and `symlink_dir` instead of the old `soft_link` - create a junction instead of a directory symlink for testing recursive_rmdir (as it causes the same troubles, but can be created by users without `SeCreateSymbolicLinkPrivilege`) - `remove_dir_all` was unable to remove directory symlinks and junctions - only run tests that create symlinks if we have the right permissions. - rename `Path2` to `Path` - remove the global `#[allow(deprecated)]` and outdated comments - After factoring out `create_junction()` from the test `directory_junctions_are_directories` and removing needlessly complex code, what I was left with was: ``` #[test] #[cfg(windows)] fn directory_junctions_are_directories() { use sys::fs::create_junction; let tmpdir = tmpdir(); let foo = tmpdir.join("foo"); let bar = tmpdir.join("bar"); fs::create_dir(&foo).unwrap(); check!(create_junction(&foo, &bar)); assert!(bar.metadata().unwrap().is_dir()); } ``` It test whether a junction is a directory instead of a reparse point. But it actually test the target of the junction (which is a directory if it exists) instead of the junction itself, which should always be a symlink. So this test is invalid, and I expect it only exists because the author was suprised by it. So I removed it. Some things that do not yet work right: - relative symlinks do not accept forward slashes - the conversion of paths for `create_junction` is hacky - `remove_dir_all` now messes with the internal data of `FileAttr` to be able to remove symlinks. We should add some method like `is_symlink_dir()` to it, so code outside the standard library can see the difference between file and directory symlinks too.
2016-02-04Allow dead code for `symlink_junction()`Paul Dicker-0/+2
2016-02-04Auto merge of #31069 - sfackler:file-try-clone, r=alexcrichtonbors-39/+53
I have it set as stable right now under the rationale that it's extending an existing, stable API to another type in the "obvious" way. r? @alexcrichton cc @reem
2016-02-04Add File::try_cloneSteven Fackler-39/+53
2016-02-03Auto merge of #31078 - nbaksalyar:illumos, r=alexcrichtonbors-25/+132
This pull request adds support for [Illumos](http://illumos.org/)-based operating systems: SmartOS, OpenIndiana, and others. For now it's x86-64 only, as I'm not sure if 32-bit installations are widespread. This PR is based on #28589 by @potatosalad, and also closes #21000, #25845, and #25846. Required changes in libc are already merged: https://github.com/rust-lang-nursery/libc/pull/138 Here's a snapshot required to build a stage0 compiler: https://s3-eu-west-1.amazonaws.com/nbaksalyar/rustc-sunos-snapshot.tar.gz It passes all checks from `make check`. There are some changes I'm not quite sure about, e.g. macro usage in `src/libstd/num/f64.rs` and `DirEntry` structure in `src/libstd/sys/unix/fs.rs`, so any comments on how to rewrite it better would be greatly appreciated. Also, LLVM configure script might need to be patched to build it successfully, or a pre-built libLLVM should be used. Some details can be found here: https://llvm.org/bugs/show_bug.cgi?id=25409 Thanks! r? @brson
2016-02-03Adress commentsPaul Dicker-28/+30
2016-02-03Auto merge of #31056 - kamalmarhubi:std-process-nul-chars, r=alexcrichtonbors-47/+112
This reports an error at the point of calling `Command::spawn()` or one of its equivalents. Fixes #30858 Fixes #30862
2016-02-03std: Properly handle interior NULs in std::processKamal Marhubi-47/+112
This reports an error at the point of calling `Command::spawn()` or one of its equivalents. Fixes https://github.com/rust-lang/rust/issues/30858 Fixes https://github.com/rust-lang/rust/issues/30862
2016-02-03Fix broken auto-mac-ios-opt buildNikita Baksalyar-27/+23
2016-02-02trying again at fixing stackp initializationDave Huseby-3/+18
2016-02-02simplifying get_stackDave Huseby-24/+3
2016-02-02refactoring get_stack to be cleanerDave Huseby-27/+20
2016-02-02unifying name_bytes now that the two blocks are the sameDave Huseby-8/+2
2016-02-02Fixes #31229Dave Huseby-10/+35
2016-02-02Auto merge of #31312 - alexcrichton:no-le-in-powerpc64le, r=alexcrichtonbors-3/+2
Currently the `mipsel-unknown-linux-gnu` target doesn't actually set the `target_arch` value to `mipsel` but it rather uses `mips`. Alternatively the `powerpc64le` target does indeed set the `target_arch` as `powerpc64le`, causing a bit of inconsistency between theset two. As these are just the same instance of one instruction set, let's use `target_endian` to switch between them and only set the `target_arch` as one value. This should cut down on the number of `#[cfg]` annotations necessary and all around be a little more ergonomic.
2016-02-02Enable more fs tests on WindowsPaul Dicker-114/+71