master
h 127 lines 3.91 KB
Raw
1 /*
2 * FreeBSD ELF definitions
3 *
4 * Copyright (c) 2013-2015 Stacey D. Son
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 #ifndef TARGET_OS_ELF_H
9 #define TARGET_OS_ELF_H
10
11 #include "target_arch_elf.h"
12 #include "elf.h"
13 #include "user/tswap-target.h"
14
15 #define bsd_get_ncpu() 1 /* until we pull in bsd-proc.[hc] */
16
17 /* this flag is uneffective under linux too, should be deleted */
18 #ifndef MAP_DENYWRITE
19 #define MAP_DENYWRITE 0
20 #endif
21
22 /* should probably go in elf.h */
23 #ifndef ELIBBAD
24 #define ELIBBAD 80
25 #endif
26
27 #ifndef ELF_PLATFORM
28 #define ELF_PLATFORM (NULL)
29 #endif
30
31 /* XXX Look at the other conflicting AT_* values. */
32 #define FREEBSD_AT_NCPUS 19
33 #define FREEBSD_AT_HWCAP 25
34 #define FREEBSD_AT_HWCAP2 26
35
36 #ifdef TARGET_ABI32
37 #undef ELF_CLASS
38 #define ELF_CLASS ELFCLASS32
39 #undef bswaptls
40 #define bswaptls(ptr) bswap32s(ptr)
41 #endif
42
43 /* max code+data+bss space allocated to elf interpreter */
44 #define INTERP_MAP_SIZE (32 * 1024 * 1024)
45
46 /* max code+data+bss+brk space allocated to ET_DYN executables */
47 #define ET_DYN_MAP_SIZE (128 * 1024 * 1024)
48
49 /* Necessary parameters */
50 #define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE
51 #define TARGET_ELF_PAGESTART(_v) ((_v) & \
52 ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1))
53 #define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1))
54
55 #define DLINFO_ITEMS 14
56
57 static abi_ulong target_create_elf_tables(abi_ulong p, int argc, int envc,
58 abi_ulong stringp,
59 struct elfhdr *exec,
60 abi_ulong load_addr,
61 abi_ulong load_bias,
62 abi_ulong interp_load_addr,
63 struct image_info *info)
64 {
65 abi_ulong features, sp;
66 int size;
67 const int n = sizeof(elf_addr_t);
68
69 target_auxents_sz = 0;
70 sp = p;
71 /*
72 * Force 16 byte _final_ alignment here for generality.
73 */
74 sp = sp & ~(abi_ulong)15;
75 size = (DLINFO_ITEMS + 1) * 2;
76 size += envc + argc + 2;
77 size += 1; /* argc itself */
78 size *= n;
79 if (size & 15) {
80 sp -= 16 - (size & 15);
81 }
82
83 /*
84 * FreeBSD defines elf_addr_t as Elf32_Off / Elf64_Off
85 */
86 #define NEW_AUX_ENT(id, val) do { \
87 sp -= n; put_user_ual(val, sp); \
88 sp -= n; put_user_ual(id, sp); \
89 target_auxents_sz += 2 * n; \
90 } while (0)
91
92 NEW_AUX_ENT(AT_NULL, 0);
93
94 /* There must be exactly DLINFO_ITEMS entries here. */
95 NEW_AUX_ENT(AT_PHDR, (abi_ulong)(load_addr + exec->e_phoff));
96 NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof(struct elf_phdr)));
97 NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum));
98 NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE));
99 NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_load_addr));
100 NEW_AUX_ENT(AT_FLAGS, (abi_ulong)0);
101 NEW_AUX_ENT(FREEBSD_AT_NCPUS, (abi_ulong)bsd_get_ncpu());
102 NEW_AUX_ENT(AT_ENTRY, load_bias + exec->e_entry);
103 features = ELF_HWCAP;
104 NEW_AUX_ENT(FREEBSD_AT_HWCAP, features);
105 #ifdef ELF_HWCAP2
106 features = ELF_HWCAP2;
107 NEW_AUX_ENT(FREEBSD_AT_HWCAP2, features);
108 #endif
109 NEW_AUX_ENT(AT_UID, (abi_ulong)getuid());
110 NEW_AUX_ENT(AT_EUID, (abi_ulong)geteuid());
111 NEW_AUX_ENT(AT_GID, (abi_ulong)getgid());
112 NEW_AUX_ENT(AT_EGID, (abi_ulong)getegid());
113 target_auxents = sp; /* Note where the aux entries are in the target */
114 #ifdef ARCH_DLINFO
115 /*
116 * ARCH_DLINFO must come last so platform specific code can enforce
117 * special alignment requirements on the AUXV if necessary (eg. PPC).
118 */
119 ARCH_DLINFO;
120 #endif
121 #undef NEW_AUX_ENT
122
123 sp = loader_build_argptr(envc, argc, sp, stringp);
124 return sp;
125 }
126
127 #endif /* TARGET_OS_ELF_H */