Skip to content

Commit 027cc09

Browse files
committed
[RemoteMirror] Only look through Task wait adapters when there's a dependency record.
When the RunJob pointer is set to adapters, we try to get the "real" run pointer from the context. However, there are cases where the context can be a dangling pointer, when the task has finished with it but hasn't reset the pointer to anything else. For cases where that can happen, the context is legitimate only when there's a dependency record. Check for a dependency record before trying to read the context in those cases. In most uses this will fail gracefully or return a garbage run pointer, but swift-reflection-test uses an in-process memory reader which can crash when trying to chase this pointer, resulting in test failures. rdar://149252404
1 parent fcebcd3 commit 027cc09

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

include/swift/RemoteInspection/ReflectionContext.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -1929,12 +1929,17 @@ class ReflectionContext
19291929
Fptr == target_task_wait_throwing_resume_adapter) ||
19301930
(target_task_future_wait_resume_adapter &&
19311931
Fptr == target_task_future_wait_resume_adapter)) {
1932-
auto ContextBytes = getReader().readBytes(RemoteAddress(ResumeContextPtr),
1933-
sizeof(AsyncContext<Runtime>));
1934-
if (ContextBytes) {
1935-
auto ContextPtr =
1936-
reinterpret_cast<const AsyncContext<Runtime> *>(ContextBytes.get());
1937-
return stripSignedPointer(ContextPtr->ResumeParent);
1932+
// It's only safe to look through these adapters when there's a dependency
1933+
// record. If there isn't a dependency record, then the task was resumed
1934+
// and the pointers are potentially stale.
1935+
if (AsyncTaskObj->PrivateStorage.DependencyRecord) {
1936+
auto ContextBytes = getReader().readBytes(
1937+
RemoteAddress(ResumeContextPtr), sizeof(AsyncContext<Runtime>));
1938+
if (ContextBytes) {
1939+
auto ContextPtr = reinterpret_cast<const AsyncContext<Runtime> *>(
1940+
ContextBytes.get());
1941+
return stripSignedPointer(ContextPtr->ResumeParent);
1942+
}
19381943
}
19391944
}
19401945

include/swift/RemoteInspection/RuntimeInternals.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ template <typename Runtime>
8282
struct StackAllocator {
8383
typename Runtime::StoredPointer LastAllocation;
8484
typename Runtime::StoredPointer FirstSlab;
85-
int32_t NumAllocatedSlabs;
86-
bool FirstSlabIsPreallocated;
85+
int32_t NumAllocatedSlabsAndFirstSlabIsPreallocated;
8786

8887
struct Slab {
8988
typename Runtime::StoredPointer Metadata;
@@ -123,7 +122,8 @@ struct AsyncTaskPrivateStorage {
123122
StackAllocator<Runtime> Allocator;
124123
typename Runtime::StoredPointer Local;
125124
uint32_t Id;
126-
uint32_t BasePriority;
125+
typename Runtime::StoredSize BasePriority;
126+
typename Runtime::StoredPointer DependencyRecord;
127127
};
128128

129129
template <typename Runtime, typename ActiveTaskStatus>

0 commit comments

Comments
 (0)