if (!pk11_getFinalizeModulesOption()) {
if (!pk11_getFinalizeModulesOption() || ((mod->cryptokiVersion.major == 2) && (mod->cryptokiVersion.minor < 1))) {
SECMOD_WaitForAnyTokenEvent(SECMODModule *mod, unsigned long flags,						 PRIntervalTime latency){    CK_SLOT_ID id;    CK_RV crv;    PK11SlotInfo *slot;    if (!pk11_getFinalizeModulesOption()) {        /* if we are sharing the module with other software in our         * address space, we can't reliably use C_WaitForSlotEvent() */	return secmod_HandleWaitForSlotEvent(mod, flags, latency);    }    /* first the the PKCS #11 call */    PZ_Lock(mod->refLock);    if (mod->evControlMask & SECMOD_END_WAIT) {	goto end_wait;    }    mod->evControlMask |= SECMOD_WAIT_PKCS11_EVENT;    PZ_Unlock(mod->refLock);    crv = PK11_GETTAB(mod)->C_WaitForSlotEvent(flags, &id, NULL);    PZ_Lock(mod->refLock);    mod->evControlMask &= ~SECMOD_WAIT_PKCS11_EVENT;    /* if we are in end wait, short circuit now, don't even risk     * going into secmod_HandleWaitForSlotEvent */    if (mod->evControlMask & SECMOD_END_WAIT) {	goto end_wait;    }    PZ_Unlock(mod->refLock);    if (crv == CKR_FUNCTION_NOT_SUPPORTED) {	/* module doesn't support that call, simulate it */	return secmod_HandleWaitForSlotEvent(mod, flags, latency);    }    if (crv != CKR_OK) {	/* we can get this error if finalize was called while we were	 * still running. This is the only way to force a C_WaitForSlotEvent()	 * to return in PKCS #11. In this case, just return that there	 * was no event. */	if (crv == CKR_CRYPTOKI_NOT_INITIALIZED) {	    PORT_SetError(SEC_ERROR_NO_EVENT);	} else {	    PORT_SetError(PK11_MapError(crv));	}	return NULL;    }    slot = SECMOD_FindSlotByID(mod, id);    if (slot == NULL) {	/* possibly a new slot that was added? */	SECMOD_UpdateSlotList(mod);	slot = SECMOD_FindSlotByID(mod, id);    }    /* if we are in the delay period for the "isPresent" call, reset     * the delay since we know things have probably changed... */    if (slot && slot->nssToken && slot->nssToken->slot) {	nssSlot_ResetDelay(slot->nssToken->slot);    }    return slot;    /* must be called with the lock on. */end_wait:    mod->evControlMask &= ~SECMOD_END_WAIT;    PZ_Unlock(mod->refLock);    PORT_SetError(SEC_ERROR_NO_EVENT);    return NULL;}