You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@httpd.apache.org by "MATHIHALLI,MADHUSUDAN (HP-Cupertino,ex1)" <ma...@hp.com> on 2001/08/24 23:11:30 UTC

[PATCH] dynamic crypto locking in flood_net_ssl.c

Hi Justin,
	Continuing with the discussion that we had yesterday, here's that
work that I'd done for dynamic locks in SSL.. As I'd mentioned earlier, it's
pretty similar to the stuff in flood_net_ssl.c, except that I maintain a
linked list of the locks created.. I was planning to enquire with the
OpenSSL community if there was actually a need to have these dynamic lock
utilites defined.. Pl. let me know your comments.. 
The only change that I've done for the flood_net_ssl.c is to comment out the
CRYPTO_dynlock_value structure that you define.. 

Thanks
-Madhu

Index: flood_net_ssl.c
===================================================================
RCS file: /home/cvspublic/httpd-test/flood/flood_net_ssl.c,v
retrieving revision 1.9
diff -u -r1.9 flood_net_ssl.c
--- flood_net_ssl.c     2001/08/24 04:26:39     1.9
+++ flood_net_ssl.c     2001/08/24 20:55:42
@@ -79,9 +79,101 @@
 #if APR_HAS_THREADS
 apr_lock_t **ssl_locks;
 
+#if 0
 typedef struct CRYPTO_dynlock_value { 
     apr_lock_t *lock; 
 } CRYPTO_dynlock_value;
+
+#else
+
+/* 
+ * CRYPTO DYNAMIC LOCKS :
+ * This is the set of dynamic locks that may (or may not) be requested by
+ * OpenSSL. We maintain a Simple Linked list for all the dynamic locks 
+ * requested by OpenSSL. The first element is the header
(ssl_dynlock_header) 
+ * - it'll ONLY contain the pool from which the apr_palloc /apr_lock_create

+ * has to be done. 
+ *
+ * Dynamic Lock Creation : 
+ * - Memory is allocated from the pool pointed by ssl_dynlock_header->pool
+ * - The LL is traversed and the lock added at the end of the list
+ * Dynamic Lock Deletion :
+ * - The LL is traversed to find the requested lock to be deleted, and the
+ *   corresponding element is deleted from the LL.
+ * - The requested lock is destroyed / freed.
+ */
+typedef struct CRYPTO_dynlock_value 
+{
+  struct CRYPTO_dynlock_value *prev;
+  apr_pool_t           *pool;
+  apr_lock_t           *lock;
+  struct CRYPTO_dynlock_value *next;
+} CRYPTO_dynlock_value;
+typedef CRYPTO_dynlock_value ssl_dynlock_t;
+
+ssl_dynlock_t *ssl_dynlock_header;
+
+static ssl_dynlock_t *ssl_util_thr_dyncreate(const char* file, int line)
+{
+    ssl_dynlock_t *l, *iter = ssl_dynlock_header;
+
+    l = (ssl_dynlock_t *)apr_palloc(iter->pool, sizeof(ssl_dynlock_t));
+    apr_lock_create(&l->lock, APR_MUTEX, APR_INTRAPROCESS, NULL,
iter->pool);
+
+    ssl_lock (CRYPTO_LOCK, CRYPTO_LOCK_MALLOC2, NULL, 0);
+
+    while (iter->next != (ssl_dynlock_t *)NULL)
+        iter = iter->next;
+
+    iter->next = l;
+    l->pool    = (apr_pool_t *)NULL;
+    l->prev    = iter;
+    l->next    = (ssl_dynlock_t *)NULL;
+
+    ssl_lock(CRYPTO_UNLOCK, CRYPTO_LOCK_MALLOC2, NULL, 0);
+    return l;
+}
+
+static void ssl_util_thr_dynlock(int mode, ssl_dynlock_t *l,
+                                            const char *file,int line)
+{
+    if (mode & CRYPTO_LOCK)
+        apr_lock_acquire(l->lock);
+    else if (mode & CRYPTO_UNLOCK)
+        apr_lock_release(l->lock);
+}
+
+static void ssl_util_thr_dyndestroy(ssl_dynlock_t *l,
+                                            const char *file, int line)
+{
+    ssl_dynlock_t *iter = ssl_dynlock_header->next;
+
+    ssl_lock(CRYPTO_LOCK, CRYPTO_LOCK_MALLOC2, NULL, 0);
+    do
+    {
+        if ((iter->lock == l->lock) && (iter->prev != (ssl_dynlock_t
*)NULL))
+        {
+            (iter->prev)->next = l->next;
+            apr_lock_destroy(l->lock);
+            ssl_lock(CRYPTO_UNLOCK,CRYPTO_LOCK_MALLOC2,NULL,0);
+            return;
+        }
+    }
+    while ((iter = iter->next) != (ssl_dynlock_t *)NULL);
+    ssl_lock(CRYPTO_UNLOCK, CRYPTO_LOCK_MALLOC2, NULL, 0);
+}
+
+/*
+ * This is yet to be registered - TBD.
+ */
+static void ssl_util_thr_dyncleanup()
+{
+    ssl_dynlock_t *iter = ssl_dynlock_header;
+    
+    while ((iter = iter->next) != (ssl_dynlock_t *)NULL)
+        ssl_util_thr_dyndestroy(iter, NULL, 0);
+}
+#endif
 
 CRYPTO_dynlock_value * ssl_dyn_create(const char* file, int line)
 {