Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/lib')
-rw-r--r--winsup/cygwin/lib/_cygwin_crt0_common.cc156
-rw-r--r--winsup/cygwin/lib/crt0.h23
-rw-r--r--winsup/cygwin/lib/cygwin_attach_dll.c27
-rw-r--r--winsup/cygwin/lib/cygwin_crt0.c23
-rw-r--r--winsup/cygwin/lib/dll_entry.c17
-rw-r--r--winsup/cygwin/lib/dll_main.cc38
-rw-r--r--winsup/cygwin/lib/libcmain.c43
-rw-r--r--winsup/cygwin/lib/premain0.c14
-rw-r--r--winsup/cygwin/lib/premain1.c14
-rw-r--r--winsup/cygwin/lib/premain2.c14
-rw-r--r--winsup/cygwin/lib/premain3.c14
-rw-r--r--winsup/cygwin/lib/pseudo-reloc.c367
12 files changed, 0 insertions, 750 deletions
diff --git a/winsup/cygwin/lib/_cygwin_crt0_common.cc b/winsup/cygwin/lib/_cygwin_crt0_common.cc
deleted file mode 100644
index 173f85268..000000000
--- a/winsup/cygwin/lib/_cygwin_crt0_common.cc
+++ /dev/null
@@ -1,156 +0,0 @@
-/* _cygwin_crt0_common.cc: common crt0 function for cygwin crt0's.
-
- Copyright 2000, 2001, 2002, 2003, 2004, 2009 Red Hat, Inc.
-
-This file is part of Cygwin.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-#include "winsup.h"
-#include "crt0.h"
-#include "cygwin-cxx.h"
-
-/* Weaken these declarations so the references don't pull in C++ dependencies
- unnecessarily. */
-#define WEAK __attribute__ ((weak))
-
-/* Use asm names to bypass the --wrap that is being applied to redirect all other
- references to these operators toward the redirectors in the Cygwin DLL; this
- way we can record what definitions were visible at final link time but still
- send all calls to the redirectors. */
-extern WEAK void *operator new(std::size_t sz) throw (std::bad_alloc)
- __asm__ ("___real__Znwj");
-extern WEAK void *operator new[](std::size_t sz) throw (std::bad_alloc)
- __asm__ ("___real__Znaj");
-extern WEAK void operator delete(void *p) throw()
- __asm__ ("___real__ZdlPv ");
-extern WEAK void operator delete[](void *p) throw()
- __asm__ ("___real__ZdaPv");
-extern WEAK void *operator new(std::size_t sz, const std::nothrow_t &nt) throw()
- __asm__ ("___real__ZnwjRKSt9nothrow_t");
-extern WEAK void *operator new[](std::size_t sz, const std::nothrow_t &nt) throw()
- __asm__ ("___real__ZnajRKSt9nothrow_t");
-extern WEAK void operator delete(void *p, const std::nothrow_t &nt) throw()
- __asm__ ("___real__ZdlPvRKSt9nothrow_t");
-extern WEAK void operator delete[](void *p, const std::nothrow_t &nt) throw()
- __asm__ ("___real__ZdaPvRKSt9nothrow_t");
-
-/* Avoid an info message from linker when linking applications. */
-extern __declspec(dllimport) struct _reent *_impure_ptr;
-
-/* Initialised in _cygwin_dll_entry. */
-extern int __dynamically_loaded;
-
-#undef environ
-
-extern "C"
-{
-char **environ;
-int cygwin_attach_dll (HMODULE, MainFunc);
-int cygwin_attach_noncygwin_dll (HMODULE, MainFunc);
-int main (int, char **, char **);
-int _fmode;
-void _pei386_runtime_relocator ();
-
-struct per_process_cxx_malloc __cygwin_cxx_malloc =
-{
- &(operator new), &(operator new[]),
- &(operator delete), &(operator delete[]),
- &(operator new), &(operator new[]),
- &(operator delete), &(operator delete[])
-};
-
-/* Set up pointers to various pieces so the dll can then use them,
- and then jump to the dll. */
-
-int __stdcall
-_cygwin_crt0_common (MainFunc f, per_process *u)
-{
- per_process *newu = (per_process *) cygwin_internal (CW_USER_DATA);
- bool uwasnull;
-
- /* u is non-NULL if we are in a DLL, and NULL in the main exe.
- newu is the Cygwin DLL's internal per_process and never NULL. */
- if (u != NULL)
- uwasnull = false; /* Caller allocated space for per_process structure. */
- else
- {
- u = newu; /* Using DLL built-in per_process. */
- uwasnull = true; /* Remember for later. */
- }
-
- /* The version numbers are the main source of compatibility checking.
- As a backup to them, we use the size of the per_process struct. */
- u->magic_biscuit = sizeof (per_process);
-
- /* cygwin.dll version number in effect at the time the app was created. */
- u->dll_major = CYGWIN_VERSION_DLL_MAJOR;
- u->dll_minor = CYGWIN_VERSION_DLL_MINOR;
- u->api_major = CYGWIN_VERSION_API_MAJOR;
- u->api_minor = CYGWIN_VERSION_API_MINOR;
-
- u->ctors = &__CTOR_LIST__;
- u->dtors = &__DTOR_LIST__;
- u->envptr = &environ;
- if (uwasnull)
- _impure_ptr = u->impure_ptr; /* Use field initialized in newer DLLs. */
- else
- u->impure_ptr_ptr = &_impure_ptr; /* Older DLLs need this. */
-
- u->main = f;
-
- /* These functions are executed prior to main. They are just stubs unless the
- user overrides them. */
- u->premain[0] = cygwin_premain0;
- u->premain[1] = cygwin_premain1;
- u->premain[2] = cygwin_premain2;
- u->premain[3] = cygwin_premain3;
- u->fmode_ptr = &_fmode;
-
- /* This is used to record what the initial sp was. The value is needed
- when copying the parent's stack to the child during a fork. */
- u->initial_sp = (char *) __builtin_frame_address (1);
-
- /* Remember whatever the user linked his application with - or
- point to entries in the dll. */
- u->malloc = &malloc;
- u->free = &free;
- u->realloc = &realloc;
- u->calloc = &calloc;
-
- /* Likewise for the C++ memory operators, if any, but not if we
- were dlopen()'d, as we might get dlclose()'d and that would
- leave stale function pointers behind. */
- if (newu && newu->cxx_malloc && !__dynamically_loaded)
- {
- /* Inherit what we don't override. */
-#define CONDITIONALLY_OVERRIDE(MEMBER) \
- if (!__cygwin_cxx_malloc.MEMBER) \
- __cygwin_cxx_malloc.MEMBER = newu->cxx_malloc->MEMBER;
- CONDITIONALLY_OVERRIDE(oper_new);
- CONDITIONALLY_OVERRIDE(oper_new__);
- CONDITIONALLY_OVERRIDE(oper_delete);
- CONDITIONALLY_OVERRIDE(oper_delete__);
- CONDITIONALLY_OVERRIDE(oper_new_nt);
- CONDITIONALLY_OVERRIDE(oper_new___nt);
- CONDITIONALLY_OVERRIDE(oper_delete_nt);
- CONDITIONALLY_OVERRIDE(oper_delete___nt);
- /* Now update the resulting set into the global redirectors. */
- *newu->cxx_malloc = __cygwin_cxx_malloc;
- }
-
- /* Setup the module handle so fork can get the path name. */
- u->hmodule = GetModuleHandle (0);
-
- /* variables for fork */
- u->data_start = &_data_start__;
- u->data_end = &_data_end__;
- u->bss_start = &_bss_start__;
- u->bss_end = &_bss_end__;
-
- _pei386_runtime_relocator ();
- return 1;
-}
-} /* "C" */
diff --git a/winsup/cygwin/lib/crt0.h b/winsup/cygwin/lib/crt0.h
deleted file mode 100644
index 461ea9b2e..000000000
--- a/winsup/cygwin/lib/crt0.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* crt0.h: header file for crt0.
-
- Copyright 2000, 2001, 2008 Red Hat, Inc.
-
-This file is part of Cygwin.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <windows.h>
-struct per_process;
-typedef int (*MainFunc) (int argc, char *argv[], char **env);
-int __stdcall _cygwin_crt0_common (MainFunc, struct per_process *);
-int dll_dllcrt0 (HMODULE, struct per_process *);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/winsup/cygwin/lib/cygwin_attach_dll.c b/winsup/cygwin/lib/cygwin_attach_dll.c
deleted file mode 100644
index 49bb9256d..000000000
--- a/winsup/cygwin/lib/cygwin_attach_dll.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* attach_dll.cc: crt0 for attaching cygwin DLL from a non-cygwin app.
-
- Copyright 2000, 2001 Red Hat, Inc.
-
-This file is part of Cygwin.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-#undef __INSIDE_CYGWIN__
-#include <windows.h>
-#include <time.h> /* Needed since call to sys/time.h via sys/cygwin.h
- complains otherwise */
-#include <sys/cygwin.h>
-#include "crt0.h"
-
-/* for a loaded dll */
-int
-cygwin_attach_dll (HMODULE h, MainFunc f)
-{
- static struct per_process u;
- (void) _cygwin_crt0_common (f, &u);
-
- /* jump into the dll. */
- return dll_dllcrt0 (h, &u);
-}
diff --git a/winsup/cygwin/lib/cygwin_crt0.c b/winsup/cygwin/lib/cygwin_crt0.c
deleted file mode 100644
index a3aa07773..000000000
--- a/winsup/cygwin/lib/cygwin_crt0.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/* cygwin_crt0.cc: crt0 for cygwin
-
- Copyright 2000, 2001, 2008, 2009 Red Hat, Inc.
-
-This file is part of Cygwin.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-#undef __INSIDE_CYGWIN__
-#include "crt0.h"
-
-extern void __stdcall _dll_crt0 ()
- __declspec (dllimport) __attribute ((noreturn));
-
-/* for main module */
-void
-cygwin_crt0 (MainFunc f)
-{
- _cygwin_crt0_common (f, NULL);
- _dll_crt0 (); /* Jump into the dll, never to return */
-}
diff --git a/winsup/cygwin/lib/dll_entry.c b/winsup/cygwin/lib/dll_entry.c
deleted file mode 100644
index 781f6a3ea..000000000
--- a/winsup/cygwin/lib/dll_entry.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/* dll_entry.cc: Provide the default user DLL linker entry point.
-
- Copyright 1998, 2000, 2001 Red Hat, Inc.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-/* Here we simply instantiate the DECLARE_CYGWIN_DLL to define the
- linker entry point, __cygwin_dll_entry@12, which in turn calls
- _DllMain@12 to do user-specific initialization, if any. There is a
- default DllMain stub in the library if there is no user supplied
- one. */
-
-#include "cygwin/cygwin_dll.h"
-
-DECLARE_CYGWIN_DLL (DllMain);
diff --git a/winsup/cygwin/lib/dll_main.cc b/winsup/cygwin/lib/dll_main.cc
deleted file mode 100644
index 7f977f689..000000000
--- a/winsup/cygwin/lib/dll_main.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-/* dll_main.cc: Provide the DllMain stub that the user can override.
-
- Copyright 1998, 2000, 2001, 2009 Red Hat, Inc.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-extern "C"
-BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason,
- LPVOID reserved /* Not used. */);
-
-BOOL APIENTRY
-DllMain (
- HINSTANCE hInst /* Library instance handle. */ ,
- DWORD reason /* Reason this function is being called. */ ,
- LPVOID reserved /* Not used. */)
-{
- switch (reason)
- {
- case DLL_PROCESS_ATTACH:
- break;
-
- case DLL_PROCESS_DETACH:
- break;
-
- case DLL_THREAD_ATTACH:
- break;
-
- case DLL_THREAD_DETACH:
- break;
- }
- return TRUE;
-}
diff --git a/winsup/cygwin/lib/libcmain.c b/winsup/cygwin/lib/libcmain.c
deleted file mode 100644
index d1faba1b3..000000000
--- a/winsup/cygwin/lib/libcmain.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* libcmain.c
-
- Copyright 1996, 1997, 1998, 2000, 2001, 2006, 2009 Red Hat, Inc.
-
-This file is part of Cygwin.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-#include <windows.h>
-
-#define SP " \t\n"
-
-/* Allow apps which don't have a main to work, as long as they define WinMain */
-int
-main ()
-{
- HMODULE x = GetModuleHandle (0);
- char *s = GetCommandLine ();
- STARTUPINFO si;
- char *nexts;
-
- s += strspn (s, SP);
-
- if (*s != '"')
- nexts = strpbrk (s, SP);
- else
- while ((nexts = strchr (s + 1, '"')) != NULL && nexts[-1] == '\\')
- s = nexts;
-
- if (!nexts)
- nexts = strchr (s, '\0');
- else
- nexts += strspn (nexts + 1, SP);
-
- GetStartupInfo (&si);
-
- return WinMain (x, 0, nexts,
- ((si.dwFlags & STARTF_USESHOWWINDOW) != 0
- ? si.wShowWindow
- : SW_SHOWNORMAL));
-}
diff --git a/winsup/cygwin/lib/premain0.c b/winsup/cygwin/lib/premain0.c
deleted file mode 100644
index b77e02e8e..000000000
--- a/winsup/cygwin/lib/premain0.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/* premain0.c
-
- Copyright 2000 Red Hat, Inc.
-
-This file is part of Cygwin.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-void
-cygwin_premain0(int argc, char **argv)
-{
-}
diff --git a/winsup/cygwin/lib/premain1.c b/winsup/cygwin/lib/premain1.c
deleted file mode 100644
index 99aeac916..000000000
--- a/winsup/cygwin/lib/premain1.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/* premain1.c
-
- Copyright 2000 Red Hat, Inc.
-
-This file is part of Cygwin.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-void
-cygwin_premain1(int argc, char **argv)
-{
-}
diff --git a/winsup/cygwin/lib/premain2.c b/winsup/cygwin/lib/premain2.c
deleted file mode 100644
index a89e76ec3..000000000
--- a/winsup/cygwin/lib/premain2.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/* premain2.c
-
- Copyright 2000 Red Hat, Inc.
-
-This file is part of Cygwin.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-void
-cygwin_premain2(int argc, char **argv)
-{
-}
diff --git a/winsup/cygwin/lib/premain3.c b/winsup/cygwin/lib/premain3.c
deleted file mode 100644
index c5b99b918..000000000
--- a/winsup/cygwin/lib/premain3.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/* premain3.c
-
- Copyright 2000 Red Hat, Inc.
-
-This file is part of Cygwin.
-
-This software is a copyrighted work licensed under the terms of the
-Cygwin license. Please consult the file "CYGWIN_LICENSE" for
-details. */
-
-void
-cygwin_premain3(int argc, char **argv)
-{
-}
diff --git a/winsup/cygwin/lib/pseudo-reloc.c b/winsup/cygwin/lib/pseudo-reloc.c
deleted file mode 100644
index 77f041114..000000000
--- a/winsup/cygwin/lib/pseudo-reloc.c
+++ /dev/null
@@ -1,367 +0,0 @@
-/* pseudo-reloc.c
-
- Contributed by Egor Duda <deo@logos-m.ru>
- Modified by addition of runtime_pseudo_reloc version 2
- by Kai Tietz <kai.tietz@onevision.com>
-
- THIS SOFTWARE IS NOT COPYRIGHTED
-
- This source code is offered for use in the public domain. You may
- use, modify or distribute it freely.
-
- This code is distributed in the hope that it will be useful but
- WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
- DISCLAMED. This includes but is not limited to warrenties of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-*/
-
-#include <windows.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <memory.h>
-
-#if defined(__CYGWIN__)
-#include <wchar.h>
-#include <ntdef.h>
-#include <sys/cygwin.h>
-/* copied from winsup.h */
-# define NO_COPY __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy")))
-/* custom status code: */
-#define STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION ((NTSTATUS) 0xe0000269)
-#define SHORT_MSG_BUF_SZ 128
-#else
-# define NO_COPY
-#endif
-
-#ifdef __GNUC__
-#define ATTRIBUTE_NORETURN __attribute__ ((noreturn))
-#else
-#define ATTRIBUTE_NORETURN
-#endif
-
-#ifndef __MINGW_LSYMBOL
-#define __MINGW_LSYMBOL(sym) sym
-#endif
-
-extern char __RUNTIME_PSEUDO_RELOC_LIST__;
-extern char __RUNTIME_PSEUDO_RELOC_LIST_END__;
-extern char __MINGW_LSYMBOL(_image_base__);
-
-void _pei386_runtime_relocator (void);
-
-/* v1 relocation is basically:
- * *(base + .target) += .addend
- * where (base + .target) is always assumed to point
- * to a DWORD (4 bytes).
- */
-typedef struct {
- DWORD addend;
- DWORD target;
-} runtime_pseudo_reloc_item_v1;
-
-/* v2 relocation is more complex. In effect, it is
- * *(base + .target) += *(base + .sym) - (base + .sym)
- * with care taken in both reading, sign extension, and writing
- * because .flags may indicate that (base + .target) may point
- * to a BYTE, WORD, DWORD, or QWORD (w64).
- */
-typedef struct {
- DWORD sym;
- DWORD target;
- DWORD flags;
-} runtime_pseudo_reloc_item_v2;
-
-typedef struct {
- DWORD magic1;
- DWORD magic2;
- DWORD version;
-} runtime_pseudo_reloc_v2;
-
-static void ATTRIBUTE_NORETURN
-__report_error (const char *msg, ...)
-{
-#ifdef __CYGWIN__
- /* This function is used to print short error messages
- * to stderr, which may occur during DLL initialization
- * while fixing up 'pseudo' relocations. This early, we
- * may not be able to use cygwin stdio functions, so we
- * use the win32 WriteFile api. This should work with both
- * normal win32 console IO handles, redirected ones, and
- * cygwin ptys.
- */
- char buf[SHORT_MSG_BUF_SZ];
- wchar_t module[MAX_PATH];
- char * posix_module = NULL;
- static const char UNKNOWN_MODULE[] = "<unknown module>: ";
- static const size_t UNKNOWN_MODULE_LEN = sizeof (UNKNOWN_MODULE) - 1;
- static const char CYGWIN_FAILURE_MSG[] = "Cygwin runtime failure: ";
- static const size_t CYGWIN_FAILURE_MSG_LEN = sizeof (CYGWIN_FAILURE_MSG) - 1;
- DWORD len;
- DWORD done;
- va_list args;
- HANDLE errh = GetStdHandle (STD_ERROR_HANDLE);
- ssize_t modulelen = GetModuleFileNameW (NULL, module, sizeof (module));
-
- if (errh == INVALID_HANDLE_VALUE)
- cygwin_internal (CW_EXIT_PROCESS,
- STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION,
- 1);
-
- if (modulelen > 0)
- posix_module = cygwin_create_path (CCP_WIN_W_TO_POSIX, module);
-
- va_start (args, msg);
- len = (DWORD) vsnprintf (buf, SHORT_MSG_BUF_SZ, msg, args);
- va_end (args);
- buf[SHORT_MSG_BUF_SZ-1] = '\0'; /* paranoia */
-
- if (posix_module)
- {
- WriteFile (errh, (PCVOID)CYGWIN_FAILURE_MSG,
- CYGWIN_FAILURE_MSG_LEN, &done, NULL);
- WriteFile (errh, (PCVOID)posix_module,
- strlen(posix_module), &done, NULL);
- WriteFile (errh, (PCVOID)": ", 2, &done, NULL);
- WriteFile (errh, (PCVOID)buf, len, &done, NULL);
- free (posix_module);
- }
- else
- {
- WriteFile (errh, (PCVOID)CYGWIN_FAILURE_MSG,
- CYGWIN_FAILURE_MSG_LEN, &done, NULL);
- WriteFile (errh, (PCVOID)UNKNOWN_MODULE,
- UNKNOWN_MODULE_LEN, &done, NULL);
- WriteFile (errh, (PCVOID)buf, len, &done, NULL);
- }
- WriteFile (errh, (PCVOID)"\n", 1, &done, NULL);
-
- cygwin_internal (CW_EXIT_PROCESS,
- STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION,
- 1);
- /* not reached, but silences noreturn warning */
- abort ();
-#else
- va_list argp;
- va_start (argp, msg);
-# ifdef __MINGW64_VERSION_MAJOR
- fprintf (stderr, "Mingw-w64 runtime failure:\n");
-# else
- fprintf (stderr, "Mingw runtime failure:\n");
-# endif
- vfprintf (stderr, msg, argp);
- va_end (argp);
- abort ();
-#endif
-}
-
-/* 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);
- }
-
- /* 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);
-}
-
-#define RP_VERSION_V1 0
-#define RP_VERSION_V2 1
-
-static void
-do_pseudo_reloc (void * start, void * end, void * base)
-{
- ptrdiff_t addr_imp, reldata;
- ptrdiff_t reloc_target = (ptrdiff_t) ((char *)end - (char*)start);
- runtime_pseudo_reloc_v2 *v2_hdr = (runtime_pseudo_reloc_v2 *) start;
- runtime_pseudo_reloc_item_v2 *r;
-
- /* A valid relocation list will contain at least one entry, and
- * one v1 data structure (the smallest one) requires two DWORDs.
- * So, if the relocation list is smaller than 8 bytes, bail.
- */
- if (reloc_target < 8)
- return;
-
- /* Check if this is the old pseudo relocation version. */
- /* There are two kinds of v1 relocation lists:
- * 1) With a (v2-style) version header. In this case, the
- * first entry in the list is a 3-DWORD structure, with
- * value:
- * { 0, 0, RP_VERSION_V1 }
- * In this case, we skip to the next entry in the list,
- * knowing that all elements after the head item can
- * be cast to runtime_pseudo_reloc_item_v1.
- * 2) Without a (v2-style) version header. In this case, the
- * first element in the list IS an actual v1 relocation
- * record, which is two DWORDs. Because there will never
- * be a case where a v1 relocation record has both
- * addend == 0 and target == 0, this case will not be
- * confused with the prior one.
- * All current binutils, when generating a v1 relocation list,
- * use the second (e.g. original) form -- that is, without the
- * v2-style version header.
- */
- if (reloc_target >= 12
- && v2_hdr->magic1 == 0 && v2_hdr->magic2 == 0
- && v2_hdr->version == RP_VERSION_V1)
- {
- /* We have a list header item indicating that the rest
- * of the list contains v1 entries. Move the pointer to
- * the first true v1 relocation record. By definition,
- * that v1 element will not have both addend == 0 and
- * target == 0 (and thus, when interpreted as a
- * runtime_pseudo_reloc_v2, it will not have both
- * magic1 == 0 and magic2 == 0).
- */
- v2_hdr++;
- }
-
- if (v2_hdr->magic1 != 0 || v2_hdr->magic2 != 0)
- {
- /*************************
- * Handle v1 relocations *
- *************************/
- runtime_pseudo_reloc_item_v1 * o;
- for (o = (runtime_pseudo_reloc_item_v1 *) v2_hdr;
- o < (runtime_pseudo_reloc_item_v1 *)end;
- o++)
- {
- DWORD newval;
- reloc_target = (ptrdiff_t) base + o->target;
- newval = (*((DWORD*) reloc_target)) + o->addend;
- __write_memory ((void *) reloc_target, &newval, sizeof(DWORD));
- }
- return;
- }
-
- /* If we got this far, then we have relocations of version 2 or newer */
-
- /* Check if this is a known version. */
- if (v2_hdr->version != RP_VERSION_V2)
- {
- __report_error (" Unknown pseudo relocation protocol version %d.\n",
- (int) v2_hdr->version);
- return;
- }
-
- /*************************
- * Handle v2 relocations *
- *************************/
-
- /* Walk over header. */
- r = (runtime_pseudo_reloc_item_v2 *) &v2_hdr[1];
-
- for (; r < (runtime_pseudo_reloc_item_v2 *) end; r++)
- {
- /* location where new address will be written */
- reloc_target = (ptrdiff_t) base + r->target;
-
- /* get sym pointer. It points either to the iat entry
- * of the referenced element, or to the stub function.
- */
- addr_imp = (ptrdiff_t) base + r->sym;
- addr_imp = *((ptrdiff_t *) addr_imp);
-
- /* read existing relocation value from image, casting to the
- * bitsize indicated by the 8 LSBs of flags. If the value is
- * negative, manually sign-extend to ptrdiff_t width. Raise an
- * error if the bitsize indicated by the 8 LSBs of flags is not
- * supported.
- */
- switch ((r->flags & 0xff))
- {
- case 8:
- reldata = (ptrdiff_t) (*((unsigned char *)reloc_target));
- if ((reldata & 0x80) != 0)
- reldata |= ~((ptrdiff_t) 0xff);
- break;
- case 16:
- reldata = (ptrdiff_t) (*((unsigned short *)reloc_target));
- if ((reldata & 0x8000) != 0)
- reldata |= ~((ptrdiff_t) 0xffff);
- break;
- case 32:
- reldata = (ptrdiff_t) (*((unsigned int *)reloc_target));
-#ifdef _WIN64
- if ((reldata & 0x80000000) != 0)
- reldata |= ~((ptrdiff_t) 0xffffffff);
-#endif
- break;
-#ifdef _WIN64
- case 64:
- reldata = (ptrdiff_t) (*((unsigned long long *)reloc_target));
- break;
-#endif
- default:
- reldata=0;
- __report_error (" Unknown pseudo relocation bit size %d.\n",
- (int) (r->flags & 0xff));
- break;
- }
-
- /* Adjust the relocation value */
- reldata -= ((ptrdiff_t) base + r->sym);
- reldata += addr_imp;
-
- /* Write the new relocation value back to *reloc_target */
- switch ((r->flags & 0xff))
- {
- case 8:
- __write_memory ((void *) reloc_target, &reldata, 1);
- break;
- case 16:
- __write_memory ((void *) reloc_target, &reldata, 2);
- break;
- case 32:
- __write_memory ((void *) reloc_target, &reldata, 4);
- break;
-#ifdef _WIN64
- case 64:
- __write_memory ((void *) reloc_target, &reldata, 8);
- break;
-#endif
- }
- }
-}
-
-void
-_pei386_runtime_relocator (void)
-{
- static NO_COPY int was_init = 0;
- if (was_init)
- return;
- ++was_init;
- do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,
- &__RUNTIME_PSEUDO_RELOC_LIST_END__,
- &__MINGW_LSYMBOL(_image_base__));
-}