Re: Marking a Page of Memory Executable
- From: richard@xxxxxxxxxxxxxxx (Richard Tobin)
- Date: 5 Jun 2008 11:11:34 GMT
In article <DkH1k.3477$E41.2245@xxxxxxxxxxxxxxxxxxxxxxxxx>,
Bartc <bc@xxxxxxxxxx> wrote:
What I want to do is get an executable and writable page of memory, so
that I can (say) write machine code to it and then switch %eip (the
instruction pointer on x86) to that page so that it will execute that
code, or something similar.
This sounds like a problem peculiar to your system. Under WinXP I don't have
a problem executing code created in my data:
Just because something isn't the same as Windows XP doesn't mean it's
"peculiar to your system". For decades processors and operating
systems have distinguished between executable and non-executable
memory, just as between writable and read-only memory.
(It's one of the deficiencies of the x86 architecture that it has
not generally been possible to make the stack non-executable, making
possible most of the buffer-overflow exploits that are so popular.)
Most operating systems have functions for controlling this, assuming
the processor supports it. In unix mmap() allows permissions to
be set on allocated memory, and mprotect() allows them to be changed.
int testfn(int a,int b) {return a*b;}
int main(void){
int (*newfn)(int,int);
int i;
newfn=malloc(100); /* assumed to work */
memcpy(newfn,&testfn,100); /* assumes testfn has <=100 bytes */
And it works for this example although crashes if testfn is changed, maybe
because some x86 code is not relocatable.
There's also no guarantee that all the code for testfn immediately
follows the address of testfn.
-- Richard
--
In the selection of the two characters immediately succeeding the numeral 9,
consideration shall be given to their replacement by the graphics 10 and 11 to
facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
.
- Follow-Ups:
- Re: Marking a Page of Memory Executable
- From: Kenny McCormack
- Re: Marking a Page of Memory Executable
- From: Bartc
- Re: Marking a Page of Memory Executable
- References:
- Marking a Page of Memory Executable
- From: Pie Squared
- Re: Marking a Page of Memory Executable
- From: Bartc
- Marking a Page of Memory Executable
- Prev by Date: Including compiled C source file in array
- Next by Date: Re: warning while making cast
- Previous by thread: Re: Marking a Page of Memory Executable
- Next by thread: Re: Marking a Page of Memory Executable
- Index(es):
Relevant Pages
|