Archived
1
0
Fork 0
forked from Mirror/Ryujinx

Replace DllImport usage with LibraryImport (#4084)

* Replace usage of `DllImport` with `LibraryImport`

* Mark methods as `partial`

* Marshalling

* More `partial` & marshalling

* More `partial` and marshalling

* More partial and marshalling

* Update GdiPlusHelper to LibraryImport

* Unicorn

* More Partial

* Marshal

* Specify EntryPoint

* Specify EntryPoint

* Change GlobalMemoryStatusEx to LibraryImport

* Change RegisterClassEx to LibraryImport

* Define EntryPoints

* Update Ryujinx.Ava/Ui/Controls/Win32NativeInterop.cs

Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>

* Update Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs

Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>

* Move return mashal

* Remove calling convention specification

* Remove calling conventions

* Update Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs

Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>

* Update Ryujinx/Modules/Updater/Updater.cs

Co-authored-by: Mary-nyan <thog@protonmail.com>

* Update Ryujinx.Ava/Modules/Updater/Updater.cs

Co-authored-by: Mary-nyan <thog@protonmail.com>

Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
Co-authored-by: Mary-nyan <thog@protonmail.com>
This commit is contained in:
Isaac Marovitz 2022-12-15 12:07:31 -05:00 committed by GitHub
parent f4d731ae20
commit 0fbcd630bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 308 additions and 299 deletions

View file

@ -18,17 +18,17 @@ namespace ARMeilleure.Signal
public IntPtr sa_restorer; public IntPtr sa_restorer;
} }
static class UnixSignalHandlerRegistration static partial class UnixSignalHandlerRegistration
{ {
private const int SIGSEGV = 11; private const int SIGSEGV = 11;
private const int SIGBUS = 10; private const int SIGBUS = 10;
private const int SA_SIGINFO = 0x00000004; private const int SA_SIGINFO = 0x00000004;
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
private static extern int sigaction(int signum, ref SigAction sigAction, out SigAction oldAction); private static partial int sigaction(int signum, ref SigAction sigAction, out SigAction oldAction);
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
private static extern int sigemptyset(ref SigSet set); private static partial int sigemptyset(ref SigSet set);
public static SigAction RegisterExceptionHandler(IntPtr action) public static SigAction RegisterExceptionHandler(IntPtr action)
{ {

View file

@ -3,19 +3,19 @@ using System.Runtime.InteropServices;
namespace ARMeilleure.Signal namespace ARMeilleure.Signal
{ {
unsafe class WindowsSignalHandlerRegistration unsafe partial class WindowsSignalHandlerRegistration
{ {
[DllImport("kernel32.dll")] [LibraryImport("kernel32.dll")]
private static extern IntPtr AddVectoredExceptionHandler(uint first, IntPtr handler); private static partial IntPtr AddVectoredExceptionHandler(uint first, IntPtr handler);
[DllImport("kernel32.dll")] [LibraryImport("kernel32.dll")]
private static extern ulong RemoveVectoredExceptionHandler(IntPtr handle); private static partial ulong RemoveVectoredExceptionHandler(IntPtr handle);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)] [LibraryImport("kernel32.dll", SetLastError = true, EntryPoint = "LoadLibraryA")]
static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName); private static partial IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName);
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)] [LibraryImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr GetProcAddress(IntPtr hModule, string procName); private static partial IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string procName);
private static IntPtr _getCurrentThreadIdPtr; private static IntPtr _getCurrentThreadIdPtr;

View file

@ -7,7 +7,7 @@ using System.Runtime.InteropServices;
namespace ARMeilleure.Translation.Cache namespace ARMeilleure.Translation.Cache
{ {
static class JitUnwindWindows static partial class JitUnwindWindows
{ {
private const int MaxUnwindCodesArraySize = 32; // Must be an even value. private const int MaxUnwindCodesArraySize = 32; // Must be an even value.
@ -42,14 +42,15 @@ namespace ARMeilleure.Translation.Cache
private unsafe delegate RuntimeFunction* GetRuntimeFunctionCallback(ulong controlPc, IntPtr context); private unsafe delegate RuntimeFunction* GetRuntimeFunctionCallback(ulong controlPc, IntPtr context);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] [LibraryImport("kernel32.dll")]
private static unsafe extern bool RtlInstallFunctionTableCallback( [return: MarshalAs(UnmanagedType.Bool)]
private static unsafe partial bool RtlInstallFunctionTableCallback(
ulong tableIdentifier, ulong tableIdentifier,
ulong baseAddress, ulong baseAddress,
uint length, uint length,
GetRuntimeFunctionCallback callback, GetRuntimeFunctionCallback callback,
IntPtr context, IntPtr context,
string outOfProcessCallbackDll); [MarshalAs(UnmanagedType.LPWStr)] string outOfProcessCallbackDll);
private static GetRuntimeFunctionCallback _getRuntimeFunctionCallback; private static GetRuntimeFunctionCallback _getRuntimeFunctionCallback;

View file

@ -17,7 +17,7 @@ using Ryujinx.Ava.Ui.Windows;
using Ryujinx.Common; using Ryujinx.Common;
using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Common.System; using Ryujinx.Common.SystemInterop;
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.GAL.Multithreading; using Ryujinx.Graphics.GAL.Multithreading;
using Ryujinx.Graphics.Gpu; using Ryujinx.Graphics.Gpu;

View file

@ -8,7 +8,7 @@ namespace Ryujinx.Ava.Ui.Helper
public delegate void UpdateBoundsCallbackDelegate(Rect rect); public delegate void UpdateBoundsCallbackDelegate(Rect rect);
[SupportedOSPlatform("macos")] [SupportedOSPlatform("macos")]
static class MetalHelper static partial class MetalHelper
{ {
private const string LibObjCImport = "/usr/lib/libobjc.A.dylib"; private const string LibObjCImport = "/usr/lib/libobjc.A.dylib";
@ -100,28 +100,28 @@ namespace Ryujinx.Ava.Ui.Helper
// TODO // TODO
} }
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static unsafe extern IntPtr sel_registerName(byte* data); private static unsafe partial IntPtr sel_registerName(byte* data);
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static unsafe extern IntPtr objc_getClass(byte* data); private static unsafe partial IntPtr objc_getClass(byte* data);
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static extern void objc_msgSend(IntPtr receiver, Selector selector); private static partial void objc_msgSend(IntPtr receiver, Selector selector);
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static extern void objc_msgSend(IntPtr receiver, Selector selector, byte value); private static partial void objc_msgSend(IntPtr receiver, Selector selector, byte value);
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static extern void objc_msgSend(IntPtr receiver, Selector selector, IntPtr value); private static partial void objc_msgSend(IntPtr receiver, Selector selector, IntPtr value);
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static extern void objc_msgSend(IntPtr receiver, Selector selector, NSRect point); private static partial void objc_msgSend(IntPtr receiver, Selector selector, NSRect point);
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static extern void objc_msgSend(IntPtr receiver, Selector selector, double value); private static partial void objc_msgSend(IntPtr receiver, Selector selector, double value);
[DllImport(LibObjCImport, EntryPoint = "objc_msgSend")] [LibraryImport(LibObjCImport, EntryPoint = "objc_msgSend")]
private static extern IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector); private static partial IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector);
} }
} }

View file

@ -6,7 +6,7 @@ using Ryujinx.Common;
using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration;
using Ryujinx.Common.GraphicsDriver; using Ryujinx.Common.GraphicsDriver;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Common.System; using Ryujinx.Common.SystemInterop;
using Ryujinx.Common.SystemInfo; using Ryujinx.Common.SystemInfo;
using Ryujinx.Modules; using Ryujinx.Modules;
using Ryujinx.SDL2.Common; using Ryujinx.SDL2.Common;
@ -20,7 +20,7 @@ using System.Threading.Tasks;
namespace Ryujinx.Ava namespace Ryujinx.Ava
{ {
internal class Program internal partial class Program
{ {
public static double WindowScaleFactor { get; set; } public static double WindowScaleFactor { get; set; }
public static double DesktopScaleFactor { get; set; } = 1.0; public static double DesktopScaleFactor { get; set; } = 1.0;
@ -28,8 +28,8 @@ namespace Ryujinx.Ava
public static string ConfigurationPath { get; private set; } public static string ConfigurationPath { get; private set; }
public static bool PreviewerDetached { get; private set; } public static bool PreviewerDetached { get; private set; }
[DllImport("user32.dll", SetLastError = true)] [LibraryImport("user32.dll", SetLastError = true)]
public static extern int MessageBoxA(IntPtr hWnd, string text, string caption, uint type); public static partial int MessageBoxA(IntPtr hWnd, [MarshalAs(UnmanagedType.LPStr)] string text, [MarshalAs(UnmanagedType.LPStr)] string caption, uint type);
private const uint MB_ICONWARNING = 0x30; private const uint MB_ICONWARNING = 0x30;

View file

@ -125,9 +125,9 @@ namespace Ryujinx.Ava.Ui.Controls
{ {
cbSize = Marshal.SizeOf<WNDCLASSEX>(), cbSize = Marshal.SizeOf<WNDCLASSEX>(),
hInstance = GetModuleHandle(null), hInstance = GetModuleHandle(null),
lpfnWndProc = _wndProcDelegate, lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_wndProcDelegate),
style = ClassStyles.CS_OWNDC, style = ClassStyles.CS_OWNDC,
lpszClassName = _className, lpszClassName = Marshal.StringToHGlobalUni(_className),
hCursor = LoadCursor(IntPtr.Zero, (IntPtr)Cursors.IDC_ARROW) hCursor = LoadCursor(IntPtr.Zero, (IntPtr)Cursors.IDC_ARROW)
}; };
@ -148,7 +148,9 @@ namespace Ryujinx.Ava.Ui.Controls
IntPtr.Zero); IntPtr.Zero);
WindowHandle = handle; WindowHandle = handle;
Marshal.FreeHGlobal(wndClassEx.lpszClassName);
return new PlatformHandle(WindowHandle, "HWND"); return new PlatformHandle(WindowHandle, "HWND");
} }

View file

@ -5,7 +5,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Ava.Ui.Controls namespace Ryujinx.Ava.Ui.Controls
{ {
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
internal class Win32NativeInterop internal partial class Win32NativeInterop
{ {
[Flags] [Flags]
public enum ClassStyles : uint public enum ClassStyles : uint
@ -48,58 +48,52 @@ namespace Ryujinx.Ava.Ui.Controls
[UnmanagedFunctionPointer(CallingConvention.Winapi)] [UnmanagedFunctionPointer(CallingConvention.Winapi)]
internal delegate IntPtr WindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam); internal delegate IntPtr WindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] [StructLayout(LayoutKind.Sequential)]
public struct WNDCLASSEX public struct WNDCLASSEX
{ {
public int cbSize; public int cbSize;
public ClassStyles style; public ClassStyles style;
[MarshalAs(UnmanagedType.FunctionPtr)] public IntPtr lpfnWndProc; // not WndProc
public WindowProc lpfnWndProc; // not WndProc
public int cbClsExtra; public int cbClsExtra;
public int cbWndExtra; public int cbWndExtra;
public IntPtr hInstance; public IntPtr hInstance;
public IntPtr hIcon; public IntPtr hIcon;
public IntPtr hCursor; public IntPtr hCursor;
public IntPtr hbrBackground; public IntPtr hbrBackground;
[MarshalAs(UnmanagedType.LPWStr)] public IntPtr lpszMenuName;
public string lpszMenuName; public IntPtr lpszClassName;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpszClassName;
public IntPtr hIconSm; public IntPtr hIconSm;
public static WNDCLASSEX Create() public WNDCLASSEX()
{ {
return new WNDCLASSEX cbSize = Marshal.SizeOf<WNDCLASSEX>();
{
cbSize = Marshal.SizeOf<WNDCLASSEX>()
};
} }
} }
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "RegisterClassExW")]
public static extern ushort RegisterClassEx(ref WNDCLASSEX param); public static partial ushort RegisterClassEx(ref WNDCLASSEX param);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "UnregisterClassW")]
public static extern short UnregisterClass([MarshalAs(UnmanagedType.LPWStr)] string lpClassName, IntPtr instance); public static partial short UnregisterClass([MarshalAs(UnmanagedType.LPWStr)] string lpClassName, IntPtr instance);
[DllImport("user32.dll", CharSet = CharSet.Unicode)] [LibraryImport("user32.dll", EntryPoint = "DefWindowProcW")]
public static extern IntPtr DefWindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam); public static partial IntPtr DefWindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll")] [LibraryImport("kernel32.dll", EntryPoint = "GetModuleHandleA")]
public static extern IntPtr GetModuleHandle(string lpModuleName); public static partial IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPStr)] string lpModuleName);
[DllImport("user32.dll", SetLastError = true)] [LibraryImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DestroyWindow(IntPtr hwnd); public static partial bool DestroyWindow(IntPtr hwnd);
[DllImport("user32.dll", SetLastError = true)] [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "LoadCursorA")]
public static extern IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName); public static partial IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "CreateWindowExW")]
public static extern IntPtr CreateWindowEx( public static partial IntPtr CreateWindowEx(
uint dwExStyle, uint dwExStyle,
string lpClassName, [MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
string lpWindowName, [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName,
WindowStyles dwStyle, WindowStyles dwStyle,
int x, int x,
int y, int y,

View file

@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
namespace Ryujinx.Common.GraphicsDriver namespace Ryujinx.Common.GraphicsDriver
{ {
static class NVThreadedOptimization static partial class NVThreadedOptimization
{ {
private const string ProfileName = "Ryujinx Nvidia Profile"; private const string ProfileName = "Ryujinx Nvidia Profile";
@ -19,8 +19,8 @@ namespace Ryujinx.Common.GraphicsDriver
private const uint NvAPI_DRS_SaveSettings_ID = 0xFCBC7E14; private const uint NvAPI_DRS_SaveSettings_ID = 0xFCBC7E14;
private const uint NvAPI_DRS_DestroySession_ID = 0x0DAD9CFF8; private const uint NvAPI_DRS_DestroySession_ID = 0x0DAD9CFF8;
[DllImport("nvapi64")] [LibraryImport("nvapi64")]
private static extern IntPtr nvapi_QueryInterface(uint id); private static partial IntPtr nvapi_QueryInterface(uint id);
private delegate int NvAPI_InitializeDelegate(); private delegate int NvAPI_InitializeDelegate();
private static NvAPI_InitializeDelegate NvAPI_Initialize; private static NvAPI_InitializeDelegate NvAPI_Initialize;

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Threading; using System.Threading;
@ -12,7 +13,7 @@ namespace Ryujinx.Common.Memory.PartialUnmaps
/// State for partial unmaps. Intended to be used on Windows. /// State for partial unmaps. Intended to be used on Windows.
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct PartialUnmapState public partial struct PartialUnmapState
{ {
public NativeReaderWriterLock PartialUnmapLock; public NativeReaderWriterLock PartialUnmapLock;
public int PartialUnmapsCount; public int PartialUnmapsCount;
@ -25,20 +26,22 @@ namespace Ryujinx.Common.Memory.PartialUnmaps
public readonly static IntPtr GlobalState; public readonly static IntPtr GlobalState;
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
[DllImport("kernel32.dll")] [LibraryImport("kernel32.dll")]
public static extern int GetCurrentThreadId(); public static partial int GetCurrentThreadId();
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
[DllImport("kernel32.dll", SetLastError = true)] [LibraryImport("kernel32.dll", SetLastError = true)]
static extern IntPtr OpenThread(int dwDesiredAccess, bool bInheritHandle, uint dwThreadId); private static partial IntPtr OpenThread(int dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, uint dwThreadId);
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
[DllImport("kernel32.dll", SetLastError = true)] [LibraryImport("kernel32.dll", SetLastError = true)]
public static extern bool CloseHandle(IntPtr hObject); [return: MarshalAs (UnmanagedType.Bool)]
public static partial bool CloseHandle(IntPtr hObject);
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
[DllImport("kernel32.dll", SetLastError = true)] [LibraryImport("kernel32.dll", SetLastError = true)]
static extern bool GetExitCodeThread(IntPtr hThread, out uint lpExitCode); [return: MarshalAs(UnmanagedType.Bool)]
private static partial bool GetExitCodeThread(IntPtr hThread, out uint lpExitCode);
/// <summary> /// <summary>
/// Creates a global static PartialUnmapState and populates the field offsets. /// Creates a global static PartialUnmapState and populates the field offsets.

View file

@ -8,7 +8,7 @@ using Ryujinx.Common.Logging;
namespace Ryujinx.Common.SystemInfo namespace Ryujinx.Common.SystemInfo
{ {
[SupportedOSPlatform("macos")] [SupportedOSPlatform("macos")]
class MacOSSystemInfo : SystemInfo partial class MacOSSystemInfo : SystemInfo
{ {
internal MacOSSystemInfo() internal MacOSSystemInfo()
{ {
@ -60,8 +60,8 @@ namespace Ryujinx.Common.SystemInfo
private const string SystemLibraryName = "libSystem.dylib"; private const string SystemLibraryName = "libSystem.dylib";
[DllImport(SystemLibraryName, CharSet = CharSet.Ansi, SetLastError = true)] [LibraryImport(SystemLibraryName, SetLastError = true)]
private static extern int sysctlbyname(string name, IntPtr oldValue, ref ulong oldSize, IntPtr newValue, ulong newValueSize); private static partial int sysctlbyname([MarshalAs(UnmanagedType.LPStr)] string name, IntPtr oldValue, ref ulong oldSize, IntPtr newValue, ulong newValueSize);
private static int sysctlbyname(string name, IntPtr oldValue, ref ulong oldSize) private static int sysctlbyname(string name, IntPtr oldValue, ref ulong oldSize)
{ {
@ -116,11 +116,11 @@ namespace Ryujinx.Common.SystemInfo
return res; return res;
} }
[DllImport(SystemLibraryName, CharSet = CharSet.Ansi, SetLastError = true)] [LibraryImport(SystemLibraryName, SetLastError = true)]
private static extern uint mach_host_self(); private static partial uint mach_host_self();
[DllImport(SystemLibraryName, CharSet = CharSet.Ansi, SetLastError = true)] [LibraryImport(SystemLibraryName, SetLastError = true)]
private static extern int host_page_size(uint host, ref uint out_page_size); private static partial int host_page_size(uint host, ref uint out_page_size);
[StructLayout(LayoutKind.Sequential, Pack = 8)] [StructLayout(LayoutKind.Sequential, Pack = 8)]
struct VMStatistics64 struct VMStatistics64
@ -151,7 +151,7 @@ namespace Ryujinx.Common.SystemInfo
public ulong TotalUncompressedPagesInCompressor; public ulong TotalUncompressedPagesInCompressor;
} }
[DllImport(SystemLibraryName, CharSet = CharSet.Ansi, SetLastError = true)] [LibraryImport(SystemLibraryName, SetLastError = true)]
private static extern int host_statistics64(uint host_priv, int host_flavor, ref VMStatistics64 host_info64_out, ref uint host_info64_outCnt); private static partial int host_statistics64(uint host_priv, int host_flavor, ref VMStatistics64 host_info64_out, ref uint host_info64_outCnt);
} }
} }

View file

@ -7,7 +7,7 @@ using Ryujinx.Common.Logging;
namespace Ryujinx.Common.SystemInfo namespace Ryujinx.Common.SystemInfo
{ {
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
class WindowsSystemInfo : SystemInfo partial class WindowsSystemInfo : SystemInfo
{ {
internal WindowsSystemInfo() internal WindowsSystemInfo()
{ {
@ -18,7 +18,7 @@ namespace Ryujinx.Common.SystemInfo
private static (ulong Total, ulong Available) GetMemoryStats() private static (ulong Total, ulong Available) GetMemoryStats()
{ {
MemoryStatusEx memStatus = new MemoryStatusEx(); MemoryStatusEx memStatus = new MemoryStatusEx();
if (GlobalMemoryStatusEx(memStatus)) if (GlobalMemoryStatusEx(ref memStatus))
{ {
return (memStatus.TotalPhys, memStatus.AvailPhys); // Bytes return (memStatus.TotalPhys, memStatus.AvailPhys); // Bytes
} }
@ -45,8 +45,8 @@ namespace Ryujinx.Common.SystemInfo
return Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER").Trim(); return Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER").Trim();
} }
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] [StructLayout(LayoutKind.Sequential)]
private class MemoryStatusEx private struct MemoryStatusEx
{ {
public uint Length; public uint Length;
public uint MemoryLoad; public uint MemoryLoad;
@ -64,9 +64,9 @@ namespace Ryujinx.Common.SystemInfo
} }
} }
[LibraryImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static partial bool GlobalMemoryStatusEx(ref MemoryStatusEx lpBuffer);
private static extern bool GlobalMemoryStatusEx([In, Out] MemoryStatusEx lpBuffer);
private static ManagementObjectCollection GetWMIObjects(string scope, string query) private static ManagementObjectCollection GetWMIObjects(string scope, string query)
{ {

View file

@ -1,9 +1,9 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Ryujinx.Common.System namespace Ryujinx.Common.SystemInterop
{ {
public class DisplaySleep public partial class DisplaySleep
{ {
[Flags] [Flags]
enum EXECUTION_STATE : uint enum EXECUTION_STATE : uint
@ -13,8 +13,8 @@ namespace Ryujinx.Common.System
ES_SYSTEM_REQUIRED = 0x00000001 ES_SYSTEM_REQUIRED = 0x00000001
} }
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] [LibraryImport("kernel32.dll", SetLastError = true)]
static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags); private static partial EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
static public void Prevent() static public void Prevent()
{ {

View file

@ -3,29 +3,30 @@ using System;
using System.Globalization; using System.Globalization;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Ryujinx.Common.System namespace Ryujinx.Common.SystemInterop
{ {
public static class ForceDpiAware public static partial class ForceDpiAware
{ {
[DllImport("user32.dll")] [LibraryImport("user32.dll")]
private static extern bool SetProcessDPIAware(); [return: MarshalAs(UnmanagedType.Bool)]
private static partial bool SetProcessDPIAware();
private const string X11LibraryName = "libX11.so.6"; private const string X11LibraryName = "libX11.so.6";
[DllImport(X11LibraryName)] [LibraryImport(X11LibraryName)]
private static extern IntPtr XOpenDisplay(string display); private static partial IntPtr XOpenDisplay([MarshalAs(UnmanagedType.LPStr)] string display);
[DllImport(X11LibraryName)] [LibraryImport(X11LibraryName)]
private static extern IntPtr XGetDefault(IntPtr display, string program, string option); private static partial IntPtr XGetDefault(IntPtr display, [MarshalAs(UnmanagedType.LPStr)] string program, [MarshalAs(UnmanagedType.LPStr)] string option);
[DllImport(X11LibraryName)] [LibraryImport(X11LibraryName)]
private static extern int XDisplayWidth(IntPtr display, int screenNumber); private static partial int XDisplayWidth(IntPtr display, int screenNumber);
[DllImport(X11LibraryName)] [LibraryImport(X11LibraryName)]
private static extern int XDisplayWidthMM(IntPtr display, int screenNumber); private static partial int XDisplayWidthMM(IntPtr display, int screenNumber);
[DllImport(X11LibraryName)] [LibraryImport(X11LibraryName)]
private static extern int XCloseDisplay(IntPtr display); private static partial int XCloseDisplay(IntPtr display);
private static readonly double _standardDpiScale = 96.0; private static readonly double _standardDpiScale = 96.0;
private static readonly double _maxScaleFactor = 1.25; private static readonly double _maxScaleFactor = 1.25;

View file

@ -2,10 +2,10 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning; using System.Runtime.Versioning;
namespace Ryujinx.Common.System namespace Ryujinx.Common.SystemInterop
{ {
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
public static class GdiPlusHelper public static partial class GdiPlusHelper
{ {
private const string LibraryName = "gdiplus.dll"; private const string LibraryName = "gdiplus.dll";
@ -52,17 +52,17 @@ namespace Ryujinx.Common.System
public IntPtr NotificationUnhook; public IntPtr NotificationUnhook;
} }
[DllImport(LibraryName)] [LibraryImport(LibraryName)]
private static extern int GdiplusStartup(out IntPtr token, in StartupInputEx input, out StartupOutput output); private static partial int GdiplusStartup(out IntPtr token, in StartupInputEx input, out StartupOutput output);
[DllImport(LibraryName)] [LibraryImport(LibraryName)]
private static extern int GdipCreateFromHWND(IntPtr hwnd, out IntPtr graphics); private static partial int GdipCreateFromHWND(IntPtr hwnd, out IntPtr graphics);
[DllImport(LibraryName)] [LibraryImport(LibraryName)]
private static extern int GdipDeleteGraphics(IntPtr graphics); private static partial int GdipDeleteGraphics(IntPtr graphics);
[DllImport(LibraryName)] [LibraryImport(LibraryName)]
private static extern int GdipGetDpiX(IntPtr graphics, out float dpi); private static partial int GdipGetDpiX(IntPtr graphics, out float dpi);
public static float GetDpiX(IntPtr hwnd) public static float GetDpiX(IntPtr hwnd)
{ {

View file

@ -4,13 +4,13 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning; using System.Runtime.Versioning;
namespace Ryujinx.Common.System namespace Ryujinx.Common.SystemInterop
{ {
/// <summary> /// <summary>
/// Handle Windows Multimedia timer resolution. /// Handle Windows Multimedia timer resolution.
/// </summary> /// </summary>
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
public class WindowsMultimediaTimerResolution : IDisposable public partial class WindowsMultimediaTimerResolution : IDisposable
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct TimeCaps public struct TimeCaps
@ -19,14 +19,14 @@ namespace Ryujinx.Common.System
public uint wPeriodMax; public uint wPeriodMax;
}; };
[DllImport("winmm.dll", EntryPoint = "timeGetDevCaps", SetLastError = true)] [LibraryImport("winmm.dll", EntryPoint = "timeGetDevCaps", SetLastError = true)]
private static extern uint TimeGetDevCaps(ref TimeCaps timeCaps, uint sizeTimeCaps); private static partial uint TimeGetDevCaps(ref TimeCaps timeCaps, uint sizeTimeCaps);
[DllImport("winmm.dll", EntryPoint = "timeBeginPeriod")] [LibraryImport("winmm.dll", EntryPoint = "timeBeginPeriod")]
private static extern uint TimeBeginPeriod(uint uMilliseconds); private static partial uint TimeBeginPeriod(uint uMilliseconds);
[DllImport("winmm.dll", EntryPoint = "timeEndPeriod")] [LibraryImport("winmm.dll", EntryPoint = "timeEndPeriod")]
private static extern uint TimeEndPeriod(uint uMilliseconds); private static partial uint TimeEndPeriod(uint uMilliseconds);
private uint _targetResolutionInMilliseconds; private uint _targetResolutionInMilliseconds;
private bool _isActive; private bool _isActive;

View file

@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
{ {
static class FFmpegApi static partial class FFmpegApi
{ {
public const string AvCodecLibraryName = "avcodec"; public const string AvCodecLibraryName = "avcodec";
public const string AvUtilLibraryName = "avutil"; public const string AvUtilLibraryName = "avutil";
@ -78,52 +78,52 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
public unsafe delegate void av_log_set_callback_callback(void* a0, AVLog level, [MarshalAs(UnmanagedType.LPUTF8Str)] string a2, byte* a3); public unsafe delegate void av_log_set_callback_callback(void* a0, AVLog level, [MarshalAs(UnmanagedType.LPUTF8Str)] string a2, byte* a3);
[DllImport(AvUtilLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvUtilLibraryName)]
internal static unsafe extern AVFrame* av_frame_alloc(); internal static unsafe partial AVFrame* av_frame_alloc();
[DllImport(AvUtilLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvUtilLibraryName)]
internal static unsafe extern void av_frame_unref(AVFrame* frame); internal static unsafe partial void av_frame_unref(AVFrame* frame);
[DllImport(AvUtilLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvUtilLibraryName)]
internal static unsafe extern void av_free(AVFrame* frame); internal static unsafe partial void av_free(AVFrame* frame);
[DllImport(AvUtilLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvUtilLibraryName)]
internal static unsafe extern void av_log_set_level(AVLog level); internal static unsafe partial void av_log_set_level(AVLog level);
[DllImport(AvUtilLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvUtilLibraryName)]
internal static unsafe extern void av_log_set_callback(av_log_set_callback_callback callback); internal static unsafe partial void av_log_set_callback(av_log_set_callback_callback callback);
[DllImport(AvUtilLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvUtilLibraryName)]
internal static unsafe extern AVLog av_log_get_level(); internal static unsafe partial AVLog av_log_get_level();
[DllImport(AvUtilLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvUtilLibraryName)]
internal static unsafe extern void av_log_format_line(void* ptr, AVLog level, [MarshalAs(UnmanagedType.LPUTF8Str)] string fmt, byte* vl, byte* line, int lineSize, int* printPrefix); internal static unsafe partial void av_log_format_line(void* ptr, AVLog level, [MarshalAs(UnmanagedType.LPUTF8Str)] string fmt, byte* vl, byte* line, int lineSize, int* printPrefix);
[DllImport(AvCodecLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvCodecLibraryName)]
internal static unsafe extern AVCodec* avcodec_find_decoder(AVCodecID id); internal static unsafe partial AVCodec* avcodec_find_decoder(AVCodecID id);
[DllImport(AvCodecLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvCodecLibraryName)]
internal static unsafe extern AVCodecContext* avcodec_alloc_context3(AVCodec* codec); internal static unsafe partial AVCodecContext* avcodec_alloc_context3(AVCodec* codec);
[DllImport(AvCodecLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvCodecLibraryName)]
internal static unsafe extern int avcodec_open2(AVCodecContext* avctx, AVCodec* codec, void **options); internal static unsafe partial int avcodec_open2(AVCodecContext* avctx, AVCodec* codec, void **options);
[DllImport(AvCodecLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvCodecLibraryName)]
internal static unsafe extern int avcodec_close(AVCodecContext* avctx); internal static unsafe partial int avcodec_close(AVCodecContext* avctx);
[DllImport(AvCodecLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvCodecLibraryName)]
internal static unsafe extern void avcodec_free_context(AVCodecContext** avctx); internal static unsafe partial void avcodec_free_context(AVCodecContext** avctx);
[DllImport(AvCodecLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvCodecLibraryName)]
internal static unsafe extern AVPacket* av_packet_alloc(); internal static unsafe partial AVPacket* av_packet_alloc();
[DllImport(AvCodecLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvCodecLibraryName)]
internal static unsafe extern void av_packet_unref(AVPacket* pkt); internal static unsafe partial void av_packet_unref(AVPacket* pkt);
[DllImport(AvCodecLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvCodecLibraryName)]
internal static unsafe extern void av_packet_free(AVPacket** pkt); internal static unsafe partial void av_packet_free(AVPacket** pkt);
[DllImport(AvCodecLibraryName, CallingConvention = CallingConvention.Cdecl)] [LibraryImport(AvCodecLibraryName)]
internal static unsafe extern int avcodec_version(); internal static unsafe partial int avcodec_version();
} }
} }

View file

@ -5,7 +5,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Graphics.OpenGL.Helper namespace Ryujinx.Graphics.OpenGL.Helper
{ {
[SupportedOSPlatform("linux")] [SupportedOSPlatform("linux")]
internal static class GLXHelper internal static partial class GLXHelper
{ {
private const string LibraryName = "glx.dll"; private const string LibraryName = "glx.dll";
@ -30,7 +30,7 @@ namespace Ryujinx.Graphics.OpenGL.Helper
}); });
} }
[DllImport(LibraryName, EntryPoint = "glXGetCurrentContext")] [LibraryImport(LibraryName, EntryPoint = "glXGetCurrentContext")]
public static extern IntPtr GetCurrentContext(); public static partial IntPtr GetCurrentContext();
} }
} }

View file

@ -5,11 +5,11 @@ using System.Runtime.Versioning;
namespace Ryujinx.Graphics.OpenGL.Helper namespace Ryujinx.Graphics.OpenGL.Helper
{ {
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
internal static class WGLHelper internal static partial class WGLHelper
{ {
private const string LibraryName = "OPENGL32.DLL"; private const string LibraryName = "OPENGL32.DLL";
[DllImport(LibraryName, EntryPoint = "wglGetCurrentContext")] [LibraryImport(LibraryName, EntryPoint = "wglGetCurrentContext")]
public extern static IntPtr GetCurrentContext(); public static partial IntPtr GetCurrentContext();
} }
} }

View file

@ -10,7 +10,7 @@ using Ryujinx.Common.Configuration.Hid.Controller;
using Ryujinx.Common.Configuration.Hid.Controller.Motion; using Ryujinx.Common.Configuration.Hid.Controller.Motion;
using Ryujinx.Common.Configuration.Hid.Keyboard; using Ryujinx.Common.Configuration.Hid.Keyboard;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Common.System; using Ryujinx.Common.SystemInterop;
using Ryujinx.Common.Utilities; using Ryujinx.Common.Utilities;
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.GAL.Multithreading; using Ryujinx.Graphics.GAL.Multithreading;

View file

@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
namespace Ryujinx.Memory namespace Ryujinx.Memory
{ {
public static class MemoryManagerUnixHelper public static partial class MemoryManagerUnixHelper
{ {
[Flags] [Flags]
public enum MmapProts : uint public enum MmapProts : uint
@ -51,38 +51,38 @@ namespace Ryujinx.Memory
public const int MADV_DONTNEED = 4; public const int MADV_DONTNEED = 4;
public const int MADV_REMOVE = 9; public const int MADV_REMOVE = 9;
[DllImport("libc", EntryPoint = "mmap", SetLastError = true)] [LibraryImport("libc", EntryPoint = "mmap", SetLastError = true)]
private static extern IntPtr Internal_mmap(IntPtr address, ulong length, MmapProts prot, int flags, int fd, long offset); private static partial IntPtr Internal_mmap(IntPtr address, ulong length, MmapProts prot, int flags, int fd, long offset);
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
public static extern int mprotect(IntPtr address, ulong length, MmapProts prot); public static partial int mprotect(IntPtr address, ulong length, MmapProts prot);
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
public static extern int munmap(IntPtr address, ulong length); public static partial int munmap(IntPtr address, ulong length);
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
public static extern IntPtr mremap(IntPtr old_address, ulong old_size, ulong new_size, int flags, IntPtr new_address); public static partial IntPtr mremap(IntPtr old_address, ulong old_size, ulong new_size, int flags, IntPtr new_address);
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
public static extern int madvise(IntPtr address, ulong size, int advice); public static partial int madvise(IntPtr address, ulong size, int advice);
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
public static extern int mkstemp(IntPtr template); public static partial int mkstemp(IntPtr template);
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
public static extern int unlink(IntPtr pathname); public static partial int unlink(IntPtr pathname);
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
public static extern int ftruncate(int fildes, IntPtr length); public static partial int ftruncate(int fildes, IntPtr length);
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
public static extern int close(int fd); public static partial int close(int fd);
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
public static extern int shm_open(IntPtr name, int oflag, uint mode); public static partial int shm_open(IntPtr name, int oflag, uint mode);
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
public static extern int shm_unlink(IntPtr name); public static partial int shm_unlink(IntPtr name);
private static int MmapFlagsToSystemFlags(MmapFlags flags) private static int MmapFlagsToSystemFlags(MmapFlags flags)
{ {

View file

@ -3,20 +3,20 @@ using System.Runtime.InteropServices;
namespace Ryujinx.Memory.WindowsShared namespace Ryujinx.Memory.WindowsShared
{ {
static class WindowsApi static partial class WindowsApi
{ {
public static readonly IntPtr InvalidHandleValue = new IntPtr(-1); public static readonly IntPtr InvalidHandleValue = new IntPtr(-1);
public static readonly IntPtr CurrentProcessHandle = new IntPtr(-1); public static readonly IntPtr CurrentProcessHandle = new IntPtr(-1);
[DllImport("kernel32.dll", SetLastError = true)] [LibraryImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr VirtualAlloc( public static partial IntPtr VirtualAlloc(
IntPtr lpAddress, IntPtr lpAddress,
IntPtr dwSize, IntPtr dwSize,
AllocationType flAllocationType, AllocationType flAllocationType,
MemoryProtection flProtect); MemoryProtection flProtect);
[DllImport("KernelBase.dll", SetLastError = true)] [LibraryImport("KernelBase.dll", SetLastError = true)]
public static extern IntPtr VirtualAlloc2( public static partial IntPtr VirtualAlloc2(
IntPtr process, IntPtr process,
IntPtr lpAddress, IntPtr lpAddress,
IntPtr dwSize, IntPtr dwSize,
@ -25,18 +25,20 @@ namespace Ryujinx.Memory.WindowsShared
IntPtr extendedParameters, IntPtr extendedParameters,
ulong parameterCount); ulong parameterCount);
[DllImport("kernel32.dll", SetLastError = true)] [LibraryImport("kernel32.dll", SetLastError = true)]
public static extern bool VirtualProtect( [return: MarshalAs(UnmanagedType.Bool)]
public static partial bool VirtualProtect(
IntPtr lpAddress, IntPtr lpAddress,
IntPtr dwSize, IntPtr dwSize,
MemoryProtection flNewProtect, MemoryProtection flNewProtect,
out MemoryProtection lpflOldProtect); out MemoryProtection lpflOldProtect);
[DllImport("kernel32.dll", SetLastError = true)] [LibraryImport("kernel32.dll", SetLastError = true)]
public static extern bool VirtualFree(IntPtr lpAddress, IntPtr dwSize, AllocationType dwFreeType); [return: MarshalAs(UnmanagedType.Bool)]
public static partial bool VirtualFree(IntPtr lpAddress, IntPtr dwSize, AllocationType dwFreeType);
[DllImport("kernel32.dll", SetLastError = true)] [LibraryImport("kernel32.dll", SetLastError = true, EntryPoint = "CreateFileMappingW")]
public static extern IntPtr CreateFileMapping( public static partial IntPtr CreateFileMapping(
IntPtr hFile, IntPtr hFile,
IntPtr lpFileMappingAttributes, IntPtr lpFileMappingAttributes,
FileMapProtection flProtect, FileMapProtection flProtect,
@ -44,19 +46,20 @@ namespace Ryujinx.Memory.WindowsShared
uint dwMaximumSizeLow, uint dwMaximumSizeLow,
[MarshalAs(UnmanagedType.LPWStr)] string lpName); [MarshalAs(UnmanagedType.LPWStr)] string lpName);
[DllImport("kernel32.dll", SetLastError = true)] [LibraryImport("kernel32.dll", SetLastError = true)]
public static extern bool CloseHandle(IntPtr hObject); [return: MarshalAs(UnmanagedType.Bool)]
public static partial bool CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll", SetLastError = true)] [LibraryImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr MapViewOfFile( public static partial IntPtr MapViewOfFile(
IntPtr hFileMappingObject, IntPtr hFileMappingObject,
uint dwDesiredAccess, uint dwDesiredAccess,
uint dwFileOffsetHigh, uint dwFileOffsetHigh,
uint dwFileOffsetLow, uint dwFileOffsetLow,
IntPtr dwNumberOfBytesToMap); IntPtr dwNumberOfBytesToMap);
[DllImport("KernelBase.dll", SetLastError = true)] [LibraryImport("KernelBase.dll", SetLastError = true)]
public static extern IntPtr MapViewOfFile3( public static partial IntPtr MapViewOfFile3(
IntPtr hFileMappingObject, IntPtr hFileMappingObject,
IntPtr process, IntPtr process,
IntPtr baseAddress, IntPtr baseAddress,
@ -67,17 +70,19 @@ namespace Ryujinx.Memory.WindowsShared
IntPtr extendedParameters, IntPtr extendedParameters,
ulong parameterCount); ulong parameterCount);
[DllImport("kernel32.dll", SetLastError = true)] [LibraryImport("kernel32.dll", SetLastError = true)]
public static extern bool UnmapViewOfFile(IntPtr lpBaseAddress); [return: MarshalAs(UnmanagedType.Bool)]
public static partial bool UnmapViewOfFile(IntPtr lpBaseAddress);
[DllImport("KernelBase.dll", SetLastError = true)] [LibraryImport("KernelBase.dll", SetLastError = true)]
public static extern bool UnmapViewOfFile2(IntPtr process, IntPtr lpBaseAddress, ulong unmapFlags); [return: MarshalAs(UnmanagedType.Bool)]
public static partial bool UnmapViewOfFile2(IntPtr process, IntPtr lpBaseAddress, ulong unmapFlags);
[DllImport("kernel32.dll")] [LibraryImport("kernel32.dll")]
public static extern uint GetLastError(); public static partial uint GetLastError();
[DllImport("kernel32.dll")] [LibraryImport("kernel32.dll")]
public static extern int GetCurrentThreadId(); public static partial int GetCurrentThreadId();
public static MemoryProtection GetProtection(MemoryPermission permission) public static MemoryProtection GetProtection(MemoryPermission permission)
{ {

View file

@ -3,11 +3,12 @@ using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Ryujinx.Tests.Unicorn.Native namespace Ryujinx.Tests.Unicorn.Native
{ {
public static class Interface public static partial class Interface
{ {
public static bool IsUnicornAvailable { get; private set; } = true; public static bool IsUnicornAvailable { get; private set; } = true;
@ -58,43 +59,43 @@ namespace Ryujinx.Tests.Unicorn.Native
} }
} }
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern uint uc_version(out uint major, out uint minor); public static partial uint uc_version(out uint major, out uint minor);
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern Error uc_open(Arch arch, Mode mode, out IntPtr uc); public static partial Error uc_open(Arch arch, Mode mode, out IntPtr uc);
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern Error uc_close(IntPtr uc); public static partial Error uc_close(IntPtr uc);
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern IntPtr uc_strerror(Error err); public static partial IntPtr uc_strerror(Error err);
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern Error uc_reg_write(IntPtr uc, int regid, byte[] value); public static partial Error uc_reg_write(IntPtr uc, int regid, byte[] value);
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern Error uc_reg_read(IntPtr uc, int regid, byte[] value); public static partial Error uc_reg_read(IntPtr uc, int regid, byte[] value);
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern Error uc_mem_write(IntPtr uc, ulong address, byte[] bytes, ulong size); public static partial Error uc_mem_write(IntPtr uc, ulong address, byte[] bytes, ulong size);
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern Error uc_mem_read(IntPtr uc, ulong address, byte[] bytes, ulong size); public static partial Error uc_mem_read(IntPtr uc, ulong address, byte[] bytes, ulong size);
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern Error uc_emu_start(IntPtr uc, ulong begin, ulong until, ulong timeout, ulong count); public static partial Error uc_emu_start(IntPtr uc, ulong begin, ulong until, ulong timeout, ulong count);
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern Error uc_mem_map(IntPtr uc, ulong address, ulong size, uint perms); public static partial Error uc_mem_map(IntPtr uc, ulong address, ulong size, uint perms);
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern Error uc_mem_unmap(IntPtr uc, ulong address, ulong size); public static partial Error uc_mem_unmap(IntPtr uc, ulong address, ulong size);
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern Error uc_mem_protect(IntPtr uc, ulong address, ulong size, uint perms); public static partial Error uc_mem_protect(IntPtr uc, ulong address, ulong size, uint perms);
[DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] [LibraryImport("unicorn")]
public static extern Error uc_mem_regions(IntPtr uc, out IntPtr regions, out uint count); public static partial Error uc_mem_regions(IntPtr uc, out IntPtr regions, out uint count);
} }
} }

View file

@ -5,7 +5,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Ui.Common.Helper namespace Ryujinx.Ui.Common.Helper
{ {
public static class ConsoleHelper public static partial class ConsoleHelper
{ {
public static bool SetConsoleWindowStateSupported => OperatingSystem.IsWindows(); public static bool SetConsoleWindowStateSupported => OperatingSystem.IsWindows();
@ -39,11 +39,12 @@ namespace Ryujinx.Ui.Common.Helper
} }
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
[DllImport("kernel32")] [LibraryImport("kernel32")]
static extern IntPtr GetConsoleWindow(); private static partial IntPtr GetConsoleWindow();
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
[DllImport("user32")] [LibraryImport("user32")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [return: MarshalAs(UnmanagedType.Bool)]
private static partial bool ShowWindow(IntPtr hWnd, int nCmdShow);
} }
} }

View file

@ -2,6 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -4,7 +4,7 @@ using Ryujinx.Common;
using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration;
using Ryujinx.Common.GraphicsDriver; using Ryujinx.Common.GraphicsDriver;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Common.System; using Ryujinx.Common.SystemInterop;
using Ryujinx.Common.SystemInfo; using Ryujinx.Common.SystemInfo;
using Ryujinx.Modules; using Ryujinx.Modules;
using Ryujinx.SDL2.Common; using Ryujinx.SDL2.Common;
@ -23,7 +23,7 @@ using System.Threading.Tasks;
namespace Ryujinx namespace Ryujinx
{ {
class Program partial class Program
{ {
public static double WindowScaleFactor { get; private set; } public static double WindowScaleFactor { get; private set; }
@ -35,17 +35,17 @@ namespace Ryujinx
private const string X11LibraryName = "libX11"; private const string X11LibraryName = "libX11";
[DllImport(X11LibraryName)] [LibraryImport(X11LibraryName)]
private extern static int XInitThreads(); private static partial int XInitThreads();
[DllImport("user32.dll", SetLastError = true)] [LibraryImport("user32.dll", SetLastError = true)]
public static extern int MessageBoxA(IntPtr hWnd, string text, string caption, uint type); public static partial int MessageBoxA(IntPtr hWnd, [MarshalAs(UnmanagedType.LPStr)] string text, [MarshalAs(UnmanagedType.LPStr)] string caption, uint type);
[DllImport("libc", SetLastError = true)] [LibraryImport("libc", SetLastError = true)]
static extern int setenv(string name, string value, int overwrite); private static partial int setenv([MarshalAs(UnmanagedType.LPStr)] string name, [MarshalAs(UnmanagedType.LPStr)] string value, int overwrite);
[DllImport("libc")] [LibraryImport("libc")]
static extern IntPtr getenv(string name); private static partial IntPtr getenv([MarshalAs(UnmanagedType.LPStr)] string name);
private const uint MB_ICONWARNING = 0x30; private const uint MB_ICONWARNING = 0x30;

View file

@ -13,7 +13,7 @@ using System.Runtime.InteropServices;
namespace Ryujinx.Ui namespace Ryujinx.Ui
{ {
public class GlRenderer : RendererWidgetBase public partial class GlRenderer : RendererWidgetBase
{ {
private GraphicsDebugLevel _glLogLevel; private GraphicsDebugLevel _glLogLevel;
@ -74,14 +74,14 @@ namespace Ryujinx.Ui
throw new NotImplementedException(); throw new NotImplementedException();
} }
[DllImport("libgdk-3-0.dll")] [LibraryImport("libgdk-3-0.dll")]
private static extern IntPtr gdk_win32_window_get_handle(IntPtr d); private static partial IntPtr gdk_win32_window_get_handle(IntPtr d);
[DllImport("libgdk-3.so.0")] [LibraryImport("libgdk-3.so.0")]
private static extern IntPtr gdk_x11_display_get_xdisplay(IntPtr gdkDisplay); private static partial IntPtr gdk_x11_display_get_xdisplay(IntPtr gdkDisplay);
[DllImport("libgdk-3.so.0")] [LibraryImport("libgdk-3.so.0")]
private static extern IntPtr gdk_x11_window_get_xid(IntPtr gdkWindow); private static partial IntPtr gdk_x11_window_get_xid(IntPtr gdkWindow);
private static FramebufferFormat GetGraphicsMode() private static FramebufferFormat GetGraphicsMode()
{ {

View file

@ -8,7 +8,7 @@ namespace Ryujinx.Ui.Helper
public delegate void UpdateBoundsCallbackDelegate(Window window); public delegate void UpdateBoundsCallbackDelegate(Window window);
[SupportedOSPlatform("macos")] [SupportedOSPlatform("macos")]
static class MetalHelper static partial class MetalHelper
{ {
private const string LibObjCImport = "/usr/lib/libobjc.A.dylib"; private const string LibObjCImport = "/usr/lib/libobjc.A.dylib";
@ -104,31 +104,31 @@ namespace Ryujinx.Ui.Helper
return metalLayer; return metalLayer;
} }
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static unsafe extern IntPtr sel_registerName(byte* data); private static unsafe partial IntPtr sel_registerName(byte* data);
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static unsafe extern IntPtr objc_getClass(byte* data); private static unsafe partial IntPtr objc_getClass(byte* data);
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static extern void objc_msgSend(IntPtr receiver, Selector selector); private static partial void objc_msgSend(IntPtr receiver, Selector selector);
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static extern void objc_msgSend(IntPtr receiver, Selector selector, byte value); private static partial void objc_msgSend(IntPtr receiver, Selector selector, byte value);
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static extern void objc_msgSend(IntPtr receiver, Selector selector, IntPtr value); private static partial void objc_msgSend(IntPtr receiver, Selector selector, IntPtr value);
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static extern void objc_msgSend(IntPtr receiver, Selector selector, NSRect point); private static partial void objc_msgSend(IntPtr receiver, Selector selector, NSRect point);
[DllImport(LibObjCImport)] [LibraryImport(LibObjCImport)]
private static extern void objc_msgSend(IntPtr receiver, Selector selector, double value); private static partial void objc_msgSend(IntPtr receiver, Selector selector, double value);
[DllImport(LibObjCImport, EntryPoint = "objc_msgSend")] [LibraryImport(LibObjCImport, EntryPoint = "objc_msgSend")]
private static extern IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector); private static partial IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector);
[DllImport("libgdk-3.0.dylib")] [LibraryImport("libgdk-3.0.dylib")]
private static extern IntPtr gdk_quartz_window_get_nsview(IntPtr gdkWindow); private static partial IntPtr gdk_quartz_window_get_nsview(IntPtr gdkWindow);
} }
} }

View file

@ -15,7 +15,7 @@ using Ryujinx.Audio.Integration;
using Ryujinx.Common; using Ryujinx.Common;
using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Common.System; using Ryujinx.Common.SystemInterop;
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.GAL.Multithreading; using Ryujinx.Graphics.GAL.Multithreading;
using Ryujinx.Graphics.OpenGL; using Ryujinx.Graphics.OpenGL;

View file

@ -12,7 +12,7 @@ using System.Runtime.InteropServices;
namespace Ryujinx.Ui namespace Ryujinx.Ui
{ {
public class VKRenderer : RendererWidgetBase public partial class VKRenderer : RendererWidgetBase
{ {
public NativeWindowBase NativeWindow { get; private set; } public NativeWindowBase NativeWindow { get; private set; }
private UpdateBoundsCallbackDelegate _updateBoundsCallback; private UpdateBoundsCallbackDelegate _updateBoundsCallback;
@ -44,14 +44,14 @@ namespace Ryujinx.Ui
throw new NotImplementedException(); throw new NotImplementedException();
} }
[DllImport("libgdk-3-0.dll")] [LibraryImport("libgdk-3-0.dll")]
private static extern IntPtr gdk_win32_window_get_handle(IntPtr d); private static partial IntPtr gdk_win32_window_get_handle(IntPtr d);
[DllImport("libgdk-3.so.0")] [LibraryImport("libgdk-3.so.0")]
private static extern IntPtr gdk_x11_display_get_xdisplay(IntPtr gdkDisplay); private static partial IntPtr gdk_x11_display_get_xdisplay(IntPtr gdkDisplay);
[DllImport("libgdk-3.so.0")] [LibraryImport("libgdk-3.so.0")]
private static extern IntPtr gdk_x11_window_get_xid(IntPtr gdkWindow); private static partial IntPtr gdk_x11_window_get_xid(IntPtr gdkWindow);
protected override bool OnConfigureEvent(EventConfigure evnt) protected override bool OnConfigureEvent(EventConfigure evnt)
{ {