A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System;
5using System.Diagnostics;
6using System.IO;
7using System.Runtime.InteropServices;
8
9namespace osu.Framework.Platform.Linux.Native
10{
11 public static class Library
12 {
13 [DllImport("libdl.so.2", EntryPoint = "dlopen")]
14 private static extern IntPtr dlopen(string library, LoadFlags flags);
15
16 /// <summary>
17 /// Loads a library with flags to use with dlopen. Uses <see cref="LoadFlags"/> for the flags
18 ///
19 /// Uses NATIVE_DLL_SEARCH_DIRECTORIES and then ld.so for library paths
20 /// </summary>
21 /// <param name="library">Full name of the library</param>
22 /// <param name="flags">See 'man dlopen' for more information.</param>
23 public static void Load(string library, LoadFlags flags)
24 {
25 var paths = (string)AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES");
26 Debug.Assert(paths != null);
27
28 foreach (var path in paths.Split(':'))
29 {
30 if (dlopen(Path.Combine(path, library), flags) != IntPtr.Zero)
31 break;
32 }
33 }
34
35 [Flags]
36 public enum LoadFlags
37 {
38 RTLD_LAZY = 0x00001,
39 RTLD_NOW = 0x00002,
40 RTLD_BINDING_MASK = 0x00003,
41 RTLD_NOLOAD = 0x00004,
42 RTLD_DEEPBIND = 0x00008,
43 RTLD_GLOBAL = 0x00100,
44 RTLD_LOCAL = 0x00000,
45 RTLD_NODELETE = 0x01000
46 }
47 }
48}