int RLckInitLockers(void) { /* Create resource locking mutex */ if ((hRLMutex = SysCreateMutex()) == SYS_INVALID_MUTEX) return ErrGetErrorCode(); /* Initialize wait gates */ for (int i = 0; i < STD_WAIT_GATES; i++) { if ((RLGates[i].hSemaphore = SysCreateSemaphore(0, SYS_DEFAULT_MAXCOUNT)) == SYS_INVALID_SEMAPHORE) { ErrorPush(); for (--i; i >= 0; i--) { SysFree(RLGates[i].pResList); SysCloseSemaphore(RLGates[i].hSemaphore); } SysCloseMutex(hRLMutex); return ErrorPop(); } RLGates[i].iWaitingProcesses = 0; RLGates[i].iHashSize = STD_RES_HASH_SIZE; if ((RLGates[i].pResList = (SysListHead *) SysAlloc(RLGates[i].iHashSize * sizeof(SysListHead))) == NULL) { ErrorPush(); SysCloseSemaphore(RLGates[i].hSemaphore); for (--i; i >= 0; i--) { SysFree(RLGates[i].pResList); SysCloseSemaphore(RLGates[i].hSemaphore); } SysCloseMutex(hRLMutex); return ErrorPop(); } for (int j = 0; j < RLGates[i].iHashSize; j++) SYS_INIT_LIST_HEAD(&RLGates[i].pResList[j]); } return 0; }
int BSslInit(void) { int i, iNumLocks = CRYPTO_num_locks(); if ((pSslMtxs = (SYS_MUTEX *) SysAlloc(iNumLocks * sizeof(SYS_MUTEX))) == NULL) return ErrGetErrorCode(); for (i = 0; i < iNumLocks; i++) { if ((pSslMtxs[i] = SysCreateMutex()) == SYS_INVALID_MUTEX) { ErrorPush(); for (i--; i >= 0; i--) SysCloseMutex(pSslMtxs[i]); SysFreeNullify(pSslMtxs); return ErrorPop(); } } SSL_load_error_strings(); SSLeay_add_ssl_algorithms(); CRYPTO_set_id_callback(SysGetCurrentThreadId); CRYPTO_set_locking_callback(BSslLockingCB); SysAddThreadExitHook(BSslThreadExit, NULL); return 0; }
int RLckCleanupLockers(void) { if (SysLockMutex(hRLMutex, SYS_INFINITE_TIMEOUT) < 0) return ErrGetErrorCode(); for (int i = 0; i < STD_WAIT_GATES; i++) { for (int j = 0; j < RLGates[i].iHashSize; j++) { SysListHead *pHead = &RLGates[i].pResList[j]; SysListHead *pLLink; while ((pLLink = SYS_LIST_FIRST(pHead)) != NULL) { ResLockEntry *pRLE = SYS_LIST_ENTRY(pLLink, ResLockEntry, LLink); SYS_LIST_DEL(&pRLE->LLink); RLckFreeEntry(pRLE); } } SysFree(RLGates[i].pResList); SysCloseSemaphore(RLGates[i].hSemaphore); } SysUnlockMutex(hRLMutex); SysCloseMutex(hRLMutex); return 0; }
void BSslCleanup(void) { int i, iNumLocks = CRYPTO_num_locks(); #ifdef DEBUG_OSSL BIO *pErrBIO = BIO_new_fp(stderr, BIO_NOCLOSE); #endif BSslFreeOSSL(); #ifdef DEBUG_OSSL if (pErrBIO != NULL) { CRYPTO_mem_leaks(pErrBIO); BIO_free(pErrBIO); } #endif /* * This must be done as the last operation, since OpenSSL cleanup code * mayb end up calling BSslLockingCB() during its operations. */ for (i = 0; i < iNumLocks; i++) SysCloseMutex(pSslMtxs[i]); SysFreeNullify(pSslMtxs); }