public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "E. Madison Bray" <erik.m.bray@gmail.com>
To: cygwin@cygwin.com
Subject: Consider exposing mmap_is_attached_or_noreserve
Date: Wed, 27 Feb 2019 15:51:00 -0000	[thread overview]
Message-ID: <CAOTD34a-hdE0Jx=7HjB3CMYqgVr6m7Xo39YcmjeL0=43Opjkjg@mail.gmail.com> (raw)

Hello,

A very technical request regarding Cygwin internals: In mmap.c there
is a function mmap_is_attached_or_noreserve(void *addr, size_t len)
which is called from Cygwin's exception handler in the case of a
STATUS_ACCESS_VIOLATION.

This is called in case an access violation occurs in memory that was
allocated with Cygwin's mmap() with the MAP_NORESERVE flag, and allows
us to commit the relevant pages when they are accessed.

After a successful call of mmap_is_attached_or_noreserve(), the Cygwin
exception handler returns with ExceptionContinueExecution.
Unfortunately, if the application happens to have a Vectored Continue
Handler registered which happens to do something in the case of
STATUS_ACCESS_VIOLATION (see [1]) there is no obvious way to tell if
we're handling this sort of case.

Normally this isn't too much of a problem: E.g. we could just check
the address that caused the access violation and see if its status is
now MEM_COMMIT (i.e. Cygwin ran its exception handler and all is
good).  However, due to the bug described in [1], if an exception
occurs in code running on a sigaltstack, the Cygwin exception handler
isn't run.

This makes for a tricky to handle use case:  What if some code in a
signal handler function tries to access uncommitted memory in a
MAP_NORESERVE mmap?  It's probably an unusual, undesirable case, and I
haven't personally encountered it *yet*, but I could imagine some
cases where it might happen.

In order to handle such a case it might be nice if
mmap_is_attached_or_noreserve were able to be called by user code,
perhaps as a new cygwin_internal(...) call.  I'd happily provide a
patch, but I fear this might be an X/Y problem that I'm not seeing.

Thanks,
Madison



[1] https://cygwin.com/ml/cygwin/2018-05/msg00333.html

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

             reply	other threads:[~2019-02-27 15:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-27 15:51 E. Madison Bray [this message]
2019-02-27 16:19 ` Corinna Vinschen
2019-02-27 16:32   ` Corinna Vinschen
2019-02-28 13:12   ` E. Madison Bray
2019-02-28 18:01     ` Corinna Vinschen

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='CAOTD34a-hdE0Jx=7HjB3CMYqgVr6m7Xo39YcmjeL0=43Opjkjg@mail.gmail.com' \
    --to=erik.m.bray@gmail.com \
    --cc=cygwin@cygwin.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).