]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_utilities/lib/seccfobject.cpp
Security-59754.80.3.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / seccfobject.cpp
index 142a273025de8be1cf617e5b3f91e58a26bc9d1d..04972e7c303951406e4446752c974e45785f782b 100644 (file)
 #include <security_utilities/cfclass.h>
 #include <security_utilities/errors.h>
 #include <security_utilities/debugging.h>
 #include <security_utilities/cfclass.h>
 #include <security_utilities/errors.h>
 #include <security_utilities/debugging.h>
+#include <os/lock.h>
 
 #include <list>
 #include <security_utilities/globalizer.h>
 
 #include <list>
 #include <security_utilities/globalizer.h>
-#include <auto_zone.h>
+#if( __cplusplus <= 201103L)
+#include <stdatomic.h>
+#endif
 
 SecPointerBase::SecPointerBase(const SecPointerBase& p)
 {
 
 SecPointerBase::SecPointerBase(const SecPointerBase& p)
 {
@@ -40,20 +43,6 @@ SecPointerBase::SecPointerBase(const SecPointerBase& p)
 }
 
 
 }
 
 
-
-
-static void CheckForRelease(SecCFObject* ptr)
-{
-       CFTypeRef tr = ptr->operator CFTypeRef();
-       CFIndex retainCount = CFGetRetainCount(tr);
-       if (retainCount == 1 || retainCount == -1)
-       {
-               ptr->aboutToDestruct();
-       }
-}
-
-
-
 SecPointerBase::SecPointerBase(SecCFObject *p)
 {
        if (p && !p->isNew())
 SecPointerBase::SecPointerBase(SecCFObject *p)
 {
        if (p && !p->isNew())
@@ -69,7 +58,6 @@ SecPointerBase::~SecPointerBase()
 {
        if (ptr)
        {
 {
        if (ptr)
        {
-               CheckForRelease(ptr);
                CFRelease(ptr->operator CFTypeRef());
        }
 }
                CFRelease(ptr->operator CFTypeRef());
        }
 }
@@ -85,7 +73,6 @@ SecPointerBase& SecPointerBase::operator = (const SecPointerBase& p)
        }
        if (ptr)
        {
        }
        if (ptr)
        {
-               CheckForRelease(ptr);
                CFRelease(ptr->operator CFTypeRef());
        }
        ptr = p.ptr;
                CFRelease(ptr->operator CFTypeRef());
        }
        ptr = p.ptr;
@@ -102,7 +89,6 @@ void SecPointerBase::assign(SecCFObject * p)
        }
        if (ptr)
        {
        }
        if (ptr)
        {
-               CheckForRelease(ptr);
                CFRelease(ptr->operator CFTypeRef());
        }
        ptr = p;
                CFRelease(ptr->operator CFTypeRef());
        }
        ptr = p;
@@ -114,7 +100,6 @@ void SecPointerBase::copy(SecCFObject * p)
 {
        if (ptr)
        {
 {
        if (ptr)
        {
-               CheckForRelease(ptr);
                CFRelease(ptr->operator CFTypeRef());
        }
        
                CFRelease(ptr->operator CFTypeRef());
        }
        
@@ -127,7 +112,7 @@ void SecPointerBase::copy(SecCFObject * p)
 // SecCFObject
 //
 SecCFObject *
 // SecCFObject
 //
 SecCFObject *
-SecCFObject::optional(CFTypeRef cfTypeRef) throw()
+SecCFObject::optional(CFTypeRef cfTypeRef) _NOEXCEPT
 {
        if (!cfTypeRef)
                return NULL;
 {
        if (!cfTypeRef)
                return NULL;
@@ -146,33 +131,25 @@ SecCFObject::required(CFTypeRef cfTypeRef, OSStatus error)
 }
 
 void *
 }
 
 void *
-SecCFObject::allocate(size_t size, const CFClass &cfclass) throw(std::bad_alloc)
+SecCFObject::allocate(size_t size, const CFClass &cfclass)
 {
        CFTypeRef p = _CFRuntimeCreateInstance(NULL, cfclass.typeID,
                size + kAlignedRuntimeSize - sizeof(CFRuntimeBase), NULL);
        if (p == NULL)
                throw std::bad_alloc();
 
 {
        CFTypeRef p = _CFRuntimeCreateInstance(NULL, cfclass.typeID,
                size + kAlignedRuntimeSize - sizeof(CFRuntimeBase), NULL);
        if (p == NULL)
                throw std::bad_alloc();
 
-       ((SecRuntimeBase*) p)->isNew = true;
+       atomic_flag_clear(&((SecRuntimeBase*) p)->isOld);
 
        void *q = ((u_int8_t*) p) + kAlignedRuntimeSize;
 
 
        void *q = ((u_int8_t*) p) + kAlignedRuntimeSize;
 
-       if (SECURITY_DEBUG_SEC_CREATE_ENABLED()) {
-               const CFRuntimeClass *rtc = _CFRuntimeGetClassWithTypeID(cfclass.typeID);
-               SECURITY_DEBUG_SEC_CREATE(q, rtc ? (char *)rtc->className : NULL, (unsigned int)cfclass.typeID);
-       }
        return q;
 }
 
 void
        return q;
 }
 
 void
-SecCFObject::operator delete(void *object) throw()
+SecCFObject::operator delete(void *object) _NOEXCEPT
 {
        CFTypeRef cfType = reinterpret_cast<CFTypeRef>(reinterpret_cast<const uint8_t *>(object) - kAlignedRuntimeSize);
 {
        CFTypeRef cfType = reinterpret_cast<CFTypeRef>(reinterpret_cast<const uint8_t *>(object) - kAlignedRuntimeSize);
-    if (CF_IS_COLLECTABLE(cfType))
-    {
-        return;
-    }
-    
+
     CFAllocatorRef allocator = CFGetAllocator(cfType);
     CFAllocatorDeallocate(allocator, (void*) cfType);
 }
     CFAllocatorRef allocator = CFGetAllocator(cfType);
     CFAllocatorDeallocate(allocator, (void*) cfType);
 }
@@ -180,12 +157,12 @@ SecCFObject::operator delete(void *object) throw()
 SecCFObject::SecCFObject()
 {
     mRetainCount = 1;
 SecCFObject::SecCFObject()
 {
     mRetainCount = 1;
-    mRetainSpinLock = OS_SPINLOCK_INIT;
+    mRetainLock = OS_UNFAIR_LOCK_INIT;
 }
 
 uint32_t SecCFObject::updateRetainCount(intptr_t direction, uint32_t *oldCount)
 {
 }
 
 uint32_t SecCFObject::updateRetainCount(intptr_t direction, uint32_t *oldCount)
 {
-    OSSpinLockLock(&mRetainSpinLock);
+    os_unfair_lock_lock(&mRetainLock);
 
     if (oldCount != NULL)
     {
 
     if (oldCount != NULL)
     {
@@ -203,7 +180,7 @@ uint32_t SecCFObject::updateRetainCount(intptr_t direction, uint32_t *oldCount)
     
     uint32_t result = mRetainCount;
 
     
     uint32_t result = mRetainCount;
 
-    OSSpinLockUnlock(&mRetainSpinLock);
+    os_unfair_lock_unlock(&mRetainLock);
     
     return result;
 }
     
     return result;
 }
@@ -212,7 +189,7 @@ uint32_t SecCFObject::updateRetainCount(intptr_t direction, uint32_t *oldCount)
 
 SecCFObject::~SecCFObject()
 {
 
 SecCFObject::~SecCFObject()
 {
-       SECURITY_DEBUG_SEC_DESTROY(this);
+       //SECURITY_DEBUG_SEC_DESTROY(this);
 }
 
 bool
 }
 
 bool
@@ -240,7 +217,7 @@ SecCFObject::copyDebugDesc()
 }
 
 CFTypeRef
 }
 
 CFTypeRef
-SecCFObject::handle(bool retain) throw()
+SecCFObject::handle(bool retain) _NOEXCEPT
 {
        CFTypeRef cfType = *this;
        if (retain && !isNew()) CFRetain(cfType);
 {
        CFTypeRef cfType = *this;
        if (retain && !isNew()) CFRetain(cfType);
@@ -257,7 +234,7 @@ SecCFObject::aboutToDestruct()
 
 
 Mutex*
 
 
 Mutex*
-SecCFObject::getMutexForObject()
+SecCFObject::getMutexForObject() const
 {
        return NULL; // we only worry about descendants of KeychainImpl and ItemImpl
 }
 {
        return NULL; // we only worry about descendants of KeychainImpl and ItemImpl
 }