-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos_dll_uix.c
123 lines (83 loc) · 2.55 KB
/
os_dll_uix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* os_dll_uix.c
access dll for Unix-OS
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h> // for ...
#include <ctype.h> // isdigit
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <dlfcn.h> // Unix: dlopen
#define FUNC_LOAD_only 20
#define FUNC_LOAD_all 21
#define FUNC_CONNECT 22
#define FUNC_EXEC 23
#define FUNC_UNLOAD 24
#define FUNC_RECOMPILE 25
#define FUNC_QUERY 26
#define FUNC_Init 27
static void *dl1 = NULL;
//=====================================================================
int OS_dll_do (char *dllNam, char *fncNam, void *fncDat, int mode) {
//=====================================================================
/// load dll dllNam; start function fncNam (fncDat); unload dll.
/// see also UI_DllLst_work
// Input:
// dllnam name of dll; without filetyp ".dll"
// fncnam main-entry using datablock
// fncdat datablock
// mode 0=load+start+unload
// 1=load+start - do not unload (OS_dll_close_fn
// 2=unload
static char dlNamAct[256];
char *p1, s1[256];
void (*up1)();
printf("OS_dll_do uix |%s|%s| %d\n",dllNam,fncNam,mode);
if(mode == 2) {mode = 0; goto L_close;}
if(dl1 != NULL) goto L_start; // already loaded
// fix DLL-FileName
strcpy(dlNamAct, dllNam);
// sprintf(s1, "%s%s.so",AP_get_bin_dir(),dllNam);
sprintf(s1, "./%s.dll",dllNam);
// load DLL
dl1 = dlopen(s1, RTLD_LAZY);
if(dl1 == NULL) {
TX_Error("OS_dll_do: cannot open dyn. Lib. |%s|",dllNam);
return -1;
}
// get adress of func. <fncNam>
L_start:
up1 = dlsym(dl1, fncNam);
if(up1 == NULL) {
OS_dll_close (&dl1); // unload DLL
TX_Error("OS_dll_do: cannot open Func. |%s|",fncNam);
return -1;
}
printf(" OS_dll_do-dll_do-have-func\n");
// start userprog
(*up1)(fncDat);
printf(" OS_dll_do-dll_do-after-func\n");
// close DLL
L_close:
if(mode < 1) OS_dll_close (&dl1); // unload DLL
printf("ex-OS_dll_do uix\n");
return 0;
}
//================================================================
int OS_dll_close (void **dl1) {
//================================================================
// on successfule returns irc = 0, dl1 = NULL
// BUG dlclose: returnCode is OK but handle not NULL.
int irc = 0;
printf("OS_dll_close \n");
// unload if already loaded
if(*dl1 != NULL) {
irc = dlclose (*dl1); // 0=success
if(!irc) *dl1 = NULL;
}
return irc;
}
// eof