summaryrefslogtreecommitdiff
path: root/ldso/include/ldso.h
blob: 029922747950e0533055b9825008655f7af8937b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* vi: set sw=4 ts=4: */
/*
 * Copyright (C) 2000-2005 by Erik Andersen <andersen@codepoet.org>
 *
 * GNU Lesser General Public License version 2.1 or later.
 */

#ifndef _LDSO_H_
#define _LDSO_H_

#include <features.h>

/* Prepare for the case that `__builtin_expect' is not available.  */
#if defined __GNUC__ && __GNUC__ == 2 && __GNUC_MINOR__ < 96
#define __builtin_expect(x, expected_value) (x)
#endif
#ifndef likely
# define likely(x)	__builtin_expect((!!(x)),1)
#endif
#ifndef unlikely
# define unlikely(x)	__builtin_expect((!!(x)),0)
#endif
#ifndef __LINUX_COMPILER_H
#define __LINUX_COMPILER_H
#endif

/* Pull in compiler and arch stuff */
#include <stdlib.h>
#include <stdarg.h>
#include <bits/wordsize.h>
/* Pull in the arch specific type information */
#include <sys/types.h>
/* Pull in the arch specific page size */
#include <bits/uClibc_page.h>
/* Pull in the ldso syscalls and string functions */
#include <dl-syscall.h>
#include <dl-string.h>
/* Now the ldso specific headers */
#include <dl-elf.h>
#include <dl-hash.h>

/* For INIT/FINI dependency sorting. */
struct init_fini_list {
	struct init_fini_list *next;
	struct elf_resolve *tpnt;
};

/* Global variables used within the shared library loader */
extern char *_dl_library_path;         /* Where we look for libraries */
extern char *_dl_preload;              /* Things to be loaded before the libs */
extern char *_dl_ldsopath;             /* Where the shared lib loader was found */
extern const char *_dl_progname;       /* The name of the executable being run */
extern int _dl_secure;                 /* Are we dealing with setuid stuff? */
extern size_t _dl_pagesize;            /* Store the page size for use later */

#ifdef __SUPPORT_LD_DEBUG__
extern char *_dl_debug;
extern char *_dl_debug_symbols;
extern char *_dl_debug_move;
extern char *_dl_debug_reloc;
extern char *_dl_debug_detail;
extern char *_dl_debug_nofixups;
extern char *_dl_debug_bindings;
extern int   _dl_debug_file;
# define __dl_debug_dprint(fmt, args...) \
	_dl_dprintf(_dl_debug_file, "%s:%i: " fmt, __FUNCTION__, __LINE__, ## args);
# define _dl_if_debug_dprint(fmt, args...) \
	do { if (_dl_debug) __dl_debug_dprint(fmt, ## args); } while (0)	
#else
# define __dl_debug_dprint(fmt, args...)
# define _dl_if_debug_dprint(fmt, args...)
# define _dl_debug_file 2
#endif /* __SUPPORT_LD_DEBUG__ */

#ifdef IS_IN_rtld
# ifdef __SUPPORT_LD_DEBUG__
#  define _dl_assert(expr)						\
	do {								\
		if (!(expr)) {						\
			__dl_debug_dprint("assert(%s)\n", #expr);	\
			_dl_exit(45);					\
		}							\
	} while (0)
# else
#  define _dl_assert(expr) ((void)0)
# endif
#else
# include <assert.h>
# define _dl_assert(expr) assert(expr)
#endif

#ifdef __SUPPORT_LD_DEBUG_EARLY__
# define _dl_debug_early(fmt, args...) __dl_debug_dprint(fmt, ## args)
#else
# define _dl_debug_early(fmt, args...)
#endif /* __SUPPORT_LD_DEBUG_EARLY__ */

#ifndef NULL
#define NULL ((void *) 0)
#endif

extern void *_dl_malloc(size_t size);
extern void _dl_free(void *);
extern char *_dl_getenv(const char *symbol, char **envp);
extern void _dl_unsetenv(const char *symbol, char **envp);
extern char *_dl_strdup(const char *string);
extern void _dl_dprintf(int, const char *, ...);

#ifndef DL_GET_READY_TO_RUN_EXTRA_PARMS
# define DL_GET_READY_TO_RUN_EXTRA_PARMS
#endif
#ifndef DL_GET_READY_TO_RUN_EXTRA_ARGS
# define DL_GET_READY_TO_RUN_EXTRA_ARGS
#endif

extern void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
		ElfW(auxv_t) auxvt[AT_EGID + 1], char **envp, char **argv
		DL_GET_READY_TO_RUN_EXTRA_PARMS);

#ifdef HAVE_DL_INLINES_H
#include <dl-inlines.h>
#endif

#endif /* _LDSO_H_ */