Skip to content

Add the Memory Manager's heap zone, checked against Mac OS 9.2.2 - #48

Merged
colemancda merged 9 commits into
masterfrom
feature/memory-manager
Dec 1, 2026
Merged

colemancda merged 9 commits into
masterfrom
feature/memory-manager

Conversation

@colemancda

Copy link
Copy Markdown
Member

Adds a GraphiteMemory target with a heap zone that manages handles and pointers in guest memory, and a Retro68 probe whose Mac OS 9.2.2 capture the tests check it against.

What Mac OS 9.2.2 showed

ReferenceTests/Retro68/MemoryManager-macos-9.2.2-ppc.txt, summarized in the Retro68 README:

  • NewHandle(-1) and NewPtr(-1) give memSCErr (-116); SetHandleSize and SetPtrSize take a negative size as 0, without an error.
  • A handle's state bits go with its block. For an empty or purged handle, HGetState, HLock, HUnlock, HPurge, GetHandleSize and SetHandleSize give nilHandleErr (-109), and HGetState returns 0x93. ReallocateHandle gives a block with no bits set.
  • EmptyHandle and ReallocateHandle of a locked handle give memPurErr (-112). A locked block that can't grow in place gives memFullErr and keeps its size; an unlocked one moves.
  • DisposeHandle, EmptyHandle and DisposePtr accept nil; GetPtrSize(nil) gives memAZErr (-113).
  • A disposed handle's master pointer is the next one NewHandle hands out.

Changes

  • GuestMemory: checked read, write and move of guest bytes, the interface BlueBox provides; ByteGuestMemory backs it with a byte array for tests.
  • HeapZone: master pointers in guest memory, so guest code can dereference handles; generation-checked HandleIDs; compaction of unlocked blocks, then purging, when space runs out; purgeProc and resourceDisposed hooks for the Resource Manager; MemError, FreeMem, MaxBlock, CompactMem and PurgeMem.
  • MacError: memAdrErr, memWZErr, memPurErr, memAZErr, memSCErr and memLockedErr.

Two cases the capture couldn't settle, because they would crash the probe: a disposed handle gives memWZErr (-111), and an address that was never a handle gives memAdrErr (-110).

Testing

swift test passes: all 15 test runs, including 11 HeapZoneTests.

@colemancda
colemancda merged commit 529a489 into master Dec 1, 2026
3 checks passed
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.

1 participant