From 24fad01755d33e6772ea3be56b702570bf257d55 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 4 Feb 2013 13:44:14 -0800 Subject: [PATCH] Document the mallinfo struct, add missing attributes. Change-Id: Ia97acce1f6a83bd8b3ba8dd20efd962bc96f35a9 --- libc/include/malloc.h | 36 ++++++++++++++++++------------------ libc/include/sys/cdefs.h | 6 ++++++ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/libc/include/malloc.h b/libc/include/malloc.h index ec21926c9..8875e542d 100644 --- a/libc/include/malloc.h +++ b/libc/include/malloc.h @@ -27,30 +27,30 @@ __BEGIN_DECLS -extern __mallocfunc void* malloc(size_t); -extern __mallocfunc void* calloc(size_t, size_t); -extern void* realloc(void *, size_t); -extern void free(void *); +extern void* malloc(size_t byte_count) __mallocfunc __wur; +extern void* calloc(size_t item_count, size_t item_size) __mallocfunc __wur; +extern void* realloc(void* p, size_t byte_count) __wur; +extern void free(void* p); -extern void* memalign(size_t alignment, size_t bytesize); -extern size_t malloc_usable_size(void*); +extern void* memalign(size_t alignment, size_t byte_count) __mallocfunc __wur; +extern size_t malloc_usable_size(void* p); -extern void* valloc(size_t bytesize); -extern void* pvalloc(size_t bytesize); +extern void* valloc(size_t byte_count) __mallocfunc __wur; +extern void* pvalloc(size_t byte_count) __mallocfunc __wur; #ifndef STRUCT_MALLINFO_DECLARED #define STRUCT_MALLINFO_DECLARED 1 struct mallinfo { - size_t arena; - size_t ordblks; - size_t smblks; - size_t hblks; - size_t hblkhd; - size_t usmblks; - size_t fsmblks; - size_t uordblks; - size_t fordblks; - size_t keepcost; + size_t arena; /* Total number of non-mmapped bytes currently allocated from OS. */ + size_t ordblks; /* Number of free chunks. */ + size_t smblks; /* (Unused.) */ + size_t hblks; /* (Unused.) */ + size_t hblkhd; /* Total number of bytes in mmapped regions. */ + size_t usmblks; /* Maximum total allocated space; greater than total if trimming has occurred. */ + size_t fsmblks; /* (Unused.) */ + size_t uordblks; /* Total allocated space (normal or mmapped.) */ + size_t fordblks; /* Total free space. */ + size_t keepcost; /* Upper bound on number of bytes releasable by malloc_trim. */ }; #endif /* STRUCT_MALLINFO_DECLARED */ diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h index 937abe0c0..aa65b546c 100644 --- a/libc/include/sys/cdefs.h +++ b/libc/include/sys/cdefs.h @@ -321,6 +321,12 @@ #define __always_inline #endif +#if __GNUC_PREREQ__(3, 4) +#define __wur __attribute__((__warn_unused_result__)) +#else +#define __wur +#endif + /* * Macros for manipulating "link sets". Link sets are arrays of pointers * to objects, which are gathered up by the linker.