Skip to content
Snippets Groups Projects
Commit 6467775c authored by Steffen Müthing's avatar 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
parents bdd46c53 1b04f128
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
......
......@@ -116,7 +116,7 @@ dune_add_test(SOURCES testdebugallocator.cc
dune_add_test(NAME testdebugallocator_fail1
SOURCES testdebugallocator.cc
LINK_LIBRARIES dunecommon
COMPILE_DEFINITIONS "FAILURE1;EXPECTED_SIGNAL=SIGSEGV"
COMPILE_DEFINITIONS "FAILURE1;EXPECTED_SIGNAL=SIGSEGV;EXPECTED_ALT_SIGNAL=SIGBUS"
EXPECT_FAIL)
dune_add_test(NAME testdebugallocator_fail2
......@@ -134,13 +134,13 @@ dune_add_test(NAME testdebugallocator_fail3
dune_add_test(NAME testdebugallocator_fail4
SOURCES testdebugallocator.cc
LINK_LIBRARIES dunecommon
COMPILE_DEFINITIONS "FAILURE4;DEBUG_ALLOCATOR_KEEP=1;EXPECTED_SIGNAL=SIGSEGV"
COMPILE_DEFINITIONS "FAILURE4;DEBUG_ALLOCATOR_KEEP=1;EXPECTED_SIGNAL=SIGSEGV;EXPECTED_ALT_SIGNAL=SIGBUS"
EXPECT_FAIL)
dune_add_test(NAME testdebugallocator_fail5
SOURCES testdebugallocator.cc
LINK_LIBRARIES dunecommon
COMPILE_DEFINITIONS "FAILURE5;EXPECTED_SIGNAL=SIGSEGV"
COMPILE_DEFINITIONS "FAILURE5;EXPECTED_SIGNAL=SIGSEGV;EXPECTED_ALT_SIGNAL=SIGBUS"
EXPECT_FAIL)
dune_add_test(SOURCES testfloatcmp.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