Skip to content

Fixed the incorrect loop bound constant in the IAR file lock support - #695

Merged
fdesbiens merged 1 commit into
eclipse-threadx:devfrom
fdesbiens:fix/issue-444
Sep 3, 2026
Merged

Fixed the incorrect loop bound constant in the IAR file lock support#695
fdesbiens merged 1 commit into
eclipse-threadx:devfrom
fdesbiens:fix/issue-444

Conversation

@fdesbiens

Copy link
Copy Markdown
Contributor

Fixes #444

The IAR multithreaded library support code (tx_iar.c) allocates its file lock mutexes from __tx_iar_file_lock_mutexes[_MAX_FLOCK], but both the wrap-around check and the exhaustion check in __iar_file_Mtxinit() compared the index against _MAX_LOCK — the bound of the unrelated system lock mutex array.

When _MAX_FLOCK > _MAX_LOCK, the free mutex index wraps early and the exhaustion check reports failure while free entries remain, so *m is set to TX_NULL and the application hard faults the first time a file lock is taken. This is the failure @hstokes1 reported.

When _MAX_FLOCK < _MAX_LOCK, the free mutex index is allowed to run past the end of __tx_iar_file_lock_mutexes and the exhaustion check can never fire.

The reported file contained four occurrences (two in each of the _DLIB_FILE_DESCRIPTOR and non-_DLIB_FILE_DESCRIPTOR variants), and the same code is duplicated in all 27 copies of tx_iar.c across ports/, ports_arch/ and ports_module/. All 108 occurrences are corrected here.

Comment-free, behaviour-only change; no API or ABI impact.

The IAR multithreaded library support code allocates its file lock
mutexes from an array of _MAX_FLOCK entries, but the wrap-around check
and the exhaustion check in __iar_file_Mtxinit() both compared against
_MAX_LOCK, the bound of the unrelated system lock mutex array.

When _MAX_FLOCK is greater than _MAX_LOCK, the free mutex index wrapped
early and the exhaustion check reported failure while free entries
remained, so *m was set to TX_NULL and the application faulted the first
time a file lock was taken.  When _MAX_FLOCK is smaller than _MAX_LOCK,
the free mutex index was allowed to run past the end of
__tx_iar_file_lock_mutexes and the exhaustion check could never fire.

Corrected all four comparisons in each of the 27 copies of tx_iar.c.

Fixes eclipse-threadx#444

Assisted-by: Copilot (Opus 5) <noreply@github.com>
@fdesbiens
fdesbiens merged commit 508af54 into eclipse-threadx:dev Sep 3, 2026
12 checks passed
@fdesbiens
fdesbiens deleted the fix/issue-444 branch September 3, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant