]> git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSMetaClass.h
21b4f40e625647f0ce72371e8f50564e3b151256
[apple/xnu.git] / libkern / libkern / c++ / OSMetaClass.h
1 /*
2 * Copyright (c) 2000-2016 Apple 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 #ifndef _LIBKERN_OSMETACLASS_H
29 #define _LIBKERN_OSMETACLASS_H
30
31 #include <sys/types.h>
32
33 #include <libkern/OSReturn.h>
34 #include <kern/debug.h>
35
36 /*
37 * LIBKERN_ macros below can be used to describe the ownership semantics
38 * of functions handling subclasses of OSObject.
39 * The attributes propagate with inheritance, but can be overriden.
40 * New versions of the Clang Static Analyzer can use this knowledge to
41 * check the code for leaks or uses-after-free.
42 */
43
44 /*
45 * By default, methods returning OSObjects are assumed to have the following
46 * owneship semantics:
47 * - Methods which start with "get" are "Get" and which are not returning
48 * a subclass of OSIterator are assumed to be getters.
49 * They return at "+0" and the caller is not responsible for releasing the
50 * returned object.
51 *
52 * - All other methods are assumed to return at "+1", and the caller is
53 * responsible for releasing the returned object.
54 *
55 * The semantics implied by the naming convention described above can be
56 * overriden using either LIBKERN_RETURNS_RETAINED or LIBKERN_RETURNS_NOT_RETAINED
57 * attribute applied to a function.
58 * In the former case, it stipulates that the function is returning at "+1",
59 * and in the latter case "+0".
60 */
61 #if __has_attribute(os_returns_retained)
62 #define LIBKERN_RETURNS_RETAINED __attribute__((os_returns_retained))
63 #else
64 #define LIBKERN_RETURNS_RETAINED
65 #endif
66 #if __has_attribute(os_returns_not_retained)
67 #define LIBKERN_RETURNS_NOT_RETAINED __attribute__((os_returns_not_retained))
68 #else
69 #define LIBKERN_RETURNS_NOT_RETAINED
70 #endif
71
72 /*
73 * LIBKERN_CONSUMED attribute can be applied to parameters.
74 * It specifies that this function call would consume the reference to the
75 * annotated parameter.
76 */
77 #if __has_attribute(os_consumed)
78 #define LIBKERN_CONSUMED __attribute__((os_consumed))
79 #else
80 #define LIBKERN_CONSUMED
81 #endif
82
83 /*
84 * LIBKERN_CONSUMES_THIS attribute can be applied to methods.
85 * It specifies that this method call consumes a reference to "this" (e.g.
86 * by storing a reference to "this" in a passed parameter).
87 */
88 #if __has_attribute(os_consumes_this)
89 #define LIBKERN_CONSUMES_THIS __attribute__((os_consumes_this))
90 #else
91 #define LIBKERN_CONSUMES_THIS
92 #endif
93
94 class OSMetaClass;
95 class OSObject;
96 class OSString;
97 class OSSymbol;
98 class OSDictionary;
99 class OSSerialize;
100 #ifdef XNU_KERNEL_PRIVATE
101 class OSOrderedSet;
102 class OSCollection;
103 #endif /* XNU_KERNEL_PRIVATE */
104
105
106 /*!
107 * @header
108 *
109 * @abstract
110 * This header declares the OSMetaClassBase and OSMetaClass classes,
111 * which together form the basis of the Libkern and I/O Kit C++ class hierarchy
112 * and run-time type information facility.
113 */
114
115
116 /*! @parseOnly */
117 #define APPLE_KEXT_COMPATIBILITY
118
119 #ifdef XNU_KERNEL_PRIVATE
120
121 #ifdef CONFIG_EMBEDDED
122 #define APPLE_KEXT_VTABLE_PADDING 0
123 #else /* CONFIG_EMBEDDED */
124 /*! @parseOnly */
125 #define APPLE_KEXT_VTABLE_PADDING 1
126 #endif /* CONFIG_EMBEDDED */
127
128 #else /* XNU_KERNEL_PRIVATE */
129 #include <TargetConditionals.h>
130
131 #if TARGET_OS_EMBEDDED
132 #define APPLE_KEXT_VTABLE_PADDING 0
133 #else /* TARGET_OS_EMBEDDED */
134 /*! @parseOnly */
135 #define APPLE_KEXT_VTABLE_PADDING 1
136 #endif /* TARGET_OS_EMBEDDED */
137
138 #endif /* XNU_KERNEL_PRIVATE */
139
140 #define APPLE_KEXT_ALIGN_CONTAINERS (0 == APPLE_KEXT_VTABLE_PADDING)
141
142 #if defined(__LP64__)
143 /*! @parseOnly */
144 #define APPLE_KEXT_LEGACY_ABI 0
145 #elif defined(__arm__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
146 #define APPLE_KEXT_LEGACY_ABI 0
147 #else
148 #define APPLE_KEXT_LEGACY_ABI 1
149 #endif
150
151 #if defined(__LP64__)
152 /*! @parseOnly */
153 #define APPLE_KEXT_COMPATIBILITY_VIRTUAL
154 #else
155 // private method made virtual only for binary compatibility
156 #define APPLE_KEXT_COMPATIBILITY_VIRTUAL virtual
157 #endif
158
159 /*! @parseOnly */
160 #define APPLE_KEXT_DEPRECATED __attribute__((deprecated))
161
162
163 #if __cplusplus >= 201103L
164 #define APPLE_KEXT_OVERRIDE override
165 #if defined(__LP64__)
166 #define APPLE_KEXT_COMPATIBILITY_OVERRIDE
167 #else
168 #define APPLE_KEXT_COMPATIBILITY_OVERRIDE APPLE_KEXT_OVERRIDE
169 #endif
170 #else
171 #define APPLE_KEXT_OVERRIDE
172 #define APPLE_KEXT_COMPATIBILITY_OVERRIDE
173 #endif
174
175 #define APPLE_KEXT_WSHADOW_PUSH _Pragma("clang diagnostic push"); \
176 _Pragma("clang diagnostic ignored \"-Wunknown-warning-option\"") \
177 _Pragma("clang diagnostic ignored \"-Wshadow-field\"")
178
179 #define APPLE_KEXT_WSHADOW_POP _Pragma("clang diagnostic pop")
180
181
182 /*!
183 * @class OSMetaClassBase
184 *
185 * @abstract
186 * OSMetaClassBase is the abstract bootstrap class
187 * for the Libkern and I/O Kit run-time type information system.
188 *
189 * @discussion
190 * OSMetaClassBase is the abstract C++ root class
191 * underlying the entire Libkern and I/O Kit class hierarchy.
192 * It defines the run-time type information system,
193 * including dynamic class allocation and safe type-casting,
194 * as well as the abstract interface for reference counting
195 * and a few other utility functions.
196 * OSMetaClassBase is the immediate superclass of
197 * @link //apple_ref/doc/class/OSObject OSObject@/link and
198 * @link //apple_ref/doc/class/OSMetaClass OSMetaClass@/link;
199 * no other class should derive from OSMetaClassBase.
200 *
201 * For more information, see
202 * <i>@link //apple_ref/doc/uid/TP40002799
203 * I/O Kit Device Driver Design Guidelines@/link</i>.
204 *
205 * <b>Use by Kernel Extensions</b>
206 *
207 * Kernel Extensions should never interact directly with OSMetaClassBase,
208 * but they will find useful several macros that tie in
209 * to the run-time type information system, specifically:
210 * <ul>
211 * <li><code>@link OSTypeAlloc OSTypeAlloc@/link</code> - allocation of new instances</li>
212 * <li><code>@link OSDynamicCast OSDynamicCast@/link</code> - safe type casting</li>
213 * <li><code>@link OSCheckTypeInst OSCheckTypeInst@/link</code> -
214 * checking for inheritance/derivation</li>
215 * <li><code>@link OSMemberFunctionCast OSMemberFunctionCast@/link</code> -
216 * casting C++ member functions to C function pointers
217 * for registration as callbacks</li>
218 * </ul>
219 *
220 * See @link //apple_ref/doc/class/OSMetaClass OSMetaClass@/link
221 * for more run-time type information interfaces.
222 *
223 * <b>Use Restrictions</b>
224 *
225 * OSMetaClassBase should not be subclassed by kernel extensions,
226 * nor should kernel extensions call its run-time type functions directly.
227 *
228 * The run-time type functions and macros are <b>not safe</b>
229 * to call in a primary interrupt context.
230 *
231 * <b>Concurrency Protection</b>
232 *
233 * The run-time type macros and functions of OSMetaClassBase are thread-safe.
234 */
235 class OSMetaClassBase
236 {
237 public:
238
239
240 /*!
241 * @define OSTypeAlloc
242 * @hidecontents
243 *
244 * @abstract
245 * Allocates an instance of the named object class.
246 *
247 * @param type The name of the desired class to be created,
248 * as a raw token, <i>not</i> a string or macro.
249 *
250 * @result
251 * A pointer to the new, uninitialized object on success;
252 * <code>NULL</code> on failure.
253 *
254 * @discussion
255 * See also
256 * <code>@link
257 * //apple_ref/cpp/clm/OSMetaClass/allocClassWithName/staticOSObject*\/(constchar*)
258 * OSMetaClass::allocClassWithName(const char *)@/link</code>
259 * and
260 * <code>@link
261 * //apple_ref/cpp/instm/OSMetaClass/alloc/virtualOSObject*\/()
262 * OSMetaClass::alloc@/link</code>.
263 *
264 * The OSTypeAlloc macro is used to avoid binary compatibility difficulties
265 * presented by the C++ <code>new</code> operator.
266 */
267 #define OSTypeAlloc(type) ((type *) ((type::metaClass)->alloc()))
268
269
270 /*!
271 * @define OSTypeID
272 * @hidecontents
273 *
274 * @abstract
275 * Returns the type ID (metaclass) of a class based on its name.
276 *
277 * @param type The name of the desired class, as a raw token,
278 * <i>not</i> a string or macro.
279 *
280 * @result
281 * The unique type ID (metaclass) for the class.
282 *
283 * @discussion
284 * It is typically more useful to determine whether a class is derived
285 * from another; see
286 * <code>@link //apple_ref/cpp/macro/OSDynamicCast OSDynamicCast@/link</code>
287 * and
288 * <code>@link //apple_ref/cpp/macro/OSCheckTypeInst OSCheckTypeInst@/link</code>.
289 */
290 #define OSTypeID(type) (type::metaClass)
291
292
293 /*!
294 * @define OSTypeIDInst
295 * @hidecontents
296 *
297 * @abstract
298 * Returns the type ID (metaclass) for the class of an object instance.
299 *
300 * @param typeinst An instance of an OSObject subclass.
301 *
302 * @result
303 * The type ID of that object's class; that is, its metaclass.
304 *
305 * @discussion
306 * It is typically more useful to determine whether an object is derived
307 * from a particular class; see
308 * <code>@link //apple_ref/cpp/macro/OSDynamicCast OSDynamicCast@/link</code>
309 * and
310 * <code>@link //apple_ref/cpp/macro/OSCheckTypeInst OSCheckTypeInst@/link</code>.
311 */
312 #define OSTypeIDInst(typeinst) ((typeinst)->getMetaClass())
313
314
315 /*!
316 * @define OSDynamicCast
317 * @hidecontents
318 *
319 * @abstract
320 * Safe type-casting for Libkern C++ objects.
321 *
322 * @param type The name of the desired class type, as a raw token,
323 * <i>not</i> a string or macro.
324 * It is assumed you intend to cast to a pointer
325 * to an object of this type.
326 * Type qualifiers, such as <code>const</code>,
327 * are not recognized and will cause
328 * a (usually obscure) compile error.
329 * @param inst A pointer to the object instance to be cast.
330 * May be <code>NULL</code>.
331 *
332 * @result
333 * <code>inst</code> if it is non-<code>NULL</code>
334 * and derived from <code>type</code>;
335 * otherwise <code>NULL</code>.
336 *
337 * @discussion
338 * <code>OSDynamicCast</code> is a rough equivalent
339 * to the standard C++ RTTI <code>dynamic_cast&lt;T&gt;</code> operator.
340 * Your code should use this instead of raw C type-casting,
341 * and check the resulting value.
342 * If the result is non-<code>NULL</code>,
343 * the object is safe to use as the type-cast class;
344 * if the result is <code>NULL</code>,
345 * the object does not derive from the type-cast class
346 * and your code should take appropriate steps to handle the error.
347 */
348 #define OSDynamicCast(type, inst) \
349 ((type *) OSMetaClassBase::safeMetaCast((inst), OSTypeID(type)))
350
351
352 /*!
353 * @define OSCheckTypeInst
354 * @hidecontents
355 *
356 * @abstract
357 * Checks whether two objects are type-compatible.
358 *
359 * @param typeinst The reference object.
360 * @param inst The object to check for type compatibility.
361 *
362 * @result
363 * <code>true</code> if both <code>inst</code> and
364 * <code>typeinst</code> are non-<code>NULL</code>
365 * and <code>inst</code> is derived from the class of <code>typeinst</code>;
366 * otherwise <code>false</code>.
367 */
368 #define OSCheckTypeInst(typeinst, inst) \
369 OSMetaClassBase::checkTypeInst(inst, typeinst)
370
371 #define OSSafeRelease(inst) \
372 do { int OSSafeRelease __attribute__ ((deprecated("Use OSSafeReleaseNULL"))); (OSSafeRelease); \
373 if (inst) (inst)->release(); } while (0)
374
375 /*! @function OSSafeReleaseNULL
376 * @abstract Release an object if not <code>NULL</code>, then set it to <code>NULL</code>.
377 * @param inst Instance of an OSObject, may be <code>NULL</code>.
378 */
379 #define OSSafeReleaseNULL(inst) do { if (inst != NULL) (inst)->release(); (inst) = NULL; } while (0)
380
381 typedef void (*_ptf_t)(void);
382
383 #if defined(__arm__) || defined(__arm64__)
384
385 static _ptf_t _ptmf2ptf(const OSMetaClassBase * self, void (OSMetaClassBase::*func)(void));
386
387 #elif defined(__i386__) || defined(__x86_64__)
388
389 // Slightly less arcane and slightly less evil code to do
390 // the same for kexts compiled with the standard Itanium C++
391 // ABI
392
393 static inline _ptf_t
394 _ptmf2ptf(const OSMetaClassBase *self, void (OSMetaClassBase::*func)(void))
395 {
396 union {
397 void (OSMetaClassBase::*fIn)(void);
398 uintptr_t fVTOffset;
399 _ptf_t fPFN;
400 } map;
401
402 map.fIn = func;
403
404 if (map.fVTOffset & 1) {
405 // virtual
406 union {
407 const OSMetaClassBase *fObj;
408 _ptf_t **vtablep;
409 } u;
410 u.fObj = self;
411
412 // Virtual member function so dereference vtable
413 return *(_ptf_t *)(((uintptr_t)*u.vtablep) + map.fVTOffset - 1);
414 } else {
415 // Not virtual, i.e. plain member func
416 return map.fPFN;
417 }
418 }
419
420 #else
421 #error Unknown architecture.
422 #endif /* __arm__ */
423
424
425 /*!
426 * @define OSMemberFunctionCast
427 * @hidecontents
428 *
429 * @abstract
430 * Converts a C++ member function pointer, relative to an instance,
431 * to a C-style pointer to function.
432 *
433 * @param cptrtype The function type declaration to cast to
434 * (typically provided as a <code>typedef</code> by I/O KitKit classes).
435 * @param self The <code>this</code> pointer of the object whose function
436 * you wish to cache.
437 * @param func The pointer to the member function itself,
438 * something like <code>&Class::function</code>.
439 *
440 * @result
441 * A pointer to a function of the given type referencing <code>self</code>.
442 *
443 * @discussion
444 * This function is used to generate pointers to C++ functions for instances,
445 * such that they can be registered as callbacks with I/O Kit objects.
446 *
447 * No warnings are generated.
448 *
449 * This function will panic if an attempt is made to call it
450 * with a multiply-inheriting class.
451 */
452 #define OSMemberFunctionCast(cptrtype, self, func) \
453 (cptrtype) OSMetaClassBase:: \
454 _ptmf2ptf(self, (void (OSMetaClassBase::*)(void)) func)
455
456 protected:
457 OSMetaClassBase();
458 virtual
459 ~OSMetaClassBase();
460
461 private:
462 // Disable copy constructors of OSMetaClassBase based objects
463 /* Not to be included in headerdoc.
464 *
465 * @function operator =
466 *
467 * @abstract
468 * Disable implicit copy constructor by making private
469 *
470 * @param src Reference to source object that isn't allowed to be copied.
471 */
472 void operator =(OSMetaClassBase &src);
473
474 /* Not to be included in headerdoc.
475 *
476 * @function OSMetaClassBase
477 *
478 * @abstract
479 * Disable implicit copy constructor by making private
480 *
481 * @param src Reference to source object that isn't allowed to be copied.
482 */
483 OSMetaClassBase(OSMetaClassBase &src);
484
485 public:
486
487 // xx-review: the original comment for this makes it sound to me like we don't
488 // xx-review: catch over-releasing an object...?
489
490 /*!
491 * @function release
492 *
493 * @abstract
494 * Abstract declaration of
495 * <code>@link
496 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/(int)
497 * release(int freeWhen)@/link</code>.
498 *
499 * @discussion
500 * See
501 * <code>@link
502 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/(int)
503 * release(int freeWhen)@/link</code>.
504 */
505 virtual void release(int freeWhen) const = 0;
506
507
508 /*!
509 * @function getRetainCount
510 *
511 * @abstract
512 * Abstract declaration of
513 * <code>@link
514 * //apple_ref/cpp/instm/OSObject/getRetainCount/virtualint/()
515 * getRetainCount()@/link</code>.
516 *
517 * @discussion
518 * See
519 * <code>@link
520 * //apple_ref/cpp/instm/OSObject/getRetainCount/virtualint/()
521 * OSObject::getRetainCount()@/link</code>.
522 */
523 virtual int getRetainCount() const = 0;
524
525
526 /*!
527 * @function retain
528 *
529 * @abstract
530 * Abstract declaration of
531 * <code>@link
532 * //apple_ref/cpp/instm/OSObject/retain/virtualvoid/()
533 * retain()@/link</code>.
534 *
535 * @discussion
536 * See
537 * <code>@link
538 * //apple_ref/cpp/instm/OSObject/retain/virtualvoid/()
539 * OSObject::retain()@/link</code>.
540 */
541 virtual void retain() const = 0;
542
543
544 /*!
545 * @function release
546 *
547 * @abstract
548 * Abstract declaration of
549 * <code>@link
550 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/()
551 * release@/link</code>.
552 *
553 * @discussion
554 * See
555 * <code>@link
556 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/()
557 * OSObject::release@/link</code>.
558 */
559 virtual void release() const = 0;
560
561
562 /*!
563 * @function serialize
564 *
565 * @abstract
566 * Abstract declaration of
567 * <code>@link
568 * //apple_ref/cpp/instm/OSObject/serialize/virtualbool/(OSSerialize*)
569 * serialize@/link</code>.
570 *
571 * @discussion
572 * See
573 * <code>@link
574 * //apple_ref/cpp/instm/OSObject/serialize/virtualbool/(OSSerialize*)
575 * OSObject::serialize@/link</code>.
576 */
577 virtual bool serialize(OSSerialize * serializer) const = 0;
578
579
580 /*!
581 * @function getMetaClass
582 *
583 * @abstract
584 * Returns the OSMetaClass representing
585 * an OSMetaClassBase subclass.
586 *
587 * @discussion
588 * OSObject overrides this abstract member function
589 * to return the OSMetaClass object that represents
590 * each class for run-time typing.
591 */
592 virtual const OSMetaClass * getMetaClass() const = 0;
593
594
595 /*!
596 * @function isEqualTo
597 *
598 * @abstract
599 * Checks whether another object is equal to the receiver.
600 *
601 * @param anObject The object to copmare to the receiver.
602 *
603 * @result
604 * <code>true</code> if the objects are equal, <code>false</code> otherwise.
605 *
606 * @discussion
607 * OSMetaClassBase implements this as a direct pointer comparison,
608 * since it has no other information to judge equality by.
609 * Subclasses generally override this function
610 * to do a more meaningful comparison.
611 * For example, OSString implements it to return
612 * <code>true</code> if <code>anObject</code>
613 * is derived from OSString and represents the same C string.
614 */
615 virtual bool isEqualTo(const OSMetaClassBase * anObject) const;
616
617
618 /*!
619 * @function metaCast
620 *
621 * @abstract
622 * Casts this object is to the class managed by the given OSMetaClass.
623 *
624 * @param toMeta A pointer to a constant OSMetaClass
625 * for the desired target type.
626 *
627 * @result
628 * <code>this</code> if the object is derived
629 * from the class managed by <code>toMeta</code>,
630 * otherwise <code>NULL</code>.
631 *
632 * @discussion
633 * It is far more convenient to use
634 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
635 */
636 OSMetaClassBase * metaCast(const OSMetaClass * toMeta) const;
637
638
639 /*!
640 * @function metaCast
641 *
642 * @abstract
643 * Casts this object is to the class managed by the named OSMetaClass.
644 *
645 * @param toMeta An OSSymbol naming the desired target type.
646 *
647 * @result
648 * <code>this</code> if the object is derived
649 * from the class named by <code>toMeta</code>,
650 * otherwise <code>NULL</code>.
651 *
652 * @discussion
653 * It is far more convenient to use
654 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
655 */
656 OSMetaClassBase * metaCast(const OSSymbol * toMeta) const;
657
658
659 /*!
660 * @function metaCast
661 *
662 * @abstract
663 * Casts this object is to the class managed by the named OSMetaClass.
664 *
665 * @param toMeta An OSString naming the desired target type.
666 * @result
667 * <code>this</code> if the object is derived
668 * from the class named by <code>toMeta</code>,
669 * otherwise <code>NULL</code>.
670 *
671 * @discussion
672 * It is far more convenient to use
673 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
674 */
675 OSMetaClassBase * metaCast(const OSString * toMeta) const;
676
677
678 /*!
679 * @function metaCast
680 *
681 * @abstract
682 * Casts this object is to the class managed by the named OSMetaClass.
683 *
684 * @param toMeta A C string naming the desired target type.
685 * @result
686 * <code>this</code> if the object is derived
687 * from the class named by <code>toMeta</code>,
688 * otherwise <code>NULL</code>.
689 *
690 * @discussion
691 * It is far more convenient to use
692 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
693 */
694 OSMetaClassBase * metaCast(const char * toMeta) const;
695
696 // Helper inlines for run-time type preprocessor macros
697 /*!
698 * @function safeMetaCast
699 *
700 * @abstract
701 * Casts an object is to the class managed by the given OSMetaClass.
702 *
703 * @param anObject A pointer to the object to be cast.
704 * @param toMeta A pointer to a constant OSMetaClass
705 * for the desired target type.
706 *
707 * @result
708 * <code>anObject</code> if the object is derived
709 * from the class managed by <code>toMeta</code>,
710 * otherwise <code>NULL</code>.
711 *
712 * @discussion
713 * It is far more convenient to use
714 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
715 */
716 static OSMetaClassBase * safeMetaCast(
717 const OSMetaClassBase * anObject,
718 const OSMetaClass * toMeta);
719
720 /*!
721 * @function checkTypeInst
722 *
723 * @abstract
724 * Checks whether an object instance is of the same class
725 * as another object instance (or a subclass of that class).
726 *
727 * @param inst A pointer to the object to check.
728 * @param typeinst A pointer to an object of the class being checked.
729 *
730 * @result
731 * <code>true</code> if the object is derived
732 * from the class of <code>typeinst</code>
733 * or a subclass of that class,
734 * otherwise <code>false</code>.
735 *
736 * @discussion
737 * It is far more convenient to use
738 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
739 */
740 static bool checkTypeInst(
741 const OSMetaClassBase * inst,
742 const OSMetaClassBase * typeinst);
743
744 static void initialize(void);
745
746 public:
747
748 /*!
749 * @function taggedRetain
750 *
751 * @abstract
752 * Abstract declaration of
753 * <code>@link
754 * //apple_ref/cpp/instm/OSObject/taggedRetain/virtualvoid/(constvoid*)
755 * taggedRetain(const void *)@/link</code>.
756 *
757 * @discussion
758 * See
759 * <code>@link
760 * //apple_ref/cpp/instm/OSObject/taggedRetain/virtualvoid/(constvoid*)
761 * OSObject::taggedRetain(const void *)@/link</code>.
762 */
763 // WAS: virtual void _RESERVEDOSMetaClassBase0();
764 virtual void taggedRetain(const void * tag = 0) const = 0;
765
766
767 /*!
768 * @function taggedRelease
769 *
770 * @abstract
771 * Abstract declaration of
772 * <code>@link
773 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*)
774 * taggedRelease(const void *)@/link</code>.
775 *
776 * @discussion
777 * See
778 * <code>@link
779 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*)
780 * OSObject::taggedRelease(const void *)@/link</code>.
781 */
782 // WAS: virtual void _RESERVEDOSMetaClassBase1();
783 virtual void taggedRelease(const void * tag = 0) const = 0;
784
785 protected:
786 /*!
787 * @function taggedRelease
788 *
789 * @abstract
790 * Abstract declaration of
791 * <code>@link
792 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*,constint)
793 * taggedRelease(const void *, const int freeWhen)@/link</code>.
794 *
795 * @discussion
796 * See
797 * <code>@link
798 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*,constint)
799 * OSObject::taggedRelease(const void *, const int freeWhen)@/link</code>.
800 */
801 // WAS: virtual void _RESERVEDOSMetaClassBase2();
802 virtual void taggedRelease(
803 const void * tag,
804 const int freeWhen) const = 0;
805
806 private:
807 #if APPLE_KEXT_VTABLE_PADDING
808 // Virtual Padding
809 virtual void _RESERVEDOSMetaClassBase3();
810 virtual void _RESERVEDOSMetaClassBase4();
811 virtual void _RESERVEDOSMetaClassBase5();
812 virtual void _RESERVEDOSMetaClassBase6();
813 virtual void _RESERVEDOSMetaClassBase7();
814 #endif
815 } APPLE_KEXT_COMPATIBILITY;
816
817
818 #ifdef XNU_KERNEL_PRIVATE
819 typedef bool (*OSMetaClassInstanceApplierFunction)(const OSObject * instance,
820 void * context);
821 #endif /* XNU_KERNEL_PRIVATE */
822
823 /*!
824 * @class OSMetaClass
825 *
826 * @abstract
827 * OSMetaClass manages run-time type information
828 * for Libkern and I/O Kit C++ classes.
829 *
830 * @discussion OSMetaClass manages run-time type information
831 * for Libkern and I/O Kit C++ classes.
832 * An instance of OSMetaClass exists for (nearly) every such C++ class,
833 * keeping track of inheritance relationships, class lookup by name,
834 * instance counts, and more.
835 * OSMetaClass operates almost entirely behind the scenes,
836 * and kernel extensions should rarely, if ever,
837 * have to interact directly with OSMetaClass.
838 *
839 * <b>Use by Kernel Extensions</b>
840 *
841 * While kernel extensions rarey interact directly with OSMetaClass at run time,
842 * they must register their classes with the metaclass system
843 * using the macros declared here.
844 * The class declaration should use one of these two macros
845 * before its first member function declaration:
846 * <ul>
847 * <li><code>@link OSDeclareDefaultStructors OSDeclareDefaultStructors@/link</code> -
848 * for classes with no abstract member function declarations</li>
849 * <li><code>@link OSDeclareAbstractStructors OSDeclareAbstractStructors@/link</code> -
850 * for classes with at least one abstract member function declaration</li>
851 * <li><code>@link OSDeclareFinalStructors OSDeclareFinalStructors@/link</code> -
852 * for classes that should not be subclassable by another kext</li>
853 * </ul>
854 *
855 * The class implementation should then use one of these macros:
856 * <ul>
857 * <li><code>@link OSDefineMetaClassAndStructors
858 * OSDefineMetaClassAndStructors@/link</code> -
859 * for classes with no abstract member function declarations</li>
860 * <li><code>@link OSDefineMetaClassAndAbstractStructors
861 * OSDefineMetaClassAndAbstractStructors@/link</code> -
862 * for classes with at least one abstract member function declaration</li>
863 * <li><code>@link OSDefineMetaClassAndFinalStructors
864 * OSDefineMetaClassAndFinalStructors@/link</code> -
865 * for classes that should not be subclassable by another kext</li>
866 * </ul>
867 *
868 * Classes in kernel extensions that are intended for use as libraries
869 * may need to reserve vtable slots to preserve binary compatibility
870 * as new functions are added. They may do so with these macros:
871 * <ul>
872 * <li><code>@link OSMetaClassDeclareReservedUnused
873 * OSMetaClassDeclareReservedUnused@/link</code> -
874 * reserves a vtable slot</li>
875 * <li><code>@link OSMetaClassDefineReservedUnused
876 * OSMetaClassDefineReservedUnused@/link</code> -
877 * defines the reserved vtable slot as an unimplemented function</li>
878 * <li><code>@link OSMetaClassDeclareReservedUsed
879 * OSMetaClassDeclareReservedUsed@/link</code> -
880 * documents that a formerly reserved slot is now used</li>
881 * <li><code>@link OSMetaClassDefineReservedUsed
882 * OSMetaClassDefineReservedUsed@/link</code> -
883 * documents that a formerly reserved slot is now used</li>
884 * </ul>
885 *
886 * <b>Use Restrictions</b>
887 *
888 * OSMetaClass should not be explicitly subclassed by kernel extensions
889 * (the declare/define macros do that),
890 * nor should kernel extensions call its run-time type functions directly.
891 *
892 * OSMetaClass functions should be considered
893 * <b>unsafe</b> to call in a primary interrupt context.
894 *
895 * <b>Concurrency Protection</b>
896 *
897 * Kernel extensions should in general not interact
898 * with OSMetaClass objects directly,
899 * instead using the run-time type macros.
900 * Much of OSMetaClass's interface is intended for use
901 * by the run-time type information system,
902 * which handles concurrency and locking internally.
903 */
904 class OSMetaClass : private OSMetaClassBase
905 {
906 friend class OSKext;
907 #if IOKITSTATS
908 friend class IOStatistics;
909 #endif
910
911 private:
912 // Can never be allocated must be created at compile time
913 static void * operator new(size_t size);
914
915 /* Reserved for future use. (Internal use only) */
916 struct ExpansionData *reserved;
917
918 /* superClass Handle to the superclass's meta class. */
919 const OSMetaClass *superClassLink;
920
921 /* className OSSymbol of the class' name. */
922 const OSSymbol *className;
923
924 /* classSize How big is a single instance of this class. */
925 unsigned int classSize;
926
927 /* instanceCount Roughly number of instances of the object,
928 * +1 for each direct subclass with a nonzero refcount.
929 * Used primarily as a code-in-use flag.
930 */
931 mutable unsigned int instanceCount;
932
933 /* Not to be included in headerdoc.
934 *
935 * @function OSMetaClass
936 *
937 * @abstract
938 * The default private constructor.
939 */
940 OSMetaClass();
941
942 // Called by postModLoad
943 /* Not to be included in headerdoc.
944 *
945 * @function logError
946 *
947 * @abstract
948 * Logs an error string for an <code>OSReturn</code> value
949 * using <code>printf</code>.
950 *
951 * @param result The <code>OSReturn</code> value for which to log a message.
952 *
953 * @discussion
954 * This function is used to log errors loading kernel extensions.
955 * Kernel extensions themselves should not call it.
956 */
957 static void logError(OSReturn result);
958
959 public:
960
961 /*!
962 * @function getMetaClassWithName
963 *
964 * @abstract
965 * Look up a metaclass in the run-time type information system.
966 *
967 * @param name The name of the desired class's metaclass.
968 *
969 * @result
970 * A pointer to the metaclass object if found, <code>NULL</code> otherwise.
971 */
972 static const OSMetaClass * getMetaClassWithName(const OSSymbol * name);
973
974 #if XNU_KERNEL_PRIVATE
975
976 /*!
977 * @function copyMetaClassWithName
978 *
979 * @abstract
980 * Look up a metaclass in the run-time type information system.
981 *
982 * @param name The name of the desired class's metaclass.
983 *
984 * @result
985 * A pointer to the metaclass object if found, <code>NULL</code> otherwise.
986 * The metaclass will be protected from unloading until releaseMetaClass()
987 * is called.
988 */
989 static const OSMetaClass * copyMetaClassWithName(const OSSymbol * name);
990 /*!
991 * @function releaseMetaClass
992 *
993 * @abstract
994 * Releases reference obtained from copyMetaClassWithName().
995 *
996 * @discussion
997 * The metaclass will be protected from unloading until releaseMetaClass()
998 * is called.
999 */
1000 void releaseMetaClass() const;
1001
1002 #endif /* XNU_KERNEL_PRIVATE */
1003
1004 protected:
1005 /*!
1006 * @function retain
1007 *
1008 * @abstract
1009 * Implements the abstract <code>retain</code> function to do nothing.
1010 *
1011 * @discussion
1012 * Since an OSMetaClass instance must remain in existence
1013 * for as long as its kernel extension is loaded,
1014 * OSMetaClass does not use reference-counting.
1015 */
1016 virtual void retain() const;
1017
1018
1019 /*!
1020 * @function release
1021 *
1022 * @abstract
1023 * Implements the abstract <code>release</code> function to do nothing.
1024 *
1025 * @discussion
1026 * Since an OSMetaClass instance must remain in existence
1027 * for as long as its kernel extension is loaded,
1028 * OSMetaClass does not use reference-counting.
1029 */
1030 virtual void release() const;
1031
1032
1033 /*!
1034 * @function release
1035 *
1036 * @abstract
1037 * Implements the abstract <code>release(int freeWhen)</code>
1038 * function to do nothing.
1039 *
1040 * @param freeWhen Unused.
1041 *
1042 * @discussion
1043 * Since an OSMetaClass instance must remain in existence
1044 * for as long as its kernel extension is loaded,
1045 * OSMetaClass does not use reference-counting.
1046 */
1047 virtual void release(int freeWhen) const;
1048
1049
1050 /*!
1051 * @function taggedRetain
1052 *
1053 * @abstract
1054 * Implements the abstract <code>taggedRetain(const void *)</code>
1055 * function to do nothing.
1056 *
1057 * @param tag Unused.
1058 *
1059 * @discussion
1060 * Since an OSMetaClass instance must remain in existence
1061 * for as long as its kernel extension is loaded,
1062 * OSMetaClass does not use reference-counting.
1063 */
1064 virtual void taggedRetain(const void * tag = 0) const;
1065
1066
1067 /*!
1068 * @function taggedRelease
1069 *
1070 * @abstract
1071 * Implements the abstract <code>taggedRelease(const void *)</code>
1072 * function to do nothing.
1073 *
1074 * @param tag Unused.
1075 *
1076 * @discussion
1077 * Since an OSMetaClass instance must remain in existence
1078 * for as long as its kernel extension is loaded,
1079 * OSMetaClass does not use reference-counting.
1080 */
1081 virtual void taggedRelease(const void * tag = 0) const;
1082
1083
1084 /*!
1085 * @function taggedRelease
1086 *
1087 * @abstract
1088 * Implements the abstract <code>taggedRelease(const void *, cont int)</code>
1089 * function to do nothing.
1090 *
1091 * @param tag Unused.
1092 * @param freeWhen Unused.
1093 *
1094 * @discussion
1095 * Since an OSMetaClass instance must remain in existence
1096 * for as long as its kernel extension is loaded,
1097 * OSMetaClass does not use reference-counting.
1098 */
1099 virtual void taggedRelease(
1100 const void * tag,
1101 const int freeWhen) const;
1102
1103
1104 /*!
1105 * @function getRetainCount
1106 *
1107 * @abstract
1108 * Implements the abstract <code>getRetainCount</code>
1109 * function to return 0.
1110 *
1111 * @result
1112 * Always returns 0.
1113 *
1114 * @discussion
1115 * Since an OSMetaClass instance must remain in existence
1116 * for as long as its kernel extension is loaded,
1117 * OSMetaClass does not use reference-counting.
1118 */
1119 virtual int getRetainCount() const;
1120
1121
1122 /* Not to be included in headerdoc.
1123 *
1124 * @function getMetaClass
1125 *
1126 * @abstract
1127 * Returns the meta-metaclass.
1128 *
1129 * @result
1130 * The metaclass of the OSMetaClass object.
1131 */
1132 virtual const OSMetaClass * getMetaClass() const;
1133
1134
1135 /*!
1136 * @function OSMetaClass
1137 *
1138 * @abstract
1139 * Constructor for OSMetaClass objects.
1140 *
1141 * @param className A C string naming the C++ class
1142 * that this OSMetaClass represents.
1143 * @param superclass The OSMetaClass object representing the superclass
1144 * of this metaclass's class.
1145 * @param classSize The allocation size of the represented C++ class.
1146 *
1147 * @discussion
1148 * This constructor is protected and cannot be used
1149 * to instantiate OSMetaClass directly, as OSMetaClass is an abstract class.
1150 * This function is called during kext loading
1151 * to queue C++ classes for registration.
1152 * See <code>@link preModLoad preModLoad@/link</code> and
1153 * <code>@link postModLoad postModLoad@/link</code>.
1154 */
1155 OSMetaClass(const char * className,
1156 const OSMetaClass * superclass,
1157 unsigned int classSize);
1158
1159
1160 /*!
1161 * @function ~OSMetaClass
1162 *
1163 * @abstract
1164 * Destructor for OSMetaClass objects.
1165 *
1166 * @discussion
1167 * This function is called when the kernel extension that implements
1168 * the metaclass's class is unloaded.
1169 * The destructor removes all references to the class
1170 * from the run-time type information system.
1171 */
1172 virtual
1173 ~OSMetaClass();
1174
1175 // Needs to be overriden as NULL as all OSMetaClass objects are allocated
1176 // statically at compile time, don't accidently try to free them.
1177 void
1178 operator delete(void *, size_t)
1179 {
1180 }
1181
1182 public:
1183 static const OSMetaClass * const metaClass;
1184
1185 /*!
1186 * @function preModLoad
1187 *
1188 * @abstract
1189 * Prepares the run-time type system
1190 * for the creation of new metaclasses
1191 * during loading of a kernel extension (module).
1192 *
1193 * @param kextID The bundle ID of the kext being loaded.
1194 *
1195 * @result
1196 * An opaque handle to the load context
1197 * for the kernel extension on success;
1198 * <code>NULL</code> on failure.
1199 *
1200 * @discussion
1201 * <i>Not for use by kernel extensions.</i>
1202 *
1203 * Prepares the run-time type information system to record and register
1204 * metaclasses created by static constructors until a subsequent call to
1205 * <code>@link postModLoad postModLoad@/link</code>.
1206 * <code>preModLoad</code> takes a lock to ensure processing of a single
1207 * load operation at a time; the lock is released by
1208 * <code>@link postModLoad postModLoad@/link</code>.
1209 * Any OSMetaClass constructed between these two function calls
1210 * will be associated with <code>kextID</code>.
1211 */
1212 static void * preModLoad(const char * kextID);
1213
1214
1215 /*!
1216 * @function checkModLoad
1217 *
1218 * @abstract
1219 * Checks whether the current kext load operation can proceed.
1220 *
1221 * @param loadHandle The opaque handle returned
1222 * by <code>@link preModLoad preModLoad@/link</code>.
1223 * @result
1224 * <code>true</code> if no errors are outstanding
1225 * and the system is ready to process more metaclasses.
1226 *
1227 * @discussion
1228 * <i>Not for use by kernel extensions.</i>
1229 */
1230 static bool checkModLoad(void * loadHandle);
1231
1232
1233 /*!
1234 * @function postModLoad
1235 *
1236 * @abstract
1237 * Registers the metaclasses created during loading of a kernel extension.
1238 *
1239 * @param loadHandle The opaque handle returned
1240 * by <code>@link preModLoad preModLoad@/link</code>.
1241 * @result
1242 * The error code of the first error encountered,
1243 * or
1244 * <code>@link
1245 * //apple_ref/cpp/macro/kOSReturnSuccess
1246 * kOSReturnSuccess@/link</code>
1247 * if no error occurred.
1248 *
1249 * @discussion
1250 * <i>Not for use by kernel extensions.</i>
1251 *
1252 * Called after all static constructors in a kernel extension
1253 * have created metaclasses,
1254 * this function checks for duplicate class names,
1255 * then registers the new metaclasses under the kext ID
1256 * that @link preModLoad preModLoad@/link was called with,
1257 * so that they can be dynamically allocated
1258 * and have their instance counts tracked.
1259 * <code>postModLoad</code> releases the lock taken by
1260 * <code>@link preModLoad preModLoad@/link</code>.
1261 */
1262 static OSReturn postModLoad(void * loadHandle);
1263
1264 /*!
1265 * @function modHasInstance
1266 *
1267 * @abstract
1268 * Returns whether any classes defined by the named
1269 * kernel extension (or their subclasses) have existing instances.
1270 *
1271 * @param kextID The bundle ID of the kernel extension to check.
1272 *
1273 * @result
1274 * <code>true</code> if the kext is found and
1275 * if any class defined by that kext
1276 * has a nonzero instance count,
1277 * <code>false</code> otherwise.
1278 *
1279 * @discussion
1280 * This function is called before a kernel extension's static destructors
1281 * are invoked, prior to unloading the extension.
1282 * If any classes stil have instances or subclasses with instances,
1283 * those classes are logged
1284 * (using <code>@link reportModInstances reportModInstances@/link</code>) and
1285 * the kernel extension is not be unloaded.
1286 */
1287 static bool modHasInstance(const char * kextID);
1288
1289
1290 /*!
1291 * @function reportModInstances
1292 *
1293 * @abstract
1294 * Logs the instance counts for classes
1295 * defined by a kernel extension.
1296 *
1297 * @param kextID The bundle ID of the kernel extension to report on.
1298 *
1299 * @discussion
1300 * This function prints the names and instance counts
1301 * of any class defined by <code>kextID</code>
1302 * that has a nonzero instance count.
1303 * It's called by <code>@link modHasInstance modHasInstance@/link</code>
1304 * to help diagnose problems unloading kernel extensions.
1305 */
1306 static void reportModInstances(const char * kextID);
1307
1308
1309 /*!
1310 * @function considerUnloads
1311 *
1312 * @abstract
1313 * Schedule automatic unloading of unused kernel extensions.
1314 *
1315 * @discussion
1316 * This function schedules a check for kernel extensions
1317 * that can be automatically unloaded,
1318 * canceling any currently scheduled check.
1319 * At that time, any such kexts with no Libkern C++ instances
1320 * and no external references are unloaded.
1321 *
1322 * The I/O Kit calls this function when matching goes idle.
1323 *
1324 * Kernel extensions that define subclasses of
1325 * @link //apple_ref/doc/class/IOService IOService@/link
1326 * are eligible for automatic unloading.
1327 *
1328 * (On releases of Mac OS X prior to Snow Leopard (10.6),
1329 * any kernel extension defining any Libkern C++ class
1330 * was eligible for automatic unloading,
1331 * but that unload did not call the module stop routine.
1332 * Non-I/O Kit kernel extensions that define Libkern C++ subclasses
1333 * should be sure to have OSBundleLibraries declarations that ensure
1334 * they will not load on releases prior to Snow Leopard.)
1335 */
1336 static void considerUnloads();
1337
1338 #if XNU_KERNEL_PRIVATE
1339 static bool removeClasses(OSCollection * metaClasses);
1340 #endif /* XNU_KERNEL_PRIVATE */
1341
1342 /*!
1343 * @function allocClassWithName
1344 *
1345 * @abstract
1346 * Allocates an instance of a named OSObject-derived class.
1347 *
1348 * @param name The name of the desired class.
1349 *
1350 * @result
1351 * A pointer to the newly-allocated, uninitialized object on success;
1352 * <code>NULL</code> on failure.
1353 *
1354 * @discussion
1355 * Kernel extensions should not need to use this function
1356 * directly, instead using static instance-creation functions
1357 * defined by classes.
1358 *
1359 * This function consults the run-time type information system
1360 * to find the metaclass for the named class.
1361 * If it exists, it calls the metaclass's <code>@link alloc alloc@/link</code>
1362 * function and returns the result.
1363 */
1364 static OSObject * allocClassWithName(const OSSymbol * name);
1365
1366
1367 /*!
1368 * function allocClassWithName
1369 *
1370 * @abstract
1371 * Allocates an instance of a named OSObject-derived class.
1372 *
1373 * @param name The name of the desired class.
1374 *
1375 * @result
1376 * A pointer to the newly-allocated, uninitialized object on success;
1377 * <code>NULL</code> on failure.
1378 *
1379 * @discussion
1380 * Kernel extensions should not need to use this function
1381 * directly, instead using static instance-creation functions
1382 * defined by classes.
1383 *
1384 * This function consults the run-time type information system
1385 * to find the metaclass for the named class.
1386 * If it exists, it calls the metaclass's <code>@link alloc alloc@/link</code>
1387 * function and returns the result.
1388 */
1389 static OSObject * allocClassWithName(const OSString * name);
1390
1391
1392 /*!
1393 * function allocClassWithName
1394 *
1395 * @abstract
1396 * Allocates an instance of a named OSObject-derived class.
1397 *
1398 * @param name The name of the desired class.
1399 *
1400 * @result
1401 * A pointer to the newly-allocated, uninitialized object on success;
1402 * <code>NULL</code> on failure.
1403 *
1404 * @discussion
1405 * Kernel extensions should not need to use this function
1406 * directly, instead using static instance-creation functions
1407 * defined by classes.
1408 *
1409 * This function consults the run-time type information system
1410 * to find the metaclass for the named class.
1411 * If it exists, it calls the metaclass's <code>@link alloc alloc@/link</code>
1412 * function and returns the result.
1413 */
1414 static OSObject * allocClassWithName(const char * name);
1415
1416
1417 /*!
1418 * @function checkMetaCastWithName
1419 *
1420 * @abstract
1421 * Search the metaclass inheritance hierarchy by name for an object instance.
1422 *
1423 * @param className The name of the desired class or superclass.
1424 * @param object The object whose metaclass begins the search.
1425 *
1426 * @result
1427 * <code>object</code> if it's derived from <code>className</code>;
1428 * <code>NULL</code> otherwise.
1429 *
1430 * @discussion
1431 * This function is the basis of the Libkern run-time type-checking system.
1432 * Kernel extensions should not use it directly,
1433 * instead using <code>@link OSDynamicCast OSDynamicCast@/link</code> or
1434 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
1435 */
1436 static OSMetaClassBase * checkMetaCastWithName(
1437 const OSSymbol * className,
1438 const OSMetaClassBase * object);
1439
1440 /*!
1441 * @function checkMetaCastWithName
1442 *
1443 * @abstract
1444 * Search the metaclass inheritance hierarchy by name for an object instance.
1445 *
1446 * @param className The name of the desired class or superclass.
1447 * @param object The object whose metaclass begins the search.
1448 *
1449 * @result
1450 * <code>object</code> if it's derived from <code>className</code>;
1451 * <code>NULL</code> otherwise.
1452 *
1453 * @discussion
1454 * Kernel extensions should not use this function directly,
1455 * instead using <code>@link OSDynamicCast OSDynamicCast@/link</code> or
1456 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
1457 */
1458 static OSMetaClassBase * checkMetaCastWithName(
1459 const OSString * className,
1460 const OSMetaClassBase * object);
1461
1462 /*!
1463 * @function checkMetaCastWithName
1464 *
1465 * @abstract
1466 * Search the metaclass inheritance hierarchy by name for an object instance.
1467 *
1468 * @param className The name of the desired class or superclass.
1469 * @param object The object whose metaclass begins the search.
1470 *
1471 * @result
1472 * <code>object</code> if it's derived from <code>className</code>;
1473 * <code>NULL</code> otherwise.
1474 *
1475 * @discussion
1476 * Kernel extensions should not use this function directly,
1477 * instead using <code>@link OSDynamicCast OSDynamicCast@/link</code> or
1478 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
1479 */
1480 static OSMetaClassBase * checkMetaCastWithName(
1481 const char * className,
1482 const OSMetaClassBase * object);
1483
1484
1485 /*!
1486 * @function instanceConstructed
1487 *
1488 * @abstract
1489 * Counts the instances of the class managed by this metaclass.
1490 *
1491 * @discussion
1492 * <i>Not for use by kernel extensions.</i>
1493 *
1494 * Every non-abstract class that inherits from OSObject
1495 * has a default constructor that calls it's own metaclass's
1496 * <code>instanceConstructed</code> function.
1497 * This constructor is defined by the
1498 * <code>@link
1499 * OSDefineMetaClassAndStructors
1500 * OSDefineMetaClassAndStructors@/link</code>
1501 * macro that all OSObject subclasses must use.
1502 *
1503 * If a class's instance count goes from 0 to 1--that is,
1504 * upon the creation of the first instance of that class--the
1505 * superclass's instance count is also incremented.
1506 * This propagates reference counts up the inheritance chain so that
1507 * superclasses are counted as "in use" when subclasses have instances.
1508 */
1509 void instanceConstructed() const;
1510
1511
1512 /*!
1513 * @function instanceDestructed
1514 *
1515 * @abstract
1516 * Counts the instances of the class managed by this metaclass.
1517 *
1518 * @discussion
1519 * Every non-abstract class that inherits from OSObject
1520 * has a default destructor that calls it's own metaclass's
1521 * <code>instanceDestructed</code> function.
1522 * This constructor is defined by the
1523 * @link OSDefineMetaClassAndStructors OSDefineMetaClassAndStructors@/link
1524 * macro that all OSObject subclasses must use.
1525 *
1526 * If a class's instance count goes from 1 to 0--that is,
1527 * upon the destruction of the last instance of that class--the
1528 * superclass's instance count is also decremented.
1529 * This reduces "in use" counts from superclasses when their subclasses
1530 * no longer have instances.
1531 */
1532 void instanceDestructed() const;
1533
1534
1535 /*!
1536 * @function checkMetaCast
1537 *
1538 * @abstract
1539 * Check whether a given object is an instance of the receiving
1540 * metaclass's class or one derived from it.
1541 *
1542 * @param object The object to check for inheritance.
1543 *
1544 * @result
1545 * <code>object</code> if it is derived from the receiver's class,
1546 * <code>NULL</code> if not.
1547 */
1548 OSMetaClassBase * checkMetaCast(const OSMetaClassBase * object) const;
1549
1550
1551 /*!
1552 * @function getInstanceCount
1553 *
1554 * @abstract
1555 * Returns the number of existing instances of the metaclass's class.
1556 *
1557 * @result
1558 * The number of existing instances of the metaclass's class,
1559 * plus 1 for each subclass with any instance.
1560 */
1561 unsigned int getInstanceCount() const;
1562
1563
1564 /*!
1565 * @function getSuperClass
1566 *
1567 * @abstract
1568 * Returns the super-metaclass of the receiver.
1569 *
1570 * @result
1571 * Returns a pointer to the super-metaclass of the receiving
1572 * OSMetaClass, or <code>NULL</code> for OSObject's metaclass.
1573 */
1574 const OSMetaClass * getSuperClass() const;
1575
1576 /*!
1577 * @function getKmodName
1578 *
1579 * @abstract
1580 * Returns the bundle identifier of the kernel extension
1581 * that defines this metaclass.
1582 *
1583 * @result
1584 * The bundle identifier of the kernel extension that defines this metaclass.
1585 *
1586 * @discussion
1587 * "Kmod" is an older term for kernel extension.
1588 */
1589 const OSSymbol * getKmodName() const;
1590
1591
1592 /*!
1593 * @function getClassName
1594 *
1595 * @abstract
1596 * Returns the name of the C++ class managed by this metaclass.
1597 *
1598 * @result
1599 * Returns the name of the C++ class managed by this metaclass.
1600 */
1601 const char * getClassName() const;
1602 const OSSymbol * getClassNameSymbol() const;
1603
1604
1605 /*!
1606 * @function getClassSize
1607 *
1608 * @abstract
1609 * Returns the allocation size of the C++ class managed by this metaclass.
1610 *
1611 * @result
1612 * The allocation size of the C++ class managed by this metaclass.
1613 */
1614 unsigned int getClassSize() const;
1615
1616
1617 /*!
1618 * @function alloc
1619 *
1620 * @abstract
1621 * Allocates an instance of the C++ class managed by this metaclass.
1622 *
1623 * @result
1624 * A pointer to the newly allocated, uninitialized instance,
1625 * with a retain count of 1; <code>NULL</code> on allocation failure.
1626 *
1627 * @discussion
1628 * This function is automatically created by the metaclass-registration macros
1629 * to enable dynamic instance allocation.
1630 */
1631 virtual OSObject * alloc() const = 0;
1632
1633 #ifdef XNU_KERNEL_PRIVATE
1634 void addInstance(const OSObject * instance, bool super = false) const;
1635 void removeInstance(const OSObject * instance, bool super = false) const;
1636 void applyToInstances(OSMetaClassInstanceApplierFunction applier,
1637 void * context) const;
1638 static void applyToInstancesOfClassName(
1639 const OSSymbol * name,
1640 OSMetaClassInstanceApplierFunction applier,
1641 void * context);
1642 private:
1643 static void applyToInstances(OSOrderedSet * set,
1644 OSMetaClassInstanceApplierFunction applier,
1645 void * context);
1646 public:
1647 #endif /* XNU_KERNEL_PRIVATE */
1648
1649 /* Not to be included in headerdoc.
1650 *
1651 * @define OSDeclareCommonStructors
1652 * @hidecontents
1653 *
1654 * @abstract
1655 * Helper macro for for the standard metaclass-registration macros.
1656 * DO NOT USE.
1657 *
1658 * @param className The name of the C++ class, as a raw token,
1659 * <i>not</i> a string or macro.
1660 */
1661 #define OSDeclareCommonStructors(className) \
1662 private: \
1663 static const OSMetaClass * const superClass; \
1664 public: \
1665 static const OSMetaClass * const metaClass; \
1666 static class MetaClass : public OSMetaClass { \
1667 public: \
1668 MetaClass(); \
1669 virtual OSObject *alloc() const; \
1670 } gMetaClass; \
1671 friend class className ::MetaClass; \
1672 virtual const OSMetaClass * getMetaClass() const APPLE_KEXT_OVERRIDE; \
1673 protected: \
1674 className (const OSMetaClass *); \
1675 virtual ~ className () APPLE_KEXT_OVERRIDE
1676
1677
1678 /*!
1679 * @define OSDeclareDefaultStructors
1680 * @hidecontents
1681 *
1682 * @abstract
1683 * Declares run-time type information and functions
1684 * for a concrete Libkern C++ class.
1685 *
1686 * @param className The name of the C++ class, as a raw token,
1687 * <i>not</i> a string or macro.
1688 *
1689 * @discussion
1690 * Concrete Libkern C++ classes should "call" this macro
1691 * immediately after the opening brace in a class declaration.
1692 * It leaves the current privacy state as <code>protected:</code>.
1693 */
1694 #define OSDeclareDefaultStructors(className) \
1695 OSDeclareCommonStructors(className); \
1696 public: \
1697 className (); \
1698 protected:
1699
1700
1701 /*!
1702 * @define OSDeclareAbstractStructors
1703 * @hidecontents
1704 *
1705 * @abstract
1706 * Declares run-time type information and functions
1707 * for an abstract Libkern C++ class.
1708 *
1709 * @param className The name of the C++ class, as a raw token,
1710 * <i>not</i> a string or macro.
1711 *
1712 * @discussion
1713 * Abstract Libkern C++ classes--those with at least one
1714 * pure virtual method--should "call" this macro
1715 * immediately after the opening brace in a class declaration.
1716 * It leaves the current privacy state as <code>protected:</code>.
1717 */
1718 #define OSDeclareAbstractStructors(className) \
1719 OSDeclareCommonStructors(className); \
1720 private: \
1721 className (); /* Make primary constructor private in abstract */ \
1722 protected:
1723
1724 /*!
1725 * @define OSDeclareFinalStructors
1726 * @hidecontents
1727 *
1728 * @abstract
1729 * Declares run-time type information and functions
1730 * for a final (non-subclassable) Libkern C++ class.
1731 *
1732 * @param className The name of the C++ class, as a raw token,
1733 * <i>not</i> a string or macro.
1734 *
1735 * @discussion
1736 * Final Libkern C++ classes--those that do not allow subclassing--should
1737 * "call" this macro immediately after the opening brace in a class declaration.
1738 * (Final classes in the kernel may actually have subclasses in the kernel,
1739 * but kexts cannot define any subclasses of a final class.)
1740 * It leaves the current privacy state as <code>protected:</code>.
1741 *
1742 * <b>Note:</b> If the class is exported by a pseudokext (symbol set),
1743 * the final symbol generated by this macro must be exported
1744 * for the final-class attribute to be enforced.
1745 *
1746 * <b>Warning:</b> Changing a class from "Default" to "Final" will break
1747 * binary compatibility.
1748 */
1749 #define OSDeclareFinalStructors(className) \
1750 OSDeclareDefaultStructors(className) \
1751 private: \
1752 void __OSFinalClass(void); \
1753 protected:
1754
1755
1756 /* Not to be included in headerdoc.
1757 *
1758 * @define OSDefineMetaClassWithInit
1759 * @hidecontents
1760 *
1761 * @abstract
1762 * Helper macro for for the standard metaclass-registration macros.
1763 * DO NOT USE.
1764 *
1765 * @param className The name of the C++ class, as a raw token,
1766 * <i>not</i> a string or macro.
1767 * @param superclassName The name of the superclass of the C++ class,
1768 * as a raw token,
1769 * <i>not</i> a string or macro.
1770 * @param init A function to call in the constructor
1771 * of the class's OSMetaClass.
1772 */
1773 #define OSDefineMetaClassWithInit(className, superclassName, init) \
1774 /* Class global data */ \
1775 className ::MetaClass className ::gMetaClass; \
1776 const OSMetaClass * const className ::metaClass = \
1777 & className ::gMetaClass; \
1778 const OSMetaClass * const className ::superClass = \
1779 & superclassName ::gMetaClass; \
1780 /* Class member functions */ \
1781 className :: className(const OSMetaClass *meta) \
1782 : superclassName (meta) { } \
1783 className ::~ className() { } \
1784 const OSMetaClass * className ::getMetaClass() const \
1785 { return &gMetaClass; } \
1786 /* The ::MetaClass constructor */ \
1787 className ::MetaClass::MetaClass() \
1788 : OSMetaClass(#className, className::superClass, sizeof(className)) \
1789 { init; }
1790
1791
1792 /* Not to be included in headerdoc.
1793 *
1794 * @define OSDefineAbstractStructors
1795 * @hidecontents
1796 *
1797 * @abstract
1798 * Helper macro for for the standard metaclass-registration macros.
1799 * DO NOT USE.
1800 *
1801 * @param className The name of the C++ class, as a raw token,
1802 * <i>not</i> a string or macro.
1803 * @param superclassName The name of the superclass of the C++ class,
1804 * as a raw token,
1805 * <i>not</i> a string or macro.
1806 */
1807 #define OSDefineAbstractStructors(className, superclassName) \
1808 OSObject * className ::MetaClass::alloc() const { return 0; }
1809
1810
1811 /* Not to be included in headerdoc.
1812 *
1813 * @define OSDefineDefaultStructors
1814 * @hidecontents
1815 *
1816 * @abstract
1817 * Helper macro for for the standard metaclass-registration macros.
1818 * DO NOT USE.
1819 *
1820 * @param className The name of the C++ class, as a raw token,
1821 * <i>not</i> a string or macro.
1822 * @param superclassName The name of the superclass of the C++ class,
1823 * as a raw token,
1824 * <i>not</i> a string or macro.
1825 */
1826 #define OSDefineDefaultStructors(className, superclassName) \
1827 OSObject * className ::MetaClass::alloc() const \
1828 { return new className; } \
1829 className :: className () : superclassName (&gMetaClass) \
1830 { gMetaClass.instanceConstructed(); }
1831
1832 /* Not to be included in headerdoc.
1833 *
1834 * @define OSDefineDefaultStructors
1835 * @hidecontents
1836 *
1837 * @abstract
1838 * Helper macro for for the standard metaclass-registration macros.
1839 * DO NOT USE.
1840 *
1841 * @param className The name of the C++ class, as a raw token,
1842 * <i>not</i> a string or macro.
1843 * @param superclassName The name of the superclass of the C++ class,
1844 * as a raw token,
1845 * <i>not</i> a string or macro.
1846 */
1847 #define OSDefineFinalStructors(className, superclassName) \
1848 OSDefineDefaultStructors(className, superclassName) \
1849 void className ::__OSFinalClass(void) { }
1850
1851
1852 /* Not to be included in headerdoc.
1853 *
1854 * @define OSDefineMetaClassAndStructorsWithInit
1855 * @hidecontents
1856 *
1857 * @abstract
1858 * Helper macro for for the standard metaclass-registration macros.
1859 * DO NOT USE.
1860 *
1861 * @param className The name of the C++ class, as a raw token,
1862 * <i>not</i> a string or macro.
1863 * @param superclassName The name of the superclass of the C++ class,
1864 * as a raw token,
1865 * <i>not</i> a string or macro.
1866 * @param init A function to call in the constructor
1867 * of the class's OSMetaClass.
1868 */
1869 #define OSDefineMetaClassAndStructorsWithInit(className, superclassName, init) \
1870 OSDefineMetaClassWithInit(className, superclassName, init) \
1871 OSDefineDefaultStructors(className, superclassName)
1872
1873
1874 /* Not to be included in headerdoc.
1875 *
1876 * @define OSDefineMetaClassAndAbstractStructorsWithInit
1877 * @hidecontents
1878 *
1879 * @abstract
1880 * Helper macro for for the standard metaclass-registration macros.
1881 * DO NOT USE.
1882 *
1883 * @param className The name of the C++ class, as a raw token,
1884 * <i>not</i> a string or macro.
1885 * @param superclassName The name of the superclass of the C++ class,
1886 * as a raw token,
1887 * <i>not</i> a string or macro.
1888 * @param init A function to call in the constructor
1889 * of the class's OSMetaClass.
1890 */
1891 #define OSDefineMetaClassAndAbstractStructorsWithInit(className, superclassName, init) \
1892 OSDefineMetaClassWithInit(className, superclassName, init) \
1893 OSDefineAbstractStructors(className, superclassName)
1894
1895
1896 /* Not to be included in headerdoc.
1897 *
1898 * @define OSDefineMetaClassAndFinalStructorsWithInit
1899 * @hidecontents
1900 *
1901 * @abstract
1902 * Helper macro for for the standard metaclass-registration macros.
1903 * DO NOT USE.
1904 *
1905 * @param className The name of the C++ class, as a raw token,
1906 * <i>not</i> a string or macro.
1907 * @param superclassName The name of the superclass of the C++ class,
1908 * as a raw token,
1909 * <i>not</i> a string or macro.
1910 * @param init A function to call in the constructor
1911 * of the class's OSMetaClass.
1912 */
1913 #define OSDefineMetaClassAndFinalStructorsWithInit(className, superclassName, init) \
1914 OSDefineMetaClassWithInit(className, superclassName, init) \
1915 OSDefineFinalStructors(className, superclassName)
1916
1917
1918 /* Helpers */
1919
1920 /* Not to be included in headerdoc.
1921 *
1922 * @define OSDefineMetaClass
1923 * @hidecontents
1924 *
1925 * @abstract
1926 * Helper macro for for the standard metaclass-registration macros.
1927 * DO NOT USE.
1928 *
1929 * @param className The name of the C++ class, as a raw token,
1930 * <i>not</i> a string or macro.
1931 * @param superclassName The name of the superclass of the C++ class,
1932 * as a raw token,
1933 * <i>not</i> a string or macro.
1934 * @param init A function to call in the constructor
1935 * of the class's OSMetaClass.
1936 */
1937 #define OSDefineMetaClass(className, superclassName) \
1938 OSDefineMetaClassWithInit(className, superclassName, )
1939
1940
1941 /*!
1942 * @define OSDefineMetaClassAndStructors
1943 * @hidecontents
1944 *
1945 * @abstract
1946 * Defines an OSMetaClass and associated routines
1947 * for a concrete Libkern C++ class.
1948 *
1949 * @param className The name of the C++ class, as a raw token,
1950 * <i>not</i> a string or macro.
1951 * @param superclassName The name of the superclass of the C++ class,
1952 * as a raw token,
1953 * <i>not</i> a string or macro.
1954 *
1955 * @discussion
1956 * Concrete Libkern C++ classes should "call" this macro
1957 * at the beginning of their implementation files,
1958 * before any function implementations for the class.
1959 */
1960 #define OSDefineMetaClassAndStructors(className, superclassName) \
1961 OSDefineMetaClassAndStructorsWithInit(className, superclassName, )
1962
1963
1964 /*!
1965 * @define OSDefineMetaClassAndAbstractStructors
1966 * @hidecontents
1967 *
1968 * @abstract
1969 * Defines an OSMetaClass and associated routines
1970 * for an abstract Libkern C++ class.
1971 *
1972 * @param className The name of the C++ class, as a raw token,
1973 * <i>not</i> a string or macro.
1974 * @param superclassName The name of the superclass of the C++ class,
1975 * as a raw token,
1976 * <i>not</i> a string or macro.
1977 *
1978 * @discussion
1979 * Abstract Libkern C++ classes--those with at least one
1980 * pure virtual method--should "call" this macro
1981 * at the beginning of their implementation files,
1982 * before any function implementations for the class.
1983 */
1984 #define OSDefineMetaClassAndAbstractStructors(className, superclassName) \
1985 OSDefineMetaClassAndAbstractStructorsWithInit (className, superclassName, )
1986
1987
1988 /*!
1989 * @define OSDefineMetaClassAndFinalStructors
1990 * @hidecontents
1991 *
1992 * @abstract
1993 * Defines an OSMetaClass and associated routines
1994 * for a final (non-subclassable) Libkern C++ class.
1995 *
1996 * @param className The name of the C++ class, as a raw token,
1997 * <i>not</i> a string or macro.
1998 * @param superclassName The name of the superclass of the C++ class,
1999 * as a raw token,
2000 * <i>not</i> a string or macro.
2001 *
2002 * @discussion
2003 * Final Libkern C++ classes--those that do not allow
2004 * subclassing--should "call" this macro at the beginning
2005 * of their implementation files,
2006 * before any function implementations for the class.
2007 * (Final classes in the kernel may actually have subclasses in the kernel,
2008 * but kexts cannot define any subclasses of a final class.)
2009 *
2010 * <b>Note:</b> If the class is exported by a pseudokext (symbol set),
2011 * the final symbol generated by this macro must be exported
2012 * for the final-class attribute to be enforced.
2013 *
2014 * <b>Warning:</b> Changing a class from "Default" to "Final" will break
2015 * binary compatibility.
2016 */
2017 #define OSDefineMetaClassAndFinalStructors(className, superclassName) \
2018 OSDefineMetaClassAndFinalStructorsWithInit(className, superclassName, )
2019
2020
2021 // Dynamic vtable patchup support routines and types
2022 void reservedCalled(int ind) const;
2023
2024
2025 /*!
2026 * @define OSMetaClassDeclareReservedUnused
2027 * @hidecontents
2028 *
2029 * @abstract
2030 * Reserves vtable space for new virtual functions
2031 * in a Libkern C++ class.
2032 *
2033 * @param className The name of the C++ class, as a raw token,
2034 * <i>not</i> a string or macro.
2035 * @param index The numeric index of the vtable slot,
2036 * as a raw constant, beginning from 0.
2037 *
2038 * @discussion
2039 * Libkern C++ classes in kernel extensions that can be used as libraries
2040 * can provide for backward compatibility by declaring a number
2041 * of reserved vtable slots
2042 * that can be replaced with new functions as they are added.
2043 * Each reserved declaration must be accompanied in the implementation
2044 * by a corresponding reference to
2045 * <code>@link OSMetaClassDefineReservedUnused
2046 * OSMetaClassDefineReservedUnused@/link</code>.
2047 *
2048 * When replacing a reserved slot, change the macro from "Unused"
2049 * to "Used" to document the fact that the slot used to be reserved,
2050 * and declare the new function immediately after the "Used" macro
2051 * to preserve vtable ordering.
2052 * See
2053 * <code>@link OSMetaClassDeclareReservedUsed
2054 * OSMetaClassDeclareReservedUsed@/link</code>.
2055 */
2056 #if APPLE_KEXT_VTABLE_PADDING
2057 #define OSMetaClassDeclareReservedUnused(className, index) \
2058 private: \
2059 virtual void _RESERVED ## className ## index ()
2060 #else
2061 #define OSMetaClassDeclareReservedUnused(className, index)
2062 #endif
2063
2064
2065 /*!
2066 * @define OSMetaClassDeclareReservedUsed
2067 * @hidecontents
2068 *
2069 * @abstract
2070 * Documents use of reserved vtable space for new virtual functions
2071 * in a Libkern C++ class.
2072 *
2073 * @param className The name of the C++ class, as a raw token,
2074 * <i>not</i> a string or macro.
2075 * @param index The numeric index of the vtable slot,
2076 * as a raw constant, beginning from 0.
2077 *
2078 * @discussion
2079 * This macro evaluates to nothing, and is used to document reserved
2080 * vtable slots as they are filled.
2081 * See
2082 * <code>@link OSMetaClassDeclareReservedUnused
2083 * OSMetaClassDeclareReservedUnused@/link</code>.
2084 */
2085 #define OSMetaClassDeclareReservedUsed(className, index)
2086
2087
2088 /*!
2089 * @define OSMetaClassDefineReservedUnused
2090 * @hidecontents
2091 *
2092 * @abstract
2093 * Defines a reserved vtable slot for a Libkern C++ class.
2094 *
2095 * @param className The name of the C++ class, as a raw token,
2096 * <i>not</i> a string or macro.
2097 * @param index The numeric index of the vtable slot,
2098 * as a raw constant, beginning from 0.
2099 *
2100 * @discussion
2101 * Libkern C++ classes in kernel extensions that can be used as libraries
2102 * can provide for backward compatibility by declaring a number
2103 * of reserved vtable slots
2104 * that can be replaced with new functions as they are added.
2105 * Each reserved defintion accompanies
2106 * a corresponding declaration created with
2107 * <code>@link OSMetaClassDeclareReservedUnused
2108 * OSMetaClassDeclareReservedUnused@/link</code>.
2109 *
2110 * This macro is used in the implementation file
2111 * to provide a placeholder definition for the reserved vtable slot,
2112 * as a function that calls <code>panic</code> with an error message.
2113 *
2114 * When replacing a reserved slot, change the macro from "Unused"
2115 * to "Used" to document the fact that the slot used to be reserved,
2116 * and declare the new function immediately after the "Used" macro
2117 * to preserve vtable ordering.
2118 * See
2119 * <code>@link OSMetaClassDefineReservedUsed
2120 * OSMetaClassDefineReservedUsed@/link</code>.
2121 */
2122 #if APPLE_KEXT_VTABLE_PADDING
2123 #define OSMetaClassDefineReservedUnused(className, index) \
2124 void className ::_RESERVED ## className ## index () \
2125 { gMetaClass.reservedCalled(index); }
2126 #else
2127 #define OSMetaClassDefineReservedUnused(className, index)
2128 #endif
2129
2130
2131 /*!
2132 * @define OSMetaClassDefineReservedUsed
2133 * @hidecontents
2134 *
2135 * @abstract
2136 * Reserves vtable space for new virtual functions in a Libkern C++ class.
2137 *
2138 * @param className The name of the C++ class, as a raw token,
2139 * <i>not</i> a string or macro.
2140 * @param index The numeric index of the vtable slot,
2141 * as a raw constant, beginning from 0.
2142 *
2143 * @discussion
2144 * This macro evaluates to nothing, and is used to document reserved
2145 * vtable slots as they are filled.
2146 * See
2147 * <code>@link OSMetaClassDefineReservedUnused
2148 * OSMetaClassDefineReservedUnused@/link</code>.
2149 */
2150 #define OSMetaClassDefineReservedUsed(className, index)
2151
2152 // I/O Kit debug internal routines.
2153 static void printInstanceCounts();
2154 static void serializeClassDictionary(OSDictionary * dict);
2155 #ifdef XNU_KERNEL_PRIVATE
2156 #if IOTRACKING
2157 public:
2158 static void * trackedNew(size_t size);
2159 static void trackedDelete(void * mem, size_t size);
2160 void trackedInstance(OSObject * instance) const;
2161 void trackedFree(OSObject * instance) const;
2162 void trackedAccumSize(OSObject * instance, size_t size) const;
2163 struct IOTrackingQueue * getTracking() const;
2164 #endif /* IOTRACKING */
2165 #endif /* XNU_KERNEL_PRIVATE */
2166
2167 private:
2168 // Obsolete APIs
2169 static OSDictionary * getClassDictionary();
2170 virtual bool serialize(OSSerialize * serializer) const;
2171
2172 // Virtual Padding functions for MetaClass's
2173 OSMetaClassDeclareReservedUnused(OSMetaClass, 0);
2174 OSMetaClassDeclareReservedUnused(OSMetaClass, 1);
2175 OSMetaClassDeclareReservedUnused(OSMetaClass, 2);
2176 OSMetaClassDeclareReservedUnused(OSMetaClass, 3);
2177 OSMetaClassDeclareReservedUnused(OSMetaClass, 4);
2178 OSMetaClassDeclareReservedUnused(OSMetaClass, 5);
2179 OSMetaClassDeclareReservedUnused(OSMetaClass, 6);
2180 OSMetaClassDeclareReservedUnused(OSMetaClass, 7);
2181 };
2182
2183 #endif /* !_LIBKERN_OSMETACLASS_H */