blob: d7af640886890b555d05c93541a9c4bc816b5ab7 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
David 'Digit' Turner03eabfe2009-05-28 15:54:03 +020028
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029/*
30 * libc_init_static.c
31 *
David 'Digit' Turner03eabfe2009-05-28 15:54:03 +020032 * This function is called for static executables, i.e. those that
33 * dont depend on shared libraries and are directly started by the
34 * Linux kernel.
35 *
36 * It takes the raw data block set up by the ELF loader
37 * in the kernel and parses it.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080038 *
39 * The arguments are:
David 'Digit' Turner03eabfe2009-05-28 15:54:03 +020040 * elfdata -- The ELF loader data block; usually from the stack.
41 * Basically a pointer to argc.
42 *
43 * onexit -- Function to call on exit, can be NULL.
44 *
45 * slingshot -- Address of the program's main function
46 *
47 * structors -- Table of constructor functions arrays that must
48 * be called before the slingshot.
49 *
50 * It is called from the assembly fragment found in
51 * arch-$ARCH/bionic/crtbegin_static.S
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080052 */
53
54/*
55 * Several Linux ABIs don't pass the onexit pointer, and the ones that
56 * do never use it. Therefore, unless USE_ONEXIT is defined, we just
57 * ignore the onexit pointer.
58 */
59/* #define USE_ONEXIT */
60
61#include <stddef.h>
62#include <stdio.h>
63#include <stdlib.h>
64#include <stdint.h>
65#include <elf.h>
David 'Digit' Turner03eabfe2009-05-28 15:54:03 +020066#include "bionic_preinit.h"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080067#include "libc_init_common.h"
68
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080069__noreturn void __libc_init(uintptr_t *elfdata,
70 void (*onexit)(void),
71 int (*slingshot)(int, char**, char**),
72 structors_array_t const * const structors)
73{
David 'Digit' Turner03eabfe2009-05-28 15:54:03 +020074 pthread_internal_t thread;
75 void *tls_area[BIONIC_TLS_SLOTS];
76
77 __libc_preinit( &thread, tls_area );
78
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080079/*
80 * To enable malloc checks for statically linked programs, add
81 * "WITH_MALLOC_CHECK_LIBC_A := true" in device/buildspec.mk
82 */
83#ifdef MALLOC_LEAK_CHECK
84 extern void malloc_debug_init();
85 __libc_init_common(elfdata, onexit, slingshot, structors, malloc_debug_init);
86#else
87 __libc_init_common(elfdata, onexit, slingshot, structors, NULL);
88#endif
89}