[MLton] reason for mprotect with PROT_EXEC ?

Matthew Fluet fluet at tti-c.org
Thu Feb 7 06:57:33 PST 2008


On Thu, 7 Feb 2008, Wesley W. Terpstra wrote:
> On Feb 7, 2008, at 2:26 AM, Adam Goode wrote:
>> runtime/platform/mmap-protect.c line 10 contains an mprotect with
>> PROT_READ | PROT_WRITE | PROT_EXEC.
>> 
>> Is PROT_EXEC needed? I'm asking because MLton compiled executables will
>> fail on Fedora 9 with this.
>
> On some platforms the linux kernel places a "trampoline" on the stack as part 
> of invoking a signal handler. If the stack is not executable, this will cause 
> the program to segfault. In MLton, having an executable stack isn't as much 
> of a concern as it would be in most programs, since hopefully the usage of C 
> is small and stack overflows are impossible in ML.

The relevant mail item that describes the introduction of PROT_EXEC for 
the signal stack is:
   http://mlton.org/pipermail/mlton/2004-December/026512.html

In the absence of foreign function calls, MLton will set up a trivial 
signal handler that does nothing but set the limit pointer to zero and 
record the identity of the handled signal.  This clearly has 
constant stack usage.  Of course, using the FFI, one could call a C 
function that sets up a different signal handler, over which we have no 
control.



More information about the MLton mailing list