1 /****************************************************************************/
3 * QEMU bFLT binary loader. Based on linux/fs/binfmt_flat.c
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 * Copyright (C) 2006 CodeSourcery.
19 * Copyright (C) 2000-2003 David McCullough <davidm@snapgear.com>
20 * Copyright (C) 2002 Greg Ungerer <gerg@snapgear.com>
21 * Copyright (C) 2002 SnapGear, by Paul Dale <pauli@snapgear.com>
22 * Copyright (C) 2000, 2001 Lineo, by David McCullough <davidm@lineo.com>
25 * linux/fs/binfmt_aout.c:
26 * Copyright (C) 1991, 1992, 1996 Linus Torvalds
27 * linux/fs/binfmt_flat.c for 2.0 kernel
28 * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>
29 * JAN/99 -- coded full program relocation (gerg@snapgear.com)
32 /* ??? ZFLAT and shared library support is currently disabled. */
34 /****************************************************************************/
36 #include "qemu/osdep.h"
41 #define ntohl(x) be32_to_cpu(x)
42 #include <target_flat.h>
47 #define DBG_FLT(...) printf(__VA_ARGS__)
52 #define RELOC_FAILED 0xff00ff01 /* Relocation incorrect somewhere */
53 #define UNLOADED_LIB 0x7ff000ff /* Placeholder for unused library */
56 abi_ulong start_code
; /* Start of text segment */
57 abi_ulong start_data
; /* Start of data segment */
58 abi_ulong end_data
; /* Start of bss section */
59 abi_ulong start_brk
; /* End of data segment */
60 abi_ulong text_len
; /* Length of text segment */
61 abi_ulong entry
; /* Start address for this module */
62 abi_ulong build_date
; /* When this one was compiled */
63 short loaded
; /* Has this library been loaded? */
66 #ifdef CONFIG_BINFMT_SHARED_FLAT
67 static int load_flat_shared_library(int id
, struct lib_info
*p
);
72 /****************************************************************************/
74 * create_flat_tables() parses the env- and arg-strings in new user
75 * memory and creates the pointer tables from them, and puts their
76 * addresses on the "stack", returning the new stack pointer value.
79 /* Push a block of strings onto the guest stack. */
80 static abi_ulong
copy_strings(abi_ulong p
, int n
, char **s
)
85 len
= strlen(s
[n
]) + 1;
87 memcpy_to_target(p
, s
[n
], len
);
93 static int target_pread(int fd
, abi_ulong ptr
, abi_ulong len
,
99 buf
= lock_user(VERIFY_WRITE
, ptr
, len
, 0);
100 ret
= pread(fd
, buf
, len
, offset
);
101 unlock_user(buf
, ptr
, len
);
104 /****************************************************************************/
106 #ifdef CONFIG_BINFMT_ZFLAT
108 #include <linux/zlib.h>
110 #define LBUFSIZE 4000
113 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
114 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
115 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
116 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
117 #define COMMENT 0x10 /* bit 4 set: file comment present */
118 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
119 #define RESERVED 0xC0 /* bit 6,7: reserved */
121 static int decompress_exec(
122 struct linux_binprm
*bprm
,
123 unsigned long offset
,
133 DBG_FLT("decompress_exec(offset=%x,buf=%x,len=%x)\n",(int)offset
, (int)dst
, (int)len
);
135 memset(&strm
, 0, sizeof(strm
));
136 strm
.workspace
= kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL
);
137 if (strm
.workspace
== NULL
) {
138 DBG_FLT("binfmt_flat: no memory for decompress workspace\n");
141 buf
= kmalloc(LBUFSIZE
, GFP_KERNEL
);
143 DBG_FLT("binfmt_flat: no memory for read buffer\n");
148 /* Read in first chunk of data and parse gzip header. */
150 ret
= bprm
->file
->f_op
->read(bprm
->file
, buf
, LBUFSIZE
, &fpos
);
158 /* Check minimum size -- gzip header */
160 DBG_FLT("binfmt_flat: file too small?\n");
164 /* Check gzip magic number */
165 if ((buf
[0] != 037) || ((buf
[1] != 0213) && (buf
[1] != 0236))) {
166 DBG_FLT("binfmt_flat: unknown compression magic?\n");
170 /* Check gzip method */
172 DBG_FLT("binfmt_flat: unknown compression method?\n");
175 /* Check gzip flags */
176 if ((buf
[3] & ENCRYPTED
) || (buf
[3] & CONTINUATION
) ||
177 (buf
[3] & RESERVED
)) {
178 DBG_FLT("binfmt_flat: unknown flags?\n");
183 if (buf
[3] & EXTRA_FIELD
) {
184 ret
+= 2 + buf
[10] + (buf
[11] << 8);
185 if (unlikely(LBUFSIZE
== ret
)) {
186 DBG_FLT("binfmt_flat: buffer overflow (EXTRA)?\n");
190 if (buf
[3] & ORIG_NAME
) {
191 for (; ret
< LBUFSIZE
&& (buf
[ret
] != 0); ret
++)
193 if (unlikely(LBUFSIZE
== ret
)) {
194 DBG_FLT("binfmt_flat: buffer overflow (ORIG_NAME)?\n");
198 if (buf
[3] & COMMENT
) {
199 for (; ret
< LBUFSIZE
&& (buf
[ret
] != 0); ret
++)
201 if (unlikely(LBUFSIZE
== ret
)) {
202 DBG_FLT("binfmt_flat: buffer overflow (COMMENT)?\n");
208 strm
.avail_in
-= ret
;
211 strm
.avail_out
= len
;
214 if (zlib_inflateInit2(&strm
, -MAX_WBITS
) != Z_OK
) {
215 DBG_FLT("binfmt_flat: zlib init failed?\n");
219 while ((ret
= zlib_inflate(&strm
, Z_NO_FLUSH
)) == Z_OK
) {
220 ret
= bprm
->file
->f_op
->read(bprm
->file
, buf
, LBUFSIZE
, &fpos
);
223 if (ret
>= (unsigned long) -4096)
233 DBG_FLT("binfmt_flat: decompression failed (%d), %s\n",
240 zlib_inflateEnd(&strm
);
244 kfree(strm
.workspace
);
249 #endif /* CONFIG_BINFMT_ZFLAT */
251 /****************************************************************************/
254 calc_reloc(abi_ulong r
, struct lib_info
*p
, int curid
, int internalp
)
259 abi_ulong start_data
;
261 abi_ulong start_code
;
263 #ifdef CONFIG_BINFMT_SHARED_FLAT
264 #error needs checking
266 id
= curid
; /* Relocs of 0 are always self referring */
268 id
= (r
>> 24) & 0xff; /* Find ID for this reloc */
269 r
&= 0x00ffffff; /* Trim ID off here */
271 if (id
>= MAX_SHARED_LIBS
) {
272 fprintf(stderr
, "BINFMT_FLAT: reference 0x%x to shared library %d\n",
278 fprintf(stderr
, "BINFMT_FLAT: reloc address 0x%x not "
279 "in same module (%d != %d)\n",
280 (unsigned) r
, curid
, id
);
282 } else if ( ! p
[id
].loaded
&&
283 load_flat_shared_library(id
, p
) > (unsigned long) -4096) {
284 fprintf(stderr
, "BINFMT_FLAT: failed to load library %d\n", id
);
287 /* Check versioning information (i.e. time stamps) */
288 if (p
[id
].build_date
&& p
[curid
].build_date
289 && p
[curid
].build_date
< p
[id
].build_date
) {
290 fprintf(stderr
, "BINFMT_FLAT: library %d is younger than %d\n",
299 start_brk
= p
[id
].start_brk
;
300 start_data
= p
[id
].start_data
;
301 start_code
= p
[id
].start_code
;
302 text_len
= p
[id
].text_len
;
304 if (!flat_reloc_valid(r
, start_brk
- start_data
+ text_len
)) {
305 fprintf(stderr
, "BINFMT_FLAT: reloc outside program 0x%x "
307 (int) r
,(int)(start_brk
-start_code
),(int)text_len
);
311 if (r
< text_len
) /* In text segment */
312 addr
= r
+ start_code
;
313 else /* In data segment */
314 addr
= r
- text_len
+ start_data
;
316 /* Range checked already above so doing the range tests is redundant...*/
324 /****************************************************************************/
326 /* ??? This does not handle endianness correctly. */
327 static void old_reloc(struct lib_info
*libinfo
, uint32_t rl
)
330 const char *segment
[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" };
336 offset
= rl
& 0x3fffffff;
337 reloc_type
= rl
>> 30;
338 /* ??? How to handle this? */
339 #if defined(CONFIG_COLDFIRE)
340 ptr
= (uint32_t *) ((unsigned long) libinfo
->start_code
+ offset
);
342 ptr
= (uint32_t *) ((unsigned long) libinfo
->start_data
+ offset
);
346 fprintf(stderr
, "Relocation of variable at DATASEG+%x "
347 "(address %p, currently %x) into segment %s\n",
348 offset
, ptr
, (int)*ptr
, segment
[reloc_type
]);
351 switch (reloc_type
) {
352 case OLD_FLAT_RELOC_TYPE_TEXT
:
353 *ptr
+= libinfo
->start_code
;
355 case OLD_FLAT_RELOC_TYPE_DATA
:
356 *ptr
+= libinfo
->start_data
;
358 case OLD_FLAT_RELOC_TYPE_BSS
:
359 *ptr
+= libinfo
->end_data
;
362 fprintf(stderr
, "BINFMT_FLAT: Unknown relocation type=%x\n",
366 DBG_FLT("Relocation became %x\n", (int)*ptr
);
369 /****************************************************************************/
371 static int load_flat_file(struct linux_binprm
* bprm
,
372 struct lib_info
*libinfo
, int id
, abi_ulong
*extra_stack
)
374 struct flat_hdr
* hdr
;
375 abi_ulong textpos
= 0, datapos
= 0;
377 abi_ulong realdatastart
= 0;
378 abi_ulong text_len
, data_len
, bss_len
, stack_len
, flags
;
380 abi_ulong reloc
= 0, rp
;
381 int i
, rev
, relocs
= 0;
383 abi_ulong start_code
;
386 hdr
= ((struct flat_hdr
*) bprm
->buf
); /* exec-header */
388 text_len
= ntohl(hdr
->data_start
);
389 data_len
= ntohl(hdr
->data_end
) - ntohl(hdr
->data_start
);
390 bss_len
= ntohl(hdr
->bss_end
) - ntohl(hdr
->data_end
);
391 stack_len
= ntohl(hdr
->stack_size
);
393 stack_len
+= *extra_stack
;
394 *extra_stack
= stack_len
;
396 relocs
= ntohl(hdr
->reloc_count
);
397 flags
= ntohl(hdr
->flags
);
398 rev
= ntohl(hdr
->rev
);
400 DBG_FLT("BINFMT_FLAT: Loading file: %s\n", bprm
->filename
);
402 if (rev
!= FLAT_VERSION
&& rev
!= OLD_FLAT_VERSION
) {
403 fprintf(stderr
, "BINFMT_FLAT: bad magic/rev (0x%x, need 0x%x)\n",
404 rev
, (int) FLAT_VERSION
);
408 /* Don't allow old format executables to use shared libraries */
409 if (rev
== OLD_FLAT_VERSION
&& id
!= 0) {
410 fprintf(stderr
, "BINFMT_FLAT: shared libraries are not available\n");
415 * fix up the flags for the older format, there were all kinds
416 * of endian hacks, this only works for the simple cases
418 if (rev
== OLD_FLAT_VERSION
&& flat_old_ram_flag(flags
))
419 flags
= FLAT_FLAG_RAM
;
421 #ifndef CONFIG_BINFMT_ZFLAT
422 if (flags
& (FLAT_FLAG_GZIP
|FLAT_FLAG_GZDATA
)) {
423 fprintf(stderr
, "Support for ZFLAT executables is not enabled\n");
429 * calculate the extra space we need to map in
431 extra
= relocs
* sizeof(abi_ulong
);
432 if (extra
< bss_len
+ stack_len
)
433 extra
= bss_len
+ stack_len
;
435 /* Add space for library base pointers. Make sure this does not
436 misalign the doesn't misalign the data segment. */
437 indx_len
= MAX_SHARED_LIBS
* sizeof(abi_ulong
);
438 indx_len
= (indx_len
+ 15) & ~(abi_ulong
)15;
441 * there are a couple of cases here, the separate code/data
442 * case, and then the fully copied to RAM case which lumps
445 if ((flags
& (FLAT_FLAG_RAM
|FLAT_FLAG_GZIP
)) == 0) {
447 * this should give us a ROM ptr, but if it doesn't we don't
450 DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n");
452 textpos
= target_mmap(0, text_len
, PROT_READ
|PROT_EXEC
,
453 MAP_PRIVATE
, bprm
->fd
, 0);
455 fprintf(stderr
, "Unable to mmap process text\n");
459 realdatastart
= target_mmap(0, data_len
+ extra
+ indx_len
,
460 PROT_READ
|PROT_WRITE
|PROT_EXEC
,
461 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
463 if (realdatastart
== -1) {
464 fprintf(stderr
, "Unable to allocate RAM for process data\n");
465 return realdatastart
;
467 datapos
= realdatastart
+ indx_len
;
469 DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%d bytes): %x\n",
470 (int)(data_len
+ bss_len
+ stack_len
), (int)datapos
);
472 fpos
= ntohl(hdr
->data_start
);
473 #ifdef CONFIG_BINFMT_ZFLAT
474 if (flags
& FLAT_FLAG_GZDATA
) {
475 result
= decompress_exec(bprm
, fpos
, (char *) datapos
,
476 data_len
+ (relocs
* sizeof(abi_ulong
)))
480 result
= target_pread(bprm
->fd
, datapos
,
481 data_len
+ (relocs
* sizeof(abi_ulong
)),
485 fprintf(stderr
, "Unable to read data+bss\n");
489 reloc
= datapos
+ (ntohl(hdr
->reloc_start
) - text_len
);
493 textpos
= target_mmap(0, text_len
+ data_len
+ extra
+ indx_len
,
494 PROT_READ
| PROT_EXEC
| PROT_WRITE
,
495 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
496 if (textpos
== -1 ) {
497 fprintf(stderr
, "Unable to allocate RAM for process text/data\n");
501 realdatastart
= textpos
+ ntohl(hdr
->data_start
);
502 datapos
= realdatastart
+ indx_len
;
503 reloc
= (textpos
+ ntohl(hdr
->reloc_start
) + indx_len
);
505 #ifdef CONFIG_BINFMT_ZFLAT
506 #error code needs checking
508 * load it all in and treat it like a RAM load from now on
510 if (flags
& FLAT_FLAG_GZIP
) {
511 result
= decompress_exec(bprm
, sizeof (struct flat_hdr
),
512 (((char *) textpos
) + sizeof (struct flat_hdr
)),
513 (text_len
+ data_len
+ (relocs
* sizeof(unsigned long))
514 - sizeof (struct flat_hdr
)),
516 memmove((void *) datapos
, (void *) realdatastart
,
517 data_len
+ (relocs
* sizeof(unsigned long)));
518 } else if (flags
& FLAT_FLAG_GZDATA
) {
520 result
= bprm
->file
->f_op
->read(bprm
->file
,
521 (char *) textpos
, text_len
, &fpos
);
522 if (result
< (unsigned long) -4096)
523 result
= decompress_exec(bprm
, text_len
, (char *) datapos
,
524 data_len
+ (relocs
* sizeof(unsigned long)), 0);
529 result
= target_pread(bprm
->fd
, textpos
,
532 result
= target_pread(bprm
->fd
, datapos
,
533 data_len
+ (relocs
* sizeof(abi_ulong
)),
534 ntohl(hdr
->data_start
));
538 fprintf(stderr
, "Unable to read code+data+bss\n");
543 DBG_FLT("Mapping is 0x%x, Entry point is 0x%x, data_start is 0x%x\n",
544 (int)textpos
, 0x00ffffff&ntohl(hdr
->entry
),
545 ntohl(hdr
->data_start
));
547 /* The main program needs a little extra setup in the task structure */
548 start_code
= textpos
+ sizeof (struct flat_hdr
);
550 DBG_FLT("%s %s: TEXT=%x-%x DATA=%x-%x BSS=%x-%x\n",
551 id
? "Lib" : "Load", bprm
->filename
,
552 (int) start_code
, (int) (textpos
+ text_len
),
554 (int) (datapos
+ data_len
),
555 (int) (datapos
+ data_len
),
556 (int) (((datapos
+ data_len
+ bss_len
) + 3) & ~3));
558 text_len
-= sizeof(struct flat_hdr
); /* the real code len */
560 /* Store the current module values into the global library structure */
561 libinfo
[id
].start_code
= start_code
;
562 libinfo
[id
].start_data
= datapos
;
563 libinfo
[id
].end_data
= datapos
+ data_len
;
564 libinfo
[id
].start_brk
= datapos
+ data_len
+ bss_len
;
565 libinfo
[id
].text_len
= text_len
;
566 libinfo
[id
].loaded
= 1;
567 libinfo
[id
].entry
= (0x00ffffff & ntohl(hdr
->entry
)) + textpos
;
568 libinfo
[id
].build_date
= ntohl(hdr
->build_date
);
571 * We just load the allocations into some temporary memory to
572 * help simplify all this mumbo jumbo
574 * We've got two different sections of relocation entries.
575 * The first is the GOT which resides at the beginning of the data segment
576 * and is terminated with a -1. This one can be relocated in place.
577 * The second is the extra relocation entries tacked after the image's
578 * data segment. These require a little more processing as the entry is
579 * really an offset into the image which contains an offset into the
582 if (flags
& FLAT_FLAG_GOTPIC
) {
586 if (get_user_ual(addr
, rp
))
591 addr
= calc_reloc(addr
, libinfo
, id
, 0);
592 if (addr
== RELOC_FAILED
)
594 if (put_user_ual(addr
, rp
))
597 rp
+= sizeof(abi_ulong
);
602 * Now run through the relocation entries.
603 * We've got to be careful here as C++ produces relocatable zero
604 * entries in the constructor and destructor tables which are then
605 * tested for being not zero (which will always occur unless we're
606 * based from address zero). This causes an endless loop as __start
607 * is at zero. The solution used is to not relocate zero addresses.
608 * This has the negative side effect of not allowing a global data
609 * reference to be statically initialised to _stext (I've moved
610 * __start to address 4 so that is okay).
612 if (rev
> OLD_FLAT_VERSION
) {
613 abi_ulong persistent
= 0;
614 for (i
= 0; i
< relocs
; i
++) {
615 abi_ulong addr
, relval
;
617 /* Get the address of the pointer to be
618 relocated (of course, the address has to be
620 if (get_user_ual(relval
, reloc
+ i
* sizeof(abi_ulong
)))
622 relval
= ntohl(relval
);
623 if (flat_set_persistent(relval
, &persistent
))
625 addr
= flat_get_relocate_addr(relval
);
626 rp
= calc_reloc(addr
, libinfo
, id
, 1);
627 if (rp
== RELOC_FAILED
)
630 /* Get the pointer's value. */
631 if (get_user_ual(addr
, rp
))
633 addr
= flat_get_addr_from_rp(addr
, relval
, flags
, &persistent
);
636 * Do the relocation. PIC relocs in the data section are
637 * already in target order
639 if ((flags
& FLAT_FLAG_GOTPIC
) == 0)
641 addr
= calc_reloc(addr
, libinfo
, id
, 0);
642 if (addr
== RELOC_FAILED
)
645 /* Write back the relocated pointer. */
646 if (flat_put_addr_at_rp(rp
, addr
, relval
))
651 for (i
= 0; i
< relocs
; i
++) {
653 if (get_user_ual(relval
, reloc
+ i
* sizeof(abi_ulong
)))
655 old_reloc(&libinfo
[0], relval
);
660 memset(g2h(datapos
+ data_len
), 0, bss_len
);
666 /****************************************************************************/
667 #ifdef CONFIG_BINFMT_SHARED_FLAT
670 * Load a shared library into memory. The library gets its own data
671 * segment (including bss) but not argv/argc/environ.
674 static int load_flat_shared_library(int id
, struct lib_info
*libs
)
676 struct linux_binprm bprm
;
680 /* Create the file name */
681 sprintf(buf
, "/lib/lib%d.so", id
);
683 /* Open the file up */
685 bprm
.file
= open_exec(bprm
.filename
);
686 res
= PTR_ERR(bprm
.file
);
687 if (IS_ERR(bprm
.file
))
690 res
= prepare_binprm(&bprm
);
692 if (res
<= (unsigned long)-4096)
693 res
= load_flat_file(&bprm
, libs
, id
, NULL
);
695 allow_write_access(bprm
.file
);
702 #endif /* CONFIG_BINFMT_SHARED_FLAT */
704 int load_flt_binary(struct linux_binprm
*bprm
, struct image_info
*info
)
706 struct lib_info libinfo
[MAX_SHARED_LIBS
];
709 abi_ulong start_addr
;
714 memset(libinfo
, 0, sizeof(libinfo
));
716 * We have to add the size of our arguments to our stack size
717 * otherwise it's too easy for users to create stack overflows
718 * by passing in a huge argument list. And yes, we have to be
719 * pedantic and include space for the argv/envp array as it may have
723 for (i
= 0; i
< bprm
->argc
; ++i
) {
724 /* the argv strings */
725 stack_len
+= strlen(bprm
->argv
[i
]);
727 for (i
= 0; i
< bprm
->envc
; ++i
) {
728 /* the envp strings */
729 stack_len
+= strlen(bprm
->envp
[i
]);
731 stack_len
+= (bprm
->argc
+ 1) * 4; /* the argv array */
732 stack_len
+= (bprm
->envc
+ 1) * 4; /* the envp array */
735 res
= load_flat_file(bprm
, libinfo
, 0, &stack_len
);
736 if (res
> (unsigned long)-4096)
739 /* Update data segment pointers for all libraries */
740 for (i
=0; i
<MAX_SHARED_LIBS
; i
++) {
741 if (libinfo
[i
].loaded
) {
743 p
= libinfo
[i
].start_data
;
744 for (j
=0; j
<MAX_SHARED_LIBS
; j
++) {
746 /* FIXME - handle put_user() failures */
747 if (put_user_ual(libinfo
[j
].loaded
748 ? libinfo
[j
].start_data
756 p
= ((libinfo
[0].start_brk
+ stack_len
+ 3) & ~3) - 4;
757 DBG_FLT("p=%x\n", (int)p
);
759 /* Copy argv/envp. */
760 p
= copy_strings(p
, bprm
->envc
, bprm
->envp
);
761 p
= copy_strings(p
, bprm
->argc
, bprm
->argv
);
763 sp
= p
& ~(abi_ulong
)(sizeof(abi_ulong
) - 1);
764 /* Enforce final stack alignment of 16 bytes. This is sufficient
765 for all current targets, and excess alignment is harmless. */
766 stack_len
= bprm
->envc
+ bprm
->argc
+ 2;
767 stack_len
+= 3; /* argc, arvg, argp */
768 stack_len
*= sizeof(abi_ulong
);
769 if ((sp
+ stack_len
) & 15)
770 sp
-= 16 - ((sp
+ stack_len
) & 15);
771 sp
= loader_build_argptr(bprm
->envc
, bprm
->argc
, sp
, p
,
772 flat_argvp_envp_on_stack());
774 /* Fake some return addresses to ensure the call chain will
775 * initialise library in order for us. We are required to call
776 * lib 1 first, then 2, ... and finally the main program (id 0).
778 start_addr
= libinfo
[0].entry
;
780 #ifdef CONFIG_BINFMT_SHARED_FLAT
782 for (i
= MAX_SHARED_LIBS
-1; i
>0; i
--) {
783 if (libinfo
[i
].loaded
) {
784 /* Push previos first to call address */
786 if (put_user_ual(start_addr
, sp
))
788 start_addr
= libinfo
[i
].entry
;
793 /* Stash our initial stack pointer into the mm structure */
794 info
->start_code
= libinfo
[0].start_code
;
795 info
->end_code
= libinfo
[0].start_code
= libinfo
[0].text_len
;
796 info
->start_data
= libinfo
[0].start_data
;
797 info
->end_data
= libinfo
[0].end_data
;
798 info
->start_brk
= libinfo
[0].start_brk
;
799 info
->start_stack
= sp
;
800 info
->stack_limit
= libinfo
[0].start_brk
;
801 info
->entry
= start_addr
;
802 info
->code_offset
= info
->start_code
;
803 info
->data_offset
= info
->start_data
- libinfo
[0].text_len
;
805 DBG_FLT("start_thread(entry=0x%x, start_stack=0x%x)\n",
806 (int)info
->entry
, (int)info
->start_stack
);