Skip to content

Commit f60394d

Browse files
authored
[SUA][Runtime] Define swift_coroFrameAlloc function that allocates typed memory (#79200)
[SUA][Runtime] Define `swift_coroFrameAlloc` function that allocates typed memory Define `swift_coroFrameAlloc` that allocates typed memory if SWIFT_STDLIB_HAS_MALLOC_TYPE is defined. This function will be used by IRGen to emit typed memory allocations for property accessors. rdar://141235539
1 parent a86743e commit f60394d

File tree

7 files changed

+27
-0
lines changed

7 files changed

+27
-0
lines changed

include/swift/Runtime/Heap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ using MallocTypeId = unsigned long long;
3838
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD
3939
void *swift_slowAllocTyped(size_t bytes, size_t alignMask, MallocTypeId typeId);
4040

41+
// If SWIFT_STDLIB_HAS_MALLOC_TYPE is defined, allocate typed memory.
42+
// Otherwise, allocate plain memory.
43+
SWIFT_RUNTIME_EXPORT
44+
void *swift_coroFrameAlloc(size_t bytes, MallocTypeId typeId);
45+
4146
// If the caller cannot promise to zero the object during destruction,
4247
// then call these corresponding APIs:
4348
SWIFT_RUNTIME_EXPORT

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,12 @@ FUNCTION(Free, c, free, C_CC, AlwaysAvailable,
20992099
NO_ATTRS,
21002100
EFFECT(Deallocating),
21012101
UNKNOWN_MEMEFFECTS)
2102+
FUNCTION(CoroFrameAlloc, c, swift_coroFrameAlloc, C_CC, AlwaysAvailable,
2103+
RETURNS(Int8PtrTy),
2104+
ARGS(SizeTy, Int64Ty),
2105+
NO_ATTRS,
2106+
EFFECT(Allocating),
2107+
UNKNOWN_MEMEFFECTS)
21022108

21032109
// void *_Block_copy(void *block);
21042110
FUNCTION(BlockCopy, BlocksRuntime, _Block_copy, C_CC, AlwaysAvailable,

stdlib/public/runtime/Heap.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ void *swift::swift_slowAllocTyped(size_t size, size_t alignMask,
120120
return swift_slowAlloc(size, alignMask);
121121
}
122122

123+
void *swift::swift_coroFrameAlloc(size_t size,
124+
MallocTypeId typeId) {
125+
#if SWIFT_STDLIB_HAS_MALLOC_TYPE
126+
if (__builtin_available(macOS 15, iOS 17, tvOS 17, watchOS 10, *)) {
127+
void *p = malloc_type_malloc(size, typeId);
128+
if (!p) swift::crash("Could not allocate memory.");
129+
return p;
130+
}
131+
#endif
132+
return malloc(size);
133+
}
134+
123135
// Unknown alignment is specified by passing alignMask == ~(size_t(0)), forcing
124136
// the AlignedFree deallocation path for unknown alignment. The memory
125137
// deallocated with unknown alignment must have been allocated with either

test/abi/Inputs/macOS/arm64/stdlib/baseline

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13553,6 +13553,7 @@ _swift_conformsToProtocolCommon
1355313553
_swift_copyAuxiliaryExecutablePath
1355413554
_swift_copyKeyPathTrivialIndices
1355513555
_swift_copyPOD
13556+
_swift_coroFrameAlloc
1355613557
_swift_deallocBox
1355713558
_swift_deallocClassInstance
1355813559
_swift_deallocError

test/abi/Inputs/macOS/arm64/stdlib/baseline-asserts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13648,6 +13648,7 @@ _swift_conformsToProtocolCommon
1364813648
_swift_copyAuxiliaryExecutablePath
1364913649
_swift_copyKeyPathTrivialIndices
1365013650
_swift_copyPOD
13651+
_swift_coroFrameAlloc
1365113652
_swift_deallocBox
1365213653
_swift_deallocClassInstance
1365313654
_swift_deallocError

test/abi/Inputs/macOS/x86_64/stdlib/baseline

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13461,6 +13461,7 @@ _swift_conformsToProtocolCommon
1346113461
_swift_copyAuxiliaryExecutablePath
1346213462
_swift_copyKeyPathTrivialIndices
1346313463
_swift_copyPOD
13464+
_swift_coroFrameAlloc
1346413465
_swift_deallocBox
1346513466
_swift_deallocClassInstance
1346613467
_swift_deallocError

test/abi/Inputs/macOS/x86_64/stdlib/baseline-asserts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13556,6 +13556,7 @@ _swift_conformsToProtocolCommon
1355613556
_swift_copyAuxiliaryExecutablePath
1355713557
_swift_copyKeyPathTrivialIndices
1355813558
_swift_copyPOD
13559+
_swift_coroFrameAlloc
1355913560
_swift_deallocBox
1356013561
_swift_deallocClassInstance
1356113562
_swift_deallocError

0 commit comments

Comments
 (0)