Skip to content

Commit

Permalink
Merge branch 'main' into lock_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rmn30 authored Dec 5, 2023
2 parents 04fef54 + c29ef7e commit 33e670a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "sdk/third_party/microvium"]
path = sdk/third_party/microvium
url = https://github.com/coder-mike/microvium
[submodule "sdk/third_party/freertos-plus-tcp"]
path = sdk/third_party/freertos-plus-tcp
url = https://github.com/FreeRTOS/FreeRTOS-Plus-TCP.git
16 changes: 8 additions & 8 deletions sdk/include/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "cdefs.h"
#include "thread.h"
#include <compartment-macros.h>
#include <cstdlib>
#include <stdint.h>
#include <stdlib.h>
#include <timeout.h>

struct EventGroup;
Expand All @@ -30,9 +30,9 @@ struct SObjStruct;
* If the timeout expires then this returns `-ETIMEDOUT`, if memory cannot be
* allocated it returns `-ENOMEM`.
*/
int __cheri_libcall eventgroup_create(struct Timeout *timeout,
struct SObjStruct *heapCapability,
EventGroup **outGroup);
int __cheri_libcall eventgroup_create(struct Timeout *timeout,
struct SObjStruct *heapCapability,
struct EventGroup **outGroup);

/**
* Wait for events in an event group. The `bitsWanted` argument must contain
Expand Down Expand Up @@ -88,10 +88,10 @@ int __cheri_libcall eventgroup_set(Timeout *timeout,
* Independent of success or failure, `outBits` will be used to return the set
* of currently set bits in this event group.
*/
int __cheri_libcall eventgroup_clear(Timeout *timeout,
EventGroup *group,
uint32_t *outBits,
uint32_t bitsToClear);
int __cheri_libcall eventgroup_clear(Timeout *timeout,
struct EventGroup *group,
uint32_t *outBits,
uint32_t bitsToClear);

/**
* Returns the current value of the event bits via `outBits`. Returns 0 on
Expand Down
37 changes: 19 additions & 18 deletions sdk/include/locks.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include <cdefs.h>
#include <limits>
#include <stdatomic.h>
#include <stdint.h>
#include <thread.h>
Expand Down Expand Up @@ -45,7 +44,7 @@ struct RecursiveMutexState
/**
* The underlying lock.
*/
FlagLockState lock;
struct FlagLockState lock;
/**
* The count of the times the lock has been acquired by the same thread.
* This must be initialised to 0.
Expand Down Expand Up @@ -78,7 +77,8 @@ __BEGIN_DECLS
* Returns 0 on success, -ETIMEDOUT if the timeout expired, or -EINVAL if the
* arguments are invalid.
*/
int __cheri_libcall flaglock_trylock(Timeout *timeout, FlagLockState *lock);
int __cheri_libcall flaglock_trylock(Timeout *timeout,
struct FlagLockState *lock);

/**
* Try to lock a flag lock. This is the priority-inheriting version. Some
Expand All @@ -93,16 +93,17 @@ int __cheri_libcall flaglock_trylock(Timeout *timeout, FlagLockState *lock);
* Returns 0 on success, -ETIMEDOUT if the timeout expired, or -EINVAL if the
* arguments are invalid.
*/
int __cheri_libcall flaglock_priority_inheriting_trylock(Timeout *timeout,
FlagLockState *lock);
int __cheri_libcall
flaglock_priority_inheriting_trylock(Timeout *timeout,
struct FlagLockState *lock);

/**
* Convenience wrapper to acquire a lock with an unlimited timeout. See
* `flaglock_trylock` for more details.
*/
__always_inline static inline void flaglock_lock(FlagLockState *lock)
__always_inline static inline void flaglock_lock(struct FlagLockState *lock)
{
Timeout t{UnlimitedTimeout};
Timeout t = {0, UnlimitedTimeout};
flaglock_trylock(&t, lock);
}

Expand All @@ -111,16 +112,16 @@ __always_inline static inline void flaglock_lock(FlagLockState *lock)
* `flaglock_priority_inheriting_trylock` for more details.
*/
__always_inline static inline void
flaglock_priority_inheriting_lock(FlagLockState *lock)
flaglock_priority_inheriting_lock(struct FlagLockState *lock)
{
Timeout t{UnlimitedTimeout};
Timeout t = {0, UnlimitedTimeout};
flaglock_priority_inheriting_trylock(&t, lock);
}

/**
* Unlock a flag lock. This can be called with either form of flag lock.
*/
void __cheri_libcall flaglock_unlock(FlagLockState *lock);
void __cheri_libcall flaglock_unlock(struct FlagLockState *lock);

/**
* Try to acquire a recursive mutex. This is a priority-inheriting mutex that
Expand All @@ -135,8 +136,8 @@ void __cheri_libcall flaglock_unlock(FlagLockState *lock);
* arguments are invalid. Can also return -EOVERFLOW if the lock depth would
* overflow the depth counter.
*/
int __cheri_libcall recursivemutex_trylock(Timeout *timeout,
RecursiveMutexState *lock);
int __cheri_libcall recursivemutex_trylock(Timeout *timeout,
struct RecursiveMutexState *lock);

/**
* Unlock a recursive mutex. Note: This does not check that the current thread
Expand All @@ -146,30 +147,30 @@ int __cheri_libcall recursivemutex_trylock(Timeout *timeout,
* Returns 0 on success. Succeeds unconditionally (future versions may return
* non-zero on error).
*/
int __cheri_libcall recursivemutex_unlock(RecursiveMutexState *mutex);
int __cheri_libcall recursivemutex_unlock(struct RecursiveMutexState *mutex);

/**
* Acquire a ticket lock. Ticket locks, by design, cannot support a try-lock
* operation and so will block forever until the lock is acquired.
*/
void __cheri_libcall ticketlock_lock(TicketLockState *lock);
void __cheri_libcall ticketlock_lock(struct TicketLockState *lock);

/**
* Release a ticket lock.
*/
void __cheri_libcall ticketlock_unlock(TicketLockState *lock);
void __cheri_libcall ticketlock_unlock(struct TicketLockState *lock);

/**
* Semaphore get operation, decrements the semaphore count. Returns 0 on
* success, -ETIMEDOUT if the timeout expired. Can also return -EINVAL if the
* arguments are invalid.
*/
int __cheri_libcall semaphore_get(Timeout *timeout,
CountingSemaphoreState *semaphore);
int __cheri_libcall semaphore_get(Timeout *timeout,
struct CountingSemaphoreState *semaphore);
/**
* Semaphore put operation. Returns 0 on success, -EINVAL if this would push
* the semaphore count above the maximum.
*/
int __cheri_libcall semaphore_put(CountingSemaphoreState *semaphore);
int __cheri_libcall semaphore_put(struct CountingSemaphoreState *semaphore);

__END_DECLS
4 changes: 2 additions & 2 deletions sdk/include/stdatomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ __clang_ignored_warning_push("-Watomic-alignment")
__always_inline _Bool
atomic_flag_test_and_set_explicit(volatile atomic_flag *obj, enum memory_order order)
{
return __c11_atomic_exchange(obj, true, order);
return __c11_atomic_exchange(obj, 1, order);
}

__always_inline _Bool atomic_flag_test_and_set(volatile atomic_flag *obj)
Expand All @@ -48,7 +48,7 @@ __always_inline _Bool
atomic_flag_test_and_clear_explicit(volatile atomic_flag *obj,
enum memory_order order)
{
return __c11_atomic_exchange(obj, false, order);
return __c11_atomic_exchange(obj, 0, order);
}

__always_inline _Bool atomic_flag_test_and_clear(volatile atomic_flag *obj)
Expand Down
1 change: 1 addition & 0 deletions sdk/third_party/freertos-plus-tcp
Submodule freertos-plus-tcp added at d70a21
5 changes: 4 additions & 1 deletion tests/ccompile-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,27 @@
#include <compartment.h>
#include <ctype.h>
#include <errno.h>
#include <event.h>
#include <futex.h>
#include <interrupt.h>
#include <inttypes.h>
#include <limits.h>
#include <locks.h>
#include <multiwaiter.h>
#include <queue.h>
#include <riscvreg.h>
#include <stdarg.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <switcher.h>
#include <thread.h>
#include <thread_pool.h>
#include <time.h>
#include <timeout.h>
#include <token.h>
#include <switcher.h>

0 comments on commit 33e670a

Please sign in to comment.