SIMIA32: make port_lock/port_unlock nesting-aware - #66
Draft
FDSoftware wants to merge 1 commit into
Draft
FDSoftware wants to merge 1 commit into
FDSoftware wants to merge 1 commit into
Conversation
The SIMIA32 simulator port used a simple boolean flag (0/1) for port_lock()/port_unlock(). When ChibiOS timer callbacks call code that uses S-class chSysLock/chSysUnlock (e.g. CriticalSectionLocker inside efiPrintfInternal), chSysUnlock() would reset the flag to 0 even though chSysLockFromISR() had set it to 1 — effectively dropping the ISR lock and corrupting the cooperative scheduler's ready list and delta list. On real ARM hardware this never happens because both S-class and I-class locks manipulate BASEPRI identically, so nesting is implicit. Switch to a counter (++/--) so nested lock/unlock pairs balance correctly, matching the ARM port's behavior.
FDSoftware
marked this pull request as draft
April 13, 2026 18:51
dron0gus
pushed a commit
to dron0gus/ChibiOS
that referenced
this pull request
Sep 4, 2026
…usefi#66) 🤖 chibios-sheriff — backport (advisory) Backport of **rusefi#61** (main commit `2447f6a`) to `stable-21.11.x`. Stable's `ch.hpp` carries the same defects, so this is a real fix backport. **Fixes** - `Scheduler::rescheduleS()` now actually calls `chSchRescheduleS()` (was a no-op function *declaration*). - Typed `Mailbox<T>` `fetch`/`peek` no longer overrun the caller's storage when `sizeof(T) < sizeof(msg_t)` — the **memory-corruption** fix (fetch into a local `msg_t`, narrow on `MSG_OK`); `post`/`peek` use value casts. - `ObjectsPool` rounds its object size up to pointer alignment (the free-list stores a next-pointer per slot). - The synchronization wrappers are no longer copyable, and the `Registry::nextThread()` reference handoff is corrected. **Adaptation:** none — cherry-pick auto-merged cleanly (stable's `ch.hpp` matches main's structure). The `nextThread` handoff fix is semantically correct here because stable's registry iterators are reference-counting since rusefi#54. **Local gates** (stable has no CI): `RT-STM32F407-DISCOVERY-G++` builds clean (g++ 14.3.1); a compile-only probe instantiating `Mailbox<uint8_t,8>` and `ObjectsPool<uint8_t,4>` (`post`/`fetch`/`alloc`) compiles clean — exercising the small-T template fixes. (`.hpp` is not in the CI style glob.) **Changelog:** none — `os/various/cpp_wrappers` is not changelog-tracked (matches rusefi#61 on main, which added no entry). Sheriff-authored backport — a human reviews/merges. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
The SIMIA32 simulator port used a simple boolean flag (0/1) for port_lock()/port_unlock(). When ChibiOS timer callbacks call code that uses S-class chSysLock/chSysUnlock (e.g. CriticalSectionLocker inside efiPrintfInternal), chSysUnlock() would reset the flag to 0 even though chSysLockFromISR() had set it to 1 — effectively dropping the ISR lock and corrupting the cooperative scheduler's ready list and delta list.
On real ARM hardware this never happens because both S-class and I-class locks manipulate BASEPRI identically, so nesting is implicit.
Switch to a counter (++/--) so nested lock/unlock pairs balance correctly, matching the ARM port's behavior.