unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#74274: [PATCH] Revert part of d3f8ed730f to avoid segmentation fault
@ 2024-11-08  6:31 Gong Qijian
  2024-11-09  4:15 ` Gerd Möllmann
  0 siblings, 1 reply; 10+ messages in thread
From: Gong Qijian @ 2024-11-08  6:31 UTC (permalink / raw)
  To: 74274; +Cc: Gerd Möllmann, Gong Qijian

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1930 bytes --]

Patch for branch scratch/tty-child-frames to avoid segmentation fault.

The issue can be triggered by the message function when creating a tty
child frame during the initialization process.

Reproduce:

  $ src/emacs -nw -Q --eval "\
    (progn
      (require 'cl-lib)
      (require 'tty-tip)
      (advice-add 'tty-tip--compute-position :around
       (defun tty-tip--compute-position@fix-nil-error (&rest args)
         (cl-letf ((orig-mouse-position (symbol-function #'mouse-position))
                   ((symbol-function #'mouse-position)
                    (lambda ()
                      (if (terminal-parameter nil 'xterm-mouse-x)
                          (funcall orig-mouse-position)
                        (cons (window-frame) (posn-x-y (posn-at-point)))))))
           (apply args))))

      (tty-tip--create-frame \"line1\nline2\")
      (message \"tty-type: %S\" (tty-type)))"
  Fatal error 11: Segmentation fault
  ^[[Ifish: Job 1, 'src/emacs -nw -Q --eval "\…' terminated by signal (pro… (SIGABRT)
  fish: Job Abort, '' terminated by signal  ()

---
 src/term.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/term.c b/src/term.c
index a7f7baa6e3..8aeabd76b7 100644
--- a/src/term.c
+++ b/src/term.c
@@ -781,7 +781,11 @@ tty_write_glyphs (struct frame *f, struct glyph *string, int len)
     {
       /* Identify a run of glyphs with the same face.  */
       int face_id = string->face_id;
-      struct frame *face_id_frame = string->frame;
+      /* FIXME/tty: it happens that a single glyph's frame is NULL.  It
+	 might depend on a tab bar line being present, then switching
+	 from a buffer without header line to one with header line and
+	 opening a child frame.  */
+      struct frame *face_id_frame = string->frame ? string->frame : f;
 
       for (n = 1; n < stringlen; ++n)
 	if (string[n].face_id != face_id || string[n].frame != face_id_frame)
-- 
2.42.0






^ permalink raw reply related	[flat|nested] 10+ messages in thread

* bug#74274: [PATCH] Revert part of d3f8ed730f to avoid segmentation fault
  2024-11-08  6:31 bug#74274: [PATCH] Revert part of d3f8ed730f to avoid segmentation fault Gong Qijian
@ 2024-11-09  4:15 ` Gerd Möllmann
  2024-11-09  6:10   ` qijian gong
  0 siblings, 1 reply; 10+ messages in thread
From: Gerd Möllmann @ 2024-11-09  4:15 UTC (permalink / raw)
  To: Gong Qijian; +Cc: Gerd Möllmann, 74274

Gong Qijian <gongqijian@gmail.com> writes:

> Patch for branch scratch/tty-child-frames to avoid segmentation fault.
>
> The issue can be triggered by the message function when creating a tty
> child frame during the initialization process.
>
> Reproduce:
>
>   $ src/emacs -nw -Q --eval "\
>     (progn
>       (require 'cl-lib)
>       (require 'tty-tip)
>       (advice-add 'tty-tip--compute-position :around
>        (defun tty-tip--compute-position@fix-nil-error (&rest args)
>          (cl-letf ((orig-mouse-position (symbol-function #'mouse-position))
>                    ((symbol-function #'mouse-position)
>                     (lambda ()
>                       (if (terminal-parameter nil 'xterm-mouse-x)
>                           (funcall orig-mouse-position)
>                         (cons (window-frame) (posn-x-y (posn-at-point)))))))
>            (apply args))))
>
>       (tty-tip--create-frame \"line1\nline2\")
>       (message \"tty-type: %S\" (tty-type)))"
>   Fatal error 11: Segmentation fault
>   ^[[Ifish: Job 1, 'src/emacs -nw -Q --eval "\…' terminated by signal (pro… (SIGABRT)
>   fish: Job Abort, '' terminated by signal  ()

Thanks Gong Qijian, I think I can reproduce this here. Before debugging
this, I'd like to understand your test case a bit better, though. (And
I'm procrastinating a bit :-).)

Do I understand this right, that the advice you add to
tty-tip-compute-position only serves the purpose of being able to pop up
a tip frame early, when mouse-position doesn't really have a position to
report? Or does it also serve another purpose?

Another interesting question would be in which other, let's say more
normal, circumstances you observe this segfault.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#74274: [PATCH] Revert part of d3f8ed730f to avoid segmentation fault
  2024-11-09  4:15 ` Gerd Möllmann
@ 2024-11-09  6:10   ` qijian gong
  2024-11-09  6:59     ` Gerd Möllmann
  0 siblings, 1 reply; 10+ messages in thread
From: qijian gong @ 2024-11-09  6:10 UTC (permalink / raw)
  To: Gerd Möllmann; +Cc: Gerd Möllmann, 74274

[-- Attachment #1: Type: text/plain, Size: 500 bytes --]

Gerd Möllmann <gerd.moellmann@gmail.com>于2024年11月9日 周六下午12:15写道:

Do I understand this right, that the advice you add to
> tty-tip-compute-position only serves the purpose of being able to pop up
> a tip frame early, when mouse-position doesn't really have a position to
> report? Or does it also serve another purpose?
>

Yes, that's correct, there is no other purpose.  It seems mouse-position
doesn't really have a position until the mouse was moved by user.

>

[-- Attachment #2: Type: text/html, Size: 1054 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#74274: [PATCH] Revert part of d3f8ed730f to avoid segmentation fault
  2024-11-09  6:10   ` qijian gong
@ 2024-11-09  6:59     ` Gerd Möllmann
  2024-11-09  7:23       ` Gerd Möllmann
  0 siblings, 1 reply; 10+ messages in thread
From: Gerd Möllmann @ 2024-11-09  6:59 UTC (permalink / raw)
  To: qijian gong; +Cc: Gerd Möllmann, 74274

qijian gong <gongqijian@gmail.com> writes:

> Gerd Möllmann <gerd.moellmann@gmail.com>于2024年11月9日 周六下午12:15写道:
>
>  Do I understand this right, that the advice you add to
>  tty-tip-compute-position only serves the purpose of being able to pop up
>  a tip frame early, when mouse-position doesn't really have a position to
>  report? Or does it also serve another purpose?
>
> Yes, that's correct, there is no other purpose. It seems
> mouse-position doesn't really have a position until the mouse was
> moved by user.

Ok, thanks.

I think I know what this is. It's the very particular case of the very
first redisplay + presence of a child freame, which copies glyphs from a
current matrix that is still clear, i.e. zeroed, so that glyph::frame
is zero and so on.

I wonder a bit - how did you come up with such a test case? :-)
Did you perhaps see this happening elsewhere? That would be interesting.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#74274: [PATCH] Revert part of d3f8ed730f to avoid segmentation fault
  2024-11-09  6:59     ` Gerd Möllmann
@ 2024-11-09  7:23       ` Gerd Möllmann
  2024-11-09  8:02         ` Gerd Möllmann
  2024-11-09  8:17         ` Eli Zaretskii
  0 siblings, 2 replies; 10+ messages in thread
From: Gerd Möllmann @ 2024-11-09  7:23 UTC (permalink / raw)
  To: qijian gong; +Cc: Gerd Möllmann, 74274

Gerd Möllmann <gerd.moellmann@gmail.com> writes:

> qijian gong <gongqijian@gmail.com> writes:
>
>> Gerd Möllmann <gerd.moellmann@gmail.com>于2024年11月9日 周六下午12:15写道:
>>
>>  Do I understand this right, that the advice you add to
>>  tty-tip-compute-position only serves the purpose of being able to pop up
>>  a tip frame early, when mouse-position doesn't really have a position to
>>  report? Or does it also serve another purpose?
>>
>> Yes, that's correct, there is no other purpose. It seems
>> mouse-position doesn't really have a position until the mouse was
>> moved by user.
>
> Ok, thanks.
>
> I think I know what this is. It's the very particular case of the very
> first redisplay + presence of a child freame, which copies glyphs from a
> current matrix that is still clear, i.e. zeroed, so that glyph::frame
> is zero and so on.

Which is fixed for me with

1 file changed, 6 insertions(+), 3 deletions(-)
src/dispnew.c | 9 ++++++---

modified   src/dispnew.c
@@ -3544,9 +3544,12 @@ prepare_desired_root_row (struct frame *root, int y)
   if (!root_row->enabled_p)
     {
       struct glyph_row *from = MATRIX_ROW (root->current_matrix, y);
-      memcpy (root_row->glyphs[0], from->glyphs[0],
-	      root->current_matrix->matrix_w * sizeof (struct glyph));
-      root_row->enabled_p = true;
+      if (from->enabled_p)
+	{
+	  memcpy (root_row->glyphs[0], from->glyphs[0],
+		  root->current_matrix->matrix_w * sizeof (struct glyph));
+	  root_row->enabled_p = true;
+	}
     }
   return root_row;
 }






^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#74274: [PATCH] Revert part of d3f8ed730f to avoid segmentation fault
  2024-11-09  7:23       ` Gerd Möllmann
@ 2024-11-09  8:02         ` Gerd Möllmann
  2024-11-09  8:17         ` Eli Zaretskii
  1 sibling, 0 replies; 10+ messages in thread
From: Gerd Möllmann @ 2024-11-09  8:02 UTC (permalink / raw)
  To: qijian gong; +Cc: Gerd Möllmann, 74274

Gerd Möllmann <gerd.moellmann@gmail.com> writes:

> Which is fixed for me with

Also committed to savannah now.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#74274: [PATCH] Revert part of d3f8ed730f to avoid segmentation fault
  2024-11-09  7:23       ` Gerd Möllmann
  2024-11-09  8:02         ` Gerd Möllmann
@ 2024-11-09  8:17         ` Eli Zaretskii
  2024-11-09  8:26           ` Gerd Möllmann
  1 sibling, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2024-11-09  8:17 UTC (permalink / raw)
  To: Gerd Möllmann; +Cc: gerd, gongqijian, 74274

> Cc: Gerd Möllmann <gerd@gnu.org>, 74274@debbugs.gnu.org
> From: Gerd Möllmann <gerd.moellmann@gmail.com>
> Date: Sat, 09 Nov 2024 08:23:44 +0100
> 
> Gerd Möllmann <gerd.moellmann@gmail.com> writes:
> 
> > qijian gong <gongqijian@gmail.com> writes:
> >
> >> Gerd Möllmann <gerd.moellmann@gmail.com>于2024年11月9日 周六下午12:15写道:
> >>
> >>  Do I understand this right, that the advice you add to
> >>  tty-tip-compute-position only serves the purpose of being able to pop up
> >>  a tip frame early, when mouse-position doesn't really have a position to
> >>  report? Or does it also serve another purpose?
> >>
> >> Yes, that's correct, there is no other purpose. It seems
> >> mouse-position doesn't really have a position until the mouse was
> >> moved by user.
> >
> > Ok, thanks.
> >
> > I think I know what this is. It's the very particular case of the very
> > first redisplay + presence of a child freame, which copies glyphs from a
> > current matrix that is still clear, i.e. zeroed, so that glyph::frame
> > is zero and so on.
> 
> Which is fixed for me with
> 
> 1 file changed, 6 insertions(+), 3 deletions(-)
> src/dispnew.c | 9 ++++++---
> 
> modified   src/dispnew.c
> @@ -3544,9 +3544,12 @@ prepare_desired_root_row (struct frame *root, int y)
>    if (!root_row->enabled_p)
>      {
>        struct glyph_row *from = MATRIX_ROW (root->current_matrix, y);
> -      memcpy (root_row->glyphs[0], from->glyphs[0],
> -	      root->current_matrix->matrix_w * sizeof (struct glyph));
> -      root_row->enabled_p = true;
> +      if (from->enabled_p)
> +	{
> +	  memcpy (root_row->glyphs[0], from->glyphs[0],
> +		  root->current_matrix->matrix_w * sizeof (struct glyph));
> +	  root_row->enabled_p = true;
> +	}
>      }
>    return root_row;
>  }

Should this perhaps have an eassert which verifies that every glyph
has a valid frame pointer?  At the very least please add a comment
there explaining the need for the enabled_p test and mentioning the
frame pointer of the glyphs.

Thanks.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#74274: [PATCH] Revert part of d3f8ed730f to avoid segmentation fault
  2024-11-09  8:17         ` Eli Zaretskii
@ 2024-11-09  8:26           ` Gerd Möllmann
  2024-11-10 10:56             ` Gerd Möllmann
  0 siblings, 1 reply; 10+ messages in thread
From: Gerd Möllmann @ 2024-11-09  8:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gerd, gongqijian, 74274

Eli Zaretskii <eliz@gnu.org> writes:

> Should this perhaps have an eassert which verifies that every glyph
> has a valid frame pointer?  At the very least please add a comment
> there explaining the need for the enabled_p test and mentioning the
> frame pointer of the glyphs.

I don't know. It's one of the most basic things about the meaning of
enabled_p in current glyphs, and it's not limited the frame pointer in
any way.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#74274: [PATCH] Revert part of d3f8ed730f to avoid segmentation fault
  2024-11-09  8:26           ` Gerd Möllmann
@ 2024-11-10 10:56             ` Gerd Möllmann
  2024-11-10 19:06               ` Gerd Möllmann
  0 siblings, 1 reply; 10+ messages in thread
From: Gerd Möllmann @ 2024-11-10 10:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gerd, gongqijian, 74274

Gerd Möllmann <gerd.moellmann@gmail.com> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>> Should this perhaps have an eassert which verifies that every glyph
>> has a valid frame pointer?  At the very least please add a comment
>> there explaining the need for the enabled_p test and mentioning the
>> frame pointer of the glyphs.
>
> I don't know. It's one of the most basic things about the meaning of
> enabled_p in current glyphs, and it's not limited the frame pointer in
> any way.

Found another case of copying from non-enabled glyphs. Reproducable with
emacs -q -l with a file containing

  (with-current-buffer (get-buffer-create "1")
    (setq header-line-format
          '((:eval (format "*package*: -  symbol-packages: - lexical-binding: %s"
                           lexical-binding)))))
  (with-current-buffer (get-buffer-create "2")
    (insert "something"))

  (let ((w1 (selected-window))
        (w2 (split-window-right)))
    (set-window-buffer w1 (get-buffer "1"))
    (set-window-buffer w2 (get-buffer "2"))
    (message "message"))

It's a 30 years old bug, so it isn't something urgent to fix.

I'll port something to savannah as soon as I find the time.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#74274: [PATCH] Revert part of d3f8ed730f to avoid segmentation fault
  2024-11-10 10:56             ` Gerd Möllmann
@ 2024-11-10 19:06               ` Gerd Möllmann
  0 siblings, 0 replies; 10+ messages in thread
From: Gerd Möllmann @ 2024-11-10 19:06 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gerd, gongqijian, 74274

Gerd Möllmann <gerd.moellmann@gmail.com> writes:

> I'll port something to savannah as soon as I find the time.

Done, and closing because I don't expect further input.





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-11-10 19:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-08  6:31 bug#74274: [PATCH] Revert part of d3f8ed730f to avoid segmentation fault Gong Qijian
2024-11-09  4:15 ` Gerd Möllmann
2024-11-09  6:10   ` qijian gong
2024-11-09  6:59     ` Gerd Möllmann
2024-11-09  7:23       ` Gerd Möllmann
2024-11-09  8:02         ` Gerd Möllmann
2024-11-09  8:17         ` Eli Zaretskii
2024-11-09  8:26           ` Gerd Möllmann
2024-11-10 10:56             ` Gerd Möllmann
2024-11-10 19:06               ` Gerd Möllmann

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).