On Fri, 2 Oct 1998, Glynn Clements wrote:
> I don't know if there's an official way, but the address appears to be
> available in the eax register, and also at ebp+56. I think that its
> presence at ebp+56 may be deliberate (from setup_frame(), in
> arch/i386/kernel/signal.c), while its presence in eax may be
> accidental.
With -fomit-frame-pointer, address of course is not at ebp+.. any more
:-). Small investigation showed that the thing that is in stack "after"
int signum in "struct sigcontext" from asm/sigcontext.h. eax and eip from
this structure seems to have poiners I was asking about.
I just wonder, why it is not said in manpage, that _real_ prototype of
signal handler is void (*handler)(int, struct sigcontext)? Just because it
is not portable across platforms?
Karlis
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <asm/sigcontext.h>
void handler(int signum, struct sigcontext sc)
{
printf("gs=0x%04x\n", sc.gs);
printf("__gsh=0x%04x\n", sc.__gsh);
printf("fs=0x%04x\n", sc.fs);
printf("__fsh=0x%04x\n", sc.__fsh);
printf("es=0x%04x\n", sc.es);
printf("__esh=0x%04x\n", sc.__esh);
printf("ds=0x%04x\n", sc.ds);
printf("__dsh2=0x%04x\n", sc.__dsh);
printf("edi=0x%08lx\n", sc.edi);
printf("esi=0x%08lx\n", sc.esi);
printf("ebp=0x%08lx\n", sc.ebp);
printf("esp=0x%08lx\n", sc.esp);
printf("ebx=0x%08lx\n", sc.ebx);
printf("edx=0x%08lx\n", sc.edx);
printf("ecx=0x%08lx\n", sc.ecx);
printf("eax=0x%08lx\n", sc.eax);
printf("trapno=0x%08lx\n", sc.trapno);
printf("err=0x%08lx\n", sc.err);
printf("eip=0x%08lx\n", sc.eip);
printf("eflags=0x%08lx\n", sc.eflags);
printf("esp_at_signal=0x%08lx\n", sc.esp_at_signal);
printf("oldmask=0x%08lx\n", sc.oldmask);
printf("cr2=0x%08lx\n", sc.cr2);
_exit(0);
}
int main(void)
{
char *p = (char *) 0xdeadbeef;
printf("%p\n", main);
signal(SIGSEGV, handler);
return *p;
}