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