IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ClassLoader.NativeLibrary.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2007-2014 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24using System;
25using System.IO;
26using System.Runtime.InteropServices;
27using System.Security;
28using System.Threading;
29
30using IKVM.Runtime;
32
34{
35
36 static partial class ClassLoader
37 {
38
44 public static string findBuiltinLib(string name)
45 {
46#if FIRST_PASS
47 throw new NotImplementedException();
48#else
49 if (name == null)
50 throw new global::java.lang.InternalError("NULL filename for native library.");
51
52 var l = GetUnmappedLibraryName(name);
53 return IsBuiltinLib(l) ? l : null;
54#endif
55 }
56
62 static bool IsBuiltinLib(string name)
63 {
64 // a built-in library is one who's symbols are directly on the process module
65 // IKVM includes no such libraries
66 return false;
67 }
68
74 static string GetUnmappedLibraryName(string name)
75 {
76 if (name == null)
77 return null;
78
79 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
80 {
81 return Path.GetFileNameWithoutExtension(name);
82 }
83 else
84 {
85 if (name.StartsWith("lib"))
86 return Path.GetFileNameWithoutExtension(name).Substring(3);
87 else
88 return Path.GetFileNameWithoutExtension(name);
89 }
90 }
91
92 internal static class NativeLibrary
93 {
94
101 public static void load(object self, string name, bool isBuiltin)
102 {
103#if FIRST_PASS
104 throw new NotImplementedException();
105#else
106 var lib = (global::java.lang.ClassLoader.NativeLibrary)self;
107 lib.handle = isBuiltin ? 0 : JNINativeLoader.LoadLibrary(name, RuntimeJavaType.FromClass(global::java.lang.ClassLoader.NativeLibrary.getFromClass()));
108 lib.loaded = true;
109#endif
110 }
111
119 public static long find(object self, string name)
120 {
121 throw new NotImplementedException();
122 }
123
130 [SecuritySafeCritical]
131 public static void unload(object thisNativeLibrary, string name, bool isBuiltin)
132 {
133#if FIRST_PASS
134 throw new NotImplementedException();
135#else
136 if (isBuiltin == false)
137 {
138 var lib = (global::java.lang.ClassLoader.NativeLibrary)thisNativeLibrary;
139 var handle = Interlocked.Exchange(ref lib.handle, 0);
140 if (handle != 0)
141 JNINativeLoader.UnloadLibrary(handle, RuntimeJavaType.FromClass(global::java.lang.ClassLoader.NativeLibrary.getFromClass()));
142 }
143#endif
144 }
145
146 }
147
148 }
149
150}
System.Threading.Interlocked Interlocked
static string findBuiltinLib(string name)
Finds the builtin native library, or returns null if the given name isn't built in.
static void UnloadLibrary(long handle, RuntimeJavaType fromClass)
Initiates an unload of the given native library for the specified class loader.
static long LoadLibrary(string filename, RuntimeJavaType fromClass)
Initiates a load of the given JNI library by the specified class loader.
Provides methods to load libraries from standard .NET search locations. This class is not used to loa...