mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2024-11-15 09:35:27 +00:00
Remove usage of Mono.Posix.NETStandard accross all projects (#2906)
* Remove usage of Mono.Posix.NETStandard in Ryujinx project * Remove usage of Mono.Posix.NETStandard in ARMeilleure project * Remove usage of Mono.Posix.NETStandard in Ryujinx.Memory project * Address gdkchan's comments
This commit is contained in:
parent
bc4e70b6fa
commit
00c69f2098
|
@ -5,10 +5,6 @@
|
|||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Mono.Posix.NETStandard" Version="5.20.1-preview" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ryujinx.Common\Ryujinx.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Mono.Unix.Native;
|
||||
using System;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ARMeilleure.Signal
|
||||
|
@ -21,6 +20,7 @@ namespace ARMeilleure.Signal
|
|||
|
||||
static class UnixSignalHandlerRegistration
|
||||
{
|
||||
private const int SIGSEGV = 11;
|
||||
private const int SA_SIGINFO = 0x00000004;
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
|
@ -39,7 +39,7 @@ namespace ARMeilleure.Signal
|
|||
|
||||
sigemptyset(ref sig.sa_mask);
|
||||
|
||||
int result = sigaction((int)Signum.SIGSEGV, ref sig, out SigAction old);
|
||||
int result = sigaction(SIGSEGV, ref sig, out SigAction old);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ namespace ARMeilleure.Signal
|
|||
|
||||
public static bool RestoreExceptionHandler(SigAction oldAction)
|
||||
{
|
||||
return sigaction((int)Signum.SIGSEGV, ref oldAction, out SigAction _) == 0;
|
||||
return sigaction(SIGSEGV, ref oldAction, out SigAction _) == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
using Mono.Unix.Native;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
using static Ryujinx.Memory.MemoryManagerUnixHelper;
|
||||
|
||||
namespace Ryujinx.Memory
|
||||
{
|
||||
[SupportedOSPlatform("linux")]
|
||||
|
@ -18,15 +19,6 @@ namespace Ryujinx.Memory
|
|||
public IntPtr SourcePointer;
|
||||
}
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
public static extern IntPtr mremap(IntPtr old_address, ulong old_size, ulong new_size, MremapFlags flags, IntPtr new_address);
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
public static extern int madvise(IntPtr address, ulong size, int advice);
|
||||
|
||||
private const int MADV_DONTNEED = 4;
|
||||
private const int MADV_REMOVE = 9;
|
||||
|
||||
private static readonly List<UnixSharedMemory> _sharedMemory = new List<UnixSharedMemory>();
|
||||
private static readonly ConcurrentDictionary<IntPtr, ulong> _sharedMemorySource = new ConcurrentDictionary<IntPtr, ulong>();
|
||||
private static readonly ConcurrentDictionary<IntPtr, ulong> _allocations = new ConcurrentDictionary<IntPtr, ulong>();
|
||||
|
@ -47,7 +39,7 @@ namespace Ryujinx.Memory
|
|||
|
||||
if (shared)
|
||||
{
|
||||
flags |= MmapFlags.MAP_SHARED | (MmapFlags)0x80000;
|
||||
flags |= MmapFlags.MAP_SHARED | MmapFlags.MAP_UNLOCKED;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -59,7 +51,7 @@ namespace Ryujinx.Memory
|
|||
flags |= MmapFlags.MAP_NORESERVE;
|
||||
}
|
||||
|
||||
IntPtr ptr = Syscall.mmap(IntPtr.Zero, size, prot, flags, -1, 0);
|
||||
IntPtr ptr = mmap(IntPtr.Zero, size, prot, flags, -1, 0);
|
||||
|
||||
if (ptr == new IntPtr(-1L))
|
||||
{
|
||||
|
@ -77,7 +69,7 @@ namespace Ryujinx.Memory
|
|||
|
||||
public static bool Commit(IntPtr address, ulong size)
|
||||
{
|
||||
bool success = Syscall.mprotect(address, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE) == 0;
|
||||
bool success = mprotect(address, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE) == 0;
|
||||
|
||||
if (success)
|
||||
{
|
||||
|
@ -87,7 +79,7 @@ namespace Ryujinx.Memory
|
|||
{
|
||||
ulong sharedAddress = ((ulong)address - (ulong)shared.SourcePointer) + (ulong)shared.Pointer;
|
||||
|
||||
if (Syscall.mprotect((IntPtr)sharedAddress, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE) != 0)
|
||||
if (mprotect((IntPtr)sharedAddress, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -108,16 +100,16 @@ namespace Ryujinx.Memory
|
|||
}
|
||||
|
||||
// Must be writable for madvise to work properly.
|
||||
Syscall.mprotect(address, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE);
|
||||
mprotect(address, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE);
|
||||
|
||||
madvise(address, size, isShared ? MADV_REMOVE : MADV_DONTNEED);
|
||||
|
||||
return Syscall.mprotect(address, size, MmapProts.PROT_NONE) == 0;
|
||||
return mprotect(address, size, MmapProts.PROT_NONE) == 0;
|
||||
}
|
||||
|
||||
public static bool Reprotect(IntPtr address, ulong size, MemoryPermission permission)
|
||||
{
|
||||
return Syscall.mprotect(address, size, GetProtection(permission)) == 0;
|
||||
return mprotect(address, size, GetProtection(permission)) == 0;
|
||||
}
|
||||
|
||||
private static MmapProts GetProtection(MemoryPermission permission)
|
||||
|
@ -138,7 +130,7 @@ namespace Ryujinx.Memory
|
|||
{
|
||||
if (_allocations.TryRemove(address, out ulong size))
|
||||
{
|
||||
return Syscall.munmap(address, size) == 0;
|
||||
return munmap(address, size) == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -146,14 +138,14 @@ namespace Ryujinx.Memory
|
|||
|
||||
public static IntPtr Remap(IntPtr target, IntPtr source, ulong size)
|
||||
{
|
||||
int flags = (int)MremapFlags.MREMAP_MAYMOVE;
|
||||
int flags = 1;
|
||||
|
||||
if (target != IntPtr.Zero)
|
||||
{
|
||||
flags |= 2;
|
||||
}
|
||||
|
||||
IntPtr result = mremap(source, 0, size, (MremapFlags)(flags), target);
|
||||
IntPtr result = mremap(source, 0, size, flags, target);
|
||||
|
||||
if (result == IntPtr.Zero)
|
||||
{
|
||||
|
|
128
Ryujinx.Memory/MemoryManagerUnixHelper.cs
Normal file
128
Ryujinx.Memory/MemoryManagerUnixHelper.cs
Normal file
|
@ -0,0 +1,128 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Memory
|
||||
{
|
||||
public static class MemoryManagerUnixHelper
|
||||
{
|
||||
[Flags]
|
||||
public enum MmapProts : uint
|
||||
{
|
||||
PROT_NONE = 0,
|
||||
PROT_READ = 1,
|
||||
PROT_WRITE = 2,
|
||||
PROT_EXEC = 4
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum MmapFlags : uint
|
||||
{
|
||||
MAP_SHARED = 1,
|
||||
MAP_PRIVATE = 2,
|
||||
MAP_ANONYMOUS = 4,
|
||||
MAP_NORESERVE = 8,
|
||||
MAP_UNLOCKED = 16
|
||||
}
|
||||
|
||||
private const int MAP_ANONYMOUS_LINUX_GENERIC = 0x20;
|
||||
private const int MAP_NORESERVE_LINUX_GENERIC = 0x4000;
|
||||
private const int MAP_UNLOCKED_LINUX_GENERIC = 0x80000;
|
||||
|
||||
private const int MAP_NORESERVE_DARWIN = 0x40;
|
||||
private const int MAP_JIT_DARWIN = 0x800;
|
||||
private const int MAP_ANONYMOUS_DARWIN = 0x1000;
|
||||
|
||||
public const int MADV_DONTNEED = 4;
|
||||
public const int MADV_REMOVE = 9;
|
||||
|
||||
[DllImport("libc", EntryPoint = "mmap", SetLastError = true)]
|
||||
private static extern IntPtr Internal_mmap(IntPtr address, ulong length, MmapProts prot, int flags, int fd, long offset);
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
public static extern int mprotect(IntPtr address, ulong length, MmapProts prot);
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
public static extern int munmap(IntPtr address, ulong length);
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
public static extern IntPtr mremap(IntPtr old_address, ulong old_size, ulong new_size, int flags, IntPtr new_address);
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
public static extern int madvise(IntPtr address, ulong size, int advice);
|
||||
|
||||
private static int MmapFlagsToSystemFlags(MmapFlags flags)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (flags.HasFlag(MmapFlags.MAP_SHARED))
|
||||
{
|
||||
result |= (int)MmapFlags.MAP_SHARED;
|
||||
}
|
||||
|
||||
if (flags.HasFlag(MmapFlags.MAP_PRIVATE))
|
||||
{
|
||||
result |= (int)MmapFlags.MAP_PRIVATE;
|
||||
}
|
||||
|
||||
if (flags.HasFlag(MmapFlags.MAP_ANONYMOUS))
|
||||
{
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
result |= MAP_ANONYMOUS_LINUX_GENERIC;
|
||||
}
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
result |= MAP_ANONYMOUS_DARWIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
if (flags.HasFlag(MmapFlags.MAP_NORESERVE))
|
||||
{
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
result |= MAP_NORESERVE_LINUX_GENERIC;
|
||||
}
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
result |= MAP_NORESERVE_DARWIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
if (flags.HasFlag(MmapFlags.MAP_UNLOCKED))
|
||||
{
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
result |= MAP_UNLOCKED_LINUX_GENERIC;
|
||||
}
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
// FIXME: Doesn't exist on Darwin
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
if (OperatingSystem.IsMacOSVersionAtLeast(10, 14))
|
||||
{
|
||||
result |= MAP_JIT_DARWIN;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IntPtr mmap(IntPtr address, ulong length, MmapProts prot, MmapFlags flags, int fd, long offset)
|
||||
{
|
||||
return Internal_mmap(address, length, prot, MmapFlagsToSystemFlags(flags), fd, offset);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,10 +5,6 @@
|
|||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Mono.Posix.NETStandard" Version="5.20.1-preview" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ryujinx.Common\Ryujinx.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
using Gdk;
|
||||
using Gtk;
|
||||
using Mono.Unix;
|
||||
using Ryujinx.Ui;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Modules
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@ using Gtk;
|
|||
using ICSharpCode.SharpZipLib.GZip;
|
||||
using ICSharpCode.SharpZipLib.Tar;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using Mono.Unix;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Ui;
|
||||
|
@ -355,14 +354,16 @@ namespace Ryujinx.Modules
|
|||
worker.Start();
|
||||
}
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
private static extern int chmod(string path, uint mode);
|
||||
|
||||
private static void SetUnixPermissions()
|
||||
{
|
||||
string ryuBin = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Ryujinx");
|
||||
|
||||
if (!OperatingSystem.IsWindows())
|
||||
{
|
||||
UnixFileInfo unixFileInfo = new UnixFileInfo(ryuBin);
|
||||
unixFileInfo.FileAccessPermissions |= FileAccessPermissions.UserExecute;
|
||||
chmod(ryuBin, 0777);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,9 +61,6 @@ namespace Ryujinx
|
|||
}
|
||||
}
|
||||
|
||||
// Enforce loading of Mono.Posix to avoid .NET runtime lazy loading it during an update.
|
||||
Assembly.Load("Mono.Posix.NETStandard");
|
||||
|
||||
// Make process DPI aware for proper window sizing on high-res screens.
|
||||
ForceDpiAware.Windows();
|
||||
WindowScaleFactor = ForceDpiAware.GetWindowScaleFactor();
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
<PackageReference Include="OpenTK.Graphics" Version="4.5.0" />
|
||||
<PackageReference Include="SPB" Version="0.0.3-build15" />
|
||||
<PackageReference Include="SharpZipLib" Version="1.3.3" />
|
||||
<PackageReference Include="Mono.Posix.NETStandard" Version="5.20.1-preview" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Reference in a new issue