Skip to content
Snippets Groups Projects
Commit 58bf5d43 authored by Steffen Müthing's avatar Steffen Müthing Committed by Steffen Müthing
Browse files

Merge branch 'feature/fix-posix_memalign-usage' into 'master'


The point of the matter is that posix_memalign() is not allowed in this
context according to the relevant standards, so we use mmap() instad.

`mprotect` can only be used for `mmap`'ed memory

Makes testdebugallocator pass on OS X, too.

See merge request !43
(cherry picked from commit 6467775c)

Signed-off-by: default avatarSteffen Müthing <muething@dune-project.org>
parent 2a2c8337
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ namespace Dune
namespace DebugMemory
{
// system constant for page size
const std::ptrdiff_t page_size = getpagesize();
const std::ptrdiff_t page_size = sysconf(_SC_PAGESIZE);
// implement member functions
void AllocationManager::allocation_error(const char* msg)
......
......@@ -106,7 +106,7 @@ namespace Dune
it->capacity << " bytes at " << it->ptr << std::endl;
error = true;
}
free(it->page_ptr);
munmap(it->page_ptr, it->pages * page_size);
}
if (error)
allocation_error("lost allocations");
......@@ -122,8 +122,10 @@ namespace Dune
ai.pages = (ai.capacity) / page_size + 2;
ai.not_free = true;
size_type overlap = ai.capacity % page_size;
int result = posix_memalign(&(ai.page_ptr), page_size, ai.pages * page_size);
if (0 != result)
ai.page_ptr = mmap(NULL, ai.pages * page_size,
PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (MAP_FAILED == ai.page_ptr)
{
throw std::bad_alloc();
}
......@@ -171,7 +173,7 @@ namespace Dune
memprotect(it->page_ptr,
(it->pages) * page_size,
PROT_READ | PROT_WRITE);
std::free(it->page_ptr);
munmap(it->page_ptr, it->pages * page_size);
// remove chunk info
allocation_list.erase(it);
#endif
......
......@@ -145,7 +145,7 @@ add_executable("testdebugallocator" testdebugallocator.cc)
target_link_libraries(testdebugallocator dunecommon)
add_executable("testdebugallocator_fail1" testdebugallocator.cc)
target_link_libraries(testdebugallocator_fail1 dunecommon)
set_target_properties(testdebugallocator_fail1 PROPERTIES COMPILE_DEFINITIONS "FAILURE1;EXPECTED_SIGNAL=SIGSEGV")
set_target_properties(testdebugallocator_fail1 PROPERTIES COMPILE_DEFINITIONS "FAILURE1;EXPECTED_SIGNAL=SIGSEGV;EXPECTED_ALT_SIGNAL=SIGBUS")
add_executable("testdebugallocator_fail2" testdebugallocator.cc)
target_link_libraries(testdebugallocator_fail2 dunecommon)
set_target_properties(testdebugallocator_fail2 PROPERTIES COMPILE_DEFINITIONS "FAILURE2;EXPECTED_SIGNAL=SIGABRT")
......@@ -154,10 +154,10 @@ target_link_libraries(testdebugallocator_fail3 dunecommon)
set_target_properties(testdebugallocator_fail3 PROPERTIES COMPILE_DEFINITIONS "FAILURE3;EXPECTED_SIGNAL=SIGABRT")
add_executable("testdebugallocator_fail4" testdebugallocator.cc)
target_link_libraries(testdebugallocator_fail4 dunecommon)
set_target_properties(testdebugallocator_fail4 PROPERTIES COMPILE_DEFINITIONS "FAILURE4;DEBUG_ALLOCATOR_KEEP=1;EXPECTED_SIGNAL=SIGSEGV")
set_target_properties(testdebugallocator_fail4 PROPERTIES COMPILE_DEFINITIONS "FAILURE4;DEBUG_ALLOCATOR_KEEP=1;EXPECTED_SIGNAL=SIGSEGV;EXPECTED_ALT_SIGNAL=SIGBUS")
add_executable("testdebugallocator_fail5" testdebugallocator.cc)
target_link_libraries(testdebugallocator_fail5 dunecommon)
set_target_properties(testdebugallocator_fail5 PROPERTIES COMPILE_DEFINITIONS "FAILURE5;EXPECTED_SIGNAL=SIGSEGV")
set_target_properties(testdebugallocator_fail5 PROPERTIES COMPILE_DEFINITIONS "FAILURE5;EXPECTED_SIGNAL=SIGSEGV;EXPECTED_ALT_SIGNAL=SIGBUS")
add_executable("tuplestest_config" tuplestest.cc)
add_executable("tupleutilitytest" tupleutilitytest.cc)
......
......@@ -93,9 +93,16 @@ int main(int, char**)
#if EXPECTED_SIGNAL
std::signal(EXPECTED_SIGNAL, std::_Exit);
#endif
#if EXPECTED_ALT_SIGNAL
std::signal(EXPECTED_ALT_SIGNAL, std::_Exit);
#endif
basic_tests();
allocator_tests();
new_delete_tests();
#ifdef EXPECTED_SIGNAL
return 1;
#else
return 0;
#endif
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment