Re: Executing from dynamically allocated memory

Alex McDonald <blog@rivadpm.com>
Sat, 12 Oct 2013 11:12:46 -0700 (PDT)

          From comp.compilers

Related articles
Executing from dynamically allocated memory news@fx32.iad.highwinds-media.com (news) (2013-10-12)
Re: Executing from dynamically allocated memory james.harris.1@gmail.com (James Harris) (2013-10-12)
Re: Executing from dynamically allocated memory sebastien.fricker@gmail.com (=?UTF-8?B?U8OpYmFzdGllbiBGcmlja2Vy?=) (2013-10-12)
Re: Executing from dynamically allocated memory chakaram@auth.gr (2013-10-12)
Re: Executing from dynamically allocated memory blog@rivadpm.com (Alex McDonald) (2013-10-12)
Re: Executing from dynamically allocated memory sandmann@cs.au.dk (2013-10-12)
Re: Executing from dynamically allocated memory jkallup@web.de (Jens Kallup) (2013-10-13)
| List of all articles for this month |
From: Alex McDonald <blog@rivadpm.com>
Newsgroups: comp.compilers
Date: Sat, 12 Oct 2013 11:12:46 -0700 (PDT)
Organization: Compilers Central
References: 13-10-004
Keywords: architecture, code
Posted-Date: 12 Oct 2013 14:54:57 EDT

On Saturday, 12 October 2013 01:05:39 UTC+1, news wrote:
> In the past, I've malloc'd memory, written machine instructions into it,
> and called the function I built there.
> All this on a 32-bit intel instruction set, on a Debian system. ...


> Now it was a year or three ago that this worked. Has Linux changed in
> this respect? Is there something new I have to do to allocate executable
> writable memory for this purpose?
>
> Or might there be something even weirder going on?
> [ Sounds like the NX bit. See http://en.wikipedia.org/wiki/NX_bit#Linux -John]


mprotect(2) - Linux man page
Name


mprotect - set protection on a region of memory
Synopsis


#include <sys/mman.h>


int mprotect(void *addr, size_t len, int prot);


Description


mprotect() changes protection for the calling process's memory page(s)
containing any part of the address range in the interval [addr,
addr+len-1]. addr must be aligned to a page boundary.


If the calling process tries to access memory in a manner that
violates the protection, then the kernel generates a SIGSEGV signal
for the process.


prot is either PROT_NONE or a bitwise-or of the other values in the
following list:


...


PROT_EXEC


The memory can be executed.


...


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.