summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
56471f1)
Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de>
Acked-by: Jordan Crouse <jordan.crouse@amd.com>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3559
2b7e53f0-3cfb-0310-b3e9-
8179ed1497e1
void *malloc(size_t size);
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
void *malloc(size_t size);
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
+void *memalign(size_t align, size_t size);
*((hdrtype_t *) hstart) = FREE_BLOCK(size);
}
*((hdrtype_t *) hstart) = FREE_BLOCK(size);
}
-static void *alloc(int len)
+static void *alloc(int len, int align)
{
hdrtype_t header;
void *ptr = hstart;
{
hdrtype_t header;
void *ptr = hstart;
header = *((hdrtype_t *) ptr);
int size = SIZE(header);
header = *((hdrtype_t *) ptr);
int size = SIZE(header);
- if (!HAS_MAGIC(header) || size == 0) {
+ if (!HAS_MAGIC(header)) {
printf("memory allocator panic.\n");
halt();
}
if (header & FLAG_FREE) {
printf("memory allocator panic.\n");
halt();
}
if (header & FLAG_FREE) {
+ int realaddr = (int)(ptr + HDRSIZE);
+ int overhead = ((realaddr+align-1) & ~(align-1)) - realaddr;
+ if (len + overhead <= size) {
+ if (overhead != 0) {
+ *((hdrtype_t *) ptr) = FREE_BLOCK(overhead - HDRSIZE);
+ ptr += overhead;
+ size -= overhead;
+ }
void *nptr = ptr + (HDRSIZE + len);
int nsize = size - (HDRSIZE + len);
void *nptr = ptr + (HDRSIZE + len);
int nsize = size - (HDRSIZE + len);
void *malloc(size_t size)
{
void *malloc(size_t size)
{
}
void *calloc(size_t nmemb, size_t size)
{
size_t total = nmemb * size;
}
void *calloc(size_t nmemb, size_t size)
{
size_t total = nmemb * size;
- void *ptr = alloc(total);
+ void *ptr = alloc(total, 1);
if (ptr)
memset(ptr, 0, total);
if (ptr)
memset(ptr, 0, total);
unsigned int osize;
if (ptr == NULL)
unsigned int osize;
if (ptr == NULL)
* reallocated the new space.
*/
free(ptr);
* reallocated the new space.
*/
free(ptr);
/*
* if ret == NULL, then doh - failure.
/*
* if ret == NULL, then doh - failure.
+/**
+ * Allocate an aligned chunk of memory
+ *
+ * @param align alignment, must be power of two
+ * @param size size of chunk in bytes
+ * @return Return the address of such a memory region or NULL
+ */
+void *memalign(size_t align, size_t size)
+{
+ return alloc(size, align);
+}
+
/* This is for debugging purposes. */
#ifdef TEST
void print_malloc_map(void)
{
/* This is for debugging purposes. */
#ifdef TEST
void print_malloc_map(void)
{
while (ptr < hend) {
hdrtype_t hdr = *((hdrtype_t *) ptr);
while (ptr < hend) {
hdrtype_t hdr = *((hdrtype_t *) ptr);