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 /****************************************************************************/
48 #define DBG_FLT(...) printf(__VA_ARGS__)
53 #define flat_reloc_valid(reloc, size) ((reloc) <= (size))
54 #define flat_old_ram_flag(flag) (flag)
55 #ifdef TARGET_WORDS_BIGENDIAN
56 #define flat_get_relocate_addr(relval) (relval)
58 #define flat_get_relocate_addr(relval) bswap32(relval)
61 #define RELOC_FAILED 0xff00ff01 /* Relocation incorrect somewhere */
62 #define UNLOADED_LIB 0x7ff000ff /* Placeholder for unused library */
65 abi_ulong start_code
; /* Start of text segment */
66 abi_ulong start_data
; /* Start of data segment */
67 abi_ulong end_data
; /* Start of bss section */
68 abi_ulong start_brk
; /* End of data segment */
69 abi_ulong text_len
; /* Length of text segment */
70 abi_ulong entry
; /* Start address for this module */
71 abi_ulong build_date
; /* When this one was compiled */
72 short loaded
; /* Has this library been loaded? */
75 #ifdef CONFIG_BINFMT_SHARED_FLAT
76 static int load_flat_shared_library(int id
, struct lib_info
*p
);
81 #define ntohl(x) be32_to_cpu(x)
83 /****************************************************************************/
85 * create_flat_tables() parses the env- and arg-strings in new user
86 * memory and creates the pointer tables from them, and puts their
87 * addresses on the "stack", returning the new stack pointer value.
90 /* Push a block of strings onto the guest stack. */
91 static abi_ulong
copy_strings(abi_ulong p
, int n
, char **s
)
96 len
= strlen(s
[n
]) + 1;
98 memcpy_to_target(p
, s
[n
], len
);
104 static int target_pread(int fd
, abi_ulong ptr
, abi_ulong len
,
110 buf
= lock_user(VERIFY_WRITE
, ptr
, len
, 0);
111 ret
= pread(fd
, buf
, len
, offset
);
112 unlock_user(buf
, ptr
, len
);
115 /****************************************************************************/
117 #ifdef CONFIG_BINFMT_ZFLAT
119 #include <linux/zlib.h>
121 #define LBUFSIZE 4000
124 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
125 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
126 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
127 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
128 #define COMMENT 0x10 /* bit 4 set: file comment present */
129 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
130 #define RESERVED 0xC0 /* bit 6,7: reserved */
132 static int decompress_exec(
133 struct linux_binprm
*bprm
,
134 unsigned long offset
,
144 DBG_FLT("decompress_exec(offset=%x,buf=%x,len=%x)\n",(int)offset
, (int)dst
, (int)len
);
146 memset(&strm
, 0, sizeof(strm
));
147 strm
.workspace
= kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL
);
148 if (strm
.workspace
== NULL
) {
149 DBG_FLT("binfmt_flat: no memory for decompress workspace\n");
152 buf
= kmalloc(LBUFSIZE
, GFP_KERNEL
);
154 DBG_FLT("binfmt_flat: no memory for read buffer\n");
159 /* Read in first chunk of data and parse gzip header. */
161 ret
= bprm
->file
->f_op
->read(bprm
->file
, buf
, LBUFSIZE
, &fpos
);
169 /* Check minimum size -- gzip header */
171 DBG_FLT("binfmt_flat: file too small?\n");
175 /* Check gzip magic number */
176 if ((buf
[0] != 037) || ((buf
[1] != 0213) && (buf
[1] != 0236))) {
177 DBG_FLT("binfmt_flat: unknown compression magic?\n");
181 /* Check gzip method */
183 DBG_FLT("binfmt_flat: unknown compression method?\n");
186 /* Check gzip flags */
187 if ((buf
[3] & ENCRYPTED
) || (buf
[3] & CONTINUATION
) ||
188 (buf
[3] & RESERVED
)) {
189 DBG_FLT("binfmt_flat: unknown flags?\n");
194 if (buf
[3] & EXTRA_FIELD
) {
195 ret
+= 2 + buf
[10] + (buf
[11] << 8);
196 if (unlikely(LBUFSIZE
== ret
)) {
197 DBG_FLT("binfmt_flat: buffer overflow (EXTRA)?\n");
201 if (buf
[3] & ORIG_NAME
) {
202 for (; ret
< LBUFSIZE
&& (buf
[ret
] != 0); ret
++)
204 if (unlikely(LBUFSIZE
== ret
)) {
205 DBG_FLT("binfmt_flat: buffer overflow (ORIG_NAME)?\n");
209 if (buf
[3] & COMMENT
) {
210 for (; ret
< LBUFSIZE
&& (buf
[ret
] != 0); ret
++)
212 if (unlikely(LBUFSIZE
== ret
)) {
213 DBG_FLT("binfmt_flat: buffer overflow (COMMENT)?\n");
219 strm
.avail_in
-= ret
;
222 strm
.avail_out
= len
;
225 if (zlib_inflateInit2(&strm
, -MAX_WBITS
) != Z_OK
) {
226 DBG_FLT("binfmt_flat: zlib init failed?\n");
230 while ((ret
= zlib_inflate(&strm
, Z_NO_FLUSH
)) == Z_OK
) {
231 ret
= bprm
->file
->f_op
->read(bprm
->file
, buf
, LBUFSIZE
, &fpos
);
234 if (ret
>= (unsigned long) -4096)
244 DBG_FLT("binfmt_flat: decompression failed (%d), %s\n",
251 zlib_inflateEnd(&strm
);
255 kfree(strm
.workspace
);
260 #endif /* CONFIG_BINFMT_ZFLAT */
262 /****************************************************************************/
265 calc_reloc(abi_ulong r
, struct lib_info
*p
, int curid
, int internalp
)
270 abi_ulong start_data
;
272 abi_ulong start_code
;
274 #ifdef CONFIG_BINFMT_SHARED_FLAT
275 #error needs checking
277 id
= curid
; /* Relocs of 0 are always self referring */
279 id
= (r
>> 24) & 0xff; /* Find ID for this reloc */
280 r
&= 0x00ffffff; /* Trim ID off here */
282 if (id
>= MAX_SHARED_LIBS
) {
283 fprintf(stderr
, "BINFMT_FLAT: reference 0x%x to shared library %d\n",
289 fprintf(stderr
, "BINFMT_FLAT: reloc address 0x%x not "
290 "in same module (%d != %d)\n",
291 (unsigned) r
, curid
, id
);
293 } else if ( ! p
[id
].loaded
&&
294 load_flat_shared_library(id
, p
) > (unsigned long) -4096) {
295 fprintf(stderr
, "BINFMT_FLAT: failed to load library %d\n", id
);
298 /* Check versioning information (i.e. time stamps) */
299 if (p
[id
].build_date
&& p
[curid
].build_date
300 && p
[curid
].build_date
< p
[id
].build_date
) {
301 fprintf(stderr
, "BINFMT_FLAT: library %d is younger than %d\n",
310 start_brk
= p
[id
].start_brk
;
311 start_data
= p
[id
].start_data
;
312 start_code
= p
[id
].start_code
;
313 text_len
= p
[id
].text_len
;
315 if (!flat_reloc_valid(r
, start_brk
- start_data
+ text_len
)) {
316 fprintf(stderr
, "BINFMT_FLAT: reloc outside program 0x%x "
318 (int) r
,(int)(start_brk
-start_code
),(int)text_len
);
322 if (r
< text_len
) /* In text segment */
323 addr
= r
+ start_code
;
324 else /* In data segment */
325 addr
= r
- text_len
+ start_data
;
327 /* Range checked already above so doing the range tests is redundant...*/
335 /****************************************************************************/
337 /* ??? This does not handle endianness correctly. */
338 static void old_reloc(struct lib_info
*libinfo
, uint32_t rl
)
341 const char *segment
[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" };
347 offset
= rl
& 0x3fffffff;
348 reloc_type
= rl
>> 30;
349 /* ??? How to handle this? */
350 #if defined(CONFIG_COLDFIRE)
351 ptr
= (uint32_t *) ((unsigned long) libinfo
->start_code
+ offset
);
353 ptr
= (uint32_t *) ((unsigned long) libinfo
->start_data
+ offset
);
357 fprintf(stderr
, "Relocation of variable at DATASEG+%x "
358 "(address %p, currently %x) into segment %s\n",
359 offset
, ptr
, (int)*ptr
, segment
[reloc_type
]);
362 switch (reloc_type
) {
363 case OLD_FLAT_RELOC_TYPE_TEXT
:
364 *ptr
+= libinfo
->start_code
;
366 case OLD_FLAT_RELOC_TYPE_DATA
:
367 *ptr
+= libinfo
->start_data
;
369 case OLD_FLAT_RELOC_TYPE_BSS
:
370 *ptr
+= libinfo
->end_data
;
373 fprintf(stderr
, "BINFMT_FLAT: Unknown relocation type=%x\n",
377 DBG_FLT("Relocation became %x\n", (int)*ptr
);
380 /****************************************************************************/
382 static int load_flat_file(struct linux_binprm
* bprm
,
383 struct lib_info
*libinfo
, int id
, abi_ulong
*extra_stack
)
385 struct flat_hdr
* hdr
;
386 abi_ulong textpos
= 0, datapos
= 0, result
;
387 abi_ulong realdatastart
= 0;
388 abi_ulong text_len
, data_len
, bss_len
, stack_len
, flags
;
389 abi_ulong memp
= 0; /* for finding the brk area */
391 abi_ulong reloc
= 0, rp
;
392 int i
, rev
, relocs
= 0;
394 abi_ulong start_code
, end_code
;
397 hdr
= ((struct flat_hdr
*) bprm
->buf
); /* exec-header */
399 text_len
= ntohl(hdr
->data_start
);
400 data_len
= ntohl(hdr
->data_end
) - ntohl(hdr
->data_start
);
401 bss_len
= ntohl(hdr
->bss_end
) - ntohl(hdr
->data_end
);
402 stack_len
= ntohl(hdr
->stack_size
);
404 stack_len
+= *extra_stack
;
405 *extra_stack
= stack_len
;
407 relocs
= ntohl(hdr
->reloc_count
);
408 flags
= ntohl(hdr
->flags
);
409 rev
= ntohl(hdr
->rev
);
411 DBG_FLT("BINFMT_FLAT: Loading file: %s\n", bprm
->filename
);
413 if (rev
!= FLAT_VERSION
&& rev
!= OLD_FLAT_VERSION
) {
414 fprintf(stderr
, "BINFMT_FLAT: bad magic/rev (0x%x, need 0x%x)\n",
415 rev
, (int) FLAT_VERSION
);
419 /* Don't allow old format executables to use shared libraries */
420 if (rev
== OLD_FLAT_VERSION
&& id
!= 0) {
421 fprintf(stderr
, "BINFMT_FLAT: shared libraries are not available\n");
426 * fix up the flags for the older format, there were all kinds
427 * of endian hacks, this only works for the simple cases
429 if (rev
== OLD_FLAT_VERSION
&& flat_old_ram_flag(flags
))
430 flags
= FLAT_FLAG_RAM
;
432 #ifndef CONFIG_BINFMT_ZFLAT
433 if (flags
& (FLAT_FLAG_GZIP
|FLAT_FLAG_GZDATA
)) {
434 fprintf(stderr
, "Support for ZFLAT executables is not enabled\n");
440 * calculate the extra space we need to map in
442 extra
= relocs
* sizeof(abi_ulong
);
443 if (extra
< bss_len
+ stack_len
)
444 extra
= bss_len
+ stack_len
;
446 /* Add space for library base pointers. Make sure this does not
447 misalign the doesn't misalign the data segment. */
448 indx_len
= MAX_SHARED_LIBS
* sizeof(abi_ulong
);
449 indx_len
= (indx_len
+ 15) & ~(abi_ulong
)15;
452 * there are a couple of cases here, the separate code/data
453 * case, and then the fully copied to RAM case which lumps
456 if ((flags
& (FLAT_FLAG_RAM
|FLAT_FLAG_GZIP
)) == 0) {
458 * this should give us a ROM ptr, but if it doesn't we don't
461 DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n");
463 textpos
= target_mmap(0, text_len
, PROT_READ
|PROT_EXEC
,
464 MAP_PRIVATE
, bprm
->fd
, 0);
466 fprintf(stderr
, "Unable to mmap process text\n");
470 realdatastart
= target_mmap(0, data_len
+ extra
+ indx_len
,
471 PROT_READ
|PROT_WRITE
|PROT_EXEC
,
472 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
474 if (realdatastart
== -1) {
475 fprintf(stderr
, "Unable to allocate RAM for process data\n");
476 return realdatastart
;
478 datapos
= realdatastart
+ indx_len
;
480 DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%d bytes): %x\n",
481 (int)(data_len
+ bss_len
+ stack_len
), (int)datapos
);
483 fpos
= ntohl(hdr
->data_start
);
484 #ifdef CONFIG_BINFMT_ZFLAT
485 if (flags
& FLAT_FLAG_GZDATA
) {
486 result
= decompress_exec(bprm
, fpos
, (char *) datapos
,
487 data_len
+ (relocs
* sizeof(abi_ulong
)))
491 result
= target_pread(bprm
->fd
, datapos
,
492 data_len
+ (relocs
* sizeof(abi_ulong
)),
496 fprintf(stderr
, "Unable to read data+bss\n");
500 reloc
= datapos
+ (ntohl(hdr
->reloc_start
) - text_len
);
501 memp
= realdatastart
;
505 textpos
= target_mmap(0, text_len
+ data_len
+ extra
+ indx_len
,
506 PROT_READ
| PROT_EXEC
| PROT_WRITE
,
507 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
508 if (textpos
== -1 ) {
509 fprintf(stderr
, "Unable to allocate RAM for process text/data\n");
513 realdatastart
= textpos
+ ntohl(hdr
->data_start
);
514 datapos
= realdatastart
+ indx_len
;
515 reloc
= (textpos
+ ntohl(hdr
->reloc_start
) + indx_len
);
518 #ifdef CONFIG_BINFMT_ZFLAT
519 #error code needs checking
521 * load it all in and treat it like a RAM load from now on
523 if (flags
& FLAT_FLAG_GZIP
) {
524 result
= decompress_exec(bprm
, sizeof (struct flat_hdr
),
525 (((char *) textpos
) + sizeof (struct flat_hdr
)),
526 (text_len
+ data_len
+ (relocs
* sizeof(unsigned long))
527 - sizeof (struct flat_hdr
)),
529 memmove((void *) datapos
, (void *) realdatastart
,
530 data_len
+ (relocs
* sizeof(unsigned long)));
531 } else if (flags
& FLAT_FLAG_GZDATA
) {
533 result
= bprm
->file
->f_op
->read(bprm
->file
,
534 (char *) textpos
, text_len
, &fpos
);
535 if (result
< (unsigned long) -4096)
536 result
= decompress_exec(bprm
, text_len
, (char *) datapos
,
537 data_len
+ (relocs
* sizeof(unsigned long)), 0);
542 result
= target_pread(bprm
->fd
, textpos
,
545 result
= target_pread(bprm
->fd
, datapos
,
546 data_len
+ (relocs
* sizeof(abi_ulong
)),
547 ntohl(hdr
->data_start
));
551 fprintf(stderr
, "Unable to read code+data+bss\n");
556 DBG_FLT("Mapping is 0x%x, Entry point is 0x%x, data_start is 0x%x\n",
557 (int)textpos
, 0x00ffffff&ntohl(hdr
->entry
),
558 ntohl(hdr
->data_start
));
560 /* The main program needs a little extra setup in the task structure */
561 start_code
= textpos
+ sizeof (struct flat_hdr
);
562 end_code
= textpos
+ text_len
;
564 DBG_FLT("%s %s: TEXT=%x-%x DATA=%x-%x BSS=%x-%x\n",
565 id
? "Lib" : "Load", bprm
->filename
,
566 (int) start_code
, (int) end_code
,
568 (int) (datapos
+ data_len
),
569 (int) (datapos
+ data_len
),
570 (int) (((datapos
+ data_len
+ bss_len
) + 3) & ~3));
572 text_len
-= sizeof(struct flat_hdr
); /* the real code len */
574 /* Store the current module values into the global library structure */
575 libinfo
[id
].start_code
= start_code
;
576 libinfo
[id
].start_data
= datapos
;
577 libinfo
[id
].end_data
= datapos
+ data_len
;
578 libinfo
[id
].start_brk
= datapos
+ data_len
+ bss_len
;
579 libinfo
[id
].text_len
= text_len
;
580 libinfo
[id
].loaded
= 1;
581 libinfo
[id
].entry
= (0x00ffffff & ntohl(hdr
->entry
)) + textpos
;
582 libinfo
[id
].build_date
= ntohl(hdr
->build_date
);
585 * We just load the allocations into some temporary memory to
586 * help simplify all this mumbo jumbo
588 * We've got two different sections of relocation entries.
589 * The first is the GOT which resides at the begining of the data segment
590 * and is terminated with a -1. This one can be relocated in place.
591 * The second is the extra relocation entries tacked after the image's
592 * data segment. These require a little more processing as the entry is
593 * really an offset into the image which contains an offset into the
596 if (flags
& FLAT_FLAG_GOTPIC
) {
600 if (get_user_ual(addr
, rp
))
605 addr
= calc_reloc(addr
, libinfo
, id
, 0);
606 if (addr
== RELOC_FAILED
)
608 if (put_user_ual(addr
, rp
))
611 rp
+= sizeof(abi_ulong
);
616 * Now run through the relocation entries.
617 * We've got to be careful here as C++ produces relocatable zero
618 * entries in the constructor and destructor tables which are then
619 * tested for being not zero (which will always occur unless we're
620 * based from address zero). This causes an endless loop as __start
621 * is at zero. The solution used is to not relocate zero addresses.
622 * This has the negative side effect of not allowing a global data
623 * reference to be statically initialised to _stext (I've moved
624 * __start to address 4 so that is okay).
626 if (rev
> OLD_FLAT_VERSION
) {
627 for (i
= 0; i
< relocs
; i
++) {
628 abi_ulong addr
, relval
;
630 /* Get the address of the pointer to be
631 relocated (of course, the address has to be
633 if (get_user_ual(relval
, reloc
+ i
* sizeof(abi_ulong
)))
635 addr
= flat_get_relocate_addr(relval
);
636 rp
= calc_reloc(addr
, libinfo
, id
, 1);
637 if (rp
== RELOC_FAILED
)
640 /* Get the pointer's value. */
641 if (get_user_ual(addr
, rp
))
645 * Do the relocation. PIC relocs in the data section are
646 * already in target order
649 #ifndef TARGET_WORDS_BIGENDIAN
650 if ((flags
& FLAT_FLAG_GOTPIC
) == 0)
651 addr
= bswap32(addr
);
653 addr
= calc_reloc(addr
, libinfo
, id
, 0);
654 if (addr
== RELOC_FAILED
)
657 /* Write back the relocated pointer. */
658 if (put_user_ual(addr
, rp
))
663 for (i
= 0; i
< relocs
; i
++) {
665 if (get_user_ual(relval
, reloc
+ i
* sizeof(abi_ulong
)))
667 old_reloc(&libinfo
[0], relval
);
672 memset((void *)((unsigned long)datapos
+ data_len
), 0, bss_len
);
678 /****************************************************************************/
679 #ifdef CONFIG_BINFMT_SHARED_FLAT
682 * Load a shared library into memory. The library gets its own data
683 * segment (including bss) but not argv/argc/environ.
686 static int load_flat_shared_library(int id
, struct lib_info
*libs
)
688 struct linux_binprm bprm
;
692 /* Create the file name */
693 sprintf(buf
, "/lib/lib%d.so", id
);
695 /* Open the file up */
697 bprm
.file
= open_exec(bprm
.filename
);
698 res
= PTR_ERR(bprm
.file
);
699 if (IS_ERR(bprm
.file
))
702 res
= prepare_binprm(&bprm
);
704 if (res
<= (unsigned long)-4096)
705 res
= load_flat_file(&bprm
, libs
, id
, NULL
);
707 allow_write_access(bprm
.file
);
714 #endif /* CONFIG_BINFMT_SHARED_FLAT */
716 int load_flt_binary(struct linux_binprm
* bprm
, struct target_pt_regs
* regs
,
717 struct image_info
* info
)
719 struct lib_info libinfo
[MAX_SHARED_LIBS
];
720 abi_ulong p
= bprm
->p
;
722 abi_ulong start_addr
;
727 memset(libinfo
, 0, sizeof(libinfo
));
729 * We have to add the size of our arguments to our stack size
730 * otherwise it's too easy for users to create stack overflows
731 * by passing in a huge argument list. And yes, we have to be
732 * pedantic and include space for the argv/envp array as it may have
735 #define TOP_OF_ARGS (TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(void *))
736 stack_len
= TOP_OF_ARGS
- bprm
->p
; /* the strings */
737 stack_len
+= (bprm
->argc
+ 1) * 4; /* the argv array */
738 stack_len
+= (bprm
->envc
+ 1) * 4; /* the envp array */
741 res
= load_flat_file(bprm
, libinfo
, 0, &stack_len
);
742 if (res
> (unsigned long)-4096)
745 /* Update data segment pointers for all libraries */
746 for (i
=0; i
<MAX_SHARED_LIBS
; i
++) {
747 if (libinfo
[i
].loaded
) {
749 p
= libinfo
[i
].start_data
;
750 for (j
=0; j
<MAX_SHARED_LIBS
; j
++) {
752 /* FIXME - handle put_user() failures */
753 if (put_user_ual(libinfo
[j
].loaded
754 ? libinfo
[j
].start_data
762 p
= ((libinfo
[0].start_brk
+ stack_len
+ 3) & ~3) - 4;
763 DBG_FLT("p=%x\n", (int)p
);
765 /* Copy argv/envp. */
766 p
= copy_strings(p
, bprm
->envc
, bprm
->envp
);
767 p
= copy_strings(p
, bprm
->argc
, bprm
->argv
);
769 sp
= p
& ~(abi_ulong
)(sizeof(abi_ulong
) - 1);
770 /* Enforce final stack alignment of 16 bytes. This is sufficient
771 for all current targets, and excess alignment is harmless. */
772 stack_len
= bprm
->envc
+ bprm
->argc
+ 2;
773 stack_len
+= 3; /* argc, arvg, argp */
774 stack_len
*= sizeof(abi_ulong
);
775 if ((sp
+ stack_len
) & 15)
776 sp
-= 16 - ((sp
+ stack_len
) & 15);
777 sp
= loader_build_argptr(bprm
->envc
, bprm
->argc
, sp
, p
, 1);
779 /* Fake some return addresses to ensure the call chain will
780 * initialise library in order for us. We are required to call
781 * lib 1 first, then 2, ... and finally the main program (id 0).
783 start_addr
= libinfo
[0].entry
;
785 #ifdef CONFIG_BINFMT_SHARED_FLAT
787 for (i
= MAX_SHARED_LIBS
-1; i
>0; i
--) {
788 if (libinfo
[i
].loaded
) {
789 /* Push previos first to call address */
791 if (put_user_ual(start_addr
, sp
))
793 start_addr
= libinfo
[i
].entry
;
798 /* Stash our initial stack pointer into the mm structure */
799 info
->start_code
= libinfo
[0].start_code
;
800 info
->end_code
= libinfo
[0].start_code
= libinfo
[0].text_len
;
801 info
->start_data
= libinfo
[0].start_data
;
802 info
->end_data
= libinfo
[0].end_data
;
803 info
->start_brk
= libinfo
[0].start_brk
;
804 info
->start_stack
= sp
;
805 info
->stack_limit
= libinfo
[0].start_brk
;
806 info
->entry
= start_addr
;
807 info
->code_offset
= info
->start_code
;
808 info
->data_offset
= info
->start_data
- libinfo
[0].text_len
;
810 DBG_FLT("start_thread(entry=0x%x, start_stack=0x%x)\n",
811 (int)info
->entry
, (int)info
->start_stack
);