diff options
author | Per Larsen <perlarsen@google.com> | 2024-03-25 06:35:41 +0000 |
---|---|---|
committer | Per Larsen <perlarsen@google.com> | 2024-03-25 06:48:20 +0000 |
commit | 935889691ac6b52962bba7e1ec1a1ce35ee85a59 (patch) | |
tree | 7d975972f074d9a3a556e836aefa9063318fa885 | |
parent | e8b53f528aedc0d57de6091e72fac965c78479ab (diff) | |
download | common-935889691ac6b52962bba7e1ec1a1ce35ee85a59.tar.gz |
lib: rust_support: fix mutex_t wrapper impl
Testing aosp/2994822 immediately causes a panic because
mutex_acquire and mutex_release in the trusty kernel returns
NO_ERROR (0) on success but the rust code asserts that the
response is non zero.
Test: with appropriate patches applied, build.py generic-x86_64-test
Bug: 298705967
Change-Id: I16f4371640f4b5fa7fa77e6775df5f3ce38765fa
-rw-r--r-- | lib/rust_support/sync.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/rust_support/sync.rs b/lib/rust_support/sync.rs index 47c74ba7..eac9eaa2 100644 --- a/lib/rust_support/sync.rs +++ b/lib/rust_support/sync.rs @@ -31,6 +31,7 @@ use core::ops::DerefMut; use alloc::boxed::Box; +use crate::err::NO_ERROR; use crate::sys::extern_is_mutex_held; use crate::sys::mutex_acquire_timeout; use crate::sys::mutex_destroy; @@ -142,7 +143,7 @@ impl<T: ?Sized> Mutex<T> { pub fn lock(&self) -> MutexGuard<'_, T> { // SAFETY: `mutex_acquire` is thread safe and it was `mutex_init`ialized. let status = unsafe { mutex_acquire(self.mutex.get_raw()) }; - assert_ne!(status, 0); + assert_eq!(status, NO_ERROR); MutexGuard { lock: &self } } @@ -161,7 +162,7 @@ impl<T: ?Sized> Drop for MutexGuard<'_, T> { fn drop(&mut self) { // SAFETY: `mutex_release` is thread safe and it was `mutex_init`ialized. let status = unsafe { mutex_release(self.lock.mutex.get_raw()) }; - assert_ne!(status, 0); + assert_eq!(status, NO_ERROR); } } |