Skip to content

Commit

Permalink
score: Add and use malloc() family attributes
Browse files Browse the repository at this point in the history
Update #3583.
  • Loading branch information
sebhub committed Nov 12, 2018
1 parent 4539e30 commit c1f3c2b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cpukit/include/rtems/malloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ void *rtems_heap_allocate_aligned_with_boundary(
size_t size,
uintptr_t alignment,
uintptr_t boundary
);
) RTEMS_MALLOCLIKE RTEMS_ALLOC_SIZE(1) RTEMS_ALLOC_ALIGN(2)
RTEMS_WARN_UNUSED_RESULT;

/**
* @brief Extends the memory available for the heap using the memory area
Expand Down
50 changes: 50 additions & 0 deletions cpukit/include/rtems/score/basedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,56 @@
#define RTEMS_PRINTFLIKE( _format_pos, _ap_pos )
#endif

/**
* @brief Tells the compiler that this function is a memory allocation function
* similar to malloc().
*/
#if defined(__GNUC__)
#define RTEMS_MALLOCLIKE __attribute__((__malloc__))
#else
#define RTEMS_MALLOCLIKE
#endif

/**
* @brief Tells the compiler the memory allocation size parameter of this
* function similar to malloc().
*/
#if defined(__GNUC__)
#define RTEMS_ALLOC_SIZE( _index ) __attribute__((__alloc_size__(_index)))
#else
#define RTEMS_ALLOC_SIZE( _index )
#endif

/**
* @brief Tells the compiler the memory allocation item count and item size
* parameter of this function similar to calloc().
*/
#if defined(__GNUC__)
#define RTEMS_ALLOC_SIZE_2( _count_index, _size_index ) \
__attribute__((__alloc_size__(_count_index, _size_index)))
#else
#define RTEMS_ALLOC_SIZE_2( _count_index, _size_index )
#endif

/**
* @brief Tells the compiler the memory allocation alignment parameter of this
* function similar to aligned_alloc().
*/
#if defined(__GNUC__)
#define RTEMS_ALLOC_ALIGN( _index ) __attribute__((__alloc_align__(_index)))
#else
#define RTEMS_ALLOC_ALIGN( _index )
#endif

/**
* @brief Tells the compiler that the result of this function should be used.
*/
#if defined(__GNUC__)
#define RTEMS_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
#else
#define RTEMS_WARN_UNUSED_RESULT
#endif

/**
* @brief Obfuscates the variable so that the compiler cannot perform
* optimizations based on the variable value.
Expand Down

0 comments on commit c1f3c2b

Please sign in to comment.