summary refs log tree commit diff
path: root/src/libstd/sys/unix/thread.rs
AgeCommit message (Collapse)AuthorLines
2018-01-31Use a range to identify SIGSEGV in stack guardsJosh Stone-45/+70
Previously, the `guard::init()` and `guard::current()` functions were returning a `usize` address representing the top of the stack guard, respectively for the main thread and for spawned threads. The `SIGSEGV` handler on `unix` targets checked if a fault was within one page below that address, if so reporting it as a stack overflow. Now `unix` targets report a `Range<usize>` representing the guard memory, so it can cover arbitrary guard sizes. Non-`unix` targets which always return `None` for guards now do so with `Option<!>`, so they don't pay any overhead. For `linux-gnu` in particular, the previous guard upper-bound was `stackaddr + guardsize`, as the protected memory was *inside* the stack. This was a glibc bug, and starting from 2.27 they are moving the guard *past* the end of the stack. However, there's no simple way for us to know where the guard page actually lies, so now we declare it as the whole range of `stackaddr ± guardsize`, and any fault therein will be called a stack overflow. This fixes #47863.
2018-01-18in which the unused-parens lint comes to cover function and method argsZack M. Davis-2/+2
Resolves #46137.
2017-12-09Use Try syntax for Option in place of macros or matchMatt Brubeck-4/+1
2017-11-09std: Avoid use of `libc` in portable modulesAlex Crichton-1/+1
This commit removes usage of the `libc` crate in "portable" modules like those at the top level and `sys_common`. Instead common types like `*mut u8` or `u32` are used instead of `*mut c_void` or `c_int` as well as switching to platform-specific functions like `sys::strlen` instead of `libc::strlen`.
2017-10-20Fix some tests for linux gnux32Marco A L Barbosa-1/+1
2017-09-13Move default stack min size to thread implementationsTobias Schaffner-0/+5
The default min stack size value is smaller on l4re and therefore this value has to be different depending on the platform.
2017-09-08Move the stack size value for L4Re to the min_stack_size functionSebastian Humenda-4/+0
2017-09-08Add modifications needed for L4re in libstdTobias Schaffner-2/+8
This commit adds the needed modifications to compile the std crate for the L4 Runtime environment (L4Re). A target for the L4Re was introduced in commit: c151220a84e40b65e45308cc0f3bbea4466d3acf In many aspects implementations for linux also apply for the L4Re microkernel. Two uncommon characteristics had to be resolved: * L4Re has no network funktionality * L4Re has a maximum stacksize of 1Mb for threads Co-authored-by: Sebastian Humenda <sebastian.humenda@tu-dresden.de>
2017-08-26std: Handle OS errors when joining threadsAlex Crichton-1/+2
Also add to the documentation that the `join` method can panic. cc #34971 cc #43539
2017-07-07Skip the main thread's manual stack guard on LinuxJosh Stone-15/+29
Linux doesn't allocate the whole stack right away, and the kernel has its own stack-guard mechanism to fault when growing too close to an existing mapping. If we map our own guard, then the kernel starts enforcing a rather large gap above that, rendering much of the possible stack space useless. Instead, we'll just note where we expect rlimit to start faulting, so our handler can report "stack overflow", and trust that the kernel's own stack guard will work. Fixes #43052.
2016-10-22Fix tidy warningRaph Levien-1/+1
Prefer FIXME to TODO
2016-10-22Add Fuchsia supportRaph Levien-0/+4
Adds support for the x86_64-unknown-fuchsia target, which covers the Fuchsia operating system.
2016-10-08Use less `size_t` casts in libstd since it's now defined as `usize`Tobias Bucher-17/+12
2016-09-30Call emcc with ERROR_ON_UNDEFINED_SYMBOLSBrian Anderson-2/+16
2016-09-26Haiku: Use common thread set_name stubAlexander von Gluck IV-7/+5
2016-09-25Add support for the Haiku operating system on x86 and x86_64 machinesNiels Sascha Reedijk-0/+5
* Hand rebased from Niels original work on 1.9.0
2016-08-24Use `#[prelude_import]` in `libstd`.Jeffrey Seyfried-4/+0
2016-08-10[emscripten] Disable code paths that don't work on emscriptenJan-Erik Rediger-4/+3
2016-07-11std: Fix `Thread::set_name()` for newlib and solarisJosh Stone-1/+0
The `use ffi::CStr` in `unix/thread.rs` was previously guarded, but now all platforms need it for `Thread::set_name()`. Newlib and Solaris do nothing here, as they have no way to set a thread name, but they still define the same method signature.
2016-06-21Fix overflow error in thread::sleepGuillaume Gomez-6/+15
2016-04-06Remove accidental commentAlan Somers-1/+0
2016-04-05Reduce code duplication in thread.rsAlan Somers-42/+18
2016-04-04Fix stack overflow detection on FreeBSDAlan Somers-1/+44
src/libstd/sys/unix/thread.rs Implement several stack-related functions on FreeBSD src/libstd/sys/unix/stack_overflow.rs Fix a comment
2016-03-25Fix unsound behaviour with null characters in thread names (issue #32475)David Henningsson-16/+11
Previously, the thread name (&str) was converted to a CString in the new thread, but outside unwind::try, causing a panic to continue into FFI. This patch changes that behaviour, so that the panic instead happens in the parent thread (where panic infrastructure is properly set up), not the new thread. This could potentially be a breaking change for architectures who don't support thread names. Signed-off-by: David Henningsson <diwic@ubuntu.com>
2016-02-06Auto merge of #30629 - brson:emscripten-upstream, r=alexcrichtonbors-3/+5
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-1/+3
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-05std: Add a helper for symbols that may not existAlex Crichton-27/+2
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-01-31Fix unresolved name in libstd/sys/unix/threadNikita Baksalyar-1/+1
2016-01-31Rename sunos to solarisNikita Baksalyar-6/+6
2016-01-31Add Illumos supportNikita Baksalyar-7/+17
2016-01-28std: Fix rumprun buildAlex Crichton-4/+9
Looks like the rumprun build has bitrotted over time, so this includes some libc fixes and some various libstd fixes which gets it back to bootstrapping.
2016-01-26Fix warnings during testsAlex Crichton-11/+8
The deny(warnings) attribute is now enabled for tests so we need to weed out these warnings as well.
2015-12-04Add JoinHandleExt to get the pthread_t on unix platformsPeter Atashian-0/+8
Signed-off-by: Peter Atashian <retep998@gmail.com>
2015-11-09std: Migrate to the new libcAlex Crichton-105/+38
* Delete `sys::unix::{c, sync}` as these are now all folded into libc itself * Update all references to use `libc` as a result. * Update all references to the new flat namespace. * Moves all windows bindings into sys::c
2015-10-29Auto merge of #29289 - DiamondLovesYou:pnacl-std-crates, r=alexcrichtonbors-0/+5
2015-10-28Port the standard crates to PNaCl/NaCl.Richard Diamond-0/+5
2015-10-25std: Stabilize library APIs for 1.5Alex Crichton-0/+1
This commit stabilizes and deprecates library APIs whose FCP has closed in the last cycle, specifically: Stabilized APIs: * `fs::canonicalize` * `Path::{metadata, symlink_metadata, canonicalize, read_link, read_dir, exists, is_file, is_dir}` - all moved to inherent methods from the `PathExt` trait. * `Formatter::fill` * `Formatter::width` * `Formatter::precision` * `Formatter::sign_plus` * `Formatter::sign_minus` * `Formatter::alternate` * `Formatter::sign_aware_zero_pad` * `string::ParseError` * `Utf8Error::valid_up_to` * `Iterator::{cmp, partial_cmp, eq, ne, lt, le, gt, ge}` * `<[T]>::split_{first,last}{,_mut}` * `Condvar::wait_timeout` - note that `wait_timeout_ms` is not yet deprecated but will be once 1.5 is released. * `str::{R,}MatchIndices` * `str::{r,}match_indices` * `char::from_u32_unchecked` * `VecDeque::insert` * `VecDeque::shrink_to_fit` * `VecDeque::as_slices` * `VecDeque::as_mut_slices` * `VecDeque::swap_remove_front` - (renamed from `swap_front_remove`) * `VecDeque::swap_remove_back` - (renamed from `swap_back_remove`) * `Vec::resize` * `str::slice_mut_unchecked` * `FileTypeExt` * `FileTypeExt::{is_block_device, is_char_device, is_fifo, is_socket}` * `BinaryHeap::from` - `from_vec` deprecated in favor of this * `BinaryHeap::into_vec` - plus a `Into` impl * `BinaryHeap::into_sorted_vec` Deprecated APIs * `slice::ref_slice` * `slice::mut_ref_slice` * `iter::{range_inclusive, RangeInclusive}` * `std::dynamic_lib` Closes #27706 Closes #27725 cc #27726 (align not stabilized yet) Closes #27734 Closes #27737 Closes #27742 Closes #27743 Closes #27772 Closes #27774 Closes #27777 Closes #27781 cc #27788 (a few remaining methods though) Closes #27790 Closes #27793 Closes #27796 Closes #27810 cc #28147 (not all parts stabilized)
2015-09-26Add support for the rumprun unikernelSebastian Wicki-2/+2
For most parts, rumprun currently looks like NetBSD, as they share the same libc and drivers. However, being a unikernel, rumprun does not support process management, signals or virtual memory, so related functions might fail at runtime. Stack guards are disabled exactly for this reason. Code for rumprun is always cross-compiled, it uses always static linking and needs a custom linker.
2015-09-21Various fixes for NetBSD/amd64Sebastian Wicki-7/+24
2015-09-08some more clippy-based improvementsAndre Bogus-1/+1
2015-09-03Use `null()`/`null_mut()` instead of `0 as *const T`/`0 as *mut T`Vadim Petrochenkov-1/+1
2015-08-11Register new snapshotsAlex Crichton-3/+0
* Lots of core prelude imports removed * Makefile support for MSVC env vars and Rust crates removed * Makefile support for morestack removed
2015-08-11Auto merge of #26818 - sfackler:duration-stabilization, r=aturonbors-2/+2
This commit stabilizes the `std::time` module and the `Duration` type. `Duration::span` remains unstable, and the `Display` implementation for `Duration` has been removed as it is still being reworked and all trait implementations for stable types are de facto stable. This is a [breaking-change] to those using `Duration`'s `Display` implementation. I'm opening this PR as a platform for discussion - there may be some method renaming to do as part of the stabilization process.
2015-08-10Stabilize the Duration APISteven Fackler-2/+2
This commit stabilizes the `std::time` module and the `Duration` type. `Duration::span` remains unstable, and the `Display` implementation for `Duration` has been removed as it is still being reworked and all trait implementations for stable types are de facto stable. This is a [breaking-change] to those using `Duration`'s `Display` implementation.
2015-08-10Remove morestack supportAlex Crichton-4/+1
This commit removes all morestack support from the compiler which entails: * Segmented stacks are no longer emitted in codegen. * We no longer build or distribute libmorestack.a * The `stack_exhausted` lang item is no longer required The only current use of the segmented stack support in LLVM is to detect stack overflow. This is no longer really required, however, because we already have guard pages for all threads and registered signal handlers watching for a segfault on those pages (to print out a stack overflow message). Additionally, major platforms (aka Windows) already don't use morestack. This means that Rust is by default less likely to catch stack overflows because if a function takes up more than one page of stack space it won't hit the guard page. This is what the purpose of morestack was (to catch this case), but it's better served with stack probes which have more cross platform support and no runtime support necessary. Until LLVM supports this for all platform it looks like morestack isn't really buying us much. cc #16012 (still need stack probes) Closes #26458 (a drive-by fix to help diagnostics on stack overflow)
2015-08-04syntax: Don't assume `std` exists for testsAlex Crichton-0/+1
This commit removes the injection of `std::env::args()` from `--test` expanded code, relying on the test runner itself to call this funciton. This is more hygienic because we can't assume that `std` exists at the top layer all the time, and it meaks the injected test module entirely self contained.
2015-07-21std: Be resilient to failure in pthread_getattr_npAlex Crichton-38/+50
This can fail on linux for various reasons, such as the /proc filesystem not being mounted. There are already many cases where we can't set up stack guards, so just don't worry about this case and communicate that no guard was enabled. I've confirmed that this allows the compiler to run in a chroot without /proc mounted. Closes #22642
2015-07-01Add netbsd amd64 supportAlex Newman-1/+5
2015-05-27Use `const fn` to abstract away the contents of UnsafeCell & friends.Eduard Burtescu-2/+2