]> git.saurik.com Git - apple/cf.git/blob - CFInternal.h
d85772e33f45430c68d92b03b18583cb3ad2c9f1
[apple/cf.git] / CFInternal.h
1 /*
2 * Copyright (c) 2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /* CFInternal.h
25 Copyright (c) 1998-2009, Apple Inc. All rights reserved.
26 */
27
28 /*
29 NOT TO BE USED OUTSIDE CF!
30 */
31
32 #if !CF_BUILDING_CF
33 #error The header file CFInternal.h is for the exclusive use of CoreFoundation. No other project should include it.
34 #endif
35
36 #if !defined(__COREFOUNDATION_CFINTERNAL__)
37 #define __COREFOUNDATION_CFINTERNAL__ 1
38
39 CF_EXTERN_C_BEGIN
40
41 #include <CoreFoundation/CFBase.h>
42 #include <CoreFoundation/CFURL.h>
43 #include <CoreFoundation/CFString.h>
44 #include <CoreFoundation/CFDate.h>
45 #include <CoreFoundation/CFArray.h>
46 #include <CoreFoundation/CFRunLoop.h>
47 #include <CoreFoundation/CFStorage.h>
48 #include <CoreFoundation/CFLogUtilities.h>
49 #include <CoreFoundation/CFRuntime.h>
50 #include <limits.h>
51 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
52 #include <xlocale.h>
53 #include <libkern/OSAtomic.h>
54 #include <mach/mach_time.h>
55 #include <mach/mach.h>
56 #include <unistd.h>
57 #endif
58 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
59 #include <sys/time.h>
60 #include <pthread.h>
61 #include <signal.h>
62 #endif
63 #if DEPLOYMENT_TARGET_WINDOWS
64 #include <pthread.h>
65 #endif
66
67
68 #if defined(__BIG_ENDIAN__)
69 #define __CF_BIG_ENDIAN__ 1
70 #define __CF_LITTLE_ENDIAN__ 0
71 #endif
72
73 #if defined(__LITTLE_ENDIAN__)
74 #define __CF_LITTLE_ENDIAN__ 1
75 #define __CF_BIG_ENDIAN__ 0
76 #endif
77
78 #include <CoreFoundation/ForFoundationOnly.h>
79
80 CF_EXPORT const char *_CFProcessName(void);
81 CF_EXPORT CFStringRef _CFProcessNameString(void);
82
83 CF_EXPORT Boolean _CFIsCFM(void);
84
85 CF_EXPORT Boolean _CFGetCurrentDirectory(char *path, int maxlen);
86
87 CF_EXPORT CFStringRef _CFGetUserName(void);
88
89 CF_EXPORT CFArrayRef _CFGetWindowsBinaryDirectories(void);
90
91 CF_EXPORT CFStringRef _CFStringCreateHostName(void);
92
93 CF_EXPORT void _CFMachPortInstallNotifyPort(CFRunLoopRef rl, CFStringRef mode);
94
95 #if defined(__ppc__)
96 #define HALT do {asm __volatile__("trap"); kill(getpid(), 9); } while (0)
97 #elif defined(__i386__) || defined(__x86_64__)
98 #if defined(__GNUC__)
99 #define HALT do {asm __volatile__("int3"); kill(getpid(), 9); } while (0)
100 #elif defined(_MSC_VER)
101 #define HALT do { DebugBreak(); abort(); } while (0)
102 #else
103 #error Compiler not supported
104 #endif
105 #endif
106 #if defined(__arm__)
107 #define HALT do {asm __volatile__("bkpt 0xCF"); kill(getpid(), 9); } while (0)
108 #endif
109
110 #if defined(DEBUG)
111 #define __CFAssert(cond, prio, desc, a1, a2, a3, a4, a5) \
112 do { \
113 if (!(cond)) { \
114 CFLog(prio, CFSTR(desc), a1, a2, a3, a4, a5); \
115 /* HALT; */ \
116 } \
117 } while (0)
118 #else
119 #define __CFAssert(cond, prio, desc, a1, a2, a3, a4, a5) \
120 do {} while (0)
121 #endif
122
123 #define CFAssert(condition, priority, description) \
124 __CFAssert((condition), (priority), description, 0, 0, 0, 0, 0)
125 #define CFAssert1(condition, priority, description, a1) \
126 __CFAssert((condition), (priority), description, (a1), 0, 0, 0, 0)
127 #define CFAssert2(condition, priority, description, a1, a2) \
128 __CFAssert((condition), (priority), description, (a1), (a2), 0, 0, 0)
129 #define CFAssert3(condition, priority, description, a1, a2, a3) \
130 __CFAssert((condition), (priority), description, (a1), (a2), (a3), 0, 0)
131 #define CFAssert4(condition, priority, description, a1, a2, a3, a4) \
132 __CFAssert((condition), (priority), description, (a1), (a2), (a3), (a4), 0)
133
134 #define __kCFLogAssertion 3
135
136 #if defined(DEBUG)
137 extern void __CFGenericValidateType_(CFTypeRef cf, CFTypeID type, const char *func);
138 #define __CFGenericValidateType(cf, type) __CFGenericValidateType_(cf, type, __PRETTY_FUNCTION__)
139 #else
140 #define __CFGenericValidateType(cf, type) ((void)0)
141 #endif
142
143 #define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__) * 3)
144 #define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__) * 3)
145
146 /* Bit manipulation macros */
147 /* Bits are numbered from 31 on left to 0 on right */
148 /* May or may not work if you use them on bitfields in types other than UInt32, bitfields the full width of a UInt32, or anything else for which they were not designed. */
149 /* In the following, N1 and N2 specify an inclusive range N2..N1 with N1 >= N2 */
150 #define __CFBitfieldMask(N1, N2) ((((UInt32)~0UL) << (31UL - (N1) + (N2))) >> (31UL - N1))
151 #define __CFBitfieldGetValue(V, N1, N2) (((V) & __CFBitfieldMask(N1, N2)) >> (N2))
152 #define __CFBitfieldSetValue(V, N1, N2, X) ((V) = ((V) & ~__CFBitfieldMask(N1, N2)) | (((X) << (N2)) & __CFBitfieldMask(N1, N2)))
153 #define __CFBitfieldMaxValue(N1, N2) __CFBitfieldGetValue(0xFFFFFFFFUL, (N1), (N2))
154
155 #define __CFBitIsSet(V, N) (((V) & (1UL << (N))) != 0)
156 #define __CFBitSet(V, N) ((V) |= (1UL << (N)))
157 #define __CFBitClear(V, N) ((V) &= ~(1UL << (N)))
158
159
160 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
161 // The fixed range 50 - 59 of pthread_specific keys is reserved
162 // for CoreFoundation; see <System/pthread_machdep.h>.
163 // 60 - 69 are reserved for Foundation; Foundation uses 64 - 69
164 // and reserves 60-63 for CoreFoundation.
165 // Foundation knows about the value of __CFTSDKeyAutoreleaseData1
166 enum {
167 __CFTSDKeyUnused50 = 50,
168 __CFTSDKeyAllocator = 51,
169 __CFTSDKeyExceptionData = 52,
170 __CFTSDKeyRunLoopCntr = 53,
171 __CFTSDKeyRunLoop = 54,
172 __CFTSDKeyICUConverter = 55,
173 __CFTSDKeyCollatorLocale = 56,
174 __CFTSDKeyCollatorUCollator = 57,
175 __CFTSDKeyIsInNSCache = 58,
176 __CFTSDKeyIsInCFLog = 59,
177 __CFTSDKeyIsInGCDMainQ = 60,
178 __CFTSDKeyUnused61 = 61,
179 __CFTSDKeyAutoreleaseData1 = 62,
180 __CFTSDKeyAutoreleaseData2 = 63, // autorelease pool stuff must be higher than run loop constants
181 };
182
183 extern int pthread_key_init_np(int, void (*)(void *));
184 #endif
185
186 #if DEPLOYMENT_TARGET_WINDOWS
187 typedef struct ___CFThreadSpecificData {
188 void *_unused1;
189 void *_allocator;
190 void *_runLoop;
191 int _runLoop_pid;
192 HHOOK _messageHook;
193 void *_icuThreadData;
194
195 // If you add things to this struct, add cleanup to __CFFinalizeThreadData()
196 } __CFThreadSpecificData;
197
198 extern __CFThreadSpecificData *__CFGetThreadSpecificData(void);
199 __private_extern__ void __CFFinalizeThreadData(void *arg);
200 extern DWORD __CFTSDKey;
201
202 // implemented in windowsSyncHelper.c
203 __private_extern__ __CFThreadSpecificData *__CFGetThreadSpecificData_inline(void);
204
205 #endif
206
207 #define __kCFAllocatorTypeID_CONST 2
208
209 CF_INLINE CFAllocatorRef __CFGetDefaultAllocator(void) {
210 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
211 CFAllocatorRef allocator = pthread_getspecific(__CFTSDKeyAllocator);
212 #else
213 CFAllocatorRef allocator = (CFAllocatorRef)__CFGetThreadSpecificData_inline()->_allocator;
214 #endif
215 if (NULL == allocator) {
216 allocator = kCFAllocatorSystemDefault;
217 }
218 return allocator;
219 }
220
221 extern CFTypeID __CFGenericTypeID(const void *cf);
222
223 // This should only be used in CF types, not toll-free bridged objects!
224 // It should not be used with CFAllocator arguments!
225 // Use CFGetAllocator() in the general case, and this inline function in a few limited (but often called) situations.
226 CF_INLINE CFAllocatorRef __CFGetAllocator(CFTypeRef cf) { // !!! Use with CF types only, and NOT WITH CFAllocator!
227 CFAssert1(__kCFAllocatorTypeID_CONST != __CFGenericTypeID(cf), __kCFLogAssertion, "__CFGetAllocator(): CFAllocator argument", cf);
228 if (__builtin_expect(__CFBitfieldGetValue(((const CFRuntimeBase *)cf)->_cfinfo[CF_INFO_BITS], 7, 7), 1)) {
229 return kCFAllocatorSystemDefault;
230 }
231 return *(CFAllocatorRef *)((char *)cf - sizeof(CFAllocatorRef));
232 }
233
234 // Don't define a __CFGetCurrentRunLoop(), because even internal clients should go through the real one
235
236
237 #if !defined(LLONG_MAX)
238 #if defined(_I64_MAX)
239 #define LLONG_MAX _I64_MAX
240 #else
241 #warning Arbitrarily defining LLONG_MAX
242 #define LLONG_MAX (int64_t)9223372036854775807
243 #endif
244 #endif /* !defined(LLONG_MAX) */
245
246 #if !defined(LLONG_MIN)
247 #if defined(_I64_MIN)
248 #define LLONG_MIN _I64_MIN
249 #else
250 #warning Arbitrarily defining LLONG_MIN
251 #define LLONG_MIN (-LLONG_MAX - (int64_t)1)
252 #endif
253 #endif /* !defined(LLONG_MIN) */
254
255 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
256 #define __CFMin(A,B) ({__typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
257 #define __CFMax(A,B) ({__typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
258 #else /* __GNUC__ */
259 #define __CFMin(A,B) ((A) < (B) ? (A) : (B))
260 #define __CFMax(A,B) ((A) > (B) ? (A) : (B))
261 #endif /* __GNUC__ */
262
263 /* Secret CFAllocator hint bits */
264 #define __kCFAllocatorTempMemory 0x2
265 #define __kCFAllocatorNoPointers 0x10
266 #define __kCFAllocatorDoNotRecordEvent 0x100
267 #define __kCFAllocatorGCScannedMemory 0x200 /* GC: memory should be scanned. */
268 #define __kCFAllocatorGCObjectMemory 0x400 /* GC: memory needs to be finalized. */
269
270 CF_INLINE auto_memory_type_t CF_GET_GC_MEMORY_TYPE(CFOptionFlags flags) {
271 auto_memory_type_t type = (flags & __kCFAllocatorGCScannedMemory ? 0 : AUTO_UNSCANNED) | (flags & __kCFAllocatorGCObjectMemory ? AUTO_OBJECT : 0);
272 return type;
273 }
274
275 CF_INLINE void __CFAssignWithWriteBarrier(void **location, void *value) {
276 if (kCFUseCollectableAllocator) {
277 objc_assign_strongCast((id)value, (id *)location);
278 } else {
279 *location = value;
280 }
281 }
282
283 // Zero-retain count CFAllocator functions, i.e. memory that will be collected, no dealloc necessary
284 CF_EXPORT void *_CFAllocatorAllocateGC(CFAllocatorRef allocator, CFIndex size, CFOptionFlags hint);
285 CF_EXPORT void *_CFAllocatorReallocateGC(CFAllocatorRef allocator, void *ptr, CFIndex newsize, CFOptionFlags hint);
286 CF_EXPORT void _CFAllocatorDeallocateGC(CFAllocatorRef allocator, void *ptr);
287
288 CF_EXPORT CFAllocatorRef _CFTemporaryMemoryAllocator(void);
289
290 extern SInt64 __CFTimeIntervalToTSR(CFTimeInterval ti);
291 extern CFTimeInterval __CFTSRToTimeInterval(SInt64 tsr);
292
293 extern CFStringRef __CFCopyFormattingDescription(CFTypeRef cf, CFDictionaryRef formatOptions);
294
295 /* result is long long or int, depending on doLonglong
296 */
297 extern Boolean __CFStringScanInteger(CFStringInlineBuffer *buf, CFTypeRef locale, SInt32 *indexPtr, Boolean doLonglong, void *result);
298 extern Boolean __CFStringScanDouble(CFStringInlineBuffer *buf, CFTypeRef locale, SInt32 *indexPtr, double *resultPtr);
299 extern Boolean __CFStringScanHex(CFStringInlineBuffer *buf, SInt32 *indexPtr, unsigned *result);
300
301 extern const char *__CFgetenv(const char *n);
302
303 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
304 #define STACK_BUFFER_DECL(T, N, C) T N[C]
305 #elif DEPLOYMENT_TARGET_WINDOWS
306 #define STACK_BUFFER_DECL(T, N, C) T *N = (T *)_alloca((C) * sizeof(T))
307 #else
308 #error Unknown or unspecified DEPLOYMENT_TARGET
309 #endif
310
311
312 #ifdef __CONSTANT_CFSTRINGS__
313 #define CONST_STRING_DECL(S, V) const CFStringRef S = (const CFStringRef)__builtin___CFStringMakeConstantString(V);
314 #define PE_CONST_STRING_DECL(S, V) __private_extern__ const CFStringRef S = (const CFStringRef)__builtin___CFStringMakeConstantString(V);
315 #else
316
317 struct CF_CONST_STRING {
318 CFRuntimeBase _base;
319 uint8_t *_ptr;
320 uint32_t _length;
321 };
322
323 CF_EXPORT int __CFConstantStringClassReference[];
324
325 /* CFNetwork also has a copy of the CONST_STRING_DECL macro (for use on platforms without constant string support in cc); please warn cfnetwork-core@group.apple.com of any necessary changes to this macro. -- REW, 1/28/2002 */
326
327 #if __CF_BIG_ENDIAN__ && (DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED)
328 #define CONST_STRING_DECL(S, V) \
329 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x0000, 0x07c8}}, V, sizeof(V) - 1}; \
330 const CFStringRef S = (CFStringRef) & __ ## S ## __;
331 #define PE_CONST_STRING_DECL(S, V) \
332 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x0000, 0x07c8}}, V, sizeof(V) - 1}; \
333 __private_extern__ const CFStringRef S = (CFStringRef) & __ ## S ## __;
334 #elif __CF_LITTLE_ENDIAN__ && (DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED)
335 #define CONST_STRING_DECL(S, V) \
336 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x07c8, 0x0000}}, V, sizeof(V) - 1}; \
337 const CFStringRef S = (CFStringRef) & __ ## S ## __;
338 #define PE_CONST_STRING_DECL(S, V) \
339 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x07c8, 0x0000}}, V, sizeof(V) - 1}; \
340 __private_extern__ const CFStringRef S = (CFStringRef) & __ ## S ## __;
341 #elif DEPLOYMENT_TARGET_WINDOWS
342 #define CONST_STRING_DECL(S, V) \
343 static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
344 const CFStringRef S = (CFStringRef) & __ ## S ## __;
345 #define PE_CONST_STRING_DECL(S, V) \
346 static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
347 __private_extern__ const CFStringRef S = (CFStringRef) & __ ## S ## __;
348 #endif
349 #endif // __BIG_ENDIAN__
350
351
352 /* Buffer size for file pathname */
353 #if DEPLOYMENT_TARGET_WINDOWS
354 #define CFMaxPathSize ((CFIndex)262)
355 #define CFMaxPathLength ((CFIndex)260)
356 #else
357 #define CFMaxPathSize ((CFIndex)1026)
358 #define CFMaxPathLength ((CFIndex)1024)
359 #endif
360
361 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
362 extern bool __CFOASafe;
363 extern void __CFSetLastAllocationEventName(void *ptr, const char *classname);
364 #else
365 #define __CFOASafe 0
366 #define __CFSetLastAllocationEventName(a, b) ((void) 0)
367 #endif
368
369
370
371 /* Comparators are passed the address of the values; this is somewhat different than CFComparatorFunction is used in public API usually. */
372 CF_EXPORT CFIndex CFBSearch(const void *element, CFIndex elementSize, const void *list, CFIndex count, CFComparatorFunction comparator, void *context);
373
374 CF_EXPORT CFHashCode CFHashBytes(UInt8 *bytes, CFIndex length);
375
376 CF_EXPORT CFStringEncoding CFStringFileSystemEncoding(void);
377
378 __private_extern__ CFStringRef __CFStringCreateImmutableFunnel3(CFAllocatorRef alloc, const void *bytes, CFIndex numBytes, CFStringEncoding encoding, Boolean possiblyExternalFormat, Boolean tryToReduceUnicode, Boolean hasLengthByte, Boolean hasNullByte, Boolean noCopy, CFAllocatorRef contentsDeallocator, UInt32 converterFlags);
379
380 extern const void *__CFStringCollectionCopy(CFAllocatorRef allocator, const void *ptr);
381 extern const void *__CFTypeCollectionRetain(CFAllocatorRef allocator, const void *ptr);
382 extern void __CFTypeCollectionRelease(CFAllocatorRef allocator, const void *ptr);
383
384 extern CFTypeRef CFMakeUncollectable(CFTypeRef cf);
385
386 __private_extern__ void _CFRaiseMemoryException(CFStringRef reason);
387
388 __private_extern__ Boolean __CFProphylacticAutofsAccess;
389
390
391 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
392
393 typedef OSSpinLock CFSpinLock_t;
394
395 #define CFSpinLockInit OS_SPINLOCK_INIT
396 #define CF_SPINLOCK_INIT_FOR_STRUCTS(X) (X = CFSpinLockInit)
397
398 #define __CFSpinLock(LP) ({ \
399 OSSpinLock *__lockp__ = (LP); \
400 OSSpinLock __lockv__ = *__lockp__; \
401 if (0 != __lockv__ && ~0 != __lockv__ && (uintptr_t)__lockp__ != (uintptr_t)__lockv__) { \
402 CFLog(3, CFSTR("In '%s', file %s, line %d, during lock, spin lock %p has value 0x%x, which is neither locked nor unlocked. The memory has been smashed."), __PRETTY_FUNCTION__, __FILE__, __LINE__, __lockp__, __lockv__); \
403 /* HALT; */ \
404 } \
405 OSSpinLockLock(__lockp__); })
406
407 #define __CFSpinUnlock(LP) ({ \
408 OSSpinLock *__lockp__ = (LP); \
409 OSSpinLock __lockv__ = *__lockp__; \
410 if (~0 != __lockv__ && (uintptr_t)__lockp__ != (uintptr_t)__lockv__) { \
411 CFLog(3, CFSTR("In '%s', file %s, line %d, during unlock, spin lock %p has value 0x%x, which is not locked. The memory has been smashed or the lock is being unlocked when not locked."), __PRETTY_FUNCTION__, __FILE__, __LINE__, __lockp__, __lockv__); \
412 /* HALT; */ \
413 } \
414 OSSpinLockUnlock(__lockp__); })
415
416 #elif DEPLOYMENT_TARGET_WINDOWS
417
418 typedef int32_t CFSpinLock_t;
419 #define CFSpinLockInit 0
420 #define CF_SPINLOCK_INIT_FOR_STRUCTS(X) (X = CFSpinLockInit)
421
422 CF_INLINE void __CFSpinLock(volatile CFSpinLock_t *lock) {
423 while (InterlockedCompareExchange((LONG volatile *)lock, ~0, 0) != 0) {
424 Sleep(0);
425 }
426 }
427
428 CF_INLINE void __CFSpinUnlock(volatile CFSpinLock_t *lock) {
429 MemoryBarrier();
430 *lock = 0;
431 }
432
433
434 #else
435
436 #warning CF spin locks not defined for this platform -- CF is not thread-safe
437 #define __CFSpinLock(A) do {} while (0)
438 #define __CFSpinUnlock(A) do {} while (0)
439
440 #endif
441
442
443 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
444 extern uint8_t __CF120293;
445 extern uint8_t __CF120290;
446 extern void __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__(void);
447 #define CHECK_FOR_FORK() do { __CF120290 = true; if (__CF120293) __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__(); } while (0)
448 #define CHECK_FOR_FORK_RET(...) do { CHECK_FOR_FORK(); if (__CF120293) return __VA_ARGS__; } while (0)
449 #define HAS_FORKED() (__CF120293)
450 #endif
451
452 #if !defined(CHECK_FOR_FORK)
453 #define CHECK_FOR_FORK() do { } while (0)
454 #endif
455
456 #if !defined(CHECK_FOR_FORK_RET)
457 #define CHECK_FOR_FORK_RET(...) do { } while (0)
458 #endif
459
460 #if !defined(HAS_FORKED)
461 #define HAS_FORKED() 0
462 #endif
463
464 #if DEPLOYMENT_TARGET_WINDOWS
465 #include <errno.h>
466 #elif DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
467 #include <sys/errno.h>
468 #endif
469
470 #define thread_errno() errno
471 #define thread_set_errno(V) do {errno = (V);} while (0)
472
473 extern void *__CFStartSimpleThread(void *func, void *arg);
474
475 /* ==================== Simple file access ==================== */
476 /* For dealing with abstract types. MF:!!! These ought to be somewhere else and public. */
477
478 CF_EXPORT CFStringRef _CFCopyExtensionForAbstractType(CFStringRef abstractType);
479
480 /* ==================== Simple file access ==================== */
481 /* These functions all act on a c-strings which must be in the file system encoding. */
482
483 CF_EXPORT Boolean _CFCreateDirectory(const char *path);
484 #if DEPLOYMENT_TARGET_WINDOWS
485 CF_EXPORT Boolean _CFCreateDirectoryWide(const wchar_t *path);
486 #endif
487 CF_EXPORT Boolean _CFRemoveDirectory(const char *path);
488 CF_EXPORT Boolean _CFDeleteFile(const char *path);
489
490 CF_EXPORT Boolean _CFReadBytesFromFile(CFAllocatorRef alloc, CFURLRef url, void **bytes, CFIndex *length, CFIndex maxLength);
491 /* resulting bytes are allocated from alloc which MUST be non-NULL. */
492 /* maxLength of zero means the whole file. Otherwise it sets a limit on the number of bytes read. */
493
494 CF_EXPORT Boolean _CFWriteBytesToFile(CFURLRef url, const void *bytes, CFIndex length);
495 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
496 CF_EXPORT Boolean _CFWriteBytesToFileWithAtomicity(CFURLRef url, const void *bytes, unsigned int length, SInt32 mode, Boolean atomic);
497 #endif
498
499 CF_EXPORT CFMutableArrayRef _CFContentsOfDirectory(CFAllocatorRef alloc, char *dirPath, void *dirSpec, CFURLRef dirURL, CFStringRef matchingAbstractType);
500 /* On Mac OS 8/9, one of dirSpec, dirPath and dirURL must be non-NULL */
501 /* On all other platforms, one of path and dirURL must be non-NULL */
502 /* If both are present, they are assumed to be in-synch; that is, they both refer to the same directory. */
503 /* alloc may be NULL */
504 /* return value is CFArray of CFURLs */
505
506 CF_EXPORT SInt32 _CFGetFileProperties(CFAllocatorRef alloc, CFURLRef pathURL, Boolean *exists, SInt32 *posixMode, SInt64 *size, CFDateRef *modTime, SInt32 *ownerID, CFArrayRef *dirContents);
507 /* alloc may be NULL */
508 /* any of exists, posixMode, size, modTime, and dirContents can be NULL. Usually it is not a good idea to pass NULL for exists, since interpretting the other values sometimes requires that you know whether the file existed or not. Except for dirContents, it is pretty cheap to compute any of these things as loing as one of them must be computed. */
509
510
511 /* ==================== Simple path manipulation ==================== */
512 /* These functions all act on a UniChar buffers. */
513
514 CF_EXPORT Boolean _CFIsAbsolutePath(UniChar *unichars, CFIndex length);
515 CF_EXPORT Boolean _CFStripTrailingPathSlashes(UniChar *unichars, CFIndex *length);
516 CF_EXPORT Boolean _CFAppendPathComponent(UniChar *unichars, CFIndex *length, CFIndex maxLength, UniChar *component, CFIndex componentLength);
517 CF_EXPORT Boolean _CFAppendPathExtension(UniChar *unichars, CFIndex *length, CFIndex maxLength, UniChar *extension, CFIndex extensionLength);
518 CF_EXPORT Boolean _CFTransmutePathSlashes(UniChar *unichars, CFIndex *length, UniChar replSlash);
519 CF_EXPORT CFIndex _CFStartOfLastPathComponent(UniChar *unichars, CFIndex length);
520 CF_EXPORT CFIndex _CFLengthAfterDeletingLastPathComponent(UniChar *unichars, CFIndex length);
521 CF_EXPORT CFIndex _CFStartOfPathExtension(UniChar *unichars, CFIndex length);
522 CF_EXPORT CFIndex _CFLengthAfterDeletingPathExtension(UniChar *unichars, CFIndex length);
523
524 #define __CFMaxRuntimeTypes 65535
525
526 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS_SYNC
527
528 #include <objc/runtime.h>
529
530 extern int32_t __CFRuntimeClassTableSize;
531
532 extern uintptr_t *__CFRuntimeObjCClassTable;
533 CF_INLINE uintptr_t __CFISAForTypeID(CFTypeID typeID) {
534 return (typeID < __CFRuntimeClassTableSize) ? __CFRuntimeObjCClassTable[typeID] : 0;
535 }
536
537 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
538 extern id objc_msgSend(id, SEL, ...);
539 #elif DEPLOYMENT_TARGET_WINDOWS && defined(__cplusplus)
540 extern "C" __declspec(dllimport) id objc_msgSend(id, SEL, ...);
541 #elif DEPLOYMENT_TARGET_WINDOWS
542 extern __declspec(dllimport) id objc_msgSend(id, SEL, ...);
543 #endif
544
545 extern void * (*__CFSendObjCMsg)(const void *, SEL, ...);
546
547 CF_INLINE Boolean CF_IS_OBJC(CFTypeID typeID, const void *obj) {
548 return (typeID >= __CFRuntimeClassTableSize) || (((CFRuntimeBase *)obj)->_cfisa != __CFISAForTypeID(typeID) && ((CFRuntimeBase *)obj)->_cfisa > (uintptr_t)0xFFF);
549 }
550
551
552 #define CF_IS_OBJC(typeID, obj) (false)
553
554 #define CF_OBJC_VOIDCALL0(obj, sel)
555 #define CF_OBJC_VOIDCALL1(obj, sel, a1)
556 #define CF_OBJC_VOIDCALL2(obj, sel, a1, a2)
557
558 #define CF_OBJC_CALL0(rettype, retvar, obj, sel)
559 #define CF_OBJC_CALL1(rettype, retvar, obj, sel, a1)
560 #define CF_OBJC_CALL2(rettype, retvar, obj, sel, a1, a2)
561
562 #define CF_OBJC_FUNCDISPATCH0(typeID, rettype, obj, sel)
563 #define CF_OBJC_FUNCDISPATCH1(typeID, rettype, obj, sel, a1)
564 #define CF_OBJC_FUNCDISPATCH2(typeID, rettype, obj, sel, a1, a2)
565 #define CF_OBJC_FUNCDISPATCH3(typeID, rettype, obj, sel, a1, a2, a3)
566 #define CF_OBJC_FUNCDISPATCH4(typeID, rettype, obj, sel, a1, a2, a3, a4)
567 #define CF_OBJC_FUNCDISPATCH5(typeID, rettype, obj, sel, a1, a2, a3, a4, a5)
568
569 #endif
570
571 /* See comments in CFBase.c
572 */
573 #if DEPLOYMENT_TARGET_MACOSX && defined(__ppc__)
574 extern void __CF_FAULT_CALLBACK(void **ptr);
575 extern void *__CF_INVOKE_CALLBACK(void *, ...);
576 #define FAULT_CALLBACK(V) __CF_FAULT_CALLBACK(V)
577 #define INVOKE_CALLBACK1(P, A) (__CF_INVOKE_CALLBACK(P, A))
578 #define INVOKE_CALLBACK2(P, A, B) (__CF_INVOKE_CALLBACK(P, A, B))
579 #define INVOKE_CALLBACK3(P, A, B, C) (__CF_INVOKE_CALLBACK(P, A, B, C))
580 #define INVOKE_CALLBACK4(P, A, B, C, D) (__CF_INVOKE_CALLBACK(P, A, B, C, D))
581 #define INVOKE_CALLBACK5(P, A, B, C, D, E) (__CF_INVOKE_CALLBACK(P, A, B, C, D, E))
582 #define UNFAULT_CALLBACK(V) do { V = (void *)((uintptr_t)V & ~0x3); } while (0)
583 #else
584 #define FAULT_CALLBACK(V)
585 #define INVOKE_CALLBACK1(P, A) (P)(A)
586 #define INVOKE_CALLBACK2(P, A, B) (P)(A, B)
587 #define INVOKE_CALLBACK3(P, A, B, C) (P)(A, B, C)
588 #define INVOKE_CALLBACK4(P, A, B, C, D) (P)(A, B, C, D)
589 #define INVOKE_CALLBACK5(P, A, B, C, D, E) (P)(A, B, C, D, E)
590 #define UNFAULT_CALLBACK(V) do { } while (0)
591 #endif
592
593 /* For the support of functionality which needs CarbonCore or other frameworks */
594 // These macros define an upcall or weak "symbol-lookup" wrapper function.
595 // The parameters are:
596 // R : the return type of the function
597 // N : the name of the function (in the other library)
598 // P : the parenthesized parameter list of the function
599 // A : the parenthesized actual argument list to be passed
600 // opt: a fifth optional argument can be passed in which is the
601 // return value of the wrapper when the function cannot be
602 // found; should be of type R, & can be a function call
603 // The name of the resulting wrapper function is:
604 // __CFCarbonCore_N (where N is the second parameter)
605 // __CFNetwork_N (where N is the second parameter)
606 //
607 // Example:
608 // DEFINE_WEAK_CARBONCORE_FUNC(void, DisposeHandle, (Handle h), (h))
609 //
610
611 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
612
613 extern void *__CFLookupCFNetworkFunction(const char *name);
614
615 #define DEFINE_WEAK_CFNETWORK_FUNC(R, N, P, A, ...) \
616 static R __CFNetwork_ ## N P { \
617 static R (*dyfunc) P = (void *)(~(uintptr_t)0); \
618 if ((void *)(~(uintptr_t)0) == dyfunc) { \
619 dyfunc = __CFLookupCFNetworkFunction(#N); } \
620 if (dyfunc) { return dyfunc A ; } \
621 return __VA_ARGS__ ; \
622 }
623
624 #define DEFINE_WEAK_CFNETWORK_FUNC_FAIL(R, N, P, A, FAILACTION, ...) \
625 static R __CFNetwork_ ## N P { \
626 static R (*dyfunc) P = (void *)(~(uintptr_t)0); \
627 if ((void *)(~(uintptr_t)0) == dyfunc) { \
628 dyfunc = __CFLookupCFNetworkFunction(#N); } \
629 if (dyfunc) { return dyfunc A ; } \
630 FAILACTION ; \
631 return __VA_ARGS__ ; \
632 }
633
634 #else
635
636 #define DEFINE_WEAK_CFNETWORK_FUNC(R, N, P, A, ...)
637 #define DEFINE_WEAK_CFNETWORK_FUNC_FAIL(R, N, P, A, ...)
638
639 #endif
640
641
642 #if !defined(DEFINE_WEAK_CARBONCORE_FUNC)
643 #define DEFINE_WEAK_CARBONCORE_FUNC(R, N, P, A, ...)
644 #endif
645
646 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS
647 __private_extern__ CFComparisonResult _CFCompareStringsWithLocale(CFStringInlineBuffer *str1, CFRange str1Range, CFStringInlineBuffer *str2, CFRange str2Range, CFOptionFlags options, const void *compareLocale);
648 #endif
649
650
651 __private_extern__ CFArrayRef _CFBundleCopyUserLanguages(Boolean useBackstops);
652
653
654 #if DEPLOYMENT_TARGET_WINDOWS
655 __private_extern__ const wchar_t *_CFDLLPath(void);
656 __private_extern__ void __CFStringCleanup(void);
657 __private_extern__ void __CFSocketCleanup(void);
658 __private_extern__ void __CFUniCharCleanup(void);
659 __private_extern__ void __CFStreamCleanup(void);
660 #endif
661
662 /* !!! Avoid #importing objc.h; e.g. converting this to a .m file */
663 struct __objcFastEnumerationStateEquivalent {
664 unsigned long state;
665 unsigned long *itemsPtr;
666 unsigned long *mutationsPtr;
667 unsigned long extra[5];
668 };
669
670 unsigned long _CFStorageFastEnumeration(CFStorageRef storage, struct __objcFastEnumerationStateEquivalent *state, void *stackbuffer, unsigned long count);
671
672 CF_EXTERN_C_END
673
674 #endif /* ! __COREFOUNDATION_CFINTERNAL__ */
675