Skip to content

Commit 4559ad7

Browse files
authored
Merge pull request #32817 from mikeash/swift-inspect-ptrauth-mask
[swift-inspect] Support DLQ_GetPtrAuthMask.
2 parents 40d7da4 + 5eb2265 commit 4559ad7

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

include/swift/Reflection/ReflectionContext.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include <utility>
3939
#include <vector>
4040

41+
#include <inttypes.h>
42+
4143
namespace {
4244

4345
template <unsigned PointerSize> struct MachOTraits;
@@ -958,7 +960,8 @@ class ReflectionContext
958960
// FIXME: std::stringstream would be better, but LLVM's standard library
959961
// introduces a vtable and we don't want that.
960962
char result[128];
961-
std::snprintf(result, sizeof(result), "unable to read Next pointer %p",
963+
std::snprintf(result, sizeof(result),
964+
"unable to read Next pointer %#" PRIx64,
962965
BacktraceListNext.getAddressData());
963966
return std::string(result);
964967
}

tools/swift-inspect/Sources/SymbolicationShims/SymbolicationShims.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include <stdint.h>
14+
#include <ptrauth.h>
1415

1516
struct CSTypeRef {
1617
uintptr_t a, b;
@@ -19,3 +20,11 @@ struct CSTypeRef {
1920
struct Range {
2021
uintptr_t location, length;
2122
};
23+
24+
uintptr_t GetPtrauthMask(void) {
25+
#if __has_feature(ptrauth_calls)
26+
return (uintptr_t)ptrauth_strip((void*)0x0007ffffffffffff, 0);
27+
#else
28+
return (uintptr_t)~0ull;
29+
#endif
30+
}

tools/swift-inspect/Sources/swift-inspect/Inspector.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ private func QueryDataLayoutFn(context: UnsafeMutableRawPointer?,
126126
let size = UInt8(MemoryLayout<UnsafeRawPointer>.stride)
127127
outBuffer!.storeBytes(of: size, toByteOffset: 0, as: UInt8.self)
128128
return 1
129+
case DLQ_GetPtrAuthMask:
130+
let mask = GetPtrauthMask()
131+
outBuffer!.storeBytes(of: mask, toByteOffset: 0, as: UInt.self)
132+
return 1
129133
default:
130134
return 0
131135
}

0 commit comments

Comments
 (0)