Skip to content

[swift-inspect] Support DLQ_GetPtrAuthMask. #32817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/swift/Reflection/ReflectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <utility>
#include <vector>

#include <inttypes.h>

namespace {

template <unsigned PointerSize> struct MachOTraits;
Expand Down Expand Up @@ -958,7 +960,8 @@ class ReflectionContext
// FIXME: std::stringstream would be better, but LLVM's standard library
// introduces a vtable and we don't want that.
char result[128];
std::snprintf(result, sizeof(result), "unable to read Next pointer %p",
std::snprintf(result, sizeof(result),
"unable to read Next pointer %#" PRIx64,
BacktraceListNext.getAddressData());
return std::string(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include <stdint.h>
#include <ptrauth.h>

struct CSTypeRef {
uintptr_t a, b;
Expand All @@ -19,3 +20,11 @@ struct CSTypeRef {
struct Range {
uintptr_t location, length;
};

uintptr_t GetPtrauthMask(void) {
#if __has_feature(ptrauth_calls)
return (uintptr_t)ptrauth_strip((void*)0x0007ffffffffffff, 0);
#else
return (uintptr_t)~0ull;
#endif
}
4 changes: 4 additions & 0 deletions tools/swift-inspect/Sources/swift-inspect/Inspector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ private func QueryDataLayoutFn(context: UnsafeMutableRawPointer?,
let size = UInt8(MemoryLayout<UnsafeRawPointer>.stride)
outBuffer!.storeBytes(of: size, toByteOffset: 0, as: UInt8.self)
return 1
case DLQ_GetPtrAuthMask:
let mask = GetPtrauthMask()
outBuffer!.storeBytes(of: mask, toByteOffset: 0, as: UInt.self)
return 1
default:
return 0
}
Expand Down