Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news.linkpendium.com!news.linkpendium.com!news.iecc.com!.POSTED!nerds-end From: Alex McDonald Newsgroups: comp.compilers Subject: Re: Executing from dynamically allocated memory Date: Sat, 12 Oct 2013 11:12:46 -0700 (PDT) Organization: Compilers Central Lines: 42 Sender: johnl@iecc.com Approved: comp.compilers@iecc.com Message-ID: <13-10-008@comp.compilers> References: <13-10-004@comp.compilers> NNTP-Posting-Host: news.iecc.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: leila.iecc.com 1381604097 84585 64.57.183.58 (12 Oct 2013 18:54:57 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sat, 12 Oct 2013 18:54:57 +0000 (UTC) Keywords: architecture, code Posted-Date: 12 Oct 2013 14:54:57 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:991 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 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. ...