Changeset 133461c in mainline


Ignore:
Timestamp:
2023-10-22T17:49:28Z (7 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1c6c3e1d, cc73f6d4
Parents:
78f0422c
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-10-22 17:44:39)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-10-22 17:49:28)
Message:

Align arm32 atomic op prototypes with compiler's expectations

Based on a patch by @vhotspur, but without explicit casts
between pointer types. Those are evil footguns.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/arm32/src/atomic.c

    r78f0422c r133461c  
    3838#include <arch/asm.h>
    3939
    40 unsigned __atomic_fetch_add_4(volatile unsigned *mem, unsigned val, int model)
     40unsigned __atomic_fetch_add_4(volatile void *mem0, unsigned val, int model)
    4141{
     42        volatile unsigned *mem = mem0;
     43
    4244        /*
    4345         * This implementation is for UP pre-ARMv6 systems where we do not have
     
    5153}
    5254
    53 unsigned __atomic_fetch_sub_4(volatile unsigned *mem, unsigned val, int model)
     55unsigned __atomic_fetch_sub_4(volatile void *mem0, unsigned val, int model)
    5456{
     57        volatile unsigned *mem = mem0;
     58
    5559        ipl_t ipl = interrupts_disable();
    5660        unsigned ret = *mem;
     
    6771 * returns the previous value of \a *ptr.
    6872 */
    69 void *__sync_val_compare_and_swap_4(void **ptr, void *expected, void *new_val)
     73unsigned __sync_val_compare_and_swap_4(volatile void *ptr0, unsigned expected,
     74    unsigned new_val)
    7075{
     76        volatile unsigned *ptr = ptr0;
     77
    7178        /*
    7279         * Using an interrupt disabling spinlock might still lead to deadlock
     
    7885        irq_spinlock_lock(&cas_lock, true);
    7986
    80         void *cur_val = *ptr;
     87        unsigned cur_val = *ptr;
    8188
    8289        if (cur_val == expected) {
     
    96103/* Naive implementations of the newer intrinsics. */
    97104
    98 _Bool __atomic_compare_exchange_4(void **mem, void **expected, void *desired, _Bool weak, int success, int failure)
     105_Bool __atomic_compare_exchange_4(volatile void *mem, void *expected0,
     106    unsigned desired, _Bool weak, int success, int failure)
    99107{
     108        unsigned *expected = expected0;
     109
    100110        (void) weak;
    101111        (void) success;
    102112        (void) failure;
    103113
    104         void *old = *expected;
    105         void *new = __sync_val_compare_and_swap_4(mem, old, desired);
     114        unsigned old = *expected;
     115        unsigned new = __sync_val_compare_and_swap_4(mem, old, desired);
    106116        if (old == new) {
    107117                return 1;
     
    112122}
    113123
    114 void *__atomic_exchange_4(void **mem, void *val, int model)
     124unsigned __atomic_exchange_4(volatile void *mem0, unsigned val, int model)
    115125{
     126        volatile unsigned *mem = mem0;
     127
    116128        (void) model;
    117129
    118130        irq_spinlock_lock(&cas_lock, true);
    119         void *old = *mem;
     131        unsigned old = *mem;
    120132        *mem = val;
    121133        irq_spinlock_unlock(&cas_lock, true);
  • uspace/lib/c/arch/arm32/src/atomic.c

    r78f0422c r133461c  
    3838volatile unsigned *ras_page;
    3939
    40 bool __atomic_compare_exchange_4(volatile unsigned *mem, unsigned *expected, unsigned desired, bool weak, int success, int failure)
     40bool __atomic_compare_exchange_4(volatile void *mem0, void *expected0,
     41    unsigned desired, bool weak, int success, int failure)
    4142{
     43        volatile unsigned *mem = mem0;
     44        unsigned *expected = expected0;
     45
    4246        (void) success;
    4347        (void) failure;
     
    8286}
    8387
    84 unsigned short __atomic_fetch_add_2(volatile unsigned short *mem, unsigned short val, int model)
     88unsigned short __atomic_fetch_add_2(volatile void *mem0, unsigned short val,
     89    int model)
    8590{
     91        volatile unsigned short *mem = mem0;
     92
    8693        (void) model;
    8794
     
    116123}
    117124
    118 unsigned __atomic_fetch_add_4(volatile unsigned *mem, unsigned val, int model)
     125unsigned __atomic_fetch_add_4(volatile void *mem0, unsigned val, int model)
    119126{
     127        volatile unsigned *mem = mem0;
     128
    120129        (void) model;
    121130
     
    150159}
    151160
    152 unsigned __atomic_fetch_sub_4(volatile unsigned *mem, unsigned val, int model)
     161unsigned __atomic_fetch_sub_4(volatile void *mem, unsigned val, int model)
    153162{
    154163        return __atomic_fetch_add_4(mem, -val, model);
Note: See TracChangeset for help on using the changeset viewer.