/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+#define kIORegPlaneParentSuffix "ParentLinks"
+#define kIORegPlaneChildSuffix "ChildLinks"
+#define kIORegPlaneNameSuffix "Name"
+#define kIORegPlaneLocationSuffix "Location"
+#define kIORegPlaneParentSuffixLen (sizeof(kIORegPlaneParentSuffix) - 1)
+
static IORegistryEntry * gRegistryRoot;
static OSDictionary * gIORegistryPlanes;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
struct s_lock_t {
- decl_simple_lock_data(,interlock) /* "hardware" interlock field */
+ lck_spin_t interlock; /* "hardware" interlock field */
volatile unsigned int
read_count:16, /* No. of accepted readers */
want_upgrade:1, /* Read-to-write upgrade waiting */
{
(void) memset((void *) l, 0, sizeof(s_lock_t));
- simple_lock_init(&l->interlock, 0);
+ lck_spin_init(&l->interlock, IOLockGroup, LCK_ATTR_NULL);
l->want_write = FALSE;
l->want_upgrade = FALSE;
l->read_count = 0;
{
register int i;
- simple_lock(&l->interlock);
+ lck_spin_lock(&l->interlock);
/*
* Try to acquire the want_write bit.
i = lock_wait_time[l->can_sleep ? 1 : 0];
if (i != 0) {
- simple_unlock(&l->interlock);
+ lck_spin_unlock(&l->interlock);
while (--i != 0 && l->want_write)
continue;
- simple_lock(&l->interlock);
+ lck_spin_lock(&l->interlock);
}
if (l->can_sleep && l->want_write) {
l->waiting = TRUE;
- thread_sleep_simple_lock((event_t) l,
- simple_lock_addr(l->interlock),
- THREAD_UNINT);
+ lck_spin_sleep( &l->interlock, LCK_SLEEP_DEFAULT,
+ (event_t) l, THREAD_UNINT);
/* interlock relocked */
}
}
i = lock_wait_time[l->can_sleep ? 1 : 0];
if (i != 0) {
- simple_unlock(&l->interlock);
+ lck_spin_unlock(&l->interlock);
while (--i != 0 && (l->read_count != 0 ||
l->want_upgrade))
continue;
- simple_lock(&l->interlock);
+ lck_spin_lock(&l->interlock);
}
if (l->can_sleep && (l->read_count != 0 || l->want_upgrade)) {
l->waiting = TRUE;
- thread_sleep_simple_lock((event_t) l,
- simple_lock_addr(l->interlock),
- THREAD_UNINT);
+ lck_spin_sleep( &l->interlock, LCK_SLEEP_DEFAULT,
+ (event_t) l, THREAD_UNINT);
/* interlock relocked */
}
}
- simple_unlock(&l->interlock);
+ lck_spin_unlock(&l->interlock);
}
static void
{
boolean_t do_wakeup = FALSE;
- simple_lock(&l->interlock);
+ lck_spin_lock(&l->interlock);
if (l->read_count != 0) {
l->read_count -= 1;
do_wakeup = TRUE;
}
- simple_unlock(&l->interlock);
+ lck_spin_unlock(&l->interlock);
if (do_wakeup)
thread_wakeup((event_t) l);
{
register int i;
- simple_lock(&l->interlock);
+ lck_spin_lock(&l->interlock);
while ( l->want_upgrade || ((0 == l->read_count) && l->want_write )) {
i = lock_wait_time[l->can_sleep ? 1 : 0];
if (i != 0) {
- simple_unlock(&l->interlock);
+ lck_spin_unlock(&l->interlock);
while (--i != 0 &&
(l->want_upgrade || ((0 == l->read_count) && l->want_write )))
continue;
- simple_lock(&l->interlock);
+ lck_spin_lock(&l->interlock);
}
if (l->can_sleep &&
(l->want_upgrade || ((0 == l->read_count) && l->want_write ))) {
l->waiting = TRUE;
- thread_sleep_simple_lock((event_t) l,
- simple_lock_addr(l->interlock),
- THREAD_UNINT);
+ lck_spin_sleep( &l->interlock, LCK_SLEEP_DEFAULT,
+ (event_t) l, THREAD_UNINT);
/* interlock relocked */
}
}
l->read_count += 1;
- simple_unlock(&l->interlock);
+ lck_spin_unlock(&l->interlock);
}
nameKey = OSSymbol::withCString( key);
- strcpy( end, "ParentLinks" );
+ strcpy( end, kIORegPlaneParentSuffix );
parentKey = OSSymbol::withCString( key);
- strcpy( end, "ChildLinks" );
+ strcpy( end, kIORegPlaneChildSuffix );
childKey = OSSymbol::withCString( key);
- strcpy( end, "Name" );
+ strcpy( end, kIORegPlaneNameSuffix );
pathNameKey = OSSymbol::withCString( key);
- strcpy( end, "Location" );
+ strcpy( end, kIORegPlaneLocationSuffix );
pathLocationKey = OSSymbol::withCString( key);
plane = new IORegistryPlane;
enum { kIORegCapacityIncrement = 4 };
-bool IORegistryEntry::init( OSDictionary * dict = 0 )
+bool IORegistryEntry::init( OSDictionary * dict )
{
OSString * prop;
/* Wrappers to synchronize property table */
-#define wrap1(func, type, constant) \
-OSObject * \
-IORegistryEntry::func ## Property( type * aKey) constant \
-{ \
- OSObject * obj; \
- \
- PLOCK; \
- obj = getPropertyTable()->func ## Object( aKey ); \
- PUNLOCK; \
- \
- return( obj ); \
-}
-
#define wrap2(type, constant) \
OSObject * \
IORegistryEntry::copyProperty( type * aKey) constant \
return( obj ); \
}
-#define wrap3(func,type,constant) \
-void \
-IORegistryEntry::func ## Property( type * aKey) constant \
-{ \
- PLOCK; \
- getPropertyTable()->func ## Object( aKey ); \
- PUNLOCK; \
-}
-
#define wrap4(type,constant) \
OSObject * \
IORegistryEntry::getProperty( type * aKey, \
bool IORegistryEntry::serializeProperties( OSSerialize * s ) const
{
- bool ok;
-
// setProperty( getRetainCount(), 32, "__retain" );
PLOCK;
- ok = getPropertyTable()->serialize( s );
+ OSCollection *snapshotProperties = getPropertyTable()->copyCollection();
PUNLOCK;
+ bool ok = snapshotProperties->serialize( s );
+ snapshotProperties->release();
return( ok );
}
return( kIOReturnUnsupported );
}
-wrap1(get, const OSSymbol, const) // getProperty() definition
-wrap1(get, const OSString, const) // getProperty() definition
-wrap1(get, const char, const) // getProperty() definition
-
wrap2(const OSSymbol, const) // copyProperty() definition
wrap2(const OSString, const) // copyProperty() definition
wrap2(const char, const) // copyProperty() definition
-wrap3(remove, const OSSymbol,) // removeProperty() definition
-wrap3(remove, const OSString,) // removeProperty() definition
-wrap3(remove, const char,) // removeProperty() definition
-
wrap4(const OSSymbol, const) // getProperty() w/plane definition
wrap4(const OSString, const) // getProperty() w/plane definition
wrap4(const char, const) // getProperty() w/plane definition
wrap5(const char, const) // copyProperty() w/plane definition
+OSObject *
+IORegistryEntry::getProperty( const OSSymbol * aKey) const
+{
+ OSObject * obj;
+
+ PLOCK;
+ obj = getPropertyTable()->getObject( aKey );
+ PUNLOCK;
+
+ return( obj );
+}
+
+void
+IORegistryEntry::removeProperty( const OSSymbol * aKey)
+{
+ PLOCK;
+ getPropertyTable()->removeObject( aKey );
+ PUNLOCK;
+}
+
bool
IORegistryEntry::setProperty( const OSSymbol * aKey, OSObject * anObject)
{
bool ret = false;
+
+ // If we are inserting a collection class and the current entry
+ // is attached into the registry (inPlane()) then mark the collection
+ // as immutable.
+ OSCollection *coll = OSDynamicCast(OSCollection, anObject);
+ bool makeImmutable = (coll && inPlane());
+
PLOCK;
+ if( makeImmutable )
+ coll->setOptions( OSCollection::kMASK, OSCollection::kImmutable );
+
ret = getPropertyTable()->setObject( aKey, anObject );
PUNLOCK;
return ret;
}
-bool
-IORegistryEntry::setProperty( const OSString * aKey, OSObject * anObject)
+IOReturn IORegistryEntry::
+runPropertyAction(Action inAction, OSObject *target,
+ void *arg0, void *arg1, void *arg2, void *arg3)
{
- bool ret = false;
+ IOReturn res;
+
+ // closeGate is recursive so don't worry if we already hold the lock.
PLOCK;
- ret = getPropertyTable()->setObject( aKey, anObject );
+ res = (*inAction)(target, arg0, arg1, arg2, arg3);
PUNLOCK;
+ return res;
+}
+
+OSObject *
+IORegistryEntry::getProperty( const OSString * aKey) const
+{
+ const OSSymbol * tmpKey = OSSymbol::withString( aKey );
+ OSObject * obj = getProperty( tmpKey );
+
+ tmpKey->release();
+ return( obj );
+}
+
+OSObject *
+IORegistryEntry::getProperty( const char * aKey) const
+{
+ const OSSymbol * tmpKey = OSSymbol::withCString( aKey );
+ OSObject * obj = getProperty( tmpKey );
+
+ tmpKey->release();
+ return( obj );
+}
+
+
+void
+IORegistryEntry::removeProperty( const OSString * aKey)
+{
+ const OSSymbol * tmpKey = OSSymbol::withString( aKey );
+ removeProperty( tmpKey );
+ tmpKey->release();
+}
+
+void
+IORegistryEntry::removeProperty( const char * aKey)
+{
+ const OSSymbol * tmpKey = OSSymbol::withCString( aKey );
+ removeProperty( tmpKey );
+ tmpKey->release();
+}
+
+bool
+IORegistryEntry::setProperty( const OSString * aKey, OSObject * anObject)
+{
+ const OSSymbol * tmpKey = OSSymbol::withString( aKey );
+ bool ret = setProperty( tmpKey, anObject );
+
+ tmpKey->release();
return ret;
}
bool
IORegistryEntry::setProperty( const char * aKey, OSObject * anObject)
{
- bool ret = false;
- PLOCK;
- ret = getPropertyTable()->setObject( aKey, anObject );
- PUNLOCK;
-
+ const OSSymbol * tmpKey = OSSymbol::withCString( aKey );
+ bool ret = setProperty( tmpKey, anObject );
+
+ tmpKey->release();
return ret;
}
OSSymbol * aSymbol = (OSSymbol *) OSSymbol::withCString( aString );
if( aSymbol) {
- PLOCK;
- ret = getPropertyTable()->setObject( aKey, aSymbol );
- PUNLOCK;
+ const OSSymbol * tmpKey = OSSymbol::withCString( aKey );
+ ret = setProperty( tmpKey, aSymbol );
+
+ tmpKey->release();
aSymbol->release();
}
return( ret );
OSBoolean * aBooleanObj = OSBoolean::withBoolean( aBoolean );
if( aBooleanObj) {
- PLOCK;
- ret = getPropertyTable()->setObject( aKey, aBooleanObj );
- PUNLOCK;
+ const OSSymbol * tmpKey = OSSymbol::withCString( aKey );
+ ret = setProperty( tmpKey, aBooleanObj );
+
+ tmpKey->release();
aBooleanObj->release();
}
return( ret );
OSNumber * anOffset = OSNumber::withNumber( aValue, aNumberOfBits );
if( anOffset) {
- PLOCK;
- ret = getPropertyTable()->setObject( aKey, anOffset );
- PUNLOCK;
+ const OSSymbol * tmpKey = OSSymbol::withCString( aKey );
+ ret = setProperty( tmpKey, anOffset );
+
+ tmpKey->release();
anOffset->release();
}
return( ret );
OSData * data = OSData::withBytes( bytes, length );
if( data) {
- PLOCK;
- ret = getPropertyTable()->setObject( aKey, data );
- PUNLOCK;
+ const OSSymbol * tmpKey = OSSymbol::withCString( aKey );
+ ret = setProperty( tmpKey, data );
+
+ tmpKey->release();
data->release();
}
return( ret );
/* Name, location, paths */
-const char * IORegistryEntry::getName( const IORegistryPlane * plane = 0 ) const
+const char * IORegistryEntry::getName( const IORegistryPlane * plane ) const
{
OSSymbol * sym = 0;
}
const OSSymbol * IORegistryEntry::copyName(
- const IORegistryPlane * plane = 0 ) const
+ const IORegistryPlane * plane ) const
{
OSSymbol * sym = 0;
}
const OSSymbol * IORegistryEntry::copyLocation(
- const IORegistryPlane * plane = 0 ) const
+ const IORegistryPlane * plane ) const
{
OSSymbol * sym = 0;
return( sym );
}
-const char * IORegistryEntry::getLocation( const IORegistryPlane * plane = 0 ) const
+const char * IORegistryEntry::getLocation( const IORegistryPlane * plane ) const
{
const OSSymbol * sym = copyLocation( plane );
const char * result = 0;
}
void IORegistryEntry::setName( const OSSymbol * name,
- const IORegistryPlane * plane = 0 )
+ const IORegistryPlane * plane )
{
const OSSymbol * key;
}
void IORegistryEntry::setName( const char * name,
- const IORegistryPlane * plane = 0 )
+ const IORegistryPlane * plane )
{
OSSymbol * sym = (OSSymbol *)OSSymbol::withCString( name );
if ( sym ) {
}
void IORegistryEntry::setLocation( const OSSymbol * location,
- const IORegistryPlane * plane = 0 )
+ const IORegistryPlane * plane )
{
const OSSymbol * key;
}
void IORegistryEntry::setLocation( const char * location,
- const IORegistryPlane * plane = 0 )
+ const IORegistryPlane * plane )
{
OSSymbol * sym = (OSSymbol *)OSSymbol::withCString( location );
if ( sym ) {
}
bool
-IORegistryEntry::compareName( OSString * name, OSString ** matched = 0 ) const
+IORegistryEntry::compareName( OSString * name, OSString ** matched ) const
{
const OSSymbol * sym = copyName();
bool isEqual;
}
bool
-IORegistryEntry::compareNames( OSObject * names, OSString ** matched = 0 ) const
+IORegistryEntry::compareNames( OSObject * names, OSString ** matched ) const
{
OSString * string;
OSCollection * collection;
const char * str;
const char * result = 0;
u_quad_t num1, num2;
- char c1, c2;
+ char lastPathChar, lastLocationChar;
str = getLocation( plane );
if( str) {
- c2 = str[0];
+ lastPathChar = cmp[0];
+ lastLocationChar = str[0];
do {
- num1 = strtouq( cmp, (char **) &cmp, 16 );
- if( c2) {
+ if( lastPathChar) {
+ num1 = strtouq( cmp, (char **) &cmp, 16 );
+ lastPathChar = *cmp++;
+ } else
+ num1 = 0;
+
+ if( lastLocationChar) {
num2 = strtouq( str, (char **) &str, 16 );
- c2 = str[0];
+ lastLocationChar = *str++;
} else
num2 = 0;
if( num1 != num2)
break;
- c1 = *cmp++;
-
- if( (c2 == ':') && (c2 == c1)) {
- str++;
- continue;
- }
-
- if( ',' != c1) {
+ if (!lastPathChar && !lastLocationChar) {
result = cmp - 1;
break;
}
- if( c2) {
- if( c2 != ',')
- break;
- str++;
- }
+ if( (',' != lastPathChar) && (':' != lastPathChar))
+ lastPathChar = 0;
+
+ if (lastPathChar && lastLocationChar && (lastPathChar != lastLocationChar))
+ break;
} while( true);
}
}
const OSSymbol * IORegistryEntry::hasAlias( const IORegistryPlane * plane,
- char * opath = 0, int * length = 0 ) const
+ char * opath, int * length ) const
{
IORegistryEntry * entry;
IORegistryEntry * entry2;
IORegistryEntry * IORegistryEntry::fromPath(
const char * path,
- const IORegistryPlane * plane = 0,
- char * opath = 0,
- int * length = 0,
- IORegistryEntry * fromEntry = 0 )
+ const IORegistryPlane * plane,
+ char * opath,
+ int * length,
+ IORegistryEntry * fromEntry )
{
IORegistryEntry * where = 0;
IORegistryEntry * aliasEntry = 0;
IORegistryEntry * IORegistryEntry::childFromPath(
const char * path,
- const IORegistryPlane * plane = 0,
- char * opath = 0,
- int * len = 0 )
+ const IORegistryPlane * plane,
+ char * opath,
+ int * len )
{
return( IORegistryEntry::fromPath( path, plane, opath, len, this ));
}
inline bool IORegistryEntry::arrayMember( OSArray * set,
const IORegistryEntry * member,
- unsigned int * index = 0 ) const
+ unsigned int * index ) const
{
int i;
OSObject * probeObject;
} else {
- links = OSArray::withObjects( & (const OSObject *) to, 1, 1 );
+ links = OSArray::withObjects( (const OSObject **) &to, 1, 1 );
result = (links != 0);
if( result) {
result = registryTable()->setObject( plane->keys[ relation ],
bool IORegistryEntry::isChild( IORegistryEntry * child,
const IORegistryPlane * plane,
- bool onlyChild = false ) const
+ bool onlyChild ) const
{
OSArray * links;
bool ret = false;
bool IORegistryEntry::isParent( IORegistryEntry * parent,
const IORegistryPlane * plane,
- bool onlyParent = false ) const
+ bool onlyParent ) const
{
OSArray * links;
RLOCK;
- ret = (0 != getParentSetReference( plane ));
+ if( plane)
+ ret = (0 != getParentSetReference( plane ));
+ else {
+
+ // Check to see if this is in any plane. If it is in a plane
+ // then the registryTable will contain a key with the ParentLinks
+ // suffix. When we iterate over the keys looking for that suffix
+ ret = false;
+
+ OSCollectionIterator *iter =
+ OSCollectionIterator::withCollection( registryTable());
+ if( iter) {
+ const OSSymbol *key;
+
+ while( (key = (OSSymbol *) iter->getNextObject()) ) {
+ const char *keysuffix;
+
+ // Get a pointer to this keys suffix
+ keysuffix = key->getCStringNoCopy()
+ + key->getLength() - kIORegPlaneParentSuffixLen;
+ if( !strcmp(keysuffix, kIORegPlaneParentSuffix) ) {
+ ret = true;
+ break;
+ }
+ }
+ iter->release();
+ }
+ }
UNLOCK;
else
needParent = true;
-// ret &= parent->makeLink( this, kChildSetIndex, plane );
-
UNLOCK;
+ PLOCK;
+
+ // Mark any collections in the property list as immutable
+ OSDictionary *ptable = getPropertyTable();
+ OSCollectionIterator *iter =
+ OSCollectionIterator::withCollection( ptable );
+ if( iter) {
+ const OSSymbol *key;
+
+ while( (key = (OSSymbol *) iter->getNextObject( ))) {
+ // Is object for key a collection?
+ OSCollection *coll =
+ OSDynamicCast( OSCollection, ptable->getObject( key ));
+
+ if( coll) {
+ // Yup so mark it as immutable
+ coll->setOptions( OSCollection::kMASK,
+ OSCollection::kImmutable );
+ }
+ }
+ iter->release();
+ }
+
+ PUNLOCK;
+
if( needParent)
ret &= parent->attachToChild( this, plane );
IORegistryIterator *
IORegistryIterator::iterateOver( IORegistryEntry * root,
const IORegistryPlane * plane,
- IOOptionBits options = 0 )
+ IOOptionBits options )
{
IORegistryIterator * create;
IORegistryIterator *
IORegistryIterator::iterateOver( const IORegistryPlane * plane,
- IOOptionBits options = 0 )
+ IOOptionBits options )
{
return( iterateOver( gRegistryRoot, plane, options ));
}
OSMetaClassDefineReservedUsed(IORegistryEntry, 2);
OSMetaClassDefineReservedUsed(IORegistryEntry, 3);
OSMetaClassDefineReservedUsed(IORegistryEntry, 4);
+OSMetaClassDefineReservedUsed(IORegistryEntry, 5);
-OSMetaClassDefineReservedUnused(IORegistryEntry, 5);
OSMetaClassDefineReservedUnused(IORegistryEntry, 6);
OSMetaClassDefineReservedUnused(IORegistryEntry, 7);
OSMetaClassDefineReservedUnused(IORegistryEntry, 8);