about summary refs log tree commit diff
path: root/src/libstd
AgeCommit message (Collapse)AuthorLines
2016-02-11Auto merge of #31083 - SimonSapin:set_port, r=alexcrichtonbors-10/+120
As demonstrated in the `resolve_socket_addr` change, this is less awkward than re-creating a new address from the other parts. If this is to be accepted, pleas open a tracking issue (I can’t set the appropriate tags) and I’ll update the PR with the tracking issue number.
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-11Add SocketAddrV6::set_flowinfo and set_scope_idSimon Sapin-0/+28
2016-02-11Add `SocketAddr{,V4,V6}::set_ip`.Simon Sapin-3/+52
2016-02-11Add `SocketAddr{,V4,V6}::set_port`.Simon Sapin-10/+43
As demonstrated in the `resolve_socket_addr` change, this is less awkward than re-creating a new address from the other parts.
2016-02-11Auto merge of #31357 - rthomas:hashers, r=alexcrichtonbors-0/+14
add a public hasher function for HashSet and HashMap
2016-02-11Add a public hasher function for HashSet and HashMapRyan Thomas-0/+14
2016-02-10mod.rs: fix typoScott Whittaker-1/+1
"destructors" was misspelled.
2016-02-10Auto merge of #31409 - alexcrichton:command-exec, r=aturonbors-562/+664
These commits are an implementation of https://github.com/rust-lang/rfcs/pull/1359 which is tracked via https://github.com/rust-lang/rust/issues/31398. The `before_exec` implementation fit easily with the current process spawning framework we have, but unfortunately the `exec` implementation required a bit of a larger refactoring. The stdio handles were all largely managed as implementation details of `std::process` and the `exec` function lived in `std::sys`, so the two didn't have access to one another. I took this as a sign that a deeper refactoring was necessary, and I personally feel that the end result is cleaner for both Windows and Unix. The commits should be separated nicely for reviewing (or all at once if you're feeling ambitious), but the changes made here were: * The process spawning on Unix was refactored in to a pre-exec and post-exec function. The post-exec function isn't allowed to do any allocations of any form, and management of transmitting errors back to the parent is managed by the pre-exec function (as it's the one that actually forks). * Some management of the exit status was pushed into platform-specific modules. On Unix we must cache the return value of `wait` as the pid is consumed after we wait on it, but on Windows we can just keep querying the system because the handle stays valid. * The `Stdio::None` variant was renamed to `Stdio::Null` to better reflect what it's doing. * The global lock on `CreateProcess` is now correctly positioned to avoid unintended inheritance of pipe handles that other threads are sending to their child processes. After a more careful reading of the article referenced the race is not in `CreateProcess` itself, but rather the property that handles are unintentionally shared. * All stdio management now happens in platform-specific modules. This provides a cleaner implementation/interpretation for `FromFraw{Fd,Handle}` for each platform as well as a cleaner transition from a configuration to what-to-do once we actually need to do the spawn. With these refactorings in place, implementing `before_exec` and `exec` ended up both being pretty trivial! (each in their own commit)
2016-02-11doc: concat_idents! macro: more on its limitations.NODA, Kai-3/+6
Signed-off-by: NODA, Kai <nodakai@gmail.com>
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-367/+440
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-18/+15
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-69/+30
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-4/+53
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-168/+166
* 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-10Auto merge of #31438 - aturon:stab-ip-addr, r=alexcrichtonbors-22/+8
After [considerable pushback](https://github.com/rust-lang/rfcs/issues/1451), it's clear that there is a community consensus around providing `IpAddr` in the standard library, together with other APIs using it. This commit reverts from deprecated status directly to stable. The deprecation landed in 1.6, which has already been released, so the stabilization is marked for 1.7 (currently in beta; will require a backport). r? @alexcrichton
2016-02-09Rollup merge of #31520 - steveklabnik:doc_num, r=alexcrichtonSteve Klabnik-3/+3
This commit does two things: * Re-works the module-level documentation. * Cleaning up wording and adding links to where error types are used. Part of #29364
2016-02-09Rollup merge of #31516 - steveklabnik:doc_tuples, r=brsonSteve Klabnik-27/+71
Fixes #29339
2016-02-09Rollup merge of #31514 - cgar:spelling, r=alexcrichtonSteve Klabnik-3/+3
2016-02-09make note of arity and 32-length restrictionSteve Klabnik-0/+6
2016-02-09Properly document tuplesSteve Klabnik-27/+65
Fixes #29339
2016-02-09Some docs for std::numSteve Klabnik-3/+3
This commit does two things: * Re-works the module-level documentation. * Cleaning up wording and adding links to where error types are used. Part of #29364
2016-02-09Minor spelling fixesCarlos E. Garcia-3/+3
2016-02-09mod.rs: fix typoScott Whittaker-1/+1
"particularly" was misspelled.
2016-02-09Revert deprecation of IpAddr, stabilizing for 1.7Aaron Turon-22/+8
After [considerable pushback](https://github.com/rust-lang/rfcs/issues/1451), it's clear that there is a community consensus around providing `IpAddr` in the standard library, together with other APIs using it. This commit reverts from deprecated status directly to stable. The deprecation landed in 1.6, which has already been released, so the stabilization is marked for 1.7 (currently in beta; will require a backport).
2016-02-09Auto merge of #31493 - mechaxl:master, r=steveklabnikbors-1/+1
This pull request fixes a minor typo in the prelude documentation. r? @steveklabnik
2016-02-08Fixing typo in prelude documentationKenneth Koski-1/+1
2016-02-08std: `_lock` -> `_guard` in Mutex exampleBenjamin Herr-1/+1
The comment in the next line was already talking about `_guard`, and the scope guard a couple lines further down is also called `guard`, so I assume that was just a typo.
2016-02-08Auto merge of #31468 - pitdicker:fs_tests_cleanup, r=alexcrichtonbors-2/+56
See #29412
2016-02-07Ignore if we can't create a symlink in this testPaul Dicker-1/+1
2016-02-07Don't let `remove_dir_all` recursively remove a symlinkPaul Dicker-2/+56
See #29412
2016-02-07Auto merge of #31440 - reem:rwlock-map-fix, r=alexcrichtonbors-4/+6
Also update the instability reason to include a note about a possible bad interaction with condition variables on systems that allow waiting on a RwLock guard.
2016-02-06Auto merge of #30629 - brson:emscripten-upstream, r=alexcrichtonbors-16/+63
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-14/+61
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 #31428 - reem:remove-mutexguard-map, r=alexcrichtonbors-60/+1
It could return in the future if it returned a different guard type, which could not be used with Condvar, otherwise it is unsafe as another thread can invalidate an "inner" reference during a Condvar::wait. cc #27746
2016-02-06Auto merge of #31427 - reem:more-debug-mutex, r=sfacklerbors-1/+1
There is no reason to require T: 'static; the bound appears to be a historical artifact.
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-05Fix RwLock*Guard::map to not allow escaping a reference to the data.Jonathan Reem-4/+6
Also update the instability reason to include a note about a possible bad interaction with condition variables on systems that allow waiting on a RwLock guard.
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.