示例#1
0
        internal static unsafe void Fill(VoidPtr dest, uint length, byte value)
        {
            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
            {
                Win32.FillMemory(dest, length, value);
                break;
            }

            case PlatformID.MacOSX:
            {
                OSX.memset(dest, value, length);
                break;
            }

            case PlatformID.Unix:
            {
                if (Directory.Exists("/Applications")
                    & Directory.Exists("/System")
                    & Directory.Exists("/Users")
                    & Directory.Exists("/Volumes"))
                {
                    goto case PlatformID.MacOSX;
                }

                Linux.memset(dest, value, length);

                break;
            }
            }
        }
示例#2
0
        public static unsafe void Move(VoidPtr dst, VoidPtr src, uint size)
        {
            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
                Win32.MoveMemory(dst, src, size);
                break;

            case PlatformID.MacOSX:
                OSX.memmove(dst, src, size);
                break;

            case PlatformID.Unix:
                if (Directory.Exists("/Applications")
                    & Directory.Exists("/System")
                    & Directory.Exists("/Users")
                    & Directory.Exists("/Volumes"))
                {
                    goto case PlatformID.MacOSX;
                }
                else
                {
                    Linux.memmove(dst, src, size);
                }

                break;
            }
        }
示例#3
0
文件: Stb.cs 项目: parhelia512/nginz
        public static void Free(IntPtr data)
        {
            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32Windows:
            case PlatformID.Win32NT:
            case PlatformID.Win32S:
                if (Environment.Is64BitProcess)
                {
                    Win64.stbi_image_free(data);
                }
                else
                {
                    Win32.stbi_image_free(data);
                }
                break;

            default:
                if (Directory.Exists("/Library") &&
                    Directory.Exists("/System"))
                {
                    OSX.stbi_image_free(data);
                }
                else if (Environment.Is64BitProcess)
                {
                    Linux64.stbi_image_free(data);
                }
                else
                {
                    Linux32.stbi_image_free(data);
                }
                break;
            }
        }
示例#4
0
        public static T LoadFunction <T>(IntPtr library, string function, bool throwIfNotFound = false)
        {
            IntPtr result;

            if (Environment.OSVersion.IsWindows())
            {
                result = Windows.GetProcAddress(library, function);
            }
            else if (Environment.OSVersion.IsMacOSX())
            {
                result = OSX.dlsym(library, function);
            }
            else
            {
                result = Linux.dlsym(library, function);
            }

            if (result == IntPtr.Zero)
            {
                if (throwIfNotFound)
                {
                    throw new EntryPointNotFoundException(function);
                }

                return(default(T));
            }

            return(Marshal.GetDelegateForFunctionPointer <T>(result));
        }
示例#5
0
        public static bool TryLoadFunction <T>(
            IntPtr library,
            string functionName,
            [NotNullWhen(true)] out T?func)
            where T : Delegate
        {
            IntPtr ret;

            if (PlatformInfo.CurrentOS == PlatformInfo.OS.Windows)
            {
                ret = Windows.GetProcAddress(library, functionName);
            }
            else if (PlatformInfo.CurrentOS == PlatformInfo.OS.MacOSX)
            {
                ret = OSX.dlsym(library, functionName);
            }
            else
            {
                ret = Linux.dlsym(library, functionName);
            }

            if (ret == IntPtr.Zero)
            {
                func = default;
                return(false);
            }

            func = Marshal.GetDelegateForFunctionPointer <T>(ret);
            return(true);
        }
示例#6
0
文件: Stb.cs 项目: parhelia512/nginz
        public static IntPtr Load(string filename, ref int x, ref int y, ref int n, int req_comp)
        {
            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32Windows:
            case PlatformID.Win32NT:
            case PlatformID.Win32S:
                if (Environment.Is64BitProcess)
                {
                    return(Win64.stbi_load(filename, ref x, ref y, ref n, req_comp));
                }
                else
                {
                    return(Win32.stbi_load(filename, ref x, ref y, ref n, req_comp));
                }

            default:
                if (Directory.Exists("/Library") &&
                    Directory.Exists("/System"))
                {
                    return(OSX.stbi_load(filename, ref x, ref y, ref n, req_comp));
                }
                if (Environment.Is64BitProcess)
                {
                    return(Linux64.stbi_load(filename, ref x, ref y, ref n, req_comp));
                }
                else
                {
                    return(Linux32.stbi_load(filename, ref x, ref y, ref n, req_comp));
                }
            }
        }
示例#7
0
        public static T LoadFunction <T> (IntPtr library, string function, bool throwIfNotFound = true)
        {
            var ret = IntPtr.Zero;

            if (CurrentPlatform.OS == OS.Windows)
            {
                ret = Windows.GetProcAddress(library, function);
            }
            else if (CurrentPlatform.OS == OS.MacOSX)
            {
                ret = OSX.dlsym(library, function);
            }
            else
            {
                ret = Linux.dlsym(library, function);
            }

            if (ret == IntPtr.Zero)
            {
                if (throwIfNotFound)
                {
                    throw new EntryPointNotFoundException(function);
                }

                return(default(T));
            }

#if NETSTANDARD
            return(Marshal.GetDelegateForFunctionPointer <T> (ret));
#else
            return(( T )( object )Marshal.GetDelegateForFunctionPointer(ret, typeof(T)));
#endif
        }
        public static T LoadFunction <T>(IntPtr library, string function)
        {
            var ret = IntPtr.Zero;

            if (CurrentPlatform.OS == OS.Windows)
            {
                ret = Windows.GetProcAddress(library, function);
            }
            else if (CurrentPlatform.OS == OS.MacOSX)
            {
                ret = OSX.dlsym(library, function);
            }
            else
            {
                ret = Linux.dlsym(library, function);
            }

            if (ret == IntPtr.Zero)
            {
                return(default(T));
            }

            // TODO: Use the function bellow once Protobuild gets axed
            // requires .NET Framework 4.5.1 and its useful for corert
            // return Marshal.GetDelegateForFunctionPointer<T>(ret);

            return((T)(object)Marshal.GetDelegateForFunctionPointer(ret, typeof(T)));
        }
 public static IntPtr LoadLibrary(string libname)
 {
     if (IsWindows)
     {
         return(Windows.LoadLibraryW(libname));
     }
     return(IsOSX ? OSX.dlopen(libname, 1) : Linux.dlopen(libname, 1));
 }
 public static bool FreeLibrary(IntPtr library)
 {
     if (IsWindows)
     {
         return(Windows.FreeLibrary(library));
     }
     return((IsOSX ? OSX.dlclose(library) : Linux.dlclose(library)) == 0);
 }
            public static IntPtr GetProcAddress(IntPtr library, string function)
            {
                var num = !IsWindows
                    ? !IsOSX?Linux.dlsym(library, function) : OSX.dlsym(library, function)
                              : Windows.GetProcAddress(library, function);

                return(num);
            }
示例#12
0
    public static IntPtr GetProcAddress(IntPtr library, string function)
    {
        var ret = IntPtr.Zero;

        ret = Common.OSTest.IsWindows()
            ? Windows.DLSym(library, function)
            : Common.OSTest.IsRunningOnMac() ? OSX.DLSym(library, function) : Linux.DLSym(library, function);

        return(ret);
    }
示例#13
0
            public static IntPtr GetProcAddress(IntPtr library, string function)
            {
                var num = !IsWindows ? (!IsOSX ? Linux.dlsym(library, function) : OSX.dlsym(library, function)) : Windows.GetProcAddress(library, function);

                if (num == IntPtr.Zero)
                {
                    Logger.Warn("Função não encontrada: " + function);
                }
                return(num);
            }
示例#14
0
        public static IntPtr LoadLibrary(string libname)
        {
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                return(Windows.LoadLibraryW(libname));
            }

            if (Environment.OSVersion.Platform == PlatformID.MacOSX)
            {
                return(OSX.dlopen(libname, RTLD_LAZY));
            }

            return(Linux.dlopen(libname, RTLD_LAZY));
        }
示例#15
0
        public static IntPtr LoadLibrary(string libname)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return(Windows.LoadLibraryW(libname));
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                return(OSX.dlopen(libname, RTLD_LAZY));
            }

            return(Linux.dlopen(libname, RTLD_LAZY));
        }
        public static IntPtr LoadLibrary(string libname)
        {
            if (CurrentPlatform.OS == OS.Windows)
            {
                return(Windows.LoadLibraryW(libname));
            }

            if (CurrentPlatform.OS == OS.MacOSX)
            {
                return(OSX.dlopen(libname, RTLD_GLOBAL | RTLD_LAZY));
            }

            return(Linux.dlopen(libname, RTLD_GLOBAL | RTLD_LAZY));
        }
示例#17
0
        public static IntPtr LoadLibrary(string libname)
        {
            if (IsWindows)
            {
                return(Windows.LoadLibraryW(libname));
            }

            if (IsOSX)
            {
                return(OSX.dlopen(libname, RTLD_GLOBAL | RTLD_LAZY));
            }

            return(Linux.dlopen(libname, RTLD_GLOBAL | RTLD_LAZY));
        }
示例#18
0
        public static IntPtr LoadLibrary(string libname)
        {
            if (Environment.OSVersion.IsWindows())
            {
                return(Windows.LoadLibraryW(libname));
            }

            if (Environment.OSVersion.IsMacOSX())
            {
                return(OSX.dlopen(libname, RTLD_LAZY));
            }

            return(Linux.dlopen(libname, RTLD_LAZY));
        }
示例#19
0
 internal static string TryDetectConfigPath(int processId)
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         return(Windows.TryDetectConfigPath(processId));
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
     {
         return(Linux.TryDetectConfigPath(processId));
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
     {
         return(OSX.TryDetectConfigPath(processId));
     }
     return(null);
 }
示例#20
0
        public static IntPtr GetProcAddress(IntPtr library, string function)
        {
            var ret = IntPtr.Zero;

            if (IsWindows)
            {
                ret = Windows.GetProcAddress(library, function);
            }
            else if (IsOSX)
            {
                ret = OSX.dlsym(library, function);
            }
            else
            {
                ret = Linux.dlsym(library, function);
            }

            return(ret);
        }
示例#21
0
        static NativeLibrary()
        {
            const int RTLD_NOW = 2;

            if (Platform.IsWindows)
            {
                Open      = Windows.LoadLibrary;
                GetSymbol = Windows.GetProcAddress;
            }
            else if (Platform.IsOSX)
            {
                Open      = f => OSX.dlopen(f, RTLD_NOW);
                GetSymbol = OSX.dlsym;
            }
            else if (Platform.IsLinux)
            {
                if (Platform.IsMono)
                {
                    Open      = f => Mono.dlopen(f, RTLD_NOW);
                    GetSymbol = Mono.dlsym;
                }
                else if (Platform.IsNetCore)
                {
                    Open      = f => CoreCLR.dlopen(f, RTLD_NOW);
                    GetSymbol = CoreCLR.dlsym;
                }
                else
                {
                    Open      = f => Linux.dlopen(f, RTLD_NOW);
                    GetSymbol = Linux.dlsym;
                }
            }
            else
            {
                throw new PlatformNotSupportedException();
            }
        }
示例#22
0
        public static T LoadFunction <T>(IntPtr library, string function)
        {
            var ret = IntPtr.Zero;

            if (IsWindows)
            {
                ret = Windows.GetProcAddress(library, function);
            }
            else if (IsOSX)
            {
                ret = OSX.dlsym(library, function);
            }
            else
            {
                ret = Linux.dlsym(library, function);
            }

            if (ret == IntPtr.Zero)
            {
                return(default(T));
            }

            return(Marshal.GetDelegateForFunctionPointer <T>(ret));
        }
示例#23
0
        public static T LoadFunction <T>(IntPtr library, string function)
        {
            IntPtr ret;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                ret = Windows.GetProcAddress(library, function);
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                ret = OSX.dlsym(library, function);
            }
            else
            {
                ret = Linux.dlsym(library, function);
            }

            if (ret == IntPtr.Zero)
            {
                throw new EntryPointNotFoundException(function);
            }

            return(Marshal.GetDelegateForFunctionPointer <T>(ret));
        }
示例#24
0
    public static IntPtr GetProcAddress(IntPtr library, string function)
    {
        var ret = IntPtr.Zero;

        if (IsWindows)
        {
            ret = Windows.GetProcAddress(library, function);
        }
        else if (IsOSX)
        {
            ret = OSX.dlsym(library, function);
        }
        else
        {
            ret = Linux.dlsym(library, function);
        }

        if (ret == IntPtr.Zero)
        {
            Console.WriteLine("[WARNING] Function not found: " + function);
        }

        return(ret);
    }
示例#25
0
        public Vector2Int GetMousePosition()
        {
            CGPoint position = OSX.GetMousePosition();

            return(new Vector2Int((int)position.x, (int)position.y));
        }
示例#26
0
 public void SetMousePosition(Vector2Int position)
 {
     OSX.SetMousePosition(position.x, position.y);
 }
示例#27
0
 public void Click(Vector2Int position)
 {
     OSX.Click(position.x, position.y);
 }
示例#28
0
 public static IntPtr LoadLibrary(string libname)
 {
     return(Common.OSTest.IsWindows()
         ? Windows.DLOpen(libname)
         : Common.OSTest.IsRunningOnMac() ? OSX.DLOpen(libname, RTLD_GLOBAL | RTLD_LAZY) : Linux.DLOpen(libname, RTLD_GLOBAL | RTLD_LAZY));
 }
示例#29
0
 public static int FreeLibrary(IntPtr handle)
 {
     return(Common.OSTest.IsWindows()
         ? Windows.DLClose(handle) ? 0 : 1
         : Common.OSTest.IsRunningOnMac() ? OSX.DLClose(handle) : Linux.DLClose(handle));
 }
示例#30
0
 public string Handle(OSX operatingSystem)
 {
     return("sleep");
 }