From 131d65b3e8b0d32ffd685249d58fd656cdbc2080 Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Mon, 19 Feb 2018 08:37:41 -0800 Subject: [PATCH] Use mmap retry on Cygwin too --- src/pdumper.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/pdumper.c b/src/pdumper.c index dfcf33e3914..9a0770d68ed 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -172,7 +172,7 @@ ptrdiff_t_to_dump_off (ptrdiff_t value) static int dump_get_page_size (void) { -#ifdef WINDOWSNT +#if defined (WINDOWSNT) || defined (CYGWIN) return 64 * 1024; /* Worst-case allocation granularity. */ #else return getpagesize (); @@ -4501,6 +4501,16 @@ dump_mmap_release_vm (struct dump_memory_map *map) dump_unmap_file (map->mapping, map->spec.size); } +static bool +needs_mmap_retry_p (void) +{ +#if defined (CYGWIN) || VM_SUPPORTED == VM_MS_WINDOWS + return true; +#else + return false; +#endif +} + static bool dump_mmap_contiguous_vm ( struct dump_memory_map *maps, @@ -4510,12 +4520,13 @@ dump_mmap_contiguous_vm ( bool ret = false; void *resv = NULL; bool retry = false; + const bool need_retry = needs_mmap_retry_p (); do { if (retry) { - eassert (VM_SUPPORTED == VM_MS_WINDOWS); + eassert (need_retry); retry = false; for (int i = 0; i < nr_maps; ++i) dump_mmap_release (&maps[i]); @@ -4530,7 +4541,7 @@ dump_mmap_contiguous_vm ( char *mem = resv; - if (VM_SUPPORTED == VM_MS_WINDOWS) + if (need_retry) { /* Windows lacks atomic mapping replace; need to release the reservation so we can allocate within it. Will retry the @@ -4555,9 +4566,13 @@ dump_mmap_contiguous_vm ( map->mapping = dump_map_file ( mem, spec.fd, spec.offset, spec.size, spec.protection); mem += spec.size; - if (VM_SUPPORTED == VM_MS_WINDOWS && + if (need_retry && map->mapping == NULL && - errno == EBUSY) + (errno == EBUSY +#ifdef CYGWIN + || errno == EINVAL +#endif + )) { retry = true; continue; @@ -4578,7 +4593,7 @@ dump_mmap_contiguous_vm ( { for (int i = 0; i < nr_maps; ++i) { - if (VM_SUPPORTED == VM_MS_WINDOWS) + if (need_retry) dump_mmap_reset (&maps[i]); else dump_mmap_release (&maps[i]); -- 2.39.5