From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Liam Quinlan Newsgroups: gmane.emacs.devel Subject: --with-cairo Emacs server crash and fix Date: Thu, 8 Aug 2019 03:01:39 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000bd3158058f95a1bf" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="69498"; mail-complaints-to="usenet@blaine.gmane.org" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 08 15:03:04 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hvi4M-000Hrh-Hs for ged-emacs-devel@m.gmane.org; Thu, 08 Aug 2019 15:03:02 +0200 Original-Received: from localhost ([::1]:50320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvi4L-0005iF-1j for ged-emacs-devel@m.gmane.org; Thu, 08 Aug 2019 09:03:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51390) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvcQv-00039G-PN for emacs-devel@gnu.org; Thu, 08 Aug 2019 03:02:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvcQs-0003cz-QD for emacs-devel@gnu.org; Thu, 08 Aug 2019 03:01:56 -0400 Original-Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]:35614) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hvcQq-0003ah-30 for emacs-devel@gnu.org; Thu, 08 Aug 2019 03:01:52 -0400 Original-Received: by mail-ot1-x32d.google.com with SMTP id j19so37908689otq.2 for ; Thu, 08 Aug 2019 00:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=0GUbFScoaiRTQqbHR4G7LkzkGuH9lYzrkC3RdmtTWr8=; b=XF9fpt5ogzCWLRuQHzj4ruO2rQm0S0jl9lPE2XuafEhEHQ4aLwMamBR4yGZZowAsHn 14pgu1zBHG7ofsrEEjhTQD4iCZPuPZ33faU6017zfFWbMHFJ2TpRzRrijHw+IdO3PjBn A0hskJVvvBvdUMjc5YCdjwkm48S2RJ88tQN+v7No4jKYme6opYJs3ArkVfIhbE7CnTLj sl0C0Nv+FtxLmz4cnI+SkcI6m6gfTs+CkWf7oVb0dG5loOI9/0esnewoy3crd2GaP3VT a2R0f1q4Z2Vie+r4hF5dfZp8y9/9p/2zHYoeYYyyOohQopIb1mZ+Flk1syOX3sTI5U4W egVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=0GUbFScoaiRTQqbHR4G7LkzkGuH9lYzrkC3RdmtTWr8=; b=FiWgmSo2v/hRSKh9i2siKvI9p+ZeBFp97zH5XNjfsJRzzBEoYPVlr4/R0BSvTsuLDE 7Bx7KwTygw7SPMDYA107Lz9sKyAEQsXIU55x/qeS50//6od9ACmRMV90Ow/DlVYlFMOi Uo2LDYR7eDQlxKhwnIP0AZLZyN1ju7h3hbA3o4NLaPP9JAkW0MCFDkVtPLSCjNxYoKS7 rQ+ivY/FXdj9Gl/7CMbcoKtfwltU/XAFkhfO76N0/KOe/aiBmAZscoFrRLLoexPMc/sf L6sdOjwikkHZB4wBIe02dB0xUd+AVzSu+2RQ2sRXNKMT8Y5bGAeZrPh4Cp+1WigulpG5 HdqA== X-Gm-Message-State: APjAAAX2+AzZPB6Gma5heMKxsbu+owwThawOX9OBAhjNtKheGruOn9QC DsuEUSTDBulM0ERRc1te/ju4tOjTS0SM9MoA8h0BDQ== X-Google-Smtp-Source: APXvYqxsA1Zt5qXRzU75PalIV3Bc+hHzuVIVcHNEOCx2nAOxHvI0ZKAD/+BKwv/HrrnsLFMUjeFNGidPdmEiknr7lH8= X-Received: by 2002:a5d:9749:: with SMTP id c9mr4194160ioo.258.1565247709980; Thu, 08 Aug 2019 00:01:49 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::32d X-Mailman-Approved-At: Thu, 08 Aug 2019 09:02:42 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:239248 Archived-At: --000000000000bd3158058f95a1bf Content-Type: text/plain; charset="UTF-8" If emacs is compiled for xwindows --with-cairo, then started with --daemon, and any packages that define a fringe bitmap are used (including builtin flymake), then 'define-fringe-bitmap' will be called from lisp during startup and attempt to define dynamic bitmaps when emacs has no active frame. This is a problem because 'init_fringe_bitmap' (in src/fringe.c) relies on the SELECTED_FRAME macro in order to access a redisplay_interface structure and call 'rif->define_fringe_bitmap'. Until a frame is created for a client session, this process will fail, causing emacs to skip calling 'rif->define_fringe_bitmap' (which should initialize 'fringe_bmp[which]' for cairo builds), but otherwise proceed as if the bitmap in question exists. (note the code in question already contains the following comment: '/* XXX Is SELECTED_FRAME OK here? */' ... it is not.) The upshot from there is, if[/when] emacs tries to *draw* these bitmaps, it pulls a null pointer out of 'fringe_bmp[which]' and hands it straight to libcairo. Predictably, libcairo retaliates with the SEGV, and it's all over but the coredumping. As best as I can tell, the following diff resolves the issue (at least as it manifests when using X; I haven't experimented with other configurations). Style-wise it's a touch crude and hamfisted, but tbh trying to figure out the right approach for this codebase seemed to mean a whole lot of stumbling through giant briar patches of macro indirection, and I bailed. Hopefully someone familiar with all that stuff can translate it readily enough. [git diff against commit d5622eb6fff94714c5d5a64c98c5e02bc1be478c] diff --git a/src/frame.h b/src/frame.h index fa45a32d6b..94a880f4eb 100644 --- a/src/frame.h +++ b/src/frame.h @@ -1587,6 +1587,9 @@ #define EMACS_CLASS "Emacs" #if defined HAVE_X_WINDOWS extern void x_wm_set_icon_position (struct frame *, int, int); + #if defined USE_CAIRO + extern struct redisplay_interface x_redisplay_interface; + #endif #if !defined USE_X_TOOLKIT extern const char *x_get_resource_string (const char *, const char *); #endif diff --git a/src/fringe.c b/src/fringe.c index d0d599223d..7a93afd418 100644 --- a/src/fringe.c +++ b/src/fringe.c @@ -1482,6 +1482,10 @@ init_fringe_bitmap (int which, struct fringe_bitmap *fb, int once_p) if (rif && rif->define_fringe_bitmap) rif->define_fringe_bitmap (which, fb->bits, fb->height, fb->width); +#if (defined HAVE_X_WINDOWS) && (defined USE_CAIRO) + else + x_redisplay_interface.define_fringe_bitmap(which, fb->bits, fb->height, fb->width); +#endif fringe_bitmaps[which] = fb; if (which >= max_used_fringe_bitmap) diff --git a/src/xterm.c b/src/xterm.c index bbe68ef622..76fc5c21ac 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -13298,7 +13298,7 @@ x_activate_timeout_atimer (void) extern frame_parm_handler x_frame_parm_handlers[]; -static struct redisplay_interface x_redisplay_interface = +struct redisplay_interface x_redisplay_interface = { x_frame_parm_handlers, gui_produce_glyphs, --000000000000bd3158058f95a1bf Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

If emacs is= compiled for xwindows --with-cairo, then started with --daemon, and any pa= ckages that define a fringe bitmap are used (including builtin flymake), th= en 'define-fringe-bitmap' will be called from lisp during startup a= nd attempt to define dynamic bitmaps when emacs has no active frame.
<= div dir=3D"auto">
This is a problem because '= ;init_fringe_bitmap' (in src/fringe.c) relies on the SELECTED_FRAME mac= ro in order to access a redisplay_interface structure and call 'rif->= ;define_fringe_bitmap'.=C2=A0 Until a frame is created for a client ses= sion, this process will fail, causing emacs to skip calling 'rif->de= fine_fringe_bitmap' (which should initialize 'fringe_bmp[which]'= ; for cairo builds), but otherwise proceed as if the bitmap in question exi= sts.=C2=A0 (note the code in question already contains the following commen= t: '/* XXX Is SELECTED_FRAME OK here? */' ... it is not.)

The upshot from there is, if[/whe= n] emacs tries to *draw* these bitmaps, it pulls a null pointer out of '= ;fringe_bmp[which]' and hands it straight to libcairo.=C2=A0 Predictabl= y, libcairo retaliates with the SEGV, and it's all over but the coredum= ping.


As best as I can tell, the following diff resolves the issue (at = least as it manifests when using X; I haven't experimented with other c= onfigurations).=C2=A0 Style-wise it's a touch crude and hamfisted, but = tbh trying to figure out the right approach for this codebase seemed to mea= n a whole lot of stumbling through giant briar patches of macro indirection= , and I bailed.=C2=A0 Hopefully someone familiar with all that stuff can tr= anslate it readily enough.
[git diff against commit = d5622eb6fff94714c5d5a64c98c5e02bc1be478c]

=
diff --git a/src/frame.h b/src/frame.h
index fa45a32d6b..94a880f4eb 100644
--- a/src/f= rame.h
+++ b/src/frame.h
@@ -= 1587,6 +1587,9 @@ #define EMACS_CLASS "Emacs"
=C2=A0
=C2=A0#if defined HAVE_X_WINDOWS
=C2=A0extern void x_wm_set_icon_position (struct frame *, in= t, int);
+=C2=A0 #if defined USE_CAIRO
+=C2=A0 extern struct redisplay_interface x_redisplay_interface;<= /div>
+=C2=A0 #endif
=C2=A0#if !def= ined USE_X_TOOLKIT
=C2=A0extern const char *x_get_re= source_string (const char *, const char *);
=C2=A0#e= ndif
diff --git a/src/fringe.c b/src/fringe.c
<= div dir=3D"auto">index d0d599223d..7a93afd418 100644
--- a/src/fringe.c
+++ b/src/fringe.c
@@ -1482,6 +1482,10 @@ init_fringe_bitmap (int which, struct frin= ge_bitmap *fb, int once_p)
=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0if (rif && rif->define_fringe_bi= tmap)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 rif->define_fri= nge_bitmap (which, fb->bits, fb->height, fb->width);
+#if (defined HAVE_X_WINDOWS) && (defined USE_CAIRO)
+=C2=A0 =C2=A0 =C2=A0 else
+=C2= =A0 =C2=A0 =C2=A0 =C2=A0 x_redisplay_interface.define_fringe_bitmap(which, = fb->bits, fb->height, fb->width);
+#endif
=C2=A0
=C2=A0 =C2=A0 =C2=A0 = =C2=A0fringe_bitmaps[which] =3D fb;
=C2=A0 =C2=A0 = =C2=A0 =C2=A0if (which >=3D max_used_fringe_bitmap)
diff --git a/src/xterm.c b/src/xterm.c
index bbe6= 8ef622..76fc5c21ac 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -13298,7 +13298,= 7 @@ x_activate_timeout_atimer (void)
=C2=A0
=C2=A0extern frame_parm_handler x_frame_parm_handlers[];
=C2=A0
-static struct redisplay= _interface x_redisplay_interface =3D
+struct redispl= ay_interface x_redisplay_interface =3D
=C2=A0 =C2=A0= {
=C2=A0 =C2=A0 =C2=A0x_frame_parm_handlers,
=C2=A0 =C2=A0 =C2=A0gui_produce_glyphs,
--000000000000bd3158058f95a1bf--