I've tried both patches (fixed conditions in Kai's) and both eliminate
extraneous calls to VirtualProtect.  However Kai's patch did not seem to
affect startup performance at all.   DW's patch, on the other hand, also
gets rid of VirtualQuery', and that cuts down the startup time of my test
example by 40%.
Thanks!

Vadim


On Fri, Oct 24, 2014 at 5:53 PM, dw <da...@limegreensocks.com> wrote:

>
> > Ups, that was unintended to send an empty mail :)
>
> I did wonder.  I assumed it was just a ping.
>
> > So, here is a patch.
>
> Your patch does not look right.  You have added the new checks using "||"?
>
> > It would be great if somebody could verify that the reported
> > issue is solved by it.
>
> Yes, this is the hard part.  Vadim seems to be able to produce this with
> no problem, but I'm having no luck getting it to happen at all.
>
> BTW, what is __MINGW64_VERSION_MAJOR for?  Is there a time when it might
> not be defined in pseudo-reloc?  If it is defined, we end up checking
> the page attributes twice.
>
> FWIW, my patch (which I haven't been able to test either) looks like
> this (removes the duplicate check):
>
> ----------------------- mingw-w64-crt/crt/pseudo-reloc.c
> -----------------------
> index 4e7f31b..7709208 100644
> @@ -206,7 +206,8 @@ mark_section_writable (LPVOID addr)
>         return;
>       }
>
> -  if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
> +  if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE
> +      && b.Protect != PAGE_EXECUTE_WRITECOPY && b.Protect !=
> PAGE_WRITECOPY)
>       {
>         if (!VirtualProtect (b.BaseAddress, b.RegionSize,
>                  PAGE_EXECUTE_READWRITE,
> @@ -259,16 +260,17 @@ restore_modified_sections (void)
>   static void
>   __write_memory (void *addr, const void *src, size_t len)
>   {
> -  MEMORY_BASIC_INFORMATION b;
> -  DWORD oldprot;
> -  int call_unprotect = 0;
> -
>     if (!len)
>       return;
>
>   #ifdef __MINGW64_VERSION_MAJOR
> +  /* Mark the section writable once, and unset it in
> +   * restore_modified_sections */
>     mark_section_writable ((LPVOID) addr);
> -#endif
> +#else
> +  MEMORY_BASIC_INFORMATION b;
> +  DWORD oldprot = 0;
> +  int call_unprotect = 0;
>
>     if (!VirtualQuery (addr, &b, sizeof(b)))
>       {
> @@ -277,18 +279,25 @@ __write_memory (void *addr, const void *src,
> size_t len)
>       }
>
>     /* Temporarily allow write access to read-only protected memory. */
> -  if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
> +  if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE
> +      && b.Protect != PAGE_WRITECOPY && b.Protect !=
> PAGE_EXECUTE_WRITECOPY)
>       {
>         call_unprotect = 1;
>         VirtualProtect (b.BaseAddress, b.RegionSize,
> PAGE_EXECUTE_READWRITE,
>                 &oldprot);
>       }
> +#endif
>
>     /* write the data. */
>     memcpy (addr, src, len);
> +
> +#ifndef __MINGW64_VERSION_MAJOR
>     /* Restore original protection. */
> -  if (call_unprotect && b.Protect != PAGE_EXECUTE_READWRITE &&
> b.Protect != PAGE_READWRITE)
> +  if (call_unprotect
> +      && b.Protect != PAGE_EXECUTE_READWRITE && b.Protect !=
> PAGE_READWRITE
> +      && b.Protect != PAGE_WRITECOPY && b.Protect !=
> PAGE_EXECUTE_WRITECOPY)
>       VirtualProtect (b.BaseAddress, b.RegionSize, oldprot, &oldprot);
> +#endif
>   }
>
>   #define RP_VERSION_V1 0
>
>
> ------------------------------------------------------------------------------
>
>
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Mingw-w64-public mailing list
> Mingw-w64-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
------------------------------------------------------------------------------
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to