summaryrefslogtreecommitdiff
path: root/src/module.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/module.c')
-rw-r--r--src/module.c109
1 files changed, 27 insertions, 82 deletions
diff --git a/src/module.c b/src/module.c
index b7a715b..e3008f3 100644
--- a/src/module.c
+++ b/src/module.c
@@ -1,27 +1,22 @@
+#include "p11-tests-lib.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x400
#include <windows.h>
-static HMODULE module = NULL;
-
#else /* !_WIN32 */
-#include <dlfcn.h>
#include <pthread.h>
-static void *module = NULL;
-
#endif /* !_WIN32 */
-#include "p11-tests.h"
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
CK_FUNCTION_LIST_PTR p11t_module_funcs = NULL;
static const char *init_string = NULL;
@@ -272,58 +267,6 @@ unlock_mutex (void *mutex)
return ret;
}
-int
-p11t_module_load(const char *filename)
-{
- CK_FUNCTION_LIST_PTR list;
- CK_C_GetFunctionList get_function_list;
- CK_RV rv;
-
-#ifdef _WIN32
-
- module = LoadLibrary(filename);
- if(!module)
- p11t_msg_fatal("couldn't load library: %s: %s", filename, p11t_msg_os());
-
- /* Lookup the appropriate function in the library */
- get_function_list = (CK_C_GetFunctionList)GetProcAddress(module, "C_GetFunctionList");
- if(!get_function_list)
- p11t_msg_fatal("C_GetFunctionList: couldn't find function in library: %s: %s",
- filename, p11t_msg_os());
-
-#else /* !_WIN32 */
-
- module = dlopen(filename, RTLD_NOW);
- if(!module)
- p11t_msg_fatal("couldn't open library: %s: %s", filename, dlerror());
-
- /* Lookup the appropriate function in library */
- get_function_list = (CK_C_GetFunctionList)dlsym (module, "C_GetFunctionList");
- if(!get_function_list)
- p11t_msg_fatal("C_GetFunctionList: couldn't find function in library: %s: %s",
- filename, dlerror());
-
-#endif /* !_WIN32 */
-
- /* Get the function list */
- rv = (get_function_list)(&p11t_module_funcs);
- if(rv != CKR_OK)
- p11t_msg_fatal("C_GetFunctiontList: couldn't get function list: %s", p11t_msg_rv(rv));
-
- if(p11t_test_unexpected)
- {
- P11T_SECTION("C_GetFunctionList");
-
- rv = (p11t_module_funcs->C_GetFunctionList)(&list);
- P11T_CHECK_RV("Call through function list", rv, CKR_OK);
-
- if(memcmp(list, p11t_module_funcs, sizeof(*list)) != 0)
- p11t_check_info("Call doesn't return same data as library C_GetFunctionList entry point");
- }
-
- return CONTINUE;
-}
-
static int
initialize_common(const char *mode)
{
@@ -408,11 +351,23 @@ initialize_locking_4(void)
int
p11t_module_initialize(void)
{
+ CK_FUNCTION_LIST_PTR list;
CK_INFO info;
CK_RV rv;
assert(p11t_module_funcs);
+ if(p11t_test_unexpected)
+ {
+ P11T_SECTION("C_GetFunctionList");
+
+ rv = (p11t_module_funcs->C_GetFunctionList)(&list);
+ P11T_CHECK_RV("Call through function list", rv, CKR_OK);
+
+ if(memcmp(list, p11t_module_funcs, sizeof(*list)) != 0)
+ p11t_check_info("Call doesn't return same data as library C_GetFunctionList entry point");
+ }
+
P11T_SECTION("C_Initialize");
if(p11t_test_unexpected)
@@ -439,11 +394,16 @@ p11t_module_initialize(void)
p11t_module_finalize();
/* Actually initialize with whatever succeeded last */
- if(!init_func)
- p11t_msg_fatal("Couldn't initialize module via any method");
+ if(!init_func) {
+ p11t_check_fail ("Couldn't initialize module via any method");
+ return STOP;
+ }
+
(init_func)();
- if(!is_initialized)
- p11t_msg_fatal("Failed to initialize module");
+ if(!is_initialized) {
+ p11t_check_fail ("Failed to initialize module");
+ return STOP;
+ }
if(p11t_test_unexpected)
{
@@ -484,18 +444,3 @@ p11t_module_finalize(void)
return CONTINUE;
}
-
-int
-p11t_module_unload(void)
-{
- if(module)
- {
-#ifdef _WIN32
- FreeLibrary(module);
-#else
- dlclose(module);
-#endif
- }
- module = NULL;
- return CONTINUE;
-}