who called a C routine - get it from the stack frame

Chris Torek chris at mimsy.UUCP
Sat Dec 6 06:25:54 AEST 1986


In article <961 at cuuxb.UUCP> wbp at cuuxb.UUCP (Walt Pesch) writes:
>Oh, well, you asked!  Time to get down into the mud...  For System V,
>the following dirty trick should work:

Getting down in the mud is right; this kind of thing is hardly
portable.  But `for System V' is not true:  The operation is
*machine* specific, not *operating system* specific (though there
are machines on which the operating system might affect the method).

Here is some 4.2/4.3BSD Vax Unix code to do the trick.

#include <stdio.h>
#include <sys/types.h>
#include <machine/frame.h>

main()
{

	f();
	g();
	exit(0);
}

f()
{
	g();
}

g()
{
	register struct frame *fr;	/* r11 */

	asm("	movl	fp,r11");	/* set fr=frame */
	printf("g: will return to address %x\n", fr->fr_savpc);
}
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP:	seismo!mimsy!chris	ARPA/CSNet:	chris at mimsy.umd.edu



More information about the Comp.unix.wizards mailing list