Annotation of XNU/libkern/c++/OSObject.cpp, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * The contents of this file constitute Original Code as defined in and
        !             7:  * are subject to the Apple Public Source License Version 1.1 (the
        !             8:  * "License").  You may not use this file except in compliance with the
        !             9:  * License.  Please obtain a copy of the License at
        !            10:  * http://www.apple.com/publicsource and read it before using this file.
        !            11:  * 
        !            12:  * This Original Code and all software distributed under the License are
        !            13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            17:  * License for the specific language governing rights and limitations
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: /* OSObject.cpp created by gvdl on Fri 1998-11-17 */
        !            23: 
        !            24: #include <libkern/c++/OSObject.h>
        !            25: #include <libkern/c++/OSSerialize.h>
        !            26: #include <libkern/c++/OSLib.h>
        !            27: #include <libkern/c++/OSCPPDebug.h>
        !            28: #include <libkern/OSAtomic.h>
        !            29: 
        !            30: __BEGIN_DECLS
        !            31: int debug_ivars_size;
        !            32: __END_DECLS
        !            33: 
        !            34: #ifdef DEBUG
        !            35: #define ACCUMSIZE(s) do { debug_ivars_size += (s); } while(0)
        !            36: #else
        !            37: #define ACCUMSIZE(s)
        !            38: #endif
        !            39: 
        !            40: /* MetaClass bootstrap for the Top level object */
        !            41: class  OSObjectMetaClass : public OSMetaClass {
        !            42: public:
        !            43:     OSObjectMetaClass() : OSMetaClass("OSObject", "", sizeof(OSObject)) { };
        !            44:     virtual OSObject *alloc() const;
        !            45: };
        !            46: 
        !            47: OSObject *OSObjectMetaClass::alloc() const { return 0; }
        !            48: 
        !            49: static OSObjectMetaClass sOSObjectMetaClass;
        !            50: 
        !            51: const OSMetaClass * const
        !            52: OSObject::metaClass = &sOSObjectMetaClass;
        !            53: const OSMetaClass *
        !            54: OSObject::getMetaClass() const { return &sOSObjectMetaClass; }
        !            55: 
        !            56: OSObject::OSObject()
        !            57: {
        !            58:     retainCount = 1;
        !            59: }
        !            60: 
        !            61: OSObject::OSObject(const OSMetaClass *)
        !            62: {
        !            63:     retainCount = 1;
        !            64: }
        !            65: 
        !            66: OSObject::~OSObject()
        !            67: {
        !            68:     void **thisVTable;
        !            69: 
        !            70:     thisVTable = (void **)
        !            71:                    ((char *) this + sizeof(OSObject) - sizeof(thisVTable));
        !            72:     *thisVTable = (void *) -1UL;
        !            73: }
        !            74: 
        !            75: bool OSObject::init()
        !            76: {
        !            77:     return true;
        !            78: }
        !            79: 
        !            80: void OSObject::free()
        !            81: {
        !            82:     const OSMetaClass *meta = getMetaClass();
        !            83: 
        !            84:     if (meta)
        !            85:        meta->instanceDestructed();
        !            86:     delete this;
        !            87: }
        !            88: 
        !            89: OSObject *OSObject::metaCast(const OSMetaClass *toMeta) const
        !            90: {
        !            91:     return toMeta->checkMetaCast((OSObject *) this);
        !            92: }
        !            93: 
        !            94: OSObject *OSObject::metaCast(const OSSymbol *toMetaSymb) const
        !            95: {
        !            96:     return OSMetaClass::checkMetaCastWithName(toMetaSymb, this);
        !            97: }
        !            98: 
        !            99: OSObject *OSObject::metaCast(const OSString *toMetaStr) const
        !           100: {
        !           101:     return OSMetaClass::checkMetaCastWithName(toMetaStr, this);
        !           102: }
        !           103: 
        !           104: OSObject *OSObject::metaCast(const char *toMetaCStr) const
        !           105: {
        !           106:     return OSMetaClass::checkMetaCastWithName(toMetaCStr, this);
        !           107: }
        !           108: 
        !           109: int OSObject::getRetainCount() const
        !           110: {
        !           111:     return retainCount;
        !           112: }
        !           113: 
        !           114: void OSObject::retain() const
        !           115: {
        !           116:     OSIncrementAtomic((SInt32 *)&(((OSObject *) this)->retainCount));
        !           117: }
        !           118: 
        !           119: void OSObject::release(int when) const
        !           120: {
        !           121:     if (OSDecrementAtomic((SInt32 *)&(((OSObject *) this)->retainCount)) <= when)
        !           122:        ((OSObject *) this)->free();
        !           123: }
        !           124: 
        !           125: void OSObject::release() const
        !           126: {
        !           127:     release(1);
        !           128: }
        !           129: 
        !           130: bool OSObject::isEqualTo(const OSObject *anObj) const
        !           131: {
        !           132:     return this == anObj;
        !           133: }
        !           134: 
        !           135: bool OSObject::serialize(OSSerialize *s) const
        !           136: {
        !           137:     if (s->previouslySerialized(this)) return true;
        !           138: 
        !           139:     if (!s->addXMLStartTag(this, "string")) return false;
        !           140: 
        !           141:     const OSMetaClass *meta = getMetaClass();
        !           142:     if (meta) {
        !           143:        if (!s->addString(meta->getClassName())) return false;
        !           144:     } else {
        !           145:        if (!s->addString("unknown class ?")) return false;
        !           146:     }
        !           147:     if (!s->addString(" is not serializable")) return false;
        !           148:     
        !           149:     return s->addXMLEndTag("string");
        !           150: }
        !           151: 
        !           152: void *OSObject::operator new(size_t size)
        !           153: {
        !           154:     void *mem = (void *)kalloc(size);
        !           155:     assert(mem);
        !           156:     bzero(mem, size);
        !           157: 
        !           158:     ACCUMSIZE(size);
        !           159: 
        !           160:     return mem;
        !           161: }
        !           162: 
        !           163: void OSObject::operator delete(void *mem, size_t size)
        !           164: {
        !           165:     kfree((vm_offset_t)mem, size);
        !           166: 
        !           167:     ACCUMSIZE(-size);
        !           168: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.