Fix test for memory allocators that want to look backwards.
authorPeter Griess <pgriess@fb.com>
Thu, 26 Sep 2013 18:27:05 +0000 (13:27 -0500)
committerPeter Griess <pgriess@fb.com>
Tue, 15 Oct 2013 01:47:17 +0000 (18:47 -0700)
commite34bc9cae798da3c01eca891a60d452440e728df
tree94cbe1142999033429ff8e3c7618ea1256e5f4f8
parent2549fb3c263e2d50630e5f42c0ff404b76cb7370
Fix test for memory allocators that want to look backwards.

Summary:
- The NeedleFinderTest.NoSegFault test uses mprotect(2) to ensure that
our needle implementations don't peek past the end of memory. However,
some memory allocators (e.g. the defaulton OS X) seem to look at the
last byte of a page. As a result, if we allocate 2 pages and mark the
second as PROT_NONE, then ask the memory allocator for 2 more pages,
it may end up peeking at the last byte of the second page, triggering
a SIGBUS. To work around this, allocate 8 pages of memory and only
mark the second as PROT_NONE.
- Clear mprotect(2) bits before freeing memory.

Test Plan:
- fbconfig -r folly && fbmake runtests
- ./configure && make check on Ubuntu/FC/Mac

Reviewed By: delong.j@fb.com

FB internal diff: D998592
folly/test/RangeTest.cpp