about summary refs log tree commit diff
path: root/src/libstd/sys/unix/stack_overflow.rs
AgeCommit message (Collapse)AuthorLines
2019-11-29Format libstd/sys with rustfmtDavid Tolnay-44/+43
This commit applies rustfmt with rust-lang/rust's default settings to files in src/libstd/sys *that are not involved in any currently open PR* to minimize merge conflicts. THe list of files involved in open PRs was determined by querying GitHub's GraphQL API with this script: https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8 With the list of files from the script in outstanding_files, the relevant commands were: $ find src/libstd/sys -name '*.rs' \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ rg libstd/sys outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of the files. To confirm no funny business: $ git checkout $THIS_COMMIT^ $ git show --pretty= --name-only $THIS_COMMIT \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ git diff $THIS_COMMIT # there should be no difference
2019-05-13Remove bitrig support from rustMarcel Hellwig-3/+0
2019-03-21FreeBSD 10.x is EOL, in FreeBSD 11 and later, ss_sp is actually a void* [1]MikaelUrankar-2/+2
dragonflybsd still uses c_char [2] [1] https://svnweb.freebsd.org/base/releng/11.2/sys/sys/signal.h?revision=334459&view=markup#l438 [2] https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/sys/sys/signal.h#L339
2019-02-28Fix some imports and pathsTaiki Endo-1/+0
2019-02-28libstd => 2018Taiki Endo-6/+6
2018-12-25Remove licensesMark Rousskov-10/+0
2018-01-31Use a range to identify SIGSEGV in stack guardsJosh Stone-7/+2
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.
2017-03-12Update usages of 'OSX' (and other old names) to 'macOS'.Corey Farwell-1/+1
As of last year with version 'Sierra', the Mac operating system is now called 'macOS'.
2016-04-04Fix stack overflow detection on FreeBSDAlan Somers-1/+1
src/libstd/sys/unix/thread.rs Implement several stack-related functions on FreeBSD src/libstd/sys/unix/stack_overflow.rs Fix a comment
2016-02-22Fix broken Solaris buildNikita Baksalyar-1/+2
2016-02-18Remove alternate stack with sigaltstack before unmapping it.Tomasz Miąsko-5/+24
Also reuse existing signal stack if already set, this is especially useful when working with sanitizers that configure alternate stack themselves.
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-03Auto merge of #31078 - nbaksalyar:illumos, r=alexcrichtonbors-0/+2
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-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-02Fixes #31229Dave Huseby-9/+34
2016-01-31Rename sunos to solarisNikita Baksalyar-2/+2
2016-01-31Add Illumos supportNikita Baksalyar-0/+2
2016-01-26Fix warnings during testsAlex Crichton-0/+1
The deny(warnings) attribute is now enabled for tests so we need to weed out these warnings as well.
2016-01-12make siginfo_si_addr() returns a usizeSébastien Marie-5/+5
`siginfo_si_addr()` function is used once, and the returned value is casted to `usize`. So make the function returns a `usize`. it simplifies OpenBSD case, where the return type wouldn't be a `*mut libc::c_void` but a `*mut libc::c_char`.
2015-12-29Fix warnings when compiling stdlib with --testFlorian Hahn-4/+7
2015-11-09std: Migrate to the new libcAlex Crichton-7/+23
* 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-11-01Use guard-pages also on DragonFly/FreeBSD.Michael Neumann-0/+4
Only tested on DragonFly.
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-11std: Internalize almost all of `std::rt`Alex Crichton-1/+1
This commit does some refactoring to make almost all of the `std::rt` private. Specifically, the following items are no longer part of its API: * DEFAULT_ERROR_CODE * backtrace * unwind * args * at_exit * cleanup * heap (this is just alloc::heap) * min_stack * util The module is now tagged as `#[doc(hidden)]` as the only purpose it's serve is an entry point for the `panic!` macro via the `begin_unwind` and `begin_unwind_fmt` reexports.
2015-09-04Add ptr import (fixup #28187)Manish Goregaokar-1/+1
2015-09-03Use `null()`/`null_mut()` instead of `0 as *const T`/`0 as *mut T`Vadim Petrochenkov-2/+2
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-10Remove morestack supportAlex Crichton-39/+33
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-03syntax: Implement #![no_core]Alex Crichton-1/+3
This commit is an implementation of [RFC 1184][rfc] which tweaks the behavior of the `#![no_std]` attribute and adds a new `#![no_core]` attribute. The `#![no_std]` attribute now injects `extern crate core` at the top of the crate as well as the libcore prelude into all modules (in the same manner as the standard library's prelude). The `#![no_core]` attribute disables both std and core injection. [rfc]: https://github.com/rust-lang/rfcs/pull/1184
2015-07-01Add netbsd amd64 supportAlex Newman-0/+2
2015-06-22sys/unix: Consolidate signal-handling FFI bindingsGeoffrey Thomas-136/+5
Both c.rs and stack_overflow.rs had bindings of libc's signal-handling routines. It looks like the split dated from #16388, when (what is now) c.rs was in libnative but not libgreen. Nobody is currently using the c.rs bindings, but they're a bit more accurate in some places. Move everything to c.rs (since I'll need signal handling in process.rs, and we should avoid duplication), clean up the bindings, and manually double-check everything against the relevant system headers (fixing a few things in the process).
2015-04-27std: Don't assume thread::current() works on panicAlex Crichton-1/+1
Inspecting the current thread's info may not always work due to the TLS value having been destroyed (or is actively being destroyed). The code for printing a panic message assumed, however, that it could acquire the thread's name through this method. Instead this commit propagates the `Option` outwards to allow the `std::panicking` module to handle the case where the current thread isn't present. While it solves the immediate issue of #24313, there is still another underlying issue of panicking destructors in thread locals will abort the process. Closes #24313
2015-03-26Mass rename uint/int to usize/isizeAlex Crichton-3/+3
Now that support has been removed, all lingering use cases are renamed.
2015-03-18Fix private module loophole in the 'private type in public item' checkNick Cameron-3/+3
2015-03-12std: Remove #[allow] directives in sys modulesAlex Crichton-1/+0
These were suppressing lots of interesting warnings! Turns out there was also quite a bit of dead code.
2015-02-11fixing PR review commentsDave Huseby-4/+1
2015-02-11fixing trailing whitespace errorsDave Huseby-1/+1
2015-02-11bitrig integrationDave Huseby-4/+11
2015-02-01openbsd supportSébastien Marie-3/+20
2015-01-30Remove all `i` suffixesTobias Bucher-3/+3
2015-01-17Register new snapshots.Eduard Burtescu-4/+2
2015-01-11powerpc: Fixup more stack workRicho Healey-0/+1
2015-01-08Rename `target_word_size` to `target_pointer_width`Nick Cameron-2/+4
Closes #20421 [breaking-change]
2015-01-03Initial version of AArch64 support.Akos Kiss-1/+2
Adds AArch64 knowledge to: * configure, * make files, * sources, * tests, and * documentation.
2015-01-02Fallout - change array syntax to use `;`Nick Cameron-2/+2
2014-12-26Require types to opt-in SyncFlavio Percoco-1/+1
2014-12-18Fallout from new thread APIAaron Turon-23/+9