1 /* vi: set sw=4 ts=4: */
3 * This file contains the helper routines to run init and fini functions.
5 * Copyright (C) 2000-2006 by Erik Andersen <andersen@codepoet.org>
6 * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
7 * David Engel, Hongjiu Lu and Mitch D'Souza
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. The name of the above contributors may not be
15 * used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 static void _dl_run_array_forward(unsigned long array, unsigned long size,
35 DL_LOADADDR_TYPE loadaddr)
41 jm = size / sizeof (ElfW(Addr));
42 addrs = (ElfW(Addr) *) DL_RELOC_ADDR(loadaddr, array);
43 for (j = 0; j < jm; ++j) {
44 void (*dl_elf_func) (void);
45 dl_elf_func = (void (*)(void)) (intptr_t) addrs[j];
46 DL_CALL_FUNC_AT_ADDR (dl_elf_func, loadaddr, (void (*)(void)));
51 void _dl_run_init_array(struct elf_resolve *tpnt);
52 void _dl_run_init_array(struct elf_resolve *tpnt)
54 _dl_run_array_forward(tpnt->dynamic_info[DT_INIT_ARRAY],
55 tpnt->dynamic_info[DT_INIT_ARRAYSZ],
59 void _dl_app_init_array(void);
60 void _dl_app_init_array(void)
62 _dl_run_init_array(_dl_loaded_modules);
65 void _dl_run_fini_array(struct elf_resolve *tpnt);
66 void _dl_run_fini_array(struct elf_resolve *tpnt)
68 if (tpnt->dynamic_info[DT_FINI_ARRAY]) {
69 ElfW(Addr) *array = (ElfW(Addr) *) DL_RELOC_ADDR(tpnt->loadaddr, tpnt->dynamic_info[DT_FINI_ARRAY]);
70 unsigned int i = (tpnt->dynamic_info[DT_FINI_ARRAYSZ] / sizeof(ElfW(Addr)));
72 void (*dl_elf_func) (void);
73 dl_elf_func = (void (*)(void)) (intptr_t) array[i];
74 DL_CALL_FUNC_AT_ADDR (dl_elf_func, tpnt->loadaddr, (void (*)(void)));
79 void _dl_app_fini_array(void);
80 void _dl_app_fini_array(void)
82 _dl_run_fini_array(_dl_loaded_modules);