[Swift] Optionally decode IPC arguments into Swift types
Component: WebKit IPC (Swift) | 9cce7a6
Configurations/CommonBase.xcconfig
LayoutTests/ipc/swift-receiver-swift-types-malformed.html
WebKit IPC messages are declared in .messages.in files and the types they carry in .serialization.in files; Python generators turn these into C++ encoders and decoders, so the declarations act as a central, auditable map of the attack surface. Swift receivers (currently the back/forward list and IPC testing) used to get arguments already decoded into C++ types.
For a Swift-typed message, C++ now lends generated Swift an IPC::SwiftDecoder whose primitive decoders are the existing C++ ones, behind a NonEscapableBorrow that must not outlive the call. Generated Swift composes them into Swift structs, enums, OptionSets, Variants and identifiers, and returns false on malformed input so C++ marks the message invalid. Replies go through IPC::SwiftReplyEncoder. generate-serializers.py now emits GeneratedSerializers.swift for every [Swift] type; the wire format is unchanged. SendableClosureCaptures becomes a hard error.
Significance
Swift handlers no longer pay interop costs for arguments and replies they never hand back to C++. This creates a second, generated IPC decode path in privileged processes, whose validation is reimplemented in Swift rather than shared with the C++ coders.
Audit directions
Two decoders for one wire format means every divergence is a potential validation gap:
- Compare Swift and C++ semantics per type: enum and OptionSet validation (including
boolenums and widths), Variant index range checks, identifier rejection (zero and the hash-table-deleted value), Optional/Markable handling, Vector and String lengths (beginArray,remainingByteCount, overflow, huge counts), and every String encoding. - Recursive types such as
IPCTesterNodechildren need depth and allocation limits. - C++ features the generators claim to reject (validators,
CreateUsing, conditional members) andstatic_assertgaps in enum value and width assumptions would be silent divergences if misgenerated. - The lent decoder must not escape through async or Sendable closures, and decoder validity and alignment state must stay consistent after a partial Swift-side failure.
- On the reply path, check throwing
InvalidMessagein sync and async handlers, default-reply encoding, double-completion of completion handlers, and that a failed decode of a sync message still unblocks the sender.