Sync source edition with VCC Plus 3.7.0 build 63
This commit is contained in:
1 parent
c652a5276d
commit
b2ecec4d87
86 files changed
+10519
-472
No files matched your search
@@ -20,6 +20,10 @@ struct CMOCSourceMap: Sendable {
|
||||
return (items, values.count, items.count != values.count)
|
||||
}
|
||||
|
||||
struct EvidenceAddress: Hashable {
|
||||
let module: String?
|
||||
let physical: UInt32
|
||||
}
|
||||
struct Instruction: Equatable, Sendable {
|
||||
let sourceLine: Int // one-based C source line
|
||||
let address: UInt16
|
||||
@@ -52,6 +56,19 @@ struct CMOCSourceMap: Sendable {
|
||||
Self.sha256(source) == provenance.sourceSHA256 && Self.sha256(binary) == provenance.binarySHA256
|
||||
}
|
||||
static func sha256(_ data: Data) -> String { SHA256.hash(data: data).map { String(format: "%02x", $0) }.joined() }
|
||||
// Generated assembly may contain full compiler type records and data tables;
|
||||
// it has a larger byte budget than object/listing/map/executable evidence.
|
||||
// Banked verification retains one aggregate cap across unique files.
|
||||
static let maximumVerificationBytes = 128 * 1024 * 1024
|
||||
static func evidenceByteLimit(for path: String) -> Int {
|
||||
(path as NSString).pathExtension.lowercased() == "s" ? 32 * 1024 * 1024 : 8 * 1024 * 1024
|
||||
}
|
||||
static func validateEvidenceSize(_ count: Int, path: String) throws {
|
||||
let limit = evidenceByteLimit(for: path)
|
||||
guard count <= limit else {
|
||||
throw Failure.invalid("artifact \(path) is \(count) bytes; its verification limit is \(limit) bytes.")
|
||||
}
|
||||
}
|
||||
static func decbEntryPoint(_ data: Data) throws -> UInt16 { try BinaryImage(data).entry }
|
||||
|
||||
/// The caller must build all artifacts together from an immutable source
|
||||
@@ -61,8 +78,9 @@ struct CMOCSourceMap: Sendable {
|
||||
sourceAliases: [String] = [], objectAliases: [String] = [],
|
||||
strictIdentities: Bool = false, allowEmpty: Bool = false,
|
||||
bankedLayout: CMOCBankedDebugLayout? = nil) throws -> Self {
|
||||
for data in [source, listing, object, linkMap, binary] {
|
||||
guard data.count <= 8 * 1024 * 1024 else { throw Failure.invalid("an artifact exceeds 8 MB.") }
|
||||
for (name, data) in [(sourceName, source), (String(objectName.dropLast(2)) + ".lst", listing),
|
||||
(objectName, object), ("linker map", linkMap), ("executable", binary)] {
|
||||
try validateEvidenceSize(data.count, path: name)
|
||||
}
|
||||
guard let sourceText = String(data: source, encoding: .utf8), !sourceText.contains("\0"),
|
||||
!sourceName.isEmpty, !objectName.isEmpty else { throw Failure.invalid("invalid source identity or encoding.") }
|
||||
@@ -75,7 +93,7 @@ struct CMOCSourceMap: Sendable {
|
||||
let linePattern = try NSRegularExpression(pattern: #"^\* Line (.+):([0-9]+)(?::.*)?$"#)
|
||||
let functionPattern = try NSRegularExpression(pattern: #"^\* FUNCTION .+: defined at (.+):([0-9]+)$"#)
|
||||
var sectionName: String?, sourceLine: Int?, instructions: [Instruction] = []
|
||||
var seenAddresses = Set<UInt32>()
|
||||
var seenAddresses = Set<EvidenceAddress>()
|
||||
for text in listingLines {
|
||||
let octets = Array(text.utf8)
|
||||
guard octets.count >= 22, octets[21] == 32 else { continue }
|
||||
@@ -121,7 +139,8 @@ struct CMOCSourceMap: Sendable {
|
||||
}
|
||||
let address = UInt16(section.base + offset)
|
||||
let identity = bankedLayout?.module(forSection: sectionName)?.physicalAddress(Int(address)) ?? UInt32(address)
|
||||
guard seenAddresses.insert(identity).inserted else { throw Failure.invalid("duplicate instruction addresses in the listing.") }
|
||||
let qualified = EvidenceAddress(module: bankedLayout?.module(forSection: sectionName)?.id, physical: identity)
|
||||
guard seenAddresses.insert(qualified).inserted else { throw Failure.invalid("duplicate instruction addresses in the listing module.") }
|
||||
instructions.append(Instruction(sourceLine: sourceLine, address: address,
|
||||
bytes: Array(final[offset..<(offset + originalBytes.count)]), assembly: trimmed,
|
||||
moduleID: bankedLayout?.module(forSection: sectionName)?.id,
|
||||
@@ -715,7 +734,7 @@ struct CMOCProjectSourceMap: Sendable {
|
||||
throw CMOCSourceMap.Failure.invalid("source identities must be canonical project-relative paths.")
|
||||
}
|
||||
}
|
||||
var instructions: [Instruction] = [], addresses = Set<UInt32>(), occupied = Set<UInt32>()
|
||||
var instructions: [Instruction] = [], addresses = Set<CMOCSourceMap.EvidenceAddress>(), occupied = Set<CMOCSourceMap.EvidenceAddress>()
|
||||
var entry: UInt16?, objectHashes: [String: String] = [:], listingHashes: [String: String] = [:]
|
||||
var executableSymbols: [ExecutableSymbol] = [], flatCodeGuards: [CodeGuard] = []
|
||||
let marker = try NSRegularExpression(pattern: #"\* (?:Line (.+):([0-9]+)(?::.*)?|FUNCTION .+: defined at (.+):([0-9]+))$"#)
|
||||
@@ -763,13 +782,15 @@ struct CMOCProjectSourceMap: Sendable {
|
||||
if let entry, entry != map.entryPoint { throw CMOCSourceMap.Failure.invalid("inconsistent entry points.") }
|
||||
entry = map.entryPoint
|
||||
for item in map.instructions {
|
||||
guard addresses.insert(item.physicalAddress ?? UInt32(item.address)).inserted else {
|
||||
let startIdentity = CMOCSourceMap.EvidenceAddress(module: item.moduleID, physical: item.physicalAddress ?? UInt32(item.address))
|
||||
guard addresses.insert(startIdentity).inserted else {
|
||||
throw CMOCSourceMap.Failure.invalid("two source locations claim the same instruction address.")
|
||||
}
|
||||
for index in item.bytes.indices {
|
||||
let address = Int(item.address) + index
|
||||
let identity = item.moduleID.flatMap { bankedLayout?.module(id: $0)?.physicalAddress(address) } ?? UInt32(address)
|
||||
guard address < 65536, occupied.insert(identity).inserted else {
|
||||
let qualified = CMOCSourceMap.EvidenceAddress(module: item.moduleID, physical: identity)
|
||||
guard address < 65536, occupied.insert(qualified).inserted else {
|
||||
throw CMOCSourceMap.Failure.invalid("overlapping source instruction ranges.")
|
||||
}
|
||||
}
|
||||
@@ -824,7 +845,7 @@ extension CMOCProjectSourceMap {
|
||||
func projected(physicalPages: [Int: Int]) -> Self {
|
||||
guard let bankedLayout else { return self }
|
||||
let active = Set(bankedLayout.modules.filter { module in
|
||||
module.pages.allSatisfy { physicalPages[$0.logicalPage] == $0.physicalPage }
|
||||
module.overlay == nil && module.pages.allSatisfy { physicalPages[$0.logicalPage] == $0.physicalPage }
|
||||
}.map(\.id))
|
||||
return projected(activeModuleIDs: active)
|
||||
}
|
||||
@@ -835,13 +856,30 @@ extension CMOCProjectSourceMap {
|
||||
func projected(physicalPages: [Int: Int], memory: Data, available: Data) -> Self {
|
||||
guard let bankedLayout else { return self }
|
||||
guard memory.count == 65536, available.count == 65536 else { return projected(activeModuleIDs: []) }
|
||||
func mapped(_ module: CMOCBankedDebugLayout.Module) -> Bool {
|
||||
module.pages.allSatisfy { physicalPages[$0.logicalPage] == $0.physicalPage }
|
||||
}
|
||||
func codeMatches(_ module: CMOCBankedDebugLayout.Module) -> Bool {
|
||||
mapped(module) && module.codeGuards.allSatisfy { guardRange in
|
||||
let start = Int(guardRange.address), end = start + guardRange.bytes.count
|
||||
return end <= memory.count && available[start..<end].allSatisfy { $0 != 0 } &&
|
||||
Array(memory[start..<end]) == guardRange.bytes
|
||||
}
|
||||
}
|
||||
var selectedOwners = Set<CMOCBankedDebugLayout.OverlayIdentity>()
|
||||
for group in bankedLayout.overlayGroups {
|
||||
let matches = group.owners.filter { owner in
|
||||
let identity = CMOCBankedDebugLayout.OverlayIdentity(group: group.id, owner: owner)
|
||||
let code = bankedLayout.modules.filter { $0.overlay == identity && !$0.codeGuards.isEmpty }
|
||||
return !code.isEmpty && code.allSatisfy(codeMatches)
|
||||
}
|
||||
if matches.count == 1 {
|
||||
selectedOwners.insert(.init(group: group.id, owner: matches[0]))
|
||||
}
|
||||
}
|
||||
let active = Set(bankedLayout.modules.filter { module in
|
||||
module.pages.allSatisfy { physicalPages[$0.logicalPage] == $0.physicalPage } &&
|
||||
module.codeGuards.allSatisfy { guardRange in
|
||||
let start = Int(guardRange.address), end = start + guardRange.bytes.count
|
||||
return end <= memory.count && available[start..<end].allSatisfy { $0 != 0 } &&
|
||||
Array(memory[start..<end]) == guardRange.bytes
|
||||
}
|
||||
if let overlay = module.overlay { return selectedOwners.contains(overlay) && mapped(module) }
|
||||
return codeMatches(module)
|
||||
}.map(\.id))
|
||||
return projected(activeModuleIDs: active)
|
||||
}
|
||||
@@ -958,6 +996,7 @@ struct CMOCPublicDebugEvidence {
|
||||
var fields: [String: Any] = ["status": metadata == nil ? "source_only" : "verified",
|
||||
"source_map": "verified", "variables": metadata == nil ? "unavailable" : "verified",
|
||||
"banked": map.bankedLayout != nil, "binary_sha256": map.binarySHA256,
|
||||
"supported_manifest_versions": [1, 2], "module_catalog_scope": "verified_static_declarations_not_residency",
|
||||
"entry_point": Int(map.entryPoint), "link_map_sha256": map.linkMapSHA256,
|
||||
"c_frame_locals": "unavailable", "c_frame_locals_reason": "Owned entry/instruction stops do not establish a C frame; optimized-out or unknown layouts are not guessed.",
|
||||
"owned_stop_evidence": map.bankedLayout != nil ? "declared_banked_modules" : map.flatCodeGuards.isEmpty ? "unavailable" : "verified_flat_code"]
|
||||
@@ -994,8 +1033,11 @@ struct CMOCPublicDebugEvidence {
|
||||
catalog("globals", globalDeclarations(metadata: metadata, sharedPaths: sharedPaths))
|
||||
catalog("modules", map.bankedLayout?.modules.map(\.id) ?? [])
|
||||
catalog("module_details", map.bankedLayout?.modules.map { module in
|
||||
["id": module.id, "pages": module.pages.map { ["logical_page": $0.logicalPage, "physical_page": $0.physicalPage] }] as [String: Any]
|
||||
var row: [String: Any] = ["id": module.id, "pages": module.pages.map { ["logical_page": $0.logicalPage, "physical_page": $0.physicalPage] }]
|
||||
if let overlay = module.overlay { row["overlay"] = ["group": overlay.group, "owner": overlay.owner] }
|
||||
return row
|
||||
} ?? [])
|
||||
catalog("overlay_groups", map.bankedLayout?.overlayGroups.map { ["id": $0.id, "owners": $0.owners] as [String: Any] } ?? [])
|
||||
catalog("framebuffers", map.bankedLayout?.framebuffers.map(\.workerFields) ?? [])
|
||||
fields["function_metadata_count"] = functions.count
|
||||
return fields
|
||||
|
||||
Reference in new issue
Block a user