* Main function to allocate a block of memory from the heap. * It locks the free list, scans it, and adds a new memseg if the * scan fails. Once the new memseg is added, it re-scans and should return * the new element after releasing the lock. */
| 229 | * the new element after releasing the lock. |
| 230 | */ |
| 231 | static void * |
| 232 | heap_alloc(struct malloc_heap *heap, const char *type __rte_unused, size_t size, |
| 233 | unsigned int flags, size_t align, size_t bound, bool contig) |
| 234 | { |
| 235 | struct malloc_elem *elem; |
| 236 | size_t user_size = size; |
| 237 | |
| 238 | size = RTE_CACHE_LINE_ROUNDUP(size); |
| 239 | align = RTE_CACHE_LINE_ROUNDUP(align); |
| 240 | |
| 241 | /* roundup might cause an overflow */ |
| 242 | if (size == 0) |
| 243 | return NULL; |
| 244 | elem = find_suitable_element(heap, size, flags, align, bound, contig); |
| 245 | if (elem != NULL) { |
| 246 | elem = malloc_elem_alloc(elem, size, align, bound, contig); |
| 247 | |
| 248 | /* increase heap's count of allocated elements */ |
| 249 | heap->alloc_count++; |
| 250 | |
| 251 | asan_set_redzone(elem, user_size); |
| 252 | } |
| 253 | |
| 254 | return elem == NULL ? NULL : (void *)(&elem[1]); |
| 255 | } |
| 256 | |
| 257 | static void * |
| 258 | heap_alloc_biggest(struct malloc_heap *heap, const char *type __rte_unused, |
no test coverage detected