Two fixes to the `flags` argument of `futex_timed_wait`. The `flags` argument of `futex_timed_wait` is currently of type `FutexWaitFlags`. This is not exactly what we want, since we cannot do futex_timed_wait(flag1 | flag2) as `flag1 | flag2` would implicitly cast to `int`, triggering a compilation error as `futex_timed_wait` takes a `FutexWaitFlags`. To address this, change the type of `flags` to `uint32_t`. This should be a transparent change for callers. This commit addresses a second problem: `FutexPriorityInheritance` does not currently have an explicit value, which will cause issues when we add another flag value: if another value is added without specifying an explicit power-of-two value, the resulting enum flags will not be `OR`-able, causing subtle bugs. To address this, add an explicit value of `(1 << 0)` to `FutexPriorityInheritance`. Although these two problems do not have impact right now, they will as soon as we introduce more flag values. Since we are currently replicating this code elsewhere, we may as well address these issues. Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@scisemi.com>
diff --git a/sdk/core/scheduler/main.cc b/sdk/core/scheduler/main.cc index 0983770..95ef0e2 100644 --- a/sdk/core/scheduler/main.cc +++ b/sdk/core/scheduler/main.cc
@@ -452,7 +452,7 @@ __cheriot_minimum_stack(0xa0) int futex_timed_wait(Timeout *timeout, const uint32_t *address, uint32_t expected, - FutexWaitFlags flags) + uint32_t flags) { STACK_CHECK(0xa0); if (!check_timeout_pointer(timeout) ||
diff --git a/sdk/include/futex.h b/sdk/include/futex.h index 7907e2a..482919a 100644 --- a/sdk/include/futex.h +++ b/sdk/include/futex.h
@@ -14,7 +14,7 @@ * are assumed to hold the thread ID of the thread that currently holds the * lock. */ - FutexPriorityInheritance}; + FutexPriorityInheritance = (1 << 0)}; /** * Compare the value at `address` to `expected` and, if they match, sleep the @@ -37,10 +37,10 @@ * - `-ETIMEOUT` if the timeout expires. */ [[cheri::interrupt_state(disabled)]] int __cheri_compartment("sched") - futex_timed_wait(Timeout *ticks, - const uint32_t *address, - uint32_t expected, - enum FutexWaitFlags flags __if_cxx(= FutexNone)); + futex_timed_wait(Timeout *ticks, + const uint32_t *address, + uint32_t expected, + uint32_t flags __if_cxx(= FutexNone)); /** * Compare the value at `address` to `expected` and, if they match, sleep the