1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef TARGET_OS_ELF_H
21#define TARGET_OS_ELF_H
22
23#include "target_arch_elf.h"
24#include "elf.h"
25
26
27#ifndef MAP_DENYWRITE
28#define MAP_DENYWRITE 0
29#endif
30
31
32#ifndef ELIBBAD
33#define ELIBBAD 80
34#endif
35
36#ifndef ELF_PLATFORM
37#define ELF_PLATFORM (NULL)
38#endif
39
40#ifndef ELF_HWCAP
41#define ELF_HWCAP 0
42#endif
43
44#ifdef TARGET_ABI32
45#undef ELF_CLASS
46#define ELF_CLASS ELFCLASS32
47#undef bswaptls
48#define bswaptls(ptr) bswap32s(ptr)
49#endif
50
51
52#define INTERP_MAP_SIZE (32 * 1024 * 1024)
53
54
55#define ET_DYN_MAP_SIZE (128 * 1024 * 1024)
56
57
58#define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE
59#define TARGET_ELF_PAGESTART(_v) ((_v) & \
60 ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1))
61#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1))
62
63#define DLINFO_ITEMS 12
64
65static abi_ulong target_create_elf_tables(abi_ulong p, int argc, int envc,
66 abi_ulong stringp,
67 struct elfhdr *exec,
68 abi_ulong load_addr,
69 abi_ulong load_bias,
70 abi_ulong interp_load_addr,
71 struct image_info *info)
72{
73 abi_ulong sp;
74 int size;
75 abi_ulong u_platform;
76 const char *k_platform;
77 const int n = sizeof(elf_addr_t);
78
79 sp = p;
80 u_platform = 0;
81 k_platform = ELF_PLATFORM;
82 if (k_platform) {
83 size_t len = strlen(k_platform) + 1;
84 sp -= (len + n - 1) & ~(n - 1);
85 u_platform = sp;
86
87 memcpy_to_target(sp, k_platform, len);
88 }
89
90
91
92 sp = sp & ~(abi_ulong)15;
93 size = (DLINFO_ITEMS + 1) * 2;
94 if (k_platform) {
95 size += 2;
96 }
97#ifdef DLINFO_ARCH_ITEMS
98 size += DLINFO_ARCH_ITEMS * 2;
99#endif
100 size += envc + argc + 2;
101 size += 1;
102 size *= n;
103 if (size & 15) {
104 sp -= 16 - (size & 15);
105 }
106
107
108
109
110#define NEW_AUX_ENT(id, val) do { \
111 sp -= n; put_user_ual(val, sp); \
112 sp -= n; put_user_ual(id, sp); \
113 } while (0)
114
115 NEW_AUX_ENT(AT_NULL, 0);
116
117
118 NEW_AUX_ENT(AT_PHDR, (abi_ulong)(load_addr + exec->e_phoff));
119 NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof(struct elf_phdr)));
120 NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum));
121 NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE));
122 NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_load_addr));
123 NEW_AUX_ENT(AT_FLAGS, (abi_ulong)0);
124 NEW_AUX_ENT(AT_ENTRY, load_bias + exec->e_entry);
125 NEW_AUX_ENT(AT_UID, (abi_ulong)getuid());
126 NEW_AUX_ENT(AT_EUID, (abi_ulong)geteuid());
127 NEW_AUX_ENT(AT_GID, (abi_ulong)getgid());
128 NEW_AUX_ENT(AT_EGID, (abi_ulong)getegid());
129 NEW_AUX_ENT(AT_HWCAP, (abi_ulong)ELF_HWCAP);
130 NEW_AUX_ENT(AT_CLKTCK, (abi_ulong)sysconf(_SC_CLK_TCK));
131 if (k_platform) {
132 NEW_AUX_ENT(AT_PLATFORM, u_platform);
133 }
134#ifdef ARCH_DLINFO
135
136
137
138
139 ARCH_DLINFO;
140#endif
141#undef NEW_AUX_ENT
142
143 sp = loader_build_argptr(envc, argc, sp, stringp);
144 return sp;
145}
146
147#endif
148