Repository navigation
Conversation
MISRA stack checking converted the stack address through 32-bit ULONG. Preserved ALIGN_TYPE width in both stack-alignment conversions. Added a native-width behavioral regression that fails on the original code. Focused and single-core checks passed. Local SMP ERROR eclipse-threadx#7 also occurred on the unchanged baseline; final-head upstream SMP CI remains required. The human contributor reviewed and confirmed the contribution. Fixes: eclipse-threadx#744 Assisted-by: Codex (gpt-6.1-sol) <[email protected]>
|
Hi @jnsagai. Thank k you for this contribution. I will look into it. |
fdesbiens
left a comment
There was a problem hiding this comment.
Thanks for this — the truncation is real and the diagnosis is correct. new_stack_start and updated_stack_start are already ALIGN_TYPE, so the loss is confined to the TX_MISRA_ENABLE path, and any port where ULONG is narrower than a pointer is exposed. Worth fixing.
I'd like the fix to take a different shape, though. TX_MISRA_ENABLE exists so that every pointer/integer conversion in the kernel routes through a shim in tx_misra.c, which is the single place the Rule 11.6 deviation is documented and audited. Replacing the macro with an inline cast in common/src/tx_thread_create.c moves that deviation into the kernel, so every MISRA build now carries it in the kernel sources rather than in the shim module. The comment documents it, but relocating it is the part I'd push back on.
common/src/tx_misra.c:551 already defines _tx_misra_uchar_to_align_type_pointer_convert, so an ALIGN_TYPE shim is an established shape in that file. Adding _tx_misra_pointer_to_align_type_convert and _tx_misra_align_type_to_pointer_convert alongside it, and defining TX_POINTER_TO_ALIGN_TYPE_CONVERT and TX_ALIGN_TYPE_TO_POINTER_CONVERT in the TX_MISRA_ENABLE arm of tx_api.h, lets tx_thread_create.c drop both #ifdef blocks and use the macro unconditionally. Same end state in the source, deviation stays where it is documented.
On "consistent with the SMP creation path": common_smp/src/tx_thread_create.c:142 uses TX_POINTER_TO_ALIGN_TYPE_CONVERT itself rather than an inline cast, so the macro approach is the one that matches it.
There is also a reason to prefer that shape beyond tidiness. TX_POINTER_TO_ALIGN_TYPE_CONVERT is defined only in the non-MISRA arm of both headers, and the SMP file uses it unconditionally, so SMP does not compile with TX_MISRA_ENABLE and TX_ENABLE_STACK_CHECKING together:
common_smp/src/tx_thread_create.c:142:24: error: implicit declaration of function
'TX_POINTER_TO_ALIGN_TYPE_CONVERT'; did you mean 'TX_POINTER_TO_ULONG_CONVERT'?
Nothing builds that combination today, which is why it has gone unnoticed, but the native64 MISRA stack-checking lane this PR adds is exactly the kind of configuration that would reach it. Defining the macros in the MISRA arm fixes SMP at the same time. Whether SMP belongs in this PR or a follow-up is your call — it has the same truncation, since it converts through the same path once it compiles.
|
Correction to my earlier comment. I checked the SMP path against the 6.4.1 tag rather than against the base this targets, and two of my three points are wrong as a result. #742 already moved That also settles the Rule 11.6 placement question against what I argued. #742 chose the inline conversion for the simulator ports and the SMP create path rather than adding shims to No objection to the approach from me. The open items are the ones already in your own list rather than anything from my comment. |
With
TX_MISRA_ENABLEandTX_ENABLE_STACK_CHECKINGenabled,_tx_thread_createconverts the supplied stack address throughULONG. On ports whereULONGis narrower than a pointer, this loses the high address bits before the stack metadata reaches the port builder. The native x86_64 Linux/GNU port demonstrates the defect with 32-bitULONG, 64-bitALIGN_TYPEand 64-bit pointers, for both aligned and misaligned high-address stacks.The fix uses the port-defined, pointer-capable
ALIGN_TYPEfor both conversions around stack alignment. It preserves the existing alignment, usable-size calculation and guard reservations. The conversion comment documents the required MISRA C:2012/2023 Rule 11.6 deviation (C:2004 Rule 11.3), consistent with the SMP creation path. Formal MISRA compliance is not established by these tests.The regression adds an independent native64 lane to the Linux/GNU host suite while retaining its native32 coverage. The metadata harness executes the real create service and MISRA shim across 16 alignment/size combinations, checking full-width addresses, usable size, fill boundaries, guard space, caller padding and creation state. A non-MISRA control exercises the same combinations. Four further tests use the real Linux kernel to create, resume, sleep/wake and complete threads at offsets 0–3; a wrapper checks metadata before the real stack builder can dereference it. The Linux simulator uses pthread-owned execution stacks, so this verifies supplied-stack metadata and simulator scheduling rather than execution on the supplied hardware stack.
Validation below is bound to frozen patch SHA-256
20e8f835c769f33dd69cae1bff51824b7f26e8b158c67ba01d62006ece3eb80e, based ondevcommite73752681bd405deddf247d1cf2b899d502dceaa. Local runtime checks used GCC 14.2.0 in container imagesha256:a8a3d92ee0ba622304a79ce1dcc51aba1ad1d0ac52767c71b7c1e158520275cc, withSYS_NICEandrtprio=3:3. The retained evidence bundle containsfreeze.json,verification.json, native logs and JUnit reports; its overall status isprepared-with-baseline-failure, withlocal_validation_complete: false.verification/baseline-test.log,verification/baseline.xml-Werror; unchanged native64 sources retain warnings.verification/focused-configure.log,verification/focused-build.log,verification/focused-test.log,verification/focused.xmlscripts/build_tx.shandscripts/test_tx.shTX_COVERAGE=ON,CTEST_REPEAT_FAIL=1,CTEST_TIMEOUT=120.verification/tx-build.log,verification/tx-test.log,verification/tx/*.xmlscripts/build_smp.shandscripts/test_smp.sh0,2,4,6.verification/smp-build.log,verification/smp-test.log,verification/smp/*.xmlTX_ENABLE_CONST_NAMESexplicitly enabled and a 120-second timeout. This does not establish a pass for the stock default profile.verification/freertos-configure.log,verification/freertos-build.log,verification/freertos-test.log,verification/freertos.xmlverification/license-headers.log,license-headers.jsonscripts/check_ai_disclosure.shverification/ai-disclosure.logscripts/check_ports.sh --no-regenverification/port-consistency.logThe current SMP failure is
default_build_coverage::threadx_smp_random_resume_suspend_exclusion_pt_test, assertionERROR #7. An independent run of that test on the unchanged original baseline ate73752681bd405deddf247d1cf2b899d502dceaafailed the same assertion, exit 1, with the same image, GCC 14.2/C99/native32 build profile, configuration and CPU affinity0,2,4,6. Relevant SMP, port, test, shared, toolchain and script inputs are unchanged; normalized compile/link commands match. This reproduces this particular failure on baseline and does not waive the failed suite. Seesmp-baseline-reproduction.jsonandverification/baseline-smp-default_build_coverage-1.log. Final-head upstream SMP CI must pass before requesting review or claiming merge readiness.Historical failures remain recorded separately in
diagnostics/smp-retained-failures-index.json. In particular, an earliertrace_build::threadx_event_flag_suspension_timeout_testfailedERROR #7after the 63-tick sleep, where the allowed counters are 32–33 and 13–14. All ten original-baseline diagnostic runs passed with affinity0,2,4,6: no matching failure or baseline waiver is established. The exact earlier candidate Ninja command comparison is unavailable because the next verification removed that build directory. This event-flag assertion is distinct from the randomized preemption-threshold assertion, and later verification does not erase that failed attempt. Historical randomized default and disabled-notification failures reproduced on baseline; the historical trace failure at affinity0,1,2,3did not reproduce in ten baseline attempts. Separate paired trace failures at0,2,4,6do not establish equivalence for the earlier affinity. Seediagnostics/baseline-smp-event-flag-timeout/summary.jsonand the retained index.Measured merged line coverage is 99.364% for the single-core kernel (4374/4402 lines) and 99.78% for SMP (4989/5000); branch coverage is 85.792% and 84.463%, respectively. These are local measurements, including coverage from the failed SMP run, and do not establish complete coverage or successful remote coverage gates. RISC-V, reference Arm GCC/clang, Cortex-M, FVP and real-hardware execution have not been validated locally on this frozen patch. Stock FreeRTOS and generated-port regeneration still require upstream validation; FVP execution counts only if the model actually runs.
There are no outstanding code dependencies or new external dependencies. PR #742, needed for the native MISRA simulator build, is already in the base and explicitly excluded #744. A required companion clarification of
tx_thread_createis prepared for rtos-docs-asciidoc againstmain; its submitted PR is linked below. This kernel contribution targetsdev.This contribution was developed with AI assistance from Codex (
gpt-6.1-sol), as recorded in the patch headers and review evidence; this PR text is also AI-assisted. The human contributor's actual conversation confirmation is retained inhuman-review.jsonandhuman-review-conversation.json. The receipt binds to the finalized patch digest above and approves only the three new-file header wording changes from the reviewed patch; comparison confirms no substantive delta. The independent technical and process review records both pass for this digest and are automated reviews. The receipt does not establish copyright ownership, employer permission or maintainer approval. The submitting human retains technical and provenance responsibility under ThreadX CONTRIBUTING.md and the Eclipse AI guidelines. Any substantive patch change requires renewed human review, freezing, verification and independent review.Acceptance remains conditional. The publisher requires a passing publication-phase license audit and verifies the effective and committed Author email against the human-confirmed ECA email before submission. Both contributions are submitted as drafts. A successful Eclipse username ECA lookup is recorded; final-head
eclipsefdn/ecasuccess is required for both contributions; the ECA API distinguishes lookup from contribution validation. Required final-head checks aretx / run_tests,smp / run_tests,freertos / run_testsandriscv / run_tests, including the kernel/SMP 99% line coverage gates. Applicablegnu,atfe, Cortex-M0/M3/M4/M7 build,cortex-m,cortex-a,r52and repositorychecksjobs also remain pending, as does any required fork-workflow authorization. One upstream approving review, code-owner review and documentation maintainer review are still required. No maintainer approval is evidenced.Fixes #744
Matching documentation: eclipse-threadx/rtos-docs-asciidoc#107.