On Mon, Oct 20, 2003 at 11:07:40PM +1000, Ken Foskey wrote:
>
> If anyone is on a very fresh version of K2.6 with extra patches can you
> please run this code and see if it crashes. It fails on all K2.6 up to
> Test6 release. I would be interested to hear of any success.
I don't think it's related to the kernel version.
> There should be no segfault and another signal caught.
>
> If there is any obvious blunder with this code let me know. Looks
> pretty right to me though I don't use signals much at all.
The problem is that you never return from the signal handler. Now you're
getting a SIGSEGV during execution of the SIGSEGV handler and the signal is
probably forced to SIG_DFL, otherwise you could get an infinite signal
loop. Return from the handler instead of a longjmp and you should be ok.
/Martin
> #include <stdio.h>
> #include <signal.h>
> #include <setjmp.h>
>
> /*************************************************************************
> |* Typdeclarations for memory access test functions
> *************************************************************************/
> typedef int (*TestFunc)( void* );
>
> /*************************************************************************
> *************************************************************************/
> static jmp_buf check_env;
> static int bSignal;
> static void SignalHdl( int sig )
> {
> bSignal = 1;
>
> fprintf( stderr, "Signal %d caught\n", sig );
> longjmp( check_env, sig );
> }
>
> /*************************************************************************
> *************************************************************************/
> void check( TestFunc func, void* p )
> {
> int result;
>
> fprintf( stderr, "Setting Jump\n" );
> if ( !setjmp( check_env ) )
> {
> signal( SIGSEGV, SignalHdl );
> signal( SIGBUS, SignalHdl );
> fprintf( stderr, "Running \n" );
> result = func( p );
> fprintf( stderr, "Finished \n" );
> signal( SIGSEGV, SIG_DFL );
> signal( SIGBUS, SIG_DFL );
> }
> fprintf( stderr, "After jump \n" );
> }
>
> /*************************************************************************
> *************************************************************************/
> static int GetAtAddress( void* p )
> {
> return *((char*)p);
> }
>
> /*************************************************************************
> *************************************************************************/
> static int SetAtAddress( void* p )
> {
> return *((char*)p) = 0;
> }
>
> /*************************************************************************
> *************************************************************************/
> void CheckGetAccess( void* p )
> {
> check( (TestFunc)GetAtAddress, p );
> }
> /*************************************************************************
> *************************************************************************/
> void CheckSetAccess( void* p )
> {
> check( (TestFunc)SetAtAddress, p );
> }
>
> /*************************************************************************
> *************************************************************************/
> int main( int argc, char* argv[] )
> {
> {
> char* p = NULL;
> fprintf( stderr, "Getting from NULL\n" );
> CheckGetAccess( p );
> fprintf( stderr, "Setting to NULL\n" );
> CheckSetAccess( p );
> fprintf( stderr, "After Setting to NULL\n" );
> }
>
> exit( 0 );
> }
--
"If there are no stupid questions, then what kind of questions do stupid
people ask? Do they get smart just in time to ask questions?"
- Scott Adams
--
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug