This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
segfault using _Unwind_ForcedUnwind()
- From: "Oliver Kowalke" <oliver dot kowalke at gmx dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 30 Mar 2012 15:40:43 +0200
- Subject: segfault using _Unwind_ForcedUnwind()
I get a segfault with following app - could you verify this?
platform: i386, linux
gcc -v:
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6.1/lto-wrapper
Ziel: i686-linux-gnu
Konfiguriert mit: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.1-9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread-Modell: posix
gcc-Version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)
/lib/i386-linux-gnu/libc-2.13.so
GNU C Library (Ubuntu EGLIBC 2.13-20ubuntu5.1) stable release version 2.13, by Roland McGrath et al.
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.6.1.
Compiled on a Linux 3.0.17 system on 2012-03-07.
Available extensions:
crypt add-on version 2.1 by Michael Glad and others
GNU Libidn by Simon Josefsson
Native POSIX Threads Library by Ulrich Drepper et al
BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.debian.org/Bugs/>.
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <ucontext.h>
#include <unwind.h>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
static int counter = 0;
static ucontext_t ucf, ucm;
struct X
{
X()
{ std::cout << "X()" << std::endl; }
~X()
{ std::cout << "~X()" << std::endl; }
};
_Unwind_Reason_Code stop(
int version,
_Unwind_Action actions,
_Unwind_Exception_Class exc_class,
_Unwind_Exception *exc,
_Unwind_Context *context,
void * param) {
// std::cout << "counter == " << ++counter << std::endl;
if ( actions & _UA_END_OF_STACK) {
std::cout << "end of stack, jump back" << std::endl;
_Unwind_DeleteException( exc);
if ( ::swapcontext( & ucf, & ucm) == -1)
::abort();
}
return _URC_NO_REASON;
}
void force_unwind()
{
_Unwind_Exception * exc = new _Unwind_Exception;
std::memset( exc, 0, sizeof( * exc) );
_Unwind_ForcedUnwind( exc, stop, 0);
}
void f( int i) {
if ( i > 0) {
X x;
f( --i);
} else {
force_unwind();
std::cout << "fini" << std::endl;
}
}
int main( int argc, char * argv[]) {
std::vector< char > buffer(16384, '\0');
void * fn_stack = & buffer[0];
fprintf(stdout,"buffer : %p\n", fn_stack);
fn_stack = ( char * )( ( ( ( ( uintptr_t) fn_stack) - 16) >> 4) << 4);
fprintf(stdout,"aligned : %p\n", fn_stack);
if ( ::getcontext( & ucf) == -1)
::abort();
ucf.uc_stack.ss_sp = fn_stack;
ucf.uc_stack.ss_size = buffer.size();
::makecontext( & ucf, (void(*)())( f), 1, 5);
if ( ::swapcontext( & ucm, & ucf) == -1)
::abort();
std::cout << "done" << std::endl;
return 0;
}
--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de