SimpleFontData::DerivedFontData::~DerivedFontData() { if (!forCustomFont) return; if (smallCaps) GlyphPageTreeNode::pruneTreeCustomFontData(smallCaps.get()); if (emphasisMark) GlyphPageTreeNode::pruneTreeCustomFontData(emphasisMark.get()); if (brokenIdeograph) GlyphPageTreeNode::pruneTreeCustomFontData(brokenIdeograph.get()); if (verticalRightOrientation) GlyphPageTreeNode::pruneTreeCustomFontData(verticalRightOrientation.get()); if (uprightOrientation) GlyphPageTreeNode::pruneTreeCustomFontData(uprightOrientation.get()); #if PLATFORM(MAC) if (compositeFontReferences) { CFDictionaryRef dictionary = CFDictionaryRef(compositeFontReferences.get()); CFIndex count = CFDictionaryGetCount(dictionary); if (count > 0) { Vector<SimpleFontData*, 2> stash(count); SimpleFontData** fonts = stash.data(); CFDictionaryGetKeysAndValues(dictionary, 0, (const void **)fonts); while (count-- > 0 && *fonts) { OwnPtr<SimpleFontData> afont = adoptPtr(*fonts++); GlyphPageTreeNode::pruneTreeCustomFontData(afont.get()); } } } #endif }
// // Run down a "dictionary path", validating heavily. // CFTypeRef CFScan::dictpath(CFTypeRef obj) { while (next()) { // while we've got more text next('.'); // optional if (obj == NULL || CFGetTypeID(obj) != CFDictionaryGetTypeID()) return NULL; CFTypeRef key = make(); obj = CFDictionaryGetValue(CFDictionaryRef(obj), key); CFRelease(key); } return obj; }
CFDictionaryRef makeCFDictionaryFrom(CFDataRef data) { if (data) { CFPropertyListRef plist = CFPropertyListCreateFromXMLData(NULL, data, kCFPropertyListImmutable, NULL); if (plist && CFGetTypeID(plist) != CFDictionaryGetTypeID()) CFError::throwMe(); return CFDictionaryRef(plist); } else return NULL; }
CFDictionaryRef xpcEngineUpdate(CFTypeRef target, uint flags, CFDictionaryRef context) { Message msg("update"); // target can be NULL, a CFURLRef, a SecRequirementRef, or a CFNumberRef if (target) { if (CFGetTypeID(target) == CFNumberGetTypeID()) xpc_dictionary_set_uint64(msg, "rule", cfNumber<int64_t>(CFNumberRef(target))); else if (CFGetTypeID(target) == CFURLGetTypeID()) xpc_dictionary_set_string(msg, "url", cfString(CFURLRef(target)).c_str()); else if (CFGetTypeID(target) == SecRequirementGetTypeID()) { CFRef<CFDataRef> data; MacOSError::check(SecRequirementCopyData(SecRequirementRef(target), kSecCSDefaultFlags, &data.aref())); xpc_dictionary_set_data(msg, "requirement", CFDataGetBytePtr(data), CFDataGetLength(data)); } else MacOSError::throwMe(errSecCSInvalidObjectRef); } xpc_dictionary_set_int64(msg, "flags", flags); CFRef<CFMutableDictionaryRef> ctx = makeCFMutableDictionary(); if (context) CFDictionaryApplyFunction(context, copyCFDictionary, ctx); AuthorizationRef localAuthorization = NULL; if (CFDictionaryGetValue(ctx, kSecAssessmentUpdateKeyAuthorization) == NULL) { // no caller-provided authorization MacOSError::check(AuthorizationCreate(NULL, NULL, kAuthorizationFlagDefaults, &localAuthorization)); AuthorizationExternalForm extForm; MacOSError::check(AuthorizationMakeExternalForm(localAuthorization, &extForm)); CFDictionaryAddValue(ctx, kSecAssessmentUpdateKeyAuthorization, CFTempData(&extForm, sizeof(extForm))); } CFRef<CFDataRef> contextData = makeCFData(CFDictionaryRef(ctx)); xpc_dictionary_set_data(msg, "context", CFDataGetBytePtr(contextData), CFDataGetLength(contextData)); msg.send(); if (localAuthorization) AuthorizationFree(localAuthorization, kAuthorizationFlagDefaults); if (int64_t error = xpc_dictionary_get_int64(msg, "error")) MacOSError::throwMe(error); size_t resultLength; const void *resultData = xpc_dictionary_get_data(msg, "result", &resultLength); return makeCFDictionaryFrom(resultData, resultLength); }
char* determineHostBuildVersion() { char *currentBuild = NULL; // The following is Private API. // Please don't use this in your programs as it may break. // Notice the careful dance around these symbols as they may // someday disappear entirely, in which case this program // will need to be revved. CFDictionaryRef (*fptr)() = dlsym(RTLD_DEFAULT, "_CFCopySystemVersionDictionary"); if (fptr) { CFDictionaryRef dict = fptr(); if (dict != NULL) { CFStringRef str = CFDictionaryGetValue(dict, CFSTR("ProductBuildVersion")); currentBuild = strdup_cfstr(str); CFRelease(dict); } } return currentBuild; }
void xpcEngineAssess(CFURLRef path, uint flags, CFDictionaryRef context, CFMutableDictionaryRef result) { Message msg("assess"); xpc_dictionary_set_string(msg, "path", cfString(path).c_str()); xpc_dictionary_set_int64(msg, "flags", flags); CFRef<CFMutableDictionaryRef> ctx = makeCFMutableDictionary(); if (context) CFDictionaryApplyFunction(context, copyCFDictionary, ctx); CFRef<CFDataRef> contextData = makeCFData(CFDictionaryRef(ctx)); xpc_dictionary_set_data(msg, "context", CFDataGetBytePtr(contextData), CFDataGetLength(contextData)); msg.send(); if (int64_t error = xpc_dictionary_get_int64(msg, "error")) MacOSError::throwMe(error); size_t resultLength; const void *resultData = xpc_dictionary_get_data(msg, "result", &resultLength); CFRef<CFDictionaryRef> resultDict = makeCFDictionaryFrom(resultData, resultLength); CFDictionaryApplyFunction(resultDict, copyCFDictionary, result); CFDictionaryAddValue(result, CFSTR("assessment:remote"), kCFBooleanTrue); }
int uv__set_process_title(const char* title) { #if TARGET_OS_IPHONE return uv__pthread_setname_np(title); #else CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef, const char*, CFStringEncoding); CFBundleRef (*pCFBundleGetBundleWithIdentifier)(CFStringRef); void *(*pCFBundleGetDataPointerForName)(CFBundleRef, CFStringRef); void *(*pCFBundleGetFunctionPointerForName)(CFBundleRef, CFStringRef); CFTypeRef (*pLSGetCurrentApplicationASN)(void); OSStatus (*pLSSetApplicationInformationItem)(int, CFTypeRef, CFStringRef, CFStringRef, CFDictionaryRef*); void* application_services_handle; void* core_foundation_handle; CFBundleRef launch_services_bundle; CFStringRef* display_name_key; CFDictionaryRef (*pCFBundleGetInfoDictionary)(CFBundleRef); CFBundleRef (*pCFBundleGetMainBundle)(void); CFBundleRef hi_services_bundle; OSStatus (*pSetApplicationIsDaemon)(int); CFDictionaryRef (*pLSApplicationCheckIn)(int, CFDictionaryRef); void (*pLSSetApplicationLaunchServicesServerConnectionStatus)(uint64_t, void*); CFTypeRef asn; int err; err = UV_ENOENT; application_services_handle = dlopen("/System/Library/Frameworks/" "ApplicationServices.framework/" "Versions/A/ApplicationServices", RTLD_LAZY | RTLD_LOCAL); core_foundation_handle = dlopen("/System/Library/Frameworks/" "CoreFoundation.framework/" "Versions/A/CoreFoundation", RTLD_LAZY | RTLD_LOCAL); if (application_services_handle == NULL || core_foundation_handle == NULL) goto out; *(void **)(&pCFStringCreateWithCString) = dlsym(core_foundation_handle, "CFStringCreateWithCString"); *(void **)(&pCFBundleGetBundleWithIdentifier) = dlsym(core_foundation_handle, "CFBundleGetBundleWithIdentifier"); *(void **)(&pCFBundleGetDataPointerForName) = dlsym(core_foundation_handle, "CFBundleGetDataPointerForName"); *(void **)(&pCFBundleGetFunctionPointerForName) = dlsym(core_foundation_handle, "CFBundleGetFunctionPointerForName"); if (pCFStringCreateWithCString == NULL || pCFBundleGetBundleWithIdentifier == NULL || pCFBundleGetDataPointerForName == NULL || pCFBundleGetFunctionPointerForName == NULL) { goto out; } #define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8) launch_services_bundle = pCFBundleGetBundleWithIdentifier(S("com.apple.LaunchServices")); if (launch_services_bundle == NULL) goto out; *(void **)(&pLSGetCurrentApplicationASN) = pCFBundleGetFunctionPointerForName(launch_services_bundle, S("_LSGetCurrentApplicationASN")); if (pLSGetCurrentApplicationASN == NULL) goto out; *(void **)(&pLSSetApplicationInformationItem) = pCFBundleGetFunctionPointerForName(launch_services_bundle, S("_LSSetApplicationInformationItem")); if (pLSSetApplicationInformationItem == NULL) goto out; display_name_key = pCFBundleGetDataPointerForName(launch_services_bundle, S("_kLSDisplayNameKey")); if (display_name_key == NULL || *display_name_key == NULL) goto out; *(void **)(&pCFBundleGetInfoDictionary) = dlsym(core_foundation_handle, "CFBundleGetInfoDictionary"); *(void **)(&pCFBundleGetMainBundle) = dlsym(core_foundation_handle, "CFBundleGetMainBundle"); if (pCFBundleGetInfoDictionary == NULL || pCFBundleGetMainBundle == NULL) goto out; /* Black 10.9 magic, to remove (Not responding) mark in Activity Monitor */ hi_services_bundle = pCFBundleGetBundleWithIdentifier(S("com.apple.HIServices")); err = UV_ENOENT; if (hi_services_bundle == NULL) goto out; *(void **)(&pSetApplicationIsDaemon) = pCFBundleGetFunctionPointerForName( hi_services_bundle, S("SetApplicationIsDaemon")); *(void **)(&pLSApplicationCheckIn) = pCFBundleGetFunctionPointerForName( launch_services_bundle, S("_LSApplicationCheckIn")); *(void **)(&pLSSetApplicationLaunchServicesServerConnectionStatus) = pCFBundleGetFunctionPointerForName( launch_services_bundle, S("_LSSetApplicationLaunchServicesServerConnectionStatus")); if (pSetApplicationIsDaemon == NULL || pLSApplicationCheckIn == NULL || pLSSetApplicationLaunchServicesServerConnectionStatus == NULL) { goto out; } if (pSetApplicationIsDaemon(1) != noErr) goto out; pLSSetApplicationLaunchServicesServerConnectionStatus(0, NULL); /* Check into process manager?! */ pLSApplicationCheckIn(-2, pCFBundleGetInfoDictionary(pCFBundleGetMainBundle())); asn = pLSGetCurrentApplicationASN(); err = UV_EINVAL; if (pLSSetApplicationInformationItem(-2, /* Magic value. */ asn, *display_name_key, S(title), NULL) != noErr) { goto out; } uv__pthread_setname_np(title); /* Don't care if it fails. */ err = 0; out: if (core_foundation_handle != NULL) dlclose(core_foundation_handle); if (application_services_handle != NULL) dlclose(application_services_handle); return err; #endif /* !TARGET_OS_IPHONE */ }
void ArchHooks_MacOSX::Init() { // First, handle non-fatal termination signals. SignalHandler::OnClose( DoCleanShutdown ); CrashHandler::CrashHandlerHandleArgs( g_argc, g_argv ); CrashHandler::InitializeCrashHandler(); SignalHandler::OnClose( DoCrashSignalHandler ); SignalHandler::OnClose( DoEmergencyShutdown ); // Now that the crash handler is set up, disable crash reporter. // Breaks gdb // task_set_exception_ports( mach_task_self(), EXC_MASK_ALL, MACH_PORT_NULL, EXCEPTION_DEFAULT, 0 ); // CF*Copy* functions' return values need to be released, CF*Get* functions' do not. CFStringRef key = CFSTR( "ApplicationBundlePath" ); CFBundleRef bundle = CFBundleGetMainBundle(); CFStringRef appID = CFBundleGetIdentifier( bundle ); if( appID == NULL ) { // We were probably launched through a symlink. Don't bother hunting down the real path. return; } CFStringRef version = CFStringRef( CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleVersionKey) ); CFPropertyListRef old = CFPreferencesCopyAppValue( key, appID ); CFURLRef path = CFBundleCopyBundleURL( bundle ); CFPropertyListRef value = CFURLCopyFileSystemPath( path, kCFURLPOSIXPathStyle ); CFMutableDictionaryRef newDict = NULL; if( old && CFGetTypeID(old) != CFDictionaryGetTypeID() ) { CFRelease( old ); old = NULL; } if( !old ) { newDict = CFDictionaryCreateMutable( kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks ); CFDictionaryAddValue( newDict, version, value ); } else { CFTypeRef oldValue; CFDictionaryRef dict = CFDictionaryRef( old ); if( !CFDictionaryGetValueIfPresent(dict, version, &oldValue) || !CFEqual(oldValue, value) ) { // The value is either not present or it is but it is different newDict = CFDictionaryCreateMutableCopy( kCFAllocatorDefault, 0, dict ); CFDictionarySetValue( newDict, version, value ); } CFRelease( old ); } if( newDict ) { CFPreferencesSetAppValue( key, newDict, appID ); if( !CFPreferencesAppSynchronize(appID) ) LOG->Warn( "Failed to record the run path." ); CFRelease( newDict ); } CFRelease( value ); CFRelease( path ); }