sem_waitirq: Use kmap interface to access the semaphore
The temporary mappings via addrenv_select() and addrenv_restore() simply do not work from interrupt, so remove its usage and replace with kmap which is safe.
This commit is contained in:
parent
95d1e52535
commit
510d9659b4
3 changed files with 14 additions and 16 deletions
|
|
@ -416,6 +416,9 @@ int addrenv_leave(FAR struct tcb_s *tcb);
|
||||||
* 0 (OK) is returned on success and a negated errno is returned on
|
* 0 (OK) is returned on success and a negated errno is returned on
|
||||||
* failure.
|
* failure.
|
||||||
*
|
*
|
||||||
|
* Note:
|
||||||
|
* This API is not safe to use from interrupt.
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int addrenv_select(FAR struct addrenv_s *addrenv,
|
int addrenv_select(FAR struct addrenv_s *addrenv,
|
||||||
|
|
|
||||||
|
|
@ -339,6 +339,9 @@ int addrenv_leave(FAR struct tcb_s *tcb)
|
||||||
* 0 (OK) is returned on success and a negated errno is returned on
|
* 0 (OK) is returned on success and a negated errno is returned on
|
||||||
* failure.
|
* failure.
|
||||||
*
|
*
|
||||||
|
* Note:
|
||||||
|
* This API is not safe to use from interrupt.
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int addrenv_select(FAR struct addrenv_s *addrenv,
|
int addrenv_select(FAR struct addrenv_s *addrenv,
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <nuttx/addrenv.h>
|
|
||||||
#include <nuttx/irq.h>
|
#include <nuttx/irq.h>
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/mm/kmap.h>
|
||||||
|
|
||||||
#include "sched/sched.h"
|
#include "sched/sched.h"
|
||||||
#include "semaphore/semaphore.h"
|
#include "semaphore/semaphore.h"
|
||||||
|
|
@ -54,16 +54,16 @@
|
||||||
* 2. From logic associated with sem_timedwait(). This function is called
|
* 2. From logic associated with sem_timedwait(). This function is called
|
||||||
* when the timeout elapses without receiving the semaphore.
|
* when the timeout elapses without receiving the semaphore.
|
||||||
*
|
*
|
||||||
* Note: this function should used within critical_section
|
* Note: this function should be used within critical_section.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* wtcb - A pointer to the TCB of the task that is waiting on a
|
* wtcb - A pointer to the TCB of the task that is waiting on a
|
||||||
* semphaphore, but has received a signal or timeout instead.
|
* semphaphore, but has received a signal or timeout instead.
|
||||||
* errcode - EINTR if the semaphore wait was awakened by a signal;
|
* errcode - EINTR if the semaphore wait was awakened by a signal;
|
||||||
* ETIMEDOUT if awakened by a timeout
|
* ETIMEDOUT if awakened by a timeout.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* None.
|
||||||
*
|
*
|
||||||
* Assumptions:
|
* Assumptions:
|
||||||
*
|
*
|
||||||
|
|
@ -74,13 +74,8 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
|
||||||
FAR struct tcb_s *rtcb = this_task();
|
FAR struct tcb_s *rtcb = this_task();
|
||||||
FAR sem_t *sem = wtcb->waitobj;
|
FAR sem_t *sem = wtcb->waitobj;
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_ADDRENV
|
#ifdef CONFIG_MM_KMAP
|
||||||
FAR struct addrenv_s *oldenv;
|
sem = kmm_map_user(wtcb, sem, sizeof(*sem));
|
||||||
|
|
||||||
if (wtcb->addrenv_own)
|
|
||||||
{
|
|
||||||
addrenv_select(wtcb->addrenv_own, &oldenv);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* It is possible that an interrupt/context switch beat us to the punch
|
/* It is possible that an interrupt/context switch beat us to the punch
|
||||||
|
|
@ -107,11 +102,8 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
|
||||||
|
|
||||||
dq_rem((FAR dq_entry_t *)wtcb, SEM_WAITLIST(sem));
|
dq_rem((FAR dq_entry_t *)wtcb, SEM_WAITLIST(sem));
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_ADDRENV
|
#ifdef CONFIG_MM_KMAP
|
||||||
if (wtcb->addrenv_own)
|
kmm_unmap(sem);
|
||||||
{
|
|
||||||
addrenv_restore(oldenv);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Indicate that the wait is over. */
|
/* Indicate that the wait is over. */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue