Aliasing text and data segments of a process

naren naren at vcvax1.UUCP
Thu Jan 28 05:10:39 AEST 1988


> In article <7156 at brl-smoke.ARPA>, gwyn at brl-smoke.ARPA (Doug Gwyn ) writes:
> > In article <730 at umbc3.UMD.EDU> alex at 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) 



More information about the Comp.unix.wizards mailing list