aboutsummaryrefslogtreecommitdiff
path: root/winsup/mingw/pseudo-reloc.c
blob: 9fe607d2cb85c3b4efcef6e5301836871ac762bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* pseudo-reloc.c

   Written by Egor Duda <deo@logos-m.ru>
   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>

extern char __RUNTIME_PSEUDO_RELOC_LIST__;
extern char __RUNTIME_PSEUDO_RELOC_LIST_END__;
extern char _image_base__;

typedef struct
  {
    DWORD addend;
    DWORD target;
  }
runtime_pseudo_reloc;

static void
do_pseudo_reloc (void* start, void* end, void* base)
{
  DWORD reloc_target;
  runtime_pseudo_reloc* r;
  for (r = (runtime_pseudo_reloc*) start; r < (runtime_pseudo_reloc*) end; r++)
    {
      reloc_target = (DWORD) base + r->target;
      *((DWORD*) reloc_target) += r->addend;
    }
}

void
_pei386_runtime_relocator ()
{
  do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,
		   &__RUNTIME_PSEUDO_RELOC_LIST_END__,
		   &_image_base__);
}