[Cryptech-Commits] [user/sra/pkcs11] 01/01: Minor cleanup of new mutex code after confirming that DNSSEC signer test still works.
git at cryptech.is
git at cryptech.is
Wed Jun 3 15:31:25 UTC 2015
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch master
in repository user/sra/pkcs11.
commit 67d2f799fb76197d78bbf8ab6d76557f09f30114
Author: Rob Austein <sra at hactrn.net>
Date: Wed Jun 3 11:29:54 2015 -0400
Minor cleanup of new mutex code after confirming that DNSSEC signer
test still works.
---
pkcs11.c | 84 +++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 43 insertions(+), 41 deletions(-)
diff --git a/pkcs11.c b/pkcs11.c
index fef9e0b..4063836 100644
--- a/pkcs11.c
+++ b/pkcs11.c
@@ -461,15 +461,19 @@ static char *cf_pkcs15_keyring(void)
* Slightly higher-level macros for common operations.
*/
-#define mutex_lock_or_fail(_m_) \
- do { \
- CK_RV _rv_ = mutex_lock(_m_); \
- if (_rv_ != CKR_OK) \
- return _rv_; \
+#define mutex_lock_or_return_failure(_m_) \
+ do { \
+ CK_RV _rv = mutex_lock(_m_); \
+ if (_rv != CKR_OK) \
+ return _rv; \
} while (0)
-#define mutex_unlock_with_rv(_rv_, _m_) \
- ((_rv_) == CKR_OK ? mutex_unlock(_m_) : (mutex_unlock(_m_), (_rv_)))
+#define mutex_unlock_return_with_rv(_rv_, _m_) \
+ do { \
+ CK_RV _rv1 = _rv_; \
+ CK_RV _rv2 = mutex_unlock(_m_); \
+ return _rv1 == CKR_OK ? _rv2 : _rv1; \
+ } while (0)
/*
* Mutex implementation using POSIX mutexes.
@@ -2597,7 +2601,7 @@ CK_RV C_Finalize(CK_VOID_PTR pReserved)
if (pReserved != NULL)
return CKR_ARGUMENTS_BAD;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
/*
* Destroy all current sessions.
@@ -2790,7 +2794,7 @@ CK_RV C_OpenSession(CK_SLOT_ID slotID,
p11_session_t *session = NULL;
CK_RV rv;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
if (slotID != P11_ONE_AND_ONLY_SLOT)
lose(CKR_SLOT_ID_INVALID);
@@ -2845,13 +2849,11 @@ CK_RV C_CloseSession(CK_SESSION_HANDLE hSession)
{
CK_RV rv;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
- if ((rv = p11_session_delete(hSession)) != CKR_OK)
- goto fail;
+ rv = p11_session_delete(hSession);
- fail:
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
CK_RV C_CloseAllSessions(CK_SLOT_ID slotID)
@@ -2859,7 +2861,7 @@ CK_RV C_CloseAllSessions(CK_SLOT_ID slotID)
if (slotID != P11_ONE_AND_ONLY_SLOT)
return CKR_SLOT_ID_INVALID;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
p11_session_delete_all();
@@ -2875,7 +2877,7 @@ CK_RV C_Login(CK_SESSION_HANDLE hSession,
CK_RV rv = CKR_OK;
int crypt_cmd;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
if (pPin == NULL)
lose(CKR_ARGUMENTS_BAD);
@@ -2983,7 +2985,7 @@ CK_RV C_Login(CK_SESSION_HANDLE hSession,
assert(p11_session_consistent_login());
fail:
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
CK_RV C_Logout(CK_SESSION_HANDLE hSession)
@@ -2992,7 +2994,7 @@ CK_RV C_Logout(CK_SESSION_HANDLE hSession)
CK_RV rv = CKR_OK;
int crypt_cmd;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
/*
* Mind, I don't really know why this function takes a session
@@ -3058,7 +3060,7 @@ CK_RV C_Logout(CK_SESSION_HANDLE hSession)
assert(p11_session_consistent_login());
fail:
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
CK_RV C_DestroyObject(CK_SESSION_HANDLE hSession,
@@ -3080,7 +3082,7 @@ CK_RV C_DestroyObject(CK_SESSION_HANDLE hSession,
sqlite3_int64 id;
CK_RV rv = CKR_OK;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
session = p11_session_find(hSession);
@@ -3126,7 +3128,7 @@ CK_RV C_DestroyObject(CK_SESSION_HANDLE hSession,
fail:
sqlite3_finalize(q);
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
CK_RV C_GetAttributeValue(CK_SESSION_HANDLE hSession,
@@ -3150,7 +3152,7 @@ CK_RV C_GetAttributeValue(CK_SESSION_HANDLE hSession,
CK_RV rv;
int ret, i;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
if (pTemplate == NULL)
lose(CKR_ARGUMENTS_BAD);
@@ -3221,7 +3223,7 @@ CK_RV C_GetAttributeValue(CK_SESSION_HANDLE hSession,
fail:
sqlite3_finalize(q);
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
CK_RV C_FindObjectsInit(CK_SESSION_HANDLE hSession,
@@ -3263,7 +3265,7 @@ CK_RV C_FindObjectsInit(CK_SESSION_HANDLE hSession,
CK_RV rv = CKR_OK;
int i, ret;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
if ((session = p11_session_find(hSession)) == NULL)
lose(CKR_SESSION_HANDLE_INVALID);
@@ -3362,7 +3364,7 @@ CK_RV C_FindObjectsInit(CK_SESSION_HANDLE hSession,
fail:
sqlite3_finalize(q1);
sqlite3_finalize(q2);
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
CK_RV C_FindObjects(CK_SESSION_HANDLE hSession,
@@ -3374,7 +3376,7 @@ CK_RV C_FindObjects(CK_SESSION_HANDLE hSession,
int i, ret = SQLITE_OK;
CK_RV rv = CKR_OK;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
if ((session = p11_session_find(hSession)) == NULL)
lose(CKR_SESSION_HANDLE_INVALID);
@@ -3415,7 +3417,7 @@ CK_RV C_FindObjects(CK_SESSION_HANDLE hSession,
*pulObjectCount = i;
fail:
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
CK_RV C_FindObjectsFinal(CK_SESSION_HANDLE hSession)
@@ -3427,7 +3429,7 @@ CK_RV C_FindObjectsFinal(CK_SESSION_HANDLE hSession)
sqlite3_stmt *q = NULL;
CK_RV rv = CKR_OK;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
if ((session = p11_session_find(hSession)) == NULL)
lose(CKR_SESSION_HANDLE_INVALID);
@@ -3448,7 +3450,7 @@ CK_RV C_FindObjectsFinal(CK_SESSION_HANDLE hSession)
fail:
sqlite3_finalize(q);
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
CK_RV C_DigestInit(CK_SESSION_HANDLE hSession,
@@ -3459,7 +3461,7 @@ CK_RV C_DigestInit(CK_SESSION_HANDLE hSession,
unsigned hash_len = 0;
CK_RV rv = CKR_OK;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
if ((session = p11_session_find(hSession)) == NULL)
lose(CKR_SESSION_HANDLE_INVALID);
@@ -3494,7 +3496,7 @@ CK_RV C_DigestInit(CK_SESSION_HANDLE hSession,
cryptDestroyContext(session->digest_context);
session->digest_context = CRYPT_HANDLE_NONE;
}
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
CK_RV C_Digest(CK_SESSION_HANDLE hSession,
@@ -3507,7 +3509,7 @@ CK_RV C_Digest(CK_SESSION_HANDLE hSession,
CK_RV rv = CKR_OK;
int len;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
if ((session = p11_session_find(hSession)) == NULL)
lose(CKR_SESSION_HANDLE_INVALID);
@@ -3552,7 +3554,7 @@ CK_RV C_Digest(CK_SESSION_HANDLE hSession,
cryptDestroyContext(session->digest_context);
session->digest_context = CRYPT_HANDLE_NONE;
}
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
CK_RV C_SignInit(CK_SESSION_HANDLE hSession,
@@ -3567,7 +3569,7 @@ CK_RV C_SignInit(CK_SESSION_HANDLE hSession,
int key_algo;
CK_RV rv = CKR_OK;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
if ((session = p11_session_find(hSession)) == NULL)
lose(CKR_SESSION_HANDLE_INVALID);
@@ -3629,7 +3631,7 @@ CK_RV C_SignInit(CK_SESSION_HANDLE hSession,
session->sign_digest_context = CRYPT_HANDLE_NONE;
}
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
CK_RV C_Sign(CK_SESSION_HANDLE hSession,
@@ -3642,7 +3644,7 @@ CK_RV C_Sign(CK_SESSION_HANDLE hSession,
int len, algo;
CK_RV rv;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
if ((session = p11_session_find(hSession)) == NULL)
lose(CKR_SESSION_HANDLE_INVALID);
@@ -3785,7 +3787,7 @@ CK_RV C_Sign(CK_SESSION_HANDLE hSession,
session->sign_key_context = CRYPT_HANDLE_NONE;
}
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
/*
@@ -3822,7 +3824,7 @@ CK_RV C_GenerateKeyPair(CK_SESSION_HANDLE hSession,
p11_session_t *session;
CK_RV rv;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
if ((session = p11_session_find(hSession)) == NULL)
lose(CKR_SESSION_HANDLE_INVALID);
@@ -3846,7 +3848,7 @@ CK_RV C_GenerateKeyPair(CK_SESSION_HANDLE hSession,
}
fail:
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
CK_RV C_GenerateRandom(CK_SESSION_HANDLE hSession,
@@ -3857,7 +3859,7 @@ CK_RV C_GenerateRandom(CK_SESSION_HANDLE hSession,
CRYPT_CONTEXT ctx = CRYPT_HANDLE_NONE;
CK_RV rv = CKR_OK;
- mutex_lock_or_fail(p11_global_mutex);
+ mutex_lock_or_return_failure(p11_global_mutex);
if ((session = p11_session_find(hSession)) == NULL)
lose(CKR_SESSION_HANDLE_INVALID);
@@ -3884,7 +3886,7 @@ CK_RV C_GenerateRandom(CK_SESSION_HANDLE hSession,
if (ctx != CRYPT_HANDLE_NONE)
(void) cryptDestroyContext(ctx);
- return mutex_unlock_with_rv(rv, p11_global_mutex);
+ mutex_unlock_return_with_rv(rv, p11_global_mutex);
}
More information about the Commits
mailing list