diff options
author | Marvin Borner | 2020-11-14 22:27:59 +0100 |
---|---|---|
committer | Marvin Borner | 2020-11-14 22:27:59 +0100 |
commit | 0621c44e439bedf034399e1bff139ef506039eba (patch) | |
tree | 68e69323391e5c4725fa6ef2d16e17e6664011b4 /libc | |
parent | 1af60d64fb97cfadab39b9d3e86248473cac0693 (diff) |
Some fixes
I WAS BUG-SEARCHING FOR SEVERAL HOURS
WHYYYY, WHEEERE, AAAAAH
Diffstat (limited to 'libc')
-rw-r--r-- | libc/mem.c | 50 |
1 files changed, 25 insertions, 25 deletions
@@ -58,29 +58,29 @@ int memcmp(const void *s1, const void *s2, u32 n) #ifdef kernel -/* #define ALIGNMENT 1ul */ -/* #define ALIGN_TYPE char */ -/* #define ALIGN_INFO sizeof(ALIGN_TYPE) * 16 */ - -/* #define ALIGN(ptr) \ */ -/* if (ALIGNMENT > 1) { \ */ -/* u32 diff; \ */ -/* ptr = (void *)((u32)ptr + ALIGN_INFO); \ */ -/* diff = (u32)ptr & (ALIGNMENT - 1); \ */ -/* if (diff != 0) { \ */ -/* diff = ALIGNMENT - diff; \ */ -/* ptr = (void *)((u32)ptr + diff); \ */ -/* } \ */ -/* *((ALIGN_TYPE *)((u32)ptr - ALIGN_INFO)) = diff + ALIGN_INFO; \ */ -/* } */ - -/* #define UNALIGN(ptr) \ */ -/* if (ALIGNMENT > 1) { \ */ -/* u32 diff = *((ALIGN_TYPE *)((u32)ptr - ALIGN_INFO)); \ */ -/* if (diff < (ALIGNMENT + ALIGN_INFO)) { \ */ -/* ptr = (void *)((u32)ptr - diff); \ */ -/* } \ */ -/* } */ +#define ALIGNMENT 16ul +#define ALIGN_TYPE char +#define ALIGN_INFO sizeof(ALIGN_TYPE) * 16 + +#define ALIGN(ptr) \ + if (ALIGNMENT > 1) { \ + u32 diff; \ + ptr = (void *)((u32)ptr + ALIGN_INFO); \ + diff = (u32)ptr & (ALIGNMENT - 1); \ + if (diff != 0) { \ + diff = ALIGNMENT - diff; \ + ptr = (void *)((u32)ptr + diff); \ + } \ + *((ALIGN_TYPE *)((u32)ptr - ALIGN_INFO)) = diff + ALIGN_INFO; \ + } + +#define UNALIGN(ptr) \ + if (ALIGNMENT > 1) { \ + u32 diff = *((ALIGN_TYPE *)((u32)ptr - ALIGN_INFO)); \ + if (diff < (ALIGNMENT + ALIGN_INFO)) { \ + ptr = (void *)((u32)ptr - diff); \ + } \ + } static u32 *heap; static u32 index; @@ -110,13 +110,13 @@ void *malloc(u32 size) if (size < 1) return NULL; - /* size = size + ALIGNMENT + ALIGN_INFO; */ + size = size + ALIGNMENT + ALIGN_INFO; heap[index] = size; index += size + 1; void *p = (void *)(heap + index - size); - /* ALIGN(p); */ + ALIGN(p); return p; } |