]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSMetaClass.h
cb2f9896a0a77f76a87f2cbf862a00ebb183ae37
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
64 #define APPLE_KEXT_LEGACY_ABI 1
67 #if APPLE_KEXT_VTABLE_PADDING
69 #define APPLE_KEXT_PAD_METHOD virtual
71 #define APPLE_KEXT_PAD_IMPL(index) gMetaClass.reservedCalled(index)
73 #define APPLE_KEXT_PAD_METHOD static
74 #define APPLE_KEXT_PAD_IMPL(index)
79 #define APPLE_KEXT_COMPATIBILITY_VIRTUAL
81 // private method made virtual only for binary compatibility
82 #define APPLE_KEXT_COMPATIBILITY_VIRTUAL virtual
86 #define APPLE_KEXT_DEPRECATED __attribute__((deprecated))
89 * @class OSMetaClassBase
92 * OSMetaClassBase is the abstract bootstrap class
93 * for the Libkern and I/O Kit run-time type information system.
96 * OSMetaClassBase is the abstract C++ root class
97 * underlying the entire Libkern and I/O Kit class hierarchy.
98 * It defines the run-time type information system,
99 * including dynamic class allocation and safe type-casting,
100 * as well as the abstract interface for reference counting
101 * and a few other utility functions.
102 * OSMetaClassBase is the immediate superclass of
103 * @link //apple_ref/doc/class/OSObject OSObject@/link and
104 * @link //apple_ref/doc/class/OSMetaClass OSMetaClass@/link;
105 * no other class should derive from OSMetaClassBase.
107 * For more information, see
108 * <i>@link //apple_ref/doc/uid/TP40002799
109 * I/O Kit Device Driver Design Guidelines@/link</i>.
111 * <b>Use by Kernel Extensions</b>
113 * Kernel Extensions should never interact directly with OSMetaClassBase,
114 * but they will find useful several macros that tie in
115 * to the run-time type information system, specifically:
117 * <li><code>@link OSTypeAlloc OSTypeAlloc@/link</code> - allocation of new instances</li>
118 * <li><code>@link OSDynamicCast OSDynamicCast@/link</code> - safe type casting</li>
119 * <li><code>@link OSCheckTypeInst OSCheckTypeInst@/link</code> -
120 * checking for inheritance/derivation</li>
121 * <li><code>@link OSMemberFunctionCast OSMemberFunctionCast@/link</code> -
122 * casting C++ member functions to C function pointers
123 * for registration as callbacks</li>
126 * See @link //apple_ref/doc/class/OSMetaClass OSMetaClass@/link
127 * for more run-time type information interfaces.
129 * <b>Use Restrictions</b>
131 * OSMetaClassBase should not be subclassed by kernel extensions,
132 * nor should kernel extensions call its run-time type functions directly.
134 * The run-time type functions and macros are <b>not safe</b>
135 * to call in a primary interrupt context.
137 * <b>Concurrency Protection</b>
139 * The run-time type macros and functions of OSMetaClassBase are thread-safe.
141 class OSMetaClassBase
147 * @define OSTypeAlloc
151 * Allocates an instance of the named object class.
153 * @param type The name of the desired class to be created,
154 * as a raw token, <i>not</i> a string or macro.
157 * A pointer to the new, uninitialized object on success;
158 * <code>NULL</code> on failure.
163 * //apple_ref/cpp/clm/OSMetaClass/allocClassWithName/staticOSObject*\/(constchar*)
164 * OSMetaClass::allocClassWithName(const char *)@/link</code>
167 * //apple_ref/cpp/instm/OSMetaClass/alloc/virtualOSObject*\/()
168 * OSMetaClass::alloc@/link</code>.
170 * The OSTypeAlloc macro is used to avoid binary compatibility difficulties
171 * presented by the C++ <code>new</code> operator.
173 #define OSTypeAlloc(type) ((type *) ((type::metaClass)->alloc()))
181 * Returns the type ID (metaclass) of a class based on its name.
183 * @param type The name of the desired class, as a raw token,
184 * <i>not</i> a string or macro.
187 * The unique type ID (metaclass) for the class.
190 * It is typically more useful to determine whether a class is derived
192 * <code>@link //apple_ref/cpp/macro/OSDynamicCast OSDynamicCast@/link</code>
194 * <code>@link //apple_ref/cpp/macro/OSCheckTypeInst OSCheckTypeInst@/link</code>.
196 #define OSTypeID(type) (type::metaClass)
200 * @define OSTypeIDInst
204 * Returns the type ID (metaclass) for the class of an object instance.
206 * @param typeinst An instance of an OSObject subclass.
209 * The type ID of that object's class; that is, its metaclass.
212 * It is typically more useful to determine whether an object is derived
213 * from a particular class; see
214 * <code>@link //apple_ref/cpp/macro/OSDynamicCast OSDynamicCast@/link</code>
216 * <code>@link //apple_ref/cpp/macro/OSCheckTypeInst OSCheckTypeInst@/link</code>.
218 #define OSTypeIDInst(typeinst) ((typeinst)->getMetaClass())
222 * @define OSDynamicCast
226 * Safe type-casting for Libkern C++ objects.
228 * @param type The name of the desired class type, as a raw token,
229 * <i>not</i> a string or macro.
230 * It is assumed you intend to cast to a pointer
231 * to an object of this type.
232 * Type qualifiers, such as <code>const</code>,
233 * are not recognized and will cause
234 * a (usually obscure) compile error.
235 * @param inst A pointer to the object instance to be cast.
236 * May be <code>NULL</code>.
239 * <code>inst</code> if it is non-<code>NULL</code>
240 * and derived from <code>type</code>;
241 * otherwise <code>NULL</code>.
244 * <code>OSDynamicCast</code> is a rough equivalent
245 * to the standard C++ RTTI <code>dynamic_cast<T></code> operator.
246 * Your code should use this instead of raw C type-casting,
247 * and check the resulting value.
248 * If the result is non-<code>NULL</code>,
249 * the object is safe to use as the type-cast class;
250 * if the result is <code>NULL</code>,
251 * the object does not derive from the type-cast class
252 * and your code should take appropriate steps to handle the error.
254 #define OSDynamicCast(type, inst) \
255 ((type *) OSMetaClassBase::safeMetaCast((inst), OSTypeID(type)))
259 * @define OSCheckTypeInst
263 * Checks whether two objects are type-compatible.
265 * @param typeinst The reference object.
266 * @param inst The object to check for type compatibility.
269 * <code>true</code> if both <code>inst</code> and
270 * <code>typeinst</code> are non-<code>NULL</code>
271 * and <code>inst</code> is derived from the class of <code>typeinst</code>;
272 * otherwise <code>false</code>.
274 #define OSCheckTypeInst(typeinst, inst) \
275 OSMetaClassBase::checkTypeInst(inst, typeinst)
277 /*! @function OSSafeRelease
278 * @abstract Release an object if not <code>NULL</code>.
279 * @param inst Instance of an OSObject, may be <code>NULL</code>.
281 #define OSSafeRelease(inst) do { if (inst) (inst)->release(); } while (0)
283 /*! @function OSSafeReleaseNULL
284 * @abstract Release an object if not <code>NULL</code>, then set it to <code>NULL</code>.
285 * @param inst Instance of an OSObject, may be <code>NULL</code>.
287 #define OSSafeReleaseNULL(inst) do { if (inst) (inst)->release(); (inst) = NULL; } while (0)
289 typedef void (*_ptf_t
)(void);
291 #if APPLE_KEXT_LEGACY_ABI
293 // Arcane evil code interprets a C++ pointer to function as specified in the
294 // -fapple-kext ABI, i.e. the gcc-2.95 generated code. IT DOES NOT ALLOW
295 // the conversion of functions that are from MULTIPLY inherited classes.
298 _ptmf2ptf(const OSMetaClassBase
*self
, void (OSMetaClassBase::*func
)(void))
301 void (OSMetaClassBase::*fIn
)(void);
302 struct { // Pointer to member function 2.95
303 unsigned short fToff
;
313 if (map
.fptmf2
.fToff
) {
314 panic("Multiple inheritance is not supported");
316 } else if (map
.fptmf2
.fVInd
< 0) {
317 // Not virtual, i.e. plain member func
318 return map
.fptmf2
.u
.fPFN
;
321 const OSMetaClassBase
*fObj
;
326 // Virtual member function so dereference vtable
327 return (*u
.vtablep
)[map
.fptmf2
.fVInd
- 1];
331 #else /* !APPLE_KEXT_LEGACY_ABI */
333 // Slightly less arcane and slightly less evil code to do
334 // the same for kexts compiled with the standard Itanium C++
338 _ptmf2ptf(const OSMetaClassBase
*self
, void (OSMetaClassBase::*func
)(void))
341 void (OSMetaClassBase::*fIn
)(void);
348 if (map
.fVTOffset
& 1) {
351 const OSMetaClassBase
*fObj
;
356 // Virtual member function so dereference vtable
357 return *(_ptf_t
*)(((uintptr_t)*u
.vtablep
) + map
.fVTOffset
- 1);
359 // Not virtual, i.e. plain member func
365 #endif /* !APPLE_KEXT_LEGACY_ABI */
368 * @define OSMemberFunctionCast
372 * Converts a C++ member function pointer, relative to an instance,
373 * to a C-style pointer to function.
375 * @param cptrtype The function type declaration to cast to
376 * (typically provided as a <code>typedef</code> by I/O KitKit classes).
377 * @param self The <code>this</code> pointer of the object whose function
379 * @param func The pointer to the member function itself,
380 * something like <code>&Class::function</code>.
383 * A pointer to a function of the given type referencing <code>self</code>.
386 * This function is used to generate pointers to C++ functions for instances,
387 * such that they can be registered as callbacks with I/O Kit objects.
389 * No warnings are generated.
391 * This function will panic if an attempt is made to call it
392 * with a multiply-inheriting class.
394 #define OSMemberFunctionCast(cptrtype, self, func) \
395 (cptrtype) OSMetaClassBase:: \
396 _ptmf2ptf(self, (void (OSMetaClassBase::*)(void)) func)
400 virtual ~OSMetaClassBase();
403 // Disable copy constructors of OSMetaClassBase based objects
404 /* Not to be included in headerdoc.
406 * @function operator =
409 * Disable implicit copy constructor by making private
411 * @param src Reference to source object that isn't allowed to be copied.
413 void operator =(OSMetaClassBase
&src
);
415 /* Not to be included in headerdoc.
417 * @function OSMetaClassBase
420 * Disable implicit copy constructor by making private
422 * @param src Reference to source object that isn't allowed to be copied.
424 OSMetaClassBase(OSMetaClassBase
&src
);
428 // xx-review: the original comment for this makes it sound to me like we don't
429 // xx-review: catch over-releasing an object...?
435 * Abstract declaration of
437 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/(int)
438 * release(int freeWhen)@/link</code>.
443 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/(int)
444 * release(int freeWhen)@/link</code>.
446 virtual void release(int freeWhen
) const = 0;
450 * @function getRetainCount
453 * Abstract declaration of
455 * //apple_ref/cpp/instm/OSObject/getRetainCount/virtualint/()
456 * getRetainCount()@/link</code>.
461 * //apple_ref/cpp/instm/OSObject/getRetainCount/virtualint/()
462 * OSObject::getRetainCount()@/link</code>.
464 virtual int getRetainCount() const = 0;
471 * Abstract declaration of
473 * //apple_ref/cpp/instm/OSObject/retain/virtualvoid/()
474 * retain()@/link</code>.
479 * //apple_ref/cpp/instm/OSObject/retain/virtualvoid/()
480 * OSObject::retain()@/link</code>.
482 virtual void retain() const = 0;
489 * Abstract declaration of
491 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/()
492 * release@/link</code>.
497 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/()
498 * OSObject::release@/link</code>.
500 virtual void release() const = 0;
504 * @function serialize
507 * Abstract declaration of
509 * //apple_ref/cpp/instm/OSObject/serialize/virtualbool/(OSSerialize*)
510 * serialize@/link</code>.
515 * //apple_ref/cpp/instm/OSObject/serialize/virtualbool/(OSSerialize*)
516 * OSObject::serialize@/link</code>.
518 virtual bool serialize(OSSerialize
* serializer
) const = 0;
522 * @function getMetaClass
525 * Returns the OSMetaClass representing
526 * an OSMetaClassBase subclass.
529 * OSObject overrides this abstract member function
530 * to return the OSMetaClass object that represents
531 * each class for run-time typing.
533 virtual const OSMetaClass
* getMetaClass() const = 0;
537 * @function isEqualTo
540 * Checks whether another object is equal to the receiver.
542 * @param anObject The object to copmare to the receiver.
545 * <code>true</code> if the objects are equal, <code>false</code> otherwise.
548 * OSMetaClassBase implements this as a direct pointer comparison,
549 * since it has no other information to judge equality by.
550 * Subclasses generally override this function
551 * to do a more meaningful comparison.
552 * For example, OSString implements it to return
553 * <code>true</code> if <code>anObject</code>
554 * is derived from OSString and represents the same C string.
556 virtual bool isEqualTo(const OSMetaClassBase
* anObject
) const;
563 * Casts this object is to the class managed by the given OSMetaClass.
565 * @param toMeta A pointer to a constant OSMetaClass
566 * for the desired target type.
569 * <code>this</code> if the object is derived
570 * from the class managed by <code>toMeta</code>,
571 * otherwise <code>NULL</code>.
574 * It is far more convenient to use
575 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
577 OSMetaClassBase
* metaCast(const OSMetaClass
* toMeta
) const;
584 * Casts this object is to the class managed by the named OSMetaClass.
586 * @param toMeta An OSSymbol naming the desired target type.
589 * <code>this</code> if the object is derived
590 * from the class named by <code>toMeta</code>,
591 * otherwise <code>NULL</code>.
594 * It is far more convenient to use
595 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
597 OSMetaClassBase
* metaCast(const OSSymbol
* toMeta
) const;
604 * Casts this object is to the class managed by the named OSMetaClass.
606 * @param toMeta An OSString naming the desired target type.
608 * <code>this</code> if the object is derived
609 * from the class named by <code>toMeta</code>,
610 * otherwise <code>NULL</code>.
613 * It is far more convenient to use
614 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
616 OSMetaClassBase
* metaCast(const OSString
* toMeta
) const;
623 * Casts this object is to the class managed by the named OSMetaClass.
625 * @param toMeta A C string naming the desired target type.
627 * <code>this</code> if the object is derived
628 * from the class named by <code>toMeta</code>,
629 * otherwise <code>NULL</code>.
632 * It is far more convenient to use
633 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
635 OSMetaClassBase
* metaCast(const char * toMeta
) const;
637 // Helper inlines for run-time type preprocessor macros
639 * @function safeMetaCast
642 * Casts an object is to the class managed by the given OSMetaClass.
644 * @param anObject A pointer to the object to be cast.
645 * @param toMeta A pointer to a constant OSMetaClass
646 * for the desired target type.
649 * <code>anObject</code> if the object is derived
650 * from the class managed by <code>toMeta</code>,
651 * otherwise <code>NULL</code>.
654 * It is far more convenient to use
655 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
657 static OSMetaClassBase
* safeMetaCast(
658 const OSMetaClassBase
* anObject
,
659 const OSMetaClass
* toMeta
);
662 * @function checkTypeInst
665 * Checks whether an object instance is of the same class
666 * as another object instance (or a subclass of that class).
668 * @param inst A pointer to the object to check.
669 * @param typeinst A pointer to an object of the class being checked.
672 * <code>true</code> if the object is derived
673 * from the class of <code>typeinst</code>
674 * or a subclass of that class,
675 * otherwise <code>false</code>.
678 * It is far more convenient to use
679 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
681 static bool checkTypeInst(
682 const OSMetaClassBase
* inst
,
683 const OSMetaClassBase
* typeinst
);
685 static void initialize(void);
690 * @function taggedRetain
693 * Abstract declaration of
695 * //apple_ref/cpp/instm/OSObject/taggedRetain/virtualvoid/(constvoid*)
696 * taggedRetain(const void *)@/link</code>.
701 * //apple_ref/cpp/instm/OSObject/taggedRetain/virtualvoid/(constvoid*)
702 * OSObject::taggedRetain(const void *)@/link</code>.
704 // WAS: virtual void _RESERVEDOSMetaClassBase0();
705 virtual void taggedRetain(const void * tag
= 0) const = 0;
709 * @function taggedRelease
712 * Abstract declaration of
714 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*)
715 * taggedRelease(const void *)@/link</code>.
720 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*)
721 * OSObject::taggedRelease(const void *)@/link</code>.
723 // WAS: virtual void _RESERVEDOSMetaClassBase1();
724 virtual void taggedRelease(const void * tag
= 0) const = 0;
728 * @function taggedRelease
731 * Abstract declaration of
733 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*,constint)
734 * taggedRelease(const void *, const int freeWhen)@/link</code>.
739 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*,constint)
740 * OSObject::taggedRelease(const void *, const int freeWhen)@/link</code>.
742 // WAS: virtual void _RESERVEDOSMetaClassBase2();
743 virtual void taggedRelease(
745 const int freeWhen
) const = 0;
749 virtual void _RESERVEDOSMetaClassBase3();
750 virtual void _RESERVEDOSMetaClassBase4();
751 virtual void _RESERVEDOSMetaClassBase5();
752 virtual void _RESERVEDOSMetaClassBase6();
753 virtual void _RESERVEDOSMetaClassBase7();
754 } APPLE_KEXT_COMPATIBILITY
;
761 * OSMetaClass manages run-time type information
762 * for Libkern and I/O Kit C++ classes.
766 * OSMetaClass manages run-time type information
767 * for Libkern and I/O Kit C++ classes.
768 * An instance of OSMetaClass exists for (nearly) every such C++ class,
769 * keeping track of inheritance relationships, class lookup by name,
770 * instance counts, and more.
771 * OSMetaClass operates almost entirely behind the scenes,
772 * and kernel extensions should rarely, if ever,
773 * have to interact directly with OSMetaClass.
775 * <b>Use by Kernel Extensions</b>
777 * While kernel extensions rarey interact directly with OSMetaClass at run time,
778 * they must register their classes with the metaclass system
779 * using the macros declared here.
780 * The class declaration should use one of these two macros
781 * before its first member function declaration:
783 * <li><code>@link OSDeclareDefaultStructors OSDeclareDefaultStructors@/link</code> -
784 * for classes with no abstract member function declarations</li>
785 * <li><code>@link OSDeclareAbstractStructors OSDeclareAbstractStructors@/link</code> -
786 * for classes with at least one abstract member function declaration</li>
787 * <li><code>@link OSDeclareFinalStructors OSDeclareFinalStructors@/link</code> -
788 * for classes that should not be subclassable by another kext</li>
791 * The class implementation should then use one of these macros:
793 * <li><code>@link OSDefineMetaClassAndStructors
794 * OSDefineMetaClassAndStructors@/link</code> -
795 * for classes with no abstract member function declarations</li>
796 * <li><code>@link OSDefineMetaClassAndAbstractStructors
797 * OSDefineMetaClassAndAbstractStructors@/link</code> -
798 * for classes with at least one abstract member function declaration</li>
799 * <li><code>@link OSDefineMetaClassAndFinalStructors
800 * OSDefineMetaClassAndFinalStructors@/link</code> -
801 * for classes that should not be subclassable by another kext</li>
804 * Classes in kernel extensions that are intended for use as libraries
805 * may need to reserve vtable slots to preserve binary compatibility
806 * as new functions are added. They may do so with these macros:
808 * <li><code>@link OSMetaClassDeclareReservedUnused
809 * OSMetaClassDeclareReservedUnused@/link</code> -
810 * reserves a vtable slot</li>
811 * <li><code>@link OSMetaClassDefineReservedUnused
812 * OSMetaClassDefineReservedUnused@/link</code> -
813 * defines the reserved vtable slot as an unimplemented function</li>
814 * <li><code>@link OSMetaClassDeclareReservedUsed
815 * OSMetaClassDeclareReservedUsed@/link</code> -
816 * documents that a formerly reserved slot is now used</li>
817 * <li><code>@link OSMetaClassDefineReservedUsed
818 * OSMetaClassDefineReservedUsed@/link</code> -
819 * documents that a formerly reserved slot is now used</li>
822 * <b>Use Restrictions</b>
824 * OSMetaClass should not be explicitly subclassed by kernel extensions
825 * (the declare/define macros do that),
826 * nor should kernel extensions call its run-time type functions directly.
828 * OSMetaClass functions should be considered
829 * <b>unsafe</b> to call in a primary interrupt context.
831 * <b>Concurrency Protection</b>
833 * Kernel extensions should in general not interact
834 * with OSMetaClass objects directly,
835 * instead using the run-time type macros.
836 * Much of OSMetaClass's interface is intended for use
837 * by the run-time type information system,
838 * which handles concurrency and locking internally.
840 class OSMetaClass
: private OSMetaClassBase
844 friend class IOStatistics
;
848 // Can never be allocated must be created at compile time
849 static void * operator new(size_t size
);
851 struct ExpansionData
{ };
853 /* Reserved for future use. (Internal use only) */
854 ExpansionData
*reserved
;
856 /* superClass Handle to the superclass's meta class. */
857 const OSMetaClass
*superClassLink
;
859 /* className OSSymbol of the class' name. */
860 const OSSymbol
*className
;
862 /* classSize How big is a single instance of this class. */
863 unsigned int classSize
;
865 /* instanceCount Roughly number of instances of the object,
866 * +1 for each direct subclass with a nonzero refcount.
867 * Used primarily as a code-in-use flag.
869 mutable unsigned int instanceCount
;
871 /* Not to be included in headerdoc.
873 * @function OSMetaClass
876 * The default private constructor.
880 // Called by postModLoad
881 /* Not to be included in headerdoc.
886 * Logs an error string for an <code>OSReturn</code> value
887 * using <code>printf</code>.
889 * @param result The <code>OSReturn</code> value for which to log a message.
892 * This function is used to log errors loading kernel extensions.
893 * Kernel extensions themselves should not call it.
895 static void logError(OSReturn result
);
900 * @function getMetaClassWithName
903 * Look up a metaclass in the run-time type information system.
905 * @param name The name of the desired class's metaclass.
908 * A pointer to the metaclass object if found, <code>NULL</code> otherwise.
910 static const OSMetaClass
* getMetaClassWithName(const OSSymbol
* name
);
917 * Implements the abstract <code>retain</code> function to do nothing.
920 * Since an OSMetaClass instance must remain in existence
921 * for as long as its kernel extension is loaded,
922 * OSMetaClass does not use reference-counting.
924 virtual void retain() const;
931 * Implements the abstract <code>release</code> function to do nothing.
934 * Since an OSMetaClass instance must remain in existence
935 * for as long as its kernel extension is loaded,
936 * OSMetaClass does not use reference-counting.
938 virtual void release() const;
945 * Implements the abstract <code>release(int freeWhen)</code>
946 * function to do nothing.
948 * @param freeWhen Unused.
951 * Since an OSMetaClass instance must remain in existence
952 * for as long as its kernel extension is loaded,
953 * OSMetaClass does not use reference-counting.
955 virtual void release(int freeWhen
) const;
959 * @function taggedRetain
962 * Implements the abstract <code>taggedRetain(const void *)</code>
963 * function to do nothing.
968 * Since an OSMetaClass instance must remain in existence
969 * for as long as its kernel extension is loaded,
970 * OSMetaClass does not use reference-counting.
972 virtual void taggedRetain(const void * tag
= 0) const;
976 * @function taggedRelease
979 * Implements the abstract <code>taggedRelease(const void *)</code>
980 * function to do nothing.
985 * Since an OSMetaClass instance must remain in existence
986 * for as long as its kernel extension is loaded,
987 * OSMetaClass does not use reference-counting.
989 virtual void taggedRelease(const void * tag
= 0) const;
993 * @function taggedRelease
996 * Implements the abstract <code>taggedRelease(const void *, cont int)</code>
997 * function to do nothing.
1000 * @param freeWhen Unused.
1003 * Since an OSMetaClass instance must remain in existence
1004 * for as long as its kernel extension is loaded,
1005 * OSMetaClass does not use reference-counting.
1007 virtual void taggedRelease(
1009 const int freeWhen
) const;
1013 * @function getRetainCount
1016 * Implements the abstract <code>getRetainCount</code>
1017 * function to return 0.
1023 * Since an OSMetaClass instance must remain in existence
1024 * for as long as its kernel extension is loaded,
1025 * OSMetaClass does not use reference-counting.
1027 virtual int getRetainCount() const;
1030 /* Not to be included in headerdoc.
1032 * @function getMetaClass
1035 * Returns the meta-metaclass.
1038 * The metaclass of the OSMetaClass object.
1040 virtual const OSMetaClass
* getMetaClass() const;
1044 * @function OSMetaClass
1047 * Constructor for OSMetaClass objects.
1049 * @param className A C string naming the C++ class
1050 * that this OSMetaClass represents.
1051 * @param superclass The OSMetaClass object representing the superclass
1052 * of this metaclass's class.
1053 * @param classSize The allocation size of the represented C++ class.
1056 * This constructor is protected and cannot be used
1057 * to instantiate OSMetaClass directly, as OSMetaClass is an abstract class.
1058 * This function is called during kext loading
1059 * to queue C++ classes for registration.
1060 * See <code>@link preModLoad preModLoad@/link</code> and
1061 * <code>@link postModLoad postModLoad@/link</code>.
1063 OSMetaClass(const char * className
,
1064 const OSMetaClass
* superclass
,
1065 unsigned int classSize
);
1069 * @function ~OSMetaClass
1072 * Destructor for OSMetaClass objects.
1075 * This function is called when the kernel extension that implements
1076 * the metaclass's class is unloaded.
1077 * The destructor removes all references to the class
1078 * from the run-time type information system.
1080 virtual ~OSMetaClass();
1082 // Needs to be overriden as NULL as all OSMetaClass objects are allocated
1083 // statically at compile time, don't accidently try to free them.
1084 void operator delete(void *, size_t) { };
1087 static const OSMetaClass
* const metaClass
;
1090 * @function preModLoad
1093 * Prepares the run-time type system
1094 * for the creation of new metaclasses
1095 * during loading of a kernel extension (module).
1097 * @param kextID The bundle ID of the kext being loaded.
1100 * An opaque handle to the load context
1101 * for the kernel extension on success;
1102 * <code>NULL</code> on failure.
1105 * <i>Not for use by kernel extensions.</i>
1107 * Prepares the run-time type information system to record and register
1108 * metaclasses created by static constructors until a subsequent call to
1109 * <code>@link postModLoad postModLoad@/link</code>.
1110 * <code>preModLoad</code> takes a lock to ensure processing of a single
1111 * load operation at a time; the lock is released by
1112 * <code>@link postModLoad postModLoad@/link</code>.
1113 * Any OSMetaClass constructed between these two function calls
1114 * will be associated with <code>kextID</code>.
1116 static void * preModLoad(const char * kextID
);
1120 * @function checkModLoad
1123 * Checks whether the current kext load operation can proceed.
1125 * @param loadHandle The opaque handle returned
1126 * by <code>@link preModLoad preModLoad@/link</code>.
1128 * <code>true</code> if no errors are outstanding
1129 * and the system is ready to process more metaclasses.
1132 * <i>Not for use by kernel extensions.</i>
1134 static bool checkModLoad(void * loadHandle
);
1138 * @function postModLoad
1141 * Registers the metaclasses created during loading of a kernel extension.
1143 * @param loadHandle The opaque handle returned
1144 * by <code>@link preModLoad preModLoad@/link</code>.
1146 * The error code of the first error encountered,
1149 * //apple_ref/cpp/macro/kOSReturnSuccess
1150 * kOSReturnSuccess@/link</code>
1151 * if no error occurred.
1154 * <i>Not for use by kernel extensions.</i>
1156 * Called after all static constructors in a kernel extension
1157 * have created metaclasses,
1158 * this function checks for duplicate class names,
1159 * then registers the new metaclasses under the kext ID
1160 * that @link preModLoad preModLoad@/link was called with,
1161 * so that they can be dynamically allocated
1162 * and have their instance counts tracked.
1163 * <code>postModLoad</code> releases the lock taken by
1164 * <code>@link preModLoad preModLoad@/link</code>.
1166 static OSReturn
postModLoad(void * loadHandle
);
1169 * @function modHasInstance
1172 * Returns whether any classes defined by the named
1173 * kernel extension (or their subclasses) have existing instances.
1175 * @param kextID The bundle ID of the kernel extension to check.
1178 * <code>true</code> if the kext is found and
1179 * if any class defined by that kext
1180 * has a nonzero instance count,
1181 * <code>false</code> otherwise.
1184 * This function is called before a kernel extension's static destructors
1185 * are invoked, prior to unloading the extension.
1186 * If any classes stil have instances or subclasses with instances,
1187 * those classes are logged
1188 * (using <code>@link reportModInstances reportModInstances@/link</code>) and
1189 * the kernel extension is not be unloaded.
1191 static bool modHasInstance(const char * kextID
);
1195 * @function reportModInstances
1198 * Logs the instance counts for classes
1199 * defined by a kernel extension.
1201 * @param kextID The bundle ID of the kernel extension to report on.
1204 * This function prints the names and instance counts
1205 * of any class defined by <code>kextID</code>
1206 * that has a nonzero instance count.
1207 * It's called by <code>@link modHasInstance modHasInstance@/link</code>
1208 * to help diagnose problems unloading kernel extensions.
1210 static void reportModInstances(const char * kextID
);
1214 * @function considerUnloads
1217 * Schedule automatic unloading of unused kernel extensions.
1220 * This function schedules a check for kernel extensions
1221 * that can be automatically unloaded,
1222 * canceling any currently scheduled check.
1223 * At that time, any such kexts with no Libkern C++ instances
1224 * and no external references are unloaded.
1226 * The I/O Kit calls this function when matching goes idle.
1228 * Kernel extensions that define subclasses of
1229 * @link //apple_ref/doc/class/IOService IOService@/link
1230 * are eligible for automatic unloading.
1232 * (On releases of Mac OS X prior to Snow Leopard (10.6),
1233 * any kernel extension defining any Libkern C++ class
1234 * was eligible for automatic unloading,
1235 * but that unload did not call the module stop routine.
1236 * Non-I/O Kit kernel extensions that define Libkern C++ subclasses
1237 * should be sure to have OSBundleLibraries declarations that ensure
1238 * they will not load on releases prior to Snow Leopard.)
1240 static void considerUnloads();
1244 * @function allocClassWithName
1247 * Allocates an instance of a named OSObject-derived class.
1249 * @param name The name of the desired class.
1252 * A pointer to the newly-allocated, uninitialized object on success;
1253 * <code>NULL</code> on failure.
1256 * Kernel extensions should not need to use this function
1257 * directly, instead using static instance-creation functions
1258 * defined by classes.
1260 * This function consults the run-time type information system
1261 * to find the metaclass for the named class.
1262 * If it exists, it calls the metaclass's <code>@link alloc alloc@/link</code>
1263 * function and returns the result.
1265 static OSObject
* allocClassWithName(const OSSymbol
* name
);
1269 * function allocClassWithName
1272 * Allocates an instance of a named OSObject-derived class.
1274 * @param name The name of the desired class.
1277 * A pointer to the newly-allocated, uninitialized object on success;
1278 * <code>NULL</code> on failure.
1281 * Kernel extensions should not need to use this function
1282 * directly, instead using static instance-creation functions
1283 * defined by classes.
1285 * This function consults the run-time type information system
1286 * to find the metaclass for the named class.
1287 * If it exists, it calls the metaclass's <code>@link alloc alloc@/link</code>
1288 * function and returns the result.
1290 static OSObject
* allocClassWithName(const OSString
* name
);
1294 * function allocClassWithName
1297 * Allocates an instance of a named OSObject-derived class.
1299 * @param name The name of the desired class.
1302 * A pointer to the newly-allocated, uninitialized object on success;
1303 * <code>NULL</code> on failure.
1306 * Kernel extensions should not need to use this function
1307 * directly, instead using static instance-creation functions
1308 * defined by classes.
1310 * This function consults the run-time type information system
1311 * to find the metaclass for the named class.
1312 * If it exists, it calls the metaclass's <code>@link alloc alloc@/link</code>
1313 * function and returns the result.
1315 static OSObject
* allocClassWithName(const char * name
);
1319 * @function checkMetaCastWithName
1322 * Search the metaclass inheritance hierarchy by name for an object instance.
1324 * @param className The name of the desired class or superclass.
1325 * @param object The object whose metaclass begins the search.
1328 * <code>object</code> if it's derived from <code>className</code>;
1329 * <code>NULL</code> otherwise.
1332 * This function is the basis of the Libkern run-time type-checking system.
1333 * Kernel extensions should not use it directly,
1334 * instead using <code>@link OSDynamicCast OSDynamicCast@/link</code> or
1335 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
1337 static OSMetaClassBase
* checkMetaCastWithName(
1338 const OSSymbol
* className
,
1339 const OSMetaClassBase
* object
);
1342 * @function checkMetaCastWithName
1345 * Search the metaclass inheritance hierarchy by name for an object instance.
1347 * @param className The name of the desired class or superclass.
1348 * @param object The object whose metaclass begins the search.
1351 * <code>object</code> if it's derived from <code>className</code>;
1352 * <code>NULL</code> otherwise.
1355 * Kernel extensions should not use this function directly,
1356 * instead using <code>@link OSDynamicCast OSDynamicCast@/link</code> or
1357 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
1359 static OSMetaClassBase
* checkMetaCastWithName(
1360 const OSString
* className
,
1361 const OSMetaClassBase
* object
);
1364 * @function checkMetaCastWithName
1367 * Search the metaclass inheritance hierarchy by name for an object instance.
1369 * @param className The name of the desired class or superclass.
1370 * @param object The object whose metaclass begins the search.
1373 * <code>object</code> if it's derived from <code>className</code>;
1374 * <code>NULL</code> otherwise.
1377 * Kernel extensions should not use this function directly,
1378 * instead using <code>@link OSDynamicCast OSDynamicCast@/link</code> or
1379 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
1381 static OSMetaClassBase
* checkMetaCastWithName(
1382 const char * className
,
1383 const OSMetaClassBase
* object
);
1387 * @function instanceConstructed
1390 * Counts the instances of the class managed by this metaclass.
1393 * <i>Not for use by kernel extensions.</i>
1395 * Every non-abstract class that inherits from OSObject
1396 * has a default constructor that calls it's own metaclass's
1397 * <code>instanceConstructed</code> function.
1398 * This constructor is defined by the
1400 * OSDefineMetaClassAndStructors
1401 * OSDefineMetaClassAndStructors@/link</code>
1402 * macro that all OSObject subclasses must use.
1404 * If a class's instance count goes from 0 to 1--that is,
1405 * upon the creation of the first instance of that class--the
1406 * superclass's instance count is also incremented.
1407 * This propagates reference counts up the inheritance chain so that
1408 * superclasses are counted as "in use" when subclasses have instances.
1410 void instanceConstructed() const;
1414 * @function instanceDestructed
1417 * Counts the instances of the class managed by this metaclass.
1420 * Every non-abstract class that inherits from OSObject
1421 * has a default destructor that calls it's own metaclass's
1422 * <code>instanceDestructed</code> function.
1423 * This constructor is defined by the
1424 * @link OSDefineMetaClassAndStructors OSDefineMetaClassAndStructors@/link
1425 * macro that all OSObject subclasses must use.
1427 * If a class's instance count goes from 1 to 0--that is,
1428 * upon the destruction of the last instance of that class--the
1429 * superclass's instance count is also decremented.
1430 * This reduces "in use" counts from superclasses when their subclasses
1431 * no longer have instances.
1433 void instanceDestructed() const;
1437 * @function checkMetaCast
1440 * Check whether a given object is an instance of the receiving
1441 * metaclass's class or one derived from it.
1443 * @param object The object to check for inheritance.
1446 * <code>object</code> if it is derived from the receiver's class,
1447 * <code>NULL</code> if not.
1449 OSMetaClassBase
* checkMetaCast(const OSMetaClassBase
* object
) const;
1453 * @function getInstanceCount
1456 * Returns the number of existing instances of the metaclass's class.
1459 * The number of existing instances of the metaclass's class,
1460 * plus 1 for each subclass with any instance.
1462 unsigned int getInstanceCount() const;
1466 * @function getSuperClass
1469 * Returns the super-metaclass of the receiver.
1472 * Returns a pointer to the super-metaclass of the receiving
1473 * OSMetaClass, or <code>NULL</code> for OSObject's metaclass.
1475 const OSMetaClass
* getSuperClass() const;
1479 * @function getKmodName
1482 * Returns the bundle identifier of the kernel extension
1483 * that defines this metaclass.
1486 * The bundle identifier of the kernel extension that defines this metaclass.
1489 * "Kmod" is an older term for kernel extension.
1491 const OSSymbol
* getKmodName() const;
1495 * @function getClassName
1498 * Returns the name of the C++ class managed by this metaclass.
1501 * Returns the name of the C++ class managed by this metaclass.
1503 const char * getClassName() const;
1507 * @function getClassSize
1510 * Returns the allocation size of the C++ class managed by this metaclass.
1513 * The allocation size of the C++ class managed by this metaclass.
1515 unsigned int getClassSize() const;
1522 * Allocates an instance of the C++ class managed by this metaclass.
1525 * A pointer to the newly allocated, uninitialized instance,
1526 * with a retain count of 1; <code>NULL</code> on allocation failure.
1529 * This function is automatically created by the metaclass-registration macros
1530 * to enable dynamic instance allocation.
1532 virtual OSObject
* alloc() const = 0;
1535 /* Not to be included in headerdoc.
1537 * @define OSDeclareCommonStructors
1541 * Helper macro for for the standard metaclass-registration macros.
1544 * @param className The name of the C++ class, as a raw token,
1545 * <i>not</i> a string or macro.
1547 #define OSDeclareCommonStructors(className) \
1549 static const OSMetaClass * const superClass; \
1551 static const OSMetaClass * const metaClass; \
1552 static class MetaClass : public OSMetaClass { \
1555 virtual OSObject *alloc() const; \
1557 friend class className ::MetaClass; \
1558 virtual const OSMetaClass * getMetaClass() const; \
1560 className (const OSMetaClass *); \
1561 virtual ~ className ()
1565 * @define OSDeclareDefaultStructors
1569 * Declares run-time type information and functions
1570 * for a concrete Libkern C++ class.
1572 * @param className The name of the C++ class, as a raw token,
1573 * <i>not</i> a string or macro.
1576 * Concrete Libkern C++ classes should "call" this macro
1577 * immediately after the opening brace in a class declaration.
1578 * It leaves the current privacy state as <code>protected:</code>.
1580 #define OSDeclareDefaultStructors(className) \
1581 OSDeclareCommonStructors(className); \
1588 * @define OSDeclareAbstractStructors
1592 * Declares run-time type information and functions
1593 * for an abstract Libkern C++ class.
1595 * @param className The name of the C++ class, as a raw token,
1596 * <i>not</i> a string or macro.
1599 * Abstract Libkern C++ classes--those with at least one
1600 * pure virtual method--should "call" this macro
1601 * immediately after the opening brace in a class declaration.
1602 * It leaves the current privacy state as <code>protected:</code>.
1604 #define OSDeclareAbstractStructors(className) \
1605 OSDeclareCommonStructors(className); \
1607 className (); /* Make primary constructor private in abstract */ \
1611 * @define OSDeclareFinalStructors
1615 * Declares run-time type information and functions
1616 * for a final (non-subclassable) Libkern C++ class.
1618 * @param className The name of the C++ class, as a raw token,
1619 * <i>not</i> a string or macro.
1622 * Final Libkern C++ classes--those that do not allow subclassing--should
1623 * "call" this macro immediately after the opening brace in a class declaration.
1624 * (Final classes in the kernel may actually have subclasses in the kernel,
1625 * but kexts cannot define any subclasses of a final class.)
1626 * It leaves the current privacy state as <code>protected:</code>.
1628 * <b>Note:</b> If the class is exported by a pseudokext (symbol set),
1629 * the final symbol generated by this macro must be exported
1630 * for the final-class attribute to be enforced.
1632 * <b>Warning:</b> Changing a class from "Default" to "Final" will break
1633 * binary compatibility.
1635 #define OSDeclareFinalStructors(className) \
1636 OSDeclareDefaultStructors(className) \
1638 void __OSFinalClass(void); \
1642 /* Not to be included in headerdoc.
1644 * @define OSDefineMetaClassWithInit
1648 * Helper macro for for the standard metaclass-registration macros.
1651 * @param className The name of the C++ class, as a raw token,
1652 * <i>not</i> a string or macro.
1653 * @param superclassName The name of the superclass of the C++ class,
1655 * <i>not</i> a string or macro.
1656 * @param init A function to call in the constructor
1657 * of the class's OSMetaClass.
1659 #define OSDefineMetaClassWithInit(className, superclassName, init) \
1660 /* Class global data */ \
1661 className ::MetaClass className ::gMetaClass; \
1662 const OSMetaClass * const className ::metaClass = \
1663 & className ::gMetaClass; \
1664 const OSMetaClass * const className ::superClass = \
1665 & superclassName ::gMetaClass; \
1666 /* Class member functions */ \
1667 className :: className(const OSMetaClass *meta) \
1668 : superclassName (meta) { } \
1669 className ::~ className() { } \
1670 const OSMetaClass * className ::getMetaClass() const \
1671 { return &gMetaClass; } \
1672 /* The ::MetaClass constructor */ \
1673 className ::MetaClass::MetaClass() \
1674 : OSMetaClass(#className, className::superClass, sizeof(className)) \
1678 /* Not to be included in headerdoc.
1680 * @define OSDefineAbstractStructors
1684 * Helper macro for for the standard metaclass-registration macros.
1687 * @param className The name of the C++ class, as a raw token,
1688 * <i>not</i> a string or macro.
1689 * @param superclassName The name of the superclass of the C++ class,
1691 * <i>not</i> a string or macro.
1693 #define OSDefineAbstractStructors(className, superclassName) \
1694 OSObject * className ::MetaClass::alloc() const { return 0; }
1697 /* Not to be included in headerdoc.
1699 * @define OSDefineDefaultStructors
1703 * Helper macro for for the standard metaclass-registration macros.
1706 * @param className The name of the C++ class, as a raw token,
1707 * <i>not</i> a string or macro.
1708 * @param superclassName The name of the superclass of the C++ class,
1710 * <i>not</i> a string or macro.
1712 #define OSDefineDefaultStructors(className, superclassName) \
1713 OSObject * className ::MetaClass::alloc() const \
1714 { return new className; } \
1715 className :: className () : superclassName (&gMetaClass) \
1716 { gMetaClass.instanceConstructed(); }
1718 /* Not to be included in headerdoc.
1720 * @define OSDefineDefaultStructors
1724 * Helper macro for for the standard metaclass-registration macros.
1727 * @param className The name of the C++ class, as a raw token,
1728 * <i>not</i> a string or macro.
1729 * @param superclassName The name of the superclass of the C++ class,
1731 * <i>not</i> a string or macro.
1733 #define OSDefineFinalStructors(className, superclassName) \
1734 OSDefineDefaultStructors(className, superclassName) \
1735 void className ::__OSFinalClass(void) { }
1738 /* Not to be included in headerdoc.
1740 * @define OSDefineMetaClassAndStructorsWithInit
1744 * Helper macro for for the standard metaclass-registration macros.
1747 * @param className The name of the C++ class, as a raw token,
1748 * <i>not</i> a string or macro.
1749 * @param superclassName The name of the superclass of the C++ class,
1751 * <i>not</i> a string or macro.
1752 * @param init A function to call in the constructor
1753 * of the class's OSMetaClass.
1755 #define OSDefineMetaClassAndStructorsWithInit(className, superclassName, init) \
1756 OSDefineMetaClassWithInit(className, superclassName, init) \
1757 OSDefineDefaultStructors(className, superclassName)
1760 /* Not to be included in headerdoc.
1762 * @define OSDefineMetaClassAndAbstractStructorsWithInit
1766 * Helper macro for for the standard metaclass-registration macros.
1769 * @param className The name of the C++ class, as a raw token,
1770 * <i>not</i> a string or macro.
1771 * @param superclassName The name of the superclass of the C++ class,
1773 * <i>not</i> a string or macro.
1774 * @param init A function to call in the constructor
1775 * of the class's OSMetaClass.
1777 #define OSDefineMetaClassAndAbstractStructorsWithInit(className, superclassName, init) \
1778 OSDefineMetaClassWithInit(className, superclassName, init) \
1779 OSDefineAbstractStructors(className, superclassName)
1782 /* Not to be included in headerdoc.
1784 * @define OSDefineMetaClassAndFinalStructorsWithInit
1788 * Helper macro for for the standard metaclass-registration macros.
1791 * @param className The name of the C++ class, as a raw token,
1792 * <i>not</i> a string or macro.
1793 * @param superclassName The name of the superclass of the C++ class,
1795 * <i>not</i> a string or macro.
1796 * @param init A function to call in the constructor
1797 * of the class's OSMetaClass.
1799 #define OSDefineMetaClassAndFinalStructorsWithInit(className, superclassName, init) \
1800 OSDefineMetaClassWithInit(className, superclassName, init) \
1801 OSDefineFinalStructors(className, superclassName)
1806 /* Not to be included in headerdoc.
1808 * @define OSDefineMetaClass
1812 * Helper macro for for the standard metaclass-registration macros.
1815 * @param className The name of the C++ class, as a raw token,
1816 * <i>not</i> a string or macro.
1817 * @param superclassName The name of the superclass of the C++ class,
1819 * <i>not</i> a string or macro.
1820 * @param init A function to call in the constructor
1821 * of the class's OSMetaClass.
1823 #define OSDefineMetaClass(className, superclassName) \
1824 OSDefineMetaClassWithInit(className, superclassName, )
1828 * @define OSDefineMetaClassAndStructors
1832 * Defines an OSMetaClass and associated routines
1833 * for a concrete Libkern C++ class.
1835 * @param className The name of the C++ class, as a raw token,
1836 * <i>not</i> a string or macro.
1837 * @param superclassName The name of the superclass of the C++ class,
1839 * <i>not</i> a string or macro.
1842 * Concrete Libkern C++ classes should "call" this macro
1843 * at the beginning of their implementation files,
1844 * before any function implementations for the class.
1846 #define OSDefineMetaClassAndStructors(className, superclassName) \
1847 OSDefineMetaClassAndStructorsWithInit(className, superclassName, )
1851 * @define OSDefineMetaClassAndAbstractStructors
1855 * Defines an OSMetaClass and associated routines
1856 * for an abstract Libkern C++ class.
1858 * @param className The name of the C++ class, as a raw token,
1859 * <i>not</i> a string or macro.
1860 * @param superclassName The name of the superclass of the C++ class,
1862 * <i>not</i> a string or macro.
1865 * Abstract Libkern C++ classes--those with at least one
1866 * pure virtual method--should "call" this macro
1867 * at the beginning of their implementation files,
1868 * before any function implementations for the class.
1870 #define OSDefineMetaClassAndAbstractStructors(className, superclassName) \
1871 OSDefineMetaClassAndAbstractStructorsWithInit (className, superclassName, )
1875 * @define OSDefineMetaClassAndFinalStructors
1879 * Defines an OSMetaClass and associated routines
1880 * for a final (non-subclassable) Libkern C++ class.
1882 * @param className The name of the C++ class, as a raw token,
1883 * <i>not</i> a string or macro.
1884 * @param superclassName The name of the superclass of the C++ class,
1886 * <i>not</i> a string or macro.
1889 * Final Libkern C++ classes--those that do not allow
1890 * subclassing--should "call" this macro at the beginning
1891 * of their implementation files,
1892 * before any function implementations for the class.
1893 * (Final classes in the kernel may actually have subclasses in the kernel,
1894 * but kexts cannot define any subclasses of a final class.)
1896 * <b>Note:</b> If the class is exported by a pseudokext (symbol set),
1897 * the final symbol generated by this macro must be exported
1898 * for the final-class attribute to be enforced.
1900 * <b>Warning:</b> Changing a class from "Default" to "Final" will break
1901 * binary compatibility.
1903 #define OSDefineMetaClassAndFinalStructors(className, superclassName) \
1904 OSDefineMetaClassAndFinalStructorsWithInit(className, superclassName, )
1907 // Dynamic vtable patchup support routines and types
1908 void reservedCalled(int ind
) const;
1912 * @define OSMetaClassDeclareReservedUnused
1916 * Reserves vtable space for new virtual functions
1917 * in a Libkern C++ class.
1919 * @param className The name of the C++ class, as a raw token,
1920 * <i>not</i> a string or macro.
1921 * @param index The numeric index of the vtable slot,
1922 * as a raw constant, beginning from 0.
1925 * Libkern C++ classes in kernel extensions that can be used as libraries
1926 * can provide for backward compatibility by declaring a number
1927 * of reserved vtable slots
1928 * that can be replaced with new functions as they are added.
1929 * Each reserved declaration must be accompanied in the implementation
1930 * by a corresponding reference to
1931 * <code>@link OSMetaClassDefineReservedUnused
1932 * OSMetaClassDefineReservedUnused@/link</code>.
1934 * When replacing a reserved slot, change the macro from "Unused"
1935 * to "Used" to document the fact that the slot used to be reserved,
1936 * and declare the new function immediately after the "Used" macro
1937 * to preserve vtable ordering.
1939 * <code>@link OSMetaClassDeclareReservedUsed
1940 * OSMetaClassDeclareReservedUsed@/link</code>.
1942 #define OSMetaClassDeclareReservedUnused(className, index) \
1944 APPLE_KEXT_PAD_METHOD void _RESERVED ## className ## index ()
1948 * @define OSMetaClassDeclareReservedUsed
1952 * Documents use of reserved vtable space for new virtual functions
1953 * in a Libkern C++ class.
1955 * @param className The name of the C++ class, as a raw token,
1956 * <i>not</i> a string or macro.
1957 * @param index The numeric index of the vtable slot,
1958 * as a raw constant, beginning from 0.
1961 * This macro evaluates to nothing, and is used to document reserved
1962 * vtable slots as they are filled.
1964 * <code>@link OSMetaClassDeclareReservedUnused
1965 * OSMetaClassDeclareReservedUnused@/link</code>.
1967 #define OSMetaClassDeclareReservedUsed(className, index)
1971 * @define OSMetaClassDefineReservedUnused
1975 * Defines a reserved vtable slot for a Libkern C++ class.
1977 * @param className The name of the C++ class, as a raw token,
1978 * <i>not</i> a string or macro.
1979 * @param index The numeric index of the vtable slot,
1980 * as a raw constant, beginning from 0.
1983 * Libkern C++ classes in kernel extensions that can be used as libraries
1984 * can provide for backward compatibility by declaring a number
1985 * of reserved vtable slots
1986 * that can be replaced with new functions as they are added.
1987 * Each reserved defintion accompanies
1988 * a corresponding declaration created with
1989 * <code>@link OSMetaClassDeclareReservedUnused
1990 * OSMetaClassDeclareReservedUnused@/link</code>.
1992 * This macro is used in the implementation file
1993 * to provide a placeholder definition for the reserved vtable slot,
1994 * as a function that calls <code>panic</code> with an error message.
1996 * When replacing a reserved slot, change the macro from "Unused"
1997 * to "Used" to document the fact that the slot used to be reserved,
1998 * and declare the new function immediately after the "Used" macro
1999 * to preserve vtable ordering.
2001 * <code>@link OSMetaClassDefineReservedUsed
2002 * OSMetaClassDefineReservedUsed@/link</code>.
2004 #define OSMetaClassDefineReservedUnused(className, index) \
2005 void className ::_RESERVED ## className ## index () \
2006 { APPLE_KEXT_PAD_IMPL(index); }
2010 * @define OSMetaClassDefineReservedUsed
2014 * Reserves vtable space for new virtual functions in a Libkern C++ class.
2016 * @param className The name of the C++ class, as a raw token,
2017 * <i>not</i> a string or macro.
2018 * @param index The numeric index of the vtable slot,
2019 * as a raw constant, beginning from 0.
2022 * This macro evaluates to nothing, and is used to document reserved
2023 * vtable slots as they are filled.
2025 * <code>@link OSMetaClassDefineReservedUnused
2026 * OSMetaClassDefineReservedUnused@/link</code>.
2028 #define OSMetaClassDefineReservedUsed(className, index)
2030 // I/O Kit debug internal routines.
2031 static void printInstanceCounts();
2032 static void serializeClassDictionary(OSDictionary
* dict
);
2036 static OSDictionary
* getClassDictionary();
2037 virtual bool serialize(OSSerialize
* serializer
) const;
2039 // Virtual Padding functions for MetaClass's
2040 OSMetaClassDeclareReservedUnused(OSMetaClass
, 0);
2041 OSMetaClassDeclareReservedUnused(OSMetaClass
, 1);
2042 OSMetaClassDeclareReservedUnused(OSMetaClass
, 2);
2043 OSMetaClassDeclareReservedUnused(OSMetaClass
, 3);
2044 OSMetaClassDeclareReservedUnused(OSMetaClass
, 4);
2045 OSMetaClassDeclareReservedUnused(OSMetaClass
, 5);
2046 OSMetaClassDeclareReservedUnused(OSMetaClass
, 6);
2047 OSMetaClassDeclareReservedUnused(OSMetaClass
, 7);
2050 #endif /* !_LIBKERN_OSMETACLASS_H */