mirror of
https://github.com/usatiuk/ficus.git
synced 2025-10-29 00:27:52 +01:00
kmalloc returns aligned memory
This commit is contained in:
@@ -84,6 +84,15 @@ struct HeapEntry *split_entry(struct HeapEntry *what, size_t n) {
|
||||
|
||||
void *kmalloc(size_t n) {
|
||||
assert(initialized);
|
||||
|
||||
if ((n & 0xFULL) != 0) {
|
||||
size_t origN = n;
|
||||
n += 15;
|
||||
n &= ~0xFULL;
|
||||
assert(n > origN);
|
||||
}
|
||||
assert((n & 0xFULL) == 0);
|
||||
|
||||
struct HeapEntry *res = NULL;
|
||||
{
|
||||
LockGuard l(kmem_lock);
|
||||
@@ -182,6 +191,8 @@ void *kmalloc(size_t n) {
|
||||
res->prev = NULL;
|
||||
res->magic = KERN_HeapMagicTaken;
|
||||
}
|
||||
assert((((uintptr_t) res->data) & 0xFULL) == 0);
|
||||
|
||||
for (size_t i = 0; i < n; i++) res->data[i] = 0xFEU;
|
||||
used.fetch_add(n);
|
||||
return res->data;
|
||||
|
||||
@@ -15,8 +15,8 @@ struct HeapEntry {
|
||||
struct HeapEntry *next;
|
||||
struct HeapEntry *prev;
|
||||
uint64_t len;
|
||||
char data[];
|
||||
};
|
||||
char data[] __attribute__((aligned(16)));
|
||||
} __attribute__((packed, aligned(32)));
|
||||
|
||||
extern struct HeapEntry *KERN_HeapBegin;
|
||||
extern uintptr_t KERN_HeapEnd;// Past the end
|
||||
|
||||
@@ -182,6 +182,8 @@ struct Task *new_ktask(void (*fn)(), const char *name) {
|
||||
strcpy(name, newt->name);
|
||||
|
||||
newt->frame.sp = ((((uintptr_t) newt->stack) + TASK_SS - 1) & (~0xFULL));// Ensure 16byte alignment
|
||||
assert((newt->frame.sp & 0xFULL) == 0);
|
||||
|
||||
newt->frame.ip = (uint64_t) fn;
|
||||
newt->frame.cs = GDTSEL(gdt_code);
|
||||
newt->frame.ss = GDTSEL(gdt_data);
|
||||
|
||||
Reference in New Issue
Block a user