]> git.saurik.com Git - apple/libdispatch.git/blob - private/introspection_private.h
libdispatch-339.1.9.tar.gz
[apple/libdispatch.git] / private / introspection_private.h
1 /*
2 * Copyright (c) 2012-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 /*
22 * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
23 * which are subject to change in future releases of Mac OS X. Any applications
24 * relying on these interfaces WILL break.
25 */
26
27 #ifndef __DISPATCH_INTROSPECTION_PRIVATE__
28 #define __DISPATCH_INTROSPECTION_PRIVATE__
29
30 /*!
31 * @header
32 *
33 * @abstract
34 * Introspection SPI for libdispatch.
35 *
36 * @discussion
37 * This SPI is only available in the introspection version of the library,
38 * loaded by running a process with the environment variable
39 * DYLD_LIBRARY_PATH=/usr/lib/system/introspection
40 *
41 * NOTE: these functions are _not_ exported from the shared library, they are
42 * only intended to be called from a debugger context while the rest of the
43 * process is suspended.
44 */
45
46 #ifndef __BEGIN_DECLS
47 #if defined(__cplusplus)
48 #define __BEGIN_DECLS extern "C" {
49 #define __END_DECLS }
50 #else
51 #define __BEGIN_DECLS
52 #define __END_DECLS
53 #endif
54 #endif
55
56 __BEGIN_DECLS
57
58 #ifndef __DISPATCH_INDIRECT__
59 /*
60 * Typedefs of opaque types, for direct inclusion of header in lldb expressions
61 */
62 typedef __typeof__(sizeof(int)) size_t;
63 typedef struct _opaque_pthread_t *pthread_t;
64 typedef void (*dispatch_function_t)(void *);
65 typedef struct Block_layout *dispatch_block_t;
66 typedef struct dispatch_continuation_s *dispatch_continuation_t;
67 typedef struct dispatch_queue_s *dispatch_queue_t;
68 typedef struct dispatch_source_s *dispatch_source_t;
69 typedef struct dispatch_group_s *dispatch_group_t;
70 typedef struct dispatch_object_s *dispatch_object_t;
71 #endif
72
73 /*!
74 * @typedef dispatch_introspection_versions_s
75 *
76 * @abstract
77 * A structure of version and size information of introspection structures.
78 *
79 * @field introspection_version
80 * Version of overall dispatch_introspection SPI.
81 *
82 * @field queue_version
83 * Version of dispatch_introspection_queue_s structure.
84 *
85 * @field queue_size
86 * Size of dispatch_introspection_queue_s structure.
87 *
88 * @field source_version
89 * Version of dispatch_introspection_source_s structure.
90 *
91 * @field source_size
92 * Size of dispatch_introspection_source_s structure.
93 */
94
95 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
96 DISPATCH_EXPORT const struct dispatch_introspection_versions_s {
97 unsigned long introspection_version;
98 unsigned long hooks_version;
99 size_t hooks_size;
100 unsigned long queue_item_version;
101 size_t queue_item_size;
102 unsigned long queue_block_version;
103 size_t queue_block_size;
104 unsigned long queue_function_version;
105 size_t queue_function_size;
106 unsigned long queue_thread_version;
107 size_t queue_thread_size;
108 unsigned long object_version;
109 size_t object_size;
110 unsigned long queue_version;
111 size_t queue_size;
112 unsigned long source_version;
113 size_t source_size;
114 } dispatch_introspection_versions;
115
116 /*!
117 * @typedef dispatch_introspection_queue_block_s
118 *
119 * @abstract
120 * A structure of introspection information for a block item enqueued on a
121 * dispatch queue.
122 *
123 * @field continuation
124 * Pointer to enqueued item.
125 *
126 * @field target_queue
127 * Target queue of item (may be different to the queue the item is currently
128 * enqueued on).
129 *
130 * @field block
131 * Block for enqueued item.
132 *
133 * @field block_invoke
134 * Function pointer of block for enqueued item.
135 *
136 * @field group
137 * Group containing enqueued item (may be NULL).
138 *
139 * @field waiter
140 * Thread waiting for completion of enqueued item (NULL if sync == 0).
141 *
142 * @field barrier
143 * Item is a barrier on the queue (all items on serial queues are barriers).
144 *
145 * @field sync
146 * Item was enqueued by a dispatch_sync/dispatch_barrier_sync.
147 *
148 * @field apply
149 * Item is part of a dispatch_apply.
150 */
151 typedef struct dispatch_introspection_queue_block_s {
152 dispatch_continuation_t continuation;
153 dispatch_queue_t target_queue;
154 dispatch_block_t block;
155 dispatch_function_t block_invoke;
156 dispatch_group_t group;
157 pthread_t waiter;
158 unsigned long barrier:1,
159 sync:1,
160 apply:1;
161 } dispatch_introspection_queue_block_s;
162 typedef dispatch_introspection_queue_block_s
163 *dispatch_introspection_queue_block_t;
164
165 /*!
166 * @typedef dispatch_introspection_queue_function_s
167 *
168 * @abstract
169 * A structure of introspection information for a function & context pointer
170 * item enqueued on a dispatch queue.
171 *
172 * @field continuation
173 * Pointer to enqueued item.
174 *
175 * @field target_queue
176 * Target queue of item (may be different to the queue the item is currently
177 * enqueued on).
178 *
179 * @field context
180 * Context in enqueued item.
181 *
182 * @field block_invoke
183 * Function pointer in enqueued item.
184 *
185 * @field group
186 * Group containing enqueued item (may be NULL).
187 *
188 * @field waiter
189 * Thread waiting for completion of enqueued item (NULL if sync == 0).
190 *
191 * @field barrier
192 * Item is a barrier on the queue (all items on serial queues are barriers).
193 *
194 * @field sync
195 * Item was enqueued by a dispatch_sync_f/dispatch_barrier_sync_f.
196 *
197 * @field apply
198 * Item is part of a dispatch_apply_f.
199 */
200 typedef struct dispatch_introspection_queue_function_s {
201 dispatch_continuation_t continuation;
202 dispatch_queue_t target_queue;
203 void *context;
204 dispatch_function_t function;
205 dispatch_group_t group;
206 pthread_t waiter;
207 unsigned long barrier:1,
208 sync:1,
209 apply:1;
210 } dispatch_introspection_queue_function_s;
211 typedef dispatch_introspection_queue_function_s
212 *dispatch_introspection_queue_function_t;
213
214 /*!
215 * @typedef dispatch_introspection_object_s
216 *
217 * @abstract
218 * A structure of introspection information for a generic dispatch object.
219 *
220 * @field object
221 * Pointer to object.
222 *
223 * @field target_queue
224 * Target queue of object (may be different to the queue the object is
225 * currently enqueued on).
226 *
227 * @field type
228 * Object class pointer.
229 *
230 * @field kind
231 * String describing the object type.
232 */
233 typedef struct dispatch_introspection_object_s {
234 dispatch_continuation_t object;
235 dispatch_queue_t target_queue;
236 void *type;
237 const char *kind;
238 } dispatch_introspection_object_s;
239 typedef dispatch_introspection_object_s *dispatch_introspection_object_t;
240
241 /*!
242 * @typedef dispatch_introspection_queue_s
243 *
244 * @abstract
245 * A structure of introspection information for a dispatch queue.
246 *
247 * @field queue
248 * Pointer to queue object.
249 *
250 * @field target_queue
251 * Target queue of queue (may be different to the queue the queue is currently
252 * enqueued on). NULL indicates queue is a root queue.
253 *
254 * @field label
255 * Pointer to queue label.
256 *
257 * @field serialnum
258 * Queue serial number (unique per process).
259 *
260 * @field width
261 * Queue width (1: serial queue, UINT_MAX: concurrent queue).
262 *
263 * @field suspend_count
264 * Number of times the queue has been suspended.
265 *
266 * @field enqueued
267 * Queue is enqueued on another queue.
268 *
269 * @field barrier
270 * Queue is executing a barrier item.
271 *
272 * @field draining
273 * Queue is being drained (cannot get queue items).
274 *
275 * @field global
276 * Queue is a global queue.
277 *
278 * @field main
279 * Queue is the main queue.
280 */
281 typedef struct dispatch_introspection_queue_s {
282 dispatch_queue_t queue;
283 dispatch_queue_t target_queue;
284 const char *label;
285 unsigned long serialnum;
286 unsigned int width;
287 unsigned int suspend_count;
288 unsigned long enqueued:1,
289 barrier:1,
290 draining:1,
291 global:1,
292 main:1;
293 } dispatch_introspection_queue_s;
294 typedef dispatch_introspection_queue_s *dispatch_introspection_queue_t;
295
296 /*!
297 * @typedef dispatch_introspection_source_s
298 *
299 * @abstract
300 * A structure of introspection information for a dispatch source.
301 *
302 * @field source
303 * Pointer to source object.
304 *
305 * @field target_queue
306 * Target queue of source (may be different to the queue the source is currently
307 * enqueued on).
308 *
309 * @field type
310 * Source type (kevent filter)
311 *
312 * @field handle
313 * Source handle (monitored entity).
314 *
315 * @field context
316 * Context pointer passed to source handler. Pointer to handler block if
317 * handler_is_block == 1.
318 *
319 * @field handler
320 * Source handler function. Function pointer of handler block if
321 * handler_is_block == 1.
322 *
323 * @field suspend_count
324 * Number of times the source has been suspended.
325 *
326 * @field enqueued
327 * Source is enqueued on a queue.
328 *
329 * @field handler_is_block
330 * Source handler is a block.
331 *
332 * @field timer
333 * Source is a timer.
334 *
335 * @field after
336 * Source is a dispatch_after timer.
337 */
338 typedef struct dispatch_introspection_source_s {
339 dispatch_source_t source;
340 dispatch_queue_t target_queue;
341 unsigned long type;
342 unsigned long handle;
343 void *context;
344 dispatch_function_t handler;
345 unsigned int suspend_count;
346 unsigned long enqueued:1,
347 handler_is_block:1,
348 timer:1,
349 after:1;
350 } dispatch_introspection_source_s;
351 typedef dispatch_introspection_source_s *dispatch_introspection_source_t;
352
353 /*!
354 * @typedef dispatch_introspection_queue_thread_s
355 *
356 * @abstract
357 * A structure of introspection information about a thread executing items for
358 * a dispatch queue.
359 *
360 * @field object
361 * Pointer to thread object.
362 *
363 * @field thread
364 * Thread executing items for a queue.
365 *
366 * @field queue
367 * Queue introspection information. The queue.queue field is NULL if this thread
368 * is not currently executing items for a queue.
369 */
370 typedef struct dispatch_introspection_queue_thread_s {
371 dispatch_continuation_t object;
372 pthread_t thread;
373 dispatch_introspection_queue_s queue;
374 } dispatch_introspection_queue_thread_s;
375 typedef dispatch_introspection_queue_thread_s
376 *dispatch_introspection_queue_thread_t;
377
378 /*!
379 * @enum dispatch_introspection_queue_item_type
380 *
381 * @abstract
382 * Types of items enqueued on a dispatch queue.
383 */
384 enum dispatch_introspection_queue_item_type {
385 dispatch_introspection_queue_item_type_none = 0x0,
386 dispatch_introspection_queue_item_type_block = 0x11,
387 dispatch_introspection_queue_item_type_function = 0x12,
388 dispatch_introspection_queue_item_type_object = 0x100,
389 dispatch_introspection_queue_item_type_queue = 0x101,
390 dispatch_introspection_queue_item_type_source = 0102,
391 };
392
393 /*!
394 * @typedef dispatch_introspection_queue_item_s
395 *
396 * @abstract
397 * A structure of introspection information about an item enqueued on a
398 * dispatch queue.
399 *
400 * @field type
401 * Indicates which of the union members applies to this item.
402 */
403 typedef struct dispatch_introspection_queue_item_s {
404 unsigned long type; // dispatch_introspection_queue_item_type
405 union {
406 dispatch_introspection_queue_block_s block;
407 dispatch_introspection_queue_function_s function;
408 dispatch_introspection_object_s object;
409 dispatch_introspection_queue_s queue;
410 dispatch_introspection_source_s source;
411 };
412 } dispatch_introspection_queue_item_s;
413 typedef dispatch_introspection_queue_item_s
414 *dispatch_introspection_queue_item_t;
415
416 /*!
417 * @typedef dispatch_introspection_hook_queue_create_t
418 *
419 * @abstract
420 * A function pointer called when a dispatch queue is created.
421 *
422 * @param queue_info
423 * Pointer to queue introspection structure.
424 */
425 typedef void (*dispatch_introspection_hook_queue_create_t)(
426 dispatch_introspection_queue_t queue_info);
427
428 /*!
429 * @typedef dispatch_introspection_hook_queue_dispose_t
430 *
431 * @abstract
432 * A function pointer called when a dispatch queue is destroyed.
433 *
434 * @param queue_info
435 * Pointer to queue introspection structure.
436 */
437 typedef void (*dispatch_introspection_hook_queue_dispose_t)(
438 dispatch_introspection_queue_t queue_info);
439
440 /*!
441 * @typedef dispatch_introspection_hook_queue_item_enqueue_t
442 *
443 * @abstract
444 * A function pointer called when an item is enqueued onto a dispatch queue.
445 *
446 * @param queue
447 * Pointer to queue.
448 *
449 * @param item
450 * Pointer to item introspection structure.
451 */
452 typedef void (*dispatch_introspection_hook_queue_item_enqueue_t)(
453 dispatch_queue_t queue, dispatch_introspection_queue_item_t item);
454
455 /*!
456 * @typedef dispatch_introspection_hook_queue_item_dequeue_t
457 *
458 * @abstract
459 * A function pointer called when an item is dequeued from a dispatch queue.
460 *
461 * @param queue
462 * Pointer to queue.
463 *
464 * @param item
465 * Pointer to item introspection structure.
466 */
467 typedef void (*dispatch_introspection_hook_queue_item_dequeue_t)(
468 dispatch_queue_t queue, dispatch_introspection_queue_item_t item);
469
470 /*!
471 * @typedef dispatch_introspection_hooks_s
472 *
473 * @abstract
474 * A structure of function pointer hoooks into libdispatch.
475 */
476
477 typedef struct dispatch_introspection_hooks_s {
478 dispatch_introspection_hook_queue_create_t queue_create;
479 dispatch_introspection_hook_queue_dispose_t queue_dispose;
480 dispatch_introspection_hook_queue_item_enqueue_t queue_item_enqueue;
481 dispatch_introspection_hook_queue_item_dequeue_t queue_item_dequeue;
482 void *_reserved[6];
483 } dispatch_introspection_hooks_s;
484 typedef dispatch_introspection_hooks_s *dispatch_introspection_hooks_t;
485
486 /*!
487 * @function dispatch_introspection_get_queues
488 *
489 * @abstract
490 * Retrieve introspection information about all dispatch queues in the process,
491 * in batches of specified size.
492 *
493 * @discussion
494 * Retrieving queue information and iterating through the list of all queues
495 * must take place from a debugger context (while the rest of the process is
496 * suspended).
497 *
498 * @param start
499 * Starting point for this batch of queue information, as returned by a previous
500 * call to _dispatch_introspection_get_queues().
501 * Pass NULL to retrieve the initial batch.
502 *
503 * @param count
504 * Number of queues to introspect.
505 *
506 * @param queues
507 * Array to fill with queue information. If less than 'count' queues are left
508 * in this batch, the end of valid entries in the array will be indicated
509 * by an entry with NULL queue member.
510 *
511 * @result
512 * Queue to pass to another call to _dispatch_introspection_get_queues() to
513 * retrieve information about the next batch of queues. May be NULL if there
514 * are no more queues to iterate over.
515 */
516 extern dispatch_queue_t
517 dispatch_introspection_get_queues(dispatch_queue_t start, size_t count,
518 dispatch_introspection_queue_t queues);
519
520 /*!
521 * @function dispatch_introspection_get_queue_threads
522 *
523 * @abstract
524 * Retrieve introspection information about all threads in the process executing
525 * items for dispatch queues, in batches of specified size.
526 *
527 * @discussion
528 * Retrieving thread information and iterating through the list of all queue
529 * threads must take place from a debugger context (while the rest of the
530 * process is suspended).
531 *
532 * @param start
533 * Starting point for this batch of thread information, as returned by a
534 * previous call to _dispatch_introspection_get_queue_threads().
535 * Pass NULL to retrieve the initial batch.
536 *
537 * @param count
538 * Number of queue threads to introspect.
539 *
540 * @param threads
541 * Array to fill with queue thread information. If less than 'count' threads are
542 * left in this batch, the end of valid entries in the array will be indicated
543 * by an entry with NULL object member.
544 *
545 * @result
546 * Object to pass to another call to _dispatch_introspection_get_queues() to
547 * retrieve information about the next batch of queues. May be NULL if there
548 * are no more queues to iterate over.
549 */
550 extern dispatch_continuation_t
551 dispatch_introspection_get_queue_threads(dispatch_continuation_t start,
552 size_t count, dispatch_introspection_queue_thread_t threads);
553
554 /*!
555 * @function dispatch_introspection_queue_get_items
556 *
557 * @abstract
558 * Retrieve introspection information about all items enqueued on a queue, in
559 * batches of specified size.
560 *
561 * @discussion
562 * Retrieving queue item information and iterating through a queue must take
563 * place from a debugger context (while the rest of the process is suspended).
564 *
565 * @param queue
566 * Queue to introspect.
567 *
568 * @param start
569 * Starting point for this batch of queue item information, as returned by a
570 * previous call to _dispatch_introspection_queue_get_items().
571 * Pass NULL to retrieve the initial batch.
572 *
573 * @param count
574 * Number of items to introspect.
575 *
576 * @param items
577 * Array to fill with queue item information. If less than 'count' queues are
578 * left in this batch, the end of valid entries in the array will be indicated
579 * by an entry with type dispatch_introspection_queue_item_type_none.
580 *
581 * @result
582 * Item to pass to another call to _dispatch_introspection_queue_get_items() to
583 * retrieve information about the next batch of queue items. May be NULL if
584 * there are no more items to iterate over.
585 */
586 extern dispatch_continuation_t
587 dispatch_introspection_queue_get_items(dispatch_queue_t queue,
588 dispatch_continuation_t start, size_t count,
589 dispatch_introspection_queue_item_t items);
590
591 /*!
592 * @function dispatch_introspection_queue_get_info
593 *
594 * @abstract
595 * Retrieve introspection information about a specified dispatch queue.
596 *
597 * @discussion
598 * Retrieving queue information must take place from a debugger context (while
599 * the rest of the process is suspended).
600 *
601 * @param queue
602 * Queue to introspect.
603 *
604 * @result
605 * Queue information struct.
606 */
607 extern dispatch_introspection_queue_s
608 dispatch_introspection_queue_get_info(dispatch_queue_t queue);
609
610 /*!
611 * @function dispatch_introspection_queue_item_get_info
612 *
613 * @abstract
614 * Retrieve introspection information about a specified dispatch queue item.
615 *
616 * @discussion
617 * Retrieving queue item information must take place from a debugger context
618 * (while the rest of the process is suspended).
619 *
620 * @param queue
621 * Queue to introspect.
622 *
623 * @param item
624 * Item to introspect.
625 *
626 * @result
627 * Queue item information struct.
628 */
629 extern dispatch_introspection_queue_item_s
630 dispatch_introspection_queue_item_get_info(dispatch_queue_t queue,
631 dispatch_continuation_t item);
632
633 /*!
634 * @function dispatch_introspection_hooks_install
635 *
636 * @abstract
637 * Install hook functions into libdispatch.
638 *
639 * @discussion
640 * Installing hook functions must take place from a debugger context (while the
641 * rest of the process is suspended).
642 *
643 * The caller is responsible for implementing chaining to the hooks that were
644 * previously installed (if any).
645 *
646 * @param hooks
647 * Pointer to structure of hook function pointers. Any of the structure members
648 * may be NULL to indicate that the hook in question should not be installed.
649 * The structure is copied on input and filled with the previously installed
650 * hooks on output.
651 */
652
653 extern void
654 dispatch_introspection_hooks_install(dispatch_introspection_hooks_t hooks);
655
656 /*!
657 * @function dispatch_introspection_hook_callouts_enable
658 *
659 * @abstract
660 * Enable hook callout functions in libdispatch that a debugger can break on
661 * and get introspection arguments even if there are no hook functions
662 * installed via dispatch_introspection_hooks_install().
663 *
664 * @discussion
665 * Enabling hook callout functions must take place from a debugger context
666 * (while the rest of the process is suspended).
667 *
668 * @param enable
669 * Pointer to dispatch_introspection_hooks_s structure. For every structure
670 * member with (any) non-NULL value, the corresponding hook callout will be
671 * enabled; for every NULL member the hook callout will be disabled (if there
672 * is no hook function installed).
673 * As a convenience, the 'enable' pointer may itself be NULL to indicate that
674 * all hook callouts should be enabled.
675 */
676
677 extern void
678 dispatch_introspection_hook_callouts_enable(
679 dispatch_introspection_hooks_t enable);
680
681 /*!
682 * @function dispatch_introspection_hook_callout_queue_create
683 *
684 * @abstract
685 * Callout to queue creation hook that a debugger can break on.
686 */
687
688 extern void
689 dispatch_introspection_hook_callout_queue_create(
690 dispatch_introspection_queue_t queue_info);
691
692 /*!
693 * @function dispatch_introspection_hook_callout_queue_dispose
694 *
695 * @abstract
696 * Callout to queue destruction hook that a debugger can break on.
697 */
698
699 extern void
700 dispatch_introspection_hook_callout_queue_dispose(
701 dispatch_introspection_queue_t queue_info);
702
703 /*!
704 * @function dispatch_introspection_hook_callout_queue_item_enqueue
705 *
706 * @abstract
707 * Callout to queue enqueue hook that a debugger can break on.
708 */
709
710 extern void
711 dispatch_introspection_hook_callout_queue_item_enqueue(
712 dispatch_queue_t queue, dispatch_introspection_queue_item_t item);
713
714 /*!
715 * @function dispatch_introspection_hook_callout_queue_item_dequeue
716 *
717 * @abstract
718 * Callout to queue dequeue hook that a debugger can break on.
719 */
720
721 extern void
722 dispatch_introspection_hook_callout_queue_item_dequeue(
723 dispatch_queue_t queue, dispatch_introspection_queue_item_t item);
724
725 __END_DECLS
726
727 #endif