Make the 'dynamic' ENGINE bundle up the loading application/library's
authorGeoff Thorpe <geoff@openssl.org>
Tue, 4 Sep 2001 21:25:17 +0000 (21:25 +0000)
committerGeoff Thorpe <geoff@openssl.org>
Tue, 4 Sep 2001 21:25:17 +0000 (21:25 +0000)
locking callbacks to pass to the loaded library (in addition to the
existing mem, ex_data, and err callbacks). Also change the default
implementation of the "bind_engine" function to apply those callbacks, ie.
the IMPLEMENT_DYNAMIC_BIND_FN macro.

crypto/engine/engine.h
crypto/engine/engine_dyn.c

index 149ae9a979b0650327c5eeaa213f76b5f02699c8..7c0b2f67c4b2d2ea472a3ddcf2094a8c6ef9966c 100644 (file)
@@ -504,18 +504,37 @@ const EVP_CIPHER *ENGINE_get_cipher_by_name(ENGINE *e,const char *name);
  * and memory management function pointers to the loaded library. These should
  * be used/set in the loaded library code so that the loading application's
  * 'state' will be used/changed in all operations. */
-typedef void *(*dynamic_MEM_malloc_cb)(size_t);
-typedef void *(*dynamic_MEM_realloc_cb)(void *, size_t);
-typedef void (*dynamic_MEM_free_cb)(void *);
+typedef void *(*dyn_MEM_malloc_cb)(size_t);
+typedef void *(*dyn_MEM_realloc_cb)(void *, size_t);
+typedef void (*dyn_MEM_free_cb)(void *);
 typedef struct st_dynamic_MEM_fns {
-       dynamic_MEM_malloc_cb                   malloc_cb;
-       dynamic_MEM_realloc_cb                  realloc_cb;
-       dynamic_MEM_free_cb                     free_cb;
+       dyn_MEM_malloc_cb                       malloc_cb;
+       dyn_MEM_realloc_cb                      realloc_cb;
+       dyn_MEM_free_cb                         free_cb;
        } dynamic_MEM_fns;
+/* FIXME: Perhaps the memory and locking code (crypto.h) should declare and use
+ * these types so we (and any other dependant code) can simplify a bit?? */
+typedef void (*dyn_lock_locking_cb)(int,int,const char *,int);
+typedef int (*dyn_lock_add_lock_cb)(int*,int,int,const char *,int);
+typedef struct CRYPTO_dynlock_value *(*dyn_dynlock_create_cb)(
+                                               const char *,int);
+typedef void (*dyn_dynlock_lock_cb)(int,struct CRYPTO_dynlock_value *,
+                                               const char *,int);
+typedef void (*dyn_dynlock_destroy_cb)(struct CRYPTO_dynlock_value *,
+                                               const char *,int);
+typedef struct st_dynamic_LOCK_fns {
+       dyn_lock_locking_cb                     lock_locking_cb;
+       dyn_lock_add_lock_cb                    lock_add_lock_cb;
+       dyn_dynlock_create_cb                   dynlock_create_cb;
+       dyn_dynlock_lock_cb                     dynlock_lock_cb;
+       dyn_dynlock_destroy_cb                  dynlock_destroy_cb;
+       } dynamic_LOCK_fns;
+/* The top-level structure */
 typedef struct st_dynamic_fns {
        const ERR_FNS                           *err_fns;
        const CRYPTO_EX_DATA_IMPL               *ex_data_fns;
        dynamic_MEM_fns                         mem_fns;
+       dynamic_LOCK_fns                        lock_fns;
        } dynamic_fns;
 
 /* The version checking function should be of this prototype. NB: The
@@ -555,6 +574,11 @@ typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id,
                if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \
                        fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \
                        return 0; \
+               CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \
+               CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \
+               CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \
+               CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \
+               CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \
                if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \
                        return 0; \
                if(!ERR_set_implementation(fns->err_fns)) return 0; \
index d4f00f7b6a57f29867d12b1a78a6a284194a1796..1e5eded1ee976d497fb28a3c7a63f077c42e5f96 100644 (file)
@@ -375,13 +375,21 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx)
        /* First binary copy the ENGINE structure so that we can roll back if
         * the hand-over fails */
        memcpy(&cpy, e, sizeof(ENGINE));
-       /* Provide the ERR, "ex_data", and memory callbacks so the loaded
-        * library uses our own state (and locking) rather than its own. */
+       /* Provide the ERR, "ex_data", memory, and locking callbacks so the
+        * loaded library uses our state rather than its own. FIXME: As noted in
+        * engine.h, much of this would be simplified if each area of code
+        * provided its own "summary" structure of all related callbacks. It
+        * would also increase opaqueness. */
        fns.err_fns = ERR_get_implementation();
        fns.ex_data_fns = CRYPTO_get_ex_data_implementation();
        CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb,
                                &fns.mem_fns.realloc_cb,
                                &fns.mem_fns.free_cb);
+       fns.lock_fns.lock_locking_cb = CRYPTO_get_locking_callback();
+       fns.lock_fns.lock_add_lock_cb = CRYPTO_get_add_lock_callback();
+       fns.lock_fns.dynlock_create_cb = CRYPTO_get_dynlock_create_callback();
+       fns.lock_fns.dynlock_lock_cb = CRYPTO_get_dynlock_lock_callback();
+       fns.lock_fns.dynlock_destroy_cb = CRYPTO_get_dynlock_destroy_callback();
        /* Try to bind the ENGINE onto our own ENGINE structure */
        if(!ctx->bind_engine(e, ctx->engine_id, &fns))
                {