Skip to content

Commit d8e8a8b

Browse files
committed
The Monterey Merge
This PR brings the FOSS portions of Core Foundation on par with macOS Monterey, iOS 15, watchOS 8 and tvOS 15. This includes the changes shipped during the previous releases. Most of the changes include bug fixes and performance improvements, but some are useful to highlight: - This patch adds the Core Foundation code that underlies Foundation's ListFormatter and RelativeDateTimeFormatter to the FOSS subset. - Several Emoji fixes are included that update CFString (and thus NSString and the Foundation methods on Swift.String) support for correctly decoding and iterating over emoji introduced during the Big Sur and Monterey timeframes. The corresponding character maps in CharacterSet have been updated. - Certain parsing functions, most notably those that implement property list parsing, now have a maximum recursion depth to prevent resource abuse from malicious input. - Some architectural changes have been introduced that are used on Darwin to support Pointer Authentication. For more information on the topic, see [Preparing Your App to Work with Pointer Authentication](https://developer.apple.com/documentation/security/preparing_your_app_to_work_with_pointer_authentication). Note that the FOSS subset does not ship on architectures that require this support, but the architectural changes have been merged for simplicity and synchronization between Darwin and FOSS builds. - Parameter checking has been improved for several CF functions. - Some implementations have been streamlined or consolidated, especially for CFPlugIn and CFBundle. CFBundle also adds support for "Wrapper"-style bundles (for example, the kind of bundle produced when installing iOS applications on Macs with Apple silicon).
1 parent 08f2025 commit d8e8a8b

File tree

95 files changed

+4117
-1405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+4117
-1405
lines changed

CoreFoundation/AppServices.subproj/CFUserNotification.c

+9
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ static void _CFUserNotificationMachPortCallBack(CFMachPortRef port, void *m, CFI
299299
}
300300

301301
SInt32 CFUserNotificationReceiveResponse(CFUserNotificationRef userNotification, CFTimeInterval timeout, CFOptionFlags *responseFlags) {
302+
CF_ASSERT_TYPE_OR_NULL(_kCFRuntimeIDCFUserNotification, userNotification);
302303
CHECK_FOR_FORK();
303304
SInt32 retval = ERR_SUCCESS;
304305
mach_msg_timeout_t msgtime = (timeout > 0.0 && 1000.0 * timeout < INT_MAX) ? (mach_msg_timeout_t)(1000.0 * timeout) : 0;
@@ -343,11 +344,15 @@ SInt32 CFUserNotificationReceiveResponse(CFUserNotificationRef userNotification,
343344
}
344345

345346
CFStringRef CFUserNotificationGetResponseValue(CFUserNotificationRef userNotification, CFStringRef key, CFIndex idx) {
347+
CF_ASSERT_TYPE_OR_NULL(_kCFRuntimeIDCFUserNotification, userNotification);
346348
CHECK_FOR_FORK();
347349
CFStringRef retval = NULL;
348350
CFTypeRef value = NULL;
349351
if (userNotification && userNotification->_responseDictionary) {
350352
value = CFDictionaryGetValue(userNotification->_responseDictionary, key);
353+
if (value == NULL) {
354+
return NULL;
355+
}
351356
if (CFGetTypeID(value) == CFStringGetTypeID()) {
352357
if (0 == idx) retval = (CFStringRef)value;
353358
} else if (CFGetTypeID(value) == CFArrayGetTypeID()) {
@@ -358,11 +363,13 @@ CFStringRef CFUserNotificationGetResponseValue(CFUserNotificationRef userNotific
358363
}
359364

360365
CFDictionaryRef CFUserNotificationGetResponseDictionary(CFUserNotificationRef userNotification) {
366+
CF_ASSERT_TYPE_OR_NULL(_kCFRuntimeIDCFUserNotification, userNotification);
361367
CHECK_FOR_FORK();
362368
return userNotification ? userNotification->_responseDictionary : NULL;
363369
}
364370

365371
SInt32 CFUserNotificationUpdate(CFUserNotificationRef userNotification, CFTimeInterval timeout, CFOptionFlags flags, CFDictionaryRef dictionary) {
372+
CF_ASSERT_TYPE_OR_NULL(_kCFRuntimeIDCFUserNotification, userNotification);
366373
CHECK_FOR_FORK();
367374
SInt32 retval = ERR_SUCCESS;
368375
if (userNotification && MACH_PORT_NULL != userNotification->_replyPort) {
@@ -373,6 +380,7 @@ SInt32 CFUserNotificationUpdate(CFUserNotificationRef userNotification, CFTimeIn
373380
}
374381

375382
SInt32 CFUserNotificationCancel(CFUserNotificationRef userNotification) {
383+
CF_ASSERT_TYPE_OR_NULL(_kCFRuntimeIDCFUserNotification, userNotification);
376384
CHECK_FOR_FORK();
377385
SInt32 retval = ERR_SUCCESS;
378386
if (userNotification && MACH_PORT_NULL != userNotification->_replyPort) {
@@ -383,6 +391,7 @@ SInt32 CFUserNotificationCancel(CFUserNotificationRef userNotification) {
383391
}
384392

385393
CFRunLoopSourceRef CFUserNotificationCreateRunLoopSource(CFAllocatorRef allocator, CFUserNotificationRef userNotification, CFUserNotificationCallBack callout, CFIndex order) {
394+
CF_ASSERT_TYPE_OR_NULL(_kCFRuntimeIDCFUserNotification, userNotification);
386395
CHECK_FOR_FORK();
387396
CFRunLoopSourceRef source = NULL;
388397
if (userNotification && callout && !userNotification->_machPort && MACH_PORT_NULL != userNotification->_replyPort) {

CoreFoundation/Base.subproj/CFAvailability.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@
135135
#define __CF_ENUM_FIXED_IS_AVAILABLE (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && (__has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum)))
136136

137137
#if __CF_ENUM_FIXED_IS_AVAILABLE
138-
#define __CF_NAMED_ENUM(_type, _name) int __CF_ENUM_ ## _name; enum __CF_ENUM_ATTRIBUTES _name : _type; typedef enum _name _name; enum _name : _type
138+
#define __CF_NAMED_ENUM(_type, _name) enum __CF_ENUM_ATTRIBUTES _name : _type _name; enum _name : _type
139139
#define __CF_ANON_ENUM(_type) enum __CF_ENUM_ATTRIBUTES : _type
140-
#define CF_CLOSED_ENUM(_type, _name) int __CF_ENUM_ ## _name; enum __CF_CLOSED_ENUM_ATTRIBUTES _name : _type; typedef enum _name _name; enum _name : _type
140+
#define CF_CLOSED_ENUM(_type, _name) enum __CF_CLOSED_ENUM_ATTRIBUTES _name : _type _name; enum _name : _type
141141
#if (__cplusplus)
142142
#define CF_OPTIONS(_type, _name) _type _name; enum __CF_OPTIONS_ATTRIBUTES : _type
143143
#else
144-
#define CF_OPTIONS(_type, _name) int __CF_OPTIONS_ ## _name; enum __CF_OPTIONS_ATTRIBUTES _name : _type; typedef enum _name _name; enum _name : _type
144+
#define CF_OPTIONS(_type, _name) enum __CF_OPTIONS_ATTRIBUTES _name : _type _name; enum _name : _type
145145
#endif
146146
#else
147147
#define __CF_NAMED_ENUM(_type, _name) _type _name; enum

CoreFoundation/Base.subproj/CFBase.c

+20-19
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct __CFAllocator {
5959
};
6060

6161
CF_INLINE uintptr_t __CFISAForCFAllocator(void) {
62-
return __CFRuntimeObjCClassTable[_kCFRuntimeIDCFAllocator];
62+
return _GetCFRuntimeObjcClassAtIndex(_kCFRuntimeIDCFAllocator);
6363
}
6464

6565
CF_INLINE CFAllocatorRetainCallBack __CFAllocatorGetRetainFunction(const CFAllocatorContext *context) {
@@ -478,7 +478,7 @@ void CFAllocatorSetDefault(CFAllocatorRef allocator) {
478478
}
479479
#endif
480480
#if TARGET_OS_MAC
481-
if (allocator && allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
481+
if (allocator && _CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
482482
return; // require allocator to this function to be an allocator
483483
}
484484
#endif
@@ -505,7 +505,7 @@ static CFAllocatorRef __CFAllocatorCreate(CFAllocatorRef allocator, CFAllocatorC
505505
CFAllocatorAllocateCallBack allocateFunc;
506506
void *retainedInfo;
507507
#if TARGET_OS_MAC
508-
if (allocator && kCFAllocatorUseContext != allocator && allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
508+
if (allocator && kCFAllocatorUseContext != allocator && _CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
509509
return NULL; // require allocator to this function to be an allocator
510510
}
511511
#endif
@@ -588,15 +588,15 @@ void *CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags
588588
}
589589

590590
#if defined(DEBUG) && TARGET_OS_MAC
591-
if (allocator->_base._cfisa == __CFISAForCFAllocator()) {
591+
if (_CFTypeGetClass(allocator) == __CFISAForCFAllocator()) {
592592
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
593593
}
594594
#else
595595
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
596596
#endif
597597
if (0 == size) return NULL;
598598
#if TARGET_OS_MAC
599-
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
599+
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
600600
return malloc_zone_malloc((malloc_zone_t *)allocator, size);
601601
}
602602
#endif
@@ -619,15 +619,15 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
619619
}
620620

621621
#if defined(DEBUG) && TARGET_OS_MAC
622-
if (allocator->_base._cfisa == __CFISAForCFAllocator()) {
622+
if (_CFTypeGetClass(allocator) == __CFISAForCFAllocator()) {
623623
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
624624
}
625625
#else
626626
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
627627
#endif
628628
if (NULL == ptr && 0 < newsize) {
629629
#if TARGET_OS_MAC
630-
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
630+
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
631631
return malloc_zone_malloc((malloc_zone_t *)allocator, newsize);
632632
}
633633
#endif
@@ -640,7 +640,7 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
640640
}
641641
if (NULL != ptr && 0 == newsize) {
642642
#if TARGET_OS_MAC
643-
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
643+
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
644644
#if defined(DEBUG)
645645
size_t size = malloc_size(ptr);
646646
if (size) memset(ptr, 0xCC, size);
@@ -657,7 +657,7 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
657657
}
658658
if (NULL == ptr && 0 == newsize) return NULL;
659659
#if TARGET_OS_MAC
660-
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
660+
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
661661
return malloc_zone_realloc((malloc_zone_t *)allocator, ptr, newsize);
662662
}
663663
#endif
@@ -675,14 +675,14 @@ void CFAllocatorDeallocate(CFAllocatorRef allocator, void *ptr) {
675675
}
676676

677677
#if defined(DEBUG) && TARGET_OS_MAC
678-
if (allocator->_base._cfisa == __CFISAForCFAllocator()) {
678+
if (_CFTypeGetClass(allocator) == __CFISAForCFAllocator()) {
679679
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
680680
}
681681
#else
682682
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
683683
#endif
684684
#if TARGET_OS_MAC
685-
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
685+
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
686686
#if defined(DEBUG)
687687
size_t size = malloc_size(ptr);
688688
if (size) memset(ptr, 0xCC, size);
@@ -704,15 +704,15 @@ CFIndex CFAllocatorGetPreferredSizeForSize(CFAllocatorRef allocator, CFIndex siz
704704
allocator = __CFGetDefaultAllocator();
705705
}
706706

707-
#if defined(DEBUG) && TARGET_OS_MAC
708-
if (allocator->_base._cfisa == __CFISAForCFAllocator()) {
707+
#if TARGET_OS_MAC
708+
if (_CFTypeGetClass(allocator) == __CFISAForCFAllocator()) {
709709
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
710710
}
711711
#else
712712
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
713713
#endif
714714
#if TARGET_OS_MAC
715-
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
715+
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
716716
return malloc_good_size(size);
717717
}
718718
#endif
@@ -729,16 +729,16 @@ void CFAllocatorGetContext(CFAllocatorRef allocator, CFAllocatorContext *context
729729
allocator = __CFGetDefaultAllocator();
730730
}
731731

732-
#if defined(DEBUG) && TARGET_OS_MAC
733-
if (allocator->_base._cfisa == __CFISAForCFAllocator()) {
732+
#if TARGET_OS_MAC
733+
if (_CFTypeGetClass(allocator) == __CFISAForCFAllocator()) {
734734
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
735735
}
736736
#else
737737
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
738738
#endif
739739
CFAssert1(0 == context->version, __kCFLogAssertion, "%s(): context version not initialized to 0", __PRETTY_FUNCTION__);
740740
#if TARGET_OS_MAC
741-
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
741+
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
742742
return;
743743
}
744744
#endif
@@ -808,7 +808,7 @@ struct __CFNull {
808808

809809
DECLARE_STATIC_CLASS_REF(NSNull);
810810

811-
static struct __CFNull _CF_CONSTANT_OBJECT_BACKING __kCFNull = {
811+
struct __CFNull _CF_CONSTANT_OBJECT_BACKING __kCFNull = {
812812
INIT_CFRUNTIME_BASE_WITH_CLASS(NSNull, _kCFRuntimeIDCFNull)
813813
};
814814
const CFNullRef kCFNull = &__kCFNull;
@@ -853,7 +853,8 @@ void _CFRuntimeSetCFMPresent(void *addr) {
853853
/* Keep this assembly at the bottom of the source file! */
854854

855855

856-
extern void __HALT() {
856+
extern void __HALT(void);
857+
void __HALT() {
857858
__builtin_trap();
858859
}
859860

CoreFoundation/Base.subproj/CFBase.h

+22
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
#if !defined(__COREFOUNDATION_CFBASE__)
1111
#define __COREFOUNDATION_CFBASE__ 1
1212

13+
#if __has_include(<CoreFoundation/TargetConditionals.h>)
1314
#include <CoreFoundation/TargetConditionals.h>
15+
#else
16+
#include <TargetConditionals.h>
17+
#endif
18+
1419
#include <CoreFoundation/CFAvailability.h>
1520

1621
#if (defined(__CYGWIN32__) || defined(_WIN32)) && !defined(__WIN32__)
@@ -690,6 +695,23 @@ CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE;
690695
#define _CF_CONSTANT_OBJECT_STRONG_RC ((uintptr_t)_CF_SWIFT_RC_PINNED_FLAG)
691696
#endif
692697

698+
#if __has_include(<ptrauth.h>)
699+
#include <ptrauth.h>
700+
#endif
701+
702+
#ifndef __ptrauth_objc_isa_pointer
703+
#define __ptrauth_objc_isa_pointer
704+
#endif
705+
706+
#define ISA_PTRAUTH_DISCRIMINATOR 0x6AE1
707+
#if defined(__ptrauth_objc_isa_uintptr)
708+
#define __ptrauth_cf_objc_isa_pointer __ptrauth_objc_isa_uintptr
709+
#elif defined(__arm64e__) && defined(__PTRAUTH_INTRINSICS__) && __has_feature(ptrauth_objc_isa)
710+
#define __ptrauth_cf_objc_isa_pointer __ptrauth_restricted_intptr(ptrauth_key_objc_isa_pointer, 1, ISA_PTRAUTH_DISCRIMINATOR)
711+
#else
712+
#define __ptrauth_cf_objc_isa_pointer
713+
#endif
714+
693715
CF_EXTERN_C_END
694716

695717
#endif /* ! __COREFOUNDATION_CFBASE__ */

CoreFoundation/Base.subproj/CFFileUtilities.c

+7
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ CF_PRIVATE CFMutableArrayRef _CFCreateContentsOfDirectory(CFAllocatorRef alloc,
371371
}
372372
}
373373

374+
#if TARGET_OS_MAC
375+
struct dirent buffer;
376+
#endif
374377
struct dirent *dp;
375378
int err;
376379

@@ -387,7 +390,11 @@ CF_PRIVATE CFMutableArrayRef _CFCreateContentsOfDirectory(CFAllocatorRef alloc,
387390
}
388391
files = CFArrayCreateMutable(alloc, 0, & kCFTypeArrayCallBacks);
389392

393+
#if TARGET_OS_MAC
394+
while((0 == readdir_r(dirp, &buffer, &dp)) && dp) {
395+
#else
390396
while((dp = readdir(dirp))) {
397+
#endif
391398
CFURLRef fileURL;
392399
unsigned namelen = strlen(dp->d_name);
393400

0 commit comments

Comments
 (0)