From 49ddbbd57cc4915d0652996a48505222b04d25a0 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 13 Dec 2019 13:37:02 -0500 Subject: [PATCH] Fix #316: Execption/Intterupt API updates - Ensure the FPU functions that are actually not implemented in RTEMS/POSIX all return OS_ERR_NOT_IMPLEMENTED, not OS_SUCCESS. - The RTEMS IntEnable/Disable API should not be a duplicate of the IntLock/Unlock API, as the semantics are slightly different. The Enable/Disable API should return OS_ERR_NOT_IMPLEMENTED. - The OS_FPUExcGetMask API should confirm that the output buffer is not NULL. --- src/os/posix/osapi.c | 4 ++-- src/os/rtems/osapi.c | 35 +++++++++++++++++++++++------------ src/os/shared/osapi-fpu.c | 5 +++++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/os/posix/osapi.c b/src/os/posix/osapi.c index c41cda190..dead711df 100644 --- a/src/os/posix/osapi.c +++ b/src/os/posix/osapi.c @@ -2382,7 +2382,7 @@ int32 OS_FPUExcSetMask_Impl(uint32 mask) /* ** Not implemented in linux. */ - return(OS_SUCCESS); + return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_FPUExcSetMask_Impl */ @@ -2400,7 +2400,7 @@ int32 OS_FPUExcGetMask_Impl(uint32 *mask) ** Not implemented in linux. */ *mask = 0; - return(OS_SUCCESS); + return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_FPUExcGetMask_Impl */ /********************************************************************/ diff --git a/src/os/rtems/osapi.c b/src/os/rtems/osapi.c index 56ce59f83..85e6fc9b2 100644 --- a/src/os/rtems/osapi.c +++ b/src/os/rtems/osapi.c @@ -1469,7 +1469,8 @@ int32 OS_IntAttachHandler_Impl (uint32 InterruptNumber, osal_task_entry Interru *-----------------------------------------------------------------*/ int32 OS_IntUnlock_Impl (int32 IntLevel) { - rtems_interrupt_enable ( (rtems_interrupt_level) IntLevel); + rtems_interrupt_level rtems_int_level = IntLevel; + rtems_interrupt_local_enable ( rtems_int_level ); return (OS_SUCCESS); } /* end OS_IntUnlock_Impl */ @@ -1487,7 +1488,21 @@ int32 OS_IntLock_Impl (void) { rtems_interrupt_level rtems_int_level; - rtems_interrupt_disable(rtems_int_level) ; + /* + * NOTE: rtems_interrupt_local_disable() is a macro + * that sets the rtems_int_level value. + * + * This code assumes that the value is also storable + * in an int32. + * + * This uses the "local" version which operates on + * the current CPU in case of a multi-processor environment. + * + * This should be identical to rtems_interrupt_disable in + * a single-processor config, but that call is not + * implemented in multi-processor configs. + */ + rtems_interrupt_local_disable(rtems_int_level) ; return ( (int32) rtems_int_level) ; } /* end OS_IntLock_Impl */ @@ -1504,8 +1519,7 @@ int32 OS_IntLock_Impl (void) *-----------------------------------------------------------------*/ int32 OS_IntEnable_Impl (int32 Level) { - rtems_interrupt_enable ( (rtems_interrupt_level) Level); - return(OS_SUCCESS); + return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntEnable_Impl */ @@ -1519,10 +1533,7 @@ int32 OS_IntEnable_Impl (int32 Level) *-----------------------------------------------------------------*/ int32 OS_IntDisable_Impl (int32 Level) { - rtems_interrupt_level rtems_int_level; - - rtems_interrupt_disable(rtems_int_level) ; - return ( (int32) rtems_int_level) ; + return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_IntDisable_Impl */ @@ -1612,7 +1623,7 @@ int32 OS_FPUExcEnable_Impl(int32 ExceptionNumber) /* ** Not implemented in RTEMS. */ - return(OS_SUCCESS); + return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_FPUExcEnable_Impl */ /*---------------------------------------------------------------- @@ -1628,7 +1639,7 @@ int32 OS_FPUExcDisable_Impl(int32 ExceptionNumber) /* ** Not implemented in RTEMS. */ - return(OS_SUCCESS); + return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_FPUExcDisable_Impl */ @@ -1645,7 +1656,7 @@ int32 OS_FPUExcSetMask_Impl(uint32 mask) /* ** Not implemented in RTEMS. */ - return(OS_SUCCESS); + return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_FPUExcSetMask_Impl */ @@ -1662,7 +1673,7 @@ int32 OS_FPUExcGetMask_Impl(uint32 *mask) /* ** Not implemented in RTEMS. */ - return(OS_SUCCESS); + return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_FPUExcGetMask_Impl */ /********************************************************************/ diff --git a/src/os/shared/osapi-fpu.c b/src/os/shared/osapi-fpu.c index 4959b9ff2..2d2ce1d1e 100644 --- a/src/os/shared/osapi-fpu.c +++ b/src/os/shared/osapi-fpu.c @@ -76,6 +76,11 @@ int32 OS_FPUExcSetMask(uint32 mask) *-----------------------------------------------------------------*/ int32 OS_FPUExcGetMask(uint32 *mask) { + if (mask == NULL) + { + return OS_INVALID_POINTER; + } + return OS_FPUExcGetMask_Impl(mask); } /* end OS_FPUExcGetMask */