Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/malloc.c

    r25f6bddb rffccdff0  
    3535
    3636#include <malloc.h>
     37#include <stdalign.h>
    3738#include <stdbool.h>
    3839#include <stddef.h>
     
    8182        (sizeof(heap_block_head_t) + sizeof(heap_block_foot_t))
    8283
     84/** Calculate real size of a heap block.
     85 *
     86 * Add header and footer size.
     87 *
     88 */
     89#define GROSS_SIZE(size)  ((size) + STRUCT_OVERHEAD)
     90
     91/** Calculate net size of a heap block.
     92 *
     93 * Subtract header and footer size.
     94 *
     95 */
     96#define NET_SIZE(size)  ((size) - STRUCT_OVERHEAD)
     97
    8398/** Overhead of each area. */
    8499#define AREA_OVERHEAD(size) \
    85         (ALIGN_UP(size + sizeof(heap_area_t), BASE_ALIGN))
    86 
    87 /** Calculate real size of a heap block.
    88  *
    89  * Add header and footer size.
    90  *
    91  */
    92 #define GROSS_SIZE(size)  ((size) + STRUCT_OVERHEAD)
    93 
    94 /** Calculate net size of a heap block.
    95  *
    96  * Subtract header and footer size.
    97  *
    98  */
    99 #define NET_SIZE(size)  ((size) - STRUCT_OVERHEAD)
     100        (ALIGN_UP(GROSS_SIZE(size) + sizeof(heap_area_t), BASE_ALIGN))
    100101
    101102/** Get first block in heap area.
     
    198199
    199200#define malloc_assert(expr) safe_assert(expr)
     201
     202/*
     203 * Make sure the base alignment is sufficient.
     204 */
     205static_assert(BASE_ALIGN >= alignof(heap_area_t), "");
     206static_assert(BASE_ALIGN >= alignof(heap_block_head_t), "");
     207static_assert(BASE_ALIGN >= alignof(heap_block_foot_t), "");
     208static_assert(BASE_ALIGN >= alignof(max_align_t), "");
    200209
    201210/** Serializes access to the heap from multiple threads. */
Note: See TracChangeset for help on using the changeset viewer.