8 #ifndef _KERNEL_DEFINED
10 #define _KERNEL_DEFINED
12 #if defined( INC_ALL )
65 #define isValidHandle( handle ) \
66 ( ( handle ) >= 0 && ( handle ) < krnlData->objectTableSize )
67 #define isValidObject( handle ) \
68 ( isValidHandle( handle ) && \
69 krnlData->objectTable[ ( handle ) ].objectPtr != NULL )
70 #define isFreeObject( handle ) \
71 ( isValidHandle( handle ) && \
72 krnlData->objectTable[ ( handle ) ].objectPtr == NULL )
73 #define isInternalObject( handle ) \
74 ( krnlData->objectTable[ handle ].flags & OBJECT_FLAG_INTERNAL )
75 #define isObjectAccessValid( objectHandle, message ) \
76 !( isInternalObject( objectHandle ) && \
77 !( message & MESSAGE_FLAG_INTERNAL ) )
78 #define isInvalidObjectState( handle ) \
79 ( krnlData->objectTable[ ( handle ) ].flags & OBJECT_FLAGMASK_STATUS )
80 #define isInUse( handle ) \
81 ( krnlData->objectTable[ ( handle ) ].lockCount > 0 )
82 #define isObjectOwner( handle ) \
83 THREAD_SAME( krnlData->objectTable[ ( handle ) ].lockOwner, THREAD_SELF() )
84 #define isInHighState( handle ) \
85 ( krnlData->objectTable[ ( handle ) ].flags & OBJECT_FLAG_HIGH )
86 #define isSameOwningObject( handle1, handle2 ) \
87 ( krnlData->objectTable[ ( handle1 ) ].owner == CRYPT_UNUSED || \
88 krnlData->objectTable[ ( handle2 ) ].owner == CRYPT_UNUSED || \
89 ( krnlData->objectTable[ ( handle1 ) ].owner == \
90 krnlData->objectTable[ ( handle2 ) ].owner ) || \
91 ( ( handle1 ) == krnlData->objectTable[ ( handle2 ) ].owner ) )
92 #define isValidMessage( message ) \
93 ( ( message ) > MESSAGE_NONE && ( message ) < MESSAGE_LAST )
94 #define isInternalMessage( message ) \
95 ( ( message ) & MESSAGE_FLAG_INTERNAL )
96 #define isValidType( type ) \
97 ( ( type ) > OBJECT_TYPE_NONE && ( type ) < OBJECT_TYPE_LAST )
98 #define isValidSubtype( subtypeMask, subtype ) \
99 ( ( ( subtypeMask ) & ( subtype ) ) == ( subtype ) )
104 #define fullObjectCheck( objectHandle, message ) \
105 ( isValidObject( objectHandle ) && \
106 isObjectAccessValid( objectHandle, message ) && \
107 checkObjectOwnership( objectTable[ objectHandle ] ) )
114 #define isParamMessage( message ) \
115 ( ( message ) == MESSAGE_CRT_SIGN || \
116 ( message ) == MESSAGE_CRT_SIGCHECK )
120 #define checkObjectOwnership( objectPtr ) \
121 ( !( ( objectPtr ).flags & OBJECT_FLAG_OWNED ) || \
122 THREAD_SAME( ( objectPtr ).objectOwner, THREAD_SELF() ) )
128 #define getObjectStatusValue( flags ) \
129 ( ( flags & OBJECT_FLAG_NOTINITED ) ? CRYPT_ERROR_NOTINITED : \
130 ( flags & OBJECT_FLAG_SIGNALLED ) ? CRYPT_ERROR_SIGNALLED : CRYPT_OK )
176 #define OBJECT_FLAG_NONE 0x0000
177 #define OBJECT_FLAG_INTERNAL 0x0001
178 #define OBJECT_FLAG_NOTINITED 0x0002
179 #define OBJECT_FLAG_HIGH 0x0004
180 #define OBJECT_FLAG_SIGNALLED 0x0008
181 #define OBJECT_FLAG_SECUREMALLOC 0x0010
182 #define OBJECT_FLAG_OWNED 0x0020
183 #define OBJECT_FLAG_ATTRLOCKED 0x0040
187 #define OBJECT_FLAGMASK_STATUS \
188 ( OBJECT_FLAG_NOTINITED | OBJECT_FLAG_SIGNALLED )
221 #define MESSAGE_QUEUE_SIZE 16
406 #define CLEAR_KERNEL_DATA() \
407 assert( &krnlDataBlock.endMarker - \
408 &krnlDataBlock.initLevel < sizeof( krnlDataBlock ) ); \
409 zeroise( ( void * ) ( &krnlDataBlock.initLevel ), \
410 &krnlDataBlock.endMarker - &krnlDataBlock.initLevel )
421 int preDispatchCheckCertMgmtAccess(
IN_HANDLE const int objectHandle,
432 int preDispatchCheckKeysetAccess(
IN_HANDLE const int objectHandle,
435 const void *messageDataPtr,
442 int preDispatchCheckMechanismWrapAccess(
IN_HANDLE const int objectHandle,
446 const void *messageDataPtr,
450 int preDispatchCheckMechanismSignAccess(
IN_HANDLE const int objectHandle,
454 const void *messageDataPtr,
458 int preDispatchCheckMechanismDeriveAccess(
IN_HANDLE const int objectHandle,
462 const void *messageDataPtr,
466 int preDispatchCheckMechanismKDFAccess(
IN_HANDLE const int objectHandle,
470 const void *messageDataPtr,
483 int preDispatchCheckAttributeAccess(
IN_HANDLE const int objectHandle,
485 IN_OPT const void *messageDataPtr,
488 const void *auxInfo );
492 const void *messageDataPtr,
517 const int messageValue,
519 const void *auxInfo );
524 const int messageValue,
526 const void *auxInfo );
530 const void *messageDataPtr,
531 IN_ENUM( CRYPT_CERTFORMAT )
const int messageValue,
534 int preDispatchCheckData(
IN_HANDLE const int objectHandle,
537 const void *messageDataPtr,
541 int preDispatchCheckCreate(
IN_HANDLE const int objectHandle,
544 const void *messageDataPtr,
545 IN_ENUM( OBJECT )
const int messageValue,
551 IN_ENUM( MESSAGE_USERMGMT )
const int messageValue,
556 const void *messageDataPtr,
562 const void *messageDataPtr,
563 const int messageValue,
564 const void *auxInfo );
587 const int messageValue,
593 IN_ENUM( MESSAGE_USERMGMT )
const int messageValue,
611 int getPropertyAttribute(
IN_HANDLE const int objectHandle,
615 int setPropertyAttribute(
IN_HANDLE const int objectHandle,
617 IN_BUFFER_C(
sizeof(
int ) )
void *messageDataPtr );
629 int getDependentObject(
IN_HANDLE const int objectHandle,
632 const void *messageDataPtr,
641 int setDependentObject(
IN_HANDLE const int objectHandle,
644 const void *messageDataPtr,
658 const long targets );
660 int waitForObject(
IN_HANDLE const int objectHandle,