@@ -228,6 +228,36 @@ typedef uint16_t unaligned_uint16_t;
#define __rte_alloc_size(...)
#endif
+/**
+ * Tells the compiler that the function returns a value that points to
+ * memory aligned by a function argument.
+ * Not enabled on clang because it warns if align argument is zero.
+ */
+#if defined(RTE_CC_GCC)
+#define __rte_alloc_align(align_arg) \
+ __attribute__((alloc_align(align_arg)))
+#else
+#define __rte_alloc_align(...)
+#endif
+
+/**
+ * Tells the compiler this is a function like malloc and that the pointer
+ * returned cannot alias any other pointer (ie new memory).
+ *
+ * Also, with recent GCC versions also able to track that proper
+ * dealloctor function is used for this pointer.
+ */
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 110000)
+#define __rte_alloc_func(...) \
+ __attribute__((malloc, malloc(__VA_ARGS__)))
+
+#elif defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_alloc_func(...) \
+ __attribute__((malloc))
+#else
+#define __rte_alloc_func(...)
+#endif
+
#define RTE_PRIORITY_LOG 101
#define RTE_PRIORITY_BUS 110
#define RTE_PRIORITY_CLASS 120
@@ -54,7 +54,8 @@ struct rte_malloc_socket_stats {
*/
void *
rte_malloc(const char *type, size_t size, unsigned align)
- __rte_alloc_size(2);
+ __rte_alloc_size(2)
+ __rte_alloc_align(3);
/**
* Allocate zeroed memory from the heap.
@@ -81,7 +82,8 @@ rte_malloc(const char *type, size_t size, unsigned align)
*/
void *
rte_zmalloc(const char *type, size_t size, unsigned align)
- __rte_alloc_size(2);
+ __rte_alloc_size(2)
+ __rte_alloc_align(3);
/**
* Replacement function for calloc(), using huge-page memory. Memory area is
@@ -108,7 +110,8 @@ rte_zmalloc(const char *type, size_t size, unsigned align)
*/
void *
rte_calloc(const char *type, size_t num, size_t size, unsigned align)
- __rte_alloc_size(2, 3);
+ __rte_alloc_size(2, 3)
+ __rte_alloc_align(4);
/**
* Replacement function for realloc(), using huge-page memory. Reserved area
@@ -132,7 +135,8 @@ rte_calloc(const char *type, size_t num, size_t size, unsigned align)
*/
void *
rte_realloc(void *ptr, size_t size, unsigned int align)
- __rte_alloc_size(2);
+ __rte_alloc_size(2)
+ __rte_alloc_align(3);
/**
* Replacement function for realloc(), using huge-page memory. Reserved area
@@ -158,7 +162,8 @@ rte_realloc(void *ptr, size_t size, unsigned int align)
*/
void *
rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket)
- __rte_alloc_size(2);
+ __rte_alloc_size(2)
+ __rte_alloc_align(3);
/**
* This function allocates memory from the huge-page area of memory. The memory
@@ -185,7 +190,8 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket)
*/
void *
rte_malloc_socket(const char *type, size_t size, unsigned align, int socket)
- __rte_alloc_size(2);
+ __rte_alloc_size(2)
+ __rte_alloc_align(3);
/**
* Allocate zeroed memory from the heap.
@@ -214,7 +220,8 @@ rte_malloc_socket(const char *type, size_t size, unsigned align, int socket)
*/
void *
rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket)
- __rte_alloc_size(2);
+ __rte_alloc_size(2)
+ __rte_alloc_align(3);
/**
* Replacement function for calloc(), using huge-page memory. Memory area is
@@ -243,7 +250,8 @@ rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket)
*/
void *
rte_calloc_socket(const char *type, size_t num, size_t size, unsigned align, int socket)
- __rte_alloc_size(2, 3);
+ __rte_alloc_size(2, 3)
+ __rte_alloc_align(4);
/**
* Frees the memory space pointed to by the provided pointer.