[Top] [All Lists]

Re: using mprotect to write to .text

To: Joe Buehler <>
Subject: Re: using mprotect to write to .text
From: David Daney <>
Date: Tue, 11 Oct 2011 09:36:49 -0700
In-reply-to: <>
References: <>
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20101027 Fedora/3.0.10-1.fc12 Thunderbird/3.0.10
On 10/10/2011 01:02 PM, Joe Buehler wrote:
I intend to use mprotect in a running binary to allow it to modify its .text
section.  The detailed behavior of mprotect for a multithreaded program on SMP
hardware is not documented as far as I can tell.

It is well documented. What is not well defined is what happens if you modify the code and then try to execute it.

Can I depend on the LINUX mprotect call to take care of icache flushing,
handling of hazards, etc.?

No, it does nothing of the sort.  You need cacheflush() for that.

 I am using Octeon CN5650 on and if
it matters.

It doesn't really matter.

What you need is something like:

#include <sys/cachectl.h>

cacheflush(location, size, ICACHE);

David Daney

<Prev in Thread] Current Thread [Next in Thread>