summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-11-09 11:20:09 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-11-12 13:26:22 +0100
commitc1f3c2b88a8bc902ec019a7fcf916af5674bc29b (patch)
tree80e9e0d0b3137d6ff6676a78b6fdc0ad8a775454
parentx86_64: Remove use of proc_ptr (diff)
downloadrtems-c1f3c2b88a8bc902ec019a7fcf916af5674bc29b.tar.bz2
score: Add and use malloc() family attributes
Update #3583.
-rw-r--r--cpukit/include/rtems/malloc.h3
-rw-r--r--cpukit/include/rtems/score/basedefs.h50
2 files changed, 52 insertions, 1 deletions
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
@@ -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.
*