Ryujinx-uplift/Ryujinx.Common/SystemInfo/MacOSSysteminfo.cs
mageven a33dc2f491
Improved Logger (#1292)
* Logger class changes only

Now compile-time checking is possible with the help of Nullable Value
types.

* Misc formatting

* Manual optimizations

PrintGuestLog
PrintGuestStackTrace
Surfaceflinger DequeueBuffer

* Reduce SendVibrationXX log level to Debug

* Add Notice log level

This level is always enabled and used to print system info, etc...
Also, rewrite LogColor to switch expression as colors are static

* Unify unhandled exception event handlers

* Print enabled LogLevels during init

* Re-add App Exit disposes in proper order

nit: switch case spacing

* Revert PrintGuestStackTrace to Info logs due to #1407

PrintGuestStackTrace is now called in some critical error handlers
so revert to old behavior as KThread isn't part of Guest.

* Batch replace Logger statements
2020-08-04 01:32:53 +02:00

97 lines
2.6 KiB
C#

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using Ryujinx.Common.Logging;
namespace Ryujinx.Common.SystemInfo
{
internal class MacOSSysteminfo : SystemInfo
{
public override string CpuName { get; }
public override ulong RamSize { get; }
[DllImport("libSystem.dylib", CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int sysctlbyname(string name, IntPtr oldValue, ref ulong oldSize, IntPtr newValue, ulong newValueSize);
private static int sysctlbyname(string name, IntPtr oldValue, ref ulong oldSize)
{
if (sysctlbyname(name, oldValue, ref oldSize, IntPtr.Zero, 0) == -1)
{
return Marshal.GetLastWin32Error();
}
return 0;
}
private static int sysctlbyname<T>(string name, ref T oldValue)
{
unsafe
{
ulong oldValueSize = (ulong)Unsafe.SizeOf<T>();
return sysctlbyname(name, (IntPtr)Unsafe.AsPointer(ref oldValue), ref oldValueSize);
}
}
private static int sysctlbyname(string name, out string oldValue)
{
oldValue = default;
ulong strSize = 0;
int res = sysctlbyname(name, IntPtr.Zero, ref strSize);
if (res == 0)
{
byte[] rawData = new byte[strSize];
unsafe
{
fixed (byte* rawDataPtr = rawData)
{
res = sysctlbyname(name, (IntPtr)rawDataPtr, ref strSize);
}
if (res == 0)
{
oldValue = Encoding.ASCII.GetString(rawData);
}
}
}
return res;
}
public MacOSSysteminfo()
{
ulong ramSize = 0;
int res = sysctlbyname("hw.memsize", ref ramSize);
if (res == 0)
{
RamSize = ramSize;
}
else
{
Logger.Error?.Print(LogClass.Application, $"Cannot get memory size, sysctlbyname error: {res}");
RamSize = 0;
}
res = sysctlbyname("machdep.cpu.brand_string", out string cpuName);
if (res == 0)
{
CpuName = cpuName;
}
else
{
Logger.Error?.Print(LogClass.Application, $"Cannot get CPU name, sysctlbyname error: {res}");
CpuName = "Unknown";
}
}
}
}