NSS_IMPLEMENT NSSCKFWToken * nssCKFWToken_Create
NSS_IMPLEMENT CK_STATE NSSCKFWSession_GetSessionState
NSS_IMPLEMENT NSSCKFWToken *nssCKFWToken_Create(  NSSCKFWSlot *fwSlot,  NSSCKMDToken *mdToken,  CK_RV *pError){  NSSArena *arena = (NSSArena *)NULL;  NSSCKFWToken *fwToken = (NSSCKFWToken *)NULL;  CK_BBOOL called_setup = CK_FALSE;  /*   * We have already verified the arguments in nssCKFWSlot_GetToken.   */  arena = NSSArena_Create();  if( (NSSArena *)NULL == arena ) {    *pError = CKR_HOST_MEMORY;    goto loser;  }  fwToken = nss_ZNEW(arena, NSSCKFWToken);  if( (NSSCKFWToken *)NULL == fwToken ) {    *pError = CKR_HOST_MEMORY;    goto loser;  }      fwToken->arena = arena;  fwToken->mdToken = mdToken;  fwToken->fwSlot = fwSlot;  fwToken->fwInstance = nssCKFWSlot_GetFWInstance(fwSlot);  fwToken->mdInstance = nssCKFWSlot_GetMDInstance(fwSlot);  fwToken->state = CKS_RO_PUBLIC_SESSION; /* some default */  fwToken->sessionCount = 0;  fwToken->rwSessionCount = 0;  fwToken->mutex = nssCKFWInstance_CreateMutex(fwToken->fwInstance, arena, pError);  if( (NSSCKFWMutex *)NULL == fwToken->mutex ) {    if( CKR_OK == *pError ) {      *pError = CKR_GENERAL_ERROR;    }    goto loser;  }  fwToken->sessions = nssCKFWHash_Create(fwToken->fwInstance, arena, pError);  if( (nssCKFWHash *)NULL == fwToken->sessions ) {    if( CKR_OK == *pError ) {      *pError = CKR_GENERAL_ERROR;    }    goto loser;  }  if( CK_TRUE != nssCKFWInstance_GetModuleHandlesSessionObjects(                   fwToken->fwInstance) ) {    fwToken->sessionObjectHash = nssCKFWHash_Create(fwToken->fwInstance,                                    arena, pError);    if( (nssCKFWHash *)NULL == fwToken->sessionObjectHash ) {      if( CKR_OK == *pError ) {        *pError = CKR_GENERAL_ERROR;      }      goto loser;    }  }  fwToken->mdObjectHash = nssCKFWHash_Create(fwToken->fwInstance,                             arena, pError);  if( (nssCKFWHash *)NULL == fwToken->mdObjectHash ) {    if( CKR_OK == *pError ) {      *pError = CKR_GENERAL_ERROR;    }    goto loser;  }  /* More here */  if( (void *)NULL != (void *)mdToken->Setup ) {    *pError = mdToken->Setup(mdToken, fwToken, fwToken->mdInstance, fwToken->fwInstance);    if( CKR_OK != *pError ) {      goto loser;    }  }  called_setup = CK_TRUE;#ifdef DEBUG  *pError = token_add_pointer(fwToken);  if( CKR_OK != *pError ) {    goto loser;  }#endif /* DEBUG */  *pError = CKR_OK;  return fwToken; loser:  if( CK_TRUE == called_setup ) {    if( (void *)NULL != (void *)mdToken->Invalidate ) {      mdToken->Invalidate(mdToken, fwToken, fwToken->mdInstance, fwToken->fwInstance);    }  }  if( (NSSArena *)NULL != arena ) {    (void)NSSArena_Destroy(arena);  }  return (NSSCKFWToken *)NULL;}