2010-09-22 15:10:42 +02:00
|
|
|
/**
|
|
|
|
* simple malloc wrapper for sbrk
|
|
|
|
*
|
|
|
|
* Needed on platforms without malloc in libc, e.g. msb430
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file LICENSE in the top level directory for more details.
|
|
|
|
*
|
|
|
|
* @ingroup kernel
|
|
|
|
* @{
|
|
|
|
* @file
|
|
|
|
* @author Kaspar Schleiser <kaspar.schleiser@fu-berlin.de>
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/unistd.h>
|
2010-12-03 18:42:03 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
#define ENABLE_DEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2013-02-06 13:20:21 +01:00
|
|
|
//extern void *sbrk(int incr);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
void *_malloc(size_t size) {
|
|
|
|
void* ptr = sbrk(size);
|
|
|
|
|
2013-02-06 13:20:21 +01:00
|
|
|
DEBUG("_malloc(): allocating block of size %u at 0x%X.\n", (unsigned int) size, (unsigned int)ptr);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
if (ptr != (void*)-1) {
|
|
|
|
return ptr;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-30 16:07:00 +02:00
|
|
|
void *_realloc(void *ptr, size_t size) {
|
|
|
|
void* newptr = _malloc(size);
|
|
|
|
memcpy(newptr, ptr, size);
|
|
|
|
free(ptr);
|
|
|
|
return newptr;
|
|
|
|
}
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
void _free(void* ptr) {
|
|
|
|
DEBUG("_free(): block at 0x%X lost.\n", (unsigned int)ptr);
|
|
|
|
}
|
|
|
|
|