OSDN Git Service

Merge commit 'origin/master' into nptl
[uclinux-h8/uClibc.git] / ldso / include / ldso.h
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Copyright (C) 2000-2005 by Erik Andersen <andersen@codepoet.org>
4  *
5  * GNU Lesser General Public License version 2.1 or later.
6  */
7
8 #ifndef _LDSO_H_
9 #define _LDSO_H_
10
11 #include <features.h>
12
13 /* Prepare for the case that `__builtin_expect' is not available.  */
14 #if defined __GNUC__ && __GNUC__ == 2 && __GNUC_MINOR__ < 96
15 #define __builtin_expect(x, expected_value) (x)
16 #endif
17 #ifndef likely
18 # define likely(x)      __builtin_expect((!!(x)),1)
19 #endif
20 #ifndef unlikely
21 # define unlikely(x)    __builtin_expect((!!(x)),0)
22 #endif
23 #ifndef __LINUX_COMPILER_H
24 #define __LINUX_COMPILER_H
25 #endif
26
27 /* Pull in compiler and arch stuff */
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #define _FCNTL_H
31 #include <bits/fcntl.h>
32 #include <bits/wordsize.h>
33 /* Pull in the arch specific type information */
34 #include <sys/types.h>
35 /* Pull in the arch specific page size */
36 #include <bits/uClibc_page.h>
37 /* Pull in the ldso syscalls and string functions */
38 #ifndef __ARCH_HAS_NO_SHARED__
39 #include <dl-syscall.h>
40 #include <dl-string.h>
41 /* Now the ldso specific headers */
42 #include <dl-elf.h>
43 #ifdef __UCLIBC_HAS_TLS__
44 /* Defines USE_TLS */
45 #include <tls.h>
46 #endif
47 #include <dl-hash.h>
48
49 /* common align masks, if not specified by sysdep headers */
50 #ifndef ADDR_ALIGN
51 #define ADDR_ALIGN (_dl_pagesize - 1)
52 #endif
53
54 #ifndef PAGE_ALIGN
55 #define PAGE_ALIGN (~ADDR_ALIGN)
56 #endif
57
58 #ifndef OFFS_ALIGN
59 #define OFFS_ALIGN (PAGE_ALIGN & ~(1ul << (sizeof(_dl_pagesize) * 8 - 1)))
60 #endif
61
62 /* For INIT/FINI dependency sorting. */
63 struct init_fini_list {
64         struct init_fini_list *next;
65         struct elf_resolve *tpnt;
66 };
67
68 /* Global variables used within the shared library loader */
69 extern char *_dl_library_path;         /* Where we look for libraries */
70 extern char *_dl_preload;              /* Things to be loaded before the libs */
71 extern char *_dl_ldsopath;             /* Where the shared lib loader was found */
72 extern const char *_dl_progname;       /* The name of the executable being run */
73 extern size_t _dl_pagesize;            /* Store the page size for use later */
74
75 #if defined(USE_TLS) && USE_TLS
76 extern void _dl_add_to_slotinfo (struct link_map  *l);
77 extern void ** __attribute__ ((const)) _dl_initial_error_catch_tsd (void);
78 #endif
79
80 #ifdef __SUPPORT_LD_DEBUG__
81 extern char *_dl_debug;
82 extern char *_dl_debug_symbols;
83 extern char *_dl_debug_move;
84 extern char *_dl_debug_reloc;
85 extern char *_dl_debug_detail;
86 extern char *_dl_debug_nofixups;
87 extern char *_dl_debug_bindings;
88 extern int   _dl_debug_file;
89 # define __dl_debug_dprint(fmt, args...) \
90         _dl_dprintf(_dl_debug_file, "%s:%i: " fmt, __FUNCTION__, __LINE__, ## args);
91 # define _dl_if_debug_dprint(fmt, args...) \
92         do { if (_dl_debug) __dl_debug_dprint(fmt, ## args); } while (0)
93 #else
94 # define __dl_debug_dprint(fmt, args...) do {} while (0)
95 # define _dl_if_debug_dprint(fmt, args...) do {} while (0)
96 # define _dl_debug_file 2
97 #endif /* __SUPPORT_LD_DEBUG__ */
98
99 #ifdef IS_IN_rtld
100 # ifdef __SUPPORT_LD_DEBUG__
101 #  define _dl_assert(expr)                                              \
102         do {                                                            \
103                 if (!(expr)) {                                          \
104                         __dl_debug_dprint("assert(%s)\n", #expr);       \
105                         _dl_exit(45);                                   \
106                 }                                                       \
107         } while (0)
108 # else
109 #  define _dl_assert(expr) ((void)0)
110 # endif
111 #else
112 # include <assert.h>
113 # define _dl_assert(expr) assert(expr)
114 #endif
115
116 #ifdef __SUPPORT_LD_DEBUG_EARLY__
117 # define _dl_debug_early(fmt, args...) __dl_debug_dprint(fmt, ## args)
118 #else
119 # define _dl_debug_early(fmt, args...) do {} while (0)
120 #endif /* __SUPPORT_LD_DEBUG_EARLY__ */
121
122 #ifndef NULL
123 #define NULL ((void *) 0)
124 #endif
125
126 extern void *_dl_malloc(size_t size);
127 extern void *_dl_calloc(size_t __nmemb, size_t __size);
128 extern void *_dl_realloc(void *__ptr, size_t __size);
129 extern void _dl_free(void *);
130 extern char *_dl_getenv(const char *symbol, char **envp);
131 extern void _dl_unsetenv(const char *symbol, char **envp);
132 extern char *_dl_strdup(const char *string);
133 extern void _dl_dprintf(int, const char *, ...);
134
135 #ifndef DL_GET_READY_TO_RUN_EXTRA_PARMS
136 # define DL_GET_READY_TO_RUN_EXTRA_PARMS
137 #endif
138 #ifndef DL_GET_READY_TO_RUN_EXTRA_ARGS
139 # define DL_GET_READY_TO_RUN_EXTRA_ARGS
140 #endif
141
142 extern void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
143                 ElfW(auxv_t) auxvt[AT_EGID + 1], char **envp, char **argv
144                 DL_GET_READY_TO_RUN_EXTRA_PARMS);
145
146 #ifdef HAVE_DL_INLINES_H
147 #include <dl-inlines.h>
148 #endif
149
150 #else /* __ARCH_HAS_NO_SHARED__ */
151 #include <dl-defs.h>
152 #endif
153
154 #endif /* _LDSO_H_ */