|
@@ -58,18 +58,18 @@ inline void* operator new[](size_t, void* p) { return p; }
|
|
|
template<size_t ALIGNMENT>
|
|
|
[[gnu::malloc, gnu::returns_nonnull, gnu::alloc_size(1)]] inline void* kmalloc_aligned(size_t size)
|
|
|
{
|
|
|
- static_assert(ALIGNMENT > 1);
|
|
|
- static_assert(ALIGNMENT < 255);
|
|
|
- void* ptr = kmalloc(size + ALIGNMENT + sizeof(u8));
|
|
|
+ static_assert(ALIGNMENT > sizeof(ptrdiff_t));
|
|
|
+ static_assert(ALIGNMENT <= 4096);
|
|
|
+ void* ptr = kmalloc(size + ALIGNMENT + sizeof(ptrdiff_t));
|
|
|
size_t max_addr = (size_t)ptr + ALIGNMENT;
|
|
|
void* aligned_ptr = (void*)(max_addr - (max_addr % ALIGNMENT));
|
|
|
- ((u8*)aligned_ptr)[-1] = (u8)((u8*)aligned_ptr - (u8*)ptr);
|
|
|
+ ((ptrdiff_t*)aligned_ptr)[-1] = (ptrdiff_t)((u8*)aligned_ptr - (u8*)ptr);
|
|
|
return aligned_ptr;
|
|
|
}
|
|
|
|
|
|
inline void kfree_aligned(void* ptr)
|
|
|
{
|
|
|
- kfree((u8*)ptr - ((u8*)ptr)[-1]);
|
|
|
+ kfree((u8*)ptr - ((const ptrdiff_t*)ptr)[-1]);
|
|
|
}
|
|
|
|
|
|
void kmalloc_enable_expand();
|