altstack: Don't use 0 pointer literals In a number of places the altstack module uses a literal '0' for pointer values. That's correct C, but doesn't make it obvious on a quick read whether values are integers or pointers. This patch changes those cases to use the NULL define instead. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
altstack: Restore alternate signal stack state altstack relies on catching a SIGSEGV caused when overrunning the stack. This means that the SEGV handler itself can't use the already overflowed stack, and so we use sigaltstack() to assign the signal handler a different stack. On completion, altstack() clears the alternate signal stack. However, it's possible that the calling program could be using sigaltstack() for its own reasons, so it's more correct to restore the sigaltstack() state to that from the beginning of the altstack() call. This patch implements this behaviour. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
altstack: Consolidate thread-local variables altstack uses a number of __thread variables to track internal state. This allows altstack to be thread-safe, although it's still not re-entrant. This patch gathers all these variables into a single per-thread state structure. This makes it easy to see at a glance what the whole of the required state is, and thereby easier to reason about correctness of changes to the implementation. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
altstack: Declare memory clobbers altstack includes a couple of inline asm blocks with x86 push and pop instructions. These instructions will access memory (the stack), but that's not declared in inline asm statement. We seem to be getting away with it, but in theory that could allow the compiler to re-order accesses to local variables across the asm block. Since those blocks change the location of the stack, that could be very bad. Adding a "memory" clobber should prevent this (effectively making the asm blocks a compiler memory barrier). Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
altstack: Increase signal stack size At present the altstack module uses a stack of size MINSIGSTKSZ for its SIGSEGV handler. Although MINSIGSTKSZ is defined to be large enough to execute a signal handler, it doesn't guarantee that you can do anything very much within it. With certain libc versions, MINSIGSTKSZ is not enough to execute the longjmp() used in altstack. Specfically, with Ubuntu 12.04 (the default install for Travis containers), the first time longjmp() is executed the symbol must be resolved by the dynamic linker in a process which overruns the MINSIGSTKSZ sized stack. That then corrupts local variables in altstack() itself causing a number of subsequent failures. This patch addresses the problem by changing from MINSIGSTKSZ to SIGSTKSZ which is supposed to cover "the usual requirements for an alternate signal stack". Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
altstack: stack alignment and accounting tweaks * add altstack_remn, returns amount of stack remaining * increase mapping by 1 page to handle abutment case * capture rsp earlier * align stack to 16 bytes Signed-off-by: Dan Good <dan@dancancode.com>
altstack: New module altstack - run a function with a dedicated stack, and then release the memory Signed-off-by: Dan Good <dan@dancancode.com>