cryptlib  3.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
kernel.h
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * cryptlib Kernel Header File *
4 * Copyright Peter Gutmann 1992-2005 *
5 * *
6 ****************************************************************************/
7 
8 #ifndef _KERNEL_DEFINED
9 
10 #define _KERNEL_DEFINED
11 
12 #if defined( INC_ALL )
13  #include "thread.h"
14 #else
15  #include "kernel/thread.h"
16 #endif /* Compiler-specific includes */
17 
18 /* RAY and EGON look over code.
19 
20  EGON: The structure of this kernel is exactly like the kind of telemetry
21  tracker that NASA uses to secure dead pulsars in deep space.
22 
23  RAY: All message dispatch mechanisms and callback functions.
24 
25  PETER (to other jailbirds): Everyone getting this so far? So what? I
26  guess they just don't make them like they used to.
27 
28  RAY: No! Nobody ever made them like this! The architect was either a
29  certified genius or an authentic wacko! */
30 
31 /* "There is a fine line between genius and insanity.
32  I have erased this line" - Oscar Levant
33  (or "Nullum magnum ingenium sine mixtura dementiae" if you want it in
34  the usual style) */
35 
36 /****************************************************************************
37 * *
38 * Parameter Checking Macros *
39 * *
40 ****************************************************************************/
41 
42 /* Macros to perform validity checks on objects and handles. These checks
43  are:
44 
45  isValidHandle(): Whether a handle is a valid index into the object table.
46  isValidObject(): Whether a handle refers to an object in the table.
47  isFreeObject(): Whether a handle refers to an empty entry in the table.
48  isInternalObject(): Whether an object is an internal object.
49  isInvalidObjectState(): Whether an object is in an invalid (error) state.
50  isInUse(): Whether an object is currently in use (processing a message).
51  isObjectOwner(): If inUse == TRUE, whether this thread is the one using
52  the object.
53  isInHighState(): Whether an object is in the 'high' security state.
54  isSameOwningObject(): Whether two objects have the same owner. We also
55  have to handle the situation where the first object
56  is a user object, in which case it has to be the
57  owner of the second object.
58  isObjectAccessValid(): Internal/external object access check.
59  isValidMessage(): Whether a message type is valid.
60  isInternalMessage(): Whether a message is an internal message.
61  isValidType(): Whether an object type is valid
62  isValidSubtype(): Whether an object subtype is allowed based on access
63  bitflags */
64 
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 ) )
100 
101 /* The set of object checks is used frequently enough that we combine them
102  into a composite check that performs all of the checks in one place */
103 
104 #define fullObjectCheck( objectHandle, message ) \
105  ( isValidObject( objectHandle ) && \
106  isObjectAccessValid( objectHandle, message ) && \
107  checkObjectOwnership( objectTable[ objectHandle ] ) )
108 
109 /* Macros to test whether a message falls into a certain class. These tests
110  are:
111 
112  isParamMessage(): Whether a message contains an object as a parameter */
113 
114 #define isParamMessage( message ) \
115  ( ( message ) == MESSAGE_CRT_SIGN || \
116  ( message ) == MESSAGE_CRT_SIGCHECK )
117 
118 /* Macros to manage object ownership, if the OS supports it */
119 
120 #define checkObjectOwnership( objectPtr ) \
121  ( !( ( objectPtr ).flags & OBJECT_FLAG_OWNED ) || \
122  THREAD_SAME( ( objectPtr ).objectOwner, THREAD_SELF() ) )
123 
124 /* A macro to turn an abnormal status indicated in an object's flags into a
125  status code. The values are prioritised so that notinited > signalled >
126  busy */
127 
128 #define getObjectStatusValue( flags ) \
129  ( ( flags & OBJECT_FLAG_NOTINITED ) ? CRYPT_ERROR_NOTINITED : \
130  ( flags & OBJECT_FLAG_SIGNALLED ) ? CRYPT_ERROR_SIGNALLED : CRYPT_OK )
131 
132 /****************************************************************************
133 * *
134 * Object Definitions and Information *
135 * *
136 ****************************************************************************/
137 
138 /* The information maintained by the kernel for each object */
139 
140 typedef struct {
141  /* Object type and value */
142  OBJECT_TYPE type; /* Object type */
143  OBJECT_SUBTYPE subType; /* Object subtype */
144  void *objectPtr; /* Object data */
145  int objectSize; /* Object data size */
146 
147  /* Object properties */
148  int flags; /* Internal-only, locked, etc */
149  int actionFlags; /* Permitted actions */
150  int referenceCount; /* Number of references to this object */
151  int lockCount; /* Message-processing lock recursion count */
152 #ifdef USE_THREADS
153  THREAD_HANDLE lockOwner; /* Lock owner if lockCount > 0 */
154 #endif /* USE_THREADS */
155  int uniqueID; /* Unique ID for this object */
156 /* time_t lastAccess; // Last access time */
157 
158  /* Object security properties */
159  int forwardCount; /* Number of times ownership can be transferred */
160  int usageCount; /* Number of times obj.can be used */
161 #ifdef USE_THREADS
162  THREAD_HANDLE objectOwner; /* The object's owner */
163 #endif /* USE_THREADS */
164 
165  /* Object methods */
166  MESSAGE_FUNCTION messageFunction; /* The object's message handler */
167 
168  /* Owning and dependent objects */
169  CRYPT_USER owner; /* Owner object handle */
170  CRYPT_HANDLE dependentObject; /* Dependent object (context or cert) */
171  CRYPT_HANDLE dependentDevice; /* Dependent crypto device */
172  } OBJECT_INFO;
173 
174 /* The flags that apply to each object in the table */
175 
176 #define OBJECT_FLAG_NONE 0x0000 /* Non-flag */
177 #define OBJECT_FLAG_INTERNAL 0x0001 /* Internal-use only */
178 #define OBJECT_FLAG_NOTINITED 0x0002 /* Still being initialised */
179 #define OBJECT_FLAG_HIGH 0x0004 /* In 'high' security state */
180 #define OBJECT_FLAG_SIGNALLED 0x0008 /* In signalled state */
181 #define OBJECT_FLAG_SECUREMALLOC 0x0010 /* Uses secure memory */
182 #define OBJECT_FLAG_OWNED 0x0020 /* Object is bound to a thread */
183 #define OBJECT_FLAG_ATTRLOCKED 0x0040 /* Security properties can't be modified */
184 
185 /* The flags that convey information about an object's status */
186 
187 #define OBJECT_FLAGMASK_STATUS \
188  ( OBJECT_FLAG_NOTINITED | OBJECT_FLAG_SIGNALLED )
189 
190 /****************************************************************************
191 * *
192 * Kernel Data Structures *
193 * *
194 ****************************************************************************/
195 
196 /* The object allocation state data. This controls the allocation of
197  handles to newly-created objects. The first NO_SYSTEM_OBJECTS handles
198  are system objects that exist with fixed handles, the remainder are
199  allocated pseudorandomly under the control of an LFSR */
200 
201 typedef struct {
202  long lfsrMask, lfsrPoly; /* LFSR state values */
203  int objectHandle; /* Current object handle */
205 
206 /* A structure to store the details of a message sent to an object, and the
207  size of the message queue. This defines the maximum nesting depth of
208  messages sent by an object. Because of the way krnlSendMessage() handles
209  message processing, it's extremely difficult to ever have more than two
210  or three messages in the queue unless an object starts recursively
211  sending itself messages */
212 
213 typedef struct {
214  int objectHandle; /* Handle to send message to */
215  const void *handlingInfoPtr;/* Message handling info */
217  const void *messageDataPtr;
218  int messageValue; /* Message parameters */
220 
221 #define MESSAGE_QUEUE_SIZE 16
222 
223 /* Semaphores are one-shots, so that once set and cleared they can't be
224  reset. This is handled by enforcing the following state transitions:
225 
226  Uninited -> Set | Clear
227  Set -> Set | Clear
228  Clear -> Clear
229 
230  The handling is complicated somewhat by the fact that on some systems the
231  semaphore has to be explicitly deleted, but only the last thread to use
232  it can safely delete it. In order to handle this, we reference-count the
233  semaphore and let the last thread out delete it. In order to do this we
234  introduce an additional state, preClear, which indicates that while the
235  semaphore object is still present, the last thread out should delete it,
236  bringing it to the true clear state */
237 
238 typedef enum {
244  } SEMAPHORE_STATE;
245 
246 typedef struct {
247  SEMAPHORE_STATE state; /* Semaphore state */
248  MUTEX_HANDLE object; /* Handle to system synchronisation object */
249  int refCount; /* Reference count for handle */
250  } SEMAPHORE_INFO;
251 
252 /* A structure to store the details of a thread */
253 
254 typedef struct {
255  THREAD_FUNCTION threadFunction; /* Function to call from thread */
256  THREAD_PARAMS threadParams; /* Thread function parameters */
257  SEMAPHORE_TYPE semaphore; /* Optional semaphore to set */
258  MUTEX_HANDLE syncHandle; /* Handle to use for thread sync */
259  } THREAD_INFO;
260 
261 /* When the kernel starts up and closes down it does so in a multi-stage
262  process that's equivalent to Unix runlevels. For the startup at the
263  first level the kernel data block and all kernel-level primitive
264  objects like mutexes have been initialised.
265 
266  For the shutdown, at the first level all internal worker threads/tasks
267  must exist. At the next level all messages to objects except destroy
268  messages fail. At the final level all kernel-managed primitives such as
269  mutexes and semaphores are no longer available */
270 
271 typedef enum {
272  INIT_LEVEL_NONE, /* Uninitialised */
273  INIT_LEVEL_KRNLDATA, /* Kernel data block initialised */
274  INIT_LEVEL_FULL, /* Full initialisation */
275  INIT_LEVEL_LAST /* Last possible init level */
276  } INIT_LEVEL;
277 
278 typedef enum {
279  SHUTDOWN_LEVEL_NONE, /* Normal operation */
280  SHUTDOWN_LEVEL_THREADS, /* Internal threads must exit */
281  SHUTDOWN_LEVEL_MESSAGES, /* Only destroy messages are valid */
282  SHUTDOWN_LEVEL_MUTEXES, /* Kernel objects become invalid */
283  SHUTDOWN_LEVEL_ALL, /* Complete shutdown */
284  SHUTDOWN_LEVEL_LAST /* Last possible shutdown level */
285  } SHUTDOWN_LEVEL;
286 
287 /* The kernel data block, containing all variables used by the kernel. With
288  the exception of the special-case values at the start, all values in this
289  block should be set to use zero/NULL as their ground state (for example a
290  boolean variable should have a ground state of FALSE (zero) rather than
291  TRUE (nonzero)).
292 
293  If the objectTable giant lock (or more strictly speaking monolithic lock,
294  since the kernel's message-handling is designed to be straight-line code
295  and so never blocks for any amount of time like the Linux giant lock can)
296  ever proves to be a problem then the solution would be to use lock
297  striping, dividing the load of the object table across NO_TABLE_LOCKS
298  locks. This gets a bit tricky because the object table is dynamically
299  resizeable, a basic mod_NO_TABLE_LOCKS strategy where every n-th entry
300  uses the same lock works but then we'd still need a giant lock to check
301  whether the table is being resized. To avoid this we can use a lock-free
302  implementation that operates by acquiring each lock (to make sure we have
303  complete control of the table), checking whether another thread beat us to
304  it, and if not resizing the table. The pseudocode for this is as
305  follows:
306 
307  // Remember the original table size
308  const int oldSize = krnlData->objectTableSize;
309 
310  // Acquire each lock
311  for( i = 0; i < NO_LOCKS; i++ )
312  THREAD_LOCK( krnlData->locks[ i ] );
313 
314  // Check whether another thread beat us to the resize while we were
315  // acquiring locks
316  if( krnlData->objectTableSize != oldSize )
317  {
318  // Unlock all the locks
319  // ... //
320  return;
321  }
322 
323  // We hold all the locks and therefore have exclusive control of the
324  // table, resize it
325  // ... //
326 
327  // Release each lock again //
328  for( i = 0; i < NO_LOCKS; i++ )
329  THREAD_UNLOCK( krnlData->locks[ i ] );
330 
331  This is a conventional lock-free implementation of such an algorithm but
332  is conceptually ugly in that it accesses protected data outside the lock,
333  which will cause concurrency-checking tools to complain. Until the fast-
334  path through the kernel actually becomes a real bottleneck it's probably
335  best to leave well enough alone */
336 
337 typedef struct {
338  /* The kernel initialisation state and a lock to protect it. The
339  lock and shutdown level value are handled externally and aren't
340  cleared when the kernel data block as a whole is cleared. Note
341  that the shutdown level has to be before the lock so that we can
342  statically initialise the data with '{ 0 }', which won't work if
343  the lock data is non-scalar */
344  SHUTDOWN_LEVEL shutdownLevel; /* Kernel shutdown level */
345 #ifdef USE_THREADS
346  MUTEX_DECLARE_STORAGE( initialisation );
347 #endif /* USE_THREADS */
348  /* Everything from this point on is cleared at init and shutdown */
349  int initLevel; /* Kernel initialisation level */
350 
351  /* The kernel object table and object table management info */
352  OBJECT_INFO *objectTable; /* Pointer to object table */
353  int objectTableSize; /* Current table size */
354  int objectUniqueID; /* Unique ID for next object */
355  OBJECT_STATE_INFO objectStateInfo; /* Object allocation state */
356 #ifdef USE_THREADS
357  MUTEX_DECLARE_STORAGE( objectTable );
358 #endif /* USE_THREADS */
359 
360  /* The kernel message dispatcher queue */
361  BUFFER( MESSAGE_QUEUE_SIZE, queueEnd ) \
362  MESSAGE_QUEUE_DATA messageQueue[ MESSAGE_QUEUE_SIZE + 8 ];
363  int queueEnd; /* Points past last queue element */
364 
365  /* The kernel semaphores */
367  SEMAPHORE_INFO semaphoreInfo[ SEMAPHORE_LAST + 8 ];
368 #ifdef USE_THREADS
370 #endif /* USE_THREADS */
371 
372  /* The kernel mutexes. Since mutexes usually aren't scalar values and
373  are declared and accessed via macros that manipulate various fields,
374  we have to declare a pile of them individually rather than using an
375  array of mutexes */
376 #ifdef USE_THREADS
377  MUTEX_DECLARE_STORAGE( mutex1 );
378  MUTEX_DECLARE_STORAGE( mutex2 );
379  MUTEX_DECLARE_STORAGE( mutex3);
380 #endif /* USE_THREADS */
381 
382  /* The kernel thread data */
383 #ifdef USE_THREADS
384  THREAD_INFO threadInfo;
385 #endif /* USE_THREADS */
386 
387  /* The kernel secure memory list and a lock to protect it */
388  void *allocatedListHead, *allocatedListTail;
389 #ifdef USE_THREADS
390  MUTEX_DECLARE_STORAGE( allocation );
391 #endif /* USE_THREADS */
392 
393  /* A marker for the end of the kernel data, used during init/shutdown */
395  } KERNEL_DATA;
396 
397 /* When we start up and shut down the kernel, we need to clear the kernel
398  data. However, the init lock may have been set by an external management
399  function, so we can't clear that part of the kernel data. In addition,
400  on shutdown the shutdown level value must stay set so that any threads
401  still running will be forced to exit at the earliest possible instance,
402  and remain set after the shutdown has completed. To handle this, we use
403  the following macro to clear only the appropriate area of the kernel data
404  block */
405 
406 #define CLEAR_KERNEL_DATA() \
407  assert( &krnlDataBlock.endMarker - \
408  &krnlDataBlock.initLevel < sizeof( krnlDataBlock ) ); \
409  zeroise( ( void * ) ( &krnlDataBlock.initLevel ), \
410  &krnlDataBlock.endMarker - &krnlDataBlock.initLevel )
411 
412 /****************************************************************************
413 * *
414 * ACL Functions *
415 * *
416 ****************************************************************************/
417 
418 /* Prototypes for functions in certm_acl.c */
419 
421 int preDispatchCheckCertMgmtAccess( IN_HANDLE const int objectHandle,
423  IN_BUFFER_C( sizeof( MESSAGE_CERTMGMT_INFO ) ) \
424  const void *messageDataPtr,
425  IN_ENUM( CRYPT_CERTACTION ) \
426  const int messageValue,
427  STDC_UNUSED const void *dummy );
428 
429 /* Prototypes for functions in key_acl.c */
430 
432 int preDispatchCheckKeysetAccess( IN_HANDLE const int objectHandle,
433  IN_MESSAGE const MESSAGE_TYPE message,
434  IN_BUFFER_C( sizeof( MESSAGE_KEYMGMT_INFO ) ) \
435  const void *messageDataPtr,
436  IN_ENUM( KEYMGMT_ITEM ) const int messageValue,
437  STDC_UNUSED const void *dummy );
438 
439 /* Prototypes for functions in mech_acl.c */
440 
442 int preDispatchCheckMechanismWrapAccess( IN_HANDLE const int objectHandle,
443  IN_MESSAGE const MESSAGE_TYPE message,
444  IN_BUFFER_C( sizeof( MECHANISM_WRAP_INFO ) ) \
446  const void *messageDataPtr,
447  IN_ENUM( MECHANISM ) const int messageValue,
448  STDC_UNUSED const void *dummy );
450 int preDispatchCheckMechanismSignAccess( IN_HANDLE const int objectHandle,
451  IN_MESSAGE const MESSAGE_TYPE message,
452  IN_BUFFER_C( sizeof( MECHANISM_SIGN_INFO ) ) \
454  const void *messageDataPtr,
455  IN_ENUM( MECHANISM ) const int messageValue,
456  STDC_UNUSED const void *dummy );
458 int preDispatchCheckMechanismDeriveAccess( IN_HANDLE const int objectHandle,
459  IN_MESSAGE const MESSAGE_TYPE message,
460  IN_BUFFER_C( sizeof( MECHANISM_DERIVE_INFO ) ) \
462  const void *messageDataPtr,
463  IN_ENUM( MECHANISM ) const int messageValue,
464  STDC_UNUSED const void *dummy );
466 int preDispatchCheckMechanismKDFAccess( IN_HANDLE const int objectHandle,
467  IN_MESSAGE const MESSAGE_TYPE message,
468  IN_BUFFER_C( sizeof( MECHANISM_KDF_INFO ) ) \
470  const void *messageDataPtr,
471  IN_ENUM( MECHANISM ) const int messageValue,
472  STDC_UNUSED const void *dummy );
473 
474 /* Prototypes for functions in msg_acl.c */
475 
476 CHECK_RETVAL \
477 int preDispatchSignalDependentObjects( IN_HANDLE const int objectHandle,
479  STDC_UNUSED const void *dummy2,
480  STDC_UNUSED const int dummy3,
481  STDC_UNUSED const void *dummy4 );
483 int preDispatchCheckAttributeAccess( IN_HANDLE const int objectHandle,
484  IN_MESSAGE const MESSAGE_TYPE message,
485  IN_OPT const void *messageDataPtr,
486  IN_ATTRIBUTE const int messageValue,
487  IN TYPECAST( ATTRIBUTE_ACL * ) \
488  const void *auxInfo );
489 CHECK_RETVAL \
490 int preDispatchCheckCompareParam( IN_HANDLE const int objectHandle,
491  IN_MESSAGE const MESSAGE_TYPE message,
492  const void *messageDataPtr,
493  IN_ENUM( MESSAGE_COMPARE ) const int messageValue,
494  STDC_UNUSED const void *dummy2 );
495 CHECK_RETVAL \
496 int preDispatchCheckCheckParam( IN_HANDLE const int objectHandle,
497  IN_MESSAGE const MESSAGE_TYPE message,
498  STDC_UNUSED const void *dummy1,
499  IN_ENUM( MESSAGE_CHECK ) const int messageValue,
500  STDC_UNUSED const void *dummy2 );
501 CHECK_RETVAL \
502 int preDispatchCheckActionAccess( IN_HANDLE const int objectHandle,
503  IN_MESSAGE const MESSAGE_TYPE message,
504  STDC_UNUSED const void *dummy1,
505  STDC_UNUSED const int dummy2,
506  STDC_UNUSED const void *dummy3 );
507 CHECK_RETVAL \
508 int preDispatchCheckState( IN_HANDLE const int objectHandle,
509  IN_MESSAGE const MESSAGE_TYPE message,
510  STDC_UNUSED const void *dummy1,
511  STDC_UNUSED const int dummy2,
512  STDC_UNUSED const void *dummy3 );
513 CHECK_RETVAL \
514 int preDispatchCheckParamHandleOpt( IN_HANDLE const int objectHandle,
515  IN_MESSAGE const MESSAGE_TYPE message,
516  STDC_UNUSED const void *dummy1,
517  const int messageValue,
518  IN TYPECAST( MESSAGE_ACL * ) \
519  const void *auxInfo );
520 CHECK_RETVAL \
521 int preDispatchCheckStateParamHandle( IN_HANDLE const int objectHandle,
522  IN_MESSAGE const MESSAGE_TYPE message,
523  STDC_UNUSED const void *dummy1,
524  const int messageValue,
525  IN TYPECAST( MESSAGE_ACL * ) \
526  const void *auxInfo );
527 CHECK_RETVAL \
528 int preDispatchCheckExportAccess( IN_HANDLE const int objectHandle,
529  IN_MESSAGE const MESSAGE_TYPE message,
530  const void *messageDataPtr,
531  IN_ENUM( CRYPT_CERTFORMAT ) const int messageValue,
532  STDC_UNUSED const void *dummy2 );
534 int preDispatchCheckData( IN_HANDLE const int objectHandle,
535  IN_MESSAGE const MESSAGE_TYPE message,
536  IN_BUFFER_C( sizeof( MESSAGE_DATA ) ) \
537  const void *messageDataPtr,
538  STDC_UNUSED const int dummy1,
539  STDC_UNUSED const void *dummy2 );
541 int preDispatchCheckCreate( IN_HANDLE const int objectHandle,
542  IN_MESSAGE const MESSAGE_TYPE message,
544  const void *messageDataPtr,
545  IN_ENUM( OBJECT ) const int messageValue,
546  STDC_UNUSED const void *dummy );
547 CHECK_RETVAL \
548 int preDispatchCheckUserMgmtAccess( IN_HANDLE const int objectHandle,
549  IN_MESSAGE const MESSAGE_TYPE message,
550  STDC_UNUSED const void *dummy1,
551  IN_ENUM( MESSAGE_USERMGMT ) const int messageValue,
552  STDC_UNUSED const void *dummy2 );
553 CHECK_RETVAL \
554 int preDispatchCheckTrustMgmtAccess( IN_HANDLE const int objectHandle,
555  IN_MESSAGE const MESSAGE_TYPE message,
556  const void *messageDataPtr,
557  STDC_UNUSED const int messageValue,
558  STDC_UNUSED const void *dummy );
559 CHECK_RETVAL \
561  IN_MESSAGE const MESSAGE_TYPE message,
562  const void *messageDataPtr,
563  const int messageValue,
564  const void *auxInfo );
565 CHECK_RETVAL \
566 int postDispatchForwardToDependentObject( IN_HANDLE const int objectHandle,
567  IN_MESSAGE const MESSAGE_TYPE message,
568  STDC_UNUSED const void *dummy1,
569  IN_ENUM( MESSAGE_CHECK ) const int messageValue,
570  STDC_UNUSED const void *dummy2 );
571 CHECK_RETVAL \
572 int postDispatchUpdateUsageCount( IN_HANDLE const int objectHandle,
573  STDC_UNUSED const MESSAGE_TYPE dummy1,
574  STDC_UNUSED const void *dummy2,
575  STDC_UNUSED const int dummy3,
576  STDC_UNUSED const void *dummy4 );
577 CHECK_RETVAL \
578 int postDispatchChangeState( IN_HANDLE const int objectHandle,
579  STDC_UNUSED const MESSAGE_TYPE dummy1,
580  STDC_UNUSED const void *dummy2,
581  STDC_UNUSED const int dummy3,
582  STDC_UNUSED const void *dummy4 );
583 CHECK_RETVAL \
584 int postDispatchChangeStateOpt( IN_HANDLE const int objectHandle,
585  STDC_UNUSED const MESSAGE_TYPE dummy1,
586  STDC_UNUSED const void *dummy2,
587  const int messageValue,
588  IN TYPECAST( ATTRIBUTE_ACL * ) const void *auxInfo );
589 CHECK_RETVAL \
590 int postDispatchHandleZeroise( IN_HANDLE const int objectHandle,
591  IN_MESSAGE const MESSAGE_TYPE message,
592  STDC_UNUSED const void *dummy2,
593  IN_ENUM( MESSAGE_USERMGMT ) const int messageValue,
594  STDC_UNUSED const void *dummy3 );
595 
596 /****************************************************************************
597 * *
598 * Kernel Functions *
599 * *
600 ****************************************************************************/
601 
602 /* Prototypes for functions in attr_acl.c */
603 
604 CHECK_RETVAL_PTR \
606  const BOOLEAN isInternalMessage );
607 
608 /* Prototypes for functions in int_msg.c */
609 
611 int getPropertyAttribute( IN_HANDLE const int objectHandle,
613  OUT_BUFFER_FIXED_C( sizeof( int ) ) void *messageDataPtr );
615 int setPropertyAttribute( IN_HANDLE const int objectHandle,
616  IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE attribute,
617  IN_BUFFER_C( sizeof( int ) ) void *messageDataPtr );
618 CHECK_RETVAL \
619 int incRefCount( IN_HANDLE const int objectHandle,
620  STDC_UNUSED const int dummy1,
621  STDC_UNUSED const void *dummy2,
622  STDC_UNUSED const BOOLEAN dummy3 );
623 CHECK_RETVAL \
624 int decRefCount( IN_HANDLE const int objectHandle,
625  STDC_UNUSED const int dummy1,
626  STDC_UNUSED const void *dummy2,
627  const BOOLEAN isInternal );
629 int getDependentObject( IN_HANDLE const int objectHandle,
630  const int targetType,
631  IN_BUFFER_C( sizeof( int ) ) \
632  const void *messageDataPtr,
633  /* This is a bit of a lie since we actually
634  return the dependent object through this
635  pointer, however making it non-const means
636  that we'd have to also un-const every other
637  use of this parameter in all other functions
638  accessed via this function pointer */
639  STDC_UNUSED const BOOLEAN dummy );
641 int setDependentObject( IN_HANDLE const int objectHandle,
642  IN_ENUM( SETDEP_OPTION ) const int option,
643  IN_BUFFER_C( sizeof( int ) ) \
644  const void *messageDataPtr,
645  STDC_UNUSED const BOOLEAN dummy );
646 CHECK_RETVAL \
647 int cloneObject( IN_HANDLE const int objectHandle,
648  IN_HANDLE const int clonedObject,
649  STDC_UNUSED const void *dummy1,
650  STDC_UNUSED const BOOLEAN dummy2 );
651 
652 /* Prototypes for functions in sendmsg.c */
653 
654 CHECK_RETVAL \
655 int checkTargetType( IN_HANDLE const int objectHandle, const long targets );
656 CHECK_RETVAL \
657 int findTargetType( IN_HANDLE const int originalObjectHandle,
658  const long targets );
660 int waitForObject( IN_HANDLE const int objectHandle,
662 
663 /* Prototypes for functions in objects.c */
664 
665 CHECK_RETVAL \
666 int destroyObjectData( IN_HANDLE const int objectHandle );
667 CHECK_RETVAL \
668 int destroyObjects( void );
669 
670 /* Prototypes for functions in semaphore.c */
671 
672 void setSemaphore( IN_ENUM( SEMAPHORE ) const SEMAPHORE_TYPE semaphore,
673  const MUTEX_HANDLE object );
674 void clearSemaphore( IN_ENUM( SEMAPHORE ) const SEMAPHORE_TYPE semaphore );
675 
676 /* Init/shutdown functions for each kernel module */
677 
679 int initAllocation( INOUT KERNEL_DATA *krnlDataPtr );
680 void endAllocation( void );
682 int initAttributeACL( INOUT KERNEL_DATA *krnlDataPtr );
683 void endAttributeACL( void );
685 int initCertMgmtACL( INOUT KERNEL_DATA *krnlDataPtr );
686 void endCertMgmtACL( void );
688 int initInternalMsgs( INOUT KERNEL_DATA *krnlDataPtr );
689 void endInternalMsgs( void );
691 int initKeymgmtACL( INOUT KERNEL_DATA *krnlDataPtr );
692 void endKeymgmtACL( void );
694 int initMechanismACL( INOUT KERNEL_DATA *krnlDataPtr );
695 void endMechanismACL( void );
697 int initMessageACL( INOUT KERNEL_DATA *krnlDataPtr );
698 void endMessageACL( void );
700 int initObjects( INOUT KERNEL_DATA *krnlDataPtr );
701 void endObjects( void );
703 int initObjectAltAccess( INOUT KERNEL_DATA *krnlDataPtr );
704 void endObjectAltAccess( void );
706 int initSemaphores( INOUT KERNEL_DATA *krnlDataPtr );
707 void endSemaphores( void );
709 int initSendMessage( INOUT KERNEL_DATA *krnlDataPtr );
710 void endSendMessage( void );
711 
712 #endif /* _KERNEL_DEFINED */