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: "James Harris" Newsgroups: comp.compilers Subject: Re: Executing from dynamically allocated memory Date: Sat, 12 Oct 2013 10:10:51 +0100 Organization: A noiseless patient Spider Lines: 25 Sender: johnl@iecc.com Approved: comp.compilers@iecc.com Message-ID: <13-10-005@comp.compilers> References: <13-10-004@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: leila.iecc.com 1381603921 83129 64.57.183.58 (12 Oct 2013 18:52:01 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sat, 12 Oct 2013 18:52:01 +0000 (UTC) Keywords: architecture, code Posted-Date: 12 Oct 2013 14:52:01 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:988 "news" wrote in message > 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. > > This appears no longer too work. My program gives a segmentation fault. > The debugger tells me that the segmentation fault occurs on the first > instruction of the called function, a > push %ebp > residing in malloced memory. > > 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? Possibly. As John says, this could be caused by current Linux setting the NX bit for malloced pages. The dump may/should show if that is the case, if you can decipher the dump. Instead of malloc you may need to use mmap. It allows permissions to be specified. James