commit 7b508fec7d430478e9c4d534ce0f7fa9d461f2bc
parent 146817d152c4279e0d21eca1289b6c321cfdb65d
Author: sin <sin@2f30.org>
Date: Sun, 4 Aug 2013 17:33:59 +0100
Implement align_pointer()
Diffstat:
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/lemoncake.c b/lemoncake.c
@@ -87,6 +87,12 @@ at_cmp(struct node *a, struct node *b)
}
static inline void *
+align_pointer(size_t align, void *p)
+{
+ return (void *)(((uintptr_t)p + align) & ~(align - 1));
+}
+
+static inline void *
alloc_object(size_t siz)
{
void *base, *p;
@@ -95,9 +101,8 @@ alloc_object(size_t siz)
if (base == (void *)-1)
return NULL;
p = base;
- p = (void *)(((uintptr_t)p + ALIGN) & ~(ALIGN - 1));
st.nr_sbrk++;
- return p;
+ return align_pointer(ALIGN, p);
}
static inline void *
@@ -112,9 +117,8 @@ mmap_aligned(size_t align, size_t siz)
MAP_PRIVATE | MAP_ANON, -1, 0);
if (p == MAP_FAILED)
return NULL;
- p = (void *)(((uintptr_t)p + align) & ~(align - 1));
st.nr_mmap++;
- return p;
+ return align_pointer(align, p);
}
static int