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 Keywords: Ultrix Message-ID: <453@minya.UUCP> Date: 23 Jan 88 15:00:40 GMT References: <202@sdti.UUCP> <3106@super.upenn.edu> Distribution: na Organization: home Lines: 42 You know, it occurred to me that the I-space vs D-space just might be a problem, so I looked in the manuals for this machine (which might as well remain incognito). Sure enough, there is supposedly separate address spaces for both, as well as for IO-space. So I modified the little program I posted earlier: | #include | extern char *malloc(); | char *code; /* This will point into D-space */ | int (*fct)(); /* So will this */ | | foobar(x,y) | { printf("foobar(%d,%d)\n",x,y); | return x + y; | } | main() | { int i; | char *p, *q; | | code = (char*)malloc(1000); | p = code; | q = (char*)foobar; | while (p < code+1000) /* Make copy of foobar() in code[] */ | *p++ = *q++; | fct = (int(*)())code; /* Point to the malloc()ed data area */ | i = (*fct)(7,9); /* Call the copy */ | printf("(*fct)(7,9)=%d\n",i); | exit(0); | } It compiled and linked without problems, so with a bit of trepidation I told Unix (Sys/V) to run it, and guess what it said? Give up? OK, here's the output: | foobar(7,9) | (*fct)(7,9)=16 Seems like it worked, didn't it? Clever people, those C compiler writers! -- John Chambers <{adelie,ima,maynard,mit-eddie}!minya!{jc,root}> (617/484-6393)