Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!homxb!mhuxt!mhuxm!mhuxo!ulysses!allegra!mit-eddie!husc6!think!ames!aurora!labrea!decwrl!decvax!ima!minya!jc From: jc@minya.UUCP Newsgroups: comp.unix.wizards Subject: Re: Aliasing text and data segments of a process Message-ID: <452@minya.UUCP> Date: 23 Jan 88 14:40:00 GMT References: <202@sdti.UUCP> <730@umbc3.UMD.EDU> <7156@brl-smoke.ARPA> Organization: home Lines: 39 In article <7156@brl-smoke.ARPA>, gwyn@brl-smoke.ARPA (Doug Gwyn ) writes: > In article <730@umbc3.UMD.EDU> alex@umbc3.UMD.EDU (Alex S. Crain) writes: > >loads the .o file as data, and then branches to the start of the text area > >of the .o file > > This cannot possibly work on an architecture that enforces the > distinction between Instruction and Data spaces. Jeez, why do they let such obvious non-wizards post responses to unix.wizards? (:-) There have been far too many such comments from people who obviously haven't RTFM, in this case K&R. Study the following program, which should work anywhere you have a C compiler. (If your compiler doesn't do it right, send it back to the factory; it's obviously broken.) | #include | char *code; /* This can point to any address in memory */ | int (*fct)(); /* We will point this at *code */ | | foobar(x,y) | { printf("foobar(%d,%d)\n",x,y); | return x + y; | } | main() | { int i; | | code = (char*)foobar; /* This could be malloc() */ | fct = (int(*)())code; /* Stuff random pointer into fct */ | i = (*fct)(7,9); /* Call random memory location */ | printf("(*fct)(7,9)=%d\n",i); | exit(0); | } Well, OK, he asked if there is Unix support, and there isn't. So who needs it? This oughta work on VMS or MS/DOS, too. -- John Chambers <{adelie,ima,maynard,mit-eddie}!minya!{jc,root}> (617/484-6393)