[dpdk-dev] [PATCH v2] eal/rte_malloc: add alloc_size() attribute to allocation functions

Thomas Monjalon thomas at monjalon.net
Mon Oct 19 16:13:46 CEST 2020


15/10/2020 02:55, Stephen Hemminger:
> By using the alloc_size() attribute the compiler can optimize
> better and detect errors at compile time.
> 
> For example, Gcc will fail one of the invalid allocation examples
> in app/test/test_malloc.c because the allocation is outside the
> limits of memory.
> 
> Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> ---
> v2 - rebase onto correct branch (main)
[...]
> +/**
> + * 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

Not sure about the rebase: RTE_CC_GCC and RTE_CC_CLANG don't exist.




More information about the dev mailing list