Re: Signal Handling
Jens.Toerring_at_physik.fu-berlin.de
Date: 01/31/05
- Next message: infobahn: "Re: Why pointers can only be subtracted ?"
- Previous message: Michael Wojcik: "Re: pointer to array of const objects"
- In reply to: Sontu: "Signal Handling"
- Next in thread: CBFalconer: "Re: Signal Handling"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 31 Jan 2005 17:12:28 GMT
Sontu <abhaywit@gmail.com> wrote:
> Consider the following code:
> #include<signal.h>
> #include<stdio.h>
> #include<sys/mman.h>
Non-standard header.
> void handler(int sig)
> {
> printf("abhay: caught SIGSEGV\n\n");
> }
You better don't use non-reentrant functions in signal handlers.
In principle not much more than setting a variable of type
sig_atomic_t is guaranteed to work in a signal handler.
> void func(char *buffer)
> {
> unsigned int start=0;
> //to make the starting address in mprotect as page aligned
> asm("andl $-4096, %esp");
> asm("movl %%esp, %0":"=r"(start));
No we get into completely platform dependent stuff. Don't expect
comments here in clc. Take that to a group that deals with the
platform you're using.
> //raise(SIGSEGV);
> printf("Mprotect worked:
> %d\n\n",mprotect((void*)start,4096,PROT_READ));
Non-standard function.
> buffer[3]='c';
> printf("Mprotect worked:
> %d\n\n",mprotect((void*)start,4096,PROT_WRITE|PROT_READ|PROT_EXEC));
> }
> int main(void)
> {
> char buffer[10];
> if( signal(SIGSEGV, handler)== SIG_ERR )
> printf("problem installing new signal handler\n\n");
> func(buffer);
> printf("into main\n\n");
> return 0;
> }
> My program makes the previous frame as write protected, thus when i am
It may on the platform you are using, but that's nothing related to
the C language, which hasn't frames nor functions or to make them
write protected. Since you seem to be using Linux better take that
question to comp.os.linux.development.apps.
<OT>
Actually, when you get a real SIGSEGV signal, i.e. not one that you
faked using raise(), and don't exit() from the signal handler, flow
of control is passed back to instruction that led to the signal
getting raised. Since nothing has changed to remove the reason for
the signal it gets raised again immediately and you end up in an
infinite loop.
</OT>
Regards, Jens
-- \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de \__________________________ http://www.toerring.de
- Next message: infobahn: "Re: Why pointers can only be subtracted ?"
- Previous message: Michael Wojcik: "Re: pointer to array of const objects"
- In reply to: Sontu: "Signal Handling"
- Next in thread: CBFalconer: "Re: Signal Handling"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|