Skip to content

Commit

Permalink
fix last issue in #2951 properly
Browse files Browse the repository at this point in the history
  • Loading branch information
CasualPokePlayer committed Apr 10, 2023
1 parent ffd8e68 commit 03aa420
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions ExternalProjects/NLua/src/Native/LuaState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ bool TryLoad(string name)
{
if (TryLoad(luaSo))
{
resolver.UnixMakeGlobal(luaSo);
NativeMethods = isLua54
? BizInvoker.GetInvoker<Lua54NativeMethods>(resolver, CallingConventionAdapters.Native)
: BizInvoker.GetInvoker<Lua53NativeMethods>(resolver, CallingConventionAdapters.Native);
Expand Down
Binary file modified References/NLua.dll
Binary file not shown.
21 changes: 21 additions & 0 deletions src/BizHawk.Common/IImportResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ private static string UnixResolveFilePath(string orig) => orig.IsAbsolute()
})
?? 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 */);

This comment has been minimized.

Copy link
@YoshiRulz

YoshiRulz Apr 10, 2023

Member

Can use local consts for this, and also this should go in the ILinkedLibManager impl with the others.

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;
Expand Down

0 comments on commit 03aa420

Please sign in to comment.