[PATCH 1/3] score: Add and use malloc() family attributes
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Nov 9 12:10:38 UTC 2018
Update #3583.
---
cpukit/include/rtems/malloc.h | 3 ++-
cpukit/include/rtems/score/basedefs.h | 50 +++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/cpukit/include/rtems/malloc.h b/cpukit/include/rtems/malloc.h
index 7c00f21e77..a6cfeb574f 100644
--- a/cpukit/include/rtems/malloc.h
+++ b/cpukit/include/rtems/malloc.h
@@ -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
diff --git a/cpukit/include/rtems/score/basedefs.h b/cpukit/include/rtems/score/basedefs.h
index 595d2ab805..97f4fce8d0 100644
--- a/cpukit/include/rtems/score/basedefs.h
+++ b/cpukit/include/rtems/score/basedefs.h
@@ -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.
--
2.16.4
More information about the devel
mailing list