summaryrefslogtreecommitdiff
path: root/core/mem
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2013-02-25 15:25:16 +0000
committerMatt Fleming <matt.fleming@intel.com>2013-02-26 11:29:04 +0000
commit76da2ae050d72a31fd47c2fb53f7081781de62ff (patch)
tree6da146b5f19ca17ff24d4e74940f14264d38f914 /core/mem
parent41c29c26d70fde563d7c255872bbadad87a39dfa (diff)
parent79312306de0150ef64213ef9fbc5aa8580544f03 (diff)
downloadsyslinux-76da2ae050d72a31fd47c2fb53f7081781de62ff.tar.gz
Merge branch 'lwip' into elflink
Welcome to Syslinux 5.10. Conflicts: NEWS com32/lib/Makefile com32/lib/sys/open.c com32/lib/syslinux/ipappend.c com32/modules/Makefile com32/modules/prdhcp.c core/Makefile core/cmdline.inc core/com32.inc core/comboot.inc core/configinit.inc core/fs/chdir.c core/fs/fs.c core/fs/pxe/dnsresolv.c core/fs/pxe/pxe.c core/fs/pxe/pxe.h core/idle.c core/include/ctype.h core/init.inc core/mem/init.c core/parseconfig.inc core/runkernel.inc core/syslinux.ld core/ui.inc doc/comboot.txt version
Diffstat (limited to 'core/mem')
-rw-r--r--core/mem/free.c10
-rw-r--r--core/mem/malloc.c7
-rw-r--r--core/mem/malloc.h3
3 files changed, 20 insertions, 0 deletions
diff --git a/core/mem/free.c b/core/mem/free.c
index e8a9b048..d7f912b1 100644
--- a/core/mem/free.c
+++ b/core/mem/free.c
@@ -86,7 +86,9 @@ __export void free(void *ptr)
dprintf("invalid arena type: %d\n", ARENA_TYPE_GET(ah->a.attrs));
#endif
+ sem_down(&__malloc_semaphore, 0);
__free_block(ah);
+ sem_up(&__malloc_semaphore);
/* Here we could insert code to return memory to the system. */
}
@@ -108,6 +110,8 @@ void __inject_free_block(struct free_arena_header *ah)
ARENA_SIZE_GET(ah->a.attrs), ah,
ARENA_HEAP_GET(ah->a.attrs), head);
+ sem_down(&__malloc_semaphore, 0);
+
for (nah = head->a.next ; nah != head ; nah = nah->a.next) {
n_end = (size_t) nah + ARENA_SIZE_GET(nah->a.attrs);
@@ -122,6 +126,7 @@ void __inject_free_block(struct free_arena_header *ah)
printf("conflict:ah: %p, a_end: %p, nah: %p, n_end: %p\n", ah, a_end, nah, n_end);
/* Otherwise we have some sort of overlap - reject this block */
+ sem_up(&__malloc_semaphore);
return;
}
@@ -132,6 +137,8 @@ void __inject_free_block(struct free_arena_header *ah)
ah->a.prev->a.next = ah;
__free_block(ah);
+
+ sem_up(&__malloc_semaphore);
}
/*
@@ -141,6 +148,8 @@ static void __free_tagged(malloc_tag_t tag) {
struct free_arena_header *fp, *head;
int i;
+ sem_down(&__malloc_semaphore, 0);
+
for (i = 0; i < NHEAP; i++) {
dprintf("__free_tagged(%u) heap %d\n", tag, i);
head = &__core_malloc_head[i];
@@ -151,6 +160,7 @@ static void __free_tagged(malloc_tag_t tag) {
}
}
+ sem_up(&__malloc_semaphore);
dprintf("__free_tagged(%u) done\n", tag);
}
diff --git a/core/mem/malloc.c b/core/mem/malloc.c
index 6cd3b33d..f64850d1 100644
--- a/core/mem/malloc.c
+++ b/core/mem/malloc.c
@@ -12,6 +12,9 @@
#include <minmax.h>
#include "malloc.h"
+#include "thread.h"
+
+DECLARE_INIT_SEMAPHORE(__malloc_semaphore, 1);
static void *__malloc_from_block(struct free_arena_header *fp,
size_t size, malloc_tag_t tag)
@@ -72,6 +75,8 @@ static void *_malloc(size_t size, enum heap heap, malloc_tag_t tag)
dprintf("_malloc(%zu, %u, %u) @ %p = ",
size, heap, tag, __builtin_return_address(0));
+ sem_down(&__malloc_semaphore, 0);
+
if (size) {
/* Add the obligatory arena header, and round up */
size = (size + 2 * sizeof(struct arena_header) - 1) & ARENA_SIZE_MASK;
@@ -85,6 +90,8 @@ static void *_malloc(size_t size, enum heap heap, malloc_tag_t tag)
}
}
+ sem_up(&__malloc_semaphore);
+
dprintf("%p\n", p);
return p;
}
diff --git a/core/mem/malloc.h b/core/mem/malloc.h
index d0d135bc..4611a306 100644
--- a/core/mem/malloc.h
+++ b/core/mem/malloc.h
@@ -7,6 +7,9 @@
#include <stdint.h>
#include <stddef.h>
#include "core.h"
+#include "thread.h"
+
+extern struct semaphore __malloc_semaphore;
/*
* This is a temporary hack. In Syslinux 5 this will be a pointer to