Skip to content

Commit 0fac5cb

Browse files
authored
Merge pull request #81074 from mikeash/fix-reflect-task-crash
[RemoteMirror] Only look through Task wait adapters when there's a dependency record.
2 parents 925b72e + 027cc09 commit 0fac5cb

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)