fix last issue in #2951 properly

This commit is contained in:
CasualPokePlayer 2023-04-09 23:41:42 -07:00
parent ffd8e6897a
commit 03aa420bd5
3 changed files with 22 additions and 0 deletions

View File

@ -57,6 +57,7 @@ namespace NLua
{
if (TryLoad(luaSo))
{
resolver.UnixMakeGlobal(luaSo);
NativeMethods = isLua54
? BizInvoker.GetInvoker<Lua54NativeMethods>(resolver, CallingConventionAdapters.Native)
: BizInvoker.GetInvoker<Lua53NativeMethods>(resolver, CallingConventionAdapters.Native);

Binary file not shown.

View File

@ -44,6 +44,27 @@ namespace BizHawk.Common
})
?? orig; // don't MakeAbsolute, just pass through and hope something lower-level magically makes it work
// hack for Lua since it needs to be opened as global for modules to find lua symbols
[DllImport("libdl.so.2")]
private static extern IntPtr dlopen(string fileName, int flags);
public void UnixMakeGlobal(string path)
{
if (!OSTailoredCode.IsUnixHost)
{
throw new NotSupportedException("This method is not suitable for non-Unix hosts");
}
OSTailoredCode.LinkedLibManager.FreeByPtr(_p);
path = UnixResolveFilePath(path);
_p = dlopen(path, 0x102 /* RTLD_NOW | RTLD_GLOBAL */);
if (_p == IntPtr.Zero)
{
// I guess RTLD_GLOBAL isn't supported?
Console.WriteLine($"Attempt to globalize {path} failed! Reverting back to local load...");
_p = OSTailoredCode.LinkedLibManager.LoadOrThrow(path);
}
}
private IntPtr _p;
public readonly bool HasLimitedLifetime;