[rtems commit] heap: Fix _Heap_Area_overhead()

Sebastian Huber sebh at rtems.org
Wed Jan 27 05:01:21 UTC 2021


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Jan  7 12:05:37 2021 +0100

heap: Fix _Heap_Area_overhead()

The first block must be a proper block.  Account for this in
_Heap_Area_overhead().

---

 cpukit/include/rtems/score/heap.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/cpukit/include/rtems/score/heap.h b/cpukit/include/rtems/score/heap.h
index ccc2f5c..62a81cb 100644
--- a/cpukit/include/rtems/score/heap.h
+++ b/cpukit/include/rtems/score/heap.h
@@ -455,7 +455,13 @@ RTEMS_INLINE_ROUTINE uintptr_t _Heap_Area_overhead(
     page_size = CPU_ALIGNMENT;
   }
 
-  return 2 * (page_size - 1) + HEAP_BLOCK_HEADER_SIZE;
+  /*
+   * Account for a potential alignment of the area begin address to a page
+   * boundary, the first block, and the last block.  The last block consists
+   * only of a block header.
+   */
+  return page_size - 1 + _Heap_Min_block_size( page_size ) +
+    HEAP_BLOCK_HEADER_SIZE;
 }
 
 /**



More information about the vc mailing list