topdir = ../..
include ../MCONFIG
-MODULES = test_memalign.c32 # test_com32.c32
-
+MODULES =
TESTFILES =
all: $(MODULES) $(TESTFILES)
+++ /dev/null
-#include <stdio.h>
-#include <stdlib.h>
-#include <console.h>
-#include <errno.h>
-
-void perform_allocation(size_t align)
-{
- int res = 0;
- int size = 100;
- void *ptr;
-
- printf("Allocation aligned at %#zx bytes: ", align);
- res = posix_memalign(&ptr, align, size);
-
- switch (res) {
- case 0:
- printf("address %p\n", ptr);
- break;
- case EINVAL:
- printf("EINVAL\n");
- break;
- case ENOMEM:
- printf("ENOMEM\n");
- break;
- }
-}
-
-int main(void)
-{
- size_t align = 0x10000;
-
- // Open a standard r/w console
- openconsole(&dev_stdcon_r, &dev_stdcon_w);
-
- while (align >= sizeof(void *)) {
- perform_allocation(align);
- align /= 2;
- }
-
- printf("\n");
-
- while (align <= 0x10000) {
- perform_allocation(align);
- align *= 2;
- }
-
- return 0;
-}
+++ /dev/null
-/*
- * malloc.h
- *
- * Internals for the memory allocator
- */
-
-#include <stdint.h>
-#include <stddef.h>
-
-/*
- * This is the minimum chunk size we will ask the kernel for; this should
- * be a multiple of the page size on all architectures.
- */
-#define MALLOC_CHUNK_SIZE 65536
-#define MALLOC_CHUNK_MASK (MALLOC_CHUNK_SIZE-1)
-
-/*
- * This structure should be a power of two. This becomes the
- * alignment unit.
- */
-struct free_arena_header;
-
-struct arena_header {
- size_t type;
- size_t size; /* Also gives the location of the next entry */
- struct free_arena_header *next, *prev;
-};
-
-#ifdef DEBUG_MALLOC
-#define ARENA_TYPE_USED 0x64e69c70
-#define ARENA_TYPE_FREE 0x012d610a
-#define ARENA_TYPE_HEAD 0x971676b5
-#define ARENA_TYPE_DEAD 0xeeeeeeee
-#else
-#define ARENA_TYPE_USED 0
-#define ARENA_TYPE_FREE 1
-#define ARENA_TYPE_HEAD 2
-#endif
-
-#define ARENA_SIZE_MASK (~(uintptr_t)(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))
-
-/*
- * This structure should be no more than twice the size of the
- * previous structure.
- */
-struct free_arena_header {
- struct arena_header a;
- struct free_arena_header *next_free, *prev_free;
-};
-
-extern struct free_arena_header __malloc_head;
-void __inject_free_block(struct free_arena_header *ah);
return h & 0xFFFFFFFF;
}
-#ifdef ELF_NO_POSIX_MEMALIGN
+#ifndef HAVE_ELF_POSIX_MEMALIGN
struct memalign_info {
void *start_addr;
free(memptr);
}
-#endif //ELF_NO_POSIX_MEMALIGN
+#endif //HAVE_ELF_POSIX_MEMALIGN
printf("\n\n");
}
-/*
-void mydump(void)
-{
- printf("append buf at %x\n", AppendBuf);
-
- hexdump(AppendBuf, 60, "appendbuf");
-}
-*/
-
static inline void myprint(int num)
{
uint32_t i;
return ptr;
}
-
-/* need to revisit this later */
-int posix_memalign(void **memptr, size_t align, size_t size)
-{
- void *ptr;
- unsigned long tmp;
-
- ptr = malloc(size + align - 1);
- if (!ptr)
- return -ENOMEM;
-
- /* do the alignment */
- tmp = (unsigned long)ptr;
- tmp = (tmp + align -1) & ~(align - 1);
- ptr = (void *)tmp;
-
- *memptr = ptr;
- return 0;
-
-}