2 #include "SecTransform.h"
3 #include <sys/sysctl.h>
5 #include <dispatch/dispatch.h>
7 void MyDispatchAsync(dispatch_queue_t queue
, void(^block
)(void))
9 fprintf(stderr
, "Running job on queue %p\n", queue
);
10 dispatch_async(queue
, block
);
15 dispatch_queue_t
MyDispatchQueueCreate(const char* name
, dispatch_queue_attr_t attr
)
17 dispatch_queue_t result
= dispatch_queue_create(name
, attr
);
18 // fprintf(stderr, "Created queue %s as %p\n", name, result);
24 static CFErrorRef
CreateErrorRefCore(CFStringRef domain
, int errorCode
, const char* format
, va_list ap
)
26 CFStringRef fmt
= CFStringCreateWithCString(NULL
, format
, kCFStringEncodingUTF8
);
27 CFStringRef str
= CFStringCreateWithFormatAndArguments(NULL
, NULL
, fmt
, ap
);
31 CFStringRef keys
[] = {kCFErrorDescriptionKey
};
32 CFStringRef values
[] = {str
};
34 CFErrorRef result
= CFErrorCreateWithUserInfoKeysAndValues(NULL
, domain
, errorCode
, (const void**) keys
, (const void**) values
, 1);
42 CFErrorRef
CreateGenericErrorRef(CFStringRef domain
, int errorCode
, const char* format
, ...)
46 return CreateErrorRefCore(domain
, errorCode
, format
, ap
);
51 CFErrorRef
CreateSecTransformErrorRef(int errorCode
, const char* format
, ...)
53 // create a CFError in the SecTransform error domain. You can add an explanation, which is cool.
57 return CreateErrorRefCore(kSecTransformErrorDomain
, errorCode
, format
, ap
);
62 CFErrorRef
CreateSecTransformErrorRefWithCFType(int errorCode
, CFTypeRef message
)
64 CFStringRef keys
[] = {kCFErrorLocalizedDescriptionKey
};
65 CFTypeRef values
[] = {message
};
66 return CFErrorCreateWithUserInfoKeysAndValues(NULL
, kSecTransformErrorDomain
, errorCode
, (const void**) keys
, (const void**) values
, 1);
71 CFTypeRef gAnnotatedRef
= NULL
;
73 CFTypeRef
DebugRetain(const void* owner
, CFTypeRef type
)
75 CFTypeRef result
= CFRetain(type
);
76 if (type
== gAnnotatedRef
)
78 fprintf(stderr
, "Object %p was retained by object %p, count = %ld\n", type
, owner
, CFGetRetainCount(type
));
86 void DebugRelease(const void* owner
, CFTypeRef type
)
88 if (type
== gAnnotatedRef
)
90 fprintf(stderr
, "Object %p was released by object %p, count = %ld\n", type
, owner
, CFGetRetainCount(type
) - 1);
96 // Cribbed from _dispatch_bug and altered a bit
97 void transforms_bug(size_t line
, long val
)
99 static dispatch_once_t pred
;
100 static char os_build
[16];
101 static void *last_seen
;
102 void *ra
= __builtin_return_address(0);
103 dispatch_once(&pred
, ^{
105 int mib
[] = { CTL_KERN
, KERN_OSVERSION
};
106 size_t bufsz
= sizeof(os_build
);
107 sysctl(mib
, 2, os_build
, &bufsz
, NULL
, 0);
112 if (last_seen
!= ra
) {
114 syslog(LOG_NOTICE
, "BUG in SecTransforms: %s - %p - %lu - %lu", os_build
, last_seen
, (unsigned long)line
, val
);