* 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>
- resolve fops from dfs_file instead of vnode directly
- keep compatibility with both DFSv1 and DFSv2
- validate fops before dereferencing to avoid NULL access
Newer GCC emits C++ global constructors into .init_array, which many
linker scripts keep outside [__ctors_start__, __ctors_end__), so they
never ran. Walk __init_array_start/__init_array_end (weak) as well,
skipping entries already covered by the ctors range.
Add RT_USING_CPP_CRT_INIT for ports whose startup runtime already runs
.init_array, default on for the simulator. With it set, only the
.init_array walk is skipped; the ctors range is still walked.
Renesas RA/RA_WIRELESS/RZ families select it when C++ is enabled: FSP
SystemInit() already walks .init_array, so boards whose linker script
only provides __init_array_* would run constructors twice. Boards that
fold .init_array into the ctors range (ra6m3-hmi-board, ra8d1, rz)
still run them once via RT-Thread.
Also source env.sh and restore RTT_EXEC_PATH in ToolsCI project generate
and dist steps so scons is on PATH (exit 127) and the ARM toolchain path
is not overwritten by env.sh.
Fixes#11778
The original overflow logic used __spm[tm_mon] as the current month's
length when normalizing tm_mday. This produced incorrect dates after
crossing month boundaries and left zero or negative days unnormalized.
Use the difference between adjacent cumulative day offsets with
leap-year handling. Normalize overflow in tm_sec, tm_min, tm_hour,
tm_mday, and tm_mon to keep the affected broken-down fields normalized.
Add regression tests for month boundaries, leap years, large offsets,
zero and negative days, negative time fields, combined overflow, and
boundary carry cases.
Close#11686
Signed-off-by: Hui Su <3164683437@qq.com>
[Problem Description]
In the dlmodule_load_shared_object function,
if a module loading fails once due to an unresolved symbol,
all subsequent attempts to load any module will fail.
The system becomes unable to load modules correctly until a reboot.
[Problem Analysis]
The root cause is that the variable unsolved is defined as static.
Static variables retain their value between function calls.
If a relocation error occurs, unsolved is set to RT_TRUE.
However, when the function returns with an error, the value of unsolved is not reset.
Consequently, on the next function call, unsolved remains RT_TRUE from the previous execution.
This causes the check if (unsolved) to trigger immediately (or after the loop),
forcing the function to return an error regardless of whether the current module is valid or not.
[Solution]
Reset the unsolved variable to RT_FALSE before returning the error code -RT_ERROR.
This ensures the variable is in a clean state for the next function call, preventing state leakage between invocations.
Signed-off-by: Liu Gui <kenneth.liu@sophgo.com>
The POSIX mq_send() function currently passes timeout=0 to
rt_mq_send_wait_prio(), causing it to return immediately when the
queue is full instead of blocking as required by POSIX.1-2017.
This patch:
1. Changes mq_send() to use RT_WAITING_FOREVER for blocking behavior
2. Implements mq_timedsend() properly with timeout support
3. Fixes errno mapping for different error conditions
Reference: POSIX.1-2017 mq_send(3p):
"If the specified message queue is full, mq_send() shall block until
space becomes available to enqueue the message, or until mq_send()
is interrupted by a signal."
Fixes: https://github.com/RT-Thread/rt-thread/issues/11196
Signed-off-by: hzt <3061613175@qq.com>
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
Weekly CI Scheduler / Trigger and Monitor CIs (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
doc_doxygen / doxygen_doc generate (push) Has been cancelled
doc_doxygen / deploy (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
ToolsCI / Tools (push) Has been cancelled
Weekly CI Scheduler / Create Discussion Report (push) Has been cancelled
* [components][clock_time] Refactor time subsystem around clock_time
Introduce the clock_time core with clock source/event separation, high-resolution scheduling, and boot-time helpers, plus clock_timer adapters for timer peripherals.
Remove legacy ktime/cputime/hwtimer implementations and migrate arch and BSP time paths to the new subsystem while keeping POSIX time integration functional.
Update drivers, Kconfig/SConscript wiring, documentation, and tests; add clock_time overview docs and align naming to clock_boottime/clock_hrtimer/clock_timer.
* [components][clock_time] Use BSP-provided clock timer frequency on riscv64
* [risc-v] Use runtime clock timer frequency for tick and delays
* [bsp] Add clock timer frequency hooks for riscv64 boards
* [bsp] Update Renesas RA driver doc clock_timer link
* [bsp] Sync zynqmp-r5-axu4ev rtconfig after config refresh
* [bsp][rk3500] Update rk3500 clock configuration
* [bsp][hpmicro] Add rt_hw_us_delay hook and update board delays
* [bsp][stm32l496-st-nucleo] enable clock_time for hwtimer sample in ci
* [bsp][hpmicro] Fix rtconfig include scope for hpm6750evk
Move rtconfig.h include outside the ENET_MULTIPLE_PORT guard for hpm6750evk and hpm6750evk2 so configuration macros are available regardless of ENET settings.
* [bsp][raspi3] select clock time for systimer
* [bsp][hpm5300evk] Trim trailing blank line
* [bsp][hpm5301evklite] Trim trailing blank line
* [bsp][hpm5e00evk] Trim trailing blank line
* [bsp][hpm6200evk] Trim trailing blank line
* [bsp][hpm6300evk] Trim trailing blank line
* [bsp][hpm6750evk] Trim trailing blank line
* [bsp][hpm6750evk2] Trim trailing blank line
* [bsp][hpm6750evkmini] Trim trailing blank line
* [bsp][hpm6800evk] Trim trailing blank line
* [bsp][hpm6e00evk] Trim trailing blank line
* [bsp][nxp] switch lpc178x to gcc and remove mcx timer source
* [bsp][stm32] fix the CONFIG_RT_USING_CLOCK_TIME issue.
* [docs][clock_time] add clock time documentation
* [docs][clock_time] Update clock time subsystem documentation
- Update device driver index to use correct page reference
- Clarify upper layer responsibilities in architecture overview
- Update README to describe POSIX/libc, Soft RTC, and device driver usage
- Refine architecture diagram with improved layout and color scheme
- Remove obsolete clock_timer.md file
* [kernel][utest] Trim trailing space
* [clock_time] Fix hrtimer wrap handling
* [clock_time] fix the static rt_inline issue
* [clock_time] fix the rt_clock_hrtimer_control result issue
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
doc_doxygen / deploy (push) Has been cancelled
Weekly CI Scheduler / Trigger and Monitor CIs (push) Has been cancelled
ToolsCI / Tools (push) Has been cancelled
doc_doxygen / doxygen_doc generate (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
Weekly CI Scheduler / Create Discussion Report (push) Has been cancelled
Some comments have been initially added as a bignner task.
components/libc/cplusplus/os/cxx_Semaphore.cpp
components/libc/cplusplus/os/cxx_Thread.cpp
components/libc/cplusplus/utest/tc_atomic.cpp
components/libc/cplusplus/utest/tc_smartptr.cpp
components/libc/cplusplus/utest/tc_thread.cpp
Signed-off-by:Liu Chengtao<2739960959@qq.com>
Use "Test" instead of "Unit Testcases" to make string shorter.
Use uppercase to make it look more eye-catching.
Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
* [components/libc/posix][pthreads]fix the risk of dangling pointer
* [components][dfs][dfs_elm]:fix risk of dangling pointer, unmount the temp driver then free the temp FATFS in dfs_elm_mkfs.
[Problem Description]
1. When enabling RT_USING_MODULE=y, compilation warnings occur:
dlelf.c:386:27: warning: cast from pointer to integer of different size
dlelf.c:398:25: warning: cast from pointer to integer of different size
dlelf.c:408:24: warning: cast from pointer to integer of different size
2. On RV64 architectures (e.g. Sophgo SG2042 with RISC-V Sv39 and 40-bit physical addressing),
dlsym may fail when accessing addresses beyond 32-bit range.
[Root Cause]
In dlmodule_load_relocated_object() and dlmodule_symbol_find(),
pointer is cast to rt_uint32_t which truncates:
| rt_ubase_t rodata_addr = (rt_uint32_t)ptr;
This causes:
- Warnings on 64-bit systems (pointer width > 32-bit)
- Actual address truncation on RV64 when physical address exceeds 32-bit
[Solution]
Replace rt_uint32_t with architecture-adaptive rt_ubase_t:
| rt_ubase_t rodata_addr = (rt_ubase_t)ptr;
The rt_ubase_t is defined in include/rttypes.h as:
| #ifdef ARCH_CPU_64BIT
| typedef rt_uint64_t rt_ubase_t;
| #else
| typedef rt_uint32_t rt_ubase_t;
| #endif
This ensures correct width casting for both 32/64-bit architectures.
Signed-off-by: Liu Gui <kenneth.liu@sophgo.com>
AutoTestCI / components/cpp11 (push) Waiting to run
AutoTestCI / kernel/atomic (push) Waiting to run
AutoTestCI / kernel/atomic_c11/riscv64 (push) Waiting to run
AutoTestCI / kernel/device (push) Waiting to run
AutoTestCI / kernel/ipc (push) Waiting to run
AutoTestCI / kernel/irq (push) Waiting to run
AutoTestCI / kernel/thread (push) Waiting to run
AutoTestCI / kernel/timer (push) Waiting to run
AutoTestCI / components/utest (push) Waiting to run
RT-Thread BSP Static Build Check / ESP32C3 (push) Waiting to run
RT-Thread BSP Static Build Check / Infineon_TI_microchip (push) Waiting to run
RT-Thread BSP Static Build Check / RTduino/Arduino Libraries (Raspberry Pico) (push) Waiting to run
RT-Thread BSP Static Build Check / RTduino/Arduino Libraries (STM32F412 Nucleo) (push) Waiting to run
RT-Thread BSP Static Build Check / aarch64 (push) Waiting to run
RT-Thread BSP Static Build Check / i386-unknown (push) Waiting to run
RT-Thread BSP Static Build Check / llvm-arm (push) Waiting to run
RT-Thread BSP Static Build Check / nuvoton (push) Waiting to run
RT-Thread BSP Static Build Check / riscv-none (push) Waiting to run
RT-Thread BSP Static Build Check / stm32_f2_f4 (push) Waiting to run
RT-Thread BSP Static Build Check / stm32_f7_g0_h7_mp15_u5_h5_wb5 (push) Waiting to run
pkgs_test / change (push) Has been skipped
AutoTestCI / kernel/atomic/riscv64 (push) Waiting to run
AutoTestCI / kernel/atomic_c11 (push) Waiting to run
AutoTestCI / kernel/mem (push) Waiting to run
AutoTestCI / kernel/mem/riscv64 (push) Waiting to run
AutoTestCI / rtsmart/aarch64 (push) Waiting to run
AutoTestCI / rtsmart/arm (push) Waiting to run
AutoTestCI / rtsmart/riscv64 (push) Waiting to run
RT-Thread BSP Static Build Check / RT-Thread Online Packages (STM32F407 RT-Spark) (push) Waiting to run
RT-Thread BSP Static Build Check / gd32_n32_apm32 (push) Waiting to run
RT-Thread BSP Static Build Check / hpmicro (push) Waiting to run
RT-Thread BSP Static Build Check / mips (push) Waiting to run
RT-Thread BSP Static Build Check / nordic(yml) (push) Waiting to run
RT-Thread BSP Static Build Check / nxp_renesas (push) Waiting to run
RT-Thread BSP Static Build Check / others_at32_hc32_ht32 (push) Waiting to run
RT-Thread BSP Static Build Check / riscv64-unknown (push) Waiting to run
RT-Thread BSP Static Build Check / simulator (push) Waiting to run
RT-Thread BSP Static Build Check / stm32l4_f0_f1 (push) Waiting to run
BSP compilation with more drivers / BSP Compilation with More Drivers (push) Waiting to run
[Problem Description]
When assigning name to rt_object, strncpy() uses size equal to RT_NAME_MAX,
which causes missing null-terminator and overflows into adjacent 'type' field.
This corruption leads to unexpected system behavior.
[Problem Analysis]
The rt_object structure defines:
| char name[RT_NAME_MAX] | -> buffer
| rt_uint8_t type | -> adjacent field
Original code calculates size as:
size = end - first + 1;
if (size > RT_NAME_MAX) size = RT_NAME_MAX;
When size equals RT_NAME_MAX, strncpy() will copy exactly RT_NAME_MAX bytes
without adding terminating '\0', causing two issues:
1. name buffer is not null-terminated
2. The implicit null-byte writes beyond name[] into type field
[Solution]
Change boundary check from:
if (size > RT_NAME_MAX) size = RT_NAME_MAX;
to:
if (size >= RT_NAME_MAX) size = RT_NAME_MAX - 1;
This ensures:
1. Always leaves space for null-terminator
2. Prevents overflow into type field
3. Maintains maximum valid name length (RT_NAME_MAX-1 + '\0')
Signed-off-by: Liu Gui <kenneth.liu@sophgo.com>