(3b2) functions in data space

Daniel R. Levy levy at ttrdc.UUCP
Tue Mar 18 13:32:29 AEST 1986


<Oh oh here it comes.  Watch out boy, it'll chew you up! \
Oh oh here it comes.  The LINE EATER!  [Line eater]>

In article <622 at bentley.UUCP>, kwh at bentley.UUCP (KW Heuer) writes:
>I've changed the cross-posting from net.unix to net.unix-wizards, as
>this is no longer a neophyte question.
>...
>The person who started this discussion was already able to create code
>in the .data space; whether it's done by the loader or at run-time by
>the program is irrelevant.  The question is whether it's possible to
>_execute_ such a function.  On a vax, you can.  On a pdp11 with split
>I/D, you can't, because .text and .data addresses are each 16 bits,
>so an attempt to call a function from .data space will actually call
>the function at the same address in .text space.  (The workaround is
>to use ld -N, so you don't have split I/D.)  The remainder of this
>discussion focuses on the 3b2, where .text and .data addresses have
>separate ranges (.text normally starts at 0x80800000, .data at
>0x80880000).
>[more discussion, speculation]

Well, it IS possible on the 3b2 and very simply.  Not only is it
possible to read text space but it is also possible to run data space.
Here's a quickie program which works on the 3b2:

main()
{
	char arr[100];	/* needn't be nearly this big but what the heck */
	void hello();
	charcopy(hello,arr,100);
	printf("I've now copied text space to data space.\n");
	run(arr);
	printf("I've now run data space.\n");
}
void hello()
{
	printf("Hello world\n");
}
charcopy(a,b,c)
char *a, *b;
int c;
{
	while (c--) *b++ = *a++;
}
run(stuff)
char (*stuff)();
{
	(*stuff)();
}

Now maybe some pundit out there can explain WHY this works :-).
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
						vax135}!ttrdc!levy



More information about the Comp.unix.wizards mailing list