f9micro / f9-kernel

An efficient and secure microkernel built for ARM Cortex-M cores, inspired by L4
Other
683 stars 145 forks source link

Ensure that all explicit memory accesses that appear in program order #43

Open jserv opened 11 years ago

jserv commented 11 years ago

Function test_and_set_word and test_and_set_bit in file platform/bitops.c implements the basic locking mechanism utilizing ldrex and strexeq instruction. However, other similar routines are not taken into consideration carefully, and we have to ensure that all explicit memory accesses that appear in program order before the DMB instruction are observed before any explicit memory accesses.

Here is the conceptual implementation:

int test_and_set(int *lock)
{
    int old_value;
    /* Ensure that all explicit memory accesses that appear in program order
     * before the DMB instruction are observed before any explicit memory
     * accesses. */
    __asm__ volatile ("dmb");
    old_value = *lock;
    *lock = 1;
    return old_value;
}