Loading and Executing Object Code at Runtime

Sean Eric Fagan sef at kithrup.COM
Sun Feb 17 08:35:57 AEST 1991


In article <BZS.91Feb16112944 at world.std.com> bzs at world.std.com (Barry Shein) writes:
>So what you're saying is that an (assembler, library) function could
>be written which calls a data address and used by any program (on a
>386)? Something similar to indir(), eg: call(addr,arg1,arg2,...,argn)?

*If* cs and ds (and ss, and es, at least) are aliased to the same chunk of
virtual memory, then, yes.  All indir has to do is look like this:

	call(void (*addr)()) {
		(*addr)();
	}

The compiler will spit out code that will work.  The case I had, again,
dealt with the compiler spitting out code that looked like

	call *%esp

On the '386, both ebp and esp use ss by default; and since ss is writable,
it cannot be executable.  What I have to do is get it to spit out a
segment-override prefix (namely, "cs:" 8-)).  (One thing I do have to make
sure about:  that spitting the "cs:" out does not cause a far call; that
would be *bad*.)

On the other hand, if you do not have cs aliased to ds (et al), then you
will be jumping to the wrong address.  (It will be the offset in the segment
you want, but in the wrong segment.)

-- 
Sean Eric Fagan  | "I made the universe, but please don't blame me for it;
sef at kithrup.COM  |  I had a bellyache at the time."
-----------------+           -- The Turtle (Stephen King, _It_)
Any opinions expressed are my own, and generally unpopular with others.



More information about the Comp.unix.internals mailing list