this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

More stuff building as fat, libsystem linking, the next step is to have dyld link

+248 -768
+1 -1
CMakeLists.txt
··· 19 19 # message(FATAL_ERROR "BITS is not specified (32/64)") 20 20 #endif (NOT BITS) 21 21 22 - SET(IGNORED_WARNINGS "-Wno-nullability-completeness") 22 + SET(IGNORED_WARNINGS "-Wno-nullability-completeness -Wno-deprecated-declarations") 23 23 24 24 if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang" AND NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS "3.9") 25 25 SET(IGNORED_WARNINGS "${IGNORED_WARNINGS} -Wno-expansion-to-defined")
-648
kernel-include/libkern/OSAtomic.h
··· 1 - /* 2 - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 - * 4 - * @APPLE_OSREFERENCE_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. The rights granted to you under the License 10 - * may not be used to create, or enable the creation or redistribution of, 11 - * unlawful or unlicensed copies of an Apple operating system, or to 12 - * circumvent, violate, or enable the circumvention or violation of, any 13 - * terms of an Apple operating system software license agreement. 14 - * 15 - * Please obtain a copy of the License at 16 - * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 - * 18 - * The Original Code and all software distributed under the License are 19 - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 - * Please see the License for the specific language governing rights and 24 - * limitations under the License. 25 - * 26 - * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 - */ 28 - /* 29 - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 30 - * 31 - * HISTORY 32 - * 33 - */ 34 - 35 - #ifndef _OS_OSATOMIC_H 36 - #define _OS_OSATOMIC_H 37 - 38 - #include <libkern/OSBase.h> 39 - 40 - #if defined(__cplusplus) 41 - extern "C" { 42 - #endif 43 - 44 - #ifdef XNU_KERNEL_PRIVATE 45 - /* 46 - * The macro SAFE_CAST_PTR() casts one type of pointer to another type, making sure 47 - * the data the pointer is referencing is the same size. If it is not, it will cause 48 - * a division by zero compiler warning. This is to work around "SInt32" being defined 49 - * as "long" on ILP32 and as "int" on LP64, which would require an explicit cast to 50 - * "SInt32*" when for instance passing an "int*" to OSAddAtomic() - which masks size 51 - * mismatches. 52 - * -- var is used, but sizeof does not evaluate the 53 - * argument, i.e. we're safe against "++" etc. in var -- 54 - */ 55 - #define __SAFE_CAST_PTR(type, var) (((type)(var))+(0/(sizeof(*var) == sizeof(*(type)0) ? 1 : 0))) 56 - #else 57 - #define __SAFE_CAST_PTR(type, var) ((type)(var)) 58 - #endif 59 - 60 - /*! 61 - * @header 62 - * 63 - * @abstract 64 - * This header declares the OSAtomic group of functions for atomic 65 - * reading and updating of values. 66 - */ 67 - 68 - #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) 69 - 70 - /*! 71 - * @function OSCompareAndSwap64 72 - * 73 - * @abstract 74 - * 64-bit compare and swap operation. 75 - * 76 - * @discussion 77 - * See OSCompareAndSwap. 78 - */ 79 - extern Boolean OSCompareAndSwap64( 80 - UInt64 oldValue, 81 - UInt64 newValue, 82 - volatile UInt64 * address); 83 - #define OSCompareAndSwap64(a, b, c) \ 84 - (OSCompareAndSwap64(a, b, __SAFE_CAST_PTR(volatile UInt64*,c))) 85 - 86 - #endif /* defined(__i386__) || defined(__x86_64__) */ 87 - 88 - /*! 89 - * @function OSAddAtomic64 90 - * 91 - * @abstract 92 - * 64-bit atomic add operation. 93 - * 94 - * @discussion 95 - * See OSAddAtomic. 96 - */ 97 - extern SInt64 OSAddAtomic64( 98 - SInt64 theAmount, 99 - volatile SInt64 * address); 100 - #define OSAddAtomic64(a, b) \ 101 - (OSAddAtomic64(a, __SAFE_CAST_PTR(volatile SInt64*,b))) 102 - 103 - /*! 104 - * @function OSIncrementAtomic64 105 - * 106 - * @abstract 107 - * 64-bit increment. 108 - * 109 - * @discussion 110 - * See OSIncrementAtomic. 111 - */ 112 - inline static SInt64 OSIncrementAtomic64(volatile SInt64 * address) 113 - { 114 - return OSAddAtomic64(1LL, address); 115 - } 116 - 117 - /*! 118 - * @function OSDecrementAtomic64 119 - * 120 - * @abstract 121 - * 64-bit decrement. 122 - * 123 - * @discussion 124 - * See OSDecrementAtomic. 125 - */ 126 - inline static SInt64 OSDecrementAtomic64(volatile SInt64 * address) 127 - { 128 - return OSAddAtomic64(-1LL, address); 129 - } 130 - 131 - #if XNU_KERNEL_PRIVATE 132 - /* Not to be included in headerdoc. 133 - * 134 - * @function OSAddAtomicLong 135 - * 136 - * @abstract 137 - * 32/64-bit atomic add operation, depending on sizeof(long). 138 - * 139 - * @discussion 140 - * See OSAddAtomic. 141 - */ 142 - extern long OSAddAtomicLong( 143 - long theAmount, 144 - volatile long * address); 145 - #define OSAddAtomicLong(a, b) \ 146 - (OSAddAtomicLong(a, __SAFE_CAST_PTR(volatile long*,b))) 147 - 148 - /* Not to be included in headerdoc. 149 - * 150 - * @function OSIncrementAtomicLong 151 - * 152 - * @abstract 153 - * 32/64-bit increment, depending on sizeof(long) 154 - * 155 - * @discussion 156 - * See OSIncrementAtomic. 157 - */ 158 - inline static long OSIncrementAtomicLong(volatile long * address) 159 - { 160 - return OSAddAtomicLong(1L, address); 161 - } 162 - 163 - /* Not to be included in headerdoc. 164 - * 165 - * @function OSDecrementAtomicLong 166 - * 167 - * @abstract 168 - * 32/64-bit decrement, depending on sizeof(long) 169 - *@discussion See OSDecrementAtomic. 170 - */ 171 - inline static long OSDecrementAtomicLong(volatile long * address) 172 - { 173 - return OSAddAtomicLong(-1L, address); 174 - } 175 - #endif /* XNU_KERNEL_PRIVATE */ 176 - 177 - /*! 178 - * @function OSCompareAndSwap 179 - * 180 - * @abstract 181 - * Compare and swap operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 182 - * 183 - * @discussion 184 - * The OSCompareAndSwap function compares the value at the specified address with oldVal. The value of newValue is written to the address only if oldValue and the value at the address are equal. OSCompareAndSwap returns true if newValue is written to the address; otherwise, it returns false. 185 - * 186 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 187 - * 188 - * @param oldValue The value to compare at address. 189 - * @param newValue The value to write to address if oldValue compares true. 190 - * @param address The 4-byte aligned address of the data to update atomically. 191 - * @result true if newValue was written to the address. 192 - */ 193 - extern Boolean OSCompareAndSwap( 194 - UInt32 oldValue, 195 - UInt32 newValue, 196 - volatile UInt32 * address); 197 - #define OSCompareAndSwap(a, b, c) \ 198 - (OSCompareAndSwap(a, b, __SAFE_CAST_PTR(volatile UInt32*,c))) 199 - 200 - /*! 201 - * @function OSCompareAndSwapPtr 202 - * 203 - * @abstract 204 - * Compare and swap operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 205 - * 206 - * @discussion 207 - * The OSCompareAndSwapPtr function compares the pointer-sized value at the specified address with oldVal. The value of newValue is written to the address only if oldValue and the value at the address are equal. OSCompareAndSwapPtr returns true if newValue is written to the address; otherwise, it returns false. 208 - * 209 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 210 - * @param oldValue The pointer value to compare at address. 211 - * @param newValue The pointer value to write to address if oldValue compares true. 212 - * @param address The pointer-size aligned address of the data to update atomically. 213 - * @result true if newValue was written to the address. 214 - */ 215 - extern Boolean OSCompareAndSwapPtr( 216 - void * oldValue, 217 - void * newValue, 218 - void * volatile * address); 219 - #define OSCompareAndSwapPtr(a, b, c) \ 220 - (OSCompareAndSwapPtr(a, b, __SAFE_CAST_PTR(void * volatile *,c))) 221 - 222 - /*! 223 - * @function OSAddAtomic 224 - * 225 - * @abstract 226 - * 32-bit add operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 227 - * 228 - * @discussion 229 - * The OSAddAtomic function adds the specified amount to the value at the specified address and returns the original value. 230 - * 231 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 232 - * @param amount The amount to add. 233 - * @param address The 4-byte aligned address of the value to update atomically. 234 - * @result The value before the addition 235 - */ 236 - extern SInt32 OSAddAtomic( 237 - SInt32 amount, 238 - volatile SInt32 * address); 239 - #define OSAddAtomic(a, b) \ 240 - (OSAddAtomic(a, __SAFE_CAST_PTR(volatile SInt32*,b))) 241 - 242 - /*! 243 - * @function OSAddAtomic16 244 - * 245 - * @abstract 246 - * 16-bit add operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 247 - * 248 - * @discussion 249 - * The OSAddAtomic16 function adds the specified amount to the value at the specified address and returns the original value. 250 - * 251 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 252 - * @param amount The amount to add. 253 - * @param address The 2-byte aligned address of the value to update atomically. 254 - * @result The value before the addition 255 - */ 256 - extern SInt16 OSAddAtomic16( 257 - SInt32 amount, 258 - volatile SInt16 * address); 259 - 260 - /*! 261 - * @function OSAddAtomic8 262 - * 263 - * @abstract 264 - * 8-bit add operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 265 - * 266 - * @discussion 267 - * The OSAddAtomic8 function adds the specified amount to the value at the specified address and returns the original value. 268 - * 269 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 270 - * @param amount The amount to add. 271 - * @param address The address of the value to update atomically. 272 - * @result The value before the addition. 273 - */ 274 - extern SInt8 OSAddAtomic8( 275 - SInt32 amount, 276 - volatile SInt8 * address); 277 - 278 - /*! 279 - * @function OSIncrementAtomic 280 - * 281 - * @abstract 282 - * 32-bit increment operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 283 - * 284 - * @discussion 285 - * The OSIncrementAtomic function increments the value at the specified address by one and returns the original value. 286 - * 287 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. 288 - * @param address The 4-byte aligned address of the value to update atomically. 289 - * @result The value before the increment. 290 - */ 291 - extern SInt32 OSIncrementAtomic(volatile SInt32 * address); 292 - #define OSIncrementAtomic(a) \ 293 - (OSIncrementAtomic(__SAFE_CAST_PTR(volatile SInt32*,a))) 294 - 295 - /*! 296 - * @function OSIncrementAtomic16 297 - * 298 - * @abstract 299 - * 16-bit increment operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 300 - * 301 - * @discussion 302 - * The OSIncrementAtomic16 function increments the value at the specified address by one and returns the original value. 303 - * 304 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 305 - * @param address The 2-byte aligned address of the value to update atomically. 306 - * @result The value before the increment. 307 - */ 308 - extern SInt16 OSIncrementAtomic16(volatile SInt16 * address); 309 - 310 - /*! 311 - * @function OSIncrementAtomic8 312 - * 313 - * @abstract 314 - * 8-bit increment operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 315 - * 316 - * @discussion 317 - * The OSIncrementAtomic8 function increments the value at the specified address by one and returns the original value. 318 - * 319 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 320 - * @param address The address of the value to update atomically. 321 - * @result The value before the increment. 322 - */ 323 - extern SInt8 OSIncrementAtomic8(volatile SInt8 * address); 324 - 325 - /*! 326 - * @function OSDecrementAtomic 327 - * 328 - * @abstract 329 - * 32-bit decrement operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 330 - * 331 - * @discussion 332 - * The OSDecrementAtomic function decrements the value at the specified address by one and returns the original value. 333 - * 334 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 335 - * @param address The 4-byte aligned address of the value to update atomically. 336 - * @result The value before the decrement. 337 - */ 338 - extern SInt32 OSDecrementAtomic(volatile SInt32 * address); 339 - #define OSDecrementAtomic(a) \ 340 - (OSDecrementAtomic(__SAFE_CAST_PTR(volatile SInt32*,a))) 341 - 342 - /*! 343 - * @function OSDecrementAtomic16 344 - * 345 - * @abstract 346 - * 16-bit decrement operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 347 - * 348 - * @discussion 349 - * The OSDecrementAtomic16 function decrements the value at the specified address by one and returns the original value. 350 - * 351 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 352 - * @param address The 2-byte aligned address of the value to update atomically. 353 - * @result The value before the decrement. 354 - */ 355 - extern SInt16 OSDecrementAtomic16(volatile SInt16 * address); 356 - 357 - /*! 358 - * @function OSDecrementAtomic8 359 - * 360 - * @abstract 361 - * 8-bit decrement operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 362 - * 363 - * @discussion 364 - * The OSDecrementAtomic8 function decrements the value at the specified address by one and returns the original value. 365 - * 366 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 367 - * @param address The address of the value to update atomically. 368 - * @result The value before the decrement. 369 - */ 370 - extern SInt8 OSDecrementAtomic8(volatile SInt8 * address); 371 - 372 - /*! 373 - * @function OSBitAndAtomic 374 - * 375 - * @abstract 376 - * 32-bit logical and operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 377 - * 378 - * @discussion 379 - * The OSBitAndAtomic function logically ands the bits of the specified mask into the value at the specified address and returns the original value. 380 - * 381 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 382 - * @param mask The mask to logically and with the value. 383 - * @param address The 4-byte aligned address of the value to update atomically. 384 - * @result The value before the bitwise operation 385 - */ 386 - extern UInt32 OSBitAndAtomic( 387 - UInt32 mask, 388 - volatile UInt32 * address); 389 - #define OSBitAndAtomic(a, b) \ 390 - (OSBitAndAtomic(a, __SAFE_CAST_PTR(volatile UInt32*,b))) 391 - 392 - /*! 393 - * @function OSBitAndAtomic16 394 - * 395 - * @abstract 396 - * 16-bit logical and operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 397 - * 398 - * @discussion 399 - * The OSBitAndAtomic16 function logically ands the bits of the specified mask into the value at the specified address and returns the original value. 400 - * 401 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 402 - * @param mask The mask to logically and with the value. 403 - * @param address The 2-byte aligned address of the value to update atomically. 404 - * @result The value before the bitwise operation. 405 - */ 406 - extern UInt16 OSBitAndAtomic16( 407 - UInt32 mask, 408 - volatile UInt16 * address); 409 - 410 - /*! 411 - * @function OSBitAndAtomic8 412 - * 413 - * @abstract 414 - * 8-bit logical and operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 415 - * 416 - * @discussion 417 - * The OSBitAndAtomic8 function logically ands the bits of the specified mask into the value at the specified address and returns the original value. 418 - * 419 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 420 - * @param mask The mask to logically and with the value. 421 - * @param address The address of the value to update atomically. 422 - * @result The value before the bitwise operation. 423 - */ 424 - extern UInt8 OSBitAndAtomic8( 425 - UInt32 mask, 426 - volatile UInt8 * address); 427 - 428 - /*! 429 - * @function OSBitOrAtomic 430 - * 431 - * @abstract 432 - * 32-bit logical or operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 433 - * 434 - * @discussion 435 - * The OSBitOrAtomic function logically ors the bits of the specified mask into the value at the specified address and returns the original value. 436 - * 437 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 438 - * @param mask The mask to logically or with the value. 439 - * @param address The 4-byte aligned address of the value to update atomically. 440 - * @result The value before the bitwise operation. 441 - */ 442 - extern UInt32 OSBitOrAtomic( 443 - UInt32 mask, 444 - volatile UInt32 * address); 445 - #define OSBitOrAtomic(a, b) \ 446 - (OSBitOrAtomic(a, __SAFE_CAST_PTR(volatile UInt32*,b))) 447 - 448 - /*! 449 - * @function OSBitOrAtomic16 450 - * 451 - * @abstract 452 - * 16-bit logical or operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 453 - * 454 - * @discussion 455 - * The OSBitOrAtomic16 function logically ors the bits of the specified mask into the value at the specified address and returns the original value. 456 - * 457 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 458 - * @param mask The mask to logically or with the value. 459 - * @param address The 2-byte aligned address of the value to update atomically. 460 - * @result The value before the bitwise operation. 461 - */ 462 - extern UInt16 OSBitOrAtomic16( 463 - UInt32 mask, 464 - volatile UInt16 * address); 465 - 466 - /*! 467 - * @function OSBitOrAtomic8 468 - * 469 - * @abstract 470 - * 8-bit logical or operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 471 - * 472 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 473 - * 474 - * @discussion 475 - * The OSBitOrAtomic8 function logically ors the bits of the specified mask into the value at the specified address and returns the original value. 476 - * @param mask The mask to logically or with the value. 477 - * @param address The address of the value to update atomically. 478 - * @result The value before the bitwise operation. 479 - */ 480 - extern UInt8 OSBitOrAtomic8( 481 - UInt32 mask, 482 - volatile UInt8 * address); 483 - 484 - /*! 485 - * @function OSBitXorAtomic 486 - * 487 - * @abstract 488 - * 32-bit logical xor operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 489 - * 490 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 491 - * 492 - * @discussion 493 - * The OSBitXorAtomic function logically xors the bits of the specified mask into the value at the specified address and returns the original value. 494 - * @param mask The mask to logically or with the value. 495 - * @param address The 4-byte aligned address of the value to update atomically. 496 - * @result The value before the bitwise operation. 497 - */ 498 - extern UInt32 OSBitXorAtomic( 499 - UInt32 mask, 500 - volatile UInt32 * address); 501 - #define OSBitXorAtomic(a, b) \ 502 - (OSBitXorAtomic(a, __SAFE_CAST_PTR(volatile UInt32*,b))) 503 - 504 - /*! 505 - * @function OSBitXorAtomic16 506 - * 507 - * @abstract 508 - * 16-bit logical xor operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 509 - * 510 - * @discussion 511 - * The OSBitXorAtomic16 function logically xors the bits of the specified mask into the value at the specified address and returns the original value. 512 - * 513 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 514 - * @param mask The mask to logically or with the value. 515 - * @param address The 2-byte aligned address of the value to update atomically. 516 - * @result The value before the bitwise operation. 517 - */ 518 - extern UInt16 OSBitXorAtomic16( 519 - UInt32 mask, 520 - volatile UInt16 * address); 521 - 522 - /*! 523 - * @function OSBitXorAtomic8 524 - * 525 - * @abstract 526 - * 8-bit logical xor operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 527 - * 528 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 529 - * 530 - * @discussion 531 - * The OSBitXorAtomic8 function logically xors the bits of the specified mask into the value at the specified address and returns the original value. 532 - * @param mask The mask to logically or with the value. 533 - * @param address The address of the value to update atomically. 534 - * @result The value before the bitwise operation. 535 - */ 536 - extern UInt8 OSBitXorAtomic8( 537 - UInt32 mask, 538 - volatile UInt8 * address); 539 - 540 - /*! 541 - * @function OSTestAndSet 542 - * 543 - * @abstract 544 - * Bit test and set operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 545 - * 546 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 547 - * 548 - * @discussion 549 - * The OSTestAndSet function sets a single bit in a byte at a specified address. It returns true if the bit was already set, false otherwise. 550 - * @param bit The bit number in the range 0 through 7. 551 - * @param startAddress The address of the byte to update atomically. 552 - * @result true if the bit was already set, false otherwise. 553 - */ 554 - extern Boolean OSTestAndSet( 555 - UInt32 bit, 556 - volatile UInt8 * startAddress); 557 - 558 - /*! 559 - * @function OSTestAndClear 560 - * 561 - * @abstract 562 - * Bit test and clear operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 563 - * 564 - * @discussion 565 - * The OSTestAndClear function clears a single bit in a byte at a specified address. It returns true if the bit was already clear, false otherwise. 566 - * 567 - * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures. 568 - * @param bit The bit number in the range 0 through 7. 569 - * @param startAddress The address of the byte to update atomically. 570 - * @result true if the bit was already clear, false otherwise. 571 - */ 572 - extern Boolean OSTestAndClear( 573 - UInt32 bit, 574 - volatile UInt8 * startAddress); 575 - 576 - /*! 577 - * @defined OS_SPINLOCK_INIT 578 - * 579 - * @abstract 580 - * The default value for an OSSpinLock. 581 - * 582 - * @discussion 583 - * The convention is that unlocked is zero, locked is nonzero. 584 - */ 585 - #define OS_SPINLOCK_INIT 0 586 - 587 - /*! 588 - * @typedef OSSpinLock 589 - * 590 - * @abstract 591 - * Data type for a spinlock. 592 - * 593 - * @discussion 594 - * You should always initialize a spinlock to OS_SPINLOCK_INIT before using it. 595 - */ 596 - typedef SInt32 OSSpinLock; 597 - 598 - #ifdef PRIVATE 599 - /*! 600 - * @function OSSpinLockTry 601 - * 602 - * @abstract 603 - * Locks a spinlock if it would not block. 604 - * 605 - * @discussion 606 - * Multiprocessor locks used within the shared memory area between the kernel and event system. These must work in both user and kernel mode. 607 - * 608 - * @result 609 - * Returns false if the lock was already held by another thread, true if it took the lock successfully. 610 - */ 611 - extern Boolean OSSpinLockTry(volatile OSSpinLock * lock); 612 - 613 - /*! 614 - * @function OSSpinLockUnlock 615 - * 616 - * @abstract 617 - * Unlocks a spinlock. 618 - * 619 - * @discussion 620 - * Unlocks a spinlock. 621 - */ 622 - extern void OSSpinLockUnlock(volatile OSSpinLock * lock); 623 - #endif /* PRIVATE */ 624 - 625 - /*! 626 - * @function OSSynchronizeIO 627 - * 628 - * @abstract 629 - * The OSSynchronizeIO routine ensures orderly load and store operations to noncached memory mapped I/O devices. 630 - * 631 - * @discussion 632 - * The OSSynchronizeIO routine ensures orderly load and store operations to noncached memory mapped I/O devices. It executes the eieio instruction on PowerPC processors. 633 - */ 634 - static __inline__ void OSSynchronizeIO(void) 635 - { 636 - } 637 - #if defined(XNU_KERNEL_PRIVATE) 638 - #if defined(__i386__) || defined(__x86_64__) 639 - static inline void OSMemoryBarrier(void) { 640 - __asm__ volatile("mfence" ::: "memory"); 641 - } 642 - #endif 643 - #endif /*XNU_KERNEL_PRIVATE */ 644 - #if defined(__cplusplus) 645 - } 646 - #endif 647 - 648 - #endif /* ! _OS_OSATOMIC_H */
+5 -1
src/CMakeLists.txt
··· 47 47 48 48 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/libc/include") 49 49 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/libm/Source") 50 + include_directories("${CMAKE_CURRENT_SOURCE_DIR}/kernel/libsyscall/wrappers") 50 51 include_directories("${DARLING_TOP_DIRECTORY}/platform-include") 51 52 include_directories("${DARLING_TOP_DIRECTORY}/platform-include/pthread") 52 53 include_directories("${DARLING_TOP_DIRECTORY}/kernel-include") 53 54 include_directories("${DARLING_TOP_DIRECTORY}/compiler-include") 54 55 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/duct/include") 55 56 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/external/libplatform/include") 57 + 58 + include_directories("${CMAKE_CURRENT_SOURCE_DIR}/libc/derived") 59 + add_subdirectory(external/libkqueue) 60 + 56 61 57 62 add_subdirectory(external/libplatform) 58 63 add_subdirectory(external/libpthread) ··· 83 88 add_subdirectory(libffi) 84 89 add_subdirectory(dyld-apple) 85 90 #add_subdirectory(external/objc4/runtime) 86 - add_subdirectory(external/libkqueue) 87 91 add_subdirectory(external/libdispatch) 88 92 add_subdirectory(external/zlib) 89 93 add_subdirectory(external/bzip2)
+3 -1
src/CommonCrypto/CMakeLists.txt
··· 8 8 9 9 10 10 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -D__DARWIN_UNIX03 -fPIC -fblocks -w") 11 - add_definitions(-D_APPLE_COMMON_CRYPTO_ -DLTC_SHA224 -DLTC_SHA384) 11 + add_definitions(-D_APPLE_COMMON_CRYPTO_ -DLTC_SHA224 -DLTC_SHA384 -DSHA256_USE_ASSEMBLY -DPRIVATE) 12 12 13 13 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Source/API) 14 14 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Source/libtomcrypt/src/headers) ··· 39 39 Source/Digest/sha1-x86_64.S 40 40 Source/Digest/sha2.c 41 41 Source/Digest/sha256.S 42 + Source/Digest/sha256_nossse3.S 42 43 #Source/Digest/sha1edpBigEndian.S 43 44 44 45 #Source/RC2/ccRC2.c ··· 91 92 add_darling_library(CommonCrypto SHARED ${cc_SRCS}) 92 93 target_link_libraries(CommonCrypto system_c system_m system_dyld system_malloc) 93 94 set_target_properties(CommonCrypto PROPERTIES OUTPUT_NAME "commonCrypto") 95 + make_fat(CommonCrypto) 94 96 95 97 install(TARGETS CommonCrypto DESTINATION libexec/darling/usr/lib)
+6 -10
src/CommonCrypto/Source/Digest/sha1-586.S
··· 6 6 7 7 .file "sha1-586.s" 8 8 .text 9 - .globl sha1_block_asm_data_order 10 - .type sha1_block_asm_data_order,@function 11 - .align 16 12 - sha1_block_asm_data_order: 9 + .globl _sha1_block_asm_data_order 10 + .align 4 11 + _sha1_block_asm_data_order: 13 12 movl 12(%esp), %ecx 14 13 pushl %esi 15 14 sall $6, %ecx ··· 1534 1533 popl %esi 1535 1534 ret 1536 1535 .L_sha1_block_asm_data_order_end: 1537 - .size sha1_block_asm_data_order,.L_sha1_block_asm_data_order_end-sha1_block_asm_data_order 1538 1536 .ident "sha1_block_asm_data_order" 1539 1537 .text 1540 - .globl sha1_block_asm_host_order 1541 - .type sha1_block_asm_host_order,@function 1542 - .align 16 1543 - sha1_block_asm_host_order: 1538 + .globl _sha1_block_asm_host_order 1539 + .align 4 1540 + _sha1_block_asm_host_order: 1544 1541 movl 12(%esp), %ecx 1545 1542 pushl %esi 1546 1543 sall $6, %ecx ··· 1590 1587 movl %ecx, 60(%esp) 1591 1588 jmp .L001shortcut 1592 1589 .L_sha1_block_asm_host_order_end: 1593 - .size sha1_block_asm_host_order,.L_sha1_block_asm_host_order_end-sha1_block_asm_host_order 1594 1590 .ident "sha1_block_asm_host_order" 1595 1591 1596 1592 #endif
+6 -4
src/CommonCrypto/Source/Digest/sha256.S
··· 296 296 // 4 32-bit K256 words in xmm5 297 297 #if defined (__x86_64__) 298 298 movdqu (K), %xmm5 299 + addq $$16, K // K points to next K256 word for next iteration 299 300 #else 300 301 mov K, t 301 302 movdqu (t), %xmm5 303 + addl $$16, K // K points to next K256 word for next iteration 302 304 #endif 303 - add $$16, K // K points to next K256 word for next iteration 304 305 movdqa $1, %xmm4 // W7:W4 305 306 palignr $$4, $0, %xmm4 // W4:W1 306 307 sigma0 %xmm4 // sigma0(W4:W1) ··· 395 396 add $8, ctx // now ctx = %rdi 396 397 lea 32(ctx), data // data points to ctx->wbuf 397 398 #else 398 - add $8, ctx_addr // now ctx points to ctx->hashes 399 + addl $8, ctx_addr // now ctx points to ctx->hashes 399 400 mov ctx_addr, t 400 401 add $32, t 401 402 mov t, data_addr // data points to ctx->wbuf ··· 436 437 movdqu 1*16(t), W1 437 438 movdqu 2*16(t), W2 438 439 movdqu 3*16(t), W3 439 - add $64, data_addr 440 + addl $64, data_addr 440 441 #endif 441 442 442 443 // compute WK[0:15] and save in stack ··· 445 446 movdqu 1*16(K), %xmm5 446 447 movdqu 2*16(K), %xmm6 447 448 movdqu 3*16(K), %xmm7 449 + addq $64, K 448 450 #else 449 451 mov K, t 450 452 movdqu 0*16(t), %xmm4 451 453 movdqu 1*16(t), %xmm5 452 454 movdqu 2*16(t), %xmm6 453 455 movdqu 3*16(t), %xmm7 456 + addl $64, K 454 457 #endif 455 - add $64, K 456 458 paddd %xmm0, %xmm4 457 459 paddd %xmm1, %xmm5 458 460 paddd %xmm2, %xmm6
+6 -4
src/CommonCrypto/Source/Digest/sha256_nossse3.S
··· 298 298 // 4 32-bit K256 words in xmm5 299 299 #if defined (__x86_64__) 300 300 movdqu (K), %xmm5 301 + addq $$16, K // K points to next K256 word for next iteration 301 302 #else 302 303 mov K, t 303 304 movdqu (t), %xmm5 305 + addl $$16, K // K points to next K256 word for next iteration 304 306 #endif 305 - add $$16, K // K points to next K256 word for next iteration 306 307 movdqa $1, %xmm4 // W7:W4 307 308 #if 0 308 309 palignr $$4, $0, %xmm4 // W4:W1 ··· 395 396 add $8, ctx // now ctx = %rdi 396 397 lea 32(ctx), data // data points to ctx->wbuf 397 398 #else 398 - add $8, ctx_addr // now ctx points to ctx->hashes 399 + addl $8, ctx_addr // now ctx points to ctx->hashes 399 400 mov ctx_addr, t 400 401 add $32, t 401 402 mov t, data_addr // data points to ctx->wbuf ··· 438 439 movdqu 1*16(t), W1 439 440 movdqu 2*16(t), W2 440 441 movdqu 3*16(t), W3 441 - add $64, data_addr 442 + addl $64, data_addr 442 443 #endif 443 444 444 445 // compute WK[0:15] and save in stack ··· 447 448 movdqu 1*16(K), %xmm5 448 449 movdqu 2*16(K), %xmm6 449 450 movdqu 3*16(K), %xmm7 451 + addq $64, K 450 452 #else 451 453 mov K, t 452 454 movdqu 0*16(t), %xmm4 453 455 movdqu 1*16(t), %xmm5 454 456 movdqu 2*16(t), %xmm6 455 457 movdqu 3*16(t), %xmm7 458 + addl $64, K 456 459 #endif 457 - add $64, K 458 460 paddd %xmm0, %xmm4 459 461 paddd %xmm1, %xmm5 460 462 paddd %xmm2, %xmm6
+1
src/CommonCrypto/Source/libtomcrypt/src/hashes/sha2/sha256.c
··· 9 9 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 10 */ 11 11 #include "tomcrypt.h" 12 + #include <i386/cpu_capabilities.h> 12 13 13 14 /** 14 15 @file sha256.c
+2 -1
src/dyld-apple/CMakeLists.txt
··· 24 24 include_directories(${CMAKE_SOURCE_DIR}/src/libc/locale/FreeBSD) 25 25 include_directories(${CMAKE_SOURCE_DIR}/src/libc/stdtime/FreeBSD) 26 26 include_directories(${CMAKE_SOURCE_DIR}/src/libmalloc/include) 27 + include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall/wrappers/libproc) 27 28 include_directories(${CMAKE_SOURCE_DIR}/src/kernel/emulation/linux/misc) 28 29 include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/sandbox) 29 30 include_directories(${CMAKE_SOURCE_DIR}/src/external/libcxx/include) ··· 73 74 use_ld64(system_loader) 74 75 set_target_properties(system_loader PROPERTIES OUTPUT_NAME "dyld") 75 76 set_property(TARGET system_loader APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-dylinker -Wl,-dead_strip -nostdlib -Wl,-e,__dyld_start") 76 - target_link_libraries(system_loader libc_static system_blocks_static unwind_static system_kernel_static system_m_static cxxabi_static keymgr_static compiler_rt_static system_duct_static) 77 + target_link_libraries(system_loader libc_static system_blocks_static unwind_static system_kernel_static system_m_static cxxabi_static keymgr_static compiler_rt_static32 compiler_rt_static64 system_duct_static) 77 78 78 79 make_fat(system_dyld) 79 80
+1 -7
src/kernel/libsyscall/CMakeLists.txt
··· 4 4 5 5 enable_language(C ASM) 6 6 7 - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -nostdinc") 7 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -nostdinc -include ${CMAKE_CURRENT_SOURCE_DIR}/nolegacy.h") 8 8 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/wrappers") 9 9 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/mach") 10 10 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../iokit") ··· 19 19 add_definitions(-DPRIVATE=1 -D__DARWIN_C_LEVEL=20150101) 20 20 add_definitions('-D__XNU_PRIVATE_EXTERN=') 21 21 #add_definitions(-DKERNEL) 22 - 23 - if (NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686") 24 - add_definitions(-DNO_SYSCALL_LEGACY) 25 - endif (NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686") 26 - 27 - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,--version-script=${DARLING_TOP_DIRECTORY}/darwin.map") 28 22 29 23 set(MIG_USER_HEADER_SUFFIX "_internal.h") 30 24 mig(mach/exc.defs)
+5
src/kernel/libsyscall/bsdsyscalls/___ptrace.S
··· 53 53 #else 54 54 #error Unsupported architecture 55 55 #endif 56 + 57 + #if defined(__x86_64__) || defined(__i386__) 58 + .globl _ptrace 59 + .set _ptrace, ___ptrace 60 + #endif
+4
src/kernel/libsyscall/nolegacy.h
··· 1 + #ifndef __i386__ 2 + # define NO_SYSCALL_LEGACY 3 + #endif 4 +
+13
src/libc/include/ctype.h
··· 63 63 * @(#)ctype.h 8.4 (Berkeley) 1/21/94 64 64 */ 65 65 66 + #ifdef BUILDING_LIBC 66 67 //Begin-Libc 67 68 #include "xlocale_private.h" 68 69 //End-Libc 70 + #endif 71 + // 69 72 #ifndef _CTYPE_H_ 70 73 #define _CTYPE_H_ 71 74 ··· 117 120 #define _SW3 _CTYPE_SW3 /* 3 width character */ 118 121 #endif /* _NONSTD_SOURCE */ 119 122 123 + #ifdef BUILDING_LIBC 120 124 //Begin-Libc 121 125 /* 122 126 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us ··· 132 136 #endif /* !_EXTERNALIZE_CTYPE_INLINES_ */ 133 137 //End-Libc 134 138 139 + #else // BUILDING_LIBC 140 + #define __DARWIN_CTYPE_inline __header_inline 141 + #endif 142 + 143 + #ifdef BUILDING_LIBC 135 144 //Begin-Libc 136 145 /* 137 146 * _EXTERNALIZE_CTYPE_INLINES_TOP_ is defined in locale/isctype.c to tell us ··· 146 155 //Begin-Libc 147 156 #endif /* _EXTERNALIZE_CTYPE_INLINES_TOP_ */ 148 157 //End-Libc 158 + 159 + #else // BUILDING_LIBC 160 + #define __DARWIN_CTYPE_TOP_inline __header_inline 161 + #endif 149 162 150 163 /* 151 164 * Use inline functions if we are allowed to and the compiler supports them.
+2
src/libc/include/stdlib.h
··· 124 124 #define MB_CUR_MAX_L(x) (___mb_cur_max_l(x)) 125 125 #endif 126 126 //Begin-Libc 127 + #ifdef BUILDING_LIBC 127 128 #include "libc_private.h" 128 129 /* f must be a literal string */ 129 130 #define LIBC_ABORT(f,...) abort_report_np("%s:%s:%u: " f, __FILE__, __func__, __LINE__, ## __VA_ARGS__) 131 + #endif 130 132 //End-Libc 131 133 132 134 __BEGIN_DECLS
+1
src/libffi/CMakeLists.txt
··· 31 31 set(DYLIB_INSTALL_NAME "/usr/lib/libffi.dylib") 32 32 add_darling_library(ffi SHARED ${ffi_SRCS}) 33 33 target_link_libraries(ffi system) 34 + make_fat(ffi) 34 35 35 36 install(TARGETS ffi DESTINATION libexec/darling/usr/lib)
+1
src/libiconv/CMakeLists.txt
··· 53 53 54 54 set(DYLIB_INSTALL_NAME "/usr/lib/libiconv.2.dylib") 55 55 add_darling_library(iconv SHARED ${iconv_SRCS}) 56 + make_fat(iconv) 56 57 target_link_libraries(iconv system) 57 58 set_target_properties(iconv PROPERTIES OUTPUT_NAME "iconv.2") 58 59 InstallSymlink("libiconv.2.dylib" "${CMAKE_INSTALL_PREFIX}/libexec/darling/usr/lib/libiconv.dylib")
+1
src/libstdcxx/CMakeLists.txt
··· 90 90 91 91 set(DYLIB_INSTALL_NAME "/usr/lib/libstdc++.6.dylib") 92 92 add_darling_library(stdcxx SHARED ${libstdcxx_sources}) 93 + make_fat(stdcxx) 93 94 target_link_libraries(stdcxx PRIVATE system cxxabi_shared) 94 95 set_target_properties(stdcxx PROPERTIES OUTPUT_NAME "stdc++.6") 95 96
+7 -4
src/libsystem/CMakeLists.txt
··· 10 10 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -ggdb") 11 11 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,-bind_at_load") 12 12 13 - include_directories(${DARLING_TOP_DIRECTORY}/src/libc/fbsdcompat) 14 - include_directories(${DARLING_TOP_DIRECTORY}/src/libc/darwin) 15 - include_directories(${DARLING_TOP_DIRECTORY}/src/kernel/libsyscall/wrappers) 13 + include_directories(${CMAKE_SOURCE_DIR}/src/libc/fbsdcompat) 14 + include_directories(${CMAKE_SOURCE_DIR}/src/libc/darwin) 15 + include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall/wrappers) 16 + include_directories(${CMAKE_SOURCE_DIR}/src/external/libpthread/private) 17 + include_directories(${CMAKE_SOURCE_DIR}/src/kernel/libsyscall) 18 + include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/dyld-apple/include) 16 19 17 20 add_definitions(-DTARGET_OS_MAC=1) 18 - add_definitions(-DHAVE_STDINT_H=1) 21 + add_definitions(-DHAVE_STDINT_H=1 -DHAVE_SYSTEM_CORESERVICES) 19 22 add_definitions(-D__APPLE__ -D__DYNAMIC__) 20 23 21 24 # Hide warnings
+155 -77
src/libsystem/init.c
··· 1 - // Modified by Lubos Dolezel to support older (10.8) libc and newer libsystem_kernel 2 1 /* 3 - * Copyright (c) 2007, 2008, 2011 Apple Inc. All rights reserved. 2 + * Copyright (c) 2007, 2008, 2011-2013 Apple Inc. All rights reserved. 4 3 * 5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 6 5 * ··· 27 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 28 27 */ 29 28 30 - #include <TargetConditionals.h> // for TARGET_OS_EMBEDDED 29 + #include <TargetConditionals.h> // for TARGET_OS_* 31 30 32 - #include <_libkernel_init.h> 31 + #include <stddef.h> 32 + #include <stdlib.h> 33 + #include <libc_private.h> 34 + #include <pthread.h> 35 + #include <pthread/private.h> 33 36 #include <dlfcn.h> 34 37 #include <errno.h> 35 - #include <stdlib.h> 38 + #include <_libkernel_init.h> // Must be after voucher_private.h 36 39 37 - struct ProgramVars; /* forward reference */ 40 + #include <mach-o/dyld_priv.h> 38 41 39 42 // system library initialisers 40 - extern void bootstrap_init(void); // from liblaunch.dylib 41 - extern void mach_init(void); // from libsystem_mach.dylib 42 - extern void pthread_init(void); // from libc.a 43 - extern void __libc_init(const struct ProgramVars *vars, void (*atfork_prepare)(void), void (*atfork_parent)(void), void (*atfork_child)(void), const char *apple[]); // from libc.a 44 - extern void __malloc_init(const char* apple[]); // from libmalloc 45 - extern void __keymgr_initializer(void); // from libkeymgr.a 46 - extern void _dyld_initializer(void); // from libdyld.a 47 - extern void libdispatch_init(void); // from libdispatch.a 48 - extern void _libxpc_initializer(void); // from libxpc 49 - extern void __objc_initialize(void); 50 - extern void _darling_initialize_commpage(void); // in duct, should go away 43 + extern void mach_init(void); // from libsystem_kernel.dylib 44 + extern void __libplatform_init(void *future_use, const char *envp[], const char *apple[], const struct ProgramVars *vars); 45 + extern void __pthread_init(const struct _libpthread_functions *libpthread_funcs, const char *envp[], const char *apple[], const struct ProgramVars *vars); // from libsystem_pthread.dylib 46 + extern void __malloc_init(const char *apple[]); // from libsystem_malloc.dylib 47 + extern void __keymgr_initializer(void); // from libkeymgr.dylib 48 + extern void _dyld_initializer(void); // from libdyld.dylib 49 + extern void libdispatch_init(void); // from libdispatch.dylib 50 + extern void _libxpc_initializer(void); // from libxpc.dylib 51 + extern void _libsecinit_initializer(void); // from libsecinit.dylib 52 + extern void _libtrace_init(void); // from libsystem_trace.dylib 53 + 51 54 52 55 // signal malloc stack logging that initialisation has finished 53 56 extern void __stack_logging_early_finished(void); // form libsystem_c.dylib 54 57 58 + // clear qos tsd (from pthread) 59 + extern void _pthread_clear_qos_tsd(mach_port_t) __attribute__((weak_import)); 60 + 55 61 // system library atfork handlers 56 - extern void _cthread_fork_prepare(void); 57 - extern void _cthread_fork_parent(void); 58 - extern void _cthread_fork_child(void); 59 - extern void _cthread_fork_child_postinit(void); 62 + extern void _pthread_fork_prepare(void); 63 + extern void _pthread_fork_parent(void); 64 + extern void _pthread_fork_child(void); 65 + extern void _pthread_fork_child_postinit(void); 66 + extern void _pthread_exit_if_canceled(int); 60 67 61 - extern void _mig_fork_child(void); 68 + extern void dispatch_atfork_prepare(void); 69 + extern void dispatch_atfork_parent(void); 70 + extern void dispatch_atfork_child(void); 71 + 72 + extern void _libtrace_fork_child(void); 73 + 74 + extern void _malloc_fork_prepare(void); 75 + extern void _malloc_fork_parent(void); 76 + extern void _malloc_fork_child(void); 77 + 62 78 extern void _mach_fork_child(void); 63 - extern void _cproc_fork_child(void); 64 - extern void _libc_fork_child(void); 65 79 extern void _notify_fork_child(void); 66 80 extern void _dyld_fork_child(void); 67 81 extern void xpc_atfork_prepare(void); 68 82 extern void xpc_atfork_parent(void); 69 83 extern void xpc_atfork_child(void); 84 + extern void _libSC_info_fork_prepare(void); 85 + extern void _libSC_info_fork_parent(void); 86 + extern void _libSC_info_fork_child(void); 87 + extern void _asl_fork_child(void); 88 + 89 + #if defined(HAVE_SYSTEM_CORESERVICES) 90 + // libsystem_coreservices.dylib 91 + extern void _libcoreservices_fork_child(void); 92 + extern char *_dirhelper(int, char *, size_t); 93 + #endif 94 + 95 + #if TARGET_OS_EMBEDDED && !TARGET_OS_WATCH && !__LP64__ 96 + extern void _vminterpose_init(void); 97 + #endif 70 98 71 99 // advance decls for below; 72 100 void libSystem_atfork_prepare(void); 73 101 void libSystem_atfork_parent(void); 74 102 void libSystem_atfork_child(void); 75 103 76 - // from mig_support.c in libc 77 - mach_port_t _mig_get_reply_port(void); 78 - void _mig_set_reply_port(mach_port_t); 79 - 80 - void cthread_set_errno_self(int); 81 - void* pthread_self(void); 82 - 83 - extern void _dyld_func_lookup(const char* name, void** p); 84 - 85 - static void _pthread_exit_if_canceled(int err) { if (pthread_self()) _pthread_testcancel(pthread_self(), 1); } 86 - 87 - struct ProgramVars 104 + // libsyscall_initializer() initializes all of libSystem.dylib 105 + // <rdar://problem/4892197> 106 + __attribute__((constructor)) 107 + static void 108 + libSystem_initializer(int argc, 109 + const char* argv[], 110 + const char* envp[], 111 + const char* apple[], 112 + const struct ProgramVars* vars) 88 113 { 89 - const void* mh; 90 - int* NXArgcPtr; 91 - const char*** NXArgvPtr; 92 - const char*** environPtr; 93 - const char** __prognamePtr; 94 - }; 95 - 96 - 97 - /* 98 - * libsyscall_initializer() initializes all of libSystem.dylib <rdar://problem/4892197> 99 - */ 100 - static __attribute__((constructor)) 101 - void libSystem_initializer(int argc, const char* argv[], const char* envp[] , const char* apple[], const struct ProgramVars* vars) 102 - { 103 - static const struct _libkernel_functions libkernel_funcs = { 104 - .version = 1, 114 + static const struct _libkernel_functions libkernel_funcs = { 115 + .version = 3, 116 + // V1 functions 105 117 .dlsym = dlsym, 106 118 .malloc = malloc, 107 119 .free = free, 108 120 .realloc = realloc, 109 121 ._pthread_exit_if_canceled = _pthread_exit_if_canceled, 122 + // V2 functions (removed) 123 + // V3 functions 124 + .pthread_clear_qos_tsd = _pthread_clear_qos_tsd, 110 125 .dyld_func_lookup = _dyld_func_lookup, 111 126 }; 112 127 113 - _darling_initialize_commpage(); 114 - __libkernel_init(&libkernel_funcs, *envp, apple, &vars); 128 + static const struct _libpthread_functions libpthread_funcs = { 129 + .version = 2, 130 + .exit = exit, 131 + .malloc = malloc, 132 + .free = free, 133 + }; 134 + 135 + static const struct _libc_functions libc_funcs = { 136 + .version = 1, 137 + .atfork_prepare = libSystem_atfork_prepare, 138 + .atfork_parent = libSystem_atfork_parent, 139 + .atfork_child = libSystem_atfork_child, 140 + #if defined(HAVE_SYSTEM_CORESERVICES) 141 + .dirhelper = _dirhelper, 142 + #endif 143 + }; 115 144 116 - // bootstrap_init(); // currently aborts 117 - mach_init(); 118 - pthread_init(); 119 - __libc_init(vars, libSystem_atfork_prepare, libSystem_atfork_parent, libSystem_atfork_child, apple); 145 + __libkernel_init(&libkernel_funcs, envp, apple, vars); 146 + 147 + __libplatform_init(NULL, envp, apple, vars); 148 + 149 + __pthread_init(&libpthread_funcs, envp, apple, vars); 150 + 151 + _libc_initializer(&libc_funcs, envp, apple, vars); 152 + 153 + // TODO: Move __malloc_init before __libc_init after breaking malloc's upward link to Libc 120 154 __malloc_init(apple); 155 + 156 + #if !TARGET_OS_SIMULATOR && !TARGET_OS_TV && !TARGET_OS_WATCH 157 + /* <rdar://problem/9664631> */ 121 158 __keymgr_initializer(); 159 + #endif 160 + 122 161 _dyld_initializer(); 162 + 123 163 libdispatch_init(); 124 - _libxpc_initializer(); 164 + // _libxpc_initializer(); // Darling: not yet 165 + 166 + #if !(TARGET_OS_EMBEDDED || TARGET_OS_SIMULATOR) 167 + // _libsecinit_initializer(); // Darling: not yet 168 + #endif 125 169 126 170 __stack_logging_early_finished(); 127 171 172 + #if TARGET_OS_EMBEDDED && !TARGET_OS_WATCH && !__LP64__ 173 + // _vminterpose_init(); // Darling: not yet 174 + #endif 175 + 176 + // _libtrace_init(); // must be initialized after dispatch // Darling: not yet 177 + 178 + #if !TARGET_OS_IPHONE 179 + /* <rdar://problem/22139800> - Preserve the old behavior of apple[] for 180 + * programs that haven't linked against newer SDK. 181 + */ 182 + #define APPLE0_PREFIX "executable_path=" 183 + if (dyld_get_program_sdk_version() < DYLD_MACOSX_VERSION_10_11){ 184 + if (strncmp(apple[0], APPLE0_PREFIX, strlen(APPLE0_PREFIX)) == 0){ 185 + apple[0] = apple[0] + strlen(APPLE0_PREFIX); 186 + } 187 + } 188 + #endif 189 + 128 190 /* <rdar://problem/11588042> 129 191 * C99 standard has the following in section 7.5(3): 130 192 * "The value of errno is zero at program startup, but is never set 131 193 * to zero by any library function." 132 194 */ 133 195 errno = 0; 134 - // __objc_initialize(); // TODO: temporarily commented out 135 196 } 136 197 137 198 /* 138 - * libSystem_atfork_{prepare,parent,child}() are called by libc when we fork, then we deal with running fork handlers 139 - * for everyone else. 199 + * libSystem_atfork_{prepare,parent,child}() are called by libc during fork(2). 200 + * They call the corresponding atfork handlers for other libsystem components. 140 201 */ 141 - void libSystem_atfork_prepare(void) 202 + void 203 + libSystem_atfork_prepare(void) 142 204 { 143 - xpc_atfork_prepare(); 144 - _cthread_fork_prepare(); 205 + // _libSC_info_fork_prepare(); // Darling: not yet 206 + // xpc_atfork_prepare(); // Darling: not yet 207 + dispatch_atfork_prepare(); 208 + _pthread_fork_prepare(); 209 + _malloc_fork_prepare(); 145 210 } 146 211 147 - void libSystem_atfork_parent(void) 212 + void 213 + libSystem_atfork_parent(void) 148 214 { 149 - _cthread_fork_parent(); 150 - xpc_atfork_parent(); 215 + _malloc_fork_parent(); 216 + _pthread_fork_parent(); 217 + dispatch_atfork_parent(); 218 + // xpc_atfork_parent(); // Darling: not yet 219 + // _libSC_info_fork_parent(); // Darling: not yet 151 220 } 152 221 153 - void libSystem_atfork_child(void) 222 + void 223 + libSystem_atfork_child(void) 154 224 { 225 + // Darling: change 155 226 _mach_fork_child(); 156 - // Mach ports are not inherited across fork except for the Bootstrap. 157 - // So why is the following line not needed on OS X? 158 227 _mig_fork_child(); 159 228 160 229 _dyld_fork_child(); 161 - _cthread_fork_child(); 230 + _pthread_fork_child(); 231 + _malloc_fork_child(); 232 + dispatch_atfork_child(); 162 233 163 - // bootstrap_init(); // currently aborts (needs launchd's bootstrap port) 164 - _cproc_fork_child(); 234 + // _mach_fork_child(); 165 235 _libc_fork_child(); 236 + 237 + #if defined(HAVE_SYSTEM_CORESERVICES) 238 + _libcoreservices_fork_child(); 239 + #endif 240 + 241 + _asl_fork_child(); 166 242 _notify_fork_child(); 167 - xpc_atfork_child(); 243 + // xpc_atfork_child(); // Darling: not yet 244 + // _libSC_info_fork_child(); // Darling: not yet 168 245 169 - _cthread_fork_child_postinit(); 246 + _pthread_fork_child_postinit(); 247 + // _libtrace_fork_child(); // no prep work required for the fork 170 248 } 171 249 172 250 /* ··· 180 258 * This __crashreporter_info__ symbol is for all non-dylib parts of libSystem. 181 259 */ 182 260 const char *__crashreporter_info__; 183 - //asm (".desc __crashreporter_info__, 0x10"); 261 + asm (".desc __crashreporter_info__, 0x10");
+4
src/libsystem_coreservices/dirhelper.c
··· 7 7 { 8 8 } 9 9 10 + void _libcoreservices_fork_child(void) 11 + { 12 + } 13 + 10 14 enum { 11 15 DIRHELPER_USER_LOCAL = 0, 12 16 DIRHELPER_USER_LOCAL_TEMP,
+6
src/libutil/CMakeLists.txt
··· 12 12 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib") 13 13 include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 14 14 include_directories(${DARLING_TOP_DIRECTORY}/src/libc/include) 15 + include_directories(${DARLING_TOP_DIRECTORY}/src/libc/darwin) 16 + include_directories(${DARLING_TOP_DIRECTORY}/src/libc/locale) 17 + include_directories(${DARLING_TOP_DIRECTORY}/src/libc/locale/FreeBSD) 18 + include_directories(${DARLING_TOP_DIRECTORY}/src/libc/stdtime/FreeBSD) 15 19 include_directories(${DARLING_TOP_DIRECTORY}/src/external/libcxx/include) 20 + include_directories(${DARLING_TOP_DIRECTORY}/src/kernel/libsyscall/wrappers) 16 21 17 22 set(util_SRCS 18 23 ExtentManager.cpp ··· 28 33 29 34 set(DYLIB_INSTALL_NAME "/usr/lib/libutil1.0.dylib") 30 35 add_darling_library(util SHARED ${util_SRCS}) 36 + make_fat(util) 31 37 target_link_libraries(util PRIVATE system cxx) 32 38 set_target_properties(util PROPERTIES OUTPUT_NAME "util1.0") 33 39
+5 -1
src/ncurses/CMakeLists.txt
··· 8 8 include_directories(${DARLING_TOP_DIRECTORY}/platform-include) 9 9 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 10 10 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ncurses) 11 + include_directories("${CMAKE_SOURCE_DIR}/src/libc/darwin") 12 + #include_directories("${CMAKE_SOURCE_DIR}/src/libc/locale") 13 + #include_directories("${CMAKE_SOURCE_DIR}/src/libc/locale/FreeBSD") 14 + include_directories("${CMAKE_SOURCE_DIR}/src/libc/stdtime/FreeBSD") 11 15 12 16 add_definitions(-DTARGET_OS_MAC=1) 13 17 add_definitions(-D__APPLE__ -D__DYNAMIC__) 14 18 add_definitions(-D _XOPEN_SOURCE_EXTENDED=1) 15 - add_definitions(-DTRACE) 19 + #add_definitions(-DTRACE) 16 20 17 21 # Hide warnings 18 22 add_definitions(
+1
src/ncurses/menu/CMakeLists.txt
··· 41 41 add_darling_library(menu SHARED ${menu_sources}) 42 42 target_link_libraries(menu system ncurses) 43 43 set_target_properties(menu PROPERTIES OUTPUT_NAME "menu.5.4") 44 + make_fat(menu) 44 45 45 46 InstallSymlink("libmenu.5.4.dylib" "${CMAKE_INSTALL_PREFIX}/libexec/darling/usr/lib/libmenu.dylib") 46 47
+10 -9
src/ncurses/ncurses/CMakeLists.txt
··· 139 139 tinfo/use_screen.c 140 140 tinfo/write_entry.c 141 141 142 - trace/lib_traceatr.c 143 - trace/lib_tracebits.c 142 + #trace/lib_traceatr.c 143 + #trace/lib_tracebits.c 144 144 trace/lib_trace.c 145 - trace/lib_tracechr.c 146 - trace/lib_tracedmp.c 147 - trace/lib_tracemse.c 148 - trace/trace_buf.c 149 - trace/trace_tries.c 150 - trace/trace_xnames.c 151 - trace/varargs.c 145 + #trace/lib_tracechr.c 146 + #trace/lib_tracedmp.c 147 + #trace/lib_tracemse.c 148 + #trace/trace_buf.c 149 + #trace/trace_tries.c 150 + #trace/trace_xnames.c 151 + #trace/varargs.c 152 152 trace/visbuf.c 153 153 154 154 tty/hardscroll.c ··· 193 193 add_darling_library(ncurses SHARED ${ncurses_sources}) 194 194 target_link_libraries(ncurses system) 195 195 set_target_properties(ncurses PROPERTIES OUTPUT_NAME "ncurses.5.4") 196 + make_fat(ncurses) 196 197 197 198 InstallSymlink("libncurses.5.4.dylib" "${CMAKE_INSTALL_PREFIX}/libexec/darling/usr/lib/libncurses.dylib") 198 199
+1
src/ncurses/panel/CMakeLists.txt
··· 27 27 add_darling_library(panel SHARED ${panel_sources}) 28 28 target_link_libraries(panel system ncurses) 29 29 set_target_properties(panel PROPERTIES OUTPUT_NAME "panel.5.4") 30 + make_fat(panel) 30 31 31 32 InstallSymlink("libpanel.5.4.dylib" "${CMAKE_INSTALL_PREFIX}/libexec/darling/usr/lib/libpanel.dylib") 32 33
+1
src/xar/CMakeLists.txt
··· 50 50 add_darling_library(xar SHARED ${xar_SRCS}) 51 51 set_target_properties(xar PROPERTIES OUTPUT_NAME "xar.1") 52 52 target_link_libraries(xar system z bz2 xml2 ssl098 crypto098) 53 + make_fat(xar) 53 54 54 55 install(TARGETS xar DESTINATION libexec/darling/usr/lib) 55 56 InstallSymlink("libxar.1.dylib" "${CMAKE_INSTALL_PREFIX}/libexec/darling/usr/lib/libxar.dylib")