aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Bucur <stefanb@zytor.com>2008-07-21 21:59:51 -0700
committerStefan Bucur <stefan@stefan-ubumac.(none)>2009-03-15 10:03:13 +0200
commit9c13daa87966de47de29b3fa317001bb19c54aed (patch)
tree8ac67e8e57ed8b875912a18191de476b5ebe132f
parent8e1a02afe4ed103b474142d725f8e1ee0d9ea56b (diff)
downloadsyslinux-elf-9c13daa87966de47de29b3fa317001bb19c54aed.tar.gz
syslinux-elf-9c13daa87966de47de29b3fa317001bb19c54aed.tar.xz
syslinux-elf-9c13daa87966de47de29b3fa317001bb19c54aed.zip
Made a test module and fixed a silly bug in posix_memalign().
-rw-r--r--com32/elflink/elflink.c43
-rw-r--r--com32/lib/malloc.c4
2 files changed, 45 insertions, 2 deletions
diff --git a/com32/elflink/elflink.c b/com32/elflink/elflink.c
index 22b0db5d..0f373393 100644
--- a/com32/elflink/elflink.c
+++ b/com32/elflink/elflink.c
@@ -1,6 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <console.h>
+#include <errno.h>
+
#include "elf_module.h"
+void perform_allocation(int align) {
+ int res = 0;
+ int size = 100;
+ void *ptr;
+
+ printf("Allocation aligned at 0x%05X bytes: ", align);
+ res = posix_memalign(&ptr, align, size);
+
+ switch (res) {
+ case 0:
+ printf("address 0x%08X\n", ptr);
+ break;
+ case EINVAL:
+ printf("EINVAL\n");
+ break;
+ case ENOMEM:
+ printf("ENOMEM\n");
+ break;
+ }
+}
+
int main(int argc, char **argv) {
+ int 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;
}
diff --git a/com32/lib/malloc.c b/com32/lib/malloc.c
index 5841ad13..f5b1cc99 100644
--- a/com32/lib/malloc.c
+++ b/com32/lib/malloc.c
@@ -160,7 +160,7 @@ int posix_memalign(void **memptr, size_t alignment, size_t size) {
} else {
align_addr = (align_addr + alignment - 1) & align_mask;
}
- if (align_addr - (uintptr_t)fp < 2*sizeof(struct arena_header))
+ if (align_addr - (uintptr_t)fp == 2*sizeof(struct arena_header))
align_addr += alignment;
// See if now we have enough space
@@ -190,7 +190,7 @@ int posix_memalign(void **memptr, size_t alignment, size_t size) {
} else {
*memptr = __malloc_from_block(fp, size + sizeof(struct arena_header));
}
-
+ break;
}
if (*memptr == NULL)