vppinfra: initial RISC-V support
[vpp.git] / src / vppinfra / heap.c
index 2a5fb5c..bc22da1 100644 (file)
@@ -297,6 +297,7 @@ search_free_list (void *v, uword size)
        /* Find an object that is large enough.
           Search list in reverse so that more recently freed objects will be
           allocated again sooner. */
+       u8 found = 0;
        do
          {
            l--;
@@ -304,12 +305,15 @@ search_free_list (void *v, uword size)
            f = elt_at (h, f_index);
            f_size = heap_elt_size (v, f);
            if ((s = f_size - size) >= 0)
-             break;
+             {
+               found = 1;
+               break;
+             }
          }
-       while (l >= 0);
+       while (l > 0);
 
        /* If we fail to find a large enough object, try the next larger size. */
-       if (l < 0)
+       if (found == 0)
          continue;
 
        ASSERT (heap_is_free (f));
@@ -378,7 +382,7 @@ dealloc_elt (void *v, heap_elt_t * e)
     combine_free_blocks (v, p, n);
 }
 
-void *
+__clib_export void *
 _heap_alloc (void *v,
             uword size,
             uword align,
@@ -492,7 +496,7 @@ error:
   return v;
 }
 
-void
+__clib_export void
 heap_dealloc (void *v, uword handle)
 {
   heap_header_t *h = heap_header (v);
@@ -593,7 +597,7 @@ combine_free_blocks (void *v, heap_elt_t * e0, heap_elt_t * e1)
   set_free_elt (v, elt_at (h, g.index), g.bin_index);
 }
 
-uword
+__clib_export uword
 heap_len (void *v, word handle)
 {
   heap_header_t *h = heap_header (v);
@@ -603,7 +607,7 @@ heap_len (void *v, word handle)
   return heap_elt_size (v, elt_at (h, handle));
 }
 
-void *
+__clib_export void *
 _heap_free (void *v)
 {
   heap_header_t *h = heap_header (v);
@@ -690,15 +694,15 @@ debug_elt (u8 * s, void *v, word i, word n)
   return s;
 }
 
-u8 *
-format_heap (u8 * s, va_list * va)
+__clib_export u8 *
+format_heap (u8 *s, va_list *va)
 {
   void *v = va_arg (*va, void *);
   uword verbose = va_arg (*va, uword);
   heap_header_t *h = heap_header (v);
   heap_header_t zero;
 
-  memset (&zero, 0, sizeof (zero));
+  clib_memset (&zero, 0, sizeof (zero));
 
   if (!v)
     h = &zero;
@@ -718,7 +722,7 @@ format_heap (u8 * s, va_list * va)
   return s;
 }
 
-void
+__clib_export void
 heap_validate (void *v)
 {
   heap_header_t *h = heap_header (v);