]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSMetaClass.h
662021550e093264312da1dccc700604e291635d
2 * Copyright (c) 2000 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #ifndef _LIBKERN_OSMETACLASS_H
29 #define _LIBKERN_OSMETACLASS_H
31 #include <sys/types.h>
33 #include <libkern/OSReturn.h>
34 #include <kern/debug.h>
48 * This header declares the OSMetaClassBase and OSMetaClass classes,
49 * which together form the basis of the Libkern and I/O Kit C++ class hierarchy
50 * and run-time type information facility.
55 #define APPLE_KEXT_COMPATIBILITY
58 #define APPLE_KEXT_VTABLE_PADDING 1
62 #define APPLE_KEXT_LEGACY_ABI 0
63 #elif defined(__arm__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
64 #define APPLE_KEXT_LEGACY_ABI 0
66 #define APPLE_KEXT_LEGACY_ABI 1
69 #if APPLE_KEXT_VTABLE_PADDING
71 #define APPLE_KEXT_PAD_METHOD virtual
73 #define APPLE_KEXT_PAD_IMPL(index) gMetaClass.reservedCalled(index)
75 #define APPLE_KEXT_PAD_METHOD static
76 #define APPLE_KEXT_PAD_IMPL(index)
81 #define APPLE_KEXT_COMPATIBILITY_VIRTUAL
83 // private method made virtual only for binary compatibility
84 #define APPLE_KEXT_COMPATIBILITY_VIRTUAL virtual
88 #define APPLE_KEXT_DEPRECATED __attribute__((deprecated))
91 * @class OSMetaClassBase
94 * OSMetaClassBase is the abstract bootstrap class
95 * for the Libkern and I/O Kit run-time type information system.
98 * OSMetaClassBase is the abstract C++ root class
99 * underlying the entire Libkern and I/O Kit class hierarchy.
100 * It defines the run-time type information system,
101 * including dynamic class allocation and safe type-casting,
102 * as well as the abstract interface for reference counting
103 * and a few other utility functions.
104 * OSMetaClassBase is the immediate superclass of
105 * @link //apple_ref/doc/class/OSObject OSObject@/link and
106 * @link //apple_ref/doc/class/OSMetaClass OSMetaClass@/link;
107 * no other class should derive from OSMetaClassBase.
109 * For more information, see
110 * <i>@link //apple_ref/doc/uid/TP40002799
111 * I/O Kit Device Driver Design Guidelines@/link</i>.
113 * <b>Use by Kernel Extensions</b>
115 * Kernel Extensions should never interact directly with OSMetaClassBase,
116 * but they will find useful several macros that tie in
117 * to the run-time type information system, specifically:
119 * <li><code>@link OSTypeAlloc OSTypeAlloc@/link</code> - allocation of new instances</li>
120 * <li><code>@link OSDynamicCast OSDynamicCast@/link</code> - safe type casting</li>
121 * <li><code>@link OSCheckTypeInst OSCheckTypeInst@/link</code> -
122 * checking for inheritance/derivation</li>
123 * <li><code>@link OSMemberFunctionCast OSMemberFunctionCast@/link</code> -
124 * casting C++ member functions to C function pointers
125 * for registration as callbacks</li>
128 * See @link //apple_ref/doc/class/OSMetaClass OSMetaClass@/link
129 * for more run-time type information interfaces.
131 * <b>Use Restrictions</b>
133 * OSMetaClassBase should not be subclassed by kernel extensions,
134 * nor should kernel extensions call its run-time type functions directly.
136 * The run-time type functions and macros are <b>not safe</b>
137 * to call in a primary interrupt context.
139 * <b>Concurrency Protection</b>
141 * The run-time type macros and functions of OSMetaClassBase are thread-safe.
143 class OSMetaClassBase
149 * @define OSTypeAlloc
153 * Allocates an instance of the named object class.
155 * @param type The name of the desired class to be created,
156 * as a raw token, <i>not</i> a string or macro.
159 * A pointer to the new, uninitialized object on success;
160 * <code>NULL</code> on failure.
165 * //apple_ref/cpp/clm/OSMetaClass/allocClassWithName/staticOSObject*\/(constchar*)
166 * OSMetaClass::allocClassWithName(const char *)@/link</code>
169 * //apple_ref/cpp/instm/OSMetaClass/alloc/virtualOSObject*\/()
170 * OSMetaClass::alloc@/link</code>.
172 * The OSTypeAlloc macro is used to avoid binary compatibility difficulties
173 * presented by the C++ <code>new</code> operator.
175 #define OSTypeAlloc(type) ((type *) ((type::metaClass)->alloc()))
183 * Returns the type ID (metaclass) of a class based on its name.
185 * @param type The name of the desired class, as a raw token,
186 * <i>not</i> a string or macro.
189 * The unique type ID (metaclass) for the class.
192 * It is typically more useful to determine whether a class is derived
194 * <code>@link //apple_ref/cpp/macro/OSDynamicCast OSDynamicCast@/link</code>
196 * <code>@link //apple_ref/cpp/macro/OSCheckTypeInst OSCheckTypeInst@/link</code>.
198 #define OSTypeID(type) (type::metaClass)
202 * @define OSTypeIDInst
206 * Returns the type ID (metaclass) for the class of an object instance.
208 * @param typeinst An instance of an OSObject subclass.
211 * The type ID of that object's class; that is, its metaclass.
214 * It is typically more useful to determine whether an object is derived
215 * from a particular class; see
216 * <code>@link //apple_ref/cpp/macro/OSDynamicCast OSDynamicCast@/link</code>
218 * <code>@link //apple_ref/cpp/macro/OSCheckTypeInst OSCheckTypeInst@/link</code>.
220 #define OSTypeIDInst(typeinst) ((typeinst)->getMetaClass())
224 * @define OSDynamicCast
228 * Safe type-casting for Libkern C++ objects.
230 * @param type The name of the desired class type, as a raw token,
231 * <i>not</i> a string or macro.
232 * It is assumed you intend to cast to a pointer
233 * to an object of this type.
234 * Type qualifiers, such as <code>const</code>,
235 * are not recognized and will cause
236 * a (usually obscure) compile error.
237 * @param inst A pointer to the object instance to be cast.
238 * May be <code>NULL</code>.
241 * <code>inst</code> if it is non-<code>NULL</code>
242 * and derived from <code>type</code>;
243 * otherwise <code>NULL</code>.
246 * <code>OSDynamicCast</code> is a rough equivalent
247 * to the standard C++ RTTI <code>dynamic_cast<T></code> operator.
248 * Your code should use this instead of raw C type-casting,
249 * and check the resulting value.
250 * If the result is non-<code>NULL</code>,
251 * the object is safe to use as the type-cast class;
252 * if the result is <code>NULL</code>,
253 * the object does not derive from the type-cast class
254 * and your code should take appropriate steps to handle the error.
256 #define OSDynamicCast(type, inst) \
257 ((type *) OSMetaClassBase::safeMetaCast((inst), OSTypeID(type)))
261 * @define OSCheckTypeInst
265 * Checks whether two objects are type-compatible.
267 * @param typeinst The reference object.
268 * @param inst The object to check for type compatibility.
271 * <code>true</code> if both <code>inst</code> and
272 * <code>typeinst</code> are non-<code>NULL</code>
273 * and <code>inst</code> is derived from the class of <code>typeinst</code>;
274 * otherwise <code>false</code>.
276 #define OSCheckTypeInst(typeinst, inst) \
277 OSMetaClassBase::checkTypeInst(inst, typeinst)
279 /*! @function OSSafeRelease
280 * @abstract Release an object if not <code>NULL</code>.
281 * @param inst Instance of an OSObject, may be <code>NULL</code>.
283 #define OSSafeRelease(inst) do { if (inst) (inst)->release(); } while (0)
285 /*! @function OSSafeReleaseNULL
286 * @abstract Release an object if not <code>NULL</code>, then set it to <code>NULL</code>.
287 * @param inst Instance of an OSObject, may be <code>NULL</code>.
289 #define OSSafeReleaseNULL(inst) do { if (inst) (inst)->release(); (inst) = NULL; } while (0)
291 typedef void (*_ptf_t
)(void);
293 #if APPLE_KEXT_LEGACY_ABI
295 // Arcane evil code interprets a C++ pointer to function as specified in the
296 // -fapple-kext ABI, i.e. the gcc-2.95 generated code. IT DOES NOT ALLOW
297 // the conversion of functions that are from MULTIPLY inherited classes.
300 _ptmf2ptf(const OSMetaClassBase
*self
, void (OSMetaClassBase::*func
)(void))
303 void (OSMetaClassBase::*fIn
)(void);
304 struct { // Pointer to member function 2.95
305 unsigned short fToff
;
315 if (map
.fptmf2
.fToff
) {
316 panic("Multiple inheritance is not supported");
318 } else if (map
.fptmf2
.fVInd
< 0) {
319 // Not virtual, i.e. plain member func
320 return map
.fptmf2
.u
.fPFN
;
323 const OSMetaClassBase
*fObj
;
328 // Virtual member function so dereference vtable
329 return (*u
.vtablep
)[map
.fptmf2
.fVInd
- 1];
333 #else /* !APPLE_KEXT_LEGACY_ABI */
335 // Slightly less arcane and slightly less evil code to do
336 // the same for kexts compiled with the standard Itanium C++
340 _ptmf2ptf(const OSMetaClassBase
*self
, void (OSMetaClassBase::*func
)(void))
343 void (OSMetaClassBase::*fIn
)(void);
350 if (map
.fVTOffset
& 1) {
353 const OSMetaClassBase
*fObj
;
358 // Virtual member function so dereference vtable
359 return *(_ptf_t
*)(((uintptr_t)*u
.vtablep
) + map
.fVTOffset
- 1);
361 // Not virtual, i.e. plain member func
367 #endif /* !APPLE_KEXT_LEGACY_ABI */
370 * @define OSMemberFunctionCast
374 * Converts a C++ member function pointer, relative to an instance,
375 * to a C-style pointer to function.
377 * @param cptrtype The function type declaration to cast to
378 * (typically provided as a <code>typedef</code> by I/O KitKit classes).
379 * @param self The <code>this</code> pointer of the object whose function
381 * @param func The pointer to the member function itself,
382 * something like <code>&Class::function</code>.
385 * A pointer to a function of the given type referencing <code>self</code>.
388 * This function is used to generate pointers to C++ functions for instances,
389 * such that they can be registered as callbacks with I/O Kit objects.
391 * No warnings are generated.
393 * This function will panic if an attempt is made to call it
394 * with a multiply-inheriting class.
396 #define OSMemberFunctionCast(cptrtype, self, func) \
397 (cptrtype) OSMetaClassBase:: \
398 _ptmf2ptf(self, (void (OSMetaClassBase::*)(void)) func)
402 virtual ~OSMetaClassBase();
405 // Disable copy constructors of OSMetaClassBase based objects
406 /* Not to be included in headerdoc.
408 * @function operator =
411 * Disable implicit copy constructor by making private
413 * @param src Reference to source object that isn't allowed to be copied.
415 void operator =(OSMetaClassBase
&src
);
417 /* Not to be included in headerdoc.
419 * @function OSMetaClassBase
422 * Disable implicit copy constructor by making private
424 * @param src Reference to source object that isn't allowed to be copied.
426 OSMetaClassBase(OSMetaClassBase
&src
);
430 // xx-review: the original comment for this makes it sound to me like we don't
431 // xx-review: catch over-releasing an object...?
437 * Abstract declaration of
439 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/(int)
440 * release(int freeWhen)@/link</code>.
445 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/(int)
446 * release(int freeWhen)@/link</code>.
448 virtual void release(int freeWhen
) const = 0;
452 * @function getRetainCount
455 * Abstract declaration of
457 * //apple_ref/cpp/instm/OSObject/getRetainCount/virtualint/()
458 * getRetainCount()@/link</code>.
463 * //apple_ref/cpp/instm/OSObject/getRetainCount/virtualint/()
464 * OSObject::getRetainCount()@/link</code>.
466 virtual int getRetainCount() const = 0;
473 * Abstract declaration of
475 * //apple_ref/cpp/instm/OSObject/retain/virtualvoid/()
476 * retain()@/link</code>.
481 * //apple_ref/cpp/instm/OSObject/retain/virtualvoid/()
482 * OSObject::retain()@/link</code>.
484 virtual void retain() const = 0;
491 * Abstract declaration of
493 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/()
494 * release@/link</code>.
499 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/()
500 * OSObject::release@/link</code>.
502 virtual void release() const = 0;
506 * @function serialize
509 * Abstract declaration of
511 * //apple_ref/cpp/instm/OSObject/serialize/virtualbool/(OSSerialize*)
512 * serialize@/link</code>.
517 * //apple_ref/cpp/instm/OSObject/serialize/virtualbool/(OSSerialize*)
518 * OSObject::serialize@/link</code>.
520 virtual bool serialize(OSSerialize
* serializer
) const = 0;
524 * @function getMetaClass
527 * Returns the OSMetaClass representing
528 * an OSMetaClassBase subclass.
531 * OSObject overrides this abstract member function
532 * to return the OSMetaClass object that represents
533 * each class for run-time typing.
535 virtual const OSMetaClass
* getMetaClass() const = 0;
539 * @function isEqualTo
542 * Checks whether another object is equal to the receiver.
544 * @param anObject The object to copmare to the receiver.
547 * <code>true</code> if the objects are equal, <code>false</code> otherwise.
550 * OSMetaClassBase implements this as a direct pointer comparison,
551 * since it has no other information to judge equality by.
552 * Subclasses generally override this function
553 * to do a more meaningful comparison.
554 * For example, OSString implements it to return
555 * <code>true</code> if <code>anObject</code>
556 * is derived from OSString and represents the same C string.
558 virtual bool isEqualTo(const OSMetaClassBase
* anObject
) const;
565 * Casts this object is to the class managed by the given OSMetaClass.
567 * @param toMeta A pointer to a constant OSMetaClass
568 * for the desired target type.
571 * <code>this</code> if the object is derived
572 * from the class managed by <code>toMeta</code>,
573 * otherwise <code>NULL</code>.
576 * It is far more convenient to use
577 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
579 OSMetaClassBase
* metaCast(const OSMetaClass
* toMeta
) const;
586 * Casts this object is to the class managed by the named OSMetaClass.
588 * @param toMeta An OSSymbol naming the desired target type.
591 * <code>this</code> if the object is derived
592 * from the class named by <code>toMeta</code>,
593 * otherwise <code>NULL</code>.
596 * It is far more convenient to use
597 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
599 OSMetaClassBase
* metaCast(const OSSymbol
* toMeta
) const;
606 * Casts this object is to the class managed by the named OSMetaClass.
608 * @param toMeta An OSString naming the desired target type.
610 * <code>this</code> if the object is derived
611 * from the class named by <code>toMeta</code>,
612 * otherwise <code>NULL</code>.
615 * It is far more convenient to use
616 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
618 OSMetaClassBase
* metaCast(const OSString
* toMeta
) const;
625 * Casts this object is to the class managed by the named OSMetaClass.
627 * @param toMeta A C string naming the desired target type.
629 * <code>this</code> if the object is derived
630 * from the class named by <code>toMeta</code>,
631 * otherwise <code>NULL</code>.
634 * It is far more convenient to use
635 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
637 OSMetaClassBase
* metaCast(const char * toMeta
) const;
639 // Helper inlines for run-time type preprocessor macros
641 * @function safeMetaCast
644 * Casts an object is to the class managed by the given OSMetaClass.
646 * @param anObject A pointer to the object to be cast.
647 * @param toMeta A pointer to a constant OSMetaClass
648 * for the desired target type.
651 * <code>anObject</code> if the object is derived
652 * from the class managed by <code>toMeta</code>,
653 * otherwise <code>NULL</code>.
656 * It is far more convenient to use
657 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
659 static OSMetaClassBase
* safeMetaCast(
660 const OSMetaClassBase
* anObject
,
661 const OSMetaClass
* toMeta
);
664 * @function checkTypeInst
667 * Checks whether an object instance is of the same class
668 * as another object instance (or a subclass of that class).
670 * @param inst A pointer to the object to check.
671 * @param typeinst A pointer to an object of the class being checked.
674 * <code>true</code> if the object is derived
675 * from the class of <code>typeinst</code>
676 * or a subclass of that class,
677 * otherwise <code>false</code>.
680 * It is far more convenient to use
681 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
683 static bool checkTypeInst(
684 const OSMetaClassBase
* inst
,
685 const OSMetaClassBase
* typeinst
);
687 static void initialize(void);
692 * @function taggedRetain
695 * Abstract declaration of
697 * //apple_ref/cpp/instm/OSObject/taggedRetain/virtualvoid/(constvoid*)
698 * taggedRetain(const void *)@/link</code>.
703 * //apple_ref/cpp/instm/OSObject/taggedRetain/virtualvoid/(constvoid*)
704 * OSObject::taggedRetain(const void *)@/link</code>.
706 // WAS: virtual void _RESERVEDOSMetaClassBase0();
707 virtual void taggedRetain(const void * tag
= 0) const = 0;
711 * @function taggedRelease
714 * Abstract declaration of
716 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*)
717 * taggedRelease(const void *)@/link</code>.
722 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*)
723 * OSObject::taggedRelease(const void *)@/link</code>.
725 // WAS: virtual void _RESERVEDOSMetaClassBase1();
726 virtual void taggedRelease(const void * tag
= 0) const = 0;
730 * @function taggedRelease
733 * Abstract declaration of
735 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*,constint)
736 * taggedRelease(const void *, const int freeWhen)@/link</code>.
741 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*,constint)
742 * OSObject::taggedRelease(const void *, const int freeWhen)@/link</code>.
744 // WAS: virtual void _RESERVEDOSMetaClassBase2();
745 virtual void taggedRelease(
747 const int freeWhen
) const = 0;
751 virtual void _RESERVEDOSMetaClassBase3();
752 virtual void _RESERVEDOSMetaClassBase4();
753 virtual void _RESERVEDOSMetaClassBase5();
754 virtual void _RESERVEDOSMetaClassBase6();
755 virtual void _RESERVEDOSMetaClassBase7();
756 } APPLE_KEXT_COMPATIBILITY
;
763 * OSMetaClass manages run-time type information
764 * for Libkern and I/O Kit C++ classes.
768 * OSMetaClass manages run-time type information
769 * for Libkern and I/O Kit C++ classes.
770 * An instance of OSMetaClass exists for (nearly) every such C++ class,
771 * keeping track of inheritance relationships, class lookup by name,
772 * instance counts, and more.
773 * OSMetaClass operates almost entirely behind the scenes,
774 * and kernel extensions should rarely, if ever,
775 * have to interact directly with OSMetaClass.
777 * <b>Use by Kernel Extensions</b>
779 * While kernel extensions rarey interact directly with OSMetaClass at run time,
780 * they must register their classes with the metaclass system
781 * using the macros declared here.
782 * The class declaration should use one of these two macros
783 * before its first member function declaration:
785 * <li><code>@link OSDeclareDefaultStructors OSDeclareDefaultStructors@/link</code> -
786 * for classes with no abstract member function declarations</li>
787 * <li><code>@link OSDeclareAbstractStructors OSDeclareAbstractStructors@/link</code> -
788 * for classes with at least one abstract member function declaration</li>
789 * <li><code>@link OSDeclareFinalStructors OSDeclareFinalStructors@/link</code> -
790 * for classes that should not be subclassable by another kext</li>
793 * The class implementation should then use one of these macros:
795 * <li><code>@link OSDefineMetaClassAndStructors
796 * OSDefineMetaClassAndStructors@/link</code> -
797 * for classes with no abstract member function declarations</li>
798 * <li><code>@link OSDefineMetaClassAndAbstractStructors
799 * OSDefineMetaClassAndAbstractStructors@/link</code> -
800 * for classes with at least one abstract member function declaration</li>
801 * <li><code>@link OSDefineMetaClassAndFinalStructors
802 * OSDefineMetaClassAndFinalStructors@/link</code> -
803 * for classes that should not be subclassable by another kext</li>
806 * Classes in kernel extensions that are intended for use as libraries
807 * may need to reserve vtable slots to preserve binary compatibility
808 * as new functions are added. They may do so with these macros:
810 * <li><code>@link OSMetaClassDeclareReservedUnused
811 * OSMetaClassDeclareReservedUnused@/link</code> -
812 * reserves a vtable slot</li>
813 * <li><code>@link OSMetaClassDefineReservedUnused
814 * OSMetaClassDefineReservedUnused@/link</code> -
815 * defines the reserved vtable slot as an unimplemented function</li>
816 * <li><code>@link OSMetaClassDeclareReservedUsed
817 * OSMetaClassDeclareReservedUsed@/link</code> -
818 * documents that a formerly reserved slot is now used</li>
819 * <li><code>@link OSMetaClassDefineReservedUsed
820 * OSMetaClassDefineReservedUsed@/link</code> -
821 * documents that a formerly reserved slot is now used</li>
824 * <b>Use Restrictions</b>
826 * OSMetaClass should not be explicitly subclassed by kernel extensions
827 * (the declare/define macros do that),
828 * nor should kernel extensions call its run-time type functions directly.
830 * OSMetaClass functions should be considered
831 * <b>unsafe</b> to call in a primary interrupt context.
833 * <b>Concurrency Protection</b>
835 * Kernel extensions should in general not interact
836 * with OSMetaClass objects directly,
837 * instead using the run-time type macros.
838 * Much of OSMetaClass's interface is intended for use
839 * by the run-time type information system,
840 * which handles concurrency and locking internally.
842 class OSMetaClass
: private OSMetaClassBase
846 friend class IOStatistics
;
850 // Can never be allocated must be created at compile time
851 static void * operator new(size_t size
);
853 struct ExpansionData
{ };
855 /* Reserved for future use. (Internal use only) */
856 ExpansionData
*reserved
;
858 /* superClass Handle to the superclass's meta class. */
859 const OSMetaClass
*superClassLink
;
861 /* className OSSymbol of the class' name. */
862 const OSSymbol
*className
;
864 /* classSize How big is a single instance of this class. */
865 unsigned int classSize
;
867 /* instanceCount Roughly number of instances of the object,
868 * +1 for each direct subclass with a nonzero refcount.
869 * Used primarily as a code-in-use flag.
871 mutable unsigned int instanceCount
;
873 /* Not to be included in headerdoc.
875 * @function OSMetaClass
878 * The default private constructor.
882 // Called by postModLoad
883 /* Not to be included in headerdoc.
888 * Logs an error string for an <code>OSReturn</code> value
889 * using <code>printf</code>.
891 * @param result The <code>OSReturn</code> value for which to log a message.
894 * This function is used to log errors loading kernel extensions.
895 * Kernel extensions themselves should not call it.
897 static void logError(OSReturn result
);
902 * @function getMetaClassWithName
905 * Look up a metaclass in the run-time type information system.
907 * @param name The name of the desired class's metaclass.
910 * A pointer to the metaclass object if found, <code>NULL</code> otherwise.
912 static const OSMetaClass
* getMetaClassWithName(const OSSymbol
* name
);
919 * Implements the abstract <code>retain</code> function to do nothing.
922 * Since an OSMetaClass instance must remain in existence
923 * for as long as its kernel extension is loaded,
924 * OSMetaClass does not use reference-counting.
926 virtual void retain() const;
933 * Implements the abstract <code>release</code> function to do nothing.
936 * Since an OSMetaClass instance must remain in existence
937 * for as long as its kernel extension is loaded,
938 * OSMetaClass does not use reference-counting.
940 virtual void release() const;
947 * Implements the abstract <code>release(int freeWhen)</code>
948 * function to do nothing.
950 * @param freeWhen Unused.
953 * Since an OSMetaClass instance must remain in existence
954 * for as long as its kernel extension is loaded,
955 * OSMetaClass does not use reference-counting.
957 virtual void release(int freeWhen
) const;
961 * @function taggedRetain
964 * Implements the abstract <code>taggedRetain(const void *)</code>
965 * function to do nothing.
970 * Since an OSMetaClass instance must remain in existence
971 * for as long as its kernel extension is loaded,
972 * OSMetaClass does not use reference-counting.
974 virtual void taggedRetain(const void * tag
= 0) const;
978 * @function taggedRelease
981 * Implements the abstract <code>taggedRelease(const void *)</code>
982 * function to do nothing.
987 * Since an OSMetaClass instance must remain in existence
988 * for as long as its kernel extension is loaded,
989 * OSMetaClass does not use reference-counting.
991 virtual void taggedRelease(const void * tag
= 0) const;
995 * @function taggedRelease
998 * Implements the abstract <code>taggedRelease(const void *, cont int)</code>
999 * function to do nothing.
1001 * @param tag Unused.
1002 * @param freeWhen Unused.
1005 * Since an OSMetaClass instance must remain in existence
1006 * for as long as its kernel extension is loaded,
1007 * OSMetaClass does not use reference-counting.
1009 virtual void taggedRelease(
1011 const int freeWhen
) const;
1015 * @function getRetainCount
1018 * Implements the abstract <code>getRetainCount</code>
1019 * function to return 0.
1025 * Since an OSMetaClass instance must remain in existence
1026 * for as long as its kernel extension is loaded,
1027 * OSMetaClass does not use reference-counting.
1029 virtual int getRetainCount() const;
1032 /* Not to be included in headerdoc.
1034 * @function getMetaClass
1037 * Returns the meta-metaclass.
1040 * The metaclass of the OSMetaClass object.
1042 virtual const OSMetaClass
* getMetaClass() const;
1046 * @function OSMetaClass
1049 * Constructor for OSMetaClass objects.
1051 * @param className A C string naming the C++ class
1052 * that this OSMetaClass represents.
1053 * @param superclass The OSMetaClass object representing the superclass
1054 * of this metaclass's class.
1055 * @param classSize The allocation size of the represented C++ class.
1058 * This constructor is protected and cannot be used
1059 * to instantiate OSMetaClass directly, as OSMetaClass is an abstract class.
1060 * This function is called during kext loading
1061 * to queue C++ classes for registration.
1062 * See <code>@link preModLoad preModLoad@/link</code> and
1063 * <code>@link postModLoad postModLoad@/link</code>.
1065 OSMetaClass(const char * className
,
1066 const OSMetaClass
* superclass
,
1067 unsigned int classSize
);
1071 * @function ~OSMetaClass
1074 * Destructor for OSMetaClass objects.
1077 * This function is called when the kernel extension that implements
1078 * the metaclass's class is unloaded.
1079 * The destructor removes all references to the class
1080 * from the run-time type information system.
1082 virtual ~OSMetaClass();
1084 // Needs to be overriden as NULL as all OSMetaClass objects are allocated
1085 // statically at compile time, don't accidently try to free them.
1086 void operator delete(void *, size_t) { };
1089 static const OSMetaClass
* const metaClass
;
1092 * @function preModLoad
1095 * Prepares the run-time type system
1096 * for the creation of new metaclasses
1097 * during loading of a kernel extension (module).
1099 * @param kextID The bundle ID of the kext being loaded.
1102 * An opaque handle to the load context
1103 * for the kernel extension on success;
1104 * <code>NULL</code> on failure.
1107 * <i>Not for use by kernel extensions.</i>
1109 * Prepares the run-time type information system to record and register
1110 * metaclasses created by static constructors until a subsequent call to
1111 * <code>@link postModLoad postModLoad@/link</code>.
1112 * <code>preModLoad</code> takes a lock to ensure processing of a single
1113 * load operation at a time; the lock is released by
1114 * <code>@link postModLoad postModLoad@/link</code>.
1115 * Any OSMetaClass constructed between these two function calls
1116 * will be associated with <code>kextID</code>.
1118 static void * preModLoad(const char * kextID
);
1122 * @function checkModLoad
1125 * Checks whether the current kext load operation can proceed.
1127 * @param loadHandle The opaque handle returned
1128 * by <code>@link preModLoad preModLoad@/link</code>.
1130 * <code>true</code> if no errors are outstanding
1131 * and the system is ready to process more metaclasses.
1134 * <i>Not for use by kernel extensions.</i>
1136 static bool checkModLoad(void * loadHandle
);
1140 * @function postModLoad
1143 * Registers the metaclasses created during loading of a kernel extension.
1145 * @param loadHandle The opaque handle returned
1146 * by <code>@link preModLoad preModLoad@/link</code>.
1148 * The error code of the first error encountered,
1151 * //apple_ref/cpp/macro/kOSReturnSuccess
1152 * kOSReturnSuccess@/link</code>
1153 * if no error occurred.
1156 * <i>Not for use by kernel extensions.</i>
1158 * Called after all static constructors in a kernel extension
1159 * have created metaclasses,
1160 * this function checks for duplicate class names,
1161 * then registers the new metaclasses under the kext ID
1162 * that @link preModLoad preModLoad@/link was called with,
1163 * so that they can be dynamically allocated
1164 * and have their instance counts tracked.
1165 * <code>postModLoad</code> releases the lock taken by
1166 * <code>@link preModLoad preModLoad@/link</code>.
1168 static OSReturn
postModLoad(void * loadHandle
);
1171 * @function modHasInstance
1174 * Returns whether any classes defined by the named
1175 * kernel extension (or their subclasses) have existing instances.
1177 * @param kextID The bundle ID of the kernel extension to check.
1180 * <code>true</code> if the kext is found and
1181 * if any class defined by that kext
1182 * has a nonzero instance count,
1183 * <code>false</code> otherwise.
1186 * This function is called before a kernel extension's static destructors
1187 * are invoked, prior to unloading the extension.
1188 * If any classes stil have instances or subclasses with instances,
1189 * those classes are logged
1190 * (using <code>@link reportModInstances reportModInstances@/link</code>) and
1191 * the kernel extension is not be unloaded.
1193 static bool modHasInstance(const char * kextID
);
1197 * @function reportModInstances
1200 * Logs the instance counts for classes
1201 * defined by a kernel extension.
1203 * @param kextID The bundle ID of the kernel extension to report on.
1206 * This function prints the names and instance counts
1207 * of any class defined by <code>kextID</code>
1208 * that has a nonzero instance count.
1209 * It's called by <code>@link modHasInstance modHasInstance@/link</code>
1210 * to help diagnose problems unloading kernel extensions.
1212 static void reportModInstances(const char * kextID
);
1216 * @function considerUnloads
1219 * Schedule automatic unloading of unused kernel extensions.
1222 * This function schedules a check for kernel extensions
1223 * that can be automatically unloaded,
1224 * canceling any currently scheduled check.
1225 * At that time, any such kexts with no Libkern C++ instances
1226 * and no external references are unloaded.
1228 * The I/O Kit calls this function when matching goes idle.
1230 * Kernel extensions that define subclasses of
1231 * @link //apple_ref/doc/class/IOService IOService@/link
1232 * are eligible for automatic unloading.
1234 * (On releases of Mac OS X prior to Snow Leopard (10.6),
1235 * any kernel extension defining any Libkern C++ class
1236 * was eligible for automatic unloading,
1237 * but that unload did not call the module stop routine.
1238 * Non-I/O Kit kernel extensions that define Libkern C++ subclasses
1239 * should be sure to have OSBundleLibraries declarations that ensure
1240 * they will not load on releases prior to Snow Leopard.)
1242 static void considerUnloads();
1246 * @function allocClassWithName
1249 * Allocates an instance of a named OSObject-derived class.
1251 * @param name The name of the desired class.
1254 * A pointer to the newly-allocated, uninitialized object on success;
1255 * <code>NULL</code> on failure.
1258 * Kernel extensions should not need to use this function
1259 * directly, instead using static instance-creation functions
1260 * defined by classes.
1262 * This function consults the run-time type information system
1263 * to find the metaclass for the named class.
1264 * If it exists, it calls the metaclass's <code>@link alloc alloc@/link</code>
1265 * function and returns the result.
1267 static OSObject
* allocClassWithName(const OSSymbol
* name
);
1271 * function allocClassWithName
1274 * Allocates an instance of a named OSObject-derived class.
1276 * @param name The name of the desired class.
1279 * A pointer to the newly-allocated, uninitialized object on success;
1280 * <code>NULL</code> on failure.
1283 * Kernel extensions should not need to use this function
1284 * directly, instead using static instance-creation functions
1285 * defined by classes.
1287 * This function consults the run-time type information system
1288 * to find the metaclass for the named class.
1289 * If it exists, it calls the metaclass's <code>@link alloc alloc@/link</code>
1290 * function and returns the result.
1292 static OSObject
* allocClassWithName(const OSString
* name
);
1296 * function allocClassWithName
1299 * Allocates an instance of a named OSObject-derived class.
1301 * @param name The name of the desired class.
1304 * A pointer to the newly-allocated, uninitialized object on success;
1305 * <code>NULL</code> on failure.
1308 * Kernel extensions should not need to use this function
1309 * directly, instead using static instance-creation functions
1310 * defined by classes.
1312 * This function consults the run-time type information system
1313 * to find the metaclass for the named class.
1314 * If it exists, it calls the metaclass's <code>@link alloc alloc@/link</code>
1315 * function and returns the result.
1317 static OSObject
* allocClassWithName(const char * name
);
1321 * @function checkMetaCastWithName
1324 * Search the metaclass inheritance hierarchy by name for an object instance.
1326 * @param className The name of the desired class or superclass.
1327 * @param object The object whose metaclass begins the search.
1330 * <code>object</code> if it's derived from <code>className</code>;
1331 * <code>NULL</code> otherwise.
1334 * This function is the basis of the Libkern run-time type-checking system.
1335 * Kernel extensions should not use it directly,
1336 * instead using <code>@link OSDynamicCast OSDynamicCast@/link</code> or
1337 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
1339 static OSMetaClassBase
* checkMetaCastWithName(
1340 const OSSymbol
* className
,
1341 const OSMetaClassBase
* object
);
1344 * @function checkMetaCastWithName
1347 * Search the metaclass inheritance hierarchy by name for an object instance.
1349 * @param className The name of the desired class or superclass.
1350 * @param object The object whose metaclass begins the search.
1353 * <code>object</code> if it's derived from <code>className</code>;
1354 * <code>NULL</code> otherwise.
1357 * Kernel extensions should not use this function directly,
1358 * instead using <code>@link OSDynamicCast OSDynamicCast@/link</code> or
1359 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
1361 static OSMetaClassBase
* checkMetaCastWithName(
1362 const OSString
* className
,
1363 const OSMetaClassBase
* object
);
1366 * @function checkMetaCastWithName
1369 * Search the metaclass inheritance hierarchy by name for an object instance.
1371 * @param className The name of the desired class or superclass.
1372 * @param object The object whose metaclass begins the search.
1375 * <code>object</code> if it's derived from <code>className</code>;
1376 * <code>NULL</code> otherwise.
1379 * Kernel extensions should not use this function directly,
1380 * instead using <code>@link OSDynamicCast OSDynamicCast@/link</code> or
1381 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
1383 static OSMetaClassBase
* checkMetaCastWithName(
1384 const char * className
,
1385 const OSMetaClassBase
* object
);
1389 * @function instanceConstructed
1392 * Counts the instances of the class managed by this metaclass.
1395 * <i>Not for use by kernel extensions.</i>
1397 * Every non-abstract class that inherits from OSObject
1398 * has a default constructor that calls it's own metaclass's
1399 * <code>instanceConstructed</code> function.
1400 * This constructor is defined by the
1402 * OSDefineMetaClassAndStructors
1403 * OSDefineMetaClassAndStructors@/link</code>
1404 * macro that all OSObject subclasses must use.
1406 * If a class's instance count goes from 0 to 1--that is,
1407 * upon the creation of the first instance of that class--the
1408 * superclass's instance count is also incremented.
1409 * This propagates reference counts up the inheritance chain so that
1410 * superclasses are counted as "in use" when subclasses have instances.
1412 void instanceConstructed() const;
1416 * @function instanceDestructed
1419 * Counts the instances of the class managed by this metaclass.
1422 * Every non-abstract class that inherits from OSObject
1423 * has a default destructor that calls it's own metaclass's
1424 * <code>instanceDestructed</code> function.
1425 * This constructor is defined by the
1426 * @link OSDefineMetaClassAndStructors OSDefineMetaClassAndStructors@/link
1427 * macro that all OSObject subclasses must use.
1429 * If a class's instance count goes from 1 to 0--that is,
1430 * upon the destruction of the last instance of that class--the
1431 * superclass's instance count is also decremented.
1432 * This reduces "in use" counts from superclasses when their subclasses
1433 * no longer have instances.
1435 void instanceDestructed() const;
1439 * @function checkMetaCast
1442 * Check whether a given object is an instance of the receiving
1443 * metaclass's class or one derived from it.
1445 * @param object The object to check for inheritance.
1448 * <code>object</code> if it is derived from the receiver's class,
1449 * <code>NULL</code> if not.
1451 OSMetaClassBase
* checkMetaCast(const OSMetaClassBase
* object
) const;
1455 * @function getInstanceCount
1458 * Returns the number of existing instances of the metaclass's class.
1461 * The number of existing instances of the metaclass's class,
1462 * plus 1 for each subclass with any instance.
1464 unsigned int getInstanceCount() const;
1468 * @function getSuperClass
1471 * Returns the super-metaclass of the receiver.
1474 * Returns a pointer to the super-metaclass of the receiving
1475 * OSMetaClass, or <code>NULL</code> for OSObject's metaclass.
1477 const OSMetaClass
* getSuperClass() const;
1481 * @function getKmodName
1484 * Returns the bundle identifier of the kernel extension
1485 * that defines this metaclass.
1488 * The bundle identifier of the kernel extension that defines this metaclass.
1491 * "Kmod" is an older term for kernel extension.
1493 const OSSymbol
* getKmodName() const;
1497 * @function getClassName
1500 * Returns the name of the C++ class managed by this metaclass.
1503 * Returns the name of the C++ class managed by this metaclass.
1505 const char * getClassName() const;
1509 * @function getClassSize
1512 * Returns the allocation size of the C++ class managed by this metaclass.
1515 * The allocation size of the C++ class managed by this metaclass.
1517 unsigned int getClassSize() const;
1524 * Allocates an instance of the C++ class managed by this metaclass.
1527 * A pointer to the newly allocated, uninitialized instance,
1528 * with a retain count of 1; <code>NULL</code> on allocation failure.
1531 * This function is automatically created by the metaclass-registration macros
1532 * to enable dynamic instance allocation.
1534 virtual OSObject
* alloc() const = 0;
1537 /* Not to be included in headerdoc.
1539 * @define OSDeclareCommonStructors
1543 * Helper macro for for the standard metaclass-registration macros.
1546 * @param className The name of the C++ class, as a raw token,
1547 * <i>not</i> a string or macro.
1549 #define OSDeclareCommonStructors(className) \
1551 static const OSMetaClass * const superClass; \
1553 static const OSMetaClass * const metaClass; \
1554 static class MetaClass : public OSMetaClass { \
1557 virtual OSObject *alloc() const; \
1559 friend class className ::MetaClass; \
1560 virtual const OSMetaClass * getMetaClass() const; \
1562 className (const OSMetaClass *); \
1563 virtual ~ className ()
1567 * @define OSDeclareDefaultStructors
1571 * Declares run-time type information and functions
1572 * for a concrete Libkern C++ class.
1574 * @param className The name of the C++ class, as a raw token,
1575 * <i>not</i> a string or macro.
1578 * Concrete Libkern C++ classes should "call" this macro
1579 * immediately after the opening brace in a class declaration.
1580 * It leaves the current privacy state as <code>protected:</code>.
1582 #define OSDeclareDefaultStructors(className) \
1583 OSDeclareCommonStructors(className); \
1590 * @define OSDeclareAbstractStructors
1594 * Declares run-time type information and functions
1595 * for an abstract Libkern C++ class.
1597 * @param className The name of the C++ class, as a raw token,
1598 * <i>not</i> a string or macro.
1601 * Abstract Libkern C++ classes--those with at least one
1602 * pure virtual method--should "call" this macro
1603 * immediately after the opening brace in a class declaration.
1604 * It leaves the current privacy state as <code>protected:</code>.
1606 #define OSDeclareAbstractStructors(className) \
1607 OSDeclareCommonStructors(className); \
1609 className (); /* Make primary constructor private in abstract */ \
1613 * @define OSDeclareFinalStructors
1617 * Declares run-time type information and functions
1618 * for a final (non-subclassable) Libkern C++ class.
1620 * @param className The name of the C++ class, as a raw token,
1621 * <i>not</i> a string or macro.
1624 * Final Libkern C++ classes--those that do not allow subclassing--should
1625 * "call" this macro immediately after the opening brace in a class declaration.
1626 * (Final classes in the kernel may actually have subclasses in the kernel,
1627 * but kexts cannot define any subclasses of a final class.)
1628 * It leaves the current privacy state as <code>protected:</code>.
1630 * <b>Note:</b> If the class is exported by a pseudokext (symbol set),
1631 * the final symbol generated by this macro must be exported
1632 * for the final-class attribute to be enforced.
1634 * <b>Warning:</b> Changing a class from "Default" to "Final" will break
1635 * binary compatibility.
1637 #define OSDeclareFinalStructors(className) \
1638 OSDeclareDefaultStructors(className) \
1640 void __OSFinalClass(void); \
1644 /* Not to be included in headerdoc.
1646 * @define OSDefineMetaClassWithInit
1650 * Helper macro for for the standard metaclass-registration macros.
1653 * @param className The name of the C++ class, as a raw token,
1654 * <i>not</i> a string or macro.
1655 * @param superclassName The name of the superclass of the C++ class,
1657 * <i>not</i> a string or macro.
1658 * @param init A function to call in the constructor
1659 * of the class's OSMetaClass.
1661 #define OSDefineMetaClassWithInit(className, superclassName, init) \
1662 /* Class global data */ \
1663 className ::MetaClass className ::gMetaClass; \
1664 const OSMetaClass * const className ::metaClass = \
1665 & className ::gMetaClass; \
1666 const OSMetaClass * const className ::superClass = \
1667 & superclassName ::gMetaClass; \
1668 /* Class member functions */ \
1669 className :: className(const OSMetaClass *meta) \
1670 : superclassName (meta) { } \
1671 className ::~ className() { } \
1672 const OSMetaClass * className ::getMetaClass() const \
1673 { return &gMetaClass; } \
1674 /* The ::MetaClass constructor */ \
1675 className ::MetaClass::MetaClass() \
1676 : OSMetaClass(#className, className::superClass, sizeof(className)) \
1680 /* Not to be included in headerdoc.
1682 * @define OSDefineAbstractStructors
1686 * Helper macro for for the standard metaclass-registration macros.
1689 * @param className The name of the C++ class, as a raw token,
1690 * <i>not</i> a string or macro.
1691 * @param superclassName The name of the superclass of the C++ class,
1693 * <i>not</i> a string or macro.
1695 #define OSDefineAbstractStructors(className, superclassName) \
1696 OSObject * className ::MetaClass::alloc() const { return 0; }
1699 /* Not to be included in headerdoc.
1701 * @define OSDefineDefaultStructors
1705 * Helper macro for for the standard metaclass-registration macros.
1708 * @param className The name of the C++ class, as a raw token,
1709 * <i>not</i> a string or macro.
1710 * @param superclassName The name of the superclass of the C++ class,
1712 * <i>not</i> a string or macro.
1714 #define OSDefineDefaultStructors(className, superclassName) \
1715 OSObject * className ::MetaClass::alloc() const \
1716 { return new className; } \
1717 className :: className () : superclassName (&gMetaClass) \
1718 { gMetaClass.instanceConstructed(); }
1720 /* Not to be included in headerdoc.
1722 * @define OSDefineDefaultStructors
1726 * Helper macro for for the standard metaclass-registration macros.
1729 * @param className The name of the C++ class, as a raw token,
1730 * <i>not</i> a string or macro.
1731 * @param superclassName The name of the superclass of the C++ class,
1733 * <i>not</i> a string or macro.
1735 #define OSDefineFinalStructors(className, superclassName) \
1736 OSDefineDefaultStructors(className, superclassName) \
1737 void className ::__OSFinalClass(void) { }
1740 /* Not to be included in headerdoc.
1742 * @define OSDefineMetaClassAndStructorsWithInit
1746 * Helper macro for for the standard metaclass-registration macros.
1749 * @param className The name of the C++ class, as a raw token,
1750 * <i>not</i> a string or macro.
1751 * @param superclassName The name of the superclass of the C++ class,
1753 * <i>not</i> a string or macro.
1754 * @param init A function to call in the constructor
1755 * of the class's OSMetaClass.
1757 #define OSDefineMetaClassAndStructorsWithInit(className, superclassName, init) \
1758 OSDefineMetaClassWithInit(className, superclassName, init) \
1759 OSDefineDefaultStructors(className, superclassName)
1762 /* Not to be included in headerdoc.
1764 * @define OSDefineMetaClassAndAbstractStructorsWithInit
1768 * Helper macro for for the standard metaclass-registration macros.
1771 * @param className The name of the C++ class, as a raw token,
1772 * <i>not</i> a string or macro.
1773 * @param superclassName The name of the superclass of the C++ class,
1775 * <i>not</i> a string or macro.
1776 * @param init A function to call in the constructor
1777 * of the class's OSMetaClass.
1779 #define OSDefineMetaClassAndAbstractStructorsWithInit(className, superclassName, init) \
1780 OSDefineMetaClassWithInit(className, superclassName, init) \
1781 OSDefineAbstractStructors(className, superclassName)
1784 /* Not to be included in headerdoc.
1786 * @define OSDefineMetaClassAndFinalStructorsWithInit
1790 * Helper macro for for the standard metaclass-registration macros.
1793 * @param className The name of the C++ class, as a raw token,
1794 * <i>not</i> a string or macro.
1795 * @param superclassName The name of the superclass of the C++ class,
1797 * <i>not</i> a string or macro.
1798 * @param init A function to call in the constructor
1799 * of the class's OSMetaClass.
1801 #define OSDefineMetaClassAndFinalStructorsWithInit(className, superclassName, init) \
1802 OSDefineMetaClassWithInit(className, superclassName, init) \
1803 OSDefineFinalStructors(className, superclassName)
1808 /* Not to be included in headerdoc.
1810 * @define OSDefineMetaClass
1814 * Helper macro for for the standard metaclass-registration macros.
1817 * @param className The name of the C++ class, as a raw token,
1818 * <i>not</i> a string or macro.
1819 * @param superclassName The name of the superclass of the C++ class,
1821 * <i>not</i> a string or macro.
1822 * @param init A function to call in the constructor
1823 * of the class's OSMetaClass.
1825 #define OSDefineMetaClass(className, superclassName) \
1826 OSDefineMetaClassWithInit(className, superclassName, )
1830 * @define OSDefineMetaClassAndStructors
1834 * Defines an OSMetaClass and associated routines
1835 * for a concrete Libkern C++ class.
1837 * @param className The name of the C++ class, as a raw token,
1838 * <i>not</i> a string or macro.
1839 * @param superclassName The name of the superclass of the C++ class,
1841 * <i>not</i> a string or macro.
1844 * Concrete Libkern C++ classes should "call" this macro
1845 * at the beginning of their implementation files,
1846 * before any function implementations for the class.
1848 #define OSDefineMetaClassAndStructors(className, superclassName) \
1849 OSDefineMetaClassAndStructorsWithInit(className, superclassName, )
1853 * @define OSDefineMetaClassAndAbstractStructors
1857 * Defines an OSMetaClass and associated routines
1858 * for an abstract Libkern C++ class.
1860 * @param className The name of the C++ class, as a raw token,
1861 * <i>not</i> a string or macro.
1862 * @param superclassName The name of the superclass of the C++ class,
1864 * <i>not</i> a string or macro.
1867 * Abstract Libkern C++ classes--those with at least one
1868 * pure virtual method--should "call" this macro
1869 * at the beginning of their implementation files,
1870 * before any function implementations for the class.
1872 #define OSDefineMetaClassAndAbstractStructors(className, superclassName) \
1873 OSDefineMetaClassAndAbstractStructorsWithInit (className, superclassName, )
1877 * @define OSDefineMetaClassAndFinalStructors
1881 * Defines an OSMetaClass and associated routines
1882 * for a final (non-subclassable) Libkern C++ class.
1884 * @param className The name of the C++ class, as a raw token,
1885 * <i>not</i> a string or macro.
1886 * @param superclassName The name of the superclass of the C++ class,
1888 * <i>not</i> a string or macro.
1891 * Final Libkern C++ classes--those that do not allow
1892 * subclassing--should "call" this macro at the beginning
1893 * of their implementation files,
1894 * before any function implementations for the class.
1895 * (Final classes in the kernel may actually have subclasses in the kernel,
1896 * but kexts cannot define any subclasses of a final class.)
1898 * <b>Note:</b> If the class is exported by a pseudokext (symbol set),
1899 * the final symbol generated by this macro must be exported
1900 * for the final-class attribute to be enforced.
1902 * <b>Warning:</b> Changing a class from "Default" to "Final" will break
1903 * binary compatibility.
1905 #define OSDefineMetaClassAndFinalStructors(className, superclassName) \
1906 OSDefineMetaClassAndFinalStructorsWithInit(className, superclassName, )
1909 // Dynamic vtable patchup support routines and types
1910 void reservedCalled(int ind
) const;
1914 * @define OSMetaClassDeclareReservedUnused
1918 * Reserves vtable space for new virtual functions
1919 * in a Libkern C++ class.
1921 * @param className The name of the C++ class, as a raw token,
1922 * <i>not</i> a string or macro.
1923 * @param index The numeric index of the vtable slot,
1924 * as a raw constant, beginning from 0.
1927 * Libkern C++ classes in kernel extensions that can be used as libraries
1928 * can provide for backward compatibility by declaring a number
1929 * of reserved vtable slots
1930 * that can be replaced with new functions as they are added.
1931 * Each reserved declaration must be accompanied in the implementation
1932 * by a corresponding reference to
1933 * <code>@link OSMetaClassDefineReservedUnused
1934 * OSMetaClassDefineReservedUnused@/link</code>.
1936 * When replacing a reserved slot, change the macro from "Unused"
1937 * to "Used" to document the fact that the slot used to be reserved,
1938 * and declare the new function immediately after the "Used" macro
1939 * to preserve vtable ordering.
1941 * <code>@link OSMetaClassDeclareReservedUsed
1942 * OSMetaClassDeclareReservedUsed@/link</code>.
1944 #define OSMetaClassDeclareReservedUnused(className, index) \
1946 APPLE_KEXT_PAD_METHOD void _RESERVED ## className ## index ()
1950 * @define OSMetaClassDeclareReservedUsed
1954 * Documents use of reserved vtable space for new virtual functions
1955 * in a Libkern C++ class.
1957 * @param className The name of the C++ class, as a raw token,
1958 * <i>not</i> a string or macro.
1959 * @param index The numeric index of the vtable slot,
1960 * as a raw constant, beginning from 0.
1963 * This macro evaluates to nothing, and is used to document reserved
1964 * vtable slots as they are filled.
1966 * <code>@link OSMetaClassDeclareReservedUnused
1967 * OSMetaClassDeclareReservedUnused@/link</code>.
1969 #define OSMetaClassDeclareReservedUsed(className, index)
1973 * @define OSMetaClassDefineReservedUnused
1977 * Defines a reserved vtable slot for a Libkern C++ class.
1979 * @param className The name of the C++ class, as a raw token,
1980 * <i>not</i> a string or macro.
1981 * @param index The numeric index of the vtable slot,
1982 * as a raw constant, beginning from 0.
1985 * Libkern C++ classes in kernel extensions that can be used as libraries
1986 * can provide for backward compatibility by declaring a number
1987 * of reserved vtable slots
1988 * that can be replaced with new functions as they are added.
1989 * Each reserved defintion accompanies
1990 * a corresponding declaration created with
1991 * <code>@link OSMetaClassDeclareReservedUnused
1992 * OSMetaClassDeclareReservedUnused@/link</code>.
1994 * This macro is used in the implementation file
1995 * to provide a placeholder definition for the reserved vtable slot,
1996 * as a function that calls <code>panic</code> with an error message.
1998 * When replacing a reserved slot, change the macro from "Unused"
1999 * to "Used" to document the fact that the slot used to be reserved,
2000 * and declare the new function immediately after the "Used" macro
2001 * to preserve vtable ordering.
2003 * <code>@link OSMetaClassDefineReservedUsed
2004 * OSMetaClassDefineReservedUsed@/link</code>.
2006 #define OSMetaClassDefineReservedUnused(className, index) \
2007 void className ::_RESERVED ## className ## index () \
2008 { APPLE_KEXT_PAD_IMPL(index); }
2012 * @define OSMetaClassDefineReservedUsed
2016 * Reserves vtable space for new virtual functions in a Libkern C++ class.
2018 * @param className The name of the C++ class, as a raw token,
2019 * <i>not</i> a string or macro.
2020 * @param index The numeric index of the vtable slot,
2021 * as a raw constant, beginning from 0.
2024 * This macro evaluates to nothing, and is used to document reserved
2025 * vtable slots as they are filled.
2027 * <code>@link OSMetaClassDefineReservedUnused
2028 * OSMetaClassDefineReservedUnused@/link</code>.
2030 #define OSMetaClassDefineReservedUsed(className, index)
2032 // I/O Kit debug internal routines.
2033 static void printInstanceCounts();
2034 static void serializeClassDictionary(OSDictionary
* dict
);
2038 static OSDictionary
* getClassDictionary();
2039 virtual bool serialize(OSSerialize
* serializer
) const;
2041 // Virtual Padding functions for MetaClass's
2042 OSMetaClassDeclareReservedUnused(OSMetaClass
, 0);
2043 OSMetaClassDeclareReservedUnused(OSMetaClass
, 1);
2044 OSMetaClassDeclareReservedUnused(OSMetaClass
, 2);
2045 OSMetaClassDeclareReservedUnused(OSMetaClass
, 3);
2046 OSMetaClassDeclareReservedUnused(OSMetaClass
, 4);
2047 OSMetaClassDeclareReservedUnused(OSMetaClass
, 5);
2048 OSMetaClassDeclareReservedUnused(OSMetaClass
, 6);
2049 OSMetaClassDeclareReservedUnused(OSMetaClass
, 7);
2052 #endif /* !_LIBKERN_OSMETACLASS_H */