Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: Separate data and function address spaces Message-ID: <1989Nov10.123033.2494@virtech.uucp> Date: 10 Nov 89 12:30:33 GMT References: <530@dftsrv.gsfc.nasa.gov> <225800239@uxe.cso.uiuc.edu> <2559F3AE.9260@ateng.com> Organization: Virtual Technologies Inc. Lines: 77 In article <2559F3AE.9260@ateng.com>, chip@ateng.com (Chip Salzenberg) writes: > Recent processors also have this "feature". When the '286 and '386 > processors are in protected mode -- i.e. when they're running Unix > -- they do not permit program execution from any data segment. This > restriction can be bypassed only by the subterfuge of pointing two > segment descriptors at the same piece of memory. I don't know what unix you are using, but the System V/386 Unixs use the small model for compiled programs which place the data and text portion into the same segment. I have executed out of data space on these systems. I have even executed out of a shared memory segment. > > char *p; > > int fn(); > > p = (char *)fn; while this is non-portable, it can be done on the unixs I spoke about above. Try the following on your 386 system: #include main() { int a(); int b(); int errno; int (* func )(); void * malloc(); char * shmaddr; char * test; if( (shmaddr=(char *)malloc(512)) == 0 ) { printf("malloc failed, errno = %d\n", errno); exit(10); } cpy(shmaddr,a,b); func = (int (*)()) shmaddr; test = "If the word 'shared' appears here: ...... it works."; (* func)(test); printf("%s\n",test); exit(0); } cpy(tgt,src,srcend) char * tgt; char * src; char * srcend; { while ( src != srcend ) *tgt++ = *src++; } a( s ) char *s; { s[35] = 'S'; s[36] = 'H'; s[37] = 'A'; s[38] = 'R'; s[39] = 'E'; s[40] = 'D'; return; } b( s ) char *s; { s[35] = 'N'; s[36] = 'O'; s[37] = 'R'; s[38] = 'M'; s[39] = 'A'; s[40] = 'L'; return; } -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+