arm_semihosting.zig – could @constCast cause a HardFault on read‑only memory?

Offen
#986 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
48/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
zig
Bereich
embedded-iot

Rechercherichtung

Read core/src/core/arm_semihosting.zig lines 89–96 and trace callers to determine whether the data slice can refer to read-only memory or is guaranteed writable. Check how the function modifies and restores the final byte, then assess whether the current behavior is safe for flash-backed input. Done means the safety assumption is established and, if needed, a safe approach is agreed on.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

core/src/core/arm_semihosting.zig
Lines: 89–96
Hi,I was looking at this piece of code and I have a question about safety.
The function receives data as []const u8, but then uses @constCast to turn it into []u8 and modifies the last byte (first setting it to 0, later restoring the original value).
In embedded systems, the caller might pass a string literal that lives in flash (read‑only memory). If that happens, wouldn’t that write operation trigger a HardFault? Or is the caller expected to always provide a buffer in RAM?
I’m not sure if I’m missing something – maybe the design assumes that the input is always writable? If not, would it be safer to copy the data to a temporary buffer before modifying it?
I’d appreciate your thoughts on this. Thanks!

Vorherrschende Sprache
Zig
Sterne
2.3k
Forks
198
Ø Merge
2 T. 18 Std.
Gemergte PRs (30 T.)
36

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus ZigEmbeddedGroup/microzig

Alle Issues in ZigEmbeddedGroup/microzig

Ähnliche Issues

Weitere Issues zu Embedded & IoT

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.