Path: utzoo!mnetor!uunet!husc6!mit-eddie!cybvax0!vcvax1!naren From: naren@vcvax1.UUCP (naren) Newsgroups: comp.unix.wizards Subject: Re: Aliasing text and data segments of a process Message-ID: <246@vcvax1.UUCP> Date: 27 Jan 88 19:10:39 GMT References: <202@sdti.UUCP> <730@umbc3.UMD.EDU> <7156@brl-smoke.ARPA> <452@minya.UUCP> Organization: VenturCom Inc., Cambridge, MA Lines: 29 > 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. > > [Sample program that malloc()'s and typecasts result to a func. ptr. deleted] > > John Chambers <{adelie,ima,maynard,mit-eddie}!minya!{jc,root}> (617/484-6393) Doug Gwyn is right about architectures that enforce distinctions between code and data spaces (ex: 80386). On UNIX/386, an sbrk() allocates space in the Data Segment of the process. Type casting this pointer and issuing a 'call' to this address will result in a protection exception. Now, if you REALLY want to do this, you could write a new system call like mktext(vaddr, length) where vaddr is the start of the data space you would like to fill in with code. mktext() would just create a new code segment descriptor in the LDT of your task that includes the desired section of data space and then you'd be all set. I am of course leaving out a lot of the nitty-gritty details of how this feature would interact with other things like shared texts, etc. ...!{harvard,mit-eddie}!cybvax0!vcvax1!naren Naren Nachiappan.(617/661-1230)