1e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu/*
2e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * Copyright (C) 2013 The Android Open Source Project
3e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * All rights reserved.
4e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu *
5e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * Redistribution and use in source and binary forms, with or without
6e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * modification, are permitted provided that the following conditions
7e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * are met:
8e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu *  * Redistributions of source code must retain the above copyright
9e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu *    notice, this list of conditions and the following disclaimer.
10e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu *  * Redistributions in binary form must reproduce the above copyright
11e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu *    notice, this list of conditions and the following disclaimer in
12e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu *    the documentation and/or other materials provided with the
13e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu *    distribution.
14e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu *
15e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * SUCH DAMAGE.
27e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu */
28e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu
29e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu#include "../../bionic/libc_init_common.h"
30e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu#include <stddef.h>
31e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu#include <stdint.h>
32e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu
33e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu__attribute__ ((section (".preinit_array")))
34e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescuvoid (*__PREINIT_ARRAY__)(void) = (void (*)(void)) -1;
35e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu
36e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu__attribute__ ((section (".init_array")))
37e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescuvoid (*__INIT_ARRAY__)(void) = (void (*)(void)) -1;
38e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu
39e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu__attribute__ ((section (".fini_array")))
40e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescuvoid (*__FINI_ARRAY__)(void) = (void (*)(void)) -1;
41e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu
42e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu
43d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross__LIBC_HIDDEN__ void do_arm64_start(void* raw_args) {
44e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu  structors_array_t array;
45e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu  array.preinit_array = &__PREINIT_ARRAY__;
46e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu  array.init_array = &__INIT_ARRAY__;
47e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu  array.fini_array = &__FINI_ARRAY__;
48e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu  __libc_init(raw_args, NULL, &main, &array);
49e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu}
50e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu
51e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu/*
52d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross * Put the value of sp in x0 and call do_arm64_init(). The latter will then
53e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * then be able to access the stack as prepared by the kernel's execve system
54e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu * call (via the first argument).
55e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu */
56e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu__asm__ (
57e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu"        .text                      \n"
58e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu"        .align  2                  \n"
59e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu"        .global _start             \n"
60e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu"        .hidden _start             \n"
61e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu"        .type   _start, %function  \n"
62e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu"_start:                            \n"
63e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu"        add     x0, sp, xzr        \n"
64d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross"        b       do_arm64_start   \n"
65e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu"        .size   _start, .-_start   \n"
66e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu);
67e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu
68e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu#include "../../arch-common/bionic/__dso_handle.h"
69e210488e0d4082b9a0c55195c22191f29ed56bf8Serban Constantinescu#include "../../arch-common/bionic/atexit.h"
70