예제 #1
0
        public static void ThrowLastError(PalFlags.FailCodes rc, int lastError, string msg)
        {
            string txt;

            try
            {
                txt = $"{GetNativeErrorString(lastError, msg, out var specialErrnoCodes)}. FailCode={rc}.";

                if ((specialErrnoCodes & PalFlags.ErrnoSpecialCodes.NoMem) != 0)
                {
                    throw new OutOfMemoryException(txt);
                }

                if ((specialErrnoCodes & PalFlags.ErrnoSpecialCodes.NoEnt) != 0)
                {
                    throw new FileNotFoundException(txt);
                }

                if ((specialErrnoCodes & PalFlags.ErrnoSpecialCodes.NoSpc) != 0)
                {
                    throw new DiskFullException(txt);
                }
            }
            catch (OutOfMemoryException)
            {
                throw; // we can't assume anything is safe here, just re-throw
            }
            catch (Exception ex)
            {
                txt = $"{lastError}:=(Failed to rvn_get_error_string - {ex.Message}): {msg}";
            }

            throw new InvalidOperationException(txt);
        }
예제 #2
0
        protected override bool ReleaseHandle()
        {
            FailCode = Pal.rvn_mmap_dispose_handle(handle, out ErrorNo);

            handle = IntPtr.Zero;
            return(FailCode == PalFlags.FailCodes.Success);
        }
예제 #3
0
        public const int PAL_VER = 42011; // Should match auto generated rc from rvn_get_pal_ver() @ src/rvngetpalver.c

        static Pal()
        {
            var    toFilename = LIBRVNPAL;
            string fromFilename;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                if (RuntimeInformation.ProcessArchitecture != Architecture.Arm &&
                    RuntimeInformation.ProcessArchitecture != Architecture.Arm64)
                {
                    fromFilename = Environment.Is64BitProcess ? $"{toFilename}.linux.x64.so" : $"{toFilename}.linux.x86.so";
                    toFilename  += ".so";
                }
                else
                {
                    fromFilename = Environment.Is64BitProcess ? $"{toFilename}.arm.64.so" : $"{toFilename}.arm.32.so";
                    toFilename  += ".so";
                }
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                fromFilename = Environment.Is64BitProcess ? $"{toFilename}.mac.x64.dylib" : $"{toFilename}.mac.x86.dylib";
                // in mac we are not : `toFilename += ".so";` as DllImport doesn't assume .so nor .dylib by default
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var win7 = PlatformDetails.IsWindows8OrNewer ? "" : "7";

                fromFilename = Environment.Is64BitProcess ? $"{toFilename}.win{win7}.x64.dll" : $"{toFilename}.win{win7}.x86.dll";
                toFilename  += ".dll";
            }
            else
            {
                throw new NotSupportedException("Not supported platform - no Linux/OSX/Windows is detected ");
            }

            try
            {
                var copy = true;
                if (File.Exists(toFilename))
                {
                    var fromHash = FileHelper.CalculateHash(fromFilename);
                    var toHash   = FileHelper.CalculateHash(toFilename);

                    copy = fromHash != toHash;
                }

                if (copy)
                {
                    File.Copy(fromFilename, toFilename, overwrite: true);
                }
            }
            catch (IOException e)
            {
                throw new IOException(
                          $"Cannot copy {fromFilename} to {toFilename}, make sure appropriate {toFilename} to your platform architecture exists in Raven.Server executable folder",
                          e);
            }

            PalFlags.FailCodes rc = PalFlags.FailCodes.None;
            int errorCode;

            try
            {
                var palver = rvn_get_pal_ver();
                if (palver != 0 && palver != PAL_VER)
                {
                    throw new IncorrectDllException(
                              $"{LIBRVNPAL} version '{palver}' mismatches this RavenDB instance version (set to '{PAL_VER}'). Either use correct {fromFilename}, or a new one returning zero in 'rvn_get_pal_ver()'");
                }

                rc = rvn_get_system_information(out SysInfo, out errorCode);
            }
            catch (Exception ex)
            {
                var errString = $"{LIBRVNPAL} version might be invalid, missing or not usable on current platform.";

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    errString += " Initialization error could also be caused by missing 'Microsoft Visual C++ 2015 Redistributable Package' (or newer). It can be downloaded from https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads.";
                }

                errString += $" Arch: {RuntimeInformation.OSArchitecture}, OSDesc: {RuntimeInformation.OSDescription}";

                throw new IncorrectDllException(errString, ex);
            }

            if (rc != PalFlags.FailCodes.Success)
            {
                PalHelper.ThrowLastError(rc, errorCode, "Cannot get system information");
            }
        }