← Supporting evidence

Evidence record

snippets/banked-module-model.swift.inc

From Windows Application to Portable Emulation Platform

2,168 bytes

// Public source: https://vccplus-git.brianholman.com/VCCPlus/VCCPlusOSS/src/branch/main/platforms/macos/App/CMOCBankedDebug.swift
// Selected code lines: 44; selection, not the full current source.
// Original copyright/license notice and selected code follow unchanged.
// SPDX-License-Identifier: GPL-3.0-or-later
import Foundation

/// A build-produced declaration of unpacked code placement. Hashes bind this
/// declaration to one retained build; object relocation replay and live physical
/// RAM comparisons provide the independent byte checks before debugging.
struct CMOCBankedDebugLayout: Sendable {
    struct File: Decodable, Sendable { let path: String; let sha256: String }
    struct Page: Decodable, Equatable, Sendable { let logicalPage: Int; let physicalPage: Int }
    struct CodeGuard: Equatable, Sendable { let address: UInt16; let bytes: [UInt8] }
    struct Framebuffer: Decodable, Equatable, Sendable {
        let id: String
        let physicalAddress: Int
        let mode: String
        var canvasBytes: Int? = nil
        var workerFields: [String: Any] {
            var fields: [String: Any] = ["id": id, "physical_address": physicalAddress, "mode": mode]
            if let canvasBytes { fields["canvas_bytes"] = canvasBytes }
            return fields
        }
    }
    struct Image: Decodable, Sendable {
        let path: String
        let logicalAddress: Int
        let offset: Int?
        let length: Int?
    }
    struct Module: Sendable {
        let id: String
        let sections: [String]
        let codeSections: [String]
        let logicalAddress: Int
        let bytes: [UInt8]
        let pages: [Page]
        let codeGuards: [CodeGuard]
        func physicalAddress(_ logical: Int) -> UInt32? {
            guard (0..<65536).contains(logical),
                  let page = pages.first(where: { $0.logicalPage == logical / 8192 }) else { return nil }
            return UInt32(page.physicalPage * 8192 + logical % 8192)
        }
        func isMapped(physicalPages: [Int]) -> Bool {
            physicalPages.count == 8 && pages.allSatisfy { physicalPages[$0.logicalPage] == $0.physicalPage }
        }
    }

SHA-25640a979e76ccf128d20c9f003c402f67beb43f51b2568f5a31bd14f67bed67246

A closer look

Open original