Browse Source

Merge pull request #7548 from ahopper/fix-32bit-linux-session-manger-pinvoke

fix 32 bit raspberry pi session manager seg fault
pull/7569/head
Nikita Tsukanov 4 years ago
committed by GitHub
parent
commit
f145424eff
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/Avalonia.X11/SMLib.cs
  2. 21
      src/Avalonia.X11/X11PlatformLifetimeEvents.cs

16
src/Avalonia.X11/SMLib.cs

@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Runtime.InteropServices;
@ -7,20 +8,19 @@ namespace Avalonia.X11
{
private const string LibSm = "libSM.so.6";
[DllImport(LibSm, CharSet = CharSet.Ansi)]
[DllImport(LibSm, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr SmcOpenConnection(
[MarshalAs(UnmanagedType.LPWStr)] string networkId,
[MarshalAs(UnmanagedType.LPStr)] string? networkId,
IntPtr content,
int xsmpMajorRev,
int xsmpMinorRev,
ulong mask,
nuint mask,
ref SmcCallbacks callbacks,
[MarshalAs(UnmanagedType.LPWStr)] [Out]
out string previousId,
[MarshalAs(UnmanagedType.LPWStr)] [Out]
out string clientIdRet,
[MarshalAs(UnmanagedType.LPStr)] string? previousId,
ref IntPtr clientIdRet,
int errorLength,
[Out] char[] errorStringRet);
[Out] byte[] errorStringRet
);
[DllImport(LibSm, CallingConvention = CallingConvention.StdCall)]
public static extern int SmcCloseConnection(

21
src/Avalonia.X11/X11PlatformLifetimeEvents.cs

@ -1,5 +1,6 @@
#nullable enable
using System;
using System.Text;
using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using System.Threading;
@ -14,10 +15,10 @@ namespace Avalonia.X11
internal unsafe class X11PlatformLifetimeEvents : IDisposable, IPlatformLifetimeEventsImpl
{
private readonly AvaloniaX11Platform _platform;
private const ulong SmcSaveYourselfProcMask = 1L;
private const ulong SmcDieProcMask = 2L;
private const ulong SmcSaveCompleteProcMask = 4L;
private const ulong SmcShutdownCancelledProcMask = 8L;
private const nuint SmcSaveYourselfProcMask = 1;
private const nuint SmcDieProcMask = 2;
private const nuint SmcSaveCompleteProcMask = 4;
private const nuint SmcShutdownCancelledProcMask = 8;
private static readonly ConcurrentDictionary<IntPtr, X11PlatformLifetimeEvents> s_nativeToManagedMapper =
new ConcurrentDictionary<IntPtr, X11PlatformLifetimeEvents>();
@ -62,24 +63,24 @@ namespace Avalonia.X11
return;
}
var errorBuf = new char[255];
var smcConn = SMLib.SmcOpenConnection(null!,
byte[] errorBuf = new byte[255];
IntPtr clientIdRet = IntPtr.Zero;
var smcConn = SMLib.SmcOpenConnection(null,
IntPtr.Zero, 1, 0,
SmcSaveYourselfProcMask |
SmcSaveCompleteProcMask |
SmcShutdownCancelledProcMask |
SmcDieProcMask,
ref s_callbacks,
out _,
out _,
null,
ref clientIdRet,
errorBuf.Length,
errorBuf);
if (smcConn == IntPtr.Zero)
{
Logger.TryGet(LogEventLevel.Warning, LogArea.X11Platform)?.Log(this,
$"SMLib/ICELib reported a new error: {new string(errorBuf)}");
$"SMLib/ICELib reported a new error: {Encoding.ASCII.GetString(errorBuf)}");
return;
}

Loading…
Cancel
Save