Skip to content

Commit 827b4fd

Browse files
authored
Merge pull request #66408 from al45tair/eng/PR-110261712-5.9
[Backtracing][Linux] Add support for Linux in the _Backtracing module.
2 parents cf7b7c7 + b25a04c commit 827b4fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+8090
-714
lines changed

include/swift/Runtime/Backtrace.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ struct BacktraceSettings {
134134

135135
SWIFT_RUNTIME_STDLIB_INTERNAL BacktraceSettings _swift_backtraceSettings;
136136

137-
SWIFT_RUNTIME_STDLIB_SPI SWIFT_CC(swift) bool _swift_isThunkFunction(const char *mangledName);
137+
SWIFT_RUNTIME_STDLIB_SPI
138+
bool _swift_backtrace_isThunkFunction(const char *mangledName);
138139

139140
/// Try to demangle a symbol.
140141
///
@@ -145,7 +146,6 @@ SWIFT_RUNTIME_STDLIB_SPI SWIFT_CC(swift) bool _swift_isThunkFunction(const char
145146
/// @param outputBuffer is a pointer to a buffer in which to place the result.
146147
/// @param outputBufferSize points to a variable that contains the size of the
147148
/// output buffer.
148-
/// @param status returns the status codes defined in the C++ ABI.
149149
///
150150
/// If outputBuffer is nullptr, the function will allocate memory for the
151151
/// result using malloc(). In this case, outputBufferSize may be nullptr;
@@ -167,8 +167,7 @@ SWIFT_RUNTIME_STDLIB_SPI
167167
char *_swift_backtrace_demangle(const char *mangledName,
168168
size_t mangledNameLength,
169169
char *outputBuffer,
170-
size_t *outputBufferSize,
171-
int *status);
170+
size_t *outputBufferSize);
172171
#ifdef __cplusplus
173172
} // namespace backtrace
174173
} // namespace runtime
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//===--- ArrayImageSource.swift - An image source backed by an Array -------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// Defines ArrayImageSource, an image source that is backed by a Swift Array.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
import Swift
18+
19+
@_implementationOnly import OS.Libc
20+
21+
enum ArrayImageSourceError: Error {
22+
case outOfBoundsRead(UInt64, UInt64)
23+
}
24+
25+
struct ArrayImageSource<T>: ImageSource {
26+
private var array: Array<T>
27+
28+
public init(array: Array<T>) {
29+
self.array = array
30+
}
31+
32+
public var isMappedImage: Bool { return false }
33+
public var path: String? { return nil }
34+
public var bounds: Bounds? {
35+
return Bounds(base: 0, size: Size(array.count * MemoryLayout<T>.stride))
36+
}
37+
38+
public func fetch<U>(from addr: Address,
39+
into buffer: UnsafeMutableBufferPointer<U>) throws {
40+
try array.withUnsafeBytes{
41+
let size = Size($0.count)
42+
let requested = Size(buffer.count * MemoryLayout<U>.stride)
43+
if addr > size || requested > size - addr {
44+
throw ArrayImageSourceError.outOfBoundsRead(addr, requested)
45+
}
46+
47+
memcpy(buffer.baseAddress!, $0.baseAddress! + Int(addr), Int(requested))
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)