1995-05-11 01:02:23 +00:00
|
|
|
/* Initialization code run first thing by the ELF startup code. For i386/Hurd.
|
2019-01-01 00:11:28 +00:00
|
|
|
Copyright (C) 1995-2019 Free Software Foundation, Inc.
|
1997-02-10 03:19:57 +00:00
|
|
|
This file is part of the GNU C Library.
|
1995-05-11 01:02:23 +00:00
|
|
|
|
1997-02-10 03:19:57 +00:00
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1995-05-11 01:02:23 +00:00
|
|
|
|
1997-02-10 03:19:57 +00:00
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1995-05-11 01:02:23 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
1995-05-11 01:02:23 +00:00
|
|
|
|
2001-03-24 14:36:00 +00:00
|
|
|
#include <assert.h>
|
2012-04-02 20:26:43 +00:00
|
|
|
#include <ctype.h>
|
1995-05-11 01:02:23 +00:00
|
|
|
#include <hurd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
1995-05-20 00:13:43 +00:00
|
|
|
#include <string.h>
|
1998-06-25 19:44:22 +00:00
|
|
|
#include <sysdep.h>
|
|
|
|
#include <set-hooks.h>
|
1995-05-11 01:02:23 +00:00
|
|
|
#include "hurdstartup.h"
|
|
|
|
#include "hurdmalloc.h" /* XXX */
|
2002-08-30 01:51:11 +00:00
|
|
|
#include "../locale/localeinfo.h"
|
1995-05-11 01:02:23 +00:00
|
|
|
|
2002-11-26 01:56:30 +00:00
|
|
|
#include <ldsodefs.h>
|
|
|
|
#include <fpu_control.h>
|
|
|
|
|
1995-05-11 01:02:23 +00:00
|
|
|
extern void __mach_init (void);
|
2002-02-23 08:47:54 +00:00
|
|
|
extern void __init_misc (int, char **, char **);
|
1995-09-21 06:24:21 +00:00
|
|
|
extern void __libc_global_ctors (void);
|
1995-05-11 01:02:23 +00:00
|
|
|
|
1997-02-23 22:09:31 +00:00
|
|
|
unsigned long int __hurd_threadvar_stack_offset;
|
|
|
|
unsigned long int __hurd_threadvar_stack_mask;
|
|
|
|
|
2000-04-02 22:01:23 +00:00
|
|
|
#ifndef SHARED
|
1998-10-18 21:22:08 +00:00
|
|
|
int __libc_enable_secure;
|
1998-10-24 Mark Kettenis <kettenis@phys.uva.nl>
* mach/Versions: Add evc_wait, mach_error, mach_error_string,
mach_error_type, mach_msg_destroy, mig_deallocate_reply_port.
Remove __mach_host_self, __mach_reply_port, __mach_setup_thread,
__mach_port_allocate, __mach_port_allocate_name,
__mach_port_deallocate, __mach_port_insert_right, __mutex_init,
__mutex_trylock, __mutex_lock, __mutex_unlock, __swtch, __switch,
__task_create, __task_suspend, __task_set_special_port,
__task_terminate, __thread_depress_abort, __thread_switch,
__vm_allocate, __vm_deallocate, __vm_map. These functions are not
used outside libc.
* sysdeps/mach/hurd/Versions: New file.
[libc, GLIBC_2.0]: Add _cthread_exit_routine and
_cthread_init_routine. These are set by the Hurd cthreads library.
Add __getcwd, __mmap. If we don't add these, the weak definitions in
the dynamic linker will not be replaced by the corresponding shared
library routines once they are loaded.
1998-10-21 Mark Kettenis <kettenis@phys.uva.nl>
* sysdeps/mach/hurd/i386/init-first.c: Only define
__libc_enable_secure if PIC is not defined.
1998-10-25 Roland McGrath <roland@baalperazim.frob.com>
* argp/Versions: Add _argp_unlock_xxx. Lock-savvy functions call this
to recurse into argp.
1998-10-25 20:09:00 +00:00
|
|
|
#endif
|
Update.
* ctype/ctype-info.c: Declare _nl_C_LC_CTYPE_class,
_nl_C_LC_CTYPE_class32, _nl_C_LC_CTYPE_toupper, _nl_C_LC_CTYPE_tolower,
_nl_C_LC_CTYPE_class_upper, _nl_C_LC_CTYPE_class_lower,
_nl_C_LC_CTYPE_class_alpha, _nl_C_LC_CTYPE_class_digit,
_nl_C_LC_CTYPE_class_xdigit, _nl_C_LC_CTYPE_class_space,
_nl_C_LC_CTYPE_class_print, _nl_C_LC_CTYPE_class_graph,
_nl_C_LC_CTYPE_class_blank, _nl_C_LC_CTYPE_class_cntrl,
_nl_C_LC_CTYPE_class_punct, _nl_C_LC_CTYPE_class_alnum,
_nl_C_LC_CTYPE_map_toupper, _nl_C_LC_CTYPE_map_tolower, and
_nl_C_LC_CTYPE_width: Declare as hidden.
* include/locale.h: Declare _nl_locale_file_list.
* locale/C-address.c: Define _nl_C_LC_ADDRESS as hidden.
* locale/C-collate.c: Define _nl_C_LC_COLLATE as hidden.
* locale/C-identification.c: Define _nl_C_LC_IDENTIFICATION as hidden.
* locale/C-measurement.c: Define _nl_C_LC_MEASUREMENT as hidden.
* locale/C-messages.c: Define _nl_C_LC_MESSAGES as hidden.
* locale/C-monetary.c: Define _nl_C_LC_MONETARY as hidden.
* locale/C-name.c: Define _nl_C_LC_NAME as hidden.
* locale/C-numeric.c: Define _nl_C_LC_NUMERIC as hidden.
* locale/C-paper.c: Define _nl_C_LC_PAPER as hidden.
* locale/C-telephone.c: Define _nl_C_LC_TELEPHONE as hidden.
* locale/C-time.c: Define _nl_C_LC_TIME as hidden.
* locale/C-ctype.c: Define _nl_C_LC_CTYPE_class,
_nl_C_LC_CTYPE_class32, _nl_C_LC_CTYPE_toupper, _nl_C_LC_CTYPE_tolower,
_nl_C_LC_CTYPE_class_upper, _nl_C_LC_CTYPE_class_lower,
_nl_C_LC_CTYPE_class_alpha, _nl_C_LC_CTYPE_class_digit,
_nl_C_LC_CTYPE_class_xdigit, _nl_C_LC_CTYPE_class_space,
_nl_C_LC_CTYPE_class_print, _nl_C_LC_CTYPE_class_graph,
_nl_C_LC_CTYPE_class_blank, _nl_C_LC_CTYPE_class_cntrl,
_nl_C_LC_CTYPE_class_punct, _nl_C_LC_CTYPE_class_alnum,
_nl_C_LC_CTYPE_map_toupper, _nl_C_LC_CTYPE_map_tolower,
_nl_C_LC_CTYPE_width, and as hidden.
* locale/findlocale.c: Declare _nl_C as hidden.
* locale/newlocale.c: Likewise.
* locale/setlocale.c: Define _nl_C as hidden. Remove declaration of
_nl_locale_file_list.
* locale/xlocale.c: Declare _nl_C_LC_CTYPE_class,
_nl_C_LC_CTYPE_toupper, and _nl_C_LC_CTYPE_tolower as hidden.
Define _nl_C_locobj as hidden.
* malloc/mtrace.c (_mtrace_file): Define as hidden.
(_mtrace_line): Likewise.
* include/time.h: Declare __mon_yday as hidden.
* time/strptime.c [_LIBC] (__mon_yday): Remove declaration.
* libio/libioP.h: Declare __libio_codecvt as hidden.
* libio/fileops.c: Declare __libio_translit as hidden.
* libio/iofwide.c: Define __libio_translit as hidden.
* login/getutent_r.c: Define __libc_utmp_lock as hidden.
* login/getutid_r.c: Declare __libc_utmp_lock as hidden.
* login/getutline_r.c: Likewise.
* login/utmpname.c: Likewise.
* login/utmp-private.h: Declare __libc_utmp_file_functions,
__libc_utmp_unknown_functions, __libc_utmp_jump_table, and
__libc_utmp_file_name as hidden.
* locale/setlocale.c (__libc_setlocale_lock): Define as hidden.
* locale/duplocale.c (__libc_setlocale_lock): Declare as hidden.
* locale/freelocale.c: Likewise.
* locale/lc-time.c: Likewise.
* sysdeps/unix/bsd/getpt.c (__libc_ptyname1): Define as hidden.
(__libc_ptyname2): Likewise.
* sysdeps/unix/sysv/linux/ptsname.c (__libc_ptyname1): Declare as
hidden.
(__libc_ptyname2): Likewise.
* sysdeps/generic/sbrk.c: Declare __libc_multiple_libcs as hidden.
* sysdeps/arm/init-first.c (__libc_multiple_libcs): Define as hidden.
* sysdeps/generic/init-first.c: Likewise.
* sysdeps/i386/init-first.c: Likewise.
* sysdeps/mach/hurd/i386/init-first.c: Likewise.
* sysdeps/mach/hurd/mips/init-first.c: Likewise.
* sysdeps/mach/hurd/powerpc/init-first.c: Likewise.
* sysdeps/sh/init-first.c: Likewise.
* sysdeps/unix/sysv/aix/init-first.c: Likewise.
* sysdeps/unix/sysv/linux/init-first.c: Likewise.
2002-03-13 06:33:52 +00:00
|
|
|
int __libc_multiple_libcs attribute_hidden = 1;
|
1996-08-26 17:39:10 +00:00
|
|
|
|
Update.
* stdio-common/itowa-digits.c (_itowa_lower_digits): Define as hidden.
(_itowa_upper_digits): Likewise.
* libio/stdio.c (_IO_stdin, _IO_stdout, _IO_stderr): Define as hidden.
* libio/libio.h [_LIBC] (_IO_stdin, _IO_stdout, _IO_stderr): Declare
as hidden.
* libio/libioP.h: Declare _IO_file_jumps_mmap, _IO_wfile_jumps,
_IO_wfile_jumps_mmap, _IO_proc_jumps, _IO_old_proc_jumps,
_IO_str_jumps, _IO_wstr_jumps, _IO_file_jumps_internal,
_IO_wfile_jumps_internal, and _IO_list_all_internal as hidden.
* gmon/gmon.c (__bb_head): Define as hidden.
* gmon/bb_exit_func.c (__bb_head): Declare as hidden.
* argp/argp-parse.c (_argp_hang): Define as static.
* include/libc-symbols.h (_INTVARDEF): Adjust for visibility
handling in latest compilers.
* inet/in6_addr.c (in6addr_any): Use INTVARDEF not INTDEF to
define alias.
* libio/fileops.c (_IO_file_jumps): Likewise.
* libio/stdfiles.c (_IO_list_all): Likewise.
* libio/wfileops.c (_IO_wfile_jumps): Likewise.
* malloc/malloc.h: Move __libc_malloc_initialized declaration to
include/malloc.h.
* include/malloc.h: Add __libc_malloc_initialized declaration
here. Mark variable hidden.
* malloc/malloc.c: Include <malloc.h> not "malloc.h".
* elf/dl-open.c (__libc_argc): Declare as hidden.
(__libc_argv): Likewise.
* sysdeps/generic/wordexp.c (__libc_argc): Declare as hidden.
(__libc_argv): Likewise.
* sysdeps/mach/hurd/i386/init-first.c: Define __libc_argc and
__libc_argv as hidden.
* sysdeps/mach/hurd/mips/init-first.c: Likewise.
* sysdeps/mach/hurd/powerpc/init-first.c: Likewise.
* sysdeps/unix/sysv/aix/init-first.c: Likewise.
* sysdeps/unix/sysv/linux/init-first.c: Likewise.
2002-03-13 02:17:12 +00:00
|
|
|
extern int __libc_argc attribute_hidden;
|
|
|
|
extern char **__libc_argv attribute_hidden;
|
2001-03-24 14:36:00 +00:00
|
|
|
extern char **_dl_argv;
|
1996-09-06 00:08:55 +00:00
|
|
|
|
2005-10-16 09:53:04 +00:00
|
|
|
extern void *(*_cthread_init_routine) (void) __attribute__ ((weak));
|
1995-05-11 01:02:23 +00:00
|
|
|
void (*_cthread_exit_routine) (int status) __attribute__ ((__noreturn__));
|
|
|
|
|
|
|
|
/* Things that want to be run before _hurd_init or much anything else.
|
|
|
|
Importantly, these are called before anything tries to use malloc. */
|
|
|
|
DEFINE_HOOK (_hurd_preinit_hook, (void));
|
|
|
|
|
1998-10-18 22:53:04 +00:00
|
|
|
|
|
|
|
/* We call this once the Hurd magic is all set up and we are ready to be a
|
|
|
|
Posixoid program. This does the same things the generic version does. */
|
2000-04-02 22:01:23 +00:00
|
|
|
static void
|
|
|
|
posixland_init (int argc, char **argv, char **envp)
|
1998-10-18 22:53:04 +00:00
|
|
|
{
|
2002-11-22 04:23:05 +00:00
|
|
|
__libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
|
|
|
|
|
|
|
|
/* Make sure we don't initialize twice. */
|
|
|
|
if (!__libc_multiple_libcs)
|
|
|
|
{
|
|
|
|
/* Set the FPU control word to the proper default value. */
|
|
|
|
__setfpucw (__fpu_control);
|
|
|
|
}
|
2014-11-23 19:50:24 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Initialize data structures so the additional libc can do RPCs. */
|
|
|
|
__mach_init ();
|
|
|
|
}
|
2002-11-22 04:23:05 +00:00
|
|
|
|
|
|
|
/* Save the command-line arguments. */
|
2000-04-03 17:13:21 +00:00
|
|
|
__libc_argc = argc;
|
|
|
|
__libc_argv = argv;
|
|
|
|
__environ = envp;
|
|
|
|
|
2002-02-24 08:34:04 +00:00
|
|
|
#ifndef SHARED
|
|
|
|
_dl_non_dynamic_init ();
|
|
|
|
#endif
|
2002-02-23 08:47:54 +00:00
|
|
|
__init_misc (argc, argv, envp);
|
1998-10-18 22:53:04 +00:00
|
|
|
|
2012-04-02 20:26:43 +00:00
|
|
|
/* Initialize ctype data. */
|
|
|
|
__ctype_init ();
|
|
|
|
|
2010-12-25 01:14:37 +00:00
|
|
|
#if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
|
1998-10-18 22:53:04 +00:00
|
|
|
__libc_global_ctors ();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-05-11 01:02:23 +00:00
|
|
|
static void
|
|
|
|
init1 (int argc, char *arg0, ...)
|
|
|
|
{
|
|
|
|
char **argv = &arg0;
|
|
|
|
char **envp = &argv[argc + 1];
|
|
|
|
struct hurd_startup_data *d;
|
|
|
|
|
|
|
|
while (*envp)
|
|
|
|
++envp;
|
|
|
|
d = (void *) ++envp;
|
|
|
|
|
2018-03-17 00:28:41 +00:00
|
|
|
/* Initialize libpthread if linked in. */
|
|
|
|
if (__pthread_initialize_minimal != NULL)
|
|
|
|
__pthread_initialize_minimal ();
|
|
|
|
|
|
|
|
if ((void *) d == argv[0])
|
|
|
|
/* No Hurd data block to process. */
|
|
|
|
return;
|
|
|
|
|
2018-07-31 20:33:05 +00:00
|
|
|
#ifndef SHARED
|
|
|
|
__libc_enable_secure = d->flags & EXEC_SECURE;
|
|
|
|
#endif
|
|
|
|
|
2004-09-11 23:52:43 +00:00
|
|
|
_hurd_init_dtable = d->dtable;
|
|
|
|
_hurd_init_dtablesize = d->dtablesize;
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Check if the stack we are now on is different from
|
|
|
|
the one described by _hurd_stack_{base,size}. */
|
|
|
|
|
|
|
|
char dummy;
|
|
|
|
const vm_address_t newsp = (vm_address_t) &dummy;
|
|
|
|
|
|
|
|
if (d->stack_size != 0 && (newsp < d->stack_base ||
|
|
|
|
newsp - d->stack_base > d->stack_size))
|
|
|
|
/* The new stack pointer does not intersect with the
|
|
|
|
stack the exec server set up for us, so free that stack. */
|
|
|
|
__vm_deallocate (__mach_task_self (), d->stack_base, d->stack_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->portarray || d->intarray)
|
1995-05-11 01:02:23 +00:00
|
|
|
/* Initialize library data structures, start signal processing, etc. */
|
|
|
|
_hurd_init (d->flags, argv,
|
|
|
|
d->portarray, d->portarraysize,
|
|
|
|
d->intarray, d->intarraysize);
|
|
|
|
}
|
|
|
|
|
1998-10-18 22:53:04 +00:00
|
|
|
|
1998-11-25 12:55:38 +00:00
|
|
|
static inline void
|
|
|
|
init (int *data)
|
|
|
|
{
|
|
|
|
int argc = *data;
|
|
|
|
char **argv = (void *) (data + 1);
|
|
|
|
char **envp = &argv[argc + 1];
|
|
|
|
struct hurd_startup_data *d;
|
|
|
|
|
2001-08-20 21:44:01 +00:00
|
|
|
/* Since the cthreads initialization code uses malloc, and the
|
|
|
|
malloc initialization code needs to get at the environment, make
|
|
|
|
sure we can find it. We'll need to do this again later on since
|
|
|
|
switching stacks changes the location where the environment is
|
|
|
|
stored. */
|
|
|
|
__environ = envp;
|
|
|
|
|
1998-11-25 12:55:38 +00:00
|
|
|
while (*envp)
|
|
|
|
++envp;
|
|
|
|
d = (void *) ++envp;
|
|
|
|
|
2018-07-31 20:33:05 +00:00
|
|
|
#ifndef SHARED
|
|
|
|
/* If we are the bootstrap task started by the kernel,
|
|
|
|
then after the environment pointers there is no Hurd
|
|
|
|
data block; the argument strings start there. */
|
|
|
|
if ((void *) d == argv[0] || d->phdr == 0)
|
|
|
|
{
|
|
|
|
/* With a new enough linker (binutils-2.23 or better),
|
|
|
|
the magic __ehdr_start symbol will be available and
|
|
|
|
__libc_start_main will have done this that way already. */
|
|
|
|
if (_dl_phdr == NULL)
|
|
|
|
{
|
|
|
|
/* We may need to see our own phdrs, e.g. for TLS setup.
|
|
|
|
Try the usual kludge to find the headers without help from
|
|
|
|
the exec server. */
|
|
|
|
extern const void __executable_start;
|
|
|
|
const ElfW(Ehdr) *const ehdr = &__executable_start;
|
|
|
|
_dl_phdr = (const void *) ehdr + ehdr->e_phoff;
|
|
|
|
_dl_phnum = ehdr->e_phnum;
|
|
|
|
assert (ehdr->e_phentsize == sizeof (ElfW(Phdr)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_dl_phdr = (ElfW(Phdr) *) d->phdr;
|
|
|
|
_dl_phnum = d->phdrsz / sizeof (ElfW(Phdr));
|
|
|
|
assert (d->phdrsz % sizeof (ElfW(Phdr)) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We need to setup TLS before initializing libpthread. */
|
|
|
|
__libc_setup_tls ();
|
|
|
|
#endif
|
1998-11-25 12:55:38 +00:00
|
|
|
|
|
|
|
/* After possibly switching stacks, call `init1' (above) with the user
|
|
|
|
code as the return address, and the argument data immediately above
|
|
|
|
that on the stack. */
|
|
|
|
|
2005-10-16 09:53:04 +00:00
|
|
|
if (&_cthread_init_routine && _cthread_init_routine)
|
1998-11-25 12:55:38 +00:00
|
|
|
{
|
|
|
|
/* Initialize cthreads, which will allocate us a new stack to run on. */
|
2004-09-01 02:00:03 +00:00
|
|
|
int *newsp = (*_cthread_init_routine) ();
|
1998-11-25 12:55:38 +00:00
|
|
|
struct hurd_startup_data *od;
|
|
|
|
|
1999-07-28 18:19:47 +00:00
|
|
|
void switch_stacks (void);
|
|
|
|
|
2012-05-10 21:51:22 +00:00
|
|
|
__libc_stack_end = newsp;
|
|
|
|
|
1998-11-25 12:55:38 +00:00
|
|
|
/* Copy the argdata from the old stack to the new one. */
|
|
|
|
newsp = memcpy (newsp - ((char *) &d[1] - (char *) data), data,
|
|
|
|
(char *) d - (char *) data);
|
|
|
|
|
2001-03-24 14:36:00 +00:00
|
|
|
#ifdef SHARED
|
|
|
|
/* And readjust the dynamic linker's idea of where the argument
|
2012-05-10 20:20:47 +00:00
|
|
|
vector lives. */
|
2001-03-24 14:36:00 +00:00
|
|
|
assert (_dl_argv == argv);
|
2004-09-01 02:00:03 +00:00
|
|
|
_dl_argv = (void *) (newsp + 1);
|
2001-03-24 14:36:00 +00:00
|
|
|
#endif
|
|
|
|
|
1998-11-25 12:55:38 +00:00
|
|
|
/* Set up the Hurd startup data block immediately following
|
|
|
|
the argument and environment pointers on the new stack. */
|
2004-09-01 02:00:03 +00:00
|
|
|
od = ((void *) newsp + ((char *) d - (char *) data));
|
1998-11-25 12:55:38 +00:00
|
|
|
if ((void *) argv[0] == d)
|
|
|
|
/* We were started up by the kernel with arguments on the stack.
|
|
|
|
There is no Hurd startup data, so zero the block. */
|
|
|
|
memset (od, 0, sizeof *od);
|
|
|
|
else
|
|
|
|
/* Copy the Hurd startup data block to the new stack. */
|
|
|
|
*od = *d;
|
|
|
|
|
|
|
|
/* Push the user code address on the top of the new stack. It will
|
|
|
|
be the return address for `init1'; we will jump there with NEWSP
|
|
|
|
as the stack pointer. */
|
2012-05-10 20:20:47 +00:00
|
|
|
/* The following expression would typically be written as
|
|
|
|
``__builtin_return_address (0)''. But, for example, GCC 4.4.6 doesn't
|
|
|
|
recognize that this read operation may alias the following write
|
|
|
|
operation, and thus is free to reorder the two, clobbering the
|
|
|
|
original return address. */
|
|
|
|
*--newsp = *((int *) __builtin_frame_address (0) + 1);
|
|
|
|
/* GCC 4.4.6 also wants us to force loading *NEWSP already here. */
|
|
|
|
asm volatile ("# %0" : : "X" (*newsp));
|
|
|
|
*((void **) __builtin_frame_address (0) + 1) = &switch_stacks;
|
|
|
|
/* Force NEWSP into %eax and &init1 into %ecx, which are not restored
|
1998-11-25 12:55:38 +00:00
|
|
|
by function return. */
|
|
|
|
asm volatile ("# a %0 c %1" : : "a" (newsp), "c" (&init1));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int usercode;
|
|
|
|
|
1999-07-28 18:19:47 +00:00
|
|
|
void call_init1 (void);
|
|
|
|
|
1998-11-25 12:55:38 +00:00
|
|
|
/* The argument data is just above the stack frame we will unwind by
|
|
|
|
returning. Mutate our own return address to run the code below. */
|
2012-05-10 20:20:47 +00:00
|
|
|
/* The following expression would typically be written as
|
|
|
|
``__builtin_return_address (0)''. But, for example, GCC 4.4.6 doesn't
|
|
|
|
recognize that this read operation may alias the following write
|
|
|
|
operation, and thus is free to reorder the two, clobbering the
|
|
|
|
original return address. */
|
|
|
|
usercode = *((int *) __builtin_frame_address (0) + 1);
|
|
|
|
/* GCC 4.4.6 also wants us to force loading USERCODE already here. */
|
|
|
|
asm volatile ("# %0" : : "X" (usercode));
|
|
|
|
*((void **) __builtin_frame_address (0) + 1) = &call_init1;
|
1998-11-25 12:55:38 +00:00
|
|
|
/* Force USERCODE into %eax and &init1 into %ecx, which are not
|
|
|
|
restored by function return. */
|
|
|
|
asm volatile ("# a %0 c %1" : : "a" (usercode), "c" (&init1));
|
|
|
|
}
|
1999-07-28 18:19:47 +00:00
|
|
|
}
|
1998-11-25 12:55:38 +00:00
|
|
|
|
1999-07-28 18:19:47 +00:00
|
|
|
/* These bits of inline assembler used to be located inside `init'.
|
|
|
|
However they were optimized away by gcc 2.95. */
|
|
|
|
|
|
|
|
/* The return address of `init' above, was redirected to here, so at
|
|
|
|
this point our stack is unwound and callers' registers restored.
|
|
|
|
Only %ecx and %eax are call-clobbered and thus still have the
|
|
|
|
values we set just above. Fetch from there the new stack pointer
|
|
|
|
we will run on, and jmp to the run-time address of `init1'; when it
|
|
|
|
returns, it will run the user code with the argument data at the
|
|
|
|
top of the stack. */
|
2001-12-17 01:03:08 +00:00
|
|
|
asm ("switch_stacks:\n"
|
|
|
|
" movl %eax, %esp\n"
|
|
|
|
" jmp *%ecx");
|
1999-07-28 18:19:47 +00:00
|
|
|
|
|
|
|
/* As in the stack-switching case, at this point our stack is unwound
|
|
|
|
and callers' registers restored, and only %ecx and %eax communicate
|
|
|
|
values from the lines above. In this case we have stashed in %eax
|
|
|
|
the user code return address. Push it on the top of the stack so
|
|
|
|
it acts as init1's return address, and then jump there. */
|
2001-12-17 01:03:08 +00:00
|
|
|
asm ("call_init1:\n"
|
|
|
|
" push %eax\n"
|
|
|
|
" jmp *%ecx\n");
|
1998-11-25 12:55:38 +00:00
|
|
|
|
|
|
|
|
2000-04-02 22:01:23 +00:00
|
|
|
/* Do the first essential initializations that must precede all else. */
|
|
|
|
static inline void
|
|
|
|
first_init (void)
|
1995-05-11 01:02:23 +00:00
|
|
|
{
|
|
|
|
/* Initialize data structures so we can do RPCs. */
|
|
|
|
__mach_init ();
|
|
|
|
|
|
|
|
RUN_HOOK (_hurd_preinit_hook, ());
|
2000-04-02 22:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SHARED
|
|
|
|
/* This function is called specially by the dynamic linker to do early
|
|
|
|
initialization of the shared C library before normal initializers
|
|
|
|
expecting a Posixoid environment can run. It gets called with the
|
|
|
|
stack set up just as the user will see it, so it can switch stacks. */
|
|
|
|
|
|
|
|
void
|
2012-05-10 20:20:47 +00:00
|
|
|
_dl_init_first (int argc, ...)
|
2000-04-02 22:01:23 +00:00
|
|
|
{
|
|
|
|
first_init ();
|
1997-09-21 01:47:02 +00:00
|
|
|
|
2012-05-10 20:20:47 +00:00
|
|
|
/* If we use ``__builtin_frame_address (0) + 2'' here, GCC gets confused. */
|
|
|
|
init (&argc);
|
1998-11-22 17:32:14 +00:00
|
|
|
}
|
1998-11-25 12:55:38 +00:00
|
|
|
#endif
|
1995-05-11 01:02:23 +00:00
|
|
|
|
|
|
|
|
2000-04-02 22:01:23 +00:00
|
|
|
#ifdef SHARED
|
|
|
|
/* The regular posixland initialization is what goes into libc's
|
|
|
|
normal initializer. */
|
|
|
|
/* NOTE! The linker notices the magical name `_init' and sets the DT_INIT
|
|
|
|
pointer in the dynamic section based solely on that. It is convention
|
|
|
|
for this function to be in the `.init' section, but the symbol name is
|
|
|
|
the only thing that really matters!! */
|
|
|
|
strong_alias (posixland_init, _init);
|
|
|
|
|
1995-05-11 01:02:23 +00:00
|
|
|
void
|
1998-10-18 22:53:04 +00:00
|
|
|
__libc_init_first (int argc, char **argv, char **envp)
|
1995-05-11 01:02:23 +00:00
|
|
|
{
|
1998-10-18 22:53:04 +00:00
|
|
|
/* Everything was done in the shared library initializer, _init. */
|
|
|
|
}
|
|
|
|
#else
|
2000-04-02 22:01:23 +00:00
|
|
|
strong_alias (posixland_init, __libc_init_first);
|
|
|
|
|
1998-06-25 19:44:22 +00:00
|
|
|
|
1998-10-18 22:53:04 +00:00
|
|
|
/* XXX This is all a crock and I am not happy with it.
|
|
|
|
This poorly-named function is called by static-start.S,
|
|
|
|
which should not exist at all. */
|
1998-06-25 19:44:22 +00:00
|
|
|
void
|
2005-10-16 09:53:04 +00:00
|
|
|
_hurd_stack_setup (void)
|
1998-06-25 19:44:22 +00:00
|
|
|
{
|
2005-10-16 09:53:04 +00:00
|
|
|
intptr_t caller = (intptr_t) __builtin_return_address (0);
|
|
|
|
|
2002-08-30 01:51:11 +00:00
|
|
|
void doinit (intptr_t *data)
|
1995-05-11 01:02:23 +00:00
|
|
|
{
|
1995-07-10 09:40:15 +00:00
|
|
|
/* This function gets called with the argument data at TOS. */
|
2012-05-10 20:20:47 +00:00
|
|
|
void doinit1 (int argc, ...)
|
1998-11-25 12:55:38 +00:00
|
|
|
{
|
2012-05-10 20:20:47 +00:00
|
|
|
/* If we use ``__builtin_frame_address (0) + 2'' here, GCC gets
|
|
|
|
confused. */
|
|
|
|
init ((int *) &argc);
|
1998-11-25 12:55:38 +00:00
|
|
|
}
|
1995-07-10 09:40:15 +00:00
|
|
|
|
|
|
|
/* Push the user return address after the argument data, and then
|
2012-05-10 20:20:47 +00:00
|
|
|
jump to `doinit1' (above), so it is as if __libc_init_first's
|
|
|
|
caller had called `doinit1' with the argument data already on the
|
|
|
|
stack. */
|
2005-10-16 09:53:04 +00:00
|
|
|
*--data = caller;
|
1995-07-10 09:40:15 +00:00
|
|
|
asm volatile ("movl %0, %%esp\n" /* Switch to new outermost stack. */
|
|
|
|
"movl $0, %%ebp\n" /* Clear outermost frame pointer. */
|
2018-12-13 22:36:33 +00:00
|
|
|
"jmp *%1" : : "r" (data), "r" (&doinit1));
|
1995-07-10 09:40:15 +00:00
|
|
|
/* NOTREACHED */
|
1995-05-11 01:02:23 +00:00
|
|
|
}
|
|
|
|
|
2000-04-02 22:01:23 +00:00
|
|
|
first_init ();
|
1997-09-21 01:47:02 +00:00
|
|
|
|
2005-10-16 09:53:04 +00:00
|
|
|
_hurd_startup ((void **) __builtin_frame_address (0) + 2, &doinit);
|
1995-05-11 01:02:23 +00:00
|
|
|
}
|
1998-10-18 22:53:04 +00:00
|
|
|
#endif
|
1996-09-21 20:05:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* This function is defined here so that if this file ever gets into
|
|
|
|
ld.so we will get a link error. Having this file silently included
|
|
|
|
in ld.so causes disaster, because the _init definition above will
|
|
|
|
cause ld.so to gain an init function, which is not a cool thing. */
|
|
|
|
|
1997-09-21 01:47:02 +00:00
|
|
|
void
|
|
|
|
_dl_start (void)
|
|
|
|
{
|
|
|
|
abort ();
|
1996-09-21 20:05:50 +00:00
|
|
|
}
|