4 * Copyright (C) 1995,96,97,98,99,2000,2001,2002 Free Software Foundation, Inc.
5 * Copyright (C) 2004 Mike McCormack for CodeWeavers
6 * Copyright (C) 2004 Alexandre Julliard
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 * The goal of this program is to be a workaround for exec-shield, as used
27 * by the Linux kernel distributed with Fedora Core and other distros.
29 * To do this, we implement our own shared object loader that reserves memory
30 * that is important to Wine, and then loads the main binary and its ELF
33 * We will try to set up the stack and memory area so that the program that
34 * loads after us (eg. the wine binary) never knows we were here, except that
35 * areas of memory it needs are already magically reserved.
37 * The following memory areas are important to Wine:
38 * 0x00000000 - 0x00110000 the DOS area
39 * 0x80000000 - 0x81000000 the shared heap
40 * ??? - ??? the PE binary load address (usually starting at 0x00400000)
42 * If this program is used as the shared object loader, the only difference
43 * that the loaded programs should see is that this loader will be mapped
44 * into memory when it starts.
48 * References (things I consulted to understand how ELF loading works):
50 * glibc 2.3.2 elf/dl-load.c
51 * http://www.gnu.org/directory/glibc.html
53 * Linux 2.6.4 fs/binfmt_elf.c
54 * ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.4.tar.bz2
56 * Userland exec, by <grugq@hcunix.net>
57 * http://cert.uni-stuttgart.de/archive/bugtraq/2004/01/msg00002.html
59 * The ELF specification:
60 * http://www.linuxbase.org/spec/booksets/LSB-Embedded/LSB-Embedded/book387.html
71 #include <sys/types.h>
75 #ifdef HAVE_SYS_SYSCALL_H
76 # include <sys/syscall.h>
85 #ifdef HAVE_SYS_LINK_H
86 # include <sys/link.h>
92 #pragma GCC visibility push(hidden)
95 #define ELF_PREFERRED_ADDRESS(loader, maplength, mapstartpref) (mapstartpref)
96 #define ELF_FIXED_ADDRESS(loader, mapstart) ((void) 0)
98 #define MAP_BASE_ADDR(l) 0
101 #define MAP_COPY MAP_PRIVATE
103 #ifndef MAP_NORESERVE
104 #define MAP_NORESERVE 0
107 static struct wine_preload_info preload_info
[] =
109 #if defined(__i386__) || defined(__arm__)
110 { (void *)0x00000000, 0x00010000 }, /* low 64k */
111 { (void *)0x00010000, 0x00100000 }, /* DOS area */
112 { (void *)0x00110000, 0x67ef0000 }, /* low memory area */
113 { (void *)0x7f000000, 0x03000000 }, /* top-down allocations + shared user data + virtual heap */
115 { (void *)0x000000010000, 0x00100000 }, /* DOS area */
116 { (void *)0x000000110000, 0x67ef0000 }, /* low memory area */
117 { (void *)0x00007f000000, 0x00ff0000 }, /* 32-bit top-down allocations + shared user data */
118 { (void *)0x7ffffe000000, 0x01ff0000 }, /* top-down allocations + virtual heap */
120 { 0, 0 }, /* PE exe range set with WINEPRELOADRESERVE */
121 { 0, 0 } /* end of list */
130 /* older systems may not define these */
136 #define AT_SYSINFO 32
138 #ifndef AT_SYSINFO_EHDR
139 #define AT_SYSINFO_EHDR 33
143 #define DT_GNU_HASH 0x6ffffef5
146 static size_t page_size
, page_mask
;
147 static char *preloader_start
, *preloader_end
;
149 struct wld_link_map
{
156 ElfW(Addr
) l_map_start
, l_map_end
;
170 * The __bb_init_func is an empty function only called when file is
171 * compiled with gcc flags "-fprofile-arcs -ftest-coverage". This
172 * function is normally provided by libc's startup files, but since we
173 * build the preloader with "-nostartfiles -nodefaultlibs", we have to
174 * provide our own (empty) version, otherwise linker fails.
176 void __bb_init_func(void) { return; }
178 /* similar to the above but for -fstack-protector */
179 void *__stack_chk_guard
= 0;
180 void __stack_chk_fail_local(void) { return; }
181 void __stack_chk_fail(void) { return; }
185 /* data for setting up the glibc-style thread-local storage in %gs */
187 static int thread_data
[256];
191 /* this is the kernel modify_ldt struct */
192 unsigned int entry_number
;
193 unsigned long base_addr
;
195 unsigned int seg_32bit
: 1;
196 unsigned int contents
: 2;
197 unsigned int read_exec_only
: 1;
198 unsigned int limit_in_pages
: 1;
199 unsigned int seg_not_present
: 1;
200 unsigned int usable
: 1;
201 unsigned int garbage
: 25;
202 } thread_ldt
= { -1, (unsigned long)thread_data
, 0xfffff, 1, 0, 0, 1, 0, 1, 0 };
206 * The _start function is the entry and exit point of this program
208 * It calls wld_start, passing a pointer to the args it receives
209 * then jumps to the address wld_start returns.
213 __ASM_GLOBAL_FUNC(_start
,
214 __ASM_CFI("\t.cfi_undefined %eip\n")
215 "\tmovl $243,%eax\n" /* SYS_set_thread_area */
216 "\tmovl $thread_ldt,%ebx\n"
217 "\tint $0x80\n" /* allocate gs segment */
220 "\tmovl thread_ldt,%eax\n" /* thread_ldt.entry_number */
224 "\tmov %ax,%fs\n" /* set %fs too so libwine can retrieve it later on */
225 "1:\tmovl %esp,%eax\n"
226 "\tleal -136(%esp),%esp\n" /* allocate some space for extra aux values */
227 "\tpushl %eax\n" /* orig stack pointer */
228 "\tpushl %esp\n" /* ptr to orig stack pointer */
230 "\tpopl %ecx\n" /* remove ptr to stack pointer */
231 "\tpopl %esp\n" /* new stack pointer */
232 "\tpush %eax\n" /* ELF interpreter entry point */
236 "\tmov %ax,%gs\n" /* clear %gs again */
239 /* wrappers for Linux system calls */
241 #define SYSCALL_RET(ret) (((ret) < 0 && (ret) > -4096) ? -1 : (ret))
243 static inline __attribute__((noreturn
)) void wld_exit( int code
)
245 for (;;) /* avoid warning */
246 __asm__
__volatile__( "pushl %%ebx; movl %1,%%ebx; int $0x80; popl %%ebx"
247 : : "a" (1 /* SYS_exit */), "r" (code
) );
250 static inline int wld_open( const char *name
, int flags
)
253 __asm__
__volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
254 : "=a" (ret
) : "0" (5 /* SYS_open */), "r" (name
), "c" (flags
) );
255 return SYSCALL_RET(ret
);
258 static inline int wld_close( int fd
)
261 __asm__
__volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
262 : "=a" (ret
) : "0" (6 /* SYS_close */), "r" (fd
) );
263 return SYSCALL_RET(ret
);
266 static inline ssize_t
wld_read( int fd
, void *buffer
, size_t len
)
269 __asm__
__volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
271 : "0" (3 /* SYS_read */), "r" (fd
), "c" (buffer
), "d" (len
)
273 return SYSCALL_RET(ret
);
276 static inline ssize_t
wld_write( int fd
, const void *buffer
, size_t len
)
279 __asm__
__volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
280 : "=a" (ret
) : "0" (4 /* SYS_write */), "r" (fd
), "c" (buffer
), "d" (len
) );
281 return SYSCALL_RET(ret
);
284 static inline int wld_mprotect( const void *addr
, size_t len
, int prot
)
287 __asm__
__volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
288 : "=a" (ret
) : "0" (125 /* SYS_mprotect */), "r" (addr
), "c" (len
), "d" (prot
) );
289 return SYSCALL_RET(ret
);
292 void *wld_mmap( void *start
, size_t len
, int prot
, int flags
, int fd
, unsigned int offset
);
293 __ASM_GLOBAL_FUNC(wld_mmap
,
295 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
297 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
299 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
301 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
302 "\tmovl $192,%eax\n" /* SYS_mmap2 */
303 "\tmovl 20(%esp),%ebx\n" /* start */
304 "\tmovl 24(%esp),%ecx\n" /* len */
305 "\tmovl 28(%esp),%edx\n" /* prot */
306 "\tmovl 32(%esp),%esi\n" /* flags */
307 "\tmovl 36(%esp),%edi\n" /* fd */
308 "\tmovl 40(%esp),%ebp\n" /* offset */
311 "\tcmpl $-4096,%eax\n"
313 "\tcmpl $-38,%eax\n" /* ENOSYS */
315 "\tmovl $90,%eax\n" /* SYS_mmap */
316 "\tleal 20(%esp),%ebx\n"
318 "\tcmpl $-4096,%eax\n"
320 "1:\tmovl $-1,%eax\n"
322 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
324 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
326 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
328 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
331 static inline int wld_prctl( int code
, long arg
)
334 __asm__
__volatile__( "pushl %%ebx; movl %2,%%ebx; int $0x80; popl %%ebx"
335 : "=a" (ret
) : "0" (172 /* SYS_prctl */), "r" (code
), "c" (arg
) );
336 return SYSCALL_RET(ret
);
339 #elif defined(__x86_64__)
341 void *thread_data
[256];
344 * The _start function is the entry and exit point of this program
346 * It calls wld_start, passing a pointer to the args it receives
347 * then jumps to the address wld_start returns.
351 __ASM_GLOBAL_FUNC(_start
,
352 __ASM_CFI(".cfi_undefined %rip\n\t")
354 "leaq -144(%rsp),%rsp\n\t" /* allocate some space for extra aux values */
355 "movq %rax,(%rsp)\n\t" /* orig stack pointer */
356 "movq thread_data(%rip),%rsi\n\t"
357 "movq $0x1002,%rdi\n\t" /* ARCH_SET_FS */
358 "movq $158,%rax\n\t" /* SYS_arch_prctl */
360 "movq %rsp,%rdi\n\t" /* ptr to orig stack pointer */
362 "movq (%rsp),%rsp\n\t" /* new stack pointer */
363 "pushq %rax\n\t" /* ELF interpreter entry point */
375 #define SYSCALL_FUNC( name, nr ) \
376 __ASM_GLOBAL_FUNC( name, \
377 "movq $" #nr ",%rax\n\t" \
378 "movq %rcx,%r10\n\t" \
380 "leaq 4096(%rax),%rcx\n\t" \
381 "movq $-1,%rdx\n\t" \
382 "cmp $4096,%rcx\n\t" \
383 "cmovb %rdx,%rax\n\t" \
386 #define SYSCALL_NOERR( name, nr ) \
387 __ASM_GLOBAL_FUNC( name, \
388 "movq $" #nr ",%rax\n\t" \
392 void wld_exit( int code
) __attribute__((noreturn
));
393 SYSCALL_NOERR( wld_exit
, 60 /* SYS_exit */ );
395 ssize_t
wld_read( int fd
, void *buffer
, size_t len
);
396 SYSCALL_FUNC( wld_read
, 0 /* SYS_read */ );
398 ssize_t
wld_write( int fd
, const void *buffer
, size_t len
);
399 SYSCALL_FUNC( wld_write
, 1 /* SYS_write */ );
401 int wld_open( const char *name
, int flags
);
402 SYSCALL_FUNC( wld_open
, 2 /* SYS_open */ );
404 int wld_close( int fd
);
405 SYSCALL_FUNC( wld_close
, 3 /* SYS_close */ );
407 void *wld_mmap( void *start
, size_t len
, int prot
, int flags
, int fd
, off_t offset
);
408 SYSCALL_FUNC( wld_mmap
, 9 /* SYS_mmap */ );
410 int wld_mprotect( const void *addr
, size_t len
, int prot
);
411 SYSCALL_FUNC( wld_mprotect
, 10 /* SYS_mprotect */ );
413 int wld_prctl( int code
, long arg
);
414 SYSCALL_FUNC( wld_prctl
, 157 /* SYS_prctl */ );
416 uid_t
wld_getuid(void);
417 SYSCALL_NOERR( wld_getuid
, 102 /* SYS_getuid */ );
419 gid_t
wld_getgid(void);
420 SYSCALL_NOERR( wld_getgid
, 104 /* SYS_getgid */ );
422 uid_t
wld_geteuid(void);
423 SYSCALL_NOERR( wld_geteuid
, 107 /* SYS_geteuid */ );
425 gid_t
wld_getegid(void);
426 SYSCALL_NOERR( wld_getegid
, 108 /* SYS_getegid */ );
428 #elif defined(__aarch64__)
430 void *thread_data
[256];
433 * The _start function is the entry and exit point of this program
435 * It calls wld_start, passing a pointer to the args it receives
436 * then jumps to the address wld_start returns.
440 __ASM_GLOBAL_FUNC(_start
,
442 "sub SP, SP, #144\n\t" /* allocate some space for extra aux values */
443 "str x0, [SP]\n\t" /* orig stack pointer */
444 "adrp x0, thread_data\n\t"
445 "add x0, x0, :lo12:thread_data\n\t"
446 "msr tpidr_el0, x0\n\t"
447 "mov x0, SP\n\t" /* ptr to orig stack pointer */
449 "ldr x1, [SP]\n\t" /* new stack pointer */
473 #define SYSCALL_FUNC( name, nr ) \
474 __ASM_GLOBAL_FUNC( name, \
475 "stp x8, x9, [SP, #-16]!\n\t" \
476 "mov x8, #" #nr "\n\t" \
478 "ldp x8, x9, [SP], #16\n\t" \
479 "cmn x0, #1, lsl#12\n\t" \
480 "cinv x0, x0, hi\n\t" \
483 "1: mov x0, #-1\n\t" \
486 #define SYSCALL_NOERR( name, nr ) \
487 __ASM_GLOBAL_FUNC( name, \
488 "stp x8, x9, [SP, #-16]!\n\t" \
489 "mov x8, #" #nr "\n\t" \
491 "ldp x8, x9, [SP], #16\n\t" \
494 void wld_exit( int code
) __attribute__((noreturn
));
495 SYSCALL_NOERR( wld_exit
, 93 /* SYS_exit */ );
497 ssize_t
wld_read( int fd
, void *buffer
, size_t len
);
498 SYSCALL_FUNC( wld_read
, 63 /* SYS_read */ );
500 ssize_t
wld_write( int fd
, const void *buffer
, size_t len
);
501 SYSCALL_FUNC( wld_write
, 64 /* SYS_write */ );
503 int wld_openat( int dirfd
, const char *name
, int flags
);
504 SYSCALL_FUNC( wld_openat
, 56 /* SYS_openat */ );
506 int wld_open( const char *name
, int flags
)
508 return wld_openat(-100 /* AT_FDCWD */, name
, flags
);
511 int wld_close( int fd
);
512 SYSCALL_FUNC( wld_close
, 57 /* SYS_close */ );
514 void *wld_mmap( void *start
, size_t len
, int prot
, int flags
, int fd
, off_t offset
);
515 SYSCALL_FUNC( wld_mmap
, 222 /* SYS_mmap */ );
517 int wld_mprotect( const void *addr
, size_t len
, int prot
);
518 SYSCALL_FUNC( wld_mprotect
, 226 /* SYS_mprotect */ );
520 int wld_prctl( int code
, long arg
);
521 SYSCALL_FUNC( wld_prctl
, 167 /* SYS_prctl */ );
523 uid_t
wld_getuid(void);
524 SYSCALL_NOERR( wld_getuid
, 174 /* SYS_getuid */ );
526 gid_t
wld_getgid(void);
527 SYSCALL_NOERR( wld_getgid
, 176 /* SYS_getgid */ );
529 uid_t
wld_geteuid(void);
530 SYSCALL_NOERR( wld_geteuid
, 175 /* SYS_geteuid */ );
532 gid_t
wld_getegid(void);
533 SYSCALL_NOERR( wld_getegid
, 177 /* SYS_getegid */ );
535 #elif defined(__arm__)
537 void *thread_data
[256];
540 * The _start function is the entry and exit point of this program
542 * It calls wld_start, passing a pointer to the args it receives
543 * then jumps to the address wld_start returns.
547 __ASM_GLOBAL_FUNC(_start
,
548 __ASM_EHABI(".cantunwind\n\t")
550 "sub sp, sp, #144\n\t" /* allocate some space for extra aux values */
551 "str r0, [sp]\n\t" /* orig stack pointer */
552 "ldr r0, =thread_data\n\t"
553 "movw r7, #0x0005\n\t" /* __ARM_NR_set_tls */
554 "movt r7, #0xf\n\t" /* __ARM_NR_set_tls */
556 "mov r0, sp\n\t" /* ptr to orig stack pointer */
558 "ldr r1, [sp]\n\t" /* new stack pointer */
569 #define SYSCALL_FUNC( name, nr ) \
570 __ASM_GLOBAL_FUNC( name, \
571 __ASM_EHABI(".cantunwind\n\t") \
572 "push {r4-r5,r7,lr}\n\t" \
573 "ldr r4, [sp, #16]\n\t" \
574 "ldr r5, [sp, #20]\n\t" \
575 "mov r7, #" #nr "\n\t" \
577 "cmn r0, #4096\n\t" \
579 "movhi r0, #-1\n\t" \
580 "pop {r4-r5,r7,pc}\n\t" )
582 #define SYSCALL_NOERR( name, nr ) \
583 __ASM_GLOBAL_FUNC( name, \
584 __ASM_EHABI(".cantunwind\n\t") \
586 "mov r7, #" #nr "\n\t" \
590 void wld_exit( int code
) __attribute__((noreturn
));
591 SYSCALL_NOERR( wld_exit
, 1 /* SYS_exit */ );
593 ssize_t
wld_read( int fd
, void *buffer
, size_t len
);
594 SYSCALL_FUNC( wld_read
, 3 /* SYS_read */ );
596 ssize_t
wld_write( int fd
, const void *buffer
, size_t len
);
597 SYSCALL_FUNC( wld_write
, 4 /* SYS_write */ );
599 int wld_openat( int dirfd
, const char *name
, int flags
);
600 SYSCALL_FUNC( wld_openat
, 322 /* SYS_openat */ );
602 int wld_open( const char *name
, int flags
)
604 return wld_openat(-100 /* AT_FDCWD */, name
, flags
);
607 int wld_close( int fd
);
608 SYSCALL_FUNC( wld_close
, 6 /* SYS_close */ );
610 void *wld_mmap2( void *start
, size_t len
, int prot
, int flags
, int fd
, int offset
);
611 SYSCALL_FUNC( wld_mmap2
, 192 /* SYS_mmap2 */ );
613 void *wld_mmap( void *start
, size_t len
, int prot
, int flags
, int fd
, off_t offset
)
615 return wld_mmap2(start
, len
, prot
, flags
, fd
, offset
>> 12);
618 int wld_mprotect( const void *addr
, size_t len
, int prot
);
619 SYSCALL_FUNC( wld_mprotect
, 125 /* SYS_mprotect */ );
621 int wld_prctl( int code
, long arg
);
622 SYSCALL_FUNC( wld_prctl
, 172 /* SYS_prctl */ );
624 uid_t
wld_getuid(void);
625 SYSCALL_NOERR( wld_getuid
, 24 /* SYS_getuid */ );
627 gid_t
wld_getgid(void);
628 SYSCALL_NOERR( wld_getgid
, 47 /* SYS_getgid */ );
630 uid_t
wld_geteuid(void);
631 SYSCALL_NOERR( wld_geteuid
, 49 /* SYS_geteuid */ );
633 gid_t
wld_getegid(void);
634 SYSCALL_NOERR( wld_getegid
, 50 /* SYS_getegid */ );
636 unsigned long long __aeabi_uidivmod(unsigned int num
, unsigned int den
)
638 unsigned int bit
= 1;
639 unsigned int quota
= 0;
642 while (den
< num
&& !(den
& 0x80000000)) {
654 return ((unsigned long long)num
<< 32) | quota
;
658 #error preloader not implemented for this CPU
661 /* replacement for libc functions */
663 static int wld_strcmp( const char *str1
, const char *str2
)
665 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
666 return *str1
- *str2
;
669 static int wld_strncmp( const char *str1
, const char *str2
, size_t len
)
671 if (len
<= 0) return 0;
672 while ((--len
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
673 return *str1
- *str2
;
676 static inline void *wld_memset( void *dest
, int val
, size_t len
)
679 while (len
--) *dst
++ = val
;
684 * wld_printf - just the basics
686 * %x prints a hex number
688 * %p prints a pointer
690 static int wld_vsprintf(char *buffer
, const char *fmt
, va_list args
)
692 static const char hex_chars
[16] = "0123456789abcdef";
704 unsigned int x
= va_arg( args
, unsigned int );
705 for (i
= 2*sizeof(x
) - 1; i
>= 0; i
--)
706 *str
++ = hex_chars
[(x
>>(i
*4))&0xf];
708 else if (p
[0] == 'l' && p
[1] == 'x')
710 unsigned long x
= va_arg( args
, unsigned long );
711 for (i
= 2*sizeof(x
) - 1; i
>= 0; i
--)
712 *str
++ = hex_chars
[(x
>>(i
*4))&0xf];
717 unsigned long x
= (unsigned long)va_arg( args
, void * );
718 for (i
= 2*sizeof(x
) - 1; i
>= 0; i
--)
719 *str
++ = hex_chars
[(x
>>(i
*4))&0xf];
723 char *s
= va_arg( args
, char * );
737 static __attribute__((format(printf
,1,2))) void wld_printf(const char *fmt
, ... )
743 va_start( args
, fmt
);
744 len
= wld_vsprintf(buffer
, fmt
, args
);
746 wld_write(2, buffer
, len
);
749 static __attribute__((noreturn
,format(printf
,1,2))) void fatal_error(const char *fmt
, ... )
755 va_start( args
, fmt
);
756 len
= wld_vsprintf(buffer
, fmt
, args
);
758 wld_write(2, buffer
, len
);
764 * Dump interesting bits of the ELF auxv_t structure that is passed
765 * as the 4th parameter to the _start function
767 static void dump_auxiliary( struct wld_auxv
*av
)
769 #define NAME(at) { at, #at }
770 static const struct { int val
; const char *name
; } names
[] =
786 NAME(AT_SYSINFO_EHDR
),
794 for ( ; av
->a_type
!= AT_NULL
; av
++)
796 for (i
= 0; names
[i
].name
; i
++) if (names
[i
].val
== av
->a_type
) break;
797 if (names
[i
].name
) wld_printf("%s = %lx\n", names
[i
].name
, (unsigned long)av
->a_un
.a_val
);
798 else wld_printf( "%lx = %lx\n", (unsigned long)av
->a_type
, (unsigned long)av
->a_un
.a_val
);
804 * set_auxiliary_values
806 * Set the new auxiliary values
808 static void set_auxiliary_values( struct wld_auxv
*av
, const struct wld_auxv
*new_av
,
809 const struct wld_auxv
*delete_av
, void **stack
)
811 int i
, j
, av_count
= 0, new_count
= 0, delete_count
= 0;
814 /* count how many aux values we have already */
815 while (av
[av_count
].a_type
!= AT_NULL
) av_count
++;
817 /* delete unwanted values */
818 for (j
= 0; delete_av
[j
].a_type
!= AT_NULL
; j
++)
820 for (i
= 0; i
< av_count
; i
++) if (av
[i
].a_type
== delete_av
[j
].a_type
)
822 av
[i
].a_type
= av
[av_count
-1].a_type
;
823 av
[i
].a_un
.a_val
= av
[av_count
-1].a_un
.a_val
;
824 av
[--av_count
].a_type
= AT_NULL
;
830 /* count how many values we have in new_av that aren't in av */
831 for (j
= 0; new_av
[j
].a_type
!= AT_NULL
; j
++)
833 for (i
= 0; i
< av_count
; i
++) if (av
[i
].a_type
== new_av
[j
].a_type
) break;
834 if (i
== av_count
) new_count
++;
837 src
= (char *)*stack
;
838 dst
= src
- (new_count
- delete_count
) * sizeof(*av
);
839 dst
= (char *)((unsigned long)dst
& ~15);
840 if (dst
< src
) /* need to make room for the extra values */
842 int len
= (char *)(av
+ av_count
+ 1) - src
;
843 for (i
= 0; i
< len
; i
++) dst
[i
] = src
[i
];
845 else if (dst
> src
) /* get rid of unused values */
847 int len
= (char *)(av
+ av_count
+ 1) - src
;
848 for (i
= len
- 1; i
>= 0; i
--) dst
[i
] = src
[i
];
851 av
= (struct wld_auxv
*)((char *)av
+ (dst
- src
));
853 /* now set the values */
854 for (j
= 0; new_av
[j
].a_type
!= AT_NULL
; j
++)
856 for (i
= 0; i
< av_count
; i
++) if (av
[i
].a_type
== new_av
[j
].a_type
) break;
857 if (i
< av_count
) av
[i
].a_un
.a_val
= new_av
[j
].a_un
.a_val
;
860 av
[av_count
].a_type
= new_av
[j
].a_type
;
861 av
[av_count
].a_un
.a_val
= new_av
[j
].a_un
.a_val
;
867 wld_printf("New auxiliary info:\n");
868 dump_auxiliary( av
);
875 * Get a field of the auxiliary structure
877 static ElfW(Addr
) get_auxiliary( struct wld_auxv
*av
, int type
, ElfW(Addr
) def_val
)
879 for ( ; av
->a_type
!= AT_NULL
; av
++)
880 if( av
->a_type
== type
) return av
->a_un
.a_val
;
887 * modelled after _dl_map_object_from_fd() from glibc-2.3.1/elf/dl-load.c
889 * This function maps the segments from an ELF object, and optionally
890 * stores information about the mapping into the auxv_t structure.
892 static void map_so_lib( const char *name
, struct wld_link_map
*l
)
895 unsigned char buf
[0x800];
896 ElfW(Ehdr
) *header
= (ElfW(Ehdr
)*)buf
;
897 ElfW(Phdr
) *phdr
, *ph
;
898 /* Scan the program header table, collecting its load commands. */
901 ElfW(Addr
) mapstart
, mapend
, dataend
, allocend
;
905 size_t nloadcmds
= 0, maplength
;
907 fd
= wld_open( name
, O_RDONLY
);
908 if (fd
== -1) fatal_error("%s: could not open\n", name
);
910 if (wld_read( fd
, buf
, sizeof(buf
) ) != sizeof(buf
))
911 fatal_error("%s: failed to read ELF header\n", name
);
913 phdr
= (void*) (((unsigned char*)buf
) + header
->e_phoff
);
915 if( ( header
->e_ident
[0] != 0x7f ) ||
916 ( header
->e_ident
[1] != 'E' ) ||
917 ( header
->e_ident
[2] != 'L' ) ||
918 ( header
->e_ident
[3] != 'F' ) )
919 fatal_error( "%s: not an ELF binary... don't know how to load it\n", name
);
922 if( header
->e_machine
!= EM_386
)
923 fatal_error("%s: not an i386 ELF binary... don't know how to load it\n", name
);
924 #elif defined(__x86_64__)
925 if( header
->e_machine
!= EM_X86_64
)
926 fatal_error("%s: not an x86-64 ELF binary... don't know how to load it\n", name
);
927 #elif defined(__aarch64__)
928 if( header
->e_machine
!= EM_AARCH64
)
929 fatal_error("%s: not an aarch64 ELF binary... don't know how to load it\n", name
);
930 #elif defined(__arm__)
931 if( header
->e_machine
!= EM_ARM
)
932 fatal_error("%s: not an arm ELF binary... don't know how to load it\n", name
);
935 if (header
->e_phnum
> sizeof(loadcmds
)/sizeof(loadcmds
[0]))
936 fatal_error( "%s: oops... not enough space for load commands\n", name
);
938 maplength
= header
->e_phnum
* sizeof (ElfW(Phdr
));
939 if (header
->e_phoff
+ maplength
> sizeof(buf
))
940 fatal_error( "%s: oops... not enough space for ELF headers\n", name
);
945 l
->l_phnum
= header
->e_phnum
;
946 l
->l_entry
= header
->e_entry
;
949 for (ph
= phdr
; ph
< &phdr
[l
->l_phnum
]; ++ph
)
953 wld_printf( "ph = %p\n", ph
);
954 wld_printf( " p_type = %lx\n", (unsigned long)ph
->p_type
);
955 wld_printf( " p_flags = %lx\n", (unsigned long)ph
->p_flags
);
956 wld_printf( " p_offset = %lx\n", (unsigned long)ph
->p_offset
);
957 wld_printf( " p_vaddr = %lx\n", (unsigned long)ph
->p_vaddr
);
958 wld_printf( " p_paddr = %lx\n", (unsigned long)ph
->p_paddr
);
959 wld_printf( " p_filesz = %lx\n", (unsigned long)ph
->p_filesz
);
960 wld_printf( " p_memsz = %lx\n", (unsigned long)ph
->p_memsz
);
961 wld_printf( " p_align = %lx\n", (unsigned long)ph
->p_align
);
966 /* These entries tell us where to find things once the file's
967 segments are mapped in. We record the addresses it says
968 verbatim, and later correct for the run-time load address. */
970 l
->l_ld
= (void *) ph
->p_vaddr
;
971 l
->l_ldnum
= ph
->p_memsz
/ sizeof (Elf32_Dyn
);
975 l
->l_phdr
= (void *) ph
->p_vaddr
;
980 if ((ph
->p_align
& page_mask
) != 0)
981 fatal_error( "%s: ELF load command alignment not page-aligned\n", name
);
983 if (((ph
->p_vaddr
- ph
->p_offset
) & (ph
->p_align
- 1)) != 0)
984 fatal_error( "%s: ELF load command address/offset not properly aligned\n", name
);
986 c
= &loadcmds
[nloadcmds
++];
987 c
->mapstart
= ph
->p_vaddr
& ~(ph
->p_align
- 1);
988 c
->mapend
= ((ph
->p_vaddr
+ ph
->p_filesz
+ page_mask
) & ~page_mask
);
989 c
->dataend
= ph
->p_vaddr
+ ph
->p_filesz
;
990 c
->allocend
= ph
->p_vaddr
+ ph
->p_memsz
;
991 c
->mapoff
= ph
->p_offset
& ~(ph
->p_align
- 1);
994 if (ph
->p_flags
& PF_R
)
995 c
->prot
|= PROT_READ
;
996 if (ph
->p_flags
& PF_W
)
997 c
->prot
|= PROT_WRITE
;
998 if (ph
->p_flags
& PF_X
)
999 c
->prot
|= PROT_EXEC
;
1004 l
->l_interp
= ph
->p_vaddr
;
1009 * We don't need to set anything up because we're
1010 * emulating the kernel, not ld-linux.so.2
1011 * The ELF loader will set up the TLS data itself.
1020 /* Now process the load commands and map segments into memory. */
1022 fatal_error( "%s: no segments to load\n", name
);
1025 /* Length of the sections to be loaded. */
1026 maplength
= loadcmds
[nloadcmds
- 1].allocend
- c
->mapstart
;
1028 if( header
->e_type
== ET_DYN
)
1031 mappref
= (ELF_PREFERRED_ADDRESS (loader
, maplength
, c
->mapstart
)
1032 - MAP_BASE_ADDR (l
));
1034 /* Remember which part of the address space this object uses. */
1035 l
->l_map_start
= (ElfW(Addr
)) wld_mmap ((void *) mappref
, maplength
,
1036 c
->prot
, MAP_COPY
| MAP_FILE
,
1038 /* wld_printf("set : offset = %x\n", c->mapoff); */
1039 /* wld_printf("l->l_map_start = %x\n", l->l_map_start); */
1041 l
->l_map_end
= l
->l_map_start
+ maplength
;
1042 l
->l_addr
= l
->l_map_start
- c
->mapstart
;
1044 wld_mprotect ((caddr_t
) (l
->l_addr
+ c
->mapend
),
1045 loadcmds
[nloadcmds
- 1].allocend
- c
->mapend
,
1052 if ((char *)c
->mapstart
+ maplength
> preloader_start
&&
1053 (char *)c
->mapstart
<= preloader_end
)
1054 fatal_error( "%s: binary overlaps preloader (%p-%p)\n",
1055 name
, (char *)c
->mapstart
, (char *)c
->mapstart
+ maplength
);
1057 ELF_FIXED_ADDRESS (loader
, c
->mapstart
);
1060 /* Remember which part of the address space this object uses. */
1061 l
->l_map_start
= c
->mapstart
+ l
->l_addr
;
1062 l
->l_map_end
= l
->l_map_start
+ maplength
;
1064 while (c
< &loadcmds
[nloadcmds
])
1066 if (c
->mapend
> c
->mapstart
)
1067 /* Map the segment contents from the file. */
1068 wld_mmap ((void *) (l
->l_addr
+ c
->mapstart
),
1069 c
->mapend
- c
->mapstart
, c
->prot
,
1070 MAP_FIXED
| MAP_COPY
| MAP_FILE
, fd
, c
->mapoff
);
1074 && (ElfW(Off
)) c
->mapoff
<= header
->e_phoff
1075 && ((size_t) (c
->mapend
- c
->mapstart
+ c
->mapoff
)
1076 >= header
->e_phoff
+ header
->e_phnum
* sizeof (ElfW(Phdr
))))
1077 /* Found the program header in this segment. */
1078 l
->l_phdr
= (void *)(unsigned long)(c
->mapstart
+ header
->e_phoff
- c
->mapoff
);
1080 if (c
->allocend
> c
->dataend
)
1082 /* Extra zero pages should appear at the end of this segment,
1083 after the data mapped from the file. */
1084 ElfW(Addr
) zero
, zeroend
, zeropage
;
1086 zero
= l
->l_addr
+ c
->dataend
;
1087 zeroend
= l
->l_addr
+ c
->allocend
;
1088 zeropage
= (zero
+ page_mask
) & ~page_mask
;
1091 * This is different from the dl-load load...
1092 * ld-linux.so.2 relies on the whole page being zero'ed
1094 zeroend
= (zeroend
+ page_mask
) & ~page_mask
;
1096 if (zeroend
< zeropage
)
1098 /* All the extra data is in the last page of the segment.
1099 We can just zero it. */
1103 if (zeropage
> zero
)
1105 /* Zero the final part of the last page of the segment. */
1106 if ((c
->prot
& PROT_WRITE
) == 0)
1109 wld_mprotect ((caddr_t
) (zero
& ~page_mask
), page_size
, c
->prot
|PROT_WRITE
);
1111 wld_memset ((void *) zero
, '\0', zeropage
- zero
);
1112 if ((c
->prot
& PROT_WRITE
) == 0)
1113 wld_mprotect ((caddr_t
) (zero
& ~page_mask
), page_size
, c
->prot
);
1116 if (zeroend
> zeropage
)
1118 /* Map the remaining zero pages in from the zero fill FD. */
1119 wld_mmap ((caddr_t
) zeropage
, zeroend
- zeropage
,
1120 c
->prot
, MAP_ANON
|MAP_PRIVATE
|MAP_FIXED
,
1128 if (l
->l_phdr
== NULL
) fatal_error("no program header\n");
1130 l
->l_phdr
= (void *)((ElfW(Addr
))l
->l_phdr
+ l
->l_addr
);
1131 l
->l_entry
+= l
->l_addr
;
1137 static unsigned int wld_elf_hash( const char *name
)
1139 unsigned int hi
, hash
= 0;
1142 hash
= (hash
<< 4) + (unsigned char)*name
++;
1143 hi
= hash
& 0xf0000000;
1150 static unsigned int gnu_hash( const char *name
)
1152 unsigned int h
= 5381;
1153 while (*name
) h
= h
* 33 + (unsigned char)*name
++;
1158 * Find a symbol in the symbol table of the executable loaded
1160 static void *find_symbol( const struct wld_link_map
*map
, const char *var
, int type
)
1162 const ElfW(Dyn
) *dyn
= NULL
;
1163 const ElfW(Phdr
) *ph
;
1164 const ElfW(Sym
) *symtab
= NULL
;
1165 const Elf32_Word
*hashtab
= NULL
;
1166 const Elf32_Word
*gnu_hashtab
= NULL
;
1167 const char *strings
= NULL
;
1170 /* check the values */
1172 wld_printf("%p %x\n", map
->l_phdr
, map
->l_phnum
);
1174 /* parse the (already loaded) ELF executable's header */
1175 for (ph
= map
->l_phdr
; ph
< &map
->l_phdr
[map
->l_phnum
]; ++ph
)
1177 if( PT_DYNAMIC
== ph
->p_type
)
1179 dyn
= (void *)(ph
->p_vaddr
+ map
->l_addr
);
1183 if( !dyn
) return NULL
;
1187 if( dyn
->d_tag
== DT_STRTAB
)
1188 strings
= (const char*)(dyn
->d_un
.d_ptr
+ map
->l_addr
);
1189 if( dyn
->d_tag
== DT_SYMTAB
)
1190 symtab
= (const ElfW(Sym
) *)(dyn
->d_un
.d_ptr
+ map
->l_addr
);
1191 if( dyn
->d_tag
== DT_HASH
)
1192 hashtab
= (const Elf32_Word
*)(dyn
->d_un
.d_ptr
+ map
->l_addr
);
1193 if( dyn
->d_tag
== DT_GNU_HASH
)
1194 gnu_hashtab
= (const Elf32_Word
*)(dyn
->d_un
.d_ptr
+ map
->l_addr
);
1196 wld_printf("%lx %p\n", (unsigned long)dyn
->d_tag
, (void *)dyn
->d_un
.d_ptr
);
1201 if( (!symtab
) || (!strings
) ) return NULL
;
1203 if (gnu_hashtab
) /* new style hash table */
1205 const unsigned int hash
= gnu_hash(var
);
1206 const Elf32_Word nbuckets
= gnu_hashtab
[0];
1207 const Elf32_Word symbias
= gnu_hashtab
[1];
1208 const Elf32_Word nwords
= gnu_hashtab
[2];
1209 const ElfW(Addr
) *bitmask
= (const ElfW(Addr
) *)(gnu_hashtab
+ 4);
1210 const Elf32_Word
*buckets
= (const Elf32_Word
*)(bitmask
+ nwords
);
1211 const Elf32_Word
*chains
= buckets
+ nbuckets
- symbias
;
1213 if (!(idx
= buckets
[hash
% nbuckets
])) return NULL
;
1216 if ((chains
[idx
] & ~1u) == (hash
& ~1u) &&
1217 ELF32_ST_BIND(symtab
[idx
].st_info
) == STB_GLOBAL
&&
1218 ELF32_ST_TYPE(symtab
[idx
].st_info
) == type
&&
1219 !wld_strcmp( strings
+ symtab
[idx
].st_name
, var
))
1221 } while (!(chains
[idx
++] & 1u));
1223 else if (hashtab
) /* old style hash table */
1225 const unsigned int hash
= wld_elf_hash(var
);
1226 const Elf32_Word nbuckets
= hashtab
[0];
1227 const Elf32_Word
*buckets
= hashtab
+ 2;
1228 const Elf32_Word
*chains
= buckets
+ nbuckets
;
1230 for (idx
= buckets
[hash
% nbuckets
]; idx
; idx
= chains
[idx
])
1232 if (ELF32_ST_BIND(symtab
[idx
].st_info
) == STB_GLOBAL
&&
1233 ELF32_ST_TYPE(symtab
[idx
].st_info
) == type
&&
1234 !wld_strcmp( strings
+ symtab
[idx
].st_name
, var
))
1242 wld_printf("Found %s -> %p\n", strings
+ symtab
[idx
].st_name
, (void *)symtab
[idx
].st_value
);
1244 return (void *)(symtab
[idx
].st_value
+ map
->l_addr
);
1250 * Reserve a range specified in string format
1252 static void preload_reserve( const char *str
)
1255 unsigned long result
= 0;
1256 void *start
= NULL
, *end
= NULL
;
1259 for (p
= str
; *p
; p
++)
1261 if (*p
>= '0' && *p
<= '9') result
= result
* 16 + *p
- '0';
1262 else if (*p
>= 'a' && *p
<= 'f') result
= result
* 16 + *p
- 'a' + 10;
1263 else if (*p
>= 'A' && *p
<= 'F') result
= result
* 16 + *p
- 'A' + 10;
1266 if (!first
) goto error
;
1267 start
= (void *)(result
& ~page_mask
);
1273 if (!first
) end
= (void *)((result
+ page_mask
) & ~page_mask
);
1274 else if (result
) goto error
; /* single value '0' is allowed */
1277 if (end
<= start
) start
= end
= NULL
;
1278 else if ((char *)end
> preloader_start
&&
1279 (char *)start
<= preloader_end
)
1281 wld_printf( "WINEPRELOADRESERVE range %p-%p overlaps preloader %p-%p\n",
1282 start
, end
, preloader_start
, preloader_end
);
1286 /* check for overlap with low memory areas */
1287 for (i
= 0; preload_info
[i
].size
; i
++)
1289 if ((char *)preload_info
[i
].addr
> (char *)0x00110000) break;
1290 if ((char *)end
<= (char *)preload_info
[i
].addr
+ preload_info
[i
].size
)
1295 if ((char *)start
< (char *)preload_info
[i
].addr
+ preload_info
[i
].size
)
1296 start
= (char *)preload_info
[i
].addr
+ preload_info
[i
].size
;
1299 while (preload_info
[i
].size
) i
++;
1300 preload_info
[i
].addr
= start
;
1301 preload_info
[i
].size
= (char *)end
- (char *)start
;
1305 fatal_error( "invalid WINEPRELOADRESERVE value '%s'\n", str
);
1308 /* check if address is in one of the reserved ranges */
1309 static int is_addr_reserved( const void *addr
)
1313 for (i
= 0; preload_info
[i
].size
; i
++)
1315 if ((const char *)addr
>= (const char *)preload_info
[i
].addr
&&
1316 (const char *)addr
< (const char *)preload_info
[i
].addr
+ preload_info
[i
].size
)
1322 /* remove a range from the preload list */
1323 static void remove_preload_range( int i
)
1325 while (preload_info
[i
].size
)
1327 preload_info
[i
].addr
= preload_info
[i
+1].addr
;
1328 preload_info
[i
].size
= preload_info
[i
+1].size
;
1334 * is_in_preload_range
1336 * Check if address of the given aux value is in one of the reserved ranges
1338 static int is_in_preload_range( const struct wld_auxv
*av
, int type
)
1340 while (av
->a_type
!= AT_NULL
)
1342 if (av
->a_type
== type
) return is_addr_reserved( (const void *)av
->a_un
.a_val
);
1348 /* set the process name if supported */
1349 static void set_process_name( int argc
, char *argv
[] )
1353 char *p
, *name
, *end
;
1355 /* set the process short name */
1356 for (p
= name
= argv
[1]; *p
; p
++) if (p
[0] == '/' && p
[1]) name
= p
+ 1;
1357 if (wld_prctl( 15 /* PR_SET_NAME */, (long)name
) == -1) return;
1359 /* find the end of the argv array and move everything down */
1360 end
= argv
[argc
- 1];
1362 off
= argv
[1] - argv
[0];
1363 for (p
= argv
[1]; p
<= end
; p
++) *(p
- off
) = *p
;
1364 wld_memset( end
- off
, 0, off
);
1365 for (i
= 1; i
< argc
; i
++) argv
[i
] -= off
;
1372 * Repeat the actions the kernel would do when loading a dynamically linked .so
1373 * Load the binary and then its ELF interpreter.
1374 * Note, we assume that the binary is a dynamically linked ELF shared object.
1376 void* wld_start( void **stack
)
1380 char *interp
, *reserve
= NULL
;
1381 struct wld_auxv new_av
[8], delete_av
[3], *av
;
1382 struct wld_link_map main_binary_map
, ld_so_map
;
1383 struct wine_preload_info
**wine_main_preload_info
;
1386 argv
= (char **)pargc
+ 1;
1387 if (*pargc
< 2) fatal_error( "Usage: %s wine_binary [args]\n", argv
[0] );
1389 /* skip over the parameters */
1390 p
= argv
+ *pargc
+ 1;
1392 /* skip over the environment */
1395 static const char res
[] = "WINEPRELOADRESERVE=";
1396 if (!wld_strncmp( *p
, res
, sizeof(res
)-1 )) reserve
= *p
+ sizeof(res
) - 1;
1400 av
= (struct wld_auxv
*)(p
+1);
1401 page_size
= get_auxiliary( av
, AT_PAGESZ
, 4096 );
1402 page_mask
= page_size
- 1;
1404 preloader_start
= (char *)((unsigned long)_start
& ~page_mask
);
1405 preloader_end
= (char *)((unsigned long)(_end
+ page_mask
) & ~page_mask
);
1407 #ifdef DUMP_AUX_INFO
1408 wld_printf( "stack = %p\n", *stack
);
1409 for( i
= 0; i
< *pargc
; i
++ ) wld_printf("argv[%lx] = %s\n", i
, argv
[i
]);
1410 dump_auxiliary( av
);
1413 /* reserve memory that Wine needs */
1414 if (reserve
) preload_reserve( reserve
);
1415 for (i
= 0; preload_info
[i
].size
; i
++)
1417 if ((char *)av
>= (char *)preload_info
[i
].addr
&&
1418 (char *)pargc
<= (char *)preload_info
[i
].addr
+ preload_info
[i
].size
)
1420 remove_preload_range( i
);
1423 else if (wld_mmap( preload_info
[i
].addr
, preload_info
[i
].size
, PROT_NONE
,
1424 MAP_FIXED
| MAP_PRIVATE
| MAP_ANON
| MAP_NORESERVE
, -1, 0 ) == (void *)-1)
1426 /* don't warn for low 64k */
1427 if (preload_info
[i
].addr
>= (void *)0x10000
1429 && preload_info
[i
].addr
< (void *)0x7fffffffff /* ARM64 address space might end here*/
1432 wld_printf( "preloader: Warning: failed to reserve range %p-%p\n",
1433 preload_info
[i
].addr
, (char *)preload_info
[i
].addr
+ preload_info
[i
].size
);
1434 remove_preload_range( i
);
1439 /* add an executable page at the top of the address space to defeat
1440 * broken no-exec protections that play with the code selector limit */
1441 if (is_addr_reserved( (char *)0x80000000 - page_size
))
1442 wld_mprotect( (char *)0x80000000 - page_size
, page_size
, PROT_EXEC
| PROT_READ
);
1444 /* load the main binary */
1445 map_so_lib( argv
[1], &main_binary_map
);
1447 /* load the ELF interpreter */
1448 interp
= (char *)main_binary_map
.l_addr
+ main_binary_map
.l_interp
;
1449 map_so_lib( interp
, &ld_so_map
);
1451 /* store pointer to the preload info into the appropriate main binary variable */
1452 wine_main_preload_info
= find_symbol( &main_binary_map
, "wine_main_preload_info", STT_OBJECT
);
1453 if (wine_main_preload_info
) *wine_main_preload_info
= preload_info
;
1454 else wld_printf( "wine_main_preload_info not found\n" );
1456 #define SET_NEW_AV(n,type,val) new_av[n].a_type = (type); new_av[n].a_un.a_val = (val);
1457 SET_NEW_AV( 0, AT_PHDR
, (unsigned long)main_binary_map
.l_phdr
);
1458 SET_NEW_AV( 1, AT_PHENT
, sizeof(ElfW(Phdr
)) );
1459 SET_NEW_AV( 2, AT_PHNUM
, main_binary_map
.l_phnum
);
1460 SET_NEW_AV( 3, AT_PAGESZ
, page_size
);
1461 SET_NEW_AV( 4, AT_BASE
, ld_so_map
.l_addr
);
1462 SET_NEW_AV( 5, AT_FLAGS
, get_auxiliary( av
, AT_FLAGS
, 0 ) );
1463 SET_NEW_AV( 6, AT_ENTRY
, main_binary_map
.l_entry
);
1464 SET_NEW_AV( 7, AT_NULL
, 0 );
1468 /* delete sysinfo values if addresses conflict */
1469 if (is_in_preload_range( av
, AT_SYSINFO
) || is_in_preload_range( av
, AT_SYSINFO_EHDR
))
1471 delete_av
[i
++].a_type
= AT_SYSINFO
;
1472 delete_av
[i
++].a_type
= AT_SYSINFO_EHDR
;
1474 delete_av
[i
].a_type
= AT_NULL
;
1476 /* get rid of first argument */
1477 set_process_name( *pargc
, argv
);
1478 pargc
[1] = pargc
[0] - 1;
1481 set_auxiliary_values( av
, new_av
, delete_av
, stack
);
1483 #ifdef DUMP_AUX_INFO
1484 wld_printf("new stack = %p\n", *stack
);
1485 wld_printf("jumping to %p\n", (void *)ld_so_map
.l_entry
);
1490 int len
, fd
= wld_open( "/proc/self/maps", O_RDONLY
);
1493 while ((len
= wld_read( fd
, buffer
, sizeof(buffer
) )) > 0) wld_write( 2, buffer
, len
);
1499 return (void *)ld_so_map
.l_entry
;
1502 #pragma GCC visibility pop
1504 #endif /* __linux__ */