__attribute__((format(printf, format_index, first_arg)))
#endif
+/**
+ * Tells compiler that the function returns a value that points to
+ * memory, where the size is given by the one or two arguments.
+ * Used by compiler to validate object size.
+ */
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_alloc_size(...) \
+ __attribute__((alloc_size(__VA_ARGS__)))
+#else
+#define __rte_alloc_size(...)
+#endif
+
#define RTE_PRIORITY_LOG 101
#define RTE_PRIORITY_BUS 110
#define RTE_PRIORITY_CLASS 120
* - Otherwise, the pointer to the allocated object.
*/
void *
-rte_malloc(const char *type, size_t size, unsigned align);
+rte_malloc(const char *type, size_t size, unsigned align)
+ __rte_alloc_size(2);
/**
* Allocate zero'ed memory from the heap.
* - Otherwise, the pointer to the allocated object.
*/
void *
-rte_zmalloc(const char *type, size_t size, unsigned align);
+rte_zmalloc(const char *type, size_t size, unsigned align)
+ __rte_alloc_size(2);
/**
* Replacement function for calloc(), using huge-page memory. Memory area is
* - Otherwise, the pointer to the allocated object.
*/
void *
-rte_calloc(const char *type, size_t num, size_t size, unsigned align);
+rte_calloc(const char *type, size_t num, size_t size, unsigned align)
+ __rte_alloc_size(2, 3);
/**
* Replacement function for realloc(), using huge-page memory. Reserved area
* - Otherwise, the pointer to the reallocated memory.
*/
void *
-rte_realloc(void *ptr, size_t size, unsigned int align);
+rte_realloc(void *ptr, size_t size, unsigned int align)
+ __rte_alloc_size(2);
/**
* Replacement function for realloc(), using huge-page memory. Reserved area
*/
__rte_experimental
void *
-rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket);
+rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket)
+ __rte_alloc_size(2, 3);
/**
* This function allocates memory from the huge-page area of memory. The memory
* - Otherwise, the pointer to the allocated object.
*/
void *
-rte_malloc_socket(const char *type, size_t size, unsigned align, int socket);
+rte_malloc_socket(const char *type, size_t size, unsigned align, int socket)
+ __rte_alloc_size(2);
/**
* Allocate zero'ed memory from the heap.
* - Otherwise, the pointer to the allocated object.
*/
void *
-rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket);
+rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket)
+ __rte_alloc_size(2);
/**
* Replacement function for calloc(), using huge-page memory. Memory area is
* - Otherwise, the pointer to the allocated object.
*/
void *
-rte_calloc_socket(const char *type, size_t num, size_t size, unsigned align, int socket);
+rte_calloc_socket(const char *type, size_t num, size_t size, unsigned align, int socket)
+ __rte_alloc_size(2, 3);
/**
* Frees the memory space pointed to by the provided pointer.