]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSMetaClass.h
85f9553e09243b3a1c9623141c3fa71efd515f06
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.
54 #if !defined(__ppc__) || __GNUC__ < 3
56 #define APPLE_KEXT_COMPATIBILITY
58 #define APPLE_KEXT_COMPATIBILITY __attribute__ ((apple_kext_compatibility))
62 #define APPLE_KEXT_VTABLE_PADDING 1
66 #define APPLE_KEXT_LEGACY_ABI 0
67 #elif defined(__arm__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
68 #define APPLE_KEXT_LEGACY_ABI 0
70 #define APPLE_KEXT_LEGACY_ABI 1
73 #if APPLE_KEXT_VTABLE_PADDING
75 #define APPLE_KEXT_PAD_METHOD virtual
77 #define APPLE_KEXT_PAD_IMPL(index) gMetaClass.reservedCalled(index)
79 #define APPLE_KEXT_PAD_METHOD static
80 #define APPLE_KEXT_PAD_IMPL(index)
85 #define APPLE_KEXT_COMPATIBILITY_VIRTUAL
87 // private method made virtual only for binary compatibility
88 #define APPLE_KEXT_COMPATIBILITY_VIRTUAL virtual
92 #define APPLE_KEXT_DEPRECATED __attribute__((deprecated))
95 * @class OSMetaClassBase
98 * OSMetaClassBase is the abstract bootstrap class
99 * for the Libkern and I/O Kit run-time type information system.
102 * OSMetaClassBase is the abstract C++ root class
103 * underlying the entire Libkern and I/O Kit class hierarchy.
104 * It defines the run-time type information system,
105 * including dynamic class allocation and safe type-casting,
106 * as well as the abstract interface for reference counting
107 * and a few other utility functions.
108 * OSMetaClassBase is the immediate superclass of
109 * @link //apple_ref/doc/class/OSObject OSObject@/link and
110 * @link //apple_ref/doc/class/OSMetaClass OSMetaClass@/link;
111 * no other class should derive from OSMetaClassBase.
113 * For more information, see
114 * <i>@link //apple_ref/doc/uid/TP40002799
115 * I/O Kit Device Driver Design Guidelines@/link</i>.
117 * <b>Use by Kernel Extensions</b>
119 * Kernel Extensions should never interact directly with OSMetaClassBase,
120 * but they will find useful several macros that tie in
121 * to the run-time type information system, specifically:
123 * <li><code>@link OSTypeAlloc OSTypeAlloc@/link</code> - allocation of new instances</li>
124 * <li><code>@link OSDynamicCast OSDynamicCast@/link</code> - safe type casting</li>
125 * <li><code>@link OSCheckTypeInst OSCheckTypeInst@/link</code> -
126 * checking for inheritance/derivation</li>
127 * <li><code>@link OSMemberFunctionCast OSMemberFunctionCast@/link</code> -
128 * casting C++ member functions to C function pointers
129 * for registration as callbacks</li>
132 * See @link //apple_ref/doc/class/OSMetaClass OSMetaClass@/link
133 * for more run-time type information interfaces.
135 * <b>Use Restrictions</b>
137 * OSMetaClassBase should not be subclassed by kernel extensions,
138 * nor should kernel extensions call its run-time type functions directly.
140 * The run-time type functions and macros are <b>not safe</b>
141 * to call in a primary interrupt context.
143 * <b>Concurrency Protection</b>
145 * The run-time type macros and functions of OSMetaClassBase are thread-safe.
147 class OSMetaClassBase
153 * @define OSTypeAlloc
157 * Allocates an instance of the named object class.
159 * @param type The name of the desired class to be created,
160 * as a raw token, <i>not</i> a string or macro.
163 * A pointer to the new, uninitialized object on success;
164 * <code>NULL</code> on failure.
169 * //apple_ref/cpp/clm/OSMetaClass/allocClassWithName/staticOSObject*\/(constchar*)
170 * OSMetaClass::allocClassWithName(const char *)@/link</code>
173 * //apple_ref/cpp/instm/OSMetaClass/alloc/virtualOSObject*\/()
174 * OSMetaClass::alloc@/link</code>.
176 * The OSTypeAlloc macro is used to avoid binary compatibility difficulties
177 * presented by the C++ <code>new</code> operator.
179 #define OSTypeAlloc(type) ((type *) ((type::metaClass)->alloc()))
187 * Returns the type ID (metaclass) of a class based on its name.
189 * @param type The name of the desired class, as a raw token,
190 * <i>not</i> a string or macro.
193 * The unique type ID (metaclass) for the class.
196 * It is typically more useful to determine whether a class is derived
198 * <code>@link //apple_ref/cpp/macro/OSDynamicCast OSDynamicCast@/link</code>
200 * <code>@link //apple_ref/cpp/macro/OSCheckTypeInst OSCheckTypeInst@/link</code>.
202 #define OSTypeID(type) (type::metaClass)
206 * @define OSTypeIDInst
210 * Returns the type ID (metaclass) for the class of an object instance.
212 * @param typeinst An instance of an OSObject subclass.
215 * The type ID of that object's class; that is, its metaclass.
218 * It is typically more useful to determine whether an object is derived
219 * from a particular class; see
220 * <code>@link //apple_ref/cpp/macro/OSDynamicCast OSDynamicCast@/link</code>
222 * <code>@link //apple_ref/cpp/macro/OSCheckTypeInst OSCheckTypeInst@/link</code>.
224 #define OSTypeIDInst(typeinst) ((typeinst)->getMetaClass())
228 * @define OSDynamicCast
232 * Safe type-casting for Libkern C++ objects.
234 * @param type The name of the desired class type, as a raw token,
235 * <i>not</i> a string or macro.
236 * It is assumed you intend to cast to a pointer
237 * to an object of this type.
238 * Type qualifiers, such as <code>const</code>,
239 * are not recognized and will cause
240 * a (usually obscure) compile error.
241 * @param inst A pointer to the object instance to be cast.
242 * May be <code>NULL</code>.
245 * <code>inst</code> if it is non-<code>NULL</code>
246 * and derived from <code>type</code>;
247 * otherwise <code>NULL</code>.
250 * <code>OSDynamicCast</code> is a rough equivalent
251 * to the standard C++ RTTI <code>dynamic_cast<T></code> operator.
252 * Your code should use this instead of raw C type-casting,
253 * and check the resulting value.
254 * If the result is non-<code>NULL</code>,
255 * the object is safe to use as the type-cast class;
256 * if the result is <code>NULL</code>,
257 * the object does not derive from the type-cast class
258 * and your code should take appropriate steps to handle the error.
260 #define OSDynamicCast(type, inst) \
261 ((type *) OSMetaClassBase::safeMetaCast((inst), OSTypeID(type)))
265 * @define OSCheckTypeInst
269 * Checks whether two objects are type-compatible.
271 * @param typeinst The reference object.
272 * @param inst The object to check for type compatibility.
275 * <code>true</code> if both <code>inst</code> and
276 * <code>typeinst</code> are non-<code>NULL</code>
277 * and <code>inst</code> is derived from the class of <code>typeinst</code>;
278 * otherwise <code>false</code>.
280 #define OSCheckTypeInst(typeinst, inst) \
281 OSMetaClassBase::checkTypeInst(inst, typeinst)
283 /*! @function OSSafeRelease
284 * @abstract Release an object if not <code>NULL</code>.
285 * @param inst Instance of an OSObject, may be <code>NULL</code>.
287 #define OSSafeRelease(inst) do { if (inst) (inst)->release(); } while (0)
289 /*! @function OSSafeReleaseNULL
290 * @abstract Release an object if not <code>NULL</code>, then set it to <code>NULL</code>.
291 * @param inst Instance of an OSObject, may be <code>NULL</code>.
293 #define OSSafeReleaseNULL(inst) do { if (inst) (inst)->release(); (inst) = NULL; } while (0)
295 typedef void (*_ptf_t
)(void);
297 #if APPLE_KEXT_LEGACY_ABI
299 // Arcane evil code interprets a C++ pointer to function as specified in the
300 // -fapple-kext ABI, i.e. the gcc-2.95 generated code. IT DOES NOT ALLOW
301 // the conversion of functions that are from MULTIPLY inherited classes.
304 _ptmf2ptf(const OSMetaClassBase
*self
, void (OSMetaClassBase::*func
)(void))
307 void (OSMetaClassBase::*fIn
)(void);
308 struct { // Pointer to member function 2.95
309 unsigned short fToff
;
319 if (map
.fptmf2
.fToff
) {
320 panic("Multiple inheritance is not supported");
322 } else if (map
.fptmf2
.fVInd
< 0) {
323 // Not virtual, i.e. plain member func
324 return map
.fptmf2
.u
.fPFN
;
327 const OSMetaClassBase
*fObj
;
332 // Virtual member function so dereference vtable
333 return (*u
.vtablep
)[map
.fptmf2
.fVInd
- 1];
337 #else /* !APPLE_KEXT_LEGACY_ABI */
339 // Slightly less arcane and slightly less evil code to do
340 // the same for kexts compiled with the standard Itanium C++
344 _ptmf2ptf(const OSMetaClassBase
*self
, void (OSMetaClassBase::*func
)(void))
347 void (OSMetaClassBase::*fIn
)(void);
354 if (map
.fVTOffset
& 1) {
357 const OSMetaClassBase
*fObj
;
362 // Virtual member function so dereference vtable
363 return *(_ptf_t
*)(((uintptr_t)*u
.vtablep
) + map
.fVTOffset
- 1);
365 // Not virtual, i.e. plain member func
371 #endif /* !APPLE_KEXT_LEGACY_ABI */
374 * @define OSMemberFunctionCast
378 * Converts a C++ member function pointer, relative to an instance,
379 * to a C-style pointer to function.
381 * @param cptrtype The function type declaration to cast to
382 * (typically provided as a <code>typedef</code> by I/O KitKit classes).
383 * @param self The <code>this</code> pointer of the object whose function
385 * @param func The pointer to the member function itself,
386 * something like <code>&Class::function</code>.
389 * A pointer to a function of the given type referencing <code>self</code>.
392 * This function is used to generate pointers to C++ functions for instances,
393 * such that they can be registered as callbacks with I/O Kit objects.
395 * No warnings are generated.
397 * This function will panic if an attempt is made to call it
398 * with a multiply-inheriting class.
400 #define OSMemberFunctionCast(cptrtype, self, func) \
401 (cptrtype) OSMetaClassBase:: \
402 _ptmf2ptf(self, (void (OSMetaClassBase::*)(void)) func)
406 virtual ~OSMetaClassBase();
409 // Disable copy constructors of OSMetaClassBase based objects
410 /* Not to be included in headerdoc.
412 * @function operator =
415 * Disable implicit copy constructor by making private
417 * @param src Reference to source object that isn't allowed to be copied.
419 void operator =(OSMetaClassBase
&src
);
421 /* Not to be included in headerdoc.
423 * @function OSMetaClassBase
426 * Disable implicit copy constructor by making private
428 * @param src Reference to source object that isn't allowed to be copied.
430 OSMetaClassBase(OSMetaClassBase
&src
);
434 // xx-review: the original comment for this makes it sound to me like we don't
435 // xx-review: catch over-releasing an object...?
441 * Abstract declaration of
443 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/(int)
444 * release(int freeWhen)@/link</code>.
449 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/(int)
450 * release(int freeWhen)@/link</code>.
452 virtual void release(int freeWhen
) const = 0;
456 * @function getRetainCount
459 * Abstract declaration of
461 * //apple_ref/cpp/instm/OSObject/getRetainCount/virtualint/()
462 * getRetainCount()@/link</code>.
467 * //apple_ref/cpp/instm/OSObject/getRetainCount/virtualint/()
468 * OSObject::getRetainCount()@/link</code>.
470 virtual int getRetainCount() const = 0;
477 * Abstract declaration of
479 * //apple_ref/cpp/instm/OSObject/retain/virtualvoid/()
480 * retain()@/link</code>.
485 * //apple_ref/cpp/instm/OSObject/retain/virtualvoid/()
486 * OSObject::retain()@/link</code>.
488 virtual void retain() const = 0;
495 * Abstract declaration of
497 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/()
498 * release@/link</code>.
503 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/()
504 * OSObject::release@/link</code>.
506 virtual void release() const = 0;
510 * @function serialize
513 * Abstract declaration of
515 * //apple_ref/cpp/instm/OSObject/serialize/virtualbool/(OSSerialize*)
516 * serialize@/link</code>.
521 * //apple_ref/cpp/instm/OSObject/serialize/virtualbool/(OSSerialize*)
522 * OSObject::serialize@/link</code>.
524 virtual bool serialize(OSSerialize
* serializer
) const = 0;
528 * @function getMetaClass
531 * Returns the OSMetaClass representing
532 * an OSMetaClassBase subclass.
535 * OSObject overrides this abstract member function
536 * to return the OSMetaClass object that represents
537 * each class for run-time typing.
539 virtual const OSMetaClass
* getMetaClass() const = 0;
543 * @function isEqualTo
546 * Checks whether another object is equal to the receiver.
548 * @param anObject The object to copmare to the receiver.
551 * <code>true</code> if the objects are equal, <code>false</code> otherwise.
554 * OSMetaClassBase implements this as a direct pointer comparison,
555 * since it has no other information to judge equality by.
556 * Subclasses generally override this function
557 * to do a more meaningful comparison.
558 * For example, OSString implements it to return
559 * <code>true</code> if <code>anObject</code>
560 * is derived from OSString and represents the same C string.
562 virtual bool isEqualTo(const OSMetaClassBase
* anObject
) const;
569 * Casts this object is to the class managed by the given OSMetaClass.
571 * @param toMeta A pointer to a constant OSMetaClass
572 * for the desired target type.
575 * <code>this</code> if the object is derived
576 * from the class managed by <code>toMeta</code>,
577 * otherwise <code>NULL</code>.
580 * It is far more convenient to use
581 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
583 OSMetaClassBase
* metaCast(const OSMetaClass
* toMeta
) const;
590 * Casts this object is to the class managed by the named OSMetaClass.
592 * @param toMeta An OSSymbol naming the desired target type.
595 * <code>this</code> if the object is derived
596 * from the class named by <code>toMeta</code>,
597 * otherwise <code>NULL</code>.
600 * It is far more convenient to use
601 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
603 OSMetaClassBase
* metaCast(const OSSymbol
* toMeta
) const;
610 * Casts this object is to the class managed by the named OSMetaClass.
612 * @param toMeta An OSString naming the desired target type.
614 * <code>this</code> if the object is derived
615 * from the class named by <code>toMeta</code>,
616 * otherwise <code>NULL</code>.
619 * It is far more convenient to use
620 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
622 OSMetaClassBase
* metaCast(const OSString
* toMeta
) const;
629 * Casts this object is to the class managed by the named OSMetaClass.
631 * @param toMeta A C string naming the desired target type.
633 * <code>this</code> if the object is derived
634 * from the class named by <code>toMeta</code>,
635 * otherwise <code>NULL</code>.
638 * It is far more convenient to use
639 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
641 OSMetaClassBase
* metaCast(const char * toMeta
) const;
643 // Helper inlines for run-time type preprocessor macros
645 * @function safeMetaCast
648 * Casts an object is to the class managed by the given OSMetaClass.
650 * @param anObject A pointer to the object to be cast.
651 * @param toMeta A pointer to a constant OSMetaClass
652 * for the desired target type.
655 * <code>anObject</code> if the object is derived
656 * from the class managed by <code>toMeta</code>,
657 * otherwise <code>NULL</code>.
660 * It is far more convenient to use
661 * <code>@link OSDynamicCast OSDynamicCast@/link</code>.
663 static OSMetaClassBase
* safeMetaCast(
664 const OSMetaClassBase
* anObject
,
665 const OSMetaClass
* toMeta
);
668 * @function checkTypeInst
671 * Checks whether an object instance is of the same class
672 * as another object instance (or a subclass of that class).
674 * @param inst A pointer to the object to check.
675 * @param typeinst A pointer to an object of the class being checked.
678 * <code>true</code> if the object is derived
679 * from the class of <code>typeinst</code>
680 * or a subclass of that class,
681 * otherwise <code>false</code>.
684 * It is far more convenient to use
685 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
687 static bool checkTypeInst(
688 const OSMetaClassBase
* inst
,
689 const OSMetaClassBase
* typeinst
);
691 static void initialize(void);
696 * @function taggedRetain
699 * Abstract declaration of
701 * //apple_ref/cpp/instm/OSObject/taggedRetain/virtualvoid/(constvoid*)
702 * taggedRetain(const void *)@/link</code>.
707 * //apple_ref/cpp/instm/OSObject/taggedRetain/virtualvoid/(constvoid*)
708 * OSObject::taggedRetain(const void *)@/link</code>.
710 // WAS: virtual void _RESERVEDOSMetaClassBase0();
711 virtual void taggedRetain(const void * tag
= 0) const = 0;
715 * @function taggedRelease
718 * Abstract declaration of
720 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*)
721 * taggedRelease(const void *)@/link</code>.
726 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*)
727 * OSObject::taggedRelease(const void *)@/link</code>.
729 // WAS: virtual void _RESERVEDOSMetaClassBase1();
730 virtual void taggedRelease(const void * tag
= 0) const = 0;
734 * @function taggedRelease
737 * Abstract declaration of
739 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*,constint)
740 * taggedRelease(const void *, const int freeWhen)@/link</code>.
745 * //apple_ref/cpp/instm/OSObject/taggedRelease/virtualvoid/(constvoid*,constint)
746 * OSObject::taggedRelease(const void *, const int freeWhen)@/link</code>.
748 // WAS: virtual void _RESERVEDOSMetaClassBase2();
749 virtual void taggedRelease(
751 const int freeWhen
) const = 0;
755 virtual void _RESERVEDOSMetaClassBase3();
756 virtual void _RESERVEDOSMetaClassBase4();
757 virtual void _RESERVEDOSMetaClassBase5();
758 virtual void _RESERVEDOSMetaClassBase6();
759 virtual void _RESERVEDOSMetaClassBase7();
760 } APPLE_KEXT_COMPATIBILITY
;
767 * OSMetaClass manages run-time type information
768 * for Libkern and I/O Kit C++ classes.
772 * OSMetaClass manages run-time type information
773 * for Libkern and I/O Kit C++ classes.
774 * An instance of OSMetaClass exists for (nearly) every such C++ class,
775 * keeping track of inheritance relationships, class lookup by name,
776 * instance counts, and more.
777 * OSMetaClass operates almost entirely behind the scenes,
778 * and kernel extensions should rarely, if ever,
779 * have to interact directly with OSMetaClass.
781 * <b>Use by Kernel Extensions</b>
783 * While kernel extensions rarey interact directly with OSMetaClass at run time,
784 * they must register their classes with the metaclass system
785 * using the macros declared here.
786 * The class declaration should use one of these two macros
787 * before its first member function declaration:
789 * <li><code>@link OSDeclareDefaultStructors OSDeclareDefaultStructors@/link</code> -
790 * for classes with no abstract member function declarations</li>
791 * <li><code>@link OSDeclareAbstractStructors OSDeclareAbstractStructors@/link</code> -
792 * for classes with at least one abstract member function declaration</li>
793 * <li><code>@link OSDeclareFinalStructors OSDeclareFinalStructors@/link</code> -
794 * for classes that should not be subclassable by another kext</li>
797 * The class implementation should then use one of these macros:
799 * <li><code>@link OSDefineMetaClassAndStructors
800 * OSDefineMetaClassAndStructors@/link</code> -
801 * for classes with no abstract member function declarations</li>
802 * <li><code>@link OSDefineMetaClassAndAbstractStructors
803 * OSDefineMetaClassAndAbstractStructors@/link</code> -
804 * for classes with at least one abstract member function declaration</li>
805 * <li><code>@link OSDefineMetaClassAndFinalStructors
806 * OSDefineMetaClassAndFinalStructors@/link</code> -
807 * for classes that should not be subclassable by another kext</li>
810 * Classes in kernel extensions that are intended for use as libraries
811 * may need to reserve vtable slots to preserve binary compatibility
812 * as new functions are added. They may do so with these macros:
814 * <li><code>@link OSMetaClassDeclareReservedUnused
815 * OSMetaClassDeclareReservedUnused@/link</code> -
816 * reserves a vtable slot</li>
817 * <li><code>@link OSMetaClassDefineReservedUnused
818 * OSMetaClassDefineReservedUnused@/link</code> -
819 * defines the reserved vtable slot as an unimplemented function</li>
820 * <li><code>@link OSMetaClassDeclareReservedUsed
821 * OSMetaClassDeclareReservedUsed@/link</code> -
822 * documents that a formerly reserved slot is now used</li>
823 * <li><code>@link OSMetaClassDefineReservedUsed
824 * OSMetaClassDefineReservedUsed@/link</code> -
825 * documents that a formerly reserved slot is now used</li>
828 * <b>Use Restrictions</b>
830 * OSMetaClass should not be explicitly subclassed by kernel extensions
831 * (the declare/define macros do that),
832 * nor should kernel extensions call its run-time type functions directly.
834 * OSMetaClass functions should be considered
835 * <b>unsafe</b> to call in a primary interrupt context.
837 * <b>Concurrency Protection</b>
839 * Kernel extensions should in general not interact
840 * with OSMetaClass objects directly,
841 * instead using the run-time type macros.
842 * Much of OSMetaClass's interface is intended for use
843 * by the run-time type information system,
844 * which handles concurrency and locking internally.
846 class OSMetaClass
: private OSMetaClassBase
851 // Can never be allocated must be created at compile time
852 static void * operator new(size_t size
);
854 struct ExpansionData
{ };
856 /* Reserved for future use. (Internal use only) */
857 ExpansionData
*reserved
;
859 /* superClass Handle to the superclass's meta class. */
860 const OSMetaClass
*superClassLink
;
862 /* className OSSymbol of the class' name. */
863 const OSSymbol
*className
;
865 /* classSize How big is a single instancde of this class. */
866 unsigned int classSize
;
868 /* instanceCount Roughly number of instances of the object,
869 * +1 for each direct subclass with a nonzero refcount.
870 * Used primarily as a code-in-use flag.
872 mutable unsigned int instanceCount
;
874 /* Not to be included in headerdoc.
876 * @function OSMetaClass
879 * The default private constructor.
883 // Called by postModLoad
884 /* Not to be included in headerdoc.
889 * Logs an error string for an <code>OSReturn</code> value
890 * using <code>printf</code>.
892 * @param result The <code>OSReturn</code> value for which to log a message.
895 * This function is used to log errors loading kernel extensions.
896 * Kernel extensions themselves should not call it.
898 static void logError(OSReturn result
);
903 * @function getMetaClassWithName
906 * Look up a metaclass in the run-time type information system.
908 * @param name The name of the desired class's metaclass.
911 * A pointer to the metaclass object if found, <code>NULL</code> otherwise.
913 static const OSMetaClass
* getMetaClassWithName(const OSSymbol
* name
);
920 * Implements the abstract <code>retain</code> function to do nothing.
923 * Since an OSMetaClass instance must remain in existence
924 * for as long as its kernel extension is loaded,
925 * OSMetaClass does not use reference-counting.
927 virtual void retain() const;
934 * Implements the abstract <code>release</code> function to do nothing.
937 * Since an OSMetaClass instance must remain in existence
938 * for as long as its kernel extension is loaded,
939 * OSMetaClass does not use reference-counting.
941 virtual void release() const;
948 * Implements the abstract <code>release(int freeWhen)</code>
949 * function to do nothing.
951 * @param freeWhen Unused.
954 * Since an OSMetaClass instance must remain in existence
955 * for as long as its kernel extension is loaded,
956 * OSMetaClass does not use reference-counting.
958 virtual void release(int freeWhen
) const;
962 * @function taggedRetain
965 * Implements the abstract <code>taggedRetain(const void *)</code>
966 * function to do nothing.
971 * Since an OSMetaClass instance must remain in existence
972 * for as long as its kernel extension is loaded,
973 * OSMetaClass does not use reference-counting.
975 virtual void taggedRetain(const void * tag
= 0) const;
979 * @function taggedRelease
982 * Implements the abstract <code>taggedRelease(const void *)</code>
983 * function to do nothing.
988 * Since an OSMetaClass instance must remain in existence
989 * for as long as its kernel extension is loaded,
990 * OSMetaClass does not use reference-counting.
992 virtual void taggedRelease(const void * tag
= 0) const;
996 * @function taggedRelease
999 * Implements the abstract <code>taggedRelease(const void *, cont int)</code>
1000 * function to do nothing.
1002 * @param tag Unused.
1003 * @param freeWhen Unused.
1006 * Since an OSMetaClass instance must remain in existence
1007 * for as long as its kernel extension is loaded,
1008 * OSMetaClass does not use reference-counting.
1010 virtual void taggedRelease(
1012 const int freeWhen
) const;
1016 * @function getRetainCount
1019 * Implements the abstract <code>getRetainCount</code>
1020 * function to return 0.
1026 * Since an OSMetaClass instance must remain in existence
1027 * for as long as its kernel extension is loaded,
1028 * OSMetaClass does not use reference-counting.
1030 virtual int getRetainCount() const;
1033 /* Not to be included in headerdoc.
1035 * @function getMetaClass
1038 * Returns the meta-metaclass.
1041 * The metaclass of the OSMetaClass object.
1043 virtual const OSMetaClass
* getMetaClass() const;
1047 * @function OSMetaClass
1050 * Constructor for OSMetaClass objects.
1052 * @param className A C string naming the C++ class
1053 * that this OSMetaClass represents.
1054 * @param superclass The OSMetaClass object representing the superclass
1055 * of this metaclass's class.
1056 * @param classSize The allocation size of the represented C++ class.
1059 * This constructor is protected and cannot be used
1060 * to instantiate OSMetaClass directly, as OSMetaClass is an abstract class.
1061 * This function is called during kext loading
1062 * to queue C++ classes for registration.
1063 * See <code>@link preModLoad preModLoad@/link</code> and
1064 * <code>@link postModLoad postModLoad@/link</code>.
1066 OSMetaClass(const char * className
,
1067 const OSMetaClass
* superclass
,
1068 unsigned int classSize
);
1072 * @function ~OSMetaClass
1075 * Destructor for OSMetaClass objects.
1078 * This function is called when the kernel extension that implements
1079 * the metaclass's class is unloaded.
1080 * The destructor removes all references to the class
1081 * from the run-time type information system.
1083 virtual ~OSMetaClass();
1085 // Needs to be overriden as NULL as all OSMetaClass objects are allocated
1086 // statically at compile time, don't accidently try to free them.
1087 void operator delete(void *, size_t) { };
1090 static const OSMetaClass
* const metaClass
;
1093 * @function preModLoad
1096 * Prepares the run-time type system
1097 * for the creation of new metaclasses
1098 * during loading of a kernel extension (module).
1100 * @param kextID The bundle ID of the kext being loaded.
1103 * An opaque handle to the load context
1104 * for the kernel extension on success;
1105 * <code>NULL</code> on failure.
1108 * <i>Not for use by kernel extensions.</i>
1110 * Prepares the run-time type information system to record and register
1111 * metaclasses created by static constructors until a subsequent call to
1112 * <code>@link postModLoad postModLoad@/link</code>.
1113 * <code>preModLoad</code> takes a lock to ensure processing of a single
1114 * load operation at a time; the lock is released by
1115 * <code>@link postModLoad postModLoad@/link</code>.
1116 * Any OSMetaClass constructed between these two function calls
1117 * will be associated with <code>kextID</code>.
1119 static void * preModLoad(const char * kextID
);
1123 * @function checkModLoad
1126 * Checks whether the current kext load operation can proceed.
1128 * @param loadHandle The opaque handle returned
1129 * by <code>@link preModLoad preModLoad@/link</code>.
1131 * <code>true</code> if no errors are outstanding
1132 * and the system is ready to process more metaclasses.
1135 * <i>Not for use by kernel extensions.</i>
1137 static bool checkModLoad(void * loadHandle
);
1141 * @function postModLoad
1144 * Registers the metaclasses created during loading of a kernel extension.
1146 * @param loadHandle The opaque handle returned
1147 * by <code>@link preModLoad preModLoad@/link</code>.
1149 * The error code of the first error encountered,
1152 * //apple_ref/cpp/macro/kOSReturnSuccess
1153 * kOSReturnSuccess@/link</code>
1154 * if no error occurred.
1157 * <i>Not for use by kernel extensions.</i>
1159 * Called after all static constructors in a kernel extension
1160 * have created metaclasses,
1161 * this function checks for duplicate class names,
1162 * then registers the new metaclasses under the kext ID
1163 * that @link preModLoad preModLoad@/link was called with,
1164 * so that they can be dynamically allocated
1165 * and have their instance counts tracked.
1166 * <code>postModLoad</code> releases the lock taken by
1167 * <code>@link preModLoad preModLoad@/link</code>.
1169 static OSReturn
postModLoad(void * loadHandle
);
1172 * @function modHasInstance
1175 * Returns whether any classes defined by the named
1176 * kernel extension (or their subclasses) have existing instances.
1178 * @param kextID The bundle ID of the kernel extension to check.
1181 * <code>true</code> if the kext is found and
1182 * if any class defined by that kext
1183 * has a nonzero instance count,
1184 * <code>false</code> otherwise.
1187 * This function is called before a kernel extension's static destructors
1188 * are invoked, prior to unloading the extension.
1189 * If any classes stil have instances or subclasses with instances,
1190 * those classes are logged
1191 * (using <code>@link reportModInstances reportModInstances@/link</code>) and
1192 * the kernel extension is not be unloaded.
1194 static bool modHasInstance(const char * kextID
);
1198 * @function reportModInstances
1201 * Logs the instance counts for classes
1202 * defined by a kernel extension.
1204 * @param kextID The bundle ID of the kernel extension to report on.
1207 * This function prints the names and instance counts
1208 * of any class defined by <code>kextID</code>
1209 * that has a nonzero instance count.
1210 * It's called by <code>@link modHasInstance modHasInstance@/link</code>
1211 * to help diagnose problems unloading kernel extensions.
1213 static void reportModInstances(const char * kextID
);
1217 * @function considerUnloads
1220 * Schedule automatic unloading of unused kernel extensions.
1223 * This function schedules a check for kernel extensions
1224 * that can be automatically unloaded,
1225 * canceling any currently scheduled check.
1226 * At that time, any such kexts with no Libkern C++ instances
1227 * and no external references are unloaded.
1229 * The I/O Kit calls this function when matching goes idle.
1231 * Kernel extensions that define subclasses of
1232 * @link //apple_ref/doc/class/IOService IOService@/link
1233 * are eligible for automatic unloading.
1235 * (On releases of Mac OS X prior to Snow Leopard (10.6),
1236 * any kernel extension defining any Libkern C++ class
1237 * was eligible for automatic unloading,
1238 * but that unload did not call the module stop routine.
1239 * Non-I/O Kit kernel extensions that define Libkern C++ subclasses
1240 * should be sure to have OSBundleLibraries declarations that ensure
1241 * they will not load on releases prior to Snow Leopard.)
1243 static void considerUnloads();
1247 * @function allocClassWithName
1250 * Allocates an instance of a named OSObject-derived class.
1252 * @param name The name of the desired class.
1255 * A pointer to the newly-allocated, uninitialized object on success;
1256 * <code>NULL</code> on failure.
1259 * Kernel extensions should not need to use this function
1260 * directly, instead using static instance-creation functions
1261 * defined by classes.
1263 * This function consults the run-time type information system
1264 * to find the metaclass for the named class.
1265 * If it exists, it calls the metaclass's <code>@link alloc alloc@/link</code>
1266 * function and returns the result.
1268 static OSObject
* allocClassWithName(const OSSymbol
* name
);
1272 * function allocClassWithName
1275 * Allocates an instance of a named OSObject-derived class.
1277 * @param name The name of the desired class.
1280 * A pointer to the newly-allocated, uninitialized object on success;
1281 * <code>NULL</code> on failure.
1284 * Kernel extensions should not need to use this function
1285 * directly, instead using static instance-creation functions
1286 * defined by classes.
1288 * This function consults the run-time type information system
1289 * to find the metaclass for the named class.
1290 * If it exists, it calls the metaclass's <code>@link alloc alloc@/link</code>
1291 * function and returns the result.
1293 static OSObject
* allocClassWithName(const OSString
* name
);
1297 * function allocClassWithName
1300 * Allocates an instance of a named OSObject-derived class.
1302 * @param name The name of the desired class.
1305 * A pointer to the newly-allocated, uninitialized object on success;
1306 * <code>NULL</code> on failure.
1309 * Kernel extensions should not need to use this function
1310 * directly, instead using static instance-creation functions
1311 * defined by classes.
1313 * This function consults the run-time type information system
1314 * to find the metaclass for the named class.
1315 * If it exists, it calls the metaclass's <code>@link alloc alloc@/link</code>
1316 * function and returns the result.
1318 static OSObject
* allocClassWithName(const char * name
);
1322 * @function checkMetaCastWithName
1325 * Search the metaclass inheritance hierarchy by name for an object instance.
1327 * @param className The name of the desired class or superclass.
1328 * @param object The object whose metaclass begins the search.
1331 * <code>object</code> if it's derived from <code>className</code>;
1332 * <code>NULL</code> otherwise.
1335 * This function is the basis of the Libkern run-time type-checking system.
1336 * Kernel extensions should not use it directly,
1337 * instead using <code>@link OSDynamicCast OSDynamicCast@/link</code> or
1338 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
1340 static OSMetaClassBase
* checkMetaCastWithName(
1341 const OSSymbol
* className
,
1342 const OSMetaClassBase
* object
);
1345 * @function checkMetaCastWithName
1348 * Search the metaclass inheritance hierarchy by name for an object instance.
1350 * @param className The name of the desired class or superclass.
1351 * @param object The object whose metaclass begins the search.
1354 * <code>object</code> if it's derived from <code>className</code>;
1355 * <code>NULL</code> otherwise.
1358 * Kernel extensions should not use this function directly,
1359 * instead using <code>@link OSDynamicCast OSDynamicCast@/link</code> or
1360 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
1362 static OSMetaClassBase
* checkMetaCastWithName(
1363 const OSString
* className
,
1364 const OSMetaClassBase
* object
);
1367 * @function checkMetaCastWithName
1370 * Search the metaclass inheritance hierarchy by name for an object instance.
1372 * @param className The name of the desired class or superclass.
1373 * @param object The object whose metaclass begins the search.
1376 * <code>object</code> if it's derived from <code>className</code>;
1377 * <code>NULL</code> otherwise.
1380 * Kernel extensions should not use this function directly,
1381 * instead using <code>@link OSDynamicCast OSDynamicCast@/link</code> or
1382 * <code>@link OSCheckTypeInst OSCheckTypeInst@/link</code>.
1384 static OSMetaClassBase
* checkMetaCastWithName(
1385 const char * className
,
1386 const OSMetaClassBase
* object
);
1390 * @function instanceConstructed
1393 * Counts the instances of the class managed by this metaclass.
1396 * <i>Not for use by kernel extensions.</i>
1398 * Every non-abstract class that inherits from OSObject
1399 * has a default constructor that calls it's own metaclass's
1400 * <code>instanceConstructed</code> function.
1401 * This constructor is defined by the
1403 * OSDefineMetaClassAndStructors
1404 * OSDefineMetaClassAndStructors@/link</code>
1405 * macro that all OSObject subclasses must use.
1407 * If a class's instance count goes from 0 to 1--that is,
1408 * upon the creation of the first instance of that class--the
1409 * superclass's instance count is also incremented.
1410 * This propagates reference counts up the inheritance chain so that
1411 * superclasses are counted as "in use" when subclasses have instances.
1413 void instanceConstructed() const;
1417 * @function instanceDestructed
1420 * Counts the instances of the class managed by this metaclass.
1423 * Every non-abstract class that inherits from OSObject
1424 * has a default destructor that calls it's own metaclass's
1425 * <code>instanceDestructed</code> function.
1426 * This constructor is defined by the
1427 * @link OSDefineMetaClassAndStructors OSDefineMetaClassAndStructors@/link
1428 * macro that all OSObject subclasses must use.
1430 * If a class's instance count goes from 1 to 0--that is,
1431 * upon the destruction of the last instance of that class--the
1432 * superclass's instance count is also decremented.
1433 * This reduces "in use" counts from superclasses when their subclasses
1434 * no longer have instances.
1436 void instanceDestructed() const;
1440 * @function checkMetaCast
1443 * Check whether a given object is an instance of the receiving
1444 * metaclass's class or one derived from it.
1446 * @param object The object to check for inheritance.
1449 * <code>object</code> if it is derived from the receiver's class,
1450 * <code>NULL</code> if not.
1452 OSMetaClassBase
* checkMetaCast(const OSMetaClassBase
* object
) const;
1456 * @function getInstanceCount
1459 * Returns the number of existing instances of the metaclass's class.
1462 * The number of existing instances of the metaclass's class,
1463 * plus 1 for each subclass with any instance.
1465 unsigned int getInstanceCount() const;
1469 * @function getSuperClass
1472 * Returns the super-metaclass of the receiver.
1475 * Returns a pointer to the super-metaclass of the receiving
1476 * OSMetaClass, or <code>NULL</code> for OSObject's metaclass.
1478 const OSMetaClass
* getSuperClass() const;
1482 * @function getKmodName
1485 * Returns the bundle identifier of the kernel extension
1486 * that defines this metaclass.
1489 * The bundle identifier of the kernel extension that defines this metaclass.
1492 * "Kmod" is an older term for kernel extension.
1494 const OSSymbol
* getKmodName() const;
1498 * @function getClassName
1501 * Returns the name of the C++ class managed by this metaclass.
1504 * Returns the name of the C++ class managed by this metaclass.
1506 const char * getClassName() const;
1510 * @function getClassSize
1513 * Returns the allocation size of the C++ class managed by this metaclass.
1516 * The allocation size of the C++ class managed by this metaclass.
1518 unsigned int getClassSize() const;
1525 * Allocates an instance of the C++ class managed by this metaclass.
1528 * A pointer to the newly allocated, uninitialized instance,
1529 * with a retain count of 1; <code>NULL</code> on allocation failure.
1532 * This function is automatically created by the metaclass-registration macros
1533 * to enable dynamic instance allocation.
1535 virtual OSObject
* alloc() const = 0;
1538 /* Not to be included in headerdoc.
1540 * @define OSDeclareCommonStructors
1544 * Helper macro for for the standard metaclass-registration macros.
1547 * @param className The name of the C++ class, as a raw token,
1548 * <i>not</i> a string or macro.
1550 #define OSDeclareCommonStructors(className) \
1552 static const OSMetaClass * const superClass; \
1554 static const OSMetaClass * const metaClass; \
1555 static class MetaClass : public OSMetaClass { \
1558 virtual OSObject *alloc() const; \
1560 friend class className ::MetaClass; \
1561 virtual const OSMetaClass * getMetaClass() const; \
1563 className (const OSMetaClass *); \
1564 virtual ~ className ()
1568 * @define OSDeclareDefaultStructors
1572 * Declares run-time type information and functions
1573 * for a concrete Libkern C++ class.
1575 * @param className The name of the C++ class, as a raw token,
1576 * <i>not</i> a string or macro.
1579 * Concrete Libkern C++ classes should "call" this macro
1580 * immediately after the opening brace in a class declaration.
1581 * It leaves the current privacy state as <code>protected:</code>.
1583 #define OSDeclareDefaultStructors(className) \
1584 OSDeclareCommonStructors(className); \
1591 * @define OSDeclareAbstractStructors
1595 * Declares run-time type information and functions
1596 * for an abstract Libkern C++ class.
1598 * @param className The name of the C++ class, as a raw token,
1599 * <i>not</i> a string or macro.
1602 * Abstract Libkern C++ classes--those with at least one
1603 * pure virtual method--should "call" this macro
1604 * immediately after the opening brace in a class declaration.
1605 * It leaves the current privacy state as <code>protected:</code>.
1607 #define OSDeclareAbstractStructors(className) \
1608 OSDeclareCommonStructors(className); \
1610 className (); /* Make primary constructor private in abstract */ \
1614 * @define OSDeclareFinalStructors
1618 * Declares run-time type information and functions
1619 * for a final (non-subclassable) Libkern C++ class.
1621 * @param className The name of the C++ class, as a raw token,
1622 * <i>not</i> a string or macro.
1625 * Final Libkern C++ classes--those that do not allow subclassing--should
1626 * "call" this macro immediately after the opening brace in a class declaration.
1627 * (Final classes in the kernel may actually have subclasses in the kernel,
1628 * but kexts cannot define any subclasses of a final class.)
1629 * It leaves the current privacy state as <code>protected:</code>.
1631 * <b>Note:</b> If the class is exported by a pseudokext (symbol set),
1632 * the final symbol generated by this macro must be exported
1633 * for the final-class attribute to be enforced.
1635 * <b>Warning:</b> Changing a class from "Default" to "Final" will break
1636 * binary compatibility.
1638 #define OSDeclareFinalStructors(className) \
1639 OSDeclareDefaultStructors(className) \
1641 void __OSFinalClass(void); \
1645 /* Not to be included in headerdoc.
1647 * @define OSDefineMetaClassWithInit
1651 * Helper macro for for the standard metaclass-registration macros.
1654 * @param className The name of the C++ class, as a raw token,
1655 * <i>not</i> a string or macro.
1656 * @param superclassName The name of the superclass of the C++ class,
1658 * <i>not</i> a string or macro.
1659 * @param init A function to call in the constructor
1660 * of the class's OSMetaClass.
1662 #define OSDefineMetaClassWithInit(className, superclassName, init) \
1663 /* Class global data */ \
1664 className ::MetaClass className ::gMetaClass; \
1665 const OSMetaClass * const className ::metaClass = \
1666 & className ::gMetaClass; \
1667 const OSMetaClass * const className ::superClass = \
1668 & superclassName ::gMetaClass; \
1669 /* Class member functions */ \
1670 className :: className(const OSMetaClass *meta) \
1671 : superclassName (meta) { } \
1672 className ::~ className() { } \
1673 const OSMetaClass * className ::getMetaClass() const \
1674 { return &gMetaClass; } \
1675 /* The ::MetaClass constructor */ \
1676 className ::MetaClass::MetaClass() \
1677 : OSMetaClass(#className, className::superClass, sizeof(className)) \
1681 /* Not to be included in headerdoc.
1683 * @define OSDefineAbstractStructors
1687 * Helper macro for for the standard metaclass-registration macros.
1690 * @param className The name of the C++ class, as a raw token,
1691 * <i>not</i> a string or macro.
1692 * @param superclassName The name of the superclass of the C++ class,
1694 * <i>not</i> a string or macro.
1696 #define OSDefineAbstractStructors(className, superclassName) \
1697 OSObject * className ::MetaClass::alloc() const { return 0; }
1700 /* Not to be included in headerdoc.
1702 * @define OSDefineDefaultStructors
1706 * Helper macro for for the standard metaclass-registration macros.
1709 * @param className The name of the C++ class, as a raw token,
1710 * <i>not</i> a string or macro.
1711 * @param superclassName The name of the superclass of the C++ class,
1713 * <i>not</i> a string or macro.
1715 #define OSDefineDefaultStructors(className, superclassName) \
1716 OSObject * className ::MetaClass::alloc() const \
1717 { return new className; } \
1718 className :: className () : superclassName (&gMetaClass) \
1719 { gMetaClass.instanceConstructed(); }
1721 /* Not to be included in headerdoc.
1723 * @define OSDefineDefaultStructors
1727 * Helper macro for for the standard metaclass-registration macros.
1730 * @param className The name of the C++ class, as a raw token,
1731 * <i>not</i> a string or macro.
1732 * @param superclassName The name of the superclass of the C++ class,
1734 * <i>not</i> a string or macro.
1736 #define OSDefineFinalStructors(className, superclassName) \
1737 OSDefineDefaultStructors(className, superclassName) \
1738 void className ::__OSFinalClass(void) { }
1741 /* Not to be included in headerdoc.
1743 * @define OSDefineMetaClassAndStructorsWithInit
1747 * Helper macro for for the standard metaclass-registration macros.
1750 * @param className The name of the C++ class, as a raw token,
1751 * <i>not</i> a string or macro.
1752 * @param superclassName The name of the superclass of the C++ class,
1754 * <i>not</i> a string or macro.
1755 * @param init A function to call in the constructor
1756 * of the class's OSMetaClass.
1758 #define OSDefineMetaClassAndStructorsWithInit(className, superclassName, init) \
1759 OSDefineMetaClassWithInit(className, superclassName, init) \
1760 OSDefineDefaultStructors(className, superclassName)
1763 /* Not to be included in headerdoc.
1765 * @define OSDefineMetaClassAndAbstractStructorsWithInit
1769 * Helper macro for for the standard metaclass-registration macros.
1772 * @param className The name of the C++ class, as a raw token,
1773 * <i>not</i> a string or macro.
1774 * @param superclassName The name of the superclass of the C++ class,
1776 * <i>not</i> a string or macro.
1777 * @param init A function to call in the constructor
1778 * of the class's OSMetaClass.
1780 #define OSDefineMetaClassAndAbstractStructorsWithInit(className, superclassName, init) \
1781 OSDefineMetaClassWithInit(className, superclassName, init) \
1782 OSDefineAbstractStructors(className, superclassName)
1785 /* Not to be included in headerdoc.
1787 * @define OSDefineMetaClassAndFinalStructorsWithInit
1791 * Helper macro for for the standard metaclass-registration macros.
1794 * @param className The name of the C++ class, as a raw token,
1795 * <i>not</i> a string or macro.
1796 * @param superclassName The name of the superclass of the C++ class,
1798 * <i>not</i> a string or macro.
1799 * @param init A function to call in the constructor
1800 * of the class's OSMetaClass.
1802 #define OSDefineMetaClassAndFinalStructorsWithInit(className, superclassName, init) \
1803 OSDefineMetaClassWithInit(className, superclassName, init) \
1804 OSDefineFinalStructors(className, superclassName)
1809 /* Not to be included in headerdoc.
1811 * @define OSDefineMetaClass
1815 * Helper macro for for the standard metaclass-registration macros.
1818 * @param className The name of the C++ class, as a raw token,
1819 * <i>not</i> a string or macro.
1820 * @param superclassName The name of the superclass of the C++ class,
1822 * <i>not</i> a string or macro.
1823 * @param init A function to call in the constructor
1824 * of the class's OSMetaClass.
1826 #define OSDefineMetaClass(className, superclassName) \
1827 OSDefineMetaClassWithInit(className, superclassName, )
1831 * @define OSDefineMetaClassAndStructors
1835 * Defines an OSMetaClass and associated routines
1836 * for a concrete Libkern C++ class.
1838 * @param className The name of the C++ class, as a raw token,
1839 * <i>not</i> a string or macro.
1840 * @param superclassName The name of the superclass of the C++ class,
1842 * <i>not</i> a string or macro.
1845 * Concrete Libkern C++ classes should "call" this macro
1846 * at the beginning of their implementation files,
1847 * before any function implementations for the class.
1849 #define OSDefineMetaClassAndStructors(className, superclassName) \
1850 OSDefineMetaClassAndStructorsWithInit(className, superclassName, )
1854 * @define OSDefineMetaClassAndAbstractStructors
1858 * Defines an OSMetaClass and associated routines
1859 * for an abstract Libkern C++ class.
1861 * @param className The name of the C++ class, as a raw token,
1862 * <i>not</i> a string or macro.
1863 * @param superclassName The name of the superclass of the C++ class,
1865 * <i>not</i> a string or macro.
1868 * Abstract Libkern C++ classes--those with at least one
1869 * pure virtual method--should "call" this macro
1870 * at the beginning of their implementation files,
1871 * before any function implementations for the class.
1873 #define OSDefineMetaClassAndAbstractStructors(className, superclassName) \
1874 OSDefineMetaClassAndAbstractStructorsWithInit (className, superclassName, )
1878 * @define OSDefineMetaClassAndFinalStructors
1882 * Defines an OSMetaClass and associated routines
1883 * for a final (non-subclassable) Libkern C++ class.
1885 * @param className The name of the C++ class, as a raw token,
1886 * <i>not</i> a string or macro.
1887 * @param superclassName The name of the superclass of the C++ class,
1889 * <i>not</i> a string or macro.
1892 * Final Libkern C++ classes--those that do not allow
1893 * subclassing--should "call" this macro at the beginning
1894 * of their implementation files,
1895 * before any function implementations for the class.
1896 * (Final classes in the kernel may actually have subclasses in the kernel,
1897 * but kexts cannot define any subclasses of a final class.)
1899 * <b>Note:</b> If the class is exported by a pseudokext (symbol set),
1900 * the final symbol generated by this macro must be exported
1901 * for the final-class attribute to be enforced.
1903 * <b>Warning:</b> Changing a class from "Default" to "Final" will break
1904 * binary compatibility.
1906 #define OSDefineMetaClassAndFinalStructors(className, superclassName) \
1907 OSDefineMetaClassAndFinalStructorsWithInit(className, superclassName, )
1910 // Dynamic vtable patchup support routines and types
1911 void reservedCalled(int ind
) const;
1915 * @define OSMetaClassDeclareReservedUnused
1919 * Reserves vtable space for new virtual functions
1920 * in a Libkern C++ class.
1922 * @param className The name of the C++ class, as a raw token,
1923 * <i>not</i> a string or macro.
1924 * @param index The numeric index of the vtable slot,
1925 * as a raw constant, beginning from 0.
1928 * Libkern C++ classes in kernel extensions that can be used as libraries
1929 * can provide for backward compatibility by declaring a number
1930 * of reserved vtable slots
1931 * that can be replaced with new functions as they are added.
1932 * Each reserved declaration must be accompanied in the implementation
1933 * by a corresponding reference to
1934 * <code>@link OSMetaClassDefineReservedUnused
1935 * OSMetaClassDefineReservedUnused@/link</code>.
1937 * When replacing a reserved slot, change the macro from "Unused"
1938 * to "Used" to document the fact that the slot used to be reserved,
1939 * and declare the new function immediately after the "Used" macro
1940 * to preserve vtable ordering.
1942 * <code>@link OSMetaClassDeclareReservedUsed
1943 * OSMetaClassDeclareReservedUsed@/link</code>.
1945 #define OSMetaClassDeclareReservedUnused(className, index) \
1947 APPLE_KEXT_PAD_METHOD void _RESERVED ## className ## index ()
1951 * @define OSMetaClassDeclareReservedUsed
1955 * Documents use of reserved vtable space for new virtual functions
1956 * in a Libkern C++ class.
1958 * @param className The name of the C++ class, as a raw token,
1959 * <i>not</i> a string or macro.
1960 * @param index The numeric index of the vtable slot,
1961 * as a raw constant, beginning from 0.
1964 * This macro evaluates to nothing, and is used to document reserved
1965 * vtable slots as they are filled.
1967 * <code>@link OSMetaClassDeclareReservedUnused
1968 * OSMetaClassDeclareReservedUnused@/link</code>.
1970 #define OSMetaClassDeclareReservedUsed(className, index)
1974 * @define OSMetaClassDefineReservedUnused
1978 * Defines a reserved vtable slot for a Libkern C++ class.
1980 * @param className The name of the C++ class, as a raw token,
1981 * <i>not</i> a string or macro.
1982 * @param index The numeric index of the vtable slot,
1983 * as a raw constant, beginning from 0.
1986 * Libkern C++ classes in kernel extensions that can be used as libraries
1987 * can provide for backward compatibility by declaring a number
1988 * of reserved vtable slots
1989 * that can be replaced with new functions as they are added.
1990 * Each reserved defintion accompanies
1991 * a corresponding declaration created with
1992 * <code>@link OSMetaClassDeclareReservedUnused
1993 * OSMetaClassDeclareReservedUnused@/link</code>.
1995 * This macro is used in the implementation file
1996 * to provide a placeholder definition for the reserved vtable slot,
1997 * as a function that calls <code>panic</code> with an error message.
1999 * When replacing a reserved slot, change the macro from "Unused"
2000 * to "Used" to document the fact that the slot used to be reserved,
2001 * and declare the new function immediately after the "Used" macro
2002 * to preserve vtable ordering.
2004 * <code>@link OSMetaClassDefineReservedUsed
2005 * OSMetaClassDefineReservedUsed@/link</code>.
2007 #define OSMetaClassDefineReservedUnused(className, index) \
2008 void className ::_RESERVED ## className ## index () \
2009 { APPLE_KEXT_PAD_IMPL(index); }
2013 * @define OSMetaClassDefineReservedUsed
2017 * Reserves vtable space for new virtual functions in a Libkern C++ class.
2019 * @param className The name of the C++ class, as a raw token,
2020 * <i>not</i> a string or macro.
2021 * @param index The numeric index of the vtable slot,
2022 * as a raw constant, beginning from 0.
2025 * This macro evaluates to nothing, and is used to document reserved
2026 * vtable slots as they are filled.
2028 * <code>@link OSMetaClassDefineReservedUnused
2029 * OSMetaClassDefineReservedUnused@/link</code>.
2031 #define OSMetaClassDefineReservedUsed(className, index)
2033 // I/O Kit debug internal routines.
2034 static void printInstanceCounts();
2035 static void serializeClassDictionary(OSDictionary
* dict
);
2039 static OSDictionary
* getClassDictionary();
2040 virtual bool serialize(OSSerialize
* serializer
) const;
2042 // Virtual Padding functions for MetaClass's
2043 OSMetaClassDeclareReservedUnused(OSMetaClass
, 0);
2044 OSMetaClassDeclareReservedUnused(OSMetaClass
, 1);
2045 OSMetaClassDeclareReservedUnused(OSMetaClass
, 2);
2046 OSMetaClassDeclareReservedUnused(OSMetaClass
, 3);
2047 OSMetaClassDeclareReservedUnused(OSMetaClass
, 4);
2048 OSMetaClassDeclareReservedUnused(OSMetaClass
, 5);
2049 OSMetaClassDeclareReservedUnused(OSMetaClass
, 6);
2050 OSMetaClassDeclareReservedUnused(OSMetaClass
, 7);
2053 #endif /* !_LIBKERN_OSMETACLASS_H */