From c854c3a8224da9dfa30d583edef6bc1b92b17aeb Mon Sep 17 00:00:00 2001 From: hpa Date: Sat, 18 Dec 2004 22:56:01 +0000 Subject: [PATCH] Fix handling of alignment issues --- com32/lib/malloc.c | 2 +- com32/lib/malloc.h | 6 +++--- com32/modules/Makefile | 2 +- dos/malloc.c | 6 +++--- dos/malloc.h | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/com32/lib/malloc.c b/com32/lib/malloc.c index e7a1cdc..8f6d97d 100644 --- a/com32/lib/malloc.c +++ b/com32/lib/malloc.c @@ -105,7 +105,7 @@ void *malloc(size_t size) return NULL; /* Add the obligatory arena header, and round up */ - size = (size+2*sizeof(struct arena_header)-1) & ARENA_SIZE_MASK; + size = (size+2*sizeof(struct arena_header)-1) & ~ARENA_SIZE_MASK; for ( fp = __malloc_head.next_free ; fp->a.type != ARENA_TYPE_HEAD ; fp = fp->next_free ) { diff --git a/com32/lib/malloc.h b/com32/lib/malloc.h index 57b7652..70d0e63 100644 --- a/com32/lib/malloc.h +++ b/com32/lib/malloc.h @@ -37,10 +37,10 @@ struct arena_header { #define ARENA_TYPE_HEAD 2 #endif -#define ARENA_SIZE_MASK (~(sizeof(struct arena_header)-1)) +#define ARENA_SIZE_MASK (sizeof(struct arena_header)-1) -#define ARENA_ALIGN_UP(p) ((char *)(((uintptr_t)(p) + ARENA_SIZE_MASK) & ARENA_SIZE_MASK)) -#define ARENA_ALIGN_DOWN(p) ((char *)((uintptr_t)(p) & ARENA_SIZE_MASK)) +#define ARENA_ALIGN_UP(p) ((char *)(((uintptr_t)(p) + ARENA_SIZE_MASK) & ~ARENA_SIZE_MASK)) +#define ARENA_ALIGN_DOWN(p) ((char *)((uintptr_t)(p) & ~ARENA_SIZE_MASK)) /* * This structure should be no more than twice the size of the diff --git a/com32/modules/Makefile b/com32/modules/Makefile index e5d1dfa..4b6f335 100644 --- a/com32/modules/Makefile +++ b/com32/modules/Makefile @@ -45,7 +45,7 @@ AUXDIR = $(LIBDIR)/syslinux INCDIR = /usr/include COM32DIR = $(AUXDIR)/com32 -MODULES = chain.c32 +MODULES = chain.c32 menu.c32 menu.lnx all: $(MODULES) diff --git a/dos/malloc.c b/dos/malloc.c index 8d37b5d..499d551 100644 --- a/dos/malloc.c +++ b/dos/malloc.c @@ -24,8 +24,8 @@ const size_t __stack_size = 4096; static inline size_t sp(void) { - uint16_t sp; - asm volatile("movw %%sp,%0" : "=rm" (sp)); + uint32_t sp; + asm volatile("movl %%esp,%0" : "=rm" (sp)); return sp; } @@ -99,7 +99,7 @@ void *malloc(size_t size) return NULL; /* Add the obligatory arena header, and round up */ - size = (size+2*sizeof(struct arena_header)-1) & ARENA_SIZE_MASK; + size = (size+2*sizeof(struct arena_header)-1) & ~ARENA_SIZE_MASK; for ( fp = __malloc_head.next_free ; fp->a.type != ARENA_TYPE_HEAD ; fp = fp->next_free ) { diff --git a/dos/malloc.h b/dos/malloc.h index 57b7652..70d0e63 100644 --- a/dos/malloc.h +++ b/dos/malloc.h @@ -37,10 +37,10 @@ struct arena_header { #define ARENA_TYPE_HEAD 2 #endif -#define ARENA_SIZE_MASK (~(sizeof(struct arena_header)-1)) +#define ARENA_SIZE_MASK (sizeof(struct arena_header)-1) -#define ARENA_ALIGN_UP(p) ((char *)(((uintptr_t)(p) + ARENA_SIZE_MASK) & ARENA_SIZE_MASK)) -#define ARENA_ALIGN_DOWN(p) ((char *)((uintptr_t)(p) & ARENA_SIZE_MASK)) +#define ARENA_ALIGN_UP(p) ((char *)(((uintptr_t)(p) + ARENA_SIZE_MASK) & ~ARENA_SIZE_MASK)) +#define ARENA_ALIGN_DOWN(p) ((char *)((uintptr_t)(p) & ~ARENA_SIZE_MASK)) /* * This structure should be no more than twice the size of the -- 2.7.4