summaryrefslogtreecommitdiffstats
path: root/libc/stdlib/malloc
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdlib/malloc')
-rw-r--r--libc/stdlib/malloc/calloc.c2
-rw-r--r--libc/stdlib/malloc/free.c2
-rw-r--r--libc/stdlib/malloc/heap.h5
-rw-r--r--libc/stdlib/malloc/heap_alloc.c2
-rw-r--r--libc/stdlib/malloc/heap_alloc_at.c2
-rw-r--r--libc/stdlib/malloc/heap_debug.c2
-rw-r--r--libc/stdlib/malloc/heap_free.c2
-rw-r--r--libc/stdlib/malloc/malloc.c2
-rw-r--r--libc/stdlib/malloc/malloc.h20
-rw-r--r--libc/stdlib/malloc/malloc_debug.c2
-rw-r--r--libc/stdlib/malloc/realloc.c2
11 files changed, 26 insertions, 17 deletions
diff --git a/libc/stdlib/malloc/calloc.c b/libc/stdlib/malloc/calloc.c
index 5925a9e0a..79e6ec6c7 100644
--- a/libc/stdlib/malloc/calloc.c
+++ b/libc/stdlib/malloc/calloc.c
@@ -22,7 +22,7 @@
#include <string.h>
#include <errno.h>
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
void * calloc(size_t nmemb, size_t lsize)
{
diff --git a/libc/stdlib/malloc/free.c b/libc/stdlib/malloc/free.c
index 81c718376..da395331b 100644
--- a/libc/stdlib/malloc/free.c
+++ b/libc/stdlib/malloc/free.c
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
diff --git a/libc/stdlib/malloc/heap.h b/libc/stdlib/malloc/heap.h
index b66b5ecef..38ec41cbf 100644
--- a/libc/stdlib/malloc/heap.h
+++ b/libc/stdlib/malloc/heap.h
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
@@ -17,6 +17,7 @@
/* On multi-threaded systems, the heap includes a lock. */
#ifdef __UCLIBC_HAS_THREADS__
# include <pthread.h>
+# include <bits/uClibc_pthread.h>
# define HEAP_USE_LOCKING
#endif
@@ -24,7 +25,7 @@
/* The heap allocates in multiples of, and aligned to, HEAP_GRANULARITY.
HEAP_GRANULARITY must be a power of 2. Malloc depends on this being the
same as MALLOC_ALIGNMENT. */
-#define HEAP_GRANULARITY_TYPE double
+#define HEAP_GRANULARITY_TYPE double __attribute_aligned__ (sizeof (size_t))
#define HEAP_GRANULARITY (__alignof__ (HEAP_GRANULARITY_TYPE))
diff --git a/libc/stdlib/malloc/heap_alloc.c b/libc/stdlib/malloc/heap_alloc.c
index 8a6c7842e..f8d596506 100644
--- a/libc/stdlib/malloc/heap_alloc.c
+++ b/libc/stdlib/malloc/heap_alloc.c
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
diff --git a/libc/stdlib/malloc/heap_alloc_at.c b/libc/stdlib/malloc/heap_alloc_at.c
index de84e99ee..296c6e552 100644
--- a/libc/stdlib/malloc/heap_alloc_at.c
+++ b/libc/stdlib/malloc/heap_alloc_at.c
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
diff --git a/libc/stdlib/malloc/heap_debug.c b/libc/stdlib/malloc/heap_debug.c
index e83831d3a..a2a9f4ec1 100644
--- a/libc/stdlib/malloc/heap_debug.c
+++ b/libc/stdlib/malloc/heap_debug.c
@@ -49,7 +49,7 @@ __heap_dump_freelist (struct heap *heap)
void
__heap_dump (struct heap *heap, const char *str)
{
- static int recursed = 0;
+ static smallint recursed;
if (! recursed)
{
diff --git a/libc/stdlib/malloc/heap_free.c b/libc/stdlib/malloc/heap_free.c
index a4b5259af..8bc740dd8 100644
--- a/libc/stdlib/malloc/heap_free.c
+++ b/libc/stdlib/malloc/heap_free.c
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c
index 770d7aea3..ce74c5608 100644
--- a/libc/stdlib/malloc/malloc.c
+++ b/libc/stdlib/malloc/malloc.c
@@ -184,7 +184,7 @@ malloc (size_t size)
{
void *mem;
#ifdef MALLOC_DEBUGGING
- static int debugging_initialized = 0;
+ static smallint debugging_initialized;
if (! debugging_initialized)
{
debugging_initialized = 1;
diff --git a/libc/stdlib/malloc/malloc.h b/libc/stdlib/malloc/malloc.h
index b41c4b08e..7277cd2cf 100644
--- a/libc/stdlib/malloc/malloc.h
+++ b/libc/stdlib/malloc/malloc.h
@@ -11,8 +11,13 @@
* Written by Miles Bader <miles@gnu.org>
*/
-/* The alignment we guarantee for malloc return values. */
-#define MALLOC_ALIGNMENT (__alignof__ (double))
+/* The alignment we guarantee for malloc return values. We prefer this
+ to be at least sizeof (size_t) bytes because (a) we have to allocate
+ that many bytes for the header anyway and (b) guaranteeing word
+ alignment can be a significant win on targets like m68k and Coldfire,
+ where __alignof__(double) == 2. */
+#define MALLOC_ALIGNMENT \
+ __alignof__ (double __attribute_aligned__ (sizeof (size_t)))
/* The system pagesize... */
extern size_t __pagesize;
@@ -79,7 +84,6 @@ extern struct heap __malloc_mmb_heap;
to stderr, when the variable __malloc_mmb_debug is set to true. */
#ifdef MALLOC_MMB_DEBUGGING
# include <stdio.h>
-extern int __putc(int c, FILE *stream) attribute_hidden;
extern int __malloc_mmb_debug;
# define MALLOC_MMB_DEBUG(indent, fmt, args...) \
@@ -98,17 +102,20 @@ extern int __malloc_mmb_debug;
/* The size of a malloc allocation is stored in a size_t word
- MALLOC_ALIGNMENT bytes prior to the start address of the allocation:
+ MALLOC_HEADER_SIZE bytes prior to the start address of the allocation:
+--------+---------+-------------------+
| SIZE |(unused) | allocation ... |
+--------+---------+-------------------+
^ BASE ^ ADDR
- ^ ADDR - MALLOC_ALIGN
+ ^ ADDR - MALLOC_HEADER_SIZE
*/
/* The amount of extra space used by the malloc header. */
-#define MALLOC_HEADER_SIZE MALLOC_ALIGNMENT
+#define MALLOC_HEADER_SIZE \
+ (MALLOC_ALIGNMENT < sizeof (size_t) \
+ ? sizeof (size_t) \
+ : MALLOC_ALIGNMENT)
/* Set up the malloc header, and return the user address of a malloc block. */
#define MALLOC_SETUP(base, size) \
@@ -126,6 +133,7 @@ extern int __malloc_mmb_debug;
#ifdef __UCLIBC_HAS_THREADS__
# include <pthread.h>
+# include <bits/uClibc_pthread.h>
# define MALLOC_USE_LOCKING
diff --git a/libc/stdlib/malloc/malloc_debug.c b/libc/stdlib/malloc/malloc_debug.c
index 6c74d78bb..39c3919c5 100644
--- a/libc/stdlib/malloc/malloc_debug.c
+++ b/libc/stdlib/malloc/malloc_debug.c
@@ -7,7 +7,7 @@
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License. See the file COPYING.LIB in the main
* directory of this archive for more details.
- *
+ *
* Written by Miles Bader <miles@gnu.org>
*/
diff --git a/libc/stdlib/malloc/realloc.c b/libc/stdlib/malloc/realloc.c
index ec57b874e..948326762 100644
--- a/libc/stdlib/malloc/realloc.c
+++ b/libc/stdlib/malloc/realloc.c
@@ -15,7 +15,7 @@
#include <string.h>
#include <errno.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
#include "malloc.h"
#include "heap.h"