Skip to content

Commit 315b6e2

Browse files
authored
Merge pull request #251 from p-x9/feature/use-mmap-fileio-protocol
Fix protocol constraints and perform mmap-based file I/O
2 parents 17fc581 + 6294702 commit 315b6e2

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

Sources/MachOKit/Extension/_FileIOProtocol+.swift

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ extension _FileIOProtocol {
238238
}
239239
}
240240

241+
#if false
241242
extension _FileIOProtocol {
242243
@_disfavoredOverload
243244
@inline(__always)
@@ -274,8 +275,38 @@ extension _FileIOProtocol {
274275
return String(cString: data)
275276
}
276277
}
278+
#endif
279+
280+
extension MemoryMappedFileIOProtocol {
281+
@inline(__always)
282+
func readString(
283+
offset: UInt64
284+
) -> String? {
285+
String(
286+
cString: ptr
287+
.advanced(by: numericCast(offset))
288+
.assumingMemoryBound(to: CChar.self)
289+
)
290+
}
291+
292+
@inline(__always)
293+
func readString(
294+
offset: UInt64,
295+
size: Int // ignored
296+
) -> String? {
297+
readString(offset: offset)
298+
}
299+
300+
@inline(__always)
301+
func readString(
302+
offset: UInt64,
303+
step: Int = 10 // ignored
304+
) -> String? {
305+
readString(offset: offset)
306+
}
307+
}
277308

278-
extension MemoryMappedFile {
309+
extension MemoryMappedFile.FileSlice {
279310
@inline(__always)
280311
func readString(
281312
offset: UInt64

Sources/MachOKit/Model/DyldCache/DyldCacheMappingAndSlideInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extension DyldCacheMappingAndSlideInfo {
8787
}
8888

8989
extension DyldCacheMappingAndSlideInfo {
90-
private func _slideInfo<File: FileIOProtocol>(
90+
private func _slideInfo<File: MemoryMappedFileIOProtocol>(
9191
version: DyldCacheSlideInfo.Version,
9292
fileHandle: File
9393
) -> DyldCacheSlideInfo? {

Sources/MachOKit/Protocol/_DyldCacheFileRepresentable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal protocol _DyldCacheFileRepresentable: DyldCacheRepresentable
1717
where DylibsTrie == DataTrieTree<DylibsTrieNodeContent>,
1818
ProgramsTrie == DataTrieTree<ProgramsTrieNodeContent>
1919
{
20-
associatedtype File: FileIOProtocol
20+
associatedtype File: MemoryMappedFileIOProtocol
2121
var fileHandle: File { get }
2222

2323
func machOFiles() -> AnySequence<MachOFile>

0 commit comments

Comments
 (0)