Skip to content

Commit

Permalink
Merge pull request microsoft#22 from Microsoft/zero_bug
Browse files Browse the repository at this point in the history
Pal zero bug alignment
  • Loading branch information
Theodus authored Feb 15, 2019
2 parents 3580330 + adeecfb commit 90414f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/mem/largealloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,15 @@ namespace snmalloc
memory_provider.template zero<true>(p, OS_PAGE_SIZE);

memory_provider.template notify_using<zero_mem>(
(void*)((size_t)p + OS_PAGE_SIZE), size - OS_PAGE_SIZE);
(void*)((size_t)p + OS_PAGE_SIZE),
bits::align_up(size, OS_PAGE_SIZE) - OS_PAGE_SIZE);
}
else
{
// This is a superslab that has not been decommitted.
if (zero_mem == YesZero)
memory_provider.template zero<true>(p, size);
memory_provider.template zero<true>(
p, bits::align_up(size, OS_PAGE_SIZE));
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/test/func/memory/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,17 @@ void test_alloc_16M()
alloc->dealloc(p1);
}

void test_calloc_16M()
{
auto* alloc = ThreadAlloc::get();
// sizes >= 16M use large_alloc
const size_t size = 16'000'000;

void* p1 = alloc->alloc<YesZero>(size);
assert(Alloc::alloc_size(Alloc::external_pointer(p1)) >= size);
alloc->dealloc(p1);
}

int main(int argc, char** argv)
{
#ifdef USE_SYSTEMATIC_TESTING
Expand All @@ -296,6 +307,7 @@ int main(int argc, char** argv)
test_double_alloc();
test_external_pointer();
test_alloc_16M();
test_calloc_16M();

return 0;
}

0 comments on commit 90414f8

Please sign in to comment.