* @license GNU General Public License, version 2 (GPL-2.0) * * For full copyright and license information, please see * the docs/CREDITS.txt file. * */ namespace phpbb\install; /** * Interface for installer modules * * An installer module is a task collection which executes installer tasks. */ interface module_interface { /** * Checks if the execution of the module is essential to install phpBB or it can be skipped * * Note: Please note that all the non-essential modules have to implement check_requirements() * method. * * @return bool true if the module is essential, false otherwise */ public function is_essential(); /** * Checks requirements for the tasks * * Note: Only need to be implemented for non-essential tasks, as essential tasks * requirements should be checked in the requirements install module. * * @return bool true if the task's requirements are met */ public function check_requirements(); /** * Executes the task * * @return null */ public function run(); /** * Returns the number of tasks in the module * * @return int */ public function get_step_count(); /** * Returns an array to the correct navigation stage * * @return array */ public function get_navigation_stage_path(); } '>distro/mdv2009.1 Mageia Installer and base platform for many utilitiesThierry Vignaud [tv]
summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/libdl/_dl_open.c
blob: 1f907db213e5c0816a9e053abc39fe5fe97f6d76 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <dlfcn.h>
#include <linux/elf.h>

#include "_dl_int.h"

struct _dl_handle dl_test;

#define _ELF_DWN_ROUND(ps,n)	((n)&(~((ps)-1)))
#define _ELF_UP_ROUND(ps,n)	((((n)&((ps)-1))?(ps):0)+ _ELF_DWN_ROUND((ps),(n)))
#define _ELF_RST_ROUND(ps,n)	((n)&((ps)-1))

void _dl_jump();

/*
 * this file is a Q. & D. hack ... don't think this is bug free or meaningfull
 */

static void *do_map_in(void *base, unsigned long length, int flags, int fd, unsigned long offset)
{
  int perm = 0;
  if (flags & PF_X) perm|=PROT_EXEC;
  if (flags & PF_R) perm|=PROT_READ;
  if (flags & PF_W) perm|=PROT_WRITE;
  return mmap(base, length, perm, MAP_PRIVATE|((base)?MAP_FIXED:0), fd, offset);
}

unsigned long do_rel(struct _dl_handle * tmp_dl, unsigned long off)
{
//  struct _dl_handle * tmp_dl = ((void*)*((&off)-1));
  Elf32_Rel *tmp = ((void*)tmp_dl->plt_rel)+off;
  int sym=ELF32_R_SYM(tmp->r_info);
  register unsigned long sym_val;

  printf("do_rel %08x %08x\n",tmp_dl,off);

  printf ("do_rel %08x+%x\n",tmp_dl->plt_rel,off);
  printf("do_rel @ %08x with type %d -> %d\n",tmp->r_offset,ELF32_R_TYPE(tmp->r_info),sym);

  printf("do_rel sym %08x\n",tmp_dl->dyn_sym_tab[sym].st_value);

  /* modify GOT for REAL symbol */
  sym_val=((unsigned long)(tmp_dl->mem_base+tmp_dl->dyn_sym_tab[sym].st_value));
  *((unsigned long*)(tmp_dl->mem_base+tmp->r_offset))=sym_val;

  printf("do_rel sym %08x\n",sym_val);
  /* HOWTO JUMP ?!? */
  return sym_val;
}

void *_dl_open(const char*pathname, int fd, int flag)
{
  int ps=getpagesize();
  int i;
  unsigned char buf[1024];
  char *m=0,*d;
  struct _dl_handle *ret=0;

  unsigned long l;

  Elf32_Ehdr *eh;
  Elf32_Phdr *ph;

  int ld_nr=0;
  Elf32_Phdr *ld[4]={0,0,0,0};
  Elf32_Phdr *dyn=0;

  if (fd==-1) return 0;

  printf("_dl_open: %s\n",pathname);

  read(fd, buf, 1024);
  eh=(Elf32_Ehdr*)buf;
  ph=(Elf32_Phdr*)&buf[eh->e_phoff];

  for (i=0; i<eh->e_phnum; i++) {
    if (ph[i].p_type==PT_LOAD) {
      ld[ld_nr++]=ph+i;
    }
    if (ph[i].p_type==PT_DYNAMIC) {
      dyn=ph+i;
    }
  }

  if (ld_nr==1) {
    unsigned long offset = _ELF_DWN_ROUND(ps,ld[0]->p_offset);
    unsigned long off = _ELF_RST_ROUND(ps,ld[0]->p_offset);
    unsigned long length = _ELF_UP_ROUND(ps,ld[0]->p_memsz+off);
    m = (char*)do_map_in(0, length, ld[0]->p_flags, fd, offset);

    /* zero pad bss */
    l = ld[0]->p_offset+ld[0]->p_filesz;
    memset(m+l,0,length-l);

    dl_test.mem_base=m;
    dl_test.mem_size=length;
    dl_test.lnk_count=0;

    ret = &dl_test;
  }
  else if (ld_nr==2) { /* aem... yes Quick & Really Dirty / for the avarage 99% */
    //unsigned long text_addr = _ELF_DWN_ROUND(ps,ld[0]->p_vaddr);
    unsigned long text_offset = _ELF_DWN_ROUND(ps,ld[0]->p_offset);
    unsigned long text_off = _ELF_RST_ROUND(ps,ld[0]->p_offset);
    unsigned long text_size = _ELF_UP_ROUND(ps,ld[0]->p_memsz+text_off);

    unsigned long data_addr = _ELF_DWN_ROUND(ps,ld[1]->p_vaddr);
    unsigned long data_offset = _ELF_DWN_ROUND(ps,ld[1]->p_offset);
    unsigned long data_off = _ELF_RST_ROUND(ps,ld[1]->p_offset);
    unsigned long data_size = _ELF_UP_ROUND(ps,ld[1]->p_memsz+data_off);
    unsigned long data_fsize = _ELF_UP_ROUND(ps,ld[1]->p_filesz+data_off);

    /* mmap all mem_blocks for *.so */
    l = text_size+data_size;

    dl_test.mem_size=l;

    m = (char*) do_map_in(0,l,ld[0]->p_flags,fd,text_offset);

    /* release data,bss part */
    mprotect(m+data_addr, data_size, PROT_NONE);

    /* mmap data,bss part */
    d = (char*) do_map_in(m+data_addr,data_fsize,ld[1]->p_flags,fd,data_offset);

    /* zero pad bss */
    l = data_off+ld[1]->p_filesz;
    memset(d+l,0,data_size-l);

    /* more bss ? */
    if (data_size>data_fsize) {
      l = data_size-data_fsize;
      mmap(d+data_fsize, l, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
    }

    dl_test.mem_base=m;
    dl_test.lnk_count=0;
    ret = &dl_test;
  }

  printf("_dl_open pre resolv\n");
  if (ret) {
    Elf32_Dyn* dyn_tab = (void*)m+dyn->p_vaddr;
    void (*init)();
    unsigned long* got=0;
    void* jmprel=0;
    int pltreltype=0;
    int pltrelsize=0;

    printf("_dl_open IN resolv\n");
    for(i=0;dyn_tab[i].d_tag;i++) {