Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 302769 | Differences between
and this patch

Collapse All | Expand All

(-)src/coolkey/coolkey.cpp (-11 / +25 lines)
Lines 42-48 Link Here
42
42
43
static SlotList *slotList = NULL;
43
static SlotList *slotList = NULL;
44
44
45
static OSLock finalizeLock(false);
45
static OSLock *finalizeLock = NULL;
46
#define FINALIZE_GETLOCK() if (finalizeLock) finalizeLock->getLock();
47
#define FINALIZE_RELEASELOCK() if (finalizeLock) finalizeLock->releaseLock();
46
48
47
static CK_BBOOL initialized = FALSE;
49
static CK_BBOOL initialized = FALSE;
48
static CK_BBOOL finalizing = FALSE;
50
static CK_BBOOL finalizing = FALSE;
Lines 208-218 Link Here
208
    if( initialized ) {
210
    if( initialized ) {
209
        return CKR_CRYPTOKI_ALREADY_INITIALIZED;
211
        return CKR_CRYPTOKI_ALREADY_INITIALIZED;
210
    }
212
    }
211
    if (!finalizeLock.isValid()) {
213
    if (finalizeLock && !finalizeLock->isValid()) {
212
	return CKR_CANT_LOCK;
214
	return CKR_CANT_LOCK;
213
    }
215
    }
214
    CK_C_INITIALIZE_ARGS* initArgs = (CK_C_INITIALIZE_ARGS*) pInitArgs;
216
    CK_C_INITIALIZE_ARGS* initArgs = (CK_C_INITIALIZE_ARGS*) pInitArgs;
217
    OSLock::setThreadSafe(0);
215
    if( initArgs != NULL ) {
218
    if( initArgs != NULL ) {
219
	bool needThreads;
216
	/* work around a bug in NSS where the library parameters are only
220
	/* work around a bug in NSS where the library parameters are only
217
	 * send if locking is requested */
221
	 * send if locking is requested */
218
	if (initArgs->LibraryParameters) {
222
	if (initArgs->LibraryParameters) {
Lines 220-226 Link Here
220
	} else {
224
	} else {
221
	    Params::ClearParams();
225
	    Params::ClearParams();
222
	}
226
	}
223
        if( (initArgs->flags & CKF_OS_LOCKING_OK) || initArgs->LockMutex ){
227
  	needThreads = ((initArgs->flags & CKF_OS_LOCKING_OK) != 0);
228
	OSLock::setThreadSafe(needThreads);
229
	/* don't get a finalize lock unless someone initializes us asking
230
	 * us to use threads */
231
	if (needThreads && !finalizeLock) {
232
	    finalizeLock = new OSLock(true);
233
	    if (finalizeLock == NULL) return CKR_HOST_MEMORY;
234
	}
235
	/* only support OS LOCKING threads */
236
        if( ((initArgs->flags & CKF_OS_LOCKING_OK) == 0) 
237
						&& initArgs->LockMutex ){
224
            throw PKCS11Exception(CKR_CANT_LOCK);
238
            throw PKCS11Exception(CKR_CANT_LOCK);
225
        }
239
        }
226
    }
240
    }
Lines 259-267 Link Here
259
    // the finalizing call first, we know it will set waitEvent before
273
    // the finalizing call first, we know it will set waitEvent before
260
    // we can get the lock, so we only need to protect setting finalizing
274
    // we can get the lock, so we only need to protect setting finalizing
261
    // to true.
275
    // to true.
262
    finalizeLock.getLock();
276
    FINALIZE_GETLOCK();
263
    finalizing = TRUE;
277
    finalizing = TRUE;
264
    finalizeLock.releaseLock();
278
    FINALIZE_RELEASELOCK();
265
    if (waitEvent) {
279
    if (waitEvent) {
266
	/* we're waiting on a slot event, shutdown first to allow
280
	/* we're waiting on a slot event, shutdown first to allow
267
	 * the wait function to complete before we pull the rug out.
281
	 * the wait function to complete before we pull the rug out.
Lines 273-282 Link Here
273
    } 
287
    } 
274
    delete slotList;
288
    delete slotList;
275
    delete log;
289
    delete log;
276
    finalizeLock.getLock();
290
    FINALIZE_GETLOCK();
277
    finalizing = FALSE;
291
    finalizing = FALSE;
278
    initialized = FALSE;
292
    initialized = FALSE;
279
    finalizeLock.releaseLock();
293
    FINALIZE_RELEASELOCK();
280
    return CKR_OK;
294
    return CKR_OK;
281
}
295
}
282
296
Lines 595-611 Link Here
595
CK_RV
609
CK_RV
596
C_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot, CK_VOID_PTR pReserved)
610
C_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot, CK_VOID_PTR pReserved)
597
{
611
{
598
    finalizeLock.getLock();
612
    FINALIZE_GETLOCK();
599
    if( ! initialized ) {
613
    if( ! initialized ) {
600
        finalizeLock.releaseLock();
614
	FINALIZE_RELEASELOCK();
601
        return CKR_CRYPTOKI_NOT_INITIALIZED;
615
        return CKR_CRYPTOKI_NOT_INITIALIZED;
602
    }
616
    }
603
    if (finalizing) {
617
    if (finalizing) {
604
        finalizeLock.releaseLock();
618
	FINALIZE_RELEASELOCK();
605
        return CKR_CRYPTOKI_NOT_INITIALIZED;
619
        return CKR_CRYPTOKI_NOT_INITIALIZED;
606
    }
620
    }
607
    waitEvent = TRUE;
621
    waitEvent = TRUE;
608
    finalizeLock.releaseLock();
622
    FINALIZE_RELEASELOCK();
609
    try {
623
    try {
610
        log->log("C_WaitForSlotEvent called\n");
624
        log->log("C_WaitForSlotEvent called\n");
611
        slotList->waitForSlotEvent(flags, pSlot, pReserved);
625
        slotList->waitForSlotEvent(flags, pSlot, pReserved);
(-)src/coolkey/machdep.cpp (+9 lines)
Lines 37-42 Link Here
37
#include <stdlib.h>
37
#include <stdlib.h>
38
#endif
38
#endif
39
39
40
bool OSLock::needThread = 0;
41
40
#ifdef _WIN32
42
#ifdef _WIN32
41
//
43
//
42
// Windows functions to grab a named shared memory segment of a specific size,
44
// Windows functions to grab a named shared memory segment of a specific size,
Lines 123-128 Link Here
123
125
124
OSLock::OSLock(bool exceptionAllowed)
126
OSLock::OSLock(bool exceptionAllowed)
125
{
127
{
128
    if (!needThread) {
129
	lockData = NULL;
130
	return;
131
    }
126
    lockData = new OSLockData;
132
    lockData = new OSLockData;
127
    if (lockData) {
133
    if (lockData) {
128
	InitializeCriticalSection(&lockData->mutex);
134
	InitializeCriticalSection(&lockData->mutex);
Lines 360-365 Link Here
360
    int rc;
366
    int rc;
361
367
362
    lockData = NULL;
368
    lockData = NULL;
369
    if (!needThread) {
370
	return;
371
    }
363
#ifdef MAC
372
#ifdef MAC
364
    if (!OSLock_attr_init) {
373
    if (!OSLock_attr_init) {
365
	rc = pthread_mutexattr_init(&OSLock_attr);
374
	rc = pthread_mutexattr_init(&OSLock_attr);
(-)src/coolkey/machdep.h (+2 lines)
Lines 40-51 Link Here
40
class OSLock {
40
class OSLock {
41
private:
41
private:
42
   OSLockData *lockData;
42
   OSLockData *lockData;
43
   static bool needThread;
43
public:
44
public:
44
   OSLock(bool exceptionAllowed = true);
45
   OSLock(bool exceptionAllowed = true);
45
   ~OSLock();
46
   ~OSLock();
46
   bool isValid();
47
   bool isValid();
47
   void getLock();
48
   void getLock();
48
   void releaseLock();
49
   void releaseLock();
50
   static void setThreadSafe(bool thread) { needThread = thread; }
49
};
51
};
50
52
51
typedef unsigned long OSTime;
53
typedef unsigned long OSTime;

Return to bug 302769