ADC Home > Reference Library > Reference > Darwin > Kernel Framework Reference
|
OSMetaClass |
Inherits from: | |
Declared In: |
An instance of OSMetaClass represents one class that the kernel's runtime type information system is aware of.
Allocates an instance of the class that this OSMetaClass instance represents.
Looks up a metaclass in the runtime type information system and returns the results of an alloc call.
Looks up a metaclass in the runtime type information system and returns the results of an alloc call.
Looks up a metaclass in the runtime type information system and returns the results of an alloc call.
Asks an OSMetaClass instance if the given object is either an instance of it or an instance of a subclass of it.
Introspects an object's inheritance tree looking for a class of the given name.
Introspects an object's inheritance tree looking for a class of the given name.
Introspects an object's inheritance tree looking for a class of the given name.
Checks if the current load attempt is still OK.
Schedules module unloading.
'Get'ter for class name.
'Get'ter for sizeof(class).
Gets how many instances of the class have been created.
'Get'ter for the name of the kmod.
Looks up a metaclass in the runtime type information system.
Implements abstract but should no dynamic allocation is allowed.
'Get'ter for the super class.
Counts the instances of the class behind this metaclass.
Removes one instance of the class behind this metaclass.
Logs an error string using printf given an error code.
Returns whether any of the objects represented by OSMetaClass and associated with the given kernel module name have instances.
Private default constructor.
Constructor for OSMetaClass objects.
Finishes post processing on a kernel module's metaclasses.
Prepares the runtime type system for the loading of a module.
Implements abstract but should no dynamic allocation is allowed.
Releases a tagged reference to this object.
Releases a tagged reference to this object.
Implements abstract but should no dynamic allocation is allowed.
Logs any object that has instances in a module.
Implements abstract but should no dynamic allocation is allowed.
Releases a tagged reference to this object.
Releases a tagged reference to this object.
Retains a tagged reference to this object.
Destructor for OSMetaClass objects.
alloc |
Allocates an instance of the class that this OSMetaClass instance represents.
public
virtual OSObject *alloc() const = 0;
Returns a pointer to a new object with a retain count of 1.
This alloc function is analogous to the old ObjC class alloc method. Typically not used by clients because the static function allocClassWithName is more generally useful. In fact, that function is implemented in terms of this virtual function. All subclasses of OSMetaClass must implement this function, but that is what the OSDefineMetaClassAndStructor's families of macros does for the developer automatically.
allocClassWithName |
Looks up a metaclass in the runtime type information system and returns the results of an alloc call.
public
static OSObject *allocClassWithName( const char *name);
name
Name of the desired class.
Returns a pointer to a new object, 0 if not found or no memory.
allocClassWithName(const OSString *) |
Looks up a metaclass in the runtime type information system and returns the results of an alloc call.
public
static OSObject *allocClassWithName( const OSString *name);
name
Name of the desired class.
Returns a pointer to a new object, 0 if not found or no memory.
allocClassWithName(const OSSymbol *) |
Looks up a metaclass in the runtime type information system and returns the results of an alloc call.
public
static OSObject *allocClassWithName( const OSSymbol *name);
name
Name of the desired class.
Returns a pointer to a new object, 0 if not found or no memory.
checkMetaCast |
Asks an OSMetaClass instance if the given object is either an instance of it or an instance of a subclass of it.
public
OSMetaClassBase *checkMetaCast( const OSMetaClassBase *check) const;
check
Pointer of object to introspect.
check parameter if cast is valid, 0 otherwise.
checkMetaCastWithName |
Introspects an object's inheritance tree looking for a class of the given name.
public
static OSMetaClassBase * checkMetaCastWithName( const char *name, const OSMetaClassBase *in);
name
Name of the desired class or super class.
in
Object to be introspected.
in parameter if cast is valid, 0 otherwise.
This function is the basis of the kernel dynamic casting mechanism in Mac OS X.
checkMetaCastWithName(const OSString *, const OSMetaClassBase *) |
Introspects an object's inheritance tree looking for a class of the given name.
public
static OSMetaClassBase * checkMetaCastWithName( const OSString *name, const OSMetaClassBase *in);
name
Name of the desired class or super class.
in
Object to be introspected.
in parameter if cast is valid, 0 otherwise.
This function is the basis of the kernel dynamic casting mechanism in Mac OS X.
checkMetaCastWithName(const OSSymbol *, const OSMetaClassBase *) |
Introspects an object's inheritance tree looking for a class of the given name.
public
static OSMetaClassBase * checkMetaCastWithName( const OSSymbol *name, const OSMetaClassBase *in);
name
Name of the desired class or super class.
in
Object to be introspected.
in parameter if cast is valid, 0 otherwise.
This function is the basis of the kernel dynamic casting mechanism in Mac OS X.
checkModLoad |
Checks if the current load attempt is still OK.
public
static bool checkModLoad( void *loadHandle);
loadHandle
Handle returned when a successful call to preModLoad is made.
Returns true if no errors are outstanding and the system is primed to recieve more objects.
considerUnloads |
Schedules module unloading.
public
static void considerUnloads();
Schedules unused modules to be unloaded; called when I/O Kit matching goes idle.
getClassName |
'Get'ter for class name.
public
const char *getClassName() const;
Returns a C string of the class name.
getClassSize |
'Get'ter for sizeof(class).
public
unsigned int getClassSize() const;
Returns 'sizeof' of the class that this OSMetaClass instance represents.
getInstanceCount |
Gets how many instances of the class have been created.
public
unsigned int getInstanceCount() const;
Returns the number of instances.
getKmodName |
'Get'ter for the name of the kmod.
public
const OSSymbol *getKmodName() const;
Returns an OSSymbol representing the kmod name.
getMetaClassWithName |
Looks up a metaclass in the runtime type information system.
public
static const OSMetaClass *getMetaClassWithName(const OSSymbol *name);
name
Name of the desired class's metaclass.
Returns a pointer to a metaclass object if found, 0 otherwise.
getRetainCount |
Implements abstract but should no dynamic allocation is allowed.
protected
virtual int getRetainCount() const;
getSuperClass |
'Get'ter for the super class.
public
const OSMetaClass *getSuperClass() const;
Returns a pointer to superclass, chain ends with 0 for OSObject.
instanceConstructed |
Counts the instances of the class behind this metaclass.
public
void instanceConstructed() const;
Every non-abstract class that inherits from OSObject has a default constructor that calls its own metaclass's instanceConstructed function. This constructor is defined by the OSDefineMetaClassAndStructors macro (qv) that all OSObject subclasses must use. Also, if the instance count goes from 0 to 1, i.e. the first instance, then increment the instance count of the super class.
instanceDestructed |
Removes one instance of the class behind this metaclass.
public
void instanceDestructed() const;
OSObject's free function calls this method just before it does a 'delete this' on itself. If the instance count transitions from 1 to 0, i.e. the last object, then one instance of the superclass is also removed.
logError |
Logs an error string using printf given an error code.
private
static void logError( OSReturn result);
modHasInstance |
Returns whether any of the objects represented by OSMetaClass and associated with the given kernel module name have instances.
public
static bool modHasInstance( const char *kmodName);
kmodName
C string of the kernel module name.
Returns true if there are any current instances of any class in the module.
Checks all metaclasses associated with the module name and checks their instance counts. This function is used to check to see if a module can be unloaded. Obviously if an instance is still outstanding it isn't safe to unload the code that relies on that object.
OSMetaClass() |
Private default constructor.
private
OSMetaClass();
OSMetaClass(const char *, const OSMetaClass *, unsigned int) |
Constructor for OSMetaClass objects.
protected
OSMetaClass( const char *inClassName, const OSMetaClass *inSuperClass, unsigned int inClassSize);
inClassName
C string of the name of the class this metaclass represents.
inSuperClassName
C string of the name of the super class.
inClassSize
size of the class.
This constructor is protected and cannot be used to instantiate an OSMetaClass object, i.e. OSMetaClass is an abstract class. This function stores the currently constructing OSMetaClass instance away for later processing. See preModLoad and postModLoad.
postModLoad |
Finishes post processing on a kernel module's metaclasses.
public
static OSReturn postModLoad( void *loadHandle);
loadHandle
Handle returned when a successful call to preModLoad is made.
Returns the error code of the first error encountered.
As the order of static object construction is undefined, it is necessary to process the constructors in two phases. These phases rely on global information that is created by the preparation step, preModLoad, which also guarantees single threading between multiple modules. Phase one was the static construction of each metaclass object one by one within the context prepared by the preModLoad call. postModLoad is the second phase of processing. Inserts links all of the super class inheritance chains up, inserts the metaclasses into the global register of classes, and records for each metaclass which kernel module caused its construction. Finally, it cleans up the temporary storage and releases the single threading lock and returns whatever error has been recorded during the construction phase or the post-processing phase.
preModLoad |
Prepares the runtime type system for the loading of a module.
public
static void *preModLoad( const char *kmodName);
kmodName
Globally unique C string name of the kernel module being loaded.
Returns a handle to be used in later calls if successful, 0 otherwise.
Prepares the runtime type information system for the loading of new all metaclasses constructed between now and the next postModLoad. preModLoad grabs a lock so that the runtime type information system loading can be protected, the lock is released by the postModLoad function. Any OSMetaClass that is constructed between the bracketing pre and post calls will be assosiated with the module name.
release() |
Implements abstract but should no dynamic allocation is allowed.
protected
virtual void release() const;
release(const void *) |
Releases a tagged reference to this object.
protected
virtual void taggedRelease( const void *tag = 0) const;
release(const void *, const int) |
Releases a tagged reference to this object.
protected
virtual void taggedRelease( const void *tag, const int when) const;
release(int) |
Implements abstract but should no dynamic allocation is allowed.
protected
virtual void release( int when) const;
when
ignored.
reportModInstances |
Logs any object that has instances in a module.
public
static void reportModInstances( const char *kmodName);
kmodName
C string of the kernel module name.
When a developer asks for a module to be unloaded but the unload fails due to outstanding instances. This function will report which classes still have instances. It is intended mostly for developers to find problems with unloading classes and will be called automatically by 'verbose' unloads.
retain |
Implements abstract but should no dynamic allocation is allowed.
protected
virtual void retain() const;
taggedRelease(const void *) |
Releases a tagged reference to this object.
protected
virtual void taggedRelease( const void *tag = 0) const;
taggedRelease(const void *, const int) |
Releases a tagged reference to this object.
protected
virtual void taggedRelease( const void *tag, const int when) const;
taggedRetain |
Retains a tagged reference to this object.
protected
virtual void taggedRetain( const void *tag = 0) const;
~OSMetaClass |
Destructor for OSMetaClass objects.
protected
virtual ~OSMetaClass();
If this function is called it means that the object code that implemented this class is actually in the process of unloading. The destructor removes all references to the subclass from the runtime type information system.
className |
private
const OSSymbol *className;
classSize |
private
unsigned int classSize;
instanceCount |
private
mutable unsigned int instanceCount;
reserved |
private
ExpansionData *reserved;
superClass |
private
const OSMetaClass *superClassLink;
superClassLink |
private
const OSMetaClass *superClassLink;
OSDeclareAbstractStructors |
Declares runtime type information data and interfaces (one of the macros used in the class declaration of all subclasses of OSObject).
#define OSDeclareAbstractStructors(className) \ private: \ static const OSMetaClass * const superClass; \ public: \ static const OSMetaClass * const metaClass; \ static class MetaClass : public OSMetaClass { \ public: \ MetaClass(); \ virtual OSObject *alloc() const; \ } gMetaClass; \ friend class className ::MetaClass; \ virtual const OSMetaClass * getMetaClass() const; \ protected: \ className (const OSMetaClass *); \ virtual ~ className (); \ private: \ className (); /* Make primary constructor private in abstract */ \ protected:
className
Name of class (NO QUOTES).
This macro is used when the class being declared has one or more '= 0' pure virtual methods and thus it is illegal to create an instance of this class. It leaves the current privacy state as 'protected:'.
OSDeclareCommonStructors |
DO NOT USE. Basic helper macro for the OSDeclare for Default and Abstract macros, qv.
#define OSDeclareCommonStructors(className) \ private: \ static const OSMetaClass * const superClass; \ public: \ static const OSMetaClass * const metaClass; \ static class MetaClass : public OSMetaClass { \ public: \ MetaClass(); \ virtual OSObject *alloc() const; \ } gMetaClass; \ friend class className ::MetaClass; \ virtual const OSMetaClass * getMetaClass() const; \ protected: \ className (const OSMetaClass *); \ virtual ~ className ()
className
Name of class (NO QUOTES).
OSDeclareDefaultStructors |
Declares runtime type information data and interfaces (one of the macros used in the class declaration of all subclasses of OSObject).
#define OSDeclareDefaultStructors(className) \ private: \ static const OSMetaClass * const superClass; \ public: \ static const OSMetaClass * const metaClass; \ static class MetaClass : public OSMetaClass { \ public: \ MetaClass(); \ virtual OSObject *alloc() const; \ } gMetaClass; \ friend class className ::MetaClass; \ virtual const OSMetaClass * getMetaClass() const; \ protected: \ className (const OSMetaClass *); \ virtual ~ className (); \ public: \ className (); \ protected:
className
Name of class (NO QUOTES).
By convention this should be 'called' immediately after the opening brace in a class declaration. It leaves the current privacy state as 'protected:'.
OSDefineAbstractStructors |
DO NOT USE. Basic helper macro for the OSDefineMetaClass for the default and Abstract macros, qv.
#define OSDefineAbstractStructors(className, superClassName) \ OSObject * className ::MetaClass::alloc() const { return 0; }
className
Name of class (NO QUOTES and NO MACROS).
superClassName
Name of super class (NO QUOTES and NO MACROS).
OSDefineDefaultStructors |
DO NOT USE. Basic helper macro for the OSDefineMetaClass for the default and Abstract macros, qv.
#define OSDefineDefaultStructors(className, superClassName) \ OSObject * className ::MetaClass::alloc() const \ { return new className; } \ className :: className () : superClassName (&gMetaClass) \ { gMetaClass.instanceConstructed(); }
className
Name of class. NO QUOTES and NO MACROS.
superClassName
Name of super class. NO QUOTES and NO MACROS.
OSDefineMetaClass |
Defines an OSMetaClass instance, used for backward compatiblility only.
#define OSDefineMetaClass(className, superClassName) \ className ::MetaClass className ::gMetaClass; \ const OSMetaClass * const className ::metaClass = \ & className ::gMetaClass; \ const OSMetaClass * const className ::superClass = \ & superClassName ::gMetaClass; \ \ className :: className(const OSMetaClass *meta) \ : superClassName (meta) { } \ className ::~ className() { } \ const OSMetaClass * className ::getMetaClass() const \ { return &gMetaClass; } \ \ className ::MetaClass::MetaClass() \ : OSMetaClass("className", className::superClass, sizeof(className)) \ { ; }
className
Name of class. NO QUOTES and NO MACROS.
superClassName
Name of super class. NO QUOTES and NO MACROS.
OSDefineMetaClassAndAbstractStructors |
Defines an OSMetaClass subclass and the runtime system routines.
#define OSDefineMetaClassAndAbstractStructors(className, superClassName) \ className ::MetaClass className ::gMetaClass; \ const OSMetaClass * const className ::metaClass = \ & className ::gMetaClass; \ const OSMetaClass * const className ::superClass = \ & superClassName ::gMetaClass; \ \ className :: className(const OSMetaClass *meta) \ : superClassName (meta) { } \ className ::~ className() { } \ const OSMetaClass * className ::getMetaClass() const \ { return &gMetaClass; } \ \ className ::MetaClass::MetaClass() \ : OSMetaClass("className", className::superClass, sizeof(className)) \ { ; } \ OSObject * className ::MetaClass::alloc() const { return ; }
className
Name of class. NO QUOTES and NO MACROS.
superClassName
Name of super class. NO QUOTES and NO MACROS.
Define an OSMetaClass subclass and the primary constructors and destructors for a subclass of OSObject that is an abstract class. In general this 'function' is 'called' at the top of the file just before the first function is implemented for a particular class.
OSDefineMetaClassAndAbstractStructorsWithInit |
Defines an OSMetaClass subclass and the primary constructors and destructors for a subclass of OSObject that is an abstract class.
#define OSDefineMetaClassAndAbstractStructorsWithInit(className, superClassName, init) \ className ::MetaClass className ::gMetaClass; \ const OSMetaClass * const className ::metaClass = \ & className ::gMetaClass; \ const OSMetaClass * const className ::superClass = \ & superClassName ::gMetaClass; \ \ className :: className(const OSMetaClass *meta) \ : superClassName (meta) { } \ className ::~ className() { } \ const OSMetaClass * className ::getMetaClass() const \ { return &gMetaClass; } \ \ className ::MetaClass::MetaClass() \ : OSMetaClass("className", className::superClass, sizeof(className)) \ { init; } \ OSObject * className ::MetaClass::alloc() const { return ; }
className
Name of class (NO QUOTES and NO MACROS).
superClassName
Name of super class (NO QUOTES and NO MACROS).
init
Name of a function to call after the OSMetaClass is constructed.
This is the primary definition macro for all abstract classes that are subclasses of OSObject. In general this 'function' is 'called' at the top of the file just before the first function is implemented for a particular class. Once the OSMetaClass has been constructed, at load time, call the init routine. Note: you cannot rely on the order of execution of the init routines.
OSDefineMetaClassAndStructors |
Defines an OSMetaClass subclass and the runtime system routines.
#define OSDefineMetaClassAndStructors(className, superClassName) \ className ::MetaClass className ::gMetaClass; \ const OSMetaClass * const className ::metaClass = \ & className ::gMetaClass; \ const OSMetaClass * const className ::superClass = \ & superClassName ::gMetaClass; \ \ className :: className(const OSMetaClass *meta) \ : superClassName (meta) { } \ className ::~ className() { } \ const OSMetaClass * className ::getMetaClass() const \ { return &gMetaClass; } \ \ className ::MetaClass::MetaClass() \ : OSMetaClass("className", className::superClass, sizeof(className)) \ { ; } \ OSObject * className ::MetaClass::alloc() const \ { return new className; } \ className :: className () : superClassName (&gMetaClass) \ { gMetaClass.instanceConstructed(); }
className
Name of class. NO QUOTES and NO MACROS.
superClassName
Name of super class. NO QUOTES and NO MACROS.
Define an OSMetaClass subclass and the primary constructors and destructors for a subclass of OSObject that isn't an abstract class. In general this 'function' is 'called' at the top of the file just before the first function is implemented for a particular class.
OSDefineMetaClassAndStructorsWithInit |
See OSDefineMetaClassAndStructors.
#define OSDefineMetaClassAndStructorsWithInit(className, superClassName, init) \ className ::MetaClass className ::gMetaClass; \ const OSMetaClass * const className ::metaClass = \ & className ::gMetaClass; \ const OSMetaClass * const className ::superClass = \ & superClassName ::gMetaClass; \ \ className :: className(const OSMetaClass *meta) \ : superClassName (meta) { } \ className ::~ className() { } \ const OSMetaClass * className ::getMetaClass() const \ { return &gMetaClass; } \ \ className ::MetaClass::MetaClass() \ : OSMetaClass("className", className::superClass, sizeof(className)) \ { init; } \ OSObject * className ::MetaClass::alloc() const \ { return new className; } \ className :: className () : superClassName (&gMetaClass) \ { gMetaClass.instanceConstructed(); }
className
Name of class. NO QUOTES and NO MACROS.
superClassName
Name of super class. NO QUOTES and NO MACROS.
init
Name of a function to call after the OSMetaClass is constructed.
Define an OSMetaClass subclass and the primary constructors and destructors for a subclass of OSObject that isn't an abstract class. In general this 'function' is 'called' at the top of the file just before the first function is implemented for a particular class. Once the OSMetaClass has been constructed, at load time, call the init routine. NB you can not rely on the order of execution of the init routines.
OSDefineMetaClassWithInit |
DO NOT USE. Basic helper macro for the OSDefineMetaClass for the default and Abstract macros, qv.
#define OSDefineMetaClassWithInit(className, superClassName, init) \ /* Class global data */ \ className ::MetaClass className ::gMetaClass; \ const OSMetaClass * const className ::metaClass = \ & className ::gMetaClass; \ const OSMetaClass * const className ::superClass = \ & superClassName ::gMetaClass; \ /* Class member functions */ \ className :: className(const OSMetaClass *meta) \ : superClassName (meta) { } \ className ::~ className() { } \ const OSMetaClass * className ::getMetaClass() const \ { return &gMetaClass; } \ /* The ::MetaClass constructor */ \ className ::MetaClass::MetaClass() \ : OSMetaClass(#className, className::superClass, sizeof(className)) \ { init; }
className
Name of class (NO QUOTES and NO MACROS).
superClassName
Name of super class (NO QUOTES and NO MACROS).
init
Name of a function to call after the OSMetaClass is constructed.
|
Last Updated: 2008-12-19