[rtems commit] score: Add and use malloc() family attributes

Sebastian Huber sebh at rtems.org
Mon Nov 12 14:43:43 UTC 2018


Module:    rtems
Branch:    master
Commit:    c1f3c2b88a8bc902ec019a7fcf916af5674bc29b
Changeset: http://git.rtems.org/rtems/commit/?id=c1f3c2b88a8bc902ec019a7fcf916af5674bc29b

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Nov  9 11:20:09 2018 +0100

score: Add and use malloc() family attributes

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 7c00f21..a6cfeb5 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 595d2ab..97f4fce 100644
--- a/cpukit/include/rtems/score/basedefs.h
+++ b/cpukit/include/rtems/score/basedefs.h
@@ -238,6 +238,56 @@
 #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.
  *




More information about the vc mailing list