Re: Marking a Page of Memory Executable
- From: Pie Squared <PieSquared@xxxxxxxxx>
- Date: Wed, 4 Jun 2008 17:13:22 -0700 (PDT)
On Jun 4, 7:29 pm, jacob navia <ja...@xxxxxxxxxx> wrote:
Pie Squared wrote:
I'm not completely sure that this is the right place to ask, but I'm
doing it in C, so I'm asking, but if I'm wrong, then please don't
hesitate to correct me and tell me where to post this.
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.
I'm attempting to figure out how JIT's manage to run code made during
run-time without writing to an executable file, so if anyone knows
that or has some suggestions I'd like to hear those too.
I'm using Ubuntu Hardy Heron, by the way, in case that matters. I
tried looking in comp.os.linux, but that seems to be archived, so I
can't post this there.
Thanks, and sorry if this is mis-posted.
--Piesquared
Hi Piesquared (pipi for friends I suppose :-)
% man mmap
MMAP(2) Linux Programmer's Manual MMAP(2)
NAME
mmap, munmap - map or unmap files or devices into memory
SYNOPSIS
#include <unistd.h>
#include <sys/mman.h>
#ifdef _POSIX_MAPPED_FILES
void * mmap(void *start, size_t length, int prot , int
flags, int fd, off_t offset);
int munmap(void *start, size_t length);
#endif
DESCRIPTION
The mmap function asks to map length bytes starting at
offset offset from the file (or other object) specified by
the file descriptor fd into memory, preferably at address
start. This latter address is a hint only, and is usually
specified as 0. The actual place where the object is
mapped is returned by mmap, and is never 0.
The prot argument describes the desired memory protection
(and must not conflict with the open mode of the file). It
is either PROT_NONE or is the bitwise OR of one or more of
the other PROT_* flags.
PROT_EXEC Pages may be executed.
etc, did not copy the rest
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32
Thanks, all! That was immensely useful.
Thanks, Dave, for that info. I'll keep that in mind from now on
whenever I post here (I'm sort-of new to USENET). Thanks for helping a
newbie in need. :)
Also, so _that's_ what the infamous mmap does...
And now let this topic sink into obscurity before my mispost angers
anyone. ;-)
.
- Follow-Ups:
- Re: Marking a Page of Memory Executable
- From: Antoninus Twink
- 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: jacob navia
- Marking a Page of Memory Executable
- Prev by Date: Re: is order urgent doubt
- Next by Date: Re: Marking a Page of Memory Executable
- Previous by thread: Re: Marking a Page of Memory Executable
- Next by thread: Re: Marking a Page of Memory Executable
- Index(es):
Relevant Pages
|