Skip to content

The Ventura Core Foundation Merge #4633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions CoreFoundation/AppServices.subproj/CFUserNotification.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct __CFUserNotification {
CFOptionFlags _responseFlags;
CFStringRef _sessionID;
CFDictionaryRef _responseDictionary;
CFMachPortRef _machPort;
_Atomic(CFMachPortRef) _machPort;
CFUserNotificationCallBack _callout;
};

Expand Down Expand Up @@ -116,10 +116,10 @@ CFTypeID CFUserNotificationGetTypeID(void) {

static void __CFUserNotificationDeallocate(CFTypeRef cf) {
CFUserNotificationRef userNotification = (CFUserNotificationRef)cf;
if (userNotification->_machPort) {
CFMachPortInvalidate(userNotification->_machPort);
CFRelease(userNotification->_machPort);
userNotification->_machPort = NULL; // NOTE: this is still potentially racey and should probably have a CAS (for now this is just a stop-gap to reduce an already very rare crash potential) <rdar://problem/21077032>
CFMachPortRef port = atomic_exchange(&userNotification->_machPort, NULL);
if (port) {
CFMachPortInvalidate(port);
CFRelease(port);
} else if (MACH_PORT_NULL != userNotification->_replyPort) {
mach_port_mod_refs(mach_task_self(), userNotification->_replyPort, MACH_PORT_RIGHT_RECEIVE, -1);
}
Expand Down Expand Up @@ -190,10 +190,10 @@ static SInt32 _CFUserNotificationSendRequest(CFAllocatorRef allocator, CFStringR

#if TARGET_OS_OSX
const char *namebuffer = NOTIFICATION_PORT_NAME_MAC;
const CFIndex nameLen = sizeof(NOTIFICATION_PORT_NAME_MAC);
const nameLen = sizeof(NOTIFICATION_PORT_NAME_MAC);
#else
const char *namebuffer = NOTIFICATION_PORT_NAME_IOS;
const CFIndex nameLen = sizeof(NOTIFICATION_PORT_NAME_IOS);
const nameLen = sizeof(NOTIFICATION_PORT_NAME_IOS);
#endif

if (sessionID) {
Expand Down Expand Up @@ -256,7 +256,10 @@ CFUserNotificationRef CFUserNotificationCreate(CFAllocatorRef allocator, CFTimeI
mach_port_t replyPort = MACH_PORT_NULL;

if (!allocator) allocator = __CFGetDefaultAllocator();
retval = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &replyPort);
mach_port_options_t opts = {
.flags = MPO_REPLY_PORT,
};
retval = mach_port_construct(mach_task_self(), &opts, 0, &replyPort);
if (ERR_SUCCESS == retval && MACH_PORT_NULL != replyPort) retval = _CFUserNotificationSendRequest(allocator, sessionID, replyPort, token, timeout, flags, dictionary);
if (ERR_SUCCESS == retval) {
userNotification = (CFUserNotificationRef)_CFRuntimeCreateInstance(allocator, CFUserNotificationGetTypeID(), sizeof(struct __CFUserNotification) - sizeof(CFRuntimeBase), NULL);
Expand Down Expand Up @@ -290,9 +293,11 @@ static void _CFUserNotificationMachPortCallBack(CFMachPortRef port, void *m, CFI
CFRelease(responseData);
}
}
CFMachPortInvalidate(userNotification->_machPort);
CFRelease(userNotification->_machPort);
userNotification->_machPort = NULL;
CFMachPortRef mp = atomic_exchange(&userNotification->_machPort, NULL);
if (mp) {
CFMachPortInvalidate(mp);
CFRelease(mp);
}
mach_port_mod_refs(mach_task_self(), userNotification->_replyPort, MACH_PORT_RIGHT_RECEIVE, -1);
userNotification->_replyPort = MACH_PORT_NULL;
userNotification->_callout(userNotification, responseFlags);
Expand Down Expand Up @@ -327,10 +332,10 @@ SInt32 CFUserNotificationReceiveResponse(CFUserNotificationRef userNotification,
CFRelease(responseData);
}
}
if (userNotification->_machPort) {
CFMachPortInvalidate(userNotification->_machPort);
CFRelease(userNotification->_machPort);
userNotification->_machPort = NULL;
CFMachPortRef mp = atomic_exchange(&userNotification->_machPort, NULL);
if (mp) {
CFMachPortInvalidate(mp);
CFRelease(mp);
}
mach_port_mod_refs(mach_task_self(), userNotification->_replyPort, MACH_PORT_RIGHT_RECEIVE, -1);
userNotification->_replyPort = MACH_PORT_NULL;
Expand Down
5 changes: 2 additions & 3 deletions CoreFoundation/Base.subproj/CFBase.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct __CFAllocator {
};

CF_INLINE uintptr_t __CFISAForCFAllocator(void) {
return _GetCFRuntimeObjcClassAtIndex(_kCFRuntimeIDCFAllocator);
return __CFISAForTypeID(_kCFRuntimeIDCFAllocator);
}

CF_INLINE CFAllocatorRetainCallBack __CFAllocatorGetRetainFunction(const CFAllocatorContext *context) {
Expand Down Expand Up @@ -853,8 +853,7 @@ void _CFRuntimeSetCFMPresent(void *addr) {
/* Keep this assembly at the bottom of the source file! */


extern void __HALT(void);
void __HALT() {
extern void __HALT() {
__builtin_trap();
}

Expand Down
12 changes: 12 additions & 0 deletions CoreFoundation/Base.subproj/CFBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ CF_EXTERN_C_BEGIN
# define CF_SWIFT_NAME(_name)
#endif

#if __has_attribute(__swift_attr__)
# define CF_SWIFT_UNAVAILABLE_FROM_ASYNC(msg) __attribute__((__swift_attr__("@_unavailableFromAsync(message: \"" msg "\")")))
#else
# define CF_SWIFT_UNAVAILABLE_FROM_ASYNC(msg)
#endif

#if __has_attribute(noescape)
#define CF_NOESCAPE __attribute__((noescape))
#else
Expand All @@ -324,6 +330,12 @@ CF_EXTERN_C_BEGIN
#define CF_WARN_UNUSED_RESULT
#endif

#if __has_attribute(fallthrough)
#define CF_FALLTHROUGH __attribute__((fallthrough))
#else
#define CF_FALLTHROUGH
#endif

#if !__has_feature(objc_generics_variance)
#ifndef __covariant
#define __covariant
Expand Down
36 changes: 15 additions & 21 deletions CoreFoundation/Base.subproj/CFFileUtilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ static Boolean _CFReadBytesFromPathAndGetFD(CFAllocatorRef alloc, const char *pa
struct statinfo statBuf;

*bytes = NULL;



int no_hang_fd = openAutoFSNoWait();
*fd = open(path, O_RDONLY|extraOpenFlags|CF_OPENFLGS, 0666);

Expand Down Expand Up @@ -123,7 +122,7 @@ static Boolean _CFReadBytesFromPathAndGetFD(CFAllocatorRef alloc, const char *pa
desiredLength = maxLength;
}
*bytes = CFAllocatorAllocate(alloc, desiredLength, 0);
if (!bytes) {
if (*bytes == NULL) {
close(*fd);
*fd = -1;
closeAutoFSNoWait(no_hang_fd);
Expand Down Expand Up @@ -504,7 +503,13 @@ CF_PRIVATE CFMutableArrayRef _CFCreateContentsOfDirectory(CFAllocatorRef alloc,
return files;
}

CF_PRIVATE SInt32 _CFGetPathProperties(CFAllocatorRef alloc, char *path, Boolean *exists, SInt32 *posixMode, int64_t *size, CFDateRef *modTime, SInt32 *ownerID, CFArrayRef *dirContents) {
CF_PRIVATE SInt32 _CFGetFileProperties(CFAllocatorRef alloc, CFURLRef pathURL, Boolean *exists, SInt32 *posixMode, int64_t *size, CFDateRef *modTime, SInt32 *ownerID, CFArrayRef *dirContents) {
char path[CFMaxPathSize];

if (!CFURLGetFileSystemRepresentation(pathURL, true, (uint8_t *)path, CFMaxPathLength)) {
return -1;
}

Boolean fileExists;
Boolean isDirectory = false;

Expand Down Expand Up @@ -592,17 +597,6 @@ CF_PRIVATE SInt32 _CFGetPathProperties(CFAllocatorRef alloc, char *path, Boolean
return 0;
}

CF_PRIVATE SInt32 _CFGetFileProperties(CFAllocatorRef alloc, CFURLRef pathURL, Boolean *exists, SInt32 *posixMode, int64_t *size, CFDateRef *modTime, SInt32 *ownerID, CFArrayRef *dirContents) {

char path[CFMaxPathSize];

if (!CFURLGetFileSystemRepresentation(pathURL, true, (uint8_t *)path, CFMaxPathLength)) {
return -1;
}

return _CFGetPathProperties(alloc, path, exists, posixMode, size, modTime, ownerID, dirContents);
}

CF_PRIVATE bool _CFURLExists(CFURLRef url) {
Boolean exists = false;
return url && (0 == _CFGetFileProperties(kCFAllocatorSystemDefault, url, &exists, NULL, NULL, NULL, NULL, NULL)) && exists;
Expand Down Expand Up @@ -1240,7 +1234,7 @@ static CFStringRef _CFXDGCreateHome(void) {
}

/// a single base directory relative to which user-specific data files should be written. This directory is defined by the environment variable $XDG_DATA_HOME.
CF_CROSS_PLATFORM_EXPORT
CF_EXPORT_NONOBJC_ONLY
CFStringRef _CFXDGCreateDataHomePath(void) {
// $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.
const char *dataHome = __CFgetenv("XDG_DATA_HOME");
Expand All @@ -1255,7 +1249,7 @@ CFStringRef _CFXDGCreateDataHomePath(void) {
}

/// a single base directory relative to which user-specific configuration files should be written. This directory is defined by the environment variable $XDG_CONFIG_HOME.
CF_CROSS_PLATFORM_EXPORT
CF_EXPORT_NONOBJC_ONLY
CFStringRef _CFXDGCreateConfigHomePath(void) {
// $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.
const char *configHome = __CFgetenv("XDG_CONFIG_HOME");
Expand All @@ -1270,7 +1264,7 @@ CFStringRef _CFXDGCreateConfigHomePath(void) {
}

/// a set of preference ordered base directories relative to which data files should be searched. This set of directories is defined by the environment variable $XDG_DATA_DIRS.
CF_CROSS_PLATFORM_EXPORT
CF_EXPORT_NONOBJC_ONLY
CFArrayRef _CFXDGCreateDataDirectoriesPaths(void) {
// $XDG_DATA_DIRS defines the preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME base directory. The directories in $XDG_DATA_DIRS should be separated with a colon ':'.
// If $XDG_DATA_DIRS is either not set or empty, a value equal to /usr/local/share/:/usr/share/ should be used.
Expand All @@ -1294,7 +1288,7 @@ CFArrayRef _CFXDGCreateDataDirectoriesPaths(void) {


/// a set of preference ordered base directories relative to which configuration files should be searched. This set of directories is defined by the environment variable $XDG_CONFIG_DIRS.
CF_CROSS_PLATFORM_EXPORT
CF_EXPORT_NONOBJC_ONLY
CFArrayRef _CFXDGCreateConfigDirectoriesPaths(void) {
// $XDG_CONFIG_DIRS defines the preference-ordered set of base directories to search for configuration files in addition to the $XDG_CONFIG_HOME base directory. The directories in $XDG_CONFIG_DIRS should be separated with a colon ':'.
// If $XDG_CONFIG_DIRS is either not set or empty, a value equal to /etc/xdg should be used.
Expand All @@ -1316,7 +1310,7 @@ CFArrayRef _CFXDGCreateConfigDirectoriesPaths(void) {
}

/// a single base directory relative to which user-specific non-essential (cached) data should be written. This directory is defined by the environment variable $XDG_CACHE_HOME.
CF_CROSS_PLATFORM_EXPORT
CF_EXPORT_NONOBJC_ONLY
CFStringRef _CFXDGCreateCacheDirectoryPath(void) {
//$XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.
const char *cacheHome = __CFgetenv("XDG_CACHE_HOME");
Expand All @@ -1332,7 +1326,7 @@ CFStringRef _CFXDGCreateCacheDirectoryPath(void) {
}

/// a single base directory relative to which user-specific runtime files and other file objects should be placed. This directory is defined by the environment variable $XDG_RUNTIME_DIR.
CF_CROSS_PLATFORM_EXPORT
CF_EXPORT_NONOBJC_ONLY
CFStringRef _CFXDGCreateRuntimeDirectoryPath(void) {
const char *runtimeDir = __CFgetenv("XDG_RUNTIME_DIR");
if (runtimeDir && strnlen(runtimeDir, CFMaxPathSize) > 1 && runtimeDir[0] == '/') {
Expand Down
Loading