Re: Marking a Page of Memory Executable



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/informatique
http://www.cs.virginia.edu/~lcc-win32
.



Relevant Pages

  • Re: Marking a Page of Memory Executable
    ... instruction pointer on x86) to that page so that it will execute that ... memory, just as between writable and read-only memory. ... (It's one of the deficiencies of the x86 architecture that it has ... int; ...
    (comp.lang.c)
  • Re: coding in asm
    ... or a simply ret... ... it will execute whatever random bytes happened to be in memory ... > after the int 10. ...
    (microsoft.public.vc.language)
  • [PATCH] drm: Add GEM ("graphics execution manager") to i915 driver.
    ... * Binds a collection of pages into AGP memory at the given offset, ... new file mode 100644 ... * The above copyright notice and this permission notice (including the ... +static int ...
    (Linux-Kernel)
  • [PATCH] drm: Add GEM ("graphics execution manager") to i915 driver.
    ... * Binds a collection of pages into AGP memory at the given offset, ... new file mode 100644 ... * The above copyright notice and this permission notice (including the ... +static int ...
    (Linux-Kernel)
  • [PATCH 8/19] TuxOnIce: Add core TuxOnIce code.
    ... Add the core TuxOnIce code, including hooks in snapshot.c so TuxOnIce ... can use the atomic copy and restore functions, ... +extern int toi_running; ... * system memory to an arbitrary storage device, either on the local computer, ...
    (Linux-Kernel)