Skip to content

Commit c4ce0d9

Browse files
authored
Merge pull request #42327 from xedin/ptrauth-for-dist-5.7
[5.7][Runtime] Add pointer auth to accessible function section/cache
2 parents eaa3f3d + 452d784 commit c4ce0d9

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,9 @@ namespace SpecialPointerAuthDiscriminators {
14241424

14251425
/// Dispatch integration.
14261426
const uint16_t DispatchInvokeFunction = 0xf493; // = 62611
1427+
1428+
/// Functions accessible at runtime (i.e. distributed method accessors).
1429+
const uint16_t AccessibleFunctionRecord = 0x438c; // = 17292
14271430
}
14281431

14291432
/// The number of arguments that will be passed directly to a generic

include/swift/Runtime/Config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ extern uintptr_t __COMPATIBILITY_LIBRARIES_CANNOT_CHECK_THE_IS_SWIFT_BIT_DIRECTL
302302
#define __ptrauth_swift_dispatch_invoke_function \
303303
__ptrauth(ptrauth_key_process_independent_code, 1, \
304304
SpecialPointerAuthDiscriminators::DispatchInvokeFunction)
305+
#define __ptrauth_swift_accessible_function_record \
306+
__ptrauth(ptrauth_key_process_independent_data, 1, \
307+
SpecialPointerAuthDiscriminators::AccessibleFunctionRecord)
305308
#define __ptrauth_swift_objc_superclass \
306309
__ptrauth(ptrauth_key_process_independent_data, 1, \
307310
swift::SpecialPointerAuthDiscriminators::ObjCSuperclass)
@@ -334,6 +337,7 @@ extern uintptr_t __COMPATIBILITY_LIBRARIES_CANNOT_CHECK_THE_IS_SWIFT_BIT_DIRECTL
334337
#define __ptrauth_swift_cancellation_notification_function
335338
#define __ptrauth_swift_escalation_notification_function
336339
#define __ptrauth_swift_dispatch_invoke_function
340+
#define __ptrauth_swift_accessible_function_record
337341
#define __ptrauth_swift_objc_superclass
338342
#define __ptrauth_swift_runtime_function_entry
339343
#define __ptrauth_swift_runtime_function_entry_with_key(__key)

stdlib/public/runtime/AccessibleFunction.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ using namespace swift;
3030
namespace {
3131

3232
struct AccessibleFunctionsSection {
33-
const AccessibleFunctionRecord *Begin, *End;
33+
const AccessibleFunctionRecord *__ptrauth_swift_accessible_function_record
34+
Begin;
35+
const AccessibleFunctionRecord *__ptrauth_swift_accessible_function_record
36+
End;
3437

3538
AccessibleFunctionsSection(const AccessibleFunctionRecord *begin,
3639
const AccessibleFunctionRecord *end)
@@ -51,20 +54,20 @@ struct AccessibleFunctionCacheEntry {
5154
const char *Name;
5255
size_t NameLength;
5356

54-
const AccessibleFunctionRecord *Func;
57+
const AccessibleFunctionRecord *__ptrauth_swift_accessible_function_record R;
5558

5659
public:
5760
AccessibleFunctionCacheEntry(llvm::StringRef name,
58-
const AccessibleFunctionRecord *func)
59-
: Func(func) {
61+
const AccessibleFunctionRecord *record)
62+
: R(record) {
6063
char *Name = reinterpret_cast<char *>(malloc(name.size()));
6164
memcpy(Name, name.data(), name.size());
6265

6366
this->Name = Name;
6467
this->NameLength = name.size();
6568
}
6669

67-
const AccessibleFunctionRecord *getFunction() const { return Func; }
70+
const AccessibleFunctionRecord *getRecord() const { return R; }
6871

6972
bool matchesKey(llvm::StringRef name) {
7073
return name == llvm::StringRef{Name, NameLength};
@@ -139,21 +142,21 @@ swift::runtime::swift_findAccessibleFunction(const char *targetNameStart,
139142
{
140143
auto snapshot = S.Cache.snapshot();
141144
if (auto E = snapshot.find(name))
142-
return E->getFunction();
145+
return E->getRecord();
143146
}
144147

145148
// If entry doesn't exist (either record doesn't exist, hasn't been loaded, or
146149
// requested yet), let's try to find it and add to the cache.
147150

148-
auto *function = _searchForFunctionRecord(S, name);
149-
if (function) {
151+
auto *record = _searchForFunctionRecord(S, name);
152+
if (record) {
150153
S.Cache.getOrInsert(
151154
name, [&](AccessibleFunctionCacheEntry *entry, bool created) {
152155
if (created)
153-
new (entry) AccessibleFunctionCacheEntry{name, function};
156+
new (entry) AccessibleFunctionCacheEntry{name, record};
154157
return true;
155158
});
156159
}
157160

158-
return function;
161+
return record;
159162
}

0 commit comments

Comments
 (0)