summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/libio_.h
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-03-10 17:07:19 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-03-13 09:57:04 +0100
commitc2287ba2cff59a50848151833404bce0e3cf0a70 (patch)
tree24fbd290baf4722b2dd56df731f44b41b6765c45 /cpukit/include/rtems/libio_.h
parentmrm332-testsuite.tcfg: Add dl01 (diff)
downloadrtems-c2287ba2cff59a50848151833404bce0e3cf0a70.tar.bz2
libio: Robust file descriptor reference counting
There was a race conditon in the reference counting of file descriptors during a close() operation. After the call to the close handler, the rtems_libio_free() function cleared the flags to zero. However, at this point in time there may still exist some holders of the file descriptor. With RTEMS_DEBUG enabled this could lead to failed assertions in rtems_libio_iop_drop(). Change the code to use only atomic read-modify-write operations on the rtems_libio_iop::flags.
Diffstat (limited to 'cpukit/include/rtems/libio_.h')
-rw-r--r--cpukit/include/rtems/libio_.h24
1 files changed, 1 insertions, 23 deletions
diff --git a/cpukit/include/rtems/libio_.h b/cpukit/include/rtems/libio_.h
index 916ba85b31..e9eb46263e 100644
--- a/cpukit/include/rtems/libio_.h
+++ b/cpukit/include/rtems/libio_.h
@@ -85,28 +85,6 @@ extern rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry;
extern rtems_filesystem_global_location_t rtems_filesystem_global_location_null;
/**
- * @brief Sets the iop flags to the specified flags together with
- * LIBIO_FLAGS_OPEN.
- *
- * Use this once a file descriptor allocated via rtems_libio_allocate() is
- * fully initialized.
- *
- * @param[in] iop The iop.
- * @param[in] flags The flags.
- */
-static inline void rtems_libio_iop_flags_initialize(
- rtems_libio_t *iop,
- uint32_t flags
-)
-{
- _Atomic_Store_uint(
- &iop->flags,
- LIBIO_FLAGS_OPEN | flags,
- ATOMIC_ORDER_RELEASE
- );
-}
-
-/**
* @brief Sets the specified flags in the iop.
*
* @param[in] iop The iop.
@@ -222,7 +200,7 @@ static inline void rtems_libio_iop_drop( rtems_libio_t *iop )
#define rtems_libio_check_is_open(_iop) \
do { \
- if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \
+ if ((rtems_libio_iop_flags(_iop) & LIBIO_FLAGS_OPEN) == 0) { \
errno = EBADF; \
return -1; \
} \