Update Windows support

This commit is contained in:
Zhi Guan
2022-10-05 11:12:06 +08:00
parent cb59309f67
commit 74fbb19f13
30 changed files with 645 additions and 49 deletions

0
src/sdf/sdf.c Normal file → Executable file
View File

0
src/sdf/sdf.h Normal file → Executable file
View File

0
src/sdf/sdf_dummy.c Normal file → Executable file
View File

0
src/sdf/sdf_ext.c Normal file → Executable file
View File

2
src/sdf/sdf_ext.h Normal file → Executable file
View File

@@ -1,4 +1,4 @@
/*
/*
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the License); you may

8
src/sdf/sdf_int.h Normal file → Executable file
View File

@@ -13,6 +13,10 @@
#include "sdf.h"
#ifdef WIN32
#include <windows.h>
#endif
typedef int (*SDF_OpenDevice_FuncPtr)(
void **phDeviceHandle);
@@ -346,7 +350,11 @@ typedef int (*SDF_DeleteObject_FuncPtr)(
typedef struct sdf_method_st {
char *name;
#ifdef WIN32
HMODULE dso;
#else
void *dso;
#endif
SDF_OpenDevice_FuncPtr OpenDevice;
SDF_CloseDevice_FuncPtr CloseDevice;
SDF_OpenSession_FuncPtr OpenSession;

0
src/sdf/sdf_lib.c Normal file → Executable file
View File

18
src/sdf/sdf_meth.c Normal file → Executable file
View File

@@ -11,13 +11,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#include "sdf_int.h"
#define SDFerr(a,b)
#ifdef WIN32
#define SDF_METHOD_BIND_FUNCTION_EX(func,name) \
sdf->func = (SDF_##func##_FuncPtr)GetProcAddress(sdf->dso, "SDF_"#name)
#else
#define SDF_METHOD_BIND_FUNCTION_EX(func,name) \
sdf->func = (SDF_##func##_FuncPtr)dlsym(sdf->dso, "SDF_"#name)
#endif
#define SDF_METHOD_BIND_FUNCTION(func) \
SDF_METHOD_BIND_FUNCTION_EX(func,func)
@@ -33,11 +42,18 @@ SDF_METHOD *SDF_METHOD_load_library(const char *so_path)
}
memset(sdf, 0, sizeof(*sdf));
if (!(sdf->dso = dlopen(so_path, RTLD_LAZY))) {
#ifdef WIN32
if ((sdf->dso = LoadLibraryA(so_path)) == NULL) {
goto end;
}
#else
if (!(sdf->dso = dlopen(so_path, 0/*RTLD_LAZY*/))) { // FIXME: dlfcn.h, dlopen, RTLD_LAZY not in windows!
fprintf(stderr, "%s %d: %s\n", __FILE__, __LINE__, dlerror());
SDFerr(SDF_F_SDF_METHOD_LOAD_LIBRARY, SDF_R_DSO_LOAD_FAILURE);
goto end;
}
#endif
SDF_METHOD_BIND_FUNCTION(OpenDevice);
SDF_METHOD_BIND_FUNCTION(CloseDevice);

0
src/sdf/sdf_sansec.c Normal file → Executable file
View File

0
src/sdf/sdf_sansec.h Normal file → Executable file
View File