iOS - Platform Checks

Co-authored-by: riperiperi <rhy3756547@hotmail.com>
This commit is contained in:
Isaac Marovitz 2024-01-01 15:35:30 -08:00 committed by Emmanuel Hansen
parent 5d919039d9
commit 66e58aa6a7
21 changed files with 67 additions and 38 deletions

View File

@ -20,7 +20,7 @@ namespace ARMeilleure.CodeGen.Arm64
LinuxFeatureInfoHwCap2 = (LinuxFeatureFlagsHwCap2)getauxval(AT_HWCAP2);
}
if (OperatingSystem.IsMacOS())
if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS())
{
for (int i = 0; i < _sysctlNames.Length; i++)
{
@ -124,12 +124,13 @@ namespace ARMeilleure.CodeGen.Arm64
#endregion
#region macOS
#region Darwin
[LibraryImport("libSystem.dylib", SetLastError = true)]
private static unsafe partial int sysctlbyname([MarshalAs(UnmanagedType.LPStr)] string name, out int oldValue, ref ulong oldSize, IntPtr newValue, ulong newValueSize);
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
private static bool CheckSysctlName(string name)
{
ulong size = sizeof(int);

View File

@ -5,6 +5,7 @@ using System.Runtime.Versioning;
namespace ARMeilleure.Native
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
static partial class JitSupportDarwin
{
[LibraryImport("libarmeilleure-jitsupport", EntryPoint = "armeilleure_jit_memcpy")]

View File

@ -87,13 +87,13 @@ namespace ARMeilleure.Signal
private static Operand GenerateUnixFaultAddress(EmitterContext context, Operand sigInfoPtr)
{
ulong structAddressOffset = OperatingSystem.IsMacOS() ? 24ul : 16ul; // si_addr
ulong structAddressOffset = (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS()) ? 24ul : 16ul; // si_addr
return context.Load(OperandType.I64, context.Add(sigInfoPtr, Const(structAddressOffset)));
}
private static Operand GenerateUnixWriteFlag(EmitterContext context, Operand ucontextPtr)
{
if (OperatingSystem.IsMacOS())
if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS())
{
const ulong McontextOffset = 48; // uc_mcontext
Operand ctxPtr = context.Load(OperandType.I64, context.Add(ucontextPtr, Const(McontextOffset)));

View File

@ -50,6 +50,10 @@ namespace Ryujinx.Common.Configuration
{
appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Application Support");
}
else if (OperatingSystem.IsIOS())
{
appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
else
{
appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

View File

@ -30,15 +30,25 @@ namespace Ryujinx.Common.Logging.Targets
public void Log(object sender, LogEventArgs args)
{
Console.ForegroundColor = GetLogColor(args.Level);
Console.WriteLine(_formatter.Format(args));
Console.ResetColor();
if (OperatingSystem.IsIOS())
{
Console.WriteLine(_formatter.Format(args));
}
else
{
Console.ForegroundColor = GetLogColor(args.Level);
Console.WriteLine(_formatter.Format(args));
Console.ResetColor();
}
}
public void Dispose()
{
GC.SuppressFinalize(this);
Console.ResetColor();
if (!OperatingSystem.IsIOS())
{
Console.ResetColor();
}
}
}
}

View File

@ -40,6 +40,11 @@ namespace Ryujinx.Common
return "Android_1.0";
}
if (OperatingSystem.IsIOS())
{
return "iOS";
}
try
{
return Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
@ -59,7 +64,7 @@ namespace Ryujinx.Common
#else
public static string GetBaseApplicationDirectory()
{
if (IsFlatHubBuild() || OperatingSystem.IsMacOS() || PlatformInfo.IsBionic)
if (IsFlatHubBuild() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || PlatformInfo.IsBionic)
{
return AppDataManager.BaseDirPath;
}

View File

@ -19,7 +19,7 @@ namespace Ryujinx.Common.SystemInterop
public StdErrAdapter()
{
if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS())
{
RegisterPosix();
}
@ -27,6 +27,7 @@ namespace Ryujinx.Common.SystemInterop
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
private void RegisterPosix()
{
const int StdErrFileno = 2;
@ -44,6 +45,7 @@ namespace Ryujinx.Common.SystemInterop
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
private async Task EventWorkerAsync(CancellationToken cancellationToken)
{
using TextReader reader = new StreamReader(_pipeReader, leaveOpen: true);
@ -92,6 +94,7 @@ namespace Ryujinx.Common.SystemInterop
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
private static Stream CreateFileDescriptorStream(int fd)
{
return new FileStream(

View File

@ -88,7 +88,7 @@ namespace Ryujinx.Cpu.Signal
ref SignalHandlerConfig config = ref GetConfigRef();
if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || PlatformInfo.IsBionic)
if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || PlatformInfo.IsBionic || OperatingSystem.IsIOS())
{
_signalHandlerPtr = MapCode(NativeSignalHandlerGenerator.GenerateUnixSignalHandler(_handlerConfig, rangeStructSize, pageSize));

View File

@ -135,7 +135,7 @@ namespace Ryujinx.Cpu.Signal
throw new SystemException($"Could not register SIGSEGV sigaction. Error: {Marshal.GetLastPInvokeErrorMessage()}");
}
if (OperatingSystem.IsMacOS())
if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS())
{
result = sigaction(SIGBUS, ref sig, out _);
@ -249,7 +249,7 @@ namespace Ryujinx.Cpu.Signal
{
bool success = sigaction(SIGSEGV, ref oldAction, out SigAction _) == 0;
if (success && OperatingSystem.IsMacOS())
if (success && (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS()))
{
success = sigaction(SIGBUS, ref oldAction, out SigAction _) == 0;
}

View File

@ -6,6 +6,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Graphics.Vulkan.MoltenVK
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
public static partial class MVKInitialization
{
[LibraryImport("libMoltenVK.dylib")]

View File

@ -103,11 +103,11 @@ namespace Ryujinx.Graphics.Vulkan
Textures = new HashSet<ITexture>();
Samplers = new HashSet<SamplerHolder>();
if (OperatingSystem.IsMacOS())
if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS())
{
MVKInitialization.Initialize();
// Any device running on MacOS is using MoltenVK, even Intel and AMD vendors.
// Any device running on Darwin is using MoltenVK, even Intel and AMD vendors.
IsMoltenVk = true;
}
}

View File

@ -15,7 +15,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types
public IpAddressSetting(IPInterfaceProperties interfaceProperties, UnicastIPAddressInformation unicastIPAddressInformation)
{
IsDhcpEnabled = OperatingSystem.IsMacOS() || interfaceProperties.DhcpServerAddresses.Count != 0;
IsDhcpEnabled = (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS()) || interfaceProperties.DhcpServerAddresses.Count != 0;
Address = new IpV4Address(unicastIPAddressInformation.Address);
IPv4Mask = new IpV4Address(unicastIPAddressInformation.IPv4Mask);
GatewayAddress = (interfaceProperties.GatewayAddresses.Count == 0) ? new IpV4Address() : new IpV4Address(interfaceProperties.GatewayAddresses[0].Address);

View File

@ -91,7 +91,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl
{ 0, 0 },
};
private static readonly Dictionary<int, LinuxError> _errorMapMacOs = new()
private static readonly Dictionary<int, LinuxError> _errorMapDarwin = new()
{
{ 35, LinuxError.EAGAIN },
{ 11, LinuxError.EDEADLOCK },
@ -283,9 +283,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl
public static LinuxError ConvertError(WsaError errorCode)
{
if (OperatingSystem.IsMacOS())
if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS())
{
if (_errorMapMacOs.TryGetValue((int)errorCode, out LinuxError errno))
if (_errorMapDarwin.TryGetValue((int)errorCode, out LinuxError errno))
{
return errno;
}

View File

@ -343,12 +343,12 @@ namespace Ryujinx.Headless.SDL2
GraphicsConfig.EnableShaderCache = true;
if (OperatingSystem.IsMacOS())
if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS())
{
if (option.GraphicsBackend == GraphicsBackend.OpenGl)
{
option.GraphicsBackend = GraphicsBackend.Vulkan;
Logger.Warning?.Print(LogClass.Application, "OpenGL is not supported on macOS, switching to Vulkan!");
Logger.Warning?.Print(LogClass.Application, "OpenGL is not supported on Darwin, switching to Vulkan!");
}
}

View File

@ -426,7 +426,7 @@ namespace Ryujinx.Memory
return OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17134);
}
return OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic;
return OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic;
}
return true;

View File

@ -10,7 +10,7 @@ namespace Ryujinx.Memory
{
return MemoryManagementWindows.Allocate((IntPtr)size);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic)
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic)
{
return MemoryManagementUnix.Allocate(size, forJit);
}
@ -26,7 +26,7 @@ namespace Ryujinx.Memory
{
return MemoryManagementWindows.Reserve((IntPtr)size, viewCompatible);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic)
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic)
{
return MemoryManagementUnix.Reserve(size, forJit);
}
@ -42,7 +42,7 @@ namespace Ryujinx.Memory
{
MemoryManagementWindows.Commit(address, (IntPtr)size);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic)
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic)
{
MemoryManagementUnix.Commit(address, size, forJit);
}
@ -58,7 +58,7 @@ namespace Ryujinx.Memory
{
MemoryManagementWindows.Decommit(address, (IntPtr)size);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic)
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic)
{
MemoryManagementUnix.Decommit(address, size);
}
@ -74,7 +74,7 @@ namespace Ryujinx.Memory
{
MemoryManagementWindows.MapView(sharedMemory, srcOffset, address, (IntPtr)size, owner);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic)
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic)
{
MemoryManagementUnix.MapView(sharedMemory, srcOffset, address, size);
}
@ -90,7 +90,7 @@ namespace Ryujinx.Memory
{
MemoryManagementWindows.UnmapView(sharedMemory, address, (IntPtr)size, owner);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic)
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic)
{
MemoryManagementUnix.UnmapView(address, size);
}
@ -108,7 +108,7 @@ namespace Ryujinx.Memory
{
result = MemoryManagementWindows.Reprotect(address, (IntPtr)size, permission, forView);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic)
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic)
{
result = MemoryManagementUnix.Reprotect(address, size, permission);
}
@ -129,7 +129,7 @@ namespace Ryujinx.Memory
{
return MemoryManagementWindows.Free(address, (IntPtr)size);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic)
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic)
{
return MemoryManagementUnix.Free(address);
}
@ -145,7 +145,7 @@ namespace Ryujinx.Memory
{
return MemoryManagementWindows.CreateSharedMemory((IntPtr)size, reserve);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic)
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic)
{
return MemoryManagementUnix.CreateSharedMemory(size, reserve);
}
@ -161,7 +161,7 @@ namespace Ryujinx.Memory
{
MemoryManagementWindows.DestroySharedMemory(handle);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic)
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic)
{
MemoryManagementUnix.DestroySharedMemory(handle);
}
@ -177,7 +177,7 @@ namespace Ryujinx.Memory
{
return MemoryManagementWindows.MapSharedMemory(handle);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic)
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic)
{
return MemoryManagementUnix.MapSharedMemory(handle, size);
}
@ -193,7 +193,7 @@ namespace Ryujinx.Memory
{
MemoryManagementWindows.UnmapSharedMemory(address);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || Ryujinx.Common.PlatformInfo.IsBionic)
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || Ryujinx.Common.PlatformInfo.IsBionic)
{
MemoryManagementUnix.UnmapSharedMemory(address, size);
}

View File

@ -9,6 +9,7 @@ namespace Ryujinx.Memory
{
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
[SupportedOSPlatform("android")]
static class MemoryManagementUnix
{

View File

@ -6,6 +6,7 @@ namespace Ryujinx.Memory
{
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
public static partial class MemoryManagerUnixHelper
{
[Flags]
@ -117,7 +118,7 @@ namespace Ryujinx.Memory
{
result |= MAP_ANONYMOUS_LINUX_GENERIC;
}
else if (OperatingSystem.IsMacOS())
else if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS())
{
result |= MAP_ANONYMOUS_DARWIN;
}
@ -133,7 +134,7 @@ namespace Ryujinx.Memory
{
result |= MAP_NORESERVE_LINUX_GENERIC;
}
else if (OperatingSystem.IsMacOS())
else if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS())
{
result |= MAP_NORESERVE_DARWIN;
}
@ -149,7 +150,7 @@ namespace Ryujinx.Memory
{
result |= MAP_UNLOCKED_LINUX_GENERIC;
}
else if (OperatingSystem.IsMacOS())
else if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS())
{
// FIXME: Doesn't exist on Darwin
}

View File

@ -1536,7 +1536,7 @@ namespace Ryujinx.Ui.Common.Configuration
{
// Any system running macOS or returning any amount of valid Vulkan devices should default to Vulkan.
// Checks for if the Vulkan version and featureset is compatible should be performed within VulkanRenderer.
if (OperatingSystem.IsMacOS() || VulkanRenderer.GetPhysicalDevices().Length > 0)
if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || VulkanRenderer.GetPhysicalDevices().Length > 0)
{
return GraphicsBackend.Vulkan;
}

View File

@ -5,6 +5,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Ui.Common.Helper
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
public static partial class ObjectiveC
{
private const string ObjCRuntime = "/usr/lib/libobjc.A.dylib";

View File

@ -8,6 +8,7 @@ namespace Ryujinx.Ui.Helper
public delegate void UpdateBoundsCallbackDelegate(Window window);
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
static partial class MetalHelper
{
private const string LibObjCImport = "/usr/lib/libobjc.A.dylib";