]> granicus.if.org Git - esp-idf/commitdiff
heap_caps: Add heap_caps_check_integrity() function
authorAngus Gratton <angus@espressif.com>
Wed, 10 May 2017 07:17:52 +0000 (17:17 +1000)
committerAngus Gratton <gus@projectgus.com>
Thu, 7 Sep 2017 06:32:05 +0000 (16:32 +1000)
components/heap/heap_caps.c
components/heap/include/esp_heap_caps.h

index 7993e371370c171de8ecc54c789b2241bee32369..1c7620292bd05dcf24f3b8d4642844b429a491d9 100644 (file)
@@ -288,3 +288,18 @@ void heap_caps_print_heap_info( uint32_t caps )
     printf("    free %d allocated %d min_free %d largest_free_block %d\n", info.total_free_bytes, info.total_allocated_bytes, info.minimum_free_bytes, info.largest_free_block);
 }
 
+bool heap_caps_check_integrity(uint32_t caps, bool print_errors)
+{
+    bool all_heaps = caps & MALLOC_CAP_INVALID;
+    bool valid = true;
+
+    heap_t *heap;
+    SLIST_FOREACH(heap, &registered_heaps, next) {
+        if (heap->heap != NULL
+            && (all_heaps || (get_all_caps(heap) & caps) == caps)) {
+            valid = multi_heap_check(heap->heap, print_errors) && valid;
+        }
+    }
+
+    return valid;
+}
index 23c310fa26d5fea652856f1e1b0026f82d5b5054..520642983715ce47ac39991b905da2d2ec4696d6 100644 (file)
@@ -154,3 +154,18 @@ void heap_caps_get_info( multi_heap_info_t *info, uint32_t caps );
  */
 void heap_caps_print_heap_info( uint32_t caps );
 
+/**
+ * @brief Check integrity of all heaps with the given capabilities.
+ *
+ * Calls multi_heap_check() on all heaps which share the given capabilities. Optionally
+ * print errors if the heaps are corrupt.
+ *
+ * Pass caps == MALLOC_CAP_INVALID to test all registered heaps.
+ *
+ * @param caps        Bitwise OR of MALLOC_CAP_* flags indicating the type
+ *                    of memory
+ * @param print_errors Print specific errors if heap corruption is found.
+ *
+ * @return True if all heaps are valid, False if at least one heap is corrupt.
+ */
+bool heap_caps_check_integrity(uint32_t caps, bool print_errors);