@@ -35,26 +35,37 @@ public static class SymbolResolver
35
35
36
36
static SymbolResolver ( )
37
37
{
38
- switch ( Environment . OSVersion . Platform )
38
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
39
39
{
40
- case PlatformID . Unix :
41
- case PlatformID . MacOSX :
42
- loadImage = dlopen ;
43
- resolveSymbol = dlsym ;
44
- formats = new [ ] {
40
+ loadImage = LoadLibrary ;
41
+ resolveSymbol = GetProcAddress ;
42
+ formats = new [ ] { "{0}" , "{0}.dll" } ;
43
+ }
44
+ else
45
+ {
46
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
47
+ {
48
+ loadImage = dlopen_linux ;
49
+ resolveSymbol = dlsym_linux ;
50
+ }
51
+ else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
52
+ {
53
+ loadImage = dlopen_macos ;
54
+ resolveSymbol = dlsym_macos ;
55
+ }
56
+ else
57
+ {
58
+ throw new NotImplementedException ( ) ;
59
+ }
60
+
61
+ formats = new [ ] {
45
62
"{0}" ,
46
63
"{0}.so" ,
47
64
"{0}.dylib" ,
48
65
"lib{0}.so" ,
49
66
"lib{0}.dylib" ,
50
67
"{0}.bundle"
51
68
} ;
52
- break ;
53
- default :
54
- loadImage = LoadLibrary ;
55
- resolveSymbol = GetProcAddress ;
56
- formats = new [ ] { "{0}" , "{0}.dll" } ;
57
- break ;
58
69
}
59
70
}
60
71
@@ -113,16 +124,35 @@ public static IntPtr ResolveSymbol(IntPtr image, string symbol)
113
124
114
125
private const int RTLD_LAZY = 0x1 ;
115
126
116
- static IntPtr dlopen ( string path )
127
+ #region LINUX
128
+
129
+ static IntPtr dlopen_linux ( string path )
117
130
{
118
- return dlopen ( path , RTLD_LAZY ) ;
131
+ return dlopen_linux ( path , RTLD_LAZY ) ;
119
132
}
120
133
121
- [ DllImport ( "dl" , CharSet = CharSet . Ansi ) ]
122
- static extern IntPtr dlopen ( string path , int flags ) ;
134
+ [ DllImport ( "dl.so.2" , EntryPoint = "dlopen ", CharSet = CharSet . Ansi ) ]
135
+ static extern IntPtr dlopen_linux ( string path , int flags ) ;
123
136
124
- [ DllImport ( "dl" , CharSet = CharSet . Ansi ) ]
125
- static extern IntPtr dlsym ( IntPtr handle , string symbol ) ;
137
+ [ DllImport ( "dl.so.2" , EntryPoint = "dlsym" , CharSet = CharSet . Ansi ) ]
138
+ static extern IntPtr dlsym_linux ( IntPtr handle , string symbol ) ;
139
+
140
+ #endregion
141
+
142
+ #region MACOS
143
+
144
+ static IntPtr dlopen_macos ( string path )
145
+ {
146
+ return dlopen_macos ( path , RTLD_LAZY ) ;
147
+ }
148
+
149
+ [ DllImport ( "dl" , EntryPoint = "dlopen" , CharSet = CharSet . Ansi ) ]
150
+ static extern IntPtr dlopen_macos ( string path , int flags ) ;
151
+
152
+ [ DllImport ( "dl" , EntryPoint = "dlsym" , CharSet = CharSet . Ansi ) ]
153
+ static extern IntPtr dlsym_macos ( IntPtr handle , string symbol ) ;
154
+
155
+ #endregion
126
156
127
157
#endregion
128
158
0 commit comments