}
static Ref create(size_t page_size, uint64_t offset = 0) {
+ // ensure proper alignment of the Page
+ const auto align = alignof(Page);
+ page_size = (page_size + align - 1) & ~(align - 1);
// allocate the Page and its data in a single buffer
auto buffer = new char[page_size + sizeof(Page)];
// place the Page structure at the end of the buffer
#include "os/memstore/PageSet.h"
+template <typename T>
+bool is_aligned(T* ptr) {
+ const auto align_mask = alignof(T) - 1;
+ return (reinterpret_cast<uintptr_t>(ptr) & align_mask) == 0;
+}
+
TEST(PageSet, AllocAligned)
{
PageSet pages(1);
ASSERT_EQ(1u, range[1]->offset);
ASSERT_EQ(2u, range[2]->offset);
ASSERT_EQ(3u, range[3]->offset);
+
+ // verify that the Page pointers are properly aligned
+ ASSERT_TRUE(is_aligned(range[0].get()));
+ ASSERT_TRUE(is_aligned(range[1].get()));
+ ASSERT_TRUE(is_aligned(range[2].get()));
+ ASSERT_TRUE(is_aligned(range[3].get()));
}
TEST(PageSet, AllocUnaligned)