[coreboot-gerrit] Patch set updated for coreboot: libpayload: Fix CONFIG_LP_DEBUG_MALLOC for 64-bit archs
Julius Werner (jwerner@chromium.org)
gerrit at coreboot.org
Fri May 20 01:35:06 CEST 2016
Julius Werner (jwerner at chromium.org) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/14921
-gerrit
commit 5918f3402291e874df5ea7db680eb4b4c5bdcb57
Author: Julius Werner <jwerner at chromium.org>
Date: Thu May 19 13:15:16 2016 -0700
libpayload: Fix CONFIG_LP_DEBUG_MALLOC for 64-bit archs
New compilers are a little more stringent about defining the same
prototype more than once, so some of our CONFIG_LP_DEBUG_MALLOC wrappers
don't quite work the way they are written anymore. Also, several of the
printf()s weren't written 64-bit safe. And let's add some
double-evaluation safety while I'm here anyway.
Change-Id: Ib54ebc3cfba99f372690365b78c7ceb372c0bd45
Signed-off-by: Julius Werner <jwerner at chromium.org>
---
payloads/libpayload/include/stdlib.h | 67 +++++++++++++++++++-----------------
payloads/libpayload/libc/malloc.c | 6 ++--
2 files changed, 38 insertions(+), 35 deletions(-)
diff --git a/payloads/libpayload/include/stdlib.h b/payloads/libpayload/include/stdlib.h
index 689bf01..2e9de31 100644
--- a/payloads/libpayload/include/stdlib.h
+++ b/payloads/libpayload/include/stdlib.h
@@ -46,98 +46,101 @@
* @{
*/
#if IS_ENABLED(CONFIG_LP_DEBUG_MALLOC) && !defined(IN_MALLOC_C)
+#include <stdio.h>
+void print_malloc_map(void);
+void free(void *);
+void *malloc(size_t);
+void *calloc(size_t,size_t);
+void *realloc(void*,size_t);
+void *memalign(size_t, size_t);
+void *dma_malloc(size_t);
+void *dma_memalign(size_t, size_t);
#define free(p) \
({ \
- extern void print_malloc_map(void); \
- extern void free(void *); \
- printf("free(%p) called from %s:%s:%d...\n", p, __FILE__, __func__, \
+ void * __p = p; \
+ printf("free(%p) called from %s:%s:%d...\n", __p, __FILE__, __func__, \
__LINE__);\
printf("PRE free()\n"); \
print_malloc_map(); \
- free(p); \
+ free(__p); \
printf("POST free()\n"); \
print_malloc_map(); \
})
#define malloc(s) \
({ \
- extern void print_malloc_map(void); \
- extern void *malloc(size_t); \
+ size_t __s = s; \
void *ptr; \
- printf("malloc(%u) called from %s:%s:%d...\n", s, __FILE__, __func__, \
- __LINE__);\
+ printf("malloc(%zu) called from %s:%s:%d...\n", __s, __FILE__, \
+ __func__, __LINE__);\
printf("PRE malloc\n"); \
print_malloc_map(); \
- ptr = malloc(s); \
+ ptr = malloc(__s); \
printf("POST malloc (ptr = %p)\n", ptr); \
print_malloc_map(); \
ptr; \
})
#define calloc(n,s) \
({ \
- extern void print_malloc_map(void); \
- extern void *calloc(size_t,size_t); \
+ size_t __n = n, __s = s; \
void *ptr; \
- printf("calloc(%u, %u) called from %s:%s:%d...\n", n, s, __FILE__, \
- __func__, __LINE__);\
+ printf("calloc(%zu, %zu) called from %s:%s:%d...\n", __n, __s, \
+ __FILE__, __func__, __LINE__);\
printf("PRE calloc\n"); \
print_malloc_map(); \
- ptr = calloc(n,s); \
+ ptr = calloc(__n, __s); \
printf("POST calloc (ptr = %p)\n", ptr); \
print_malloc_map(); \
ptr; \
})
#define realloc(p,s) \
({ \
- extern void print_malloc_map(void); \
- extern void *realloc(void*,size_t); \
+ void *__p = p; \
+ size_t __s = s; \
void *ptr; \
- printf("realloc(%p, %u) called from %s:%s:%d...\n", p, s, __FILE__, \
- __func__, __LINE__);\
+ printf("realloc(%p, %zu) called from %s:%s:%d...\n", __p, __s, \
+ __FILE__, __func__, __LINE__);\
printf("PRE realloc\n"); \
print_malloc_map(); \
- ptr = realloc(p,s); \
+ ptr = realloc(__p, __s); \
printf("POST realloc (ptr = %p)\n", ptr); \
print_malloc_map(); \
ptr; \
})
#define memalign(a,s) \
({ \
- extern void print_malloc_map(void); \
- extern void *memalign(size_t, size_t); \
+ size_t __a = a, __s = s; \
void *ptr; \
- printf("memalign(%u, %u) called from %s:%s:%d...\n", a, s, __FILE__, \
- __func__, __LINE__);\
+ printf("memalign(%zu, %zu) called from %s:%s:%d...\n", __a, __s, \
+ __FILE__, __func__, __LINE__);\
printf("PRE memalign\n"); \
print_malloc_map(); \
- ptr = memalign(a,s); \
+ ptr = memalign(__a, __s); \
printf("POST memalign (ptr = %p)\n", ptr); \
print_malloc_map(); \
ptr; \
})
#define dma_malloc(s) \
({ \
- extern void print_malloc_map(void); \
- extern void *dma_malloc(size_t); \
+ size_t __s = s; \
void *ptr; \
- printf("dma_malloc(%u) called from %s:%s:%d...\n", s, __FILE__, \
+ printf("dma_malloc(%zu) called from %s:%s:%d...\n", __s, __FILE__, \
__func__, __LINE__);\
printf("PRE dma_malloc\n"); \
print_malloc_map(); \
- ptr = dma_malloc(s); \
+ ptr = dma_malloc(__s); \
printf("POST dma_malloc (ptr = %p)\n", ptr); \
print_malloc_map(); \
ptr; \
})
#define dma_memalign(a,s) \
({ \
- extern void print_malloc_map(void); \
- extern void *dma_memalign(size_t, size_t); \
+ size_t __a = a, __s = s; \
void *ptr; \
- printf("dma_memalign(%u, %u) called from %s:%s:%d...\n", a, s, \
+ printf("dma_memalign(%zu, %zu) called from %s:%s:%d...\n", __a, __s, \
__FILE__, __func__, __LINE__);\
printf("PRE dma_memalign\n"); \
print_malloc_map(); \
- ptr = dma_memalign(a,s); \
+ ptr = dma_memalign(__a, __s); \
printf("POST dma_memalign (ptr = %p)\n", ptr); \
print_malloc_map(); \
ptr; \
diff --git a/payloads/libpayload/libc/malloc.c b/payloads/libpayload/libc/malloc.c
index b7ac1a7..873e3f9 100644
--- a/payloads/libpayload/libc/malloc.c
+++ b/payloads/libpayload/libc/malloc.c
@@ -480,7 +480,7 @@ look_further:
if ((reg->alignment == align) && (reg->free >= (size + align - 1)/align))
{
#if IS_ENABLED(CONFIG_LP_DEBUG_MALLOC)
- printf(" found memalign region. %x free, %x required\n", reg->free, (size + align - 1)/align);
+ printf(" found memalign region. %u free, %zu required\n", reg->free, (size + align - 1)/align);
#endif
break;
}
@@ -563,7 +563,7 @@ again:
/* FIXME: Verify the size of the block. */
- printf("%s %x: %s (%x bytes)\n", type->name,
+ printf("%s %x: %s (%llx bytes)\n", type->name,
(unsigned int)(ptr - type->start),
hdr & FLAG_FREE ? "FREE" : "USED", SIZE(hdr));
@@ -575,7 +575,7 @@ again:
if (free_memory && (type->minimal_free > free_memory))
type->minimal_free = free_memory;
- printf("%s: Maximum memory consumption: %u bytes\n", type->name,
+ printf("%s: Maximum memory consumption: %zu bytes\n", type->name,
(type->end - type->start) - HDRSIZE - type->minimal_free);
if (type != dma) {
More information about the coreboot-gerrit
mailing list