From 1e2937e1a2e4ddfed1cf484b48b916d113f8fdac Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Sun, 11 Nov 2018 09:14:00 -0600 Subject: added crypto_lock portable bits --- crypto/Makefile.am | 5 ++++ crypto/compat/crypto_lock_win.c | 53 +++++++++++++++++++++++++++++++++++++++++ crypto/crypto_lock_win.c | 53 ----------------------------------------- update.sh | 1 + 4 files changed, 59 insertions(+), 53 deletions(-) create mode 100644 crypto/compat/crypto_lock_win.c delete mode 100644 crypto/crypto_lock_win.c diff --git a/crypto/Makefile.am b/crypto/Makefile.am index ba96c51..2d95359 100644 --- a/crypto/Makefile.am +++ b/crypto/Makefile.am @@ -213,6 +213,11 @@ endif libcrypto_la_SOURCES += cpt_err.c libcrypto_la_SOURCES += cryptlib.c libcrypto_la_SOURCES += crypto_init.c +if !HOST_WIN +libcrypto_la_SOURCES += crypto_lock.c +else +libcrypto_la_SOURCES += crypto_lock_win.c +endif libcrypto_la_SOURCES += cversion.c libcrypto_la_SOURCES += ex_data.c libcrypto_la_SOURCES += malloc-wrapper.c diff --git a/crypto/compat/crypto_lock_win.c b/crypto/compat/crypto_lock_win.c new file mode 100644 index 0000000..47c3dcc --- /dev/null +++ b/crypto/compat/crypto_lock_win.c @@ -0,0 +1,53 @@ +/* $OpenBSD: crypto_lock.c,v 1.1 2018/11/11 06:41:28 bcook Exp $ */ +/* + * Copyright (c) 2018 Brent Cook + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +static HANDLE locks[CRYPTO_NUM_LOCKS]; + +void +crypto_init_locks(void) +{ + int i; + + for (i = 0; i < CRYPTO_NUM_LOCKS; i++) + locks[i] = CreateMutex(NULL, FALSE, NULL); +} + +void +CRYPTO_lock(int mode, int type, const char *file, int line) +{ + if (type < 0 || type >= CRYPTO_NUM_LOCKS) + return; + + if (mode & CRYPTO_LOCK) + WaitForSingleObject(locks[type], INFINITE); + else + ReleaseMutex(locks[type]); +} + +int +CRYPTO_add_lock(int *pointer, int amount, int type, const char *file, + int line) +{ + int ret = 0; + CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE, type, file, line); + ret = *pointer + amount; + *pointer = ret; + CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE, type, file, line); + return (ret); +} diff --git a/crypto/crypto_lock_win.c b/crypto/crypto_lock_win.c deleted file mode 100644 index 47c3dcc..0000000 --- a/crypto/crypto_lock_win.c +++ /dev/null @@ -1,53 +0,0 @@ -/* $OpenBSD: crypto_lock.c,v 1.1 2018/11/11 06:41:28 bcook Exp $ */ -/* - * Copyright (c) 2018 Brent Cook - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -static HANDLE locks[CRYPTO_NUM_LOCKS]; - -void -crypto_init_locks(void) -{ - int i; - - for (i = 0; i < CRYPTO_NUM_LOCKS; i++) - locks[i] = CreateMutex(NULL, FALSE, NULL); -} - -void -CRYPTO_lock(int mode, int type, const char *file, int line) -{ - if (type < 0 || type >= CRYPTO_NUM_LOCKS) - return; - - if (mode & CRYPTO_LOCK) - WaitForSingleObject(locks[type], INFINITE); - else - ReleaseMutex(locks[type]); -} - -int -CRYPTO_add_lock(int *pointer, int amount, int type, const char *file, - int line) -{ - int ret = 0; - CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE, type, file, line); - ret = *pointer + amount; - *pointer = ret; - CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE, type, file, line); - return (ret); -} diff --git a/update.sh b/update.sh index 375d78d..f68eefb 100755 --- a/update.sh +++ b/update.sh @@ -154,6 +154,7 @@ for i in `awk '/SOURCES|HEADERS/ { print $3 }' crypto/Makefile.am` ; do fi done $CP crypto/compat/b_win.c crypto/bio +$CP crypto/compat/crypto_lock_win.c crypto $CP crypto/compat/ui_openssl_win.c crypto/ui # add the libcrypto symbol export list $GREP -v OPENSSL_ia32cap_P $libcrypto_src/Symbols.list | $GREP '^[A-Za-z0-9_]' > crypto/crypto.sym -- cgit v1.2.3-55-g6feb