[GHC] #6059: FFI: segfault when jumping to code buffer (under certain conditions)
GHC
cvs-ghc at haskell.org
Wed May 2 20:33:15 CEST 2012
#6059: FFI: segfault when jumping to code buffer (under certain conditions)
-----------------------------+----------------------------------------------
Reporter: guest | Owner:
Type: bug | Status: closed
Priority: normal | Milestone: 7.6.1
Component: Compiler (FFI) | Version: 7.4.1
Resolution: invalid | Keywords: segfault ffi
Os: Linux | Architecture: x86
Failure: Runtime crash | Difficulty: Unknown
Testcase: | Blockedby:
Blocking: | Related:
-----------------------------+----------------------------------------------
Changes (by guest):
* status: new => closed
* resolution: => invalid
Comment:
Well, as I said, it's reproducible (at least on my system). Within `make`
it works as desired, but calling it from shell, it doesn't.
I looked at the implementation of `mallocBytes`. It's just calling
`malloc`, so a came up with this code:
{{{
#!C
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
unsigned short *ptr = (unsigned short*) malloc(2);
*ptr = 0xc390;
printf("entry point: 0x%08x\n", (unsigned short) ptr);
((void (*)()) ptr) ();
printf("welcome back\n");
}
}}}
Same behaviour: Calling it from `make`, everything is fine. Calling it
from shell, segfault.
So I guess it isn't GHC related at all. Sorry :-/ I think this ticket can
be closed.
The solution for my project was, allocate memory and mark it as executable
with `mprotect`.
Thanks,
bernhard
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/6059#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list