Fix segfaults on SELinux machines; fixes #7629
authorIan Lynagh <ian@well-typed.com>
Tue, 9 Apr 2013 12:53:28 +0000 (13:53 +0100)
committerIan Lynagh <ian@well-typed.com>
Tue, 9 Apr 2013 13:02:48 +0000 (14:02 +0100)
Patch from wgmitchener.

From the ticket:
The two addresses (adjustorStub and code) contain the same memory
(double-mapped), but one is writable while the other is executable.
This is how libffi works around the SELinux restrictions. On
non-SELinux systems the code and data addresses are probably the same.

rts/Adjustor.c

index 1a0bc28..fbf95df 100644 (file)
@@ -389,7 +389,7 @@ createAdjustor(int cconv, StgStablePtr hptr,
         int sz = totalArgumentSize(typeString);
         
         adjustorStub->call[0] = 0xe8;
-        *(long*)&adjustorStub->call[1] = ((char*)&adjustorCode) - ((char*)adjustorStub + 5);
+        *(long*)&adjustorStub->call[1] = ((char*)&adjustorCode) - ((char*)code + 5);
         adjustorStub->hptr = hptr;
         adjustorStub->wptr = wptr;