src/libcrt/crt/pseudo-reloc.c
static void
__write_memory (void *addr, const void *src, size_t len)
{
  MEMORY_BASIC_INFORMATION b;
  DWORD oldprot;

  if (!len)
    return;

  if (!VirtualQuery (addr, &b, sizeof(b)))
    {
      __report_error ("  VirtualQuery failed for %d bytes at address %p",
		      (int) sizeof(b), addr);
    }

  /* Temporarily allow write access to read-only protected memory.  */
  if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
    VirtualProtect (b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE,
		  &oldprot);
  /* write the data. */
  memcpy (addr, src, len);
  /* Restore original protection. */
  if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
    VirtualProtect (b.BaseAddress, b.RegionSize, oldprot, &oldprot);
}
/* This function temporarily marks the page containing addr
 * writable, before copying len bytes from *src to *addr, and
 * then restores the original protection settings to the page.
 *
 * Using this function eliminates the requirement with older
 * pseudo-reloc implementations, that sections containing
 * pseudo-relocs (such as .text and .rdata) be permanently
 * marked writable. This older behavior sabotaged any memory
 * savings achieved by shared libraries on win32 -- and was
 * slower, too.  However, on cygwin as of binutils 2.20 the
 * .text section is still marked writable, and the .rdata section
 * is folded into the (writable) .data when --enable-auto-import.
 */
This function temporarily marks the page containing addr
writable, before copying len bytes from *src to *addr, and
then restores the original protection settings to the page.

Using this function eliminates the requirement with older
pseudo-reloc implementations, that sections containing
pseudo-relocs (such as .text and .rdata) be permanently
marked writable. This older behavior sabotaged any memory
savings achieved by shared libraries on win32 -- and was
slower, too.  However, on cygwin as of binutils 2.20 the
.text section is still marked writable, and the .rdata section
is folded into the (writable) .data when --enable-auto-import.
This function temporarily marks the page containing addr writable before copying len bytes from * src to * addr and then restores the original protection settings to the page . Using this function eliminates the requirement with older pseudo - reloc implementations that sections containing pseudo - relocs ( such as . text and . rdata ) be permanently marked writable . This older behavior sabotaged any memory savings achieved by shared libraries on win32 -- and was slower too . However on cygwin as of binutils 2 . 20 the . text section is still marked writable and the . rdata section is folded into the ( writable ) . data when -- enable - auto - import .
static void
__write_memory (void *addr, const void *src, size_t len)
{
  MEMORY_BASIC_INFORMATION b;
  DWORD oldprot;
  if (!len)
    return;
  if (!VirtualQuery (addr, &b, sizeof(b)))
    {
      __report_error ("  VirtualQuery failed for %d bytes at address %p",
		      (int) sizeof(b), addr);
    }
  if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
    VirtualProtect (b.BaseAddress, b.RegionSize, PAGE_EXECUTE_READWRITE,
		  &oldprot);
  memcpy (addr, src, len);
  if (b.Protect != PAGE_EXECUTE_READWRITE && b.Protect != PAGE_READWRITE)
    VirtualProtect (b.BaseAddress, b.RegionSize, oldprot, &oldprot);
}
static void __write_memory ( void * addr , const void * src , size_t len ) { MEMORY_BASIC_INFORMATION b ; DWORD oldprot ; if ( ! len ) return ; if ( ! VirtualQuery ( addr , & b , sizeof ( b ) ) ) { __report_error ( " " , ( int ) sizeof ( b ) , addr ) ; } if ( b . Protect != PAGE_EXECUTE_READWRITE && b . Protect != PAGE_READWRITE ) VirtualProtect ( b . BaseAddress , b . RegionSize , PAGE_EXECUTE_READWRITE , & oldprot ) ; memcpy ( addr , src , len ) ; if ( b . Protect != PAGE_EXECUTE_READWRITE && b . Protect != PAGE_READWRITE ) VirtualProtect ( b . BaseAddress , b . RegionSize , oldprot , & oldprot ) ; }
This function temporarily marks the page containing addr
 writable, before copying len bytes from *src to *addr, and
 then restores the original protection settings to the page.
This function temporarily marks the page containing addr writable before copying len bytes from * src to * addr and then restores the original protection settings to the page .
/* Temporarily allow write access to read-only protected memory.  */ /* write the data. */ /* Restore original protection. */