about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-10-22 03:22:20 -0400
committerJune McEnroe <june@causal.agency>2020-10-22 03:22:20 -0400
commit55bd56237bac9a0522185181b3a5a6233ab5b65b (patch)
tree117ca2978aa5be870a8c066588fecf1ad0a81bf4
parentMerge LibreSSL 3.2.1 into master (diff)
parentImport LibreSSL 3.2.2 (diff)
downloadlibretls-55bd56237bac9a0522185181b3a5a6233ab5b65b.tar.gz
libretls-55bd56237bac9a0522185181b3a5a6233ab5b65b.zip
Merge LibreSSL 3.2.2 into master 3.2.2
No changes in libtls.
Diffstat (limited to '')
-rw-r--r--VERSION2
-rw-r--r--configure.ac3
-rwxr-xr-x[-rw-r--r--]include/compat/pthread.h31
3 files changed, 29 insertions, 7 deletions
diff --git a/VERSION b/VERSION
index 667b8b1..19ef286 100644
--- a/VERSION
+++ b/VERSION
@@ -1,2 +1,2 @@
-3.2.1
+3.2.2
 
diff --git a/configure.ac b/configure.ac
index 42c4c9b..f2a27a9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,8 +27,7 @@ USER_CFLAGS="$CFLAGS"
 AC_PROG_CC([cc gcc])
 AC_PROG_CC_STDC
 AM_PROG_CC_C_O
-AC_PROG_LIBTOOL
-LT_INIT
+LT_INIT([pic-only])
 
 CHECK_OS_OPTIONS
 
diff --git a/include/compat/pthread.h b/include/compat/pthread.h
index 8b8c3c6..1527d3c 100644..100755
--- a/include/compat/pthread.h
+++ b/include/compat/pthread.h
@@ -8,6 +8,8 @@
 
 #ifdef _WIN32
 
+#include <malloc.h>
+#include <stdlib.h>
 #include <windows.h>
 
 /*
@@ -16,6 +18,11 @@
 #define PTHREAD_ONCE_INIT   { INIT_ONCE_STATIC_INIT }
 
 /*
+ * Static mutex initialization values.
+ */
+#define PTHREAD_MUTEX_INITIALIZER	{ .lock = NULL }
+
+/*
  * Once definitions.
  */
 struct pthread_once {
@@ -55,27 +62,43 @@ pthread_equal(pthread_t t1, pthread_t t2)
 	return t1 == t2;
 }
 
-typedef CRITICAL_SECTION pthread_mutex_t;
+struct pthread_mutex {
+	volatile LPCRITICAL_SECTION lock;
+};
+typedef struct pthread_mutex pthread_mutex_t;
 typedef void pthread_mutexattr_t;
 
 static inline int
 pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
 {
-	InitializeCriticalSection(mutex);
+	if ((mutex->lock = malloc(sizeof(CRITICAL_SECTION))) == NULL)
+		exit(ENOMEM);
+	InitializeCriticalSection(mutex->lock);
 	return 0;
 }
 
 static inline int
 pthread_mutex_lock(pthread_mutex_t *mutex)
 {
-	EnterCriticalSection(mutex);
+	if (mutex->lock == NULL) {
+		LPCRITICAL_SECTION lcs;
+
+		if ((lcs = malloc(sizeof(CRITICAL_SECTION))) == NULL)
+			exit(ENOMEM);
+		InitializeCriticalSection(lcs);
+		if (InterlockedCompareExchangePointer((PVOID*)&mutex->lock, (PVOID)lcs, NULL) != NULL) {
+			DeleteCriticalSection(lcs);
+			free(lcs);
+		}
+	}
+	EnterCriticalSection(mutex->lock);
 	return 0;
 }
 
 static inline int
 pthread_mutex_unlock(pthread_mutex_t *mutex)
 {
-	LeaveCriticalSection(mutex);
+	LeaveCriticalSection(mutex->lock);
 	return 0;
 }