Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!samsung!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.unix.internals Subject: Re: Loading and Executing Object Code at Runtime Message-ID: <1991Feb16.163527.25147@virtech.uucp> Date: 16 Feb 91 16:35:27 GMT References: <1991Feb14.182925.15793@mtxinu.COM> <6073@auspex.auspex.com> <1991Feb16.100946.601@kithrup.COM> Organization: Virtual Technologies Inc. Lines: 44 sef@kithrup.COM (Sean Eric Fagan) writes: >*However*, you still cannot execute data; you have to execute code. > Consider it as an alias of forms. Obviously you cannot execute data since it probably doesn't make much sense as a stream of instructions. However, if you copied a function from code to data space and then branched throught a pointer to that data area, it does work. So you can execute from data space. This works on ISC UNIX, Bell Tech UNIX, Sun OS and several other OS's. I don't have SCO lying around to try, but I would bet that it does in fact work. Here is a sample program that will verify that it works: Two notes about the program: 1. Yes all error checking has been removed. I'm 2. Yes I know that it uses non-portable stuff. main() { char * addr; char test[100]; char * malloc(); int func1(); int func2(); int (*funcp)(); strcpy(test,"YES will appear here: if it worked\n"); addr = malloc(3000); docopy(addr,func1,func2); funcp = addr; /* you will get a warning about this line */ (*funcp)(test); puts(test); exit(0); } docopy(tgt,src,srcend) char *tgt; char*src; char *srcend; { while( src != srcend ) *tgt++ = *src++; } int func1(str) char * str; { str[22] = 'Y'; str[23] = 'E'; str[24] = 'S';} int func2(str) char * str; { str[22] = 'N'; str[23] = 'O'; } -- Conor P. Cahill (703)430-9247 Virtual Technologies, Inc. uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160 Sterling, VA 22170