72 ( objectTable[ objectHandle ].
type != target && \
73 objectTable[ objectHandle ].
type != altTarget ) )
77 ENSURES( objectTable[ objectHandle ].
type == target || \
78 objectTable[ objectHandle ].
type == altTarget );
80 return( objectHandle );
100 if( messageParamACLTbl[ i ].
type == message )
101 return( &messageParamACLTbl[ i ] );
117 #define MAX_WAITCOUNT 10000
118 #define WAITCOUNT_WARN_THRESHOLD 100
120 #if !defined( NDEBUG ) && !defined( __WIN16__ )
122 static void waitWarn(
IN_HANDLE const int objectHandle,
123 IN_INT const int waitCount )
125 static const char *objectTypeNames[] = {
126 "None",
"Context",
"Keyset",
"Envelope",
"Certificate",
"Device",
127 "Session",
"User",
"None",
"None"
139 strlcpy_s( buffer, 128,
"system object" );
143 strlcpy_s( buffer, 128,
"default user object" );
146 sprintf_s( buffer, 128,
"object %d (%s, subtype %X)",
147 objectHandle, objectTypeNames[ objectInfoPtr->
type ],
151 DEBUG_PRINT((
"\nWarning: Thread %lX waited %d iteration%s for %s.\n",
153 ( waitCount == 1 ) ?
"" :
"s", buffer ));
158 int waitForObject(
IN_HANDLE const int objectHandle,
176 objectTable[ objectHandle ].uniqueID == uniqueID && \
187 #if !defined( NDEBUG ) && !defined( __WIN16__ )
194 waitWarn( objectHandle, waitCount );
213 objectTable[ objectHandle ].uniqueID != uniqueID )
218 *objectInfoPtrPtr = &objectTable[ objectHandle ];
245 const OBJECT_TYPE altTarget1 = ( targets >> 8 ) & 0xFF;
246 const OBJECT_TYPE altTarget2 = ( targets >> 16 ) & 0xFF;
249 int objectHandle = originalObjectHandle,
iterations;
261 for( iterations = 0; \
263 !( target == type || \
279 objectTable[ objectHandle ].dependentDevice !=
CRYPT_ERROR )
294 type = objectTable[ objectHandle ].type;
300 objectTable[ originalObjectHandle ].
owner == objectHandle );
309 objectTable[ originalObjectHandle ].
owner == objectHandle ) && \
310 ( target == type || \
326 static
int routeCompareMessageTarget(
IN_HANDLE const int originalObjectHandle,
331 int objectHandle = originalObjectHandle;
350 switch( messageValue )
381 return( objectHandle );
427 #define PRE_DISPATCH( function ) preDispatch##function, NULL
428 #define POST_DISPATCH( function ) NULL, postDispatch##function
429 #define PRE_POST_DISPATCH( preFunction, postFunction ) \
430 preDispatch##preFunction, postDispatch##postFunction
431 #define HANDLE_INTERNAL( function ) NULL, NULL, MESSAGE_HANDLING_FLAG_INTERNAL, function
445 #define MESSAGE_HANDLING_FLAG_NONE 0
446 #define MESSAGE_HANDLING_FLAG_MAYUNLOCK 1
447 #define MESSAGE_HANDLING_FLAG_INTERNAL 2
461 int ( *routingFunction )(
const int objectHandle,
const long arg );
475 int ( *preDispatchFunction )(
const int objectHandle,
479 int ( *postDispatchFunction )(
const int objectHandle,
488 int ( *internalHandlerFunction )(
const int objectHandle,
const int arg1,
730 const int messageValue )
738 return( messageDataPtr == NULL && messageValue == 0 );
741 return( messageDataPtr == NULL );
744 return( messageDataPtr == NULL && \
745 ( messageValue ==
FALSE || messageValue ==
TRUE ) );
748 return( messageDataPtr == NULL && \
753 return( messageDataPtr != NULL && messageValue == 0 );
756 return( messageDataPtr != NULL );
759 return( messageDataPtr != NULL && messageValue >= 0 );
762 return( messageDataPtr != NULL && \
767 return( messageDataPtr != NULL && \
772 return( messageDataPtr != NULL && \
777 return( messageDataPtr != NULL && \
782 return( messageDataPtr != NULL && \
787 return( messageDataPtr != NULL && \
792 return( messageDataPtr != NULL && \
853 const MESSAGE_ACL *messageParamACL = &messageParamACLTbl[ i ];
909 krnlData = krnlDataPtr;
928 static
int enqueueMessage(
IN_HANDLE const int objectHandle,
931 IN_OPT const void *messageDataPtr,
932 const int messageValue )
935 int queuePos, i, iterationCount;
952 DEBUG_DIAG((
"Invalid kernel message queue state" ));
963 for( queuePos = krnlData->
queueEnd - 1, iterationCount = 0;
966 if( messageQueue[ queuePos ].objectHandle == objectHandle )
974 ( queuePos >= 0 && queuePos < krnlData->queueEnd ) );
977 ENSURES( queuePos >= -1 && queuePos < krnlData->queueEnd );
987 for( i = krnlData->
queueEnd - 1, iterationCount = 0;
989 i--, iterationCount++ )
990 messageQueue[ i + 1 ] = messageQueue[ i ];
1018 const int messagePosition )
1021 int i, iterationCount;
1025 REQUIRES( messagePosition >= 0 && \
1026 messagePosition < krnlData->queueEnd );
1031 for( i = messagePosition, iterationCount = 0;
1034 messageQueue[ i ] = messageQueue[ i + 1 ];
1035 ENSURES( iterationCount < MESSAGE_QUEUE_SIZE );
1044 krnlData->
queueEnd < MESSAGE_QUEUE_SIZE - 1 );
1062 assert( messageQueueInfo == NULL || \
1073 if( messageQueueInfo != NULL )
1078 krnlData->
queueEnd < MESSAGE_QUEUE_SIZE );
1085 if( messageQueue[ i ].objectHandle == objectHandle )
1089 if( messageQueueInfo != NULL )
1090 *messageQueueInfo = messageQueue[ i ];
1091 status = dequeueMessage( i );
1110 static void dequeueAllMessages(
IN_HANDLE const int objectHandle )
1122 for( iterationCount = 0;
1123 getNextMessage( objectHandle, NULL ) && \
1126 ENSURES_V( iterationCount < MESSAGE_QUEUE_SIZE );
1131 krnlData->messageQueue[ i ].objectHandle != objectHandle );
1144 static
int processInternalMessage(
IN_HANDLE const int localObjectHandle,
1147 IN_OPT void *messageDataPtr,
1148 const int messageValue,
1149 IN_OPT const void *aclPtr )
1163 message, messageDataPtr, messageValue,
1182 REQUIRES( messageDataPtr != NULL );
1185 status = getPropertyAttribute( localObjectHandle, messageValue,
1188 status = setPropertyAttribute( localObjectHandle, messageValue,
1195 messageValue, messageDataPtr,
1213 message, messageDataPtr, messageValue,
1225 static
int dispatchMessage(
IN_HANDLE const int localObjectHandle,
1228 IN_OPT const void *aclPtr )
1231 messageQueueData->handlingInfoPtr;
1235 void *
objectPtr = objectInfoPtr->objectPtr;
1246 REQUIRES( messageFunction != NULL );
1277 objectInfoPtr->lockCount++;
1286 objectInfoPtr = &krnlData->
objectTable[ localObjectHandle ];
1290 objectInfoPtr->lockCount--;
1294 ENSURES( objectInfoPtr->lockCount >= 0 && \
1318 void *messageDataPtr,
const int messageValue )
1326 const void *aclPtr = NULL;
1328 int localObjectHandle = objectHandle, iterationCount;
1343 handlingInfoPtr = &messageHandlingInfo[ localMessage ];
1357 if( attributeACL == NULL )
1359 aclPtr = attributeACL;
1375 REQUIRES( messageDataPtr != NULL );
1377 if( *( (
BOOLEAN * ) messageDataPtr ) )
1383 aclPtr = findParamACL( localMessage );
1405 messageValue == CRYPT_IATTRIBUTE_STATUS ) ) )
1438 if( !isInternalMessage && \
1499 objectInfoPtr = &objectTable[ localObjectHandle ];
1523 ( attributeACL != NULL && \
1526 status = processInternalMessage( localObjectHandle, handlingInfoPtr,
1527 message, messageDataPtr,
1528 messageValue, aclPtr );
1551 localObjectHandle, handlingInfoPtr, message, \
1552 messageDataPtr, messageValue );
1556 messageQueueData.
message = message; \
1585 status = dispatchMessage( localObjectHandle, &messageQueueData,
1586 objectInfoPtr, aclPtr );
1616 if( objectInfoPtr->
lockCount > MESSAGE_QUEUE_SIZE / 2 )
1619 DEBUG_DIAG((
"Invalid kernel message queue state" ));
1628 status = waitForObject( localObjectHandle, &objectInfoPtr );
1629 #if !defined( NDEBUG ) && defined( USE_THREADS )
1643 assert( !
isInUse( localObjectHandle ) || \
1647 if( ( message & MESSAGE_MASK ) != localMessage )
1656 status = enqueueMessage( localObjectHandle,
1658 MESSAGE_DESTROY, messageDataPtr,
TRUE );
1662 status = enqueueMessage( localObjectHandle, handlingInfoPtr, message,
1663 messageDataPtr, messageValue );
1672 assert( !
isInUse( localObjectHandle ) || \
1686 for( iterationCount = 0;
1687 getNextMessage( localObjectHandle, &enqueuedMessageData ) && \
1720 dequeueAllMessages( localObjectHandle );
1725 assert( !
isInUse( localObjectHandle ) || \
1735 status = dispatchMessage( localObjectHandle, &enqueuedMessageData,
1736 objectInfoPtr, aclPtr );
1749 dequeueAllMessages( localObjectHandle );
1760 dequeueAllMessages( localObjectHandle );
1764 ENSURES( iterationCount < FAILSAFE_ITERATIONS_LARGE );