Fixed the incorrect loop bound constant in the IAR file lock support - #695
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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*mis set toTX_NULLand 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_mutexesand the exhaustion check can never fire.The reported file contained four occurrences (two in each of the
_DLIB_FILE_DESCRIPTORand non-_DLIB_FILE_DESCRIPTORvariants), and the same code is duplicated in all 27 copies oftx_iar.cacrossports/,ports_arch/andports_module/. All 108 occurrences are corrected here.Comment-free, behaviour-only change; no API or ABI impact.