You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2023/03/29 13:53:20 UTC
[nuttx] 02/02: sched/sem_waitirq: Swap user mappings to MMU when releasing semaphore
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit f4683713327aaeab0656e3ea83814b44267bdc4a
Author: Ville Juven <vi...@unikie.com>
AuthorDate: Tue Mar 28 13:58:31 2023 +0300
sched/sem_waitirq: Swap user mappings to MMU when releasing semaphore
sem_t is user memory and the correct mappings are needed to perform
the semaphore wait interruption.
Otherwise either a page fault, or access to the WRONG address environment
happens.
---
sched/semaphore/sem_waitirq.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/sched/semaphore/sem_waitirq.c b/sched/semaphore/sem_waitirq.c
index 2f0a0d8f54..7d69029010 100644
--- a/sched/semaphore/sem_waitirq.c
+++ b/sched/semaphore/sem_waitirq.c
@@ -28,6 +28,7 @@
#include <assert.h>
#include <errno.h>
+#include <nuttx/addrenv.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
@@ -71,6 +72,13 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
FAR struct tcb_s *rtcb = this_task();
FAR sem_t *sem = wtcb->waitobj;
+#ifdef CONFIG_ARCH_ADDRENV
+ if (wtcb->addrenv_own)
+ {
+ addrenv_select(wtcb->addrenv_own);
+ }
+#endif
+
/* It is possible that an interrupt/context switch beat us to the punch
* and already changed the task's state.
*/
@@ -95,6 +103,13 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
dq_rem((FAR dq_entry_t *)wtcb, SEM_WAITLIST(sem));
+#ifdef CONFIG_ARCH_ADDRENV
+ if (wtcb->addrenv_own)
+ {
+ addrenv_restore();
+ }
+#endif
+
/* Indicate that the wait is over. */
wtcb->waitobj = NULL;