Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -1,8 +1,8 @@ CC = gcc -CFLAGS = -g3 -ggdb3 -fPIC -DPIC -Wall -CPPFLAGS = -DTCL_USE_STUBS +CFLAGS = -fPIC -DPIC -Wall +CPPFLAGS = -DTCL_USE_STUBS=1 -DHAVE_DLOPEN=1 -DHAVE_DLFCN_H=1 SHFLAGS = -nostartfiles -rdynamic -shared LIBS = -ldl -ltclstub8.5 all: tclpkcs11.so Index: tclpkcs11.c ================================================================== --- tclpkcs11.c +++ tclpkcs11.c @@ -1,9 +1,17 @@ #include #include #include -#include +#ifdef HAVE_DLFCN_H +# include +#endif +#ifdef HAVE_DL_H +# include +#endif +#ifdef _WIN32 +# include +#endif #include #if 10 * TCL_MAJOR_VERSION + TCL_MINOR_VERSION >= 86 # define TCL_INCLUDES_LOADFILE 1 #endif @@ -283,11 +291,11 @@ } return(outbufidx); } -/* PKCS#11 CreateMutex implementation that use Tcl Mutexes */ +/* PKCS#11 Mutex functions implementation that use Tcl Mutexes */ static CK_RV tclpkcs11_create_mutex(void **mutex) { Tcl_Mutex *retval; if (!mutex) { return(CKR_GENERAL_ERROR); @@ -384,11 +392,11 @@ /* * Platform Specific Functions */ static void *tclpkcs11_int_load_module(const char *pathname) { -#ifdef TCL_INCLUDES_LOADFILE +#if defined(TCL_INCLUDES_LOADFILE) int tcl_rv; Tcl_LoadHandle *new_handle; new_handle = (Tcl_LoadHandle *) ckalloc(sizeof(*new_handle)); @@ -396,44 +404,63 @@ if (tcl_rv != TCL_OK) { return(NULL); } return(new_handle); -#else - /* XXX: TODO: Replace this with Tcl_Load() in 8.6 or otherwise a system-specific loading mechanism */ +#elif defined(HAVE_DLOPEN) return(dlopen(pathname, RTLD_LAZY | RTLD_LOCAL)); +#elif defined(HAVE_SHL_LOAD) + return(shl_load(pathname, BIND_DEFERRED, 0L)); +#elif defined(_WIN32) + return(LoadLibrary(pathname)); #endif + return(NULL); } static void tclpkcs11_int_unload_module(void *handle) { -#ifdef TCL_INCLUDES_LOADFILE +#if defined(TCL_INCLUDES_LOADFILE) Tcl_LoadHandle *tcl_handle; tcl_handle = handle; Tcl_FSUnloadFile(NULL, *tcl_handle); ckfree(handle); -#else - /* XXX: TODO: Replace this with Tcl_Unload() in 8.6 or otherwise a system-specific unloading mechanism */ +#elif defined(HAVE_DLOPEN) dlclose(handle); +#elif defined(HAVE_SHL_LOAD) + shl_unload(handle); +#elif defined(_WIN32) + FreeLibrary(handle); #endif return; } static void *tclpkcs11_int_lookup_sym(void *handle, const char *sym) { -#ifdef TCL_INCLUDES_LOADFILE +#if defined(TCL_INCLUDES_LOADFILE) Tcl_LoadHandle *tcl_handle; void *retval; tcl_handle = handle; retval = Tcl_FindSymbol(NULL, *tcl_handle, sym); return(retval); -#else - /* XXX: TODO: Replace this with ... ? in 8.6 or otherwise a system-specific symbol lookup mechanism */ +#elif defined(HAVE_DLOPEN) return(dlsym(handle, sym)); +#elif defined(HAVE_SHL_LOAD) + void *retval; + int shl_findsym_ret; + + shl_findsym_ret = shl_findsym(handle, sym, TYPE_PROCEDURE, &retval); + if (shl_findsym_ret != 0) { + return(NULL); + } + + return(retval); +#elif defined(_WIN32) + return(GetProcAddress(handle, sym)); #endif + return(NULL); } /* * Tcl Commands */