public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Jon Turney <jon.turney@dronecode.org.uk>
To: David Allsopp <david@tarides.com>,
	The Cygwin Mailing List <cygwin@cygwin.com>
Subject: Re: Debugging malloc crash in gdb
Date: Wed, 2 Nov 2022 12:38:06 +0000	[thread overview]
Message-ID: <20435aae-2753-d49f-2de6-94a4ac624813@dronecode.org.uk> (raw)
In-Reply-To: <CAJQQdJhkJrzJaGVNnbQNqHSDeq1kaXLt5AOXCk3akszCjp=jLA@mail.gmail.com>

On 20/10/2022 09:22, David Allsopp wrote:
> On Tue, 18 Oct 2022 at 20:09, Jon Turney wrote:
>> On 18/10/2022 11:35, David Allsopp wrote:
>>> I'm wondering if I may be able to have some pointers for debugging what
>>> seems to be an unexpected interaction between mmap/mprotect/munmap and
>>> malloc with the OCaml runtime.
[...]>>> 
/cygdrive/d/a/scallywag/gdb/gdb-11.2-1.x86_64/src/gdb-11.2/gdb/infrun.c:2550
>>> : internal-error: void resume_1(gdb_signal): Assertion
>>> `pc_in_thread_step_range (pc, tp)' failed.
> 
> I'm not sure now which combination of stepping directly into the
> malloc call, adding set cygwin-exceptions on or switching to gdb 12.1,
> but either way I was able to get to an invalid memory access in
> mmap_alloc in malloc.cc. At this point, p was a pointer to the start
> of the 256M block which had been passed to munmap.
> 
> What I then noticed from that is a bug in our code - the mmap'd region
> was actually 256M+64K but the size passed to munmap was 256M... so the
> munmap call was not releasing the entire block. Fixing that on the
> OCaml side fixes the error completely - I don't know whether what we
> were seeing before counts as a bug in Cygwin's allocator?

That depends.

Is the ocaml code relying on undefined behaviour, which just happens to 
work elsewhere, but fails on cygwin? Or is it defined behaviour, which 
Cygwin doesn't implement correctly?

(It's not unreasonable that Cygwin's memory allocator is more sensitive 
to some classes of errors than other implementations)


      parent reply	other threads:[~2022-11-02 12:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18 10:35 David Allsopp
2022-10-18 19:08 ` Jon Turney
2022-10-19  6:20   ` Ariel Burbaickij
2022-11-02 12:38     ` Jon Turney
2022-11-02 13:24       ` Ariel Burbaickij
2022-10-20  8:22   ` David Allsopp
2022-10-20  9:38     ` Ariel Burbaickij
2022-11-02 12:38     ` Jon Turney [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20435aae-2753-d49f-2de6-94a4ac624813@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin@cygwin.com \
    --cc=david@tarides.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).