* dfs/posix: enforce bounds check and clean unregister in signalfd Validate array bounds on signalfd notification registration and remove the unsafe global index counter. Tie the registered process lifetime to the registration: each slot in sfd->lwp[] holds an LWP reference, and the listener node carries a detach hook that the process exit path runs under LWP_LOCK to unlink the node, clear the slot and drop the reference. Final close therefore never walks a freed process, and a child that registered through an inherited descriptor is unregistered when it exits. Move every change of lwp->signalfd_notify_head behind lwp_signal_notify_* helpers in the lwp core, which take LWP_LOCK, the lock lwp_signal_notify() traverses the list under. The lock order is LWP_LOCK -> sfd->lock, the same order the signal path already uses; sfd->lock is never held while taking LWP_LOCK, and a node is only unlinked under LWP_LOCK, so no in-flight notification can be inside it when it is freed. Tear down the vnode, context and mutex before fd_release() when the initial registration fails, and return instead of falling through to freed objects. Propagate registration failures: read returns the error and poll reports POLLERR before anything is added to the poll queue. Fixes: #11933 Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com> * dfs/posix: state the signalfd context lifetime and tighten close State the lifetime assumption of the signalfd context explicitly: the descriptor the caller operates on pins the context for the whole read, poll and registration, and a concurrent close of that same descriptor by another thread is not supported, which is what the existing read and poll paths already rely on. The post-registration slot re-check therefore does not add a new requirement. Clear all registration slots in one pass under sfd->lock in close and run the per-process unlink and reference drop outside the lock afterwards, so the "clear first, unlink later" invariant is one block instead of a lock round-trip per slot. Rename SIGNALFD_SHART_MAX to SIGNALFD_SHARE_MAX while the macro block is being touched. Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com> * dfs/posix: keep the LWP lock out of signalfd close and make registration atomic dfs_file_close() calls the signalfd close callback under the global DFS file lock, and the process exit path takes that same lock while it already holds LWP_LOCK (__exit_files() under _resr_cleanup()). Unlinking the listeners from close() through lwp_signal_notify_remove_queue() therefore took the two locks in the opposite order to process exit, and a parent closing a shared signalfd while a registered child exits could block each side on the other's lock. Close no longer takes any LWP lock. It marks the context closing, detaches it from the vnode and submits a release work item to the system workqueue. The work takes the slots over under sfd->lock, unlinks the listeners under each process's own LWP_LOCK with no other lock held, drops the references the slots owned, and frees the context. A process that exits before the work runs has already cleared its slot and dropped its reference through the exit hook, so the work only sees slots that are still live. Registration now does the lookup, the slot assignment and the listener insertion in one critical section under LWP_LOCK(self) -> sfd->lock, the same order the exit hook already uses. A slot is never visible without its listener, so a second thread cannot observe a registration whose listener is still missing, and the lookup cannot go stale between the check and the assignment. lwp_signal_notify_add() accordingly expects the caller to hold LWP_LOCK; the single-node unlink helper that the post-registration re-check used is gone with that re-check. A registration that races with close finds the closing flag and fails with EBADF instead of taking a slot the release work will not see. Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com> * dfs/posix: do not allocate for an existing signalfd registration signalfd_add_notify() allocated the listener node before looking the calling process up, so read and poll on an already registered descriptor failed with ENOMEM or POLLERR under memory pressure even though no node was needed and a signal may already have been queued. Look the process up first, under LWP_LOCK(self) -> sfd->lock, and return from there when it is registered or the context is closing. Only when a new registration is needed drop the locks, allocate the node, take the locks again and repeat the lookup unconditionally: the closing flag, an existing registration and the free slot are all re-evaluated before the slot is assigned and the listener is linked in the same critical section. A node left over because another thread registered the process meanwhile is freed after the locks are released. Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com> * dfs/posix: align signalfd context member comments for clang-format Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com> --------- Signed-off-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com> Co-authored-by: Adil Alperen Ciftci <adilalperenciftci@users.noreply.github.com>
English | 中文 | Español | Deutsch
RT-Thread
RT-Thread was born in 2006, it is an open source, neutral, and community-based real-time operating system (RTOS).
RT-Thread is mainly written in C language, easy to understand and easy to port(can be quickly port to a wide range of mainstream MCUs and module chips). It applies object-oriented programming methods to real-time system design, making the code elegant, structured, modular, and very tailorable.
RT-Thread has Standard version and Nano version. For resource-constrained microcontroller (MCU) systems, the Nano version that requires only 3KB Flash and 1.2KB RAM memory resources can be tailored with easy-to-use tools. For resource-rich IoT devices, RT-Thread can use the on-line software package management tool, together with system configuration tools, to achieve intuitive and rapid modular cutting, seamlessly import rich software packages; thus, achieving complex functions like Android's graphical interface and touch sliding effects, smart voice interaction effects, and so on.
RT-Thread Architecture
RT-Thread has not only a real-time kernel, but also rich components. Its architecture is as follows:
It includes:
-
Kernel layer: RT-Thread kernel, the core part of RT-Thread, includes the implementation of objects in the kernel system, such as multi-threading and its scheduling, semaphore, mailbox, message queue, memory management, timer, etc.; libcpu/BSP (Chip Migration Related Files/Board Support Package) is closely related to hardware and consists of peripheral drivers and CPU porting.
-
Components and Service Layer: Components are based on upper-level software on top of the RT-Thread kernel, such as virtual file systems, FinSH command-line interfaces, network frameworks, device frameworks, and more. Its modular design allows for high internal cohesion inside the components and low coupling between components.
-
RT-Thread software package: A general-purpose software component running on the RT-Thread IoT operating system platform for different application areas, consisting of description information, source code or library files. RT-Thread provides an open package platform with officially available or developer-supplied packages that provide developers with a choice of reusable packages that are an important part of the RT-Thread ecosystem. The package ecosystem is critical to the choice of an operating system because these packages are highly reusable and modular, making it easy for application developers to build the system they want in the shortest amount of time. RT-Thread supports 450+ software packages.
RT-Thread Features
- Designed for resource-constrained devices, the minimum kernel requires only 1.2KB of RAM and 3 KB of Flash.
- A variety of standard interfaces, such as POSIX, CMSIS, C++ application environment.
- Has rich components and a prosperous and fast growing package ecosystem.
- Elegant code style, easy to use, read and master.
- High Scalability. RT-Thread has high-quality scalable software architecture, loose coupling, modularity, is easy to tailor and expand.
- Supports high-performance applications.
- Supports all mainstream compiling tools such as GCC, Keil and IAR.
- Supports a wide range of architectures and chips.
Code Catalogue
RT-Thread source code catalog is shown as follow:
| Name | Description |
|---|---|
| bsp | Board Support Package based on the porting of various development boards |
| components | Components, such as finsh shell, file system, protocol stack etc. |
| documentation | Related documents, like coding style, doxygen etc. |
| examples | Related sample code |
| include | Head files of RT-Thread kernel |
| libcpu | CPU porting code such as ARM/MIPS/RISC-V etc. |
| src | The source files for the RT-Thread kernel. |
| tools | The script files for the RT-Thread command build tool. |
RT-Thread has now been ported for nearly 200 development boards, most BSPs support MDK, IAR development environment and GCC compiler, and have provided default MDK and IAR project, which allows users to add their own application code directly based on the project. Each BSP has a similar directory structure, and most BSPs provide a README.md file, which is a markdown-format file that contains the basic introduction of BSP, and introduces how to simply start using BSP.
Resources
Supported Architectures
RT-Thread supports many architectures, and has covered the major architectures in current applications. Architecture and chip manufacturer involved:
- ARM Cortex-M0/M0+:manufacturers like ST
- ARM Cortex-M3:manufacturers like ST、Winner Micro、MindMotion, ect.
- ARM Cortex-M4:manufacturers like ST、Infineon、Nuvoton、NXP、Nordic、GigaDevice、Realtek、Ambiq Micro, ect.
- ARM Cortex-M7:manufacturers like ST、NXP
- ARM Cortex-M23:manufacturers like GigaDevice
- ARM Cortex-M33:manufacturers like ST
- ARM Cortex-R4
- ARM Cortex-A8/A9:manufacturers like NXP
- ARM7:manufacturers like Samsung
- ARM9:manufacturers like Allwinner、Xilinx 、GOKE
- ARM11:manufacturers like Fullhan
- MIPS32:manufacturers like loongson、Ingenic
- RISC-V RV32E/RV32I[F]/RV64[D]:manufacturers like sifive、Canaan Kendryte、bouffalo_lab、Nuclei、T-Head、HPMicro
- ARC:manufacturers like SYNOPSYS
- DSP:manufacturers like TI
- C-Sky
- x86
Supported IDE and Compiler
The main IDE/compilers supported by RT-Thread are:
- RT-Thread Studio IDE
- MDK KEIL
- IAR
- GCC
RT-Thread Studio IDE
RT-Thread Studio IDE (a.k.a. RT-Studio) is a one-stop intergrated development environment built by RT-Thread team. It has a easy-to-use graphical configuration system and a wealth of software packages and components resources. RT-Studio has the features of project creation, configuration and management,as well as code editing, SDK management, build configuration, debugging configuration, program download and debug. We're looking to make the use of RT-Studio as intuitive as possible, reducing the duplication of work and improving the development efficiency.
Env Tool
In the early stage, RT-Thread team also created an auxiliary tool called Env. It is an auxiliary tool with a TUI (Text-based user interface). Developers can use Env tool to configure and generate the GCC, Keil MDK, and IAR projects.
Getting Started
RT-Thread Programming Guide | RT-Thread Studio IDE | Kernel Sample | RT-Thread Beginners Guide
Based on STM32F103 BluePill | Raspberry Pi Pico
Simulator
RT-Thread BSP can be compiled directly and downloaded to the corresponding development board for use. In addition, RT-Thread also provides qemu-vexpress-a9 BSP, which can be used without hardware platform. See the getting started guide below for details. Getting Started of QEMU with Env: Windows | Linux Ubuntu | Mac OS
License
RT-Thread follows the Apache License 2.0 free software license. It's completely open-source, can be used in commercial applications for free, does not require the disclosure of code, and has no potential commercial risk. License information and copyright information can generally be seen at the beginning of the code:
/* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
* ...
*/
Community
RT-Thread is very grateful for the support from all community developers, and if you have any ideas, suggestions or questions in the process of using RT-Thread, RT-Thread can be reached by the following means, and we are also updating RT-Thread in real time on these channels. At the same time, any questions can be asked in the issue section of RT-Thread repository or RT-Thread forum, and community members will answer them.
Website | Github | Twitter | LinkedIn | Youtube | Facebook | Medium
Contribution
If you are interested in RT-Thread and want to join in the development of RT-Thread and become a code contributor,please refer to the Code Contribution Guide.



