[Wasm][Runtime] Interpret absolute function pointer in runtime structures

When SWIFT_COMPACT_ABSOLUTE_FUNCTION_POINTER is enabled, relative direct
pointers whose pointees are functions will be turned into absolute
pointer at compile-time.
This commit is contained in:
Yuta Saito
2022-03-30 07:48:46 +00:00
parent 26ba09738e
commit 8c598e98f7
13 changed files with 251 additions and 44 deletions

View File

@@ -76,7 +76,16 @@ static uintptr_t resolveSymbolicReferenceOffset(SymbolicReferenceKind kind,
Directness isIndirect,
int32_t offset,
const void *base) {
auto ptr = detail::applyRelativeOffset(base, offset);
uintptr_t ptr;
// Function references may be resolved differently than other data references.
switch (kind) {
case SymbolicReferenceKind::AccessorFunctionReference:
ptr = (uintptr_t)TargetCompactFunctionPointer<InProcess, void>::resolve(base, offset);
break;
default:
ptr = detail::applyRelativeOffset(base, offset);
break;
}
// Indirect references may be authenticated in a way appropriate for the
// referent.
@@ -2600,10 +2609,10 @@ void DynamicReplacementDescriptor::enableReplacement() const {
// Link the replacement entry.
chainRoot->next = chainEntry.get();
// chainRoot->implementationFunction = replacementFunction.get();
// chainRoot->implementationFunction = getReplacementFunction();
swift_ptrauth_init_code_or_data(
reinterpret_cast<void **>(&chainRoot->implementationFunction),
reinterpret_cast<void *>(replacementFunction.get()),
reinterpret_cast<void *>(getReplacementFunction()),
replacedFunctionKey->getExtraDiscriminator(),
!replacedFunctionKey->isAsync());
}