OSDN Git Service

simple optimizations and style fixes in dynamic loading
[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 #include <bits/wordsize.h>
31 /* Pull in the arch specific type information */
32 #include <sys/types.h>
33 /* Pull in the arch specific page size */
34 #include <bits/uClibc_page.h>
35 /* Pull in the ldso syscalls and string functions */
36 #include <dl-syscall.h>
37 #include <dl-string.h>
38 /* Now the ldso specific headers */
39 #include <dl-elf.h>
40 #include <dl-hash.h>
41
42 /* common align masks, if not specified by sysdep headers */
43 #ifndef ADDR_ALIGN
44 #define ADDR_ALIGN (_dl_pagesize - 1)
45 #endif
46
47 #ifndef PAGE_ALIGN
48 #define PAGE_ALIGN (~ADDR_ALIGN)
49 #endif
50
51 #ifndef OFFS_ALIGN
52 #define OFFS_ALIGN (PAGE_ALIGN & ~(1ul << (sizeof(_dl_pagesize) * 8 - 1)))
53 #endif
54
55 /* For INIT/FINI dependency sorting. */
56 struct init_fini_list {
57         struct init_fini_list *next;
58         struct elf_resolve *tpnt;
59 };
60
61 /* Global variables used within the shared library loader */
62 extern char *_dl_library_path;         /* Where we look for libraries */
63 extern char *_dl_preload;              /* Things to be loaded before the libs */
64 extern char *_dl_ldsopath;             /* Where the shared lib loader was found */
65 extern const char *_dl_progname;       /* The name of the executable being run */
66 //now static: extern int _dl_secure;                 /* Are we dealing with setuid stuff? */
67 extern size_t _dl_pagesize;            /* Store the page size for use later */
68
69 #ifdef __SUPPORT_LD_DEBUG__
70 extern char *_dl_debug;
71 extern char *_dl_debug_symbols;
72 extern char *_dl_debug_move;
73 extern char *_dl_debug_reloc;
74 extern char *_dl_debug_detail;
75 extern char *_dl_debug_nofixups;
76 extern char *_dl_debug_bindings;
77 extern int   _dl_debug_file;
78 # define __dl_debug_dprint(fmt, args...) \
79         _dl_dprintf(_dl_debug_file, "%s:%i: " fmt, __FUNCTION__, __LINE__, ## args);
80 # define _dl_if_debug_dprint(fmt, args...) \
81         do { if (_dl_debug) __dl_debug_dprint(fmt, ## args); } while (0)
82 #else
83 # define __dl_debug_dprint(fmt, args...) do {} while (0)
84 # define _dl_if_debug_dprint(fmt, args...) do {} while (0)
85 # define _dl_debug_file 2
86 #endif /* __SUPPORT_LD_DEBUG__ */
87
88 #ifdef IS_IN_rtld
89 # ifdef __SUPPORT_LD_DEBUG__
90 #  define _dl_assert(expr)                                              \
91         do {                                                            \
92                 if (!(expr)) {                                          \
93                         __dl_debug_dprint("assert(%s)\n", #expr);       \
94                         _dl_exit(45);                                   \
95                 }                                                       \
96         } while (0)
97 # else
98 #  define _dl_assert(expr) ((void)0)
99 # endif
100 #else
101 # include <assert.h>
102 # define _dl_assert(expr) assert(expr)
103 #endif
104
105 #ifdef __SUPPORT_LD_DEBUG_EARLY__
106 # define _dl_debug_early(fmt, args...) __dl_debug_dprint(fmt, ## args)
107 #else
108 # define _dl_debug_early(fmt, args...) do {} while (0)
109 #endif /* __SUPPORT_LD_DEBUG_EARLY__ */
110
111 #ifndef NULL
112 #define NULL ((void *) 0)
113 #endif
114
115 extern void *_dl_malloc(size_t size);
116 extern void _dl_free(void *);
117 extern char *_dl_getenv(const char *symbol, char **envp);
118 extern void _dl_unsetenv(const char *symbol, char **envp);
119 extern char *_dl_strdup(const char *string);
120 extern void _dl_dprintf(int, const char *, ...);
121
122 #ifndef DL_GET_READY_TO_RUN_EXTRA_PARMS
123 # define DL_GET_READY_TO_RUN_EXTRA_PARMS
124 #endif
125 #ifndef DL_GET_READY_TO_RUN_EXTRA_ARGS
126 # define DL_GET_READY_TO_RUN_EXTRA_ARGS
127 #endif
128
129 extern void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
130                 ElfW(auxv_t) auxvt[AT_EGID + 1], char **envp, char **argv
131                 DL_GET_READY_TO_RUN_EXTRA_PARMS);
132
133 #ifdef HAVE_DL_INLINES_H
134 #include <dl-inlines.h>
135 #endif
136
137 #endif /* _LDSO_H_ */