]> sourceware.org Git - glibc.git/blob - sysdeps/unix/sysv/linux/init-first.c
ae163bcd493aefbc49043ee6523fb4cb747abd8e
[glibc.git] / sysdeps / unix / sysv / linux / init-first.c
1 /* Initialization code run first thing by the ELF startup code. Linux version.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library 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 GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
19
20 #include <unistd.h>
21 #include <sysdep.h>
22 #include <fpu_control.h>
23 #include <linux/personality.h>
24 #include "init-first.h"
25
26 extern void __libc_init (int, char **, char **);
27 extern void __libc_global_ctors (void);
28
29 /* The function is called from assembly stubs the compiler can't see. */
30 static void init (void *) __attribute__ ((unused));
31
32 extern int _dl_starting_up;
33 weak_extern (_dl_starting_up)
34
35 /* Set nonzero if we have to be prepared for more then one libc being
36 used in the process. Safe assumption if initializer never runs. */
37 int __libc_multiple_libcs = 1;
38
39 /* Remember the command line argument and enviroment contents for
40 later calls of initializers for dynamic libraries. */
41 int __libc_argc;
42 char **__libc_argv;
43 char **__libc_envp;
44
45
46 static void
47 init (void *data)
48 {
49 extern int __personality (int);
50
51 __libc_multiple_libcs = &_dl_starting_up && ! _dl_starting_up;
52
53
54 /* We must not call `personality' twice. */
55 if (!__libc_multiple_libcs)
56 {
57 /* The argument we got points to the values describing the
58 command line argument etc. */
59 __libc_argc = *(int *)data;
60 __libc_argv = (char **)data + 1;
61 __libc_envp = &__libc_argv[__libc_argc + 1];
62
63 /* The `personality' system call takes one argument that chooses
64 the "personality", i.e. the set of system calls and such. We
65 must make this call first thing to disable emulation of some
66 other system that might have been enabled by default based on
67 the executable format. */
68 __personality (PER_LINUX);
69
70 /* Set the FPU control word to the proper default value. */
71 __setfpucw (__fpu_control);
72 }
73 else
74 {
75 /* The argument we got points to the values describing the
76 command line argument etc. */
77 __libc_argc = *((int *)data)++;
78 __libc_argv = *((char ***)data)++;
79 __libc_envp = *(char ***)data;
80 }
81
82 __environ = __libc_envp;
83 __libc_init (__libc_argc, __libc_argv, __libc_envp);
84
85 #ifdef PIC
86 __libc_global_ctors ();
87 #endif
88 }
89
90 #ifdef PIC
91
92 SYSDEP_CALL_INIT(_init, init);
93
94 void
95 __libc_init_first (void)
96 {
97 }
98
99 #else
100
101 SYSDEP_CALL_INIT(__libc_init_first, init);
102
103 #endif
This page took 0.042905 seconds and 5 git commands to generate.