Skip to content

Commit

Permalink
Unwind mutex workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou committed Jul 5, 2024
1 parent f35e3bb commit fadc6b9
Showing 1 changed file with 1 addition and 46 deletions.
47 changes: 1 addition & 46 deletions include/ccf/pal/locking.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,17 @@

namespace ccf::pal
{
#if !defined(INSIDE_ENCLAVE) || defined(VIRTUAL_ENCLAVE)

/**
* Virtual enclaves and the host code share the same PAL.
* This PAL takes no dependence on OpenEnclave, but also does not apply
* security hardening.
*/
using Mutex = std::mutex;

#if !defined(INSIDE_ENCLAVE) || defined(VIRTUAL_ENCLAVE)
static inline void speculation_barrier() {}

#else

/**
* Temporary workaround until the fix for
* https://github.com/openenclave/openenclave/issues/4555 is available in a
* release.
*/
class MutexImpl
{
private:
pthread_spinlock_t sl;

public:
MutexImpl()
{
pthread_spin_init(&sl, PTHREAD_PROCESS_PRIVATE);
}

~MutexImpl()
{
pthread_spin_destroy(&sl);
}

void lock()
{
pthread_spin_lock(&sl);
}

bool try_lock()
{
return pthread_spin_trylock(&sl) == 0;
}

void unlock()
{
pthread_spin_unlock(&sl);
}
};

using Mutex = MutexImpl;

static inline void speculation_barrier()
{
oe_lfence();
}

#endif
}

0 comments on commit fadc6b9

Please sign in to comment.