From 935889691ac6b52962bba7e1ec1a1ce35ee85a59 Mon Sep 17 00:00:00 2001 From: Per Larsen Date: Mon, 25 Mar 2024 06:35:41 +0000 Subject: 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 --- lib/rust_support/sync.rs | 5 +++-- 1 file 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 Mutex { 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 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); } } -- cgit v1.2.3