X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/80e2389990082500d76eb566d4946be3e786c3ef..d8f41ccd20de16f8ebe2ccc84d47bf1cb2b26bbb:/libsecurity_transform/lib/Utilities.cpp diff --git a/libsecurity_transform/lib/Utilities.cpp b/libsecurity_transform/lib/Utilities.cpp deleted file mode 100644 index 094cc334..00000000 --- a/libsecurity_transform/lib/Utilities.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "Utilities.h" -#include "SecTransform.h" -#include -#include -#include - -void MyDispatchAsync(dispatch_queue_t queue, void(^block)(void)) -{ - fprintf(stderr, "Running job on queue %p\n", queue); - dispatch_async(queue, block); -} - - - -dispatch_queue_t MyDispatchQueueCreate(const char* name, dispatch_queue_attr_t attr) -{ - dispatch_queue_t result = dispatch_queue_create(name, attr); - // fprintf(stderr, "Created queue %s as %p\n", name, result); - return result; -} - - - -static CFErrorRef CreateErrorRefCore(CFStringRef domain, int errorCode, const char* format, va_list ap) -{ - CFStringRef fmt = CFStringCreateWithCString(NULL, format, kCFStringEncodingUTF8); - CFStringRef str = CFStringCreateWithFormatAndArguments(NULL, NULL, fmt, ap); - va_end(ap); - CFRelease(fmt); - - CFStringRef keys[] = {kCFErrorDescriptionKey}; - CFStringRef values[] = {str}; - - CFErrorRef result = CFErrorCreateWithUserInfoKeysAndValues(NULL, domain, errorCode, (const void**) keys, (const void**) values, 1); - CFRelease(str); - - return result; -} - - - -CFErrorRef CreateGenericErrorRef(CFStringRef domain, int errorCode, const char* format, ...) -{ - va_list ap; - va_start(ap, format); - return CreateErrorRefCore(domain, errorCode, format, ap); -} - - - -CFErrorRef CreateSecTransformErrorRef(int errorCode, const char* format, ...) -{ - // create a CFError in the SecTransform error domain. You can add an explanation, which is cool. - va_list ap; - va_start(ap, format); - - return CreateErrorRefCore(kSecTransformErrorDomain, errorCode, format, ap); -} - - - -CFErrorRef CreateSecTransformErrorRefWithCFType(int errorCode, CFTypeRef message) -{ - CFStringRef keys[] = {kCFErrorLocalizedDescriptionKey}; - CFTypeRef values[] = {message}; - return CFErrorCreateWithUserInfoKeysAndValues(NULL, kSecTransformErrorDomain, errorCode, (const void**) keys, (const void**) values, 1); -} - - - -CFTypeRef gAnnotatedRef = NULL; - -CFTypeRef DebugRetain(const void* owner, CFTypeRef type) -{ - CFTypeRef result = CFRetain(type); - if (type == gAnnotatedRef) - { - fprintf(stderr, "Object %p was retained by object %p, count = %ld\n", type, owner, CFGetRetainCount(type)); - } - - return result; -} - - - -void DebugRelease(const void* owner, CFTypeRef type) -{ - if (type == gAnnotatedRef) - { - fprintf(stderr, "Object %p was released by object %p, count = %ld\n", type, owner, CFGetRetainCount(type) - 1); - } - - CFRelease(type); -} - -// Cribbed from _dispatch_bug and altered a bit -void transforms_bug(size_t line, long val) -{ - static dispatch_once_t pred; - static char os_build[16]; - static void *last_seen; - void *ra = __builtin_return_address(0); - dispatch_once(&pred, ^{ -#ifdef __APPLE__ - int mib[] = { CTL_KERN, KERN_OSVERSION }; - size_t bufsz = sizeof(os_build); - sysctl(mib, 2, os_build, &bufsz, NULL, 0); -#else - os_build[0] = '\0'; -#endif - }); - if (last_seen != ra) { - last_seen = ra; - syslog(LOG_NOTICE, "BUG in SecTransforms: %s - %p - %lu - %lu", os_build, last_seen, (unsigned long)line, val); - } -}