|
|
On 19/05/2011 16:15, Darren New wrote:
> On 5/19/2011 2:50, Invisible wrote:
>> Depending on which operating system you're using, the OS provides various
>> ways to load code into memory and execute it. My question is this: How
>> hard
>> would it be to write a subroutine that can read raw machine code from
>> a flat
>> file and make it execute?
>
> In what language?
Most programming languages provide a way to suck the contents of a file
into memory without modifying it. So I suppose the question is, once
it's there, is there some way to execute it?
Presumably this must be very hard to do, otherwise people wouldn't jump
through all the hoops required to get dynamic linking via the OS to work.
For example:
- According to Wikipedia, every Windows DLL in the entire system must
have a unique base address. (I forget what happens if this isn't the
case; I believe it amounts to poor performance.)
- According to the LFS book, every Linux dynamic library actually has
the absolute path to the system linker program hard-coded into it. (This
almost defies belief!)
- Obviously in both cases the actual machine code must also be
surrounded by many miles of complex metadata too.
Presumably nobody would put up with such crippling limitations if doing
it yourself wasn't insanely hard.
One thing about loading data from file is that you usually don't get to
decide where it gets loaded. Is that a problem for x86? Is it hard to
write relocatable machine code or something?
Post a reply to this message
|
|