Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

machfs subtly corrupts system images when modifying them #84

Open
mihaip opened this issue Dec 27, 2022 · 0 comments
Open

machfs subtly corrupts system images when modifying them #84

mihaip opened this issue Dec 27, 2022 · 0 comments
Labels
bug Something isn't working Build Build system and process

Comments

@mihaip
Copy link
Owner

mihaip commented Dec 27, 2022

Spun off from audio not working (#67), now that I understand a bit better what is going on. Starting with 5be16f6 we would run all system images through a read-modify-write machfs operation (to insert the dynamically-generated Stickies file). This had the side effect of introducing some (as yet undetermined) corruption the main manifestation being that sound did not work.

Sound is handled by batching a driver loaded by the OS, and thus we need to hook resource loading (see https://github.com/mihaip/macemu/blob/infinite-mac-kanjitalk755/BasiliskII/src/rsrc_patches.cpp#L282-L305). When running as expected, we end up seeing a bunch of resource loads and hooking some:

DRVR -20066 found
  patch 1 applied
vCheckLoad DLOG (444c4f47) ID -20065, data 0x639728, size 48
vCheckLoad DITL (4449544c) ID -20065, data 0x639758, size 208
vCheckLoad thng (74686e67) ID -16738, data 0x634e18, size 80
69 32 63 20 6d 33 74 76 61 70 70 6c 80 00 00 00 00 00 00 00 69 32 63 20 be 9e 53 54 52 20 be ad 53 54 52 20 be ac 00 00 00 00 00 00 00 02 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 00
vCheckLoad thng (74686e67) ID -16738, data 0x6391e8, size 80
69 32 63 20 6d 33 74 76 61 70 70 6c 80 00 00 00 00 00 00 00 69 32 63 20 be 9e 53 54 52 20 be ad 53 54 52 20 be ac 00 00 00 00 00 00 00 02 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 c0 00 00 00 00
vCheckLoad i2c  (69326320) ID -16738, data 0x689278, size 2160
vCheckLoad thng (74686e67) ID -16729, data 0x6391e8, size 64
vCheckLoad thng (74686e67) ID -16729, data 0x639338, size 64
vCheckLoad vdig (76646967) ID -16728, data 0x7a8178, size 28848
vCheckLoad thng (74686e67) ID -20225, data 0x639338, size 64
vCheckLoad tdig (74646967) ID -20225, data 0x689278, size 7872
vCheckLoad thng (74686e67) ID -20035, data 0x639338, size 64
vCheckLoad vdig (76646967) ID -20035, data 0x7b3028, size 23632
vCheckLoad thng (74686e67) ID -16731, data 0x639338, size 96
vCheckLoad vdig (76646967) ID -16731, data 0x7a8178, size 29152
vCheckLoad thng (74686e67) ID -20272, data 0x639338, size 96
vCheckLoad thng (74686e67) ID -16572, data 0x639338, size 96
vCheckLoad thng (74686e67) ID -20030, data 0x639338, size 80
vCheckLoad sift (73696674) ID -20030, data 0x79efb8, size 5136
vCheckLoad thng (74686e67) ID -16570, data 0x639338, size 80
vCheckLoad adio (6164696f) ID -16570, data 0x689278, size 1168
vCheckLoad thng (74686e67) ID -16569, data 0x639338, size 80
vCheckLoad sift (73696674) ID -16569, data 0x79eff8, size 6416
vCheckLoad thng (74686e67) ID -20025, data 0x639338, size 80
vCheckLoad sift (73696674) ID -20025, data 0x689278, size 5136
vCheckLoad thng (74686e67) ID -16573, data 0x639338, size 80
vCheckLoad adio (6164696f) ID -16573, data 0x689278, size 3312
vCheckLoad thng (74686e67) ID -16563, data 0x639338, size 80
 thng -16563 found
  patch 1 applied
vCheckLoad sift (73696674) ID -16563, data 0x689278, size 5648
 sift -16563 found
  patch 1 applied
vCheckLoad thng (74686e67) ID -16730, data 0x6392f8, size 64
vCheckLoad vdig (76646967) ID -16730, data 0x7a8178, size 27024
vCheckLoad thng (74686e67) ID -16497, data 0x6392f8, size 80
vCheckLoad sift (73696674) ID -16497, data 0x689278, size 3856
vCheckLoad thng (74686e67) ID -20555, data 0x6393f8, size 64
vCheckLoad tdig (74646967) ID -20555, data 0x7a1f88, size 6992
vCheckLoad thng (74686e67) ID -20491, data 0x6393f8, size 96
vCheckLoad thng (74686e67) ID -20493, data 0x6393f8, size 96
vCheckLoad thng (74686e67) ID -20490, data 0x6393f8, size 96
vCheckLoad thng (74686e67) ID -20489, data 0x6393f8, size 96

However, once run through machfs we see a lot fewer:

DRVR -20066 found
  patch 1 applied
vCheckLoad DLOG (444c4f47) ID -20065, data 0x639728, size 48
vCheckLoad DITL (4449544c) ID -20065, data 0x639758, size 208
vCheckLoad thng (74686e67) ID -16738, data 0x634e18, size 80
459 69 32 63 20 6d 33 74 76 61 70 70 6c 80 00 00 00 00 00 00 00 69 32 63 20 be 9e 53 54 52 20 be ad 53 54 52 20 be ac 00 00 00 00 00 00 00 02 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 00
vCheckLoad thng (74686e67) ID -16729, data 0x639388, size 64

It is interesting that in the working case we end up loading thng ID -16738 twice (with slightly different contents), unclear where the second instance (that differs by one byte is coming from).

mihaip added a commit that referenced this issue Dec 27, 2022
Appears to be due to corruption introduced by modifying the images with
machfs, which in turn results in the sound driver resource not being
loaded. I do not have a fix for that yet (tracked in #84), but as a
workaround we remove the need to read-modify-write the disk image with
machfs.

The main reason why we were doing that was to insert a dynamically-
generated stickies file (see 5be16f6
and 6b04758). However, we can do that
with direct manipulation of the disk image, instead of doing HFS
operations. We do this by generating a placeholder "Stickies file" file
that we copy to the disk image by hand, and then replace it with the
actual file when building images (the images are defragmented with
Speed Disk from Norton Utilities to ensure the placeholder data is
continuous). The load-placeholder-stickies-file script helps with this.

Mac OS 9 still does not have sound by default, because the "Built-in"
source is not selected. It will likely require some tweaks to the PRAM
to fix that.

Updates #67
@mihaip mihaip added Build Build system and process bug Something isn't working labels Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Build Build system and process
Projects
None yet
Development

No branches or pull requests

1 participant