forked from trungnt2910/MemoryModule.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeAssemblyImpl.cs
More file actions
72 lines (60 loc) · 3.01 KB
/
Copy pathNativeAssemblyImpl.cs
File metadata and controls
72 lines (60 loc) · 3.01 KB
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
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace MemoryModule
{
/// <summary>
/// Implementation abstraction for Windows and Linux
/// </summary>
internal static unsafe class NativeAssemblyImpl
{
#region Delegates
public delegate IntPtr PlatformLoadLibraryFunc(
byte* dataPtr,
long length,
CustomAllocFunc allocMemory = null,
CustomFreeFunc freeMemory = null,
CustomLoadLibraryFunc loadLibrary = null,
CustomGetProcAddressFunc getProcAddress = null,
CustomFreeLibraryFunc freeLibrary = null);
public delegate bool PlatformFreeLibraryFunc(IntPtr handle);
public delegate IntPtr PlatformGetSymbolFunc(IntPtr module, string name);
internal delegate void* PlatformGetSymbolUnsafeFunc(void* module, char* name);
#endregion
public static readonly PlatformLoadLibraryFunc LoadLibrary;
public static readonly PlatformFreeLibraryFunc FreeLibrary;
public static readonly PlatformGetSymbolFunc GetSymbol;
public static readonly CustomLoadLibraryFunc MemoryDefaultLoadLibrary;
public static readonly CustomFreeLibraryFunc MemoryDefaultFreeLibrary;
public static readonly CustomGetProcAddressFunc MemoryDefaultGetProcAddress;
internal static readonly PlatformGetSymbolUnsafeFunc GetSymbolUnsafe;
static NativeAssemblyImpl()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
LoadLibrary = Windows.NativeAssemblyImpl.LoadLibrary;
FreeLibrary = Windows.NativeAssemblyImpl.FreeLibrary;
GetSymbol = Windows.NativeAssemblyImpl.GetSymbol;
MemoryDefaultLoadLibrary = Windows.NativeAssemblyImpl.MemoryDefaultLoadLibrary;
MemoryDefaultFreeLibrary = Windows.NativeAssemblyImpl.MemoryDefaultFreeLibrary;
MemoryDefaultGetProcAddress = Windows.NativeAssemblyImpl.MemoryDefaultGetProcAddress;
GetSymbolUnsafe = Windows.NativeAssemblyImpl.GetSymbolUnsafe;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
LoadLibrary = Linux.NativeAssemblyImpl.LoadLibrary;
FreeLibrary = Linux.NativeAssemblyImpl.FreeLibrary;
GetSymbol = Linux.NativeAssemblyImpl.GetSymbol;
MemoryDefaultLoadLibrary = Linux.NativeAssemblyImpl.MemoryDefaultLoadLibrary;
MemoryDefaultFreeLibrary = Linux.NativeAssemblyImpl.MemoryDefaultFreeLibrary;
MemoryDefaultGetProcAddress = Linux.NativeAssemblyImpl.MemoryDefaultGetProcAddress;
GetSymbolUnsafe = Linux.NativeAssemblyImpl.GetSymbolUnsafe;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
throw new NotImplementedException("MacOS is not implemented yet! Consider helping us!");
}
}
}
}