Page MenuHomePhabricator

[compiler-rt] [builtins] Fix clear_cache_test to work with MPROTECT
ClosedPublic

Authored by mgorny on Sun, Jan 12, 2:09 PM.

Details

Summary

Fix clear_cache_test to work on NetBSD with PaX MPROTECT enabled, that
is when creating W+X mmaps is prohibited. Use the recommended solution:
create two mappings for the same memory area, make one of them RW, while
the other RX. Copy the function into the RW area but run it from the RX
area.

In order to implement this, I've split the pointer variables to
'write_buffer' and 'execution_buffer'. Both are separate pointers
on NetBSD, while they have the same value on other systems.

I've also split the memcpy_f() into two: new memcpy_f() that only takes
care of copying memory and discards the (known) result of memcpy(),
and realign_f() that applies ARM realignment to the given pointer.
Again, there should be no difference on non-NetBSD systems but on NetBSD
copying is done on write_buffer, while realignment on pointer
to the execution_buffer.

I have tested this change on NetBSD and Linux.

Diff Detail

Event Timeline

mgorny created this revision.Sun, Jan 12, 2:09 PM
krytarowski accepted this revision.Mon, Jan 13, 12:22 AM
This revision is now accepted and ready to land.Mon, Jan 13, 12:22 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptWed, Jan 22, 8:12 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript