MSRC2=atexit.c
MOBJ2=atexit.o on_exit.o __exit_handler.o exit.o
-
CSRC = abort.c getenv.c mkdtemp.c mktemp.c realpath.c mkstemp.c mkstemp64.c \
- rand.c random.c random_r.c setenv.c system.c div.c ldiv.c \
- getpt.c ptsname.c grantpt.c unlockpt.c gcvt.c drand48.c \
- drand48-iter.c drand48_r.c erand48.c erand48_r.c jrand48.c \
- jrand48_r.c lrand48.c lrand48_r.c mrand48.c mrand48_r.c \
- nrand48.c nrand48_r.c rand_r.c srand48.c srand48_r.c calloc.c \
- valloc.c
+ rand.c random.c random_r.c setenv.c system.c div.c ldiv.c getpt.c \
+ ptsname.c grantpt.c unlockpt.c gcvt.c drand48.c drand48-iter.c \
+ drand48_r.c erand48.c erand48_r.c jrand48.c jrand48_r.c lrand48.c \
+ lrand48_r.c mrand48.c mrand48_r.c nrand48.c nrand48_r.c rand_r.c \
+ srand48.c srand48_r.c calloc.c valloc.c
ifeq ($(HAS_FLOATING_POINT),true)
CSRC += strtod.c strtof.c strtold.c
endif
include $(TOPDIR)Rules.mak
# calloc.c can be found at uClibc/libc/stdlib/calloc.c
+# valloc.c can be found at uClibc/libc/stdlib/valloc.c
CSRC=malloc.c
COBJS=$(patsubst %.c,%.o, $(CSRC))
OBJS=$(COBJS)
/* Are we experienced? */
static int initialized;
+/* List of blocks allocated with memalign or valloc */
+struct alignlist
+{
+ struct alignlist *next;
+ __ptr_t aligned; /* The address that memaligned returned. */
+ __ptr_t exact; /* The address that malloc returned. */
+};
+static struct alignlist *_aligned_blocks;
/* Aligned allocation.
return result;
}
-
-
/* Return memory to the heap. */
void free(void *ptr)
{
+ struct alignlist *l;
+
+ if (ptr == NULL)
+ return;
+
LOCK;
+ for (l = _aligned_blocks; l != NULL; l = l->next) {
+ if (l->aligned == ptr) {
+ /* Mark the block as free */
+ l->aligned = NULL;
+ ptr = l->exact;
+ break;
+ }
+ }
+
free_unlocked(ptr);
UNLOCK;
}
if (ptr == NULL)
return;
+
block = BLOCK(ptr);
switch (type = _heapinfo[block].busy.type) {
UNLOCK;
}
+__ptr_t memalign (size_t alignment, size_t size)
+{
+ __ptr_t result;
+ unsigned long int adj;
+
+ result = malloc (size + alignment - 1);
+ if (result == NULL)
+ return NULL;
+ adj = (unsigned long int) ((unsigned long int) ((char *) result -
+ (char *) NULL)) % alignment;
+ if (adj != 0)
+ {
+ struct alignlist *l;
+ LOCK;
+ for (l = _aligned_blocks; l != NULL; l = l->next)
+ if (l->aligned == NULL)
+ /* This slot is free. Use it. */
+ break;
+ if (l == NULL)
+ {
+ l = (struct alignlist *) malloc (sizeof (struct alignlist));
+ if (l == NULL) {
+ free_unlocked (result);
+ UNLOCK;
+ return NULL;
+ }
+ l->next = _aligned_blocks;
+ _aligned_blocks = l;
+ }
+ l->exact = result;
+ result = l->aligned = (char *) result + alignment - adj;
+ UNLOCK;
+ }
+
+ return result;
+}
+
or (US mail) as Mike Haertel c/o Free Software Foundation. */
#include <stdlib.h>
-#include "malloc.h"
-
-#ifdef emacs
-#include "config.h"
-#endif
-
-#ifdef __GNU_LIBRARY__
-extern size_t __getpagesize __P ((void));
-#else
-#ifndef USG
-extern size_t getpagesize __P ((void));
-#define __getpagesize() getpagesize()
-#else
-#include <sys/param.h>
-#ifdef EXEC_PAGESIZE
-#define __getpagesize() EXEC_PAGESIZE
-#else /* No EXEC_PAGESIZE. */
-#ifdef NBPG
-#ifndef CLSIZE
-#define CLSIZE 1
-#endif /* No CLSIZE. */
-#define __getpagesize() (NBPG * CLSIZE)
-#else /* No NBPG. */
-#define __getpagesize() NBPC
-#endif /* NBPG. */
-#endif /* EXEC_PAGESIZE. */
-#endif /* USG. */
-#endif
+#include <unistd.h>
static size_t pagesize;
__ptr_t valloc (size_t size)
{
if (pagesize == 0)
- pagesize = __getpagesize ();
+ pagesize = getpagesize ();
- return memalign (pagesize, size);
+ return memalign(pagesize, size);
}