mirror of
https://github.com/apache/nuttx.git
synced 2026-05-15 21:19:09 +08:00
openamp/libmetal: change the libmetal mutex to rmutex to avoid carsh
To avoid the crash when lock are acquired twice, one case is in the destory process: we hold the rpdev->lock to iterate the rpdev->endpoints to destory all the endpoints, but rpmsg_destroy_ept() may send the name service message, and need acquire the rpdev->lock again to lead crash. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
From fad5ddc80345f97a0c7b20c545502ac1f8e321a5 Mon Sep 17 00:00:00 2001
|
||||
From f959a2b5acccd2045c7277c3f3ddefe9bea08887 Mon Sep 17 00:00:00 2001
|
||||
From: Bowen Wang <wangbowen6@xiaomi.com>
|
||||
Date: Thu, 18 Dec 2025 17:26:13 +0800
|
||||
Subject: [PATCH] libmetal(cmake):set HAVE_STDATOMIC_H default true in NuttX
|
||||
platform
|
||||
Subject: [PATCH 1/3] libmetal(cmake):set HAVE_STDATOMIC_H default true in
|
||||
NuttX platform
|
||||
|
||||
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
|
||||
---
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 61756465a3dc241297b7a12d5500ac36a5ffa070 Mon Sep 17 00:00:00 2001
|
||||
From 4aaf8a78da2ac2e9627fcbbefa72db7330a57909 Mon Sep 17 00:00:00 2001
|
||||
From: chao an <anchao@lixiang.com>
|
||||
Date: Sat, 29 Jun 2024 09:40:26 +0800
|
||||
Subject: [PATCH 2/5] libmetal/atomic: enable 64-bit atomic by toolchain
|
||||
Subject: [PATCH 2/3] libmetal/atomic: enable 64-bit atomic by toolchain
|
||||
builtin flags
|
||||
|
||||
Fix compile error:
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
From ef06cf5ac9be793200783f24996d529db715ac43 Mon Sep 17 00:00:00 2001
|
||||
From: Bowen Wang <wangbowen6@xiaomi.com>
|
||||
Date: Mon, 25 Nov 2024 23:07:10 +0800
|
||||
Subject: [PATCH 3/3] mutex: change the libmetal nuttx mutex to recursive mutex
|
||||
|
||||
To avoid the crash when lock are acquired twice, one case is in the
|
||||
destroy process:
|
||||
we hold the rdev->lock to iterate the rdev->endpoints to destroy all
|
||||
the endpoints, but rpmsg_destroy_ept() may send the name service message,
|
||||
and need acquire the rdev->lock again to lead crash.
|
||||
|
||||
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
|
||||
---
|
||||
lib/system/nuttx/mutex.h | 18 +++++++++---------
|
||||
1 file changed, 9 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/lib/system/nuttx/mutex.h libmetal/lib/system/nuttx/mutex.h
|
||||
index 26ec4f9..d13c9c5 100644
|
||||
--- a/lib/system/nuttx/mutex.h
|
||||
+++ libmetal/lib/system/nuttx/mutex.h
|
||||
@@ -22,47 +22,47 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
-typedef mutex_t metal_mutex_t;
|
||||
+typedef rmutex_t metal_mutex_t;
|
||||
|
||||
/*
|
||||
* METAL_MUTEX_INIT - used for initializing an mutex element in a static struct
|
||||
* or global
|
||||
*/
|
||||
-#define METAL_MUTEX_INIT(m) NXMUTEX_INITIALIZER
|
||||
+#define METAL_MUTEX_INIT(m) NXRMUTEX_INITIALIZER
|
||||
/*
|
||||
* METAL_MUTEX_DEFINE - used for defining and initializing a global or
|
||||
* static singleton mutex
|
||||
*/
|
||||
-#define METAL_MUTEX_DEFINE(m) metal_mutex_t m = NXMUTEX_INITIALIZER
|
||||
+#define METAL_MUTEX_DEFINE(m) metal_mutex_t m = NXRMUTEX_INITIALIZER
|
||||
|
||||
static inline void __metal_mutex_init(metal_mutex_t *mutex)
|
||||
{
|
||||
- nxmutex_init(mutex);
|
||||
+ nxrmutex_init(mutex);
|
||||
}
|
||||
|
||||
static inline void __metal_mutex_deinit(metal_mutex_t *mutex)
|
||||
{
|
||||
- nxmutex_destroy(mutex);
|
||||
+ nxrmutex_destroy(mutex);
|
||||
}
|
||||
|
||||
static inline int __metal_mutex_try_acquire(metal_mutex_t *mutex)
|
||||
{
|
||||
- return nxmutex_trylock(mutex);
|
||||
+ return nxrmutex_trylock(mutex);
|
||||
}
|
||||
|
||||
static inline void __metal_mutex_acquire(metal_mutex_t *mutex)
|
||||
{
|
||||
- nxmutex_lock(mutex);
|
||||
+ nxrmutex_lock(mutex);
|
||||
}
|
||||
|
||||
static inline void __metal_mutex_release(metal_mutex_t *mutex)
|
||||
{
|
||||
- nxmutex_unlock(mutex);
|
||||
+ nxrmutex_unlock(mutex);
|
||||
}
|
||||
|
||||
static inline int __metal_mutex_is_acquired(metal_mutex_t *mutex)
|
||||
{
|
||||
- return nxmutex_is_locked(mutex);
|
||||
+ return nxrmutex_is_locked(mutex);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
--
|
||||
2.34.1
|
||||
|
||||
@@ -40,6 +40,8 @@ if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/libmetal)
|
||||
${CMAKE_CURRENT_LIST_DIR}/0001-libmetal-cmake-set-HAVE_STDATOMIC_H-default-true-in-.patch
|
||||
&& patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
|
||||
${CMAKE_CURRENT_LIST_DIR}/0002-libmetal-atomic-enable-64-bit-atomic-by-toolchain-bu.patch
|
||||
&& patch -p0 -d ${CMAKE_CURRENT_LIST_DIR} <
|
||||
${CMAKE_CURRENT_LIST_DIR}/0003-mutex-change-the-libmetal-nuttx-mutex-to-recursive-m.patch
|
||||
DOWNLOAD_NO_PROGRESS true
|
||||
TIMEOUT 30)
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ libmetal.zip:
|
||||
mv libmetal-$(LIBMETAL_VERSION) libmetal
|
||||
$(Q) patch -p0 < 0001-libmetal-cmake-set-HAVE_STDATOMIC_H-default-true-in-.patch
|
||||
$(Q) patch -p0 < 0002-libmetal-atomic-enable-64-bit-atomic-by-toolchain-bu.patch
|
||||
$(Q) patch -p0 < 0003-mutex-change-the-libmetal-nuttx-mutex-to-recursive-m.patch
|
||||
|
||||
.libmetal_headers: libmetal.zip
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user