Bug 202593 NSS does not lock non-threadsafe modules correctly.

Consolidate one lock for non-thread safe modules (not one per slot).
This commit is contained in:
relyea%netscape.com 2003-04-19 00:03:13 +00:00
Родитель a9e38dd35c
Коммит 0d76497e84
3 изменённых файлов: 49 добавлений и 7 удалений

Просмотреть файл

@ -41,7 +41,7 @@
*/
#ifdef DEBUG
static const char DEV_CVS_ID[] = "@(#) $RCSfile: dev.h,v $ $Revision: 1.32 $ $Date: 2003-01-30 03:02:55 $ $Name: $";
static const char DEV_CVS_ID[] = "@(#) $RCSfile: dev.h,v $ $Revision: 1.33 $ $Date: 2003-04-19 00:03:13 $ $Name: $";
#endif /* DEBUG */
#ifndef NSSCKT_H
@ -323,6 +323,18 @@ nssSlot_Logout
nssSession *sessionOpt
);
NSS_EXTERN void
nssSlot_EnterMonitor
(
NSSSlot *slot
);
NSS_EXTERN void
nssSlot_ExitMonitor
(
NSSSlot *slot
);
#define NSSSLOT_ASK_PASSWORD_FIRST_TIME -1
#define NSSSLOT_ASK_PASSWORD_EVERY_TIME 0
NSS_EXTERN void

Просмотреть файл

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: devslot.c,v $ $Revision: 1.12 $ $Date: 2002-09-06 00:27:37 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: devslot.c,v $ $Revision: 1.13 $ $Date: 2003-04-19 00:03:13 $ $Name: $";
#endif /* DEBUG */
#ifndef NSSCKEPV_H
@ -76,6 +76,7 @@ struct NSSSlotStr
CK_FLAGS ckFlags; /* from CK_SLOT_INFO.flags */
struct nssSlotAuthInfoStr authInfo;
PRIntervalTime lastTokenPing;
PZLock *lock;
#ifdef NSS_3_4_CODE
PK11SlotInfo *pk11slot;
#endif
@ -151,6 +152,9 @@ nssSlot_Create
if (!rvSlot->base.lock) {
goto loser;
}
if (!nssModule_IsThreadSafe(parent)) {
rvSlot->lock = nssModule_GetLock(parent);
}
rvSlot->module = parent; /* refs go from module to slots */
rvSlot->slotID = slotID;
rvSlot->ckFlags = slotInfo.flags;
@ -190,6 +194,22 @@ nssSlot_Destroy
return PR_SUCCESS;
}
void
nssSlot_EnterMonitor(NSSSlot *slot)
{
if (slot->lock) {
PZ_Lock(slot->lock);
}
}
void
nssSlot_ExitMonitor(NSSSlot *slot)
{
if (slot->lock) {
PZ_Unlock(slot->lock);
}
}
NSS_IMPLEMENT void
NSSSlot_Destroy
(
@ -274,7 +294,9 @@ nssSlot_IsTokenPresent
if (!epv) {
return PR_FALSE;
}
nssSlot_EnterMonitor(slot);
ckrv = CKAPI(epv)->C_GetSlotInfo(slot->slotID, &slotInfo);
nssSlot_ExitMonitor(slot);
if (ckrv != CKR_OK) {
slot->token->base.name[0] = 0; /* XXX */
return PR_FALSE;
@ -772,9 +794,9 @@ nssSlot_CreateSession
if (!rvSession) {
return (nssSession *)NULL;
}
if (!nssModule_IsThreadSafe(slot->module)) {
/* If the parent module is not threadsafe, create lock to manage
* session within threads.
if (nssModule_IsThreadSafe(slot->module)) {
/* If the parent module is not threadsafe,
* create lock to protect just this session.
*/
rvSession->lock = PZ_NewLock(nssILockOther);
if (!rvSession->lock) {
@ -785,7 +807,12 @@ nssSlot_CreateSession
}
return (nssSession *)NULL;
}
rvSession->ownLock = PR_TRUE;
} else {
rvSession->lock = slot->lock;
rvSession->ownLock = PR_FALSE;
}
rvSession->handle = handle;
rvSession->slot = slot;
rvSession->isRW = readWrite;
@ -802,7 +829,7 @@ nssSession_Destroy
if (s) {
void *epv = s->slot->epv;
ckrv = CKAPI(epv)->C_CloseSession(s->handle);
if (s->lock) {
if (s->ownLock && s->lock) {
PZ_DestroyLock(s->lock);
}
nss_ZFreeIf(s);

Просмотреть файл

@ -35,7 +35,7 @@
#define DEVT_H
#ifdef DEBUG
static const char DEVT_CVS_ID[] = "@(#) $RCSfile: devt.h,v $ $Revision: 1.17 $ $Date: 2002-04-18 17:29:54 $ $Name: $";
static const char DEVT_CVS_ID[] = "@(#) $RCSfile: devt.h,v $ $Revision: 1.18 $ $Date: 2003-04-19 00:03:13 $ $Name: $";
#endif /* DEBUG */
/*
@ -96,6 +96,7 @@ struct NSSTokenStr
NSSTrustDomain *trustDomain;
PRIntervalTime lastTime;
nssTokenObjectCache *cache;
PZLock *lock;
#ifdef NSS_3_4_CODE
PK11SlotInfo *pk11slot;
#endif
@ -124,6 +125,7 @@ struct NSSSlotStr
CK_FLAGS ckFlags; /* from CK_SLOT_INFO.flags */
struct nssSlotAuthInfoStr authInfo;
PRIntervalTime lastTokenPing;
PZLock *lock;
#ifdef NSS_3_4_CODE
void *epv;
PK11SlotInfo *pk11slot;
@ -136,6 +138,7 @@ struct nssSessionStr
CK_SESSION_HANDLE handle;
NSSSlot *slot;
PRBool isRW;
PRBool ownLock;
};
typedef enum {