source_private.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /*
  2. * Copyright (c) 2008-2013 Apple Inc. All rights reserved.
  3. *
  4. * @APPLE_APACHE_LICENSE_HEADER_START@
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * @APPLE_APACHE_LICENSE_HEADER_END@
  19. */
  20. /*
  21. * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
  22. * which are subject to change in future releases of Mac OS X. Any applications
  23. * relying on these interfaces WILL break.
  24. */
  25. #ifndef __DISPATCH_SOURCE_PRIVATE__
  26. #define __DISPATCH_SOURCE_PRIVATE__
  27. #ifndef __DISPATCH_INDIRECT__
  28. #error "Please #include <dispatch/private.h> instead of this file directly."
  29. #include <dispatch/base.h> // for HeaderDoc
  30. #endif
  31. DISPATCH_ASSUME_NONNULL_BEGIN
  32. __BEGIN_DECLS
  33. /*!
  34. * @const DISPATCH_SOURCE_TYPE_INTERVAL
  35. * @discussion A dispatch source that submits the event handler block at a
  36. * specified time interval, phase-aligned with all other interval sources on
  37. * the system that have the same interval value.
  38. *
  39. * The initial submission of the event handler will occur at some point during
  40. * the first time interval after the source is created (assuming the source is
  41. * resumed at that time).
  42. *
  43. * By default, the unit for the interval value is milliseconds and the leeway
  44. * (maximum amount of time any individual handler submission may be deferred to
  45. * align with other system activity) for the source is fixed at interval/2.
  46. *
  47. * If the DISPATCH_INTERVAL_UI_ANIMATION flag is specified, the unit for the
  48. * interval value is animation frames (1/60th of a second) and the leeway is
  49. * fixed at one frame.
  50. *
  51. * The handle is the interval value in milliseconds or frames.
  52. * The mask specifies which flags from dispatch_source_timer_flags_t to apply.
  53. *
  54. * Starting with macOS 10.14, iOS 12, dispatch_source_set_timer()
  55. * can be used on such sources, and its arguments are used as follow:
  56. * - start:
  57. * must be DISPATCH_TIME_NOW or DISPATCH_TIME_FOREVER.
  58. * DISPATCH_TIME_NOW will enable the timer, and align its phase, and
  59. * DISPATCH_TIME_FOREVER will disable the timer as usual.*
  60. * - interval:
  61. * its unit is in milliseconds by default, or frames if the source
  62. * was created with the DISPATCH_INTERVAL_UI_ANIMATION flag.
  63. * - leeway:
  64. * per-thousands of the interval (valid values range from 0 to 1000).
  65. * If ~0ull is passed, the default leeway for the interval is used instead.
  66. */
  67. #define DISPATCH_SOURCE_TYPE_INTERVAL (&_dispatch_source_type_interval)
  68. API_AVAILABLE(macos(10.9), ios(7.0))
  69. DISPATCH_SOURCE_TYPE_DECL(interval);
  70. /*!
  71. * @const DISPATCH_SOURCE_TYPE_VFS
  72. * @discussion Apple-internal dispatch source that monitors for vfs events
  73. * defined by dispatch_vfs_flags_t.
  74. * The handle is a process identifier (pid_t).
  75. */
  76. #define DISPATCH_SOURCE_TYPE_VFS (&_dispatch_source_type_vfs)
  77. API_AVAILABLE(macos(10.6), ios(4.0)) DISPATCH_LINUX_UNAVAILABLE()
  78. DISPATCH_SOURCE_TYPE_DECL(vfs);
  79. /*!
  80. * @const DISPATCH_SOURCE_TYPE_VM
  81. * @discussion A dispatch source that monitors virtual memory
  82. * The mask is a mask of desired events from dispatch_source_vm_flags_t.
  83. * This type is deprecated, use DISPATCH_SOURCE_TYPE_MEMORYPRESSURE instead.
  84. */
  85. #define DISPATCH_SOURCE_TYPE_VM (&_dispatch_source_type_vm)
  86. API_DEPRECATED_WITH_REPLACEMENT("DISPATCH_SOURCE_TYPE_MEMORYPRESSURE",
  87. macos(10.7,10.10), ios(4.3,8.0)) DISPATCH_LINUX_UNAVAILABLE()
  88. DISPATCH_SOURCE_TYPE_DECL(vm);
  89. /*!
  90. * @const DISPATCH_SOURCE_TYPE_MEMORYSTATUS
  91. * @discussion A dispatch source that monitors memory status
  92. * The mask is a mask of desired events from
  93. * dispatch_source_memorystatus_flags_t.
  94. */
  95. #define DISPATCH_SOURCE_TYPE_MEMORYSTATUS (&_dispatch_source_type_memorystatus)
  96. API_DEPRECATED_WITH_REPLACEMENT("DISPATCH_SOURCE_TYPE_MEMORYPRESSURE",
  97. macos(10.9, 10.12), ios(6.0, 10.0), tvos(6.0, 10.0), watchos(1.0, 3.0))
  98. DISPATCH_LINUX_UNAVAILABLE()
  99. DISPATCH_SOURCE_TYPE_DECL(memorystatus);
  100. /*!
  101. * @const DISPATCH_SOURCE_TYPE_SOCK
  102. * @discussion A dispatch source that monitors events on socket state changes.
  103. */
  104. #define DISPATCH_SOURCE_TYPE_SOCK (&_dispatch_source_type_sock)
  105. API_AVAILABLE(macos(10.8), ios(6.0)) DISPATCH_LINUX_UNAVAILABLE()
  106. DISPATCH_SOURCE_TYPE_DECL(sock);
  107. /*!
  108. * @const DISPATCH_SOURCE_TYPE_NW_CHANNEL
  109. * @discussion A dispatch source that monitors events on a network channel.
  110. */
  111. #define DISPATCH_SOURCE_TYPE_NW_CHANNEL (&_dispatch_source_type_nw_channel)
  112. API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0)) DISPATCH_LINUX_UNAVAILABLE()
  113. DISPATCH_SOURCE_TYPE_DECL(nw_channel);
  114. __END_DECLS
  115. /*!
  116. * @enum dispatch_source_sock_flags_t
  117. *
  118. * @constant DISPATCH_SOCK_CONNRESET
  119. * Received RST
  120. *
  121. * @constant DISPATCH_SOCK_READCLOSED
  122. * Read side is shutdown
  123. *
  124. * @constant DISPATCH_SOCK_WRITECLOSED
  125. * Write side is shutdown
  126. *
  127. * @constant DISPATCH_SOCK_TIMEOUT
  128. * Timeout: rexmt, keep-alive or persist
  129. *
  130. * @constant DISPATCH_SOCK_NOSRCADDR
  131. * Source address not available
  132. *
  133. * @constant DISPATCH_SOCK_IFDENIED
  134. * Interface denied connection
  135. *
  136. * @constant DISPATCH_SOCK_SUSPEND
  137. * Output queue suspended
  138. *
  139. * @constant DISPATCH_SOCK_RESUME
  140. * Output queue resumed
  141. *
  142. * @constant DISPATCH_SOCK_KEEPALIVE
  143. * TCP Keepalive received
  144. *
  145. * @constant DISPATCH_SOCK_CONNECTED
  146. * Socket is connected
  147. *
  148. * @constant DISPATCH_SOCK_DISCONNECTED
  149. * Socket is disconnected
  150. *
  151. * @constant DISPATCH_SOCK_CONNINFO_UPDATED
  152. * Connection info was updated
  153. *
  154. * @constant DISPATCH_SOCK_NOTIFY_ACK
  155. * Notify acknowledgement
  156. */
  157. enum {
  158. DISPATCH_SOCK_CONNRESET = 0x00000001,
  159. DISPATCH_SOCK_READCLOSED = 0x00000002,
  160. DISPATCH_SOCK_WRITECLOSED = 0x00000004,
  161. DISPATCH_SOCK_TIMEOUT = 0x00000008,
  162. DISPATCH_SOCK_NOSRCADDR = 0x00000010,
  163. DISPATCH_SOCK_IFDENIED = 0x00000020,
  164. DISPATCH_SOCK_SUSPEND = 0x00000040,
  165. DISPATCH_SOCK_RESUME = 0x00000080,
  166. DISPATCH_SOCK_KEEPALIVE = 0x00000100,
  167. DISPATCH_SOCK_ADAPTIVE_WTIMO = 0x00000200,
  168. DISPATCH_SOCK_ADAPTIVE_RTIMO = 0x00000400,
  169. DISPATCH_SOCK_CONNECTED = 0x00000800,
  170. DISPATCH_SOCK_DISCONNECTED = 0x00001000,
  171. DISPATCH_SOCK_CONNINFO_UPDATED = 0x00002000,
  172. DISPATCH_SOCK_NOTIFY_ACK = 0x00004000,
  173. };
  174. /*!
  175. * @enum dispatch_source_nw_channel_flags_t
  176. *
  177. * @constant DISPATCH_NW_CHANNEL_FLOW_ADV_UPDATE
  178. * Received network channel flow advisory.
  179. */
  180. enum {
  181. DISPATCH_NW_CHANNEL_FLOW_ADV_UPDATE = 0x00000001,
  182. };
  183. /*!
  184. * @enum dispatch_source_vfs_flags_t
  185. *
  186. * @constant DISPATCH_VFS_NOTRESP
  187. * Server down.
  188. *
  189. * @constant DISPATCH_VFS_NEEDAUTH
  190. * Server bad auth.
  191. *
  192. * @constant DISPATCH_VFS_LOWDISK
  193. * We're low on space.
  194. *
  195. * @constant DISPATCH_VFS_MOUNT
  196. * New filesystem arrived.
  197. *
  198. * @constant DISPATCH_VFS_UNMOUNT
  199. * Filesystem has left.
  200. *
  201. * @constant DISPATCH_VFS_DEAD
  202. * Filesystem is dead, needs force unmount.
  203. *
  204. * @constant DISPATCH_VFS_ASSIST
  205. * Filesystem needs assistance from external program.
  206. *
  207. * @constant DISPATCH_VFS_NOTRESPLOCK
  208. * Server lockd down.
  209. *
  210. * @constant DISPATCH_VFS_UPDATE
  211. * Filesystem information has changed.
  212. *
  213. * @constant DISPATCH_VFS_VERYLOWDISK
  214. * File system has *very* little disk space left.
  215. *
  216. * @constant DISPATCH_VFS_QUOTA
  217. * We hit a user quota (quotactl) for this filesystem.
  218. *
  219. * @constant DISPATCH_VFS_NEARLOWDISK
  220. * Filesystem is nearly full (below NEARLOWDISK level).
  221. *
  222. * @constant DISPATCH_VFS_DESIREDDISK
  223. * Filesystem has exceeded the DESIREDDISK level
  224. *
  225. * @constant DISPATCH_VFS_FREE_SPACE_CHANGE
  226. * Filesystem free space changed.
  227. */
  228. enum {
  229. DISPATCH_VFS_NOTRESP = 0x0001,
  230. DISPATCH_VFS_NEEDAUTH = 0x0002,
  231. DISPATCH_VFS_LOWDISK = 0x0004,
  232. DISPATCH_VFS_MOUNT = 0x0008,
  233. DISPATCH_VFS_UNMOUNT = 0x0010,
  234. DISPATCH_VFS_DEAD = 0x0020,
  235. DISPATCH_VFS_ASSIST = 0x0040,
  236. DISPATCH_VFS_NOTRESPLOCK = 0x0080,
  237. DISPATCH_VFS_UPDATE = 0x0100,
  238. DISPATCH_VFS_VERYLOWDISK = 0x0200,
  239. DISPATCH_VFS_QUOTA = 0x1000,
  240. DISPATCH_VFS_NEARLOWDISK = 0x2000,
  241. DISPATCH_VFS_DESIREDDISK = 0x4000,
  242. DISPATCH_VFS_FREE_SPACE_CHANGE = 0x8000,
  243. };
  244. /*!
  245. * @enum dispatch_clockid_t
  246. *
  247. * @discussion
  248. * These values can be used with DISPATCH_SOURCE_TYPE_TIMER as a "handle"
  249. * to anchor the timer to a given clock which allows for various optimizations.
  250. *
  251. * Note that using an explicit clock will make the dispatch source "strict"
  252. * like dispatch_source_set_mandatory_cancel_handler() does.
  253. *
  254. * @constant DISPATCH_CLOCKID_UPTIME
  255. * A monotonic clock that doesn't tick while the machine is asleep.
  256. * Equivalent to the CLOCK_UPTIME clock ID on BSD systems.
  257. *
  258. * @constant DISPATCH_CLOCKID_MONOTONIC
  259. * A monotonic clock that ticks while the machine sleeps.
  260. * Equivalent to POSIX CLOCK_MONOTONIC.
  261. * (Note that on Linux, CLOCK_MONOTONIC isn't conformant and doesn't tick while
  262. * sleeping, hence on Linux this is the same clock as CLOCK_BOOTTIME).
  263. *
  264. * @constant DISPATCH_CLOCKID_WALLTIME
  265. * A clock equivalent to the wall clock time, as returned by gettimeofday().
  266. * Equivalent to POSIX CLOCK_REALTIME.
  267. *
  268. * @constant DISPATCH_CLOCKID_REALTIME
  269. * An alias for DISPATCH_CLOCKID_WALLTIME to match the POSIX clock of the
  270. * same name.
  271. */
  272. DISPATCH_ENUM(dispatch_clockid, uintptr_t,
  273. DISPATCH_CLOCKID_UPTIME DISPATCH_ENUM_API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0)) = 1,
  274. DISPATCH_CLOCKID_MONOTONIC DISPATCH_ENUM_API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0)) = 2,
  275. DISPATCH_CLOCKID_WALLTIME DISPATCH_ENUM_API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0)) = 3,
  276. DISPATCH_CLOCKID_REALTIME DISPATCH_ENUM_API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0)) = 3,
  277. );
  278. /*!
  279. * @enum dispatch_source_timer_flags_t
  280. *
  281. * @constant DISPATCH_TIMER_BACKGROUND
  282. * Specifies that the timer is used to trigger low priority maintenance-level
  283. * activity and that the system may apply larger minimum leeway values to the
  284. * timer in order to align it with other system activity.
  285. *
  286. * @constant DISPATCH_INTERVAL_UI_ANIMATION
  287. * Specifies that the interval source is used for UI animation. The unit for
  288. * the interval value of such sources is frames (1/60th of a second) and the
  289. * leeway is fixed at one frame.
  290. */
  291. enum {
  292. DISPATCH_TIMER_BACKGROUND = 0x2,
  293. DISPATCH_INTERVAL_UI_ANIMATION = 0x20,
  294. };
  295. /*!
  296. * @enum dispatch_source_mach_send_flags_t
  297. *
  298. * @constant DISPATCH_MACH_SEND_POSSIBLE
  299. * The mach port corresponding to the given send right has space available
  300. * for messages. Delivered only once a mach_msg() to that send right with
  301. * options MACH_SEND_MSG|MACH_SEND_TIMEOUT|MACH_SEND_NOTIFY has returned
  302. * MACH_SEND_TIMED_OUT (and not again until the next such mach_msg() timeout).
  303. * NOTE: The source must have registered the send right for monitoring with the
  304. * system for such a mach_msg() to arm the send-possible notifcation, so
  305. * the initial send attempt must occur from a source registration handler.
  306. */
  307. enum {
  308. DISPATCH_MACH_SEND_POSSIBLE = 0x8,
  309. };
  310. /*!
  311. * @enum dispatch_source_proc_flags_t
  312. *
  313. * @constant DISPATCH_PROC_REAP
  314. * The process has been reaped by the parent process via wait*().
  315. * This flag is deprecated and will be removed in a future release.
  316. *
  317. * @constant DISPATCH_PROC_EXIT_STATUS
  318. * The process has exited. Specifying this flag allows the process exit status
  319. * to be retrieved from the source's status value, as returned by the
  320. * dispatch_source_get_extended_data() function. The macros
  321. * DISPATCH_PROC_EXIT_STATUS_EXITED(), DISPATCH_PROC_EXIT_STATUS_CODE(),
  322. * DISPATCH_PROC_EXIT_STATUS_SIGNALED(), DISPATCH_PROC_EXIT_STATUS_TERMSIG() and
  323. * DISPATCH_PROC_EXIT_STATUS_CORE_DUMPED() can be used to examine the status
  324. * value.
  325. */
  326. enum {
  327. DISPATCH_PROC_REAP DISPATCH_ENUM_API_DEPRECATED("unsupported flag",
  328. macos(10.6,10.9), ios(4.0,7.0)) = 0x10000000,
  329. DISPATCH_PROC_EXIT_STATUS DISPATCH_ENUM_API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(2.0)) = 0x04000000,
  330. };
  331. /*!
  332. * @enum dispatch_source_vm_flags_t
  333. *
  334. * @constant DISPATCH_VM_PRESSURE
  335. * The VM has experienced memory pressure.
  336. */
  337. enum {
  338. DISPATCH_VM_PRESSURE DISPATCH_ENUM_API_DEPRECATED_WITH_REPLACEMENT("DISPATCH_MEMORYPRESSURE_WARN", macos(10.7, 10.10), ios(4.3, 8.0))
  339. = 0x80000000,
  340. };
  341. /*!
  342. * @typedef dispatch_source_memorypressure_flags_t
  343. * Type of dispatch_source_memorypressure flags
  344. *
  345. * @constant DISPATCH_MEMORYPRESSURE_LOW_SWAP
  346. * The system's memory pressure state has entered the "low swap" condition.
  347. * Restricted to the root user.
  348. */
  349. enum {
  350. DISPATCH_MEMORYPRESSURE_LOW_SWAP DISPATCH_ENUM_API_AVAILABLE(macos(10.10), ios(8.0)) = 0x08,
  351. };
  352. /*!
  353. * @enum dispatch_source_memorystatus_flags_t
  354. * @warning Deprecated, see DISPATCH_MEMORYPRESSURE_*
  355. */
  356. enum {
  357. DISPATCH_MEMORYSTATUS_PRESSURE_NORMAL
  358. DISPATCH_ENUM_API_DEPRECATED_WITH_REPLACEMENT("DISPATCH_MEMORYPRESSURE_NORMAL", macos(10.9, 10.12),
  359. ios(6.0, 10.0), tvos(6.0, 10.0), watchos(1.0, 3.0)) = 0x01,
  360. DISPATCH_MEMORYSTATUS_PRESSURE_WARN
  361. DISPATCH_ENUM_API_DEPRECATED_WITH_REPLACEMENT("DISPATCH_MEMORYPRESSURE_WARN", macos(10.9, 10.12),
  362. ios(6.0, 10.0), tvos(6.0, 10.0), watchos(1.0, 3.0)) = 0x02,
  363. DISPATCH_MEMORYSTATUS_PRESSURE_CRITICAL
  364. DISPATCH_ENUM_API_DEPRECATED_WITH_REPLACEMENT("DISPATCH_MEMORYPRESSURE_CRITICAL", macos(10.9, 10.12),
  365. ios(6.0, 10.0), tvos(6.0, 10.0), watchos(1.0, 3.0)) = 0x04,
  366. DISPATCH_MEMORYSTATUS_LOW_SWAP
  367. DISPATCH_ENUM_API_DEPRECATED_WITH_REPLACEMENT("DISPATCH_MEMORYPRESSURE_LOW_SWAP", macos(10.9, 10.12),
  368. ios(6.0, 10.0), tvos(6.0, 10.0), watchos(1.0, 3.0)) = 0x08,
  369. };
  370. /*!
  371. * @typedef dispatch_source_memorypressure_flags_t
  372. * Type of dispatch_source_memorypressure flags
  373. *
  374. * @constant DISPATCH_MEMORYPRESSURE_PROC_LIMIT_WARN
  375. * The memory of the process has crossed 80% of its high watermark limit.
  376. *
  377. * @constant DISPATCH_MEMORYPRESSURE_PROC_LIMIT_CRITICAL
  378. * The memory of the process has reached 100% of its high watermark limit.
  379. *
  380. * @constant DISPATCH_MEMORYPRESSURE_MSL_STATUS
  381. * Mask for enabling/disabling malloc stack logging.
  382. */
  383. enum {
  384. DISPATCH_MEMORYPRESSURE_PROC_LIMIT_WARN DISPATCH_ENUM_API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) = 0x10,
  385. DISPATCH_MEMORYPRESSURE_PROC_LIMIT_CRITICAL DISPATCH_ENUM_API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) = 0x20,
  386. DISPATCH_MEMORYPRESSURE_MSL_STATUS DISPATCH_ENUM_API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0)) = 0xf0000000,
  387. };
  388. /*!
  389. * Macros to check the exit status obtained from the status field of the
  390. * structure returned by the dispatch_source_get_extended_data() function for a
  391. * source of type DISPATCH_SOURCE_TYPE_PROC when DISPATCH_PROC_EXIT_STATUS has
  392. * been requested.
  393. *
  394. * DISPATCH_PROC_EXIT_STATUS_EXITED returns whether the process exited. If this
  395. * is true, the exit status can be obtained from DISPATCH_PROC_EXIT_STATUS_CODE.
  396. *
  397. * DISPATCH_PROC_EXIT_STATUS_SIGNALED returns whether the process was terminated
  398. * by a signal.
  399. *
  400. * DISPATCH_PROC_EXIT_STATUS_TERMSIG returns the signal that caused the process
  401. * to terminate, or 0 if the process was not terminated by a signal.
  402. *
  403. * DISPATCH_PROC_EXIT_STATUS_CORE_DUMPED returns whether a core dump of the
  404. * process was created.
  405. */
  406. #define DISPATCH_PROC_EXIT_STATUS_EXITED(status) ((bool)WIFEXITED(status))
  407. #define DISPATCH_PROC_EXIT_STATUS_CODE(status) ((int)WEXITSTATUS(status))
  408. #define DISPATCH_PROC_EXIT_STATUS_SIGNALED(status) ((bool)WIFSIGNALED(status))
  409. #define DISPATCH_PROC_EXIT_STATUS_TERMSIG(status) ((int)WTERMSIG(status))
  410. #define DISPATCH_PROC_EXIT_STATUS_CORE_DUMPED(status) ((bool)WCOREDUMP(status))
  411. __BEGIN_DECLS
  412. /*!
  413. * @function dispatch_source_set_mandatory_cancel_handler
  414. *
  415. * @abstract
  416. * Sets the event handler block for the given dispatch source, and indicates
  417. * that calling dispatch_source_cancel() is mandatory for this source object.
  418. *
  419. * @discussion
  420. * The cancellation handler (if specified) will be submitted to the source's
  421. * target queue in response to a call to dispatch_source_cancel() once the
  422. * system has released all references to the source's underlying handle and
  423. * the source's event handler block has returned.
  424. *
  425. * When this function has been used used to set a cancellation handler, then
  426. * the following result in an assertion and the process being terminated:
  427. * - releasing the last reference on the dispatch source without having
  428. * cancelled it by calling dispatch_source_cancel();
  429. * - changing any handler after the source has been activated;
  430. * - changing the target queue of the source after it has been activated.
  431. *
  432. * IMPORTANT:
  433. * Source cancellation and a cancellation handler are required for file
  434. * descriptor and mach port based sources in order to safely close the
  435. * descriptor or destroy the port. Making the cancellation handler of such
  436. * sources mandatory is strongly recommended.
  437. * Closing the descriptor or port before the cancellation handler is invoked may
  438. * result in a race condition. If a new descriptor is allocated with the same
  439. * value as the recently closed descriptor while the source's event handler is
  440. * still running, the event handler may read/write data to the wrong descriptor.
  441. *
  442. * @param source
  443. * The dispatch source to modify.
  444. * The result of passing NULL in this parameter is undefined.
  445. *
  446. * @param handler
  447. * The cancellation handler block to submit to the source's target queue.
  448. * The result of passing NULL in this parameter is undefined.
  449. */
  450. #ifdef __BLOCKS__
  451. API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
  452. DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
  453. void
  454. dispatch_source_set_mandatory_cancel_handler(dispatch_source_t source,
  455. dispatch_block_t handler);
  456. #endif /* __BLOCKS__ */
  457. /*!
  458. * @function dispatch_source_set_mandatory_cancel_handler_f
  459. *
  460. * @abstract
  461. * Sets the event handler function for the given dispatch source, and causes an
  462. * assertion if this source is released before having been explicitly canceled.
  463. *
  464. * @discussion
  465. * See dispatch_source_set_mandatory_cancel_handler() for more details.
  466. *
  467. * @param source
  468. * The dispatch source to modify.
  469. * The result of passing NULL in this parameter is undefined.
  470. *
  471. * @param handler
  472. * The cancellation handler function to submit to the source's target queue.
  473. * The context parameter passed to the event handler function is the current
  474. * context of the dispatch source at the time the handler call is made.
  475. * The result of passing NULL in this parameter is undefined.
  476. */
  477. API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
  478. DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
  479. void
  480. dispatch_source_set_mandatory_cancel_handler_f(dispatch_source_t source,
  481. dispatch_function_t handler);
  482. /*!
  483. * @function dispatch_source_cancel_and_wait
  484. *
  485. * @abstract
  486. * Synchronously cancel the dispatch source, preventing any further invocation
  487. * of its event handler block.
  488. *
  489. * @discussion
  490. * Cancellation prevents any further invocation of handler blocks for the
  491. * specified dispatch source, but does not interrupt a handler block that is
  492. * already in progress.
  493. *
  494. * When this function returns, any handler block that may have been in progress
  495. * has returned, the specified source has been unregistered and it is safe to
  496. * reclaim any system resource (such as file descriptors or mach ports) that
  497. * the specified source was monitoring.
  498. *
  499. * If the specified dispatch source is inactive, it will be activated as a side
  500. * effect of calling this function.
  501. *
  502. * It is possible to call this function from several threads concurrently,
  503. * and it is the responsibility of the callers to synchronize reclaiming the
  504. * associated system resources.
  505. *
  506. * This function is not subject to priority inversion when it is waiting on
  507. * a handler block still in progress, unlike patterns based on waiting on
  508. * a dispatch semaphore or a dispatch group signaled (or left) from the source
  509. * cancel handler.
  510. *
  511. * This function must not be called if the specified source has a cancel
  512. * handler set, or from the context of its handler blocks.
  513. *
  514. * This function must not be called from the context of the target queue of
  515. * the specified source or from any queue that synchronizes with it. Note that
  516. * calling dispatch_source_cancel() from such a context already guarantees
  517. * that no handler is in progress, and that no new event will be delivered.
  518. *
  519. * This function must not be called on sources suspended with an explicit
  520. * call to dispatch_suspend(), or being concurrently activated on another
  521. * thread.
  522. *
  523. * @param source
  524. * The dispatch source to be canceled.
  525. * The result of passing NULL in this parameter is undefined.
  526. */
  527. API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
  528. DISPATCH_EXPORT DISPATCH_NOTHROW
  529. void
  530. dispatch_source_cancel_and_wait(dispatch_source_t source);
  531. #if __has_include(<mach/mach.h>)
  532. /*!
  533. * @typedef dispatch_mig_callback_t
  534. *
  535. * @abstract
  536. * The signature of a function that handles Mach message delivery and response.
  537. */
  538. typedef boolean_t (*dispatch_mig_callback_t)(mach_msg_header_t *message,
  539. mach_msg_header_t *reply);
  540. API_AVAILABLE(macos(10.6), ios(4.0)) DISPATCH_LINUX_UNAVAILABLE()
  541. DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
  542. mach_msg_return_t
  543. dispatch_mig_server(dispatch_source_t ds, size_t maxmsgsz,
  544. dispatch_mig_callback_t callback);
  545. /*!
  546. * @function dispatch_mach_msg_get_context
  547. *
  548. * @abstract
  549. * Extract the context pointer from a mach message trailer.
  550. */
  551. API_AVAILABLE(macos(10.6), ios(4.0)) DISPATCH_LINUX_UNAVAILABLE()
  552. DISPATCH_EXPORT DISPATCH_PURE DISPATCH_WARN_RESULT DISPATCH_NONNULL_ALL
  553. DISPATCH_NOTHROW
  554. void *_Nullable
  555. dispatch_mach_msg_get_context(mach_msg_header_t *msg);
  556. #endif
  557. /*!
  558. * @typedef dispatch_source_extended_data_t
  559. *
  560. * @abstract
  561. * Type used by dispatch_source_get_extended_data() to return a consistent
  562. * snapshot of the data and status of a dispatch source.
  563. */
  564. typedef struct dispatch_source_extended_data_s {
  565. unsigned long data;
  566. unsigned long status;
  567. } *dispatch_source_extended_data_t;
  568. /*!
  569. * @function dispatch_source_get_extended_data
  570. *
  571. * @abstract
  572. * Returns the current data and status values for a dispatch source.
  573. *
  574. * @discussion
  575. * This function is intended to be called from within the event handler block.
  576. * The result of calling this function outside of the event handler callback is
  577. * undefined.
  578. *
  579. * @param source
  580. * The result of passing NULL in this parameter is undefined.
  581. *
  582. * @param data
  583. * A pointer to a dispatch_source_extended_data_s in which the data and status
  584. * will be returned. The data field is populated with the value that would be
  585. * returned by dispatch_source_get_data(). The value of the status field should
  586. * be interpreted according to the type of the dispatch source:
  587. *
  588. * DISPATCH_SOURCE_TYPE_PROC: dispatch_source_proc_exit_flags_t
  589. *
  590. * If called from the event handler of a data source type not listed above, the
  591. * status value is undefined.
  592. *
  593. * @param size
  594. * The size of the specified structure. Should be set to
  595. * sizeof(dispatch_source_extended_data_s).
  596. *
  597. * @result
  598. * The size of the structure returned in *data, which will never be greater than
  599. * the value of the size argument. If this is less than the value of the size
  600. * argument, the remaining space in data will have been populated with zeroes.
  601. */
  602. API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
  603. DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_WARN_RESULT DISPATCH_PURE
  604. DISPATCH_NOTHROW
  605. size_t
  606. dispatch_source_get_extended_data(dispatch_source_t source,
  607. dispatch_source_extended_data_t data, size_t size);
  608. __END_DECLS
  609. DISPATCH_ASSUME_NONNULL_END
  610. #endif