diff --git a/repos/dde_linux/src/include/spec/arm/lx_emul/arch_spinlock.h b/repos/dde_linux/src/include/spec/arm/lx_emul/arch_spinlock.h new file mode 100644 index 0000000000..746db770e9 --- /dev/null +++ b/repos/dde_linux/src/include/spec/arm/lx_emul/arch_spinlock.h @@ -0,0 +1,20 @@ +/* + * \brief Architecture-specific accessors to spinlock types for lx_emul + * \author Johannes Schlatow + * \date 2022-04-04 + */ + +/* + * Copyright (C) 2022 Genode Labs GmbH + * + * This file is distributed under the terms of the GNU General Public License + * version 2. + */ + +#ifndef _LX_EMUL__ARCH_SPINLOCK_H_ +#define _LX_EMUL__ARCH_SPINLOCK_H_ + +#define SPINLOCK_VALUE_PTR(lock) (atomic_t*)&lock->raw_lock.slock +#define RWLOCK_VALUE(lock) lock->raw_lock.lock + +#endif /*_LX_EMUL__ARCH_SPINLOCK_H_ */ diff --git a/repos/dde_linux/src/include/spec/arm_64/lx_emul/arch_spinlock.h b/repos/dde_linux/src/include/spec/arm_64/lx_emul/arch_spinlock.h new file mode 100644 index 0000000000..eacf850362 --- /dev/null +++ b/repos/dde_linux/src/include/spec/arm_64/lx_emul/arch_spinlock.h @@ -0,0 +1,20 @@ +/* + * \brief Architecture-specific accessors to spinlock types for lx_emul + * \author Johannes Schlatow + * \date 2022-04-04 + */ + +/* + * Copyright (C) 2022 Genode Labs GmbH + * + * This file is distributed under the terms of the GNU General Public License + * version 2. + */ + +#ifndef _LX_EMUL__ARCH_SPINLOCK_H_ +#define _LX_EMUL__ARCH_SPINLOCK_H_ + +#define SPINLOCK_VALUE_PTR(lock) &lock->raw_lock.val +#define RWLOCK_VALUE(lock) lock->raw_lock.wlocked + +#endif /*_LX_EMUL__ARCH_SPINLOCK_H_ */ diff --git a/repos/dde_linux/src/include/spec/x86/lx_emul/arch_spinlock.h b/repos/dde_linux/src/include/spec/x86/lx_emul/arch_spinlock.h new file mode 100644 index 0000000000..eacf850362 --- /dev/null +++ b/repos/dde_linux/src/include/spec/x86/lx_emul/arch_spinlock.h @@ -0,0 +1,20 @@ +/* + * \brief Architecture-specific accessors to spinlock types for lx_emul + * \author Johannes Schlatow + * \date 2022-04-04 + */ + +/* + * Copyright (C) 2022 Genode Labs GmbH + * + * This file is distributed under the terms of the GNU General Public License + * version 2. + */ + +#ifndef _LX_EMUL__ARCH_SPINLOCK_H_ +#define _LX_EMUL__ARCH_SPINLOCK_H_ + +#define SPINLOCK_VALUE_PTR(lock) &lock->raw_lock.val +#define RWLOCK_VALUE(lock) lock->raw_lock.wlocked + +#endif /*_LX_EMUL__ARCH_SPINLOCK_H_ */ diff --git a/repos/dde_linux/src/lib/lx_emul/shadow/kernel/locking/spinlock.c b/repos/dde_linux/src/lib/lx_emul/shadow/kernel/locking/spinlock.c index a689115d27..0b3553aef6 100644 --- a/repos/dde_linux/src/lib/lx_emul/shadow/kernel/locking/spinlock.c +++ b/repos/dde_linux/src/lib/lx_emul/shadow/kernel/locking/spinlock.c @@ -19,13 +19,15 @@ #include #include +#include + void __lockfunc _raw_spin_lock(raw_spinlock_t * lock) { - if (atomic_read(&lock->raw_lock.val)) { + if (atomic_read(SPINLOCK_VALUE_PTR(lock))) { printk("Error: spinlock contention!"); lx_emul_trace_and_stop(__func__); } - atomic_set(&lock->raw_lock.val, 1); + atomic_set(SPINLOCK_VALUE_PTR(lock), 1); } @@ -40,7 +42,7 @@ unsigned long __lockfunc _raw_spin_lock_irqsave(raw_spinlock_t * lock) void __lockfunc _raw_spin_unlock(raw_spinlock_t * lock) { - atomic_set(&lock->raw_lock.val, 0); + atomic_set(SPINLOCK_VALUE_PTR(lock), 0); } @@ -67,7 +69,7 @@ void __lockfunc _raw_spin_unlock_irq(raw_spinlock_t * lock) int __lockfunc _raw_spin_trylock(raw_spinlock_t * lock) { - if (atomic_read(&lock->raw_lock.val)) + if (atomic_read(SPINLOCK_VALUE_PTR(lock))) return 0; _raw_spin_lock(lock); @@ -77,15 +79,15 @@ int __lockfunc _raw_spin_trylock(raw_spinlock_t * lock) void __lockfunc _raw_write_lock(rwlock_t * lock) { - if (lock->raw_lock.wlocked) { + if (RWLOCK_VALUE(lock)) { printk("Error: rwlock contention!"); lx_emul_trace_and_stop(__func__); } - lock->raw_lock.wlocked = 1; + RWLOCK_VALUE(lock) = 1; } void __lockfunc _raw_write_unlock(rwlock_t * lock) { - lock->raw_lock.wlocked = 0; + RWLOCK_VALUE(lock) = 0; }