Skip to content

fix: leave later system patches in place when dopus5.library closes - #233

Merged
midwan merged 1 commit into
masterfrom
fix/keep-later-patches-on-quit
Oct 26, 2026
Merged

midwan merged 1 commit into
masterfrom
fix/keep-later-patches-on-quit

Conversation

@midwan

@midwan midwan commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Quitting Opus no longer throws out system patches that other programs installed after it. Until now, with Sysmon's SysInfo.library on the system, the machine could freeze or reboot soon after Opus quit. dopus5.library now restores only the vectors that still point to it, and leaves its own function in a chain someone else has patched since, passing calls through.

Issue

Fixes #231

The freeze in the original report was a stack overflow in aatext.library, fixed in aatext.library 1.1. While tracking it down, the AAText author found this second problem: L_WB_Remove_Patch() wrote the saved vectors back without checking them.

Changes

  • Later patches survive Opus quitting. The clock task opens SysInfo.library for the CPU display. Sysmon's SysInfo loads sysmon.library, which patches 16 exec vectors on top of Opus, AddTask/RemTask/FindTask among them. When dopus5.library closed, it wrote its saved AddTask/RemTask/FindTask vectors back over sysmon's and left the other 13 in place. The next task start hung the machine. Now each vector is checked: if it still points to Opus it is restored, otherwise the newer patch is put back and the Opus function stays in the chain.
  • Pass-through patches. Patch state (wb_old_function, wb_patch_base, wb_patch_flags) moves out of LibData into static arrays, because a patch left in a chain must keep working after the library data is freed. Every patch function starts with a check: when Opus is not running the patch, the call goes straight to the next function and touches no library data. Removal switches the patches off, waits on usecount for calls already running inside them, and only then changes vectors.
  • The library stays loaded while a patch is left in a chain. LibExpunge/LibClose refuse to unload the segment while wb_patches_installed() is true. The next Opus start reuses the resident library and switches the patch back on instead of installing it a second time. In that case a newer dopus5.library on disk only loads after a reboot.
  • Original*() without patches. OriginalOpen() and the other DOS/icon bypass calls use the plain system function when the patch is not running. With dopus/NoSysPatch set, OriginalRelabel(), DeleteIcon(), and WriteIcon() before icon.library V44, read a patch table that was never allocated.
  • OS4: the OpenWorkbenchObject() patch returned FALSE even when the object was opened.
  • The unused #else removal branch is gone; its "reinstall" path set old_function[] instead of the patch.

The atomic usecount helpers move from three copies into wb.h and gain a compiler barrier on OS3, so the patch state is read after the count goes up. The revision bump is left to the release, as in recent PRs.

Affected platforms

  • AmigaOS 3 (os3)
  • AmigaOS 3 / 68000 (os3-68000)
  • AmigaOS 4 (os4)
  • MorphOS (mos)
  • AROS i386 (i386-aros)
  • AROS x86_64 (x86_64-aros)
  • AROS aarch64 (aarch64-aros)

Verification

Runtime checks ran on the A4000 OS 3.2 Amiberry config (68060), with Sysmon 1.20a's SysInfo.library and a probe that dumps exec LVOs -30 to -330 and classifies each vector as ROM, dopus5.library or sysmon.library. The script started Opus, quit it with command quit force, called RemLibrary() on dopus5.library, opened bullet and TrueType fonts, then started and quit Opus a second time.

5.104-era library (73.6) This branch
AddTask/RemTask/FindTask after quit back to pre-sysmon values; other 13 still sysmon all 16 still sysmon
dopus5.library after RemLibrary() unloaded stays loaded
Opus started again machine hung starts, quits, script finishes
Without Sysmon vectors restored, library unloads same
  • Calibri fails to open on this system in both runs. It is a font setup problem, unrelated to this change.
  • Builds: dopus5.library for OS3 (pinned CI image), OS4, MorphOS and AROS i386/x86_64/aarch64. No new warnings against master; MorphOS has 6 fewer (_ATOMIC_ADD pointer sign).

Checklist

  • CI is green (or expected failures are explained).
  • ChangeLog updated with a [dopus5 next] entry.
  • documents/DOpus5.guide updated and @$VER bumped if user-visible
    behaviour changed. (No documented behaviour changes.)
  • Relevant *_REVISION in source/Include/dopus/version.h bumped if
    a versioned binary changed. (Left for the release.)
  • No new compiler warnings introduced on any platform.
  • No drive-by reformatting of unrelated code.

WB_Remove_Patch() wrote the saved vectors back without checking them,
so patches another program installed after Opus were thrown out. With
Sysmon's SysInfo.library (opened by the clock task) this left
sysmon.library half installed, and the machine hung soon after Opus
quit (#231).

Patch state now lives in static arrays outside LibData. Removal turns
every patch into a pass-through, waits for running calls, and restores
only vectors that still point to Opus; a vector patched again keeps its
foreign patch and Opus stays in the chain. The library refuses to
expunge while such a patch remains, and the next Opus start switches it
back on.

The Original*() DOS/icon calls use the system function when the patches
are not running (with dopus/NoSysPatch they read an unallocated table),
and the OS4 OpenWorkbenchObject() patch returns its result.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T21:54:26.798482Z 8aa6910 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@midwan
midwan merged commit ba7da68 into master Oct 26, 2026
18 checks passed
@midwan
midwan deleted the fix/keep-later-patches-on-quit branch October 26, 2026 22:11
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.

Freeze when setting the desktop/windows icon label font to an AATextManager-installed font

1 participant