1 krisbash 1.1 #ifndef _pal_shlib_h
2 #define _pal_shlib_h
3
4 #include <stddef.h>
5 #include <string.h>
6 #include <nits/base/nits.h>
7
8 #if defined(PAL_HAVE_POSIX)
9 # include <dlfcn.h>
10 #endif
11
12 #if defined(linux)
13 # define PAL_DLOPEN_FLAGS (RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND)
14 #else
15 # define PAL_DLOPEN_FLAGS (RTLD_NOW | RTLD_LOCAL)
16 #endif
17
18 PAL_BEGIN_EXTERNC
19
20 typedef struct _Shlib Shlib;
21
22 krisbash 1.1 Shlib* Shlib_Open_Injected(
23 _In_z_ const PAL_Char* path,
24 NitsCallSite cs);
25
26
27 #define Shlib_Open(path) Shlib_Open_Injected(path, NitsHere())
28
29 PAL_INLINE int Shlib_Close(
30 _Inout_ Shlib* self)
31 {
32 #if defined(_MSC_VER)
33 return FreeLibrary((HMODULE)self) ? 0 : -1;
34 #else
35 return (dlclose(self) == 0) ? 0 : -1;
36 #endif
37 }
38
39 PAL_INLINE void* Shlib_Sym(
40 _In_ Shlib* self,
41 _In_z_ const char* symbol)
42 {
43 krisbash 1.1 #if defined(_MSC_VER)
44 #pragma warning(disable:4054)
45 #pragma warning(disable:4055)
46
47 FARPROC result;
48 result = GetProcAddress((HMODULE)self, symbol);
49 return (void*)result;
50 #else
51 return dlsym(self, symbol);
52 #endif
53 }
54
55 PAL_Char* Shlib_Err();
56
57 PAL_INLINE void Shlib_FreeErr(
58 _In_ PAL_Char* err)
59 {
60 #if defined(_MSC_VER)
61 LocalFree(err);
62 #else
63 PAL_Free(err);
64 krisbash 1.1 #endif
65 }
66
67 void Shlib_Format(
68 _Pre_writable_size_(PAL_MAX_PATH_SIZE) _Null_terminated_ TChar path[PAL_MAX_PATH_SIZE],
69 const char* dirName,
70 const char* shortName);
71
72 PAL_END_EXTERNC
73
74 #endif /* _pal_shlib_h */
|