Commit Graph

17 Commits

Author SHA1 Message Date
Nate Chandler
dd8cbe3e0a [CoroutineAccessors] Use retcon.once variant.
Allocate a coroutine frame in the caller based on the size in the
corresponding "function pointer" and pass it along with an allocator to
the callee.
2025-02-27 07:53:58 -08:00
Konrad `ktoso` Malawski
0c44645832 [Concurrency] Implement defensive copying in task groups, rather than crashing (#73978) 2024-05-31 11:27:03 -07:00
Saleem Abdulrasool
a8b0ee24dc runtime: blanket application of namespacing and inclusion of new
Apply a blanket pass of including `new` for the placement new allocation
and namespacing the call to the global placement new allocator.  This
should repair the Android ARMv7 builds.
2022-04-14 14:21:12 -07:00
Mike Ash
adec767b2d [Concurrency] Have StackAllocator gracefully fail when passed a small firstSlabBuffer.
Creating a task for an async let will attempt to allocate the task in the async let's preallocated space, and if there's any space left over then it will use the extra for the new tasks's allocator. However, StackAllocator requires the preallocated buffer to be large enough to hold a slab header, but the task creation code doesn't check for that. As a result, the task creation code can end up passing a buffer that's too small to hold the slab header. When asserts are enabled, this is caught by an assert. When asserts are not enabled, disaster strikes. We end up computing a negative number for the remaining slab capacity, which underflows to a large positive number, causing the slab to overflow the async let's preallocated space. This results in weird memory corruption.

SR-15996
rdar://90357994
2022-03-18 13:05:29 -04:00
Allan Shortlidge
a8ff646b6e NFC: Fix unintialized variable warnings and C++20 extension warnings in concurrency related code. 2022-03-07 11:59:08 -08:00
Mike Ash
6f923f35ad [Concurrency] Remove explicit_bzero call on Linux.
Clearing memory before freeing it is difficult to do portably. The Linux version didn't build on CentOS. Have Linux use `= 0` for now.
2022-02-10 21:07:39 -05:00
Rokhini Prabhu
a5fa349f88 Merge pull request #41281 from apple/rokhinip/88600541-task-priority-escalation-arm64_32
Task Escalation support on arm64_32 Apple platforms
2022-02-10 17:02:38 -08:00
Rokhini Prabhu
98a8bdbd38 Task Escalation support on arm64_32 Apple platforms
Radar-Id: rdar://problem/88600541
2022-02-10 11:50:31 -08:00
Mike Ash
1020a1a9c8 [Concurrency] Clear Slab's fake metadata pointer before freeing it.
This helps ensure that memory analysis tools don't get confused by leftover metadata pointers in reallocated memory that hasn't been initialized yet.

rdar://88494373
2022-02-09 11:41:32 -05:00
Mike Ash
17ac26903d [Concurrency] Adjust the task allocator slab size to 984 bytes.
A slab capacity of 1000 bytes was overflowing the 1024 byte malloc bucket when adding in the slab header. Adjust it down to 984 bytes. Calculate this by subtracting the slab header size from 1024, plus a little slop for malloc stack logging, to ensure we don't overflow the bucket again.

rdar://87612288
2022-01-19 16:50:15 -05:00
Mike Ash
cf3c131e7c [Reflection] Add API for inspecting async task allocation slabs.
We remove the existing `swift_reflection_iterateAsyncTaskAllocations` API that attempts to provide all necessary information about a tasks's allocations starting from the task. Instead, we split it into two pieces: `swift_reflection_asyncTaskSlabPointer` to get the first slab for a task, and `+swift_reflection_asyncTaskSlabAllocations` to get the allocations in a slab, and a pointer to the next slab.

We also add a dummy metadata pointer to the beginning of each slab. This allows tools to identify slab allocations on the heap without needing to locate every single async task object. They can then use `swift_reflection_asyncTaskSlabAllocations` on such allocations to find out about the contents.

rdar://82549631
2021-11-18 14:15:25 -05:00
Mike Ash
89d93a000d [Runtime] Replace std::max_align_t with MaximumAlignment from MetadataValues.h.
On Windows, std::max_align_t is only 8-byte aligned, but Swift assumes 16-byte alignment. MaximumAlignment is our notion of the maximum alignment of a type, so use that instead.
2021-11-18 13:56:05 -05:00
Saleem Abdulrasool
3c9c564eba Revert "[Reflection] Add API for inspecting async task allocation slabs." 2021-11-17 18:47:13 -08:00
Mike Ash
7c7dc5d5b3 [Reflection] Add API for inspecting async task allocation slabs.
We remove the existing `swift_reflection_iterateAsyncTaskAllocations` API that attempts to provide all necessary information about a tasks's allocations starting from the task. Instead, we split it into two pieces: `swift_reflection_asyncTaskSlabPointer` to get the first slab for a task, and `+swift_reflection_asyncTaskSlabAllocations` to get the allocations in a slab, and a pointer to the next slab.

We also add a dummy metadata pointer to the beginning of each slab. This allows tools to identify slab allocations on the heap without needing to locate every single async task object. They can then use `swift_reflection_asyncTaskSlabAllocations` on such allocations to find out about the contents.

rdar://82549631
2021-11-11 16:58:14 -05:00
Yuta Saito
709359cfab Rename duplicated swift::fatalError definition in swiftRuntime and swift_Concurrency
Both swiftRuntime and swift_Concurrency had swift::fatalError
implementation, but it causes symbol conflict when -static-stdlib.

This patch renames one of the impl in swift_Concurrency to avoid
conflict.
2021-04-28 23:52:18 +09:00
Erik Eckstein
ec1490d06e [concurrency] Implement the Task allocator as bump-pointer allocator.
Use the StackAllocator as task allocator.

TODO: we could pass an initial pre-allocated first slab to the allocator, which is allocated on the stack or with the parent task's allocator.

rdar://problem/71157018
2020-12-09 22:22:28 +01:00
Erik Eckstein
e7b5843b33 runtime: add a StackAllocator utility
A StackAllocator performs fast allocation and deallocation of memory by implementing a bump-pointer allocation strategy.
In contrast to a pure bump-pointer allocator, it's possible to free memory.
Allocations and deallocations must follow a strict stack discipline.

In general, slabs which become unused are _not_ freed, but reused for subsequent allocations.
The first slab can be placed into pre-allocated memory.
2020-12-09 22:22:28 +01:00