Changeset ffccdff0 in mainline


Ignore:
Timestamp:
2020-06-15T13:29:29Z (5 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4f663f3e
Parents:
128359eb
Message:

Unify alignment handling

Use the C11 alignof() operator. Make sure the allocation alignment is
sufficient.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • boot/generic/src/balloc.c

    r128359eb rffccdff0  
    2828
    2929#include <balloc.h>
     30#include <stdalign.h>
    3031#include <stddef.h>
    3132#include <align.h>
     
    5152
    5253        /* Enforce minimal alignment. */
    53         alignment = ALIGN_UP(alignment, 4);
     54        alignment = ALIGN_UP(alignment, alignof(max_align_t));
    5455
    5556        uintptr_t addr = phys_base + ALIGN_UP(ballocs->size, alignment);
  • uspace/lib/c/generic/malloc.c

    r128359eb rffccdff0  
    3535
    3636#include <malloc.h>
     37#include <stdalign.h>
    3738#include <stdbool.h>
    3839#include <stddef.h>
     
    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. */
  • uspace/lib/c/generic/rtld/module.c

    r128359eb rffccdff0  
    4040#include <errno.h>
    4141#include <loader/pcb.h>
     42#include <stdalign.h>
    4243#include <stdio.h>
    4344#include <stdlib.h>
     
    353354#ifdef CONFIG_TLS_VARIANT_1
    354355        rtld->tls_size = sizeof(tcb_t);
    355         rtld->tls_align = _Alignof(tcb_t);
     356        rtld->tls_align = alignof(tcb_t);
    356357
    357358        list_foreach(rtld->modules, modules_link, module_t, m) {
     
    366367#else
    367368        rtld->tls_size = 0;
    368         rtld->tls_align = _Alignof(tcb_t);
     369        rtld->tls_align = alignof(tcb_t);
    369370
    370371        list_foreach(rtld->modules, modules_link, module_t, m) {
  • uspace/lib/c/generic/thread/tls.c

    r128359eb rffccdff0  
    3737
    3838#include <assert.h>
     39#include <stdalign.h>
    3940#include <stddef.h>
    4041#include <align.h>
     
    6970#else
    7071        size_t tls_size = tls ? tls->p_memsz : 0;
    71         return -ALIGN_UP((ptrdiff_t) tls_size, max(tls_align, _Alignof(tcb_t)));
     72        return -ALIGN_UP((ptrdiff_t) tls_size, max(tls_align, alignof(tcb_t)));
    7273#endif
    7374}
     
    104105#else
    105106        size_t alloc_size =
    106             ALIGN_UP(tls_size, max(tls_align, _Alignof(tcb_t))) + sizeof(tcb_t);
    107 #endif
    108 
    109         void *area = alloc(max(tls_align, _Alignof(tcb_t)), alloc_size);
     107            ALIGN_UP(tls_size, max(tls_align, alignof(tcb_t))) + sizeof(tcb_t);
     108#endif
     109
     110        void *area = alloc(max(tls_align, alignof(tcb_t)), alloc_size);
    110111        if (!area)
    111112                return NULL;
     
    187188        tls_free_arch(tcb,
    188189            ALIGN_UP(tls->p_memsz, tls->p_align) + sizeof(tcb_t),
    189             max(tls->p_align, _Alignof(tcb_t)));
     190            max(tls->p_align, alignof(tcb_t)));
    190191}
    191192
  • uspace/lib/virtio/virtio.c

    r128359eb rffccdff0  
    3535#include <align.h>
    3636#include <macros.h>
     37#include <stdalign.h>
    3738
    3839#include <ddf/log.h>
     
    230231         */
    231232        size_t mem_size = sizeof(virtq_desc_t[size]);
    232         mem_size = ALIGN_UP(mem_size, _Alignof(virtq_avail_t));
     233        mem_size = ALIGN_UP(mem_size, alignof(virtq_avail_t));
    233234        avail_offset = mem_size;
    234235        mem_size += sizeof(virtq_avail_t) + sizeof(ioport16_t[size]) +
    235236            sizeof(ioport16_t);
    236         mem_size = ALIGN_UP(mem_size, _Alignof(virtq_used_t));
     237        mem_size = ALIGN_UP(mem_size, alignof(virtq_used_t));
    237238        used_offset = mem_size;
    238239        mem_size += sizeof(virtq_used_t) + sizeof(virtq_used_elem_t[size]) +
Note: See TracChangeset for help on using the changeset viewer.