Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/trusted/service_runtime/sel_ldr.h

Issue 389022: first step in factoring out code dealing with elf into a separate library.... (Closed) Base URL: http://nativeclient.googlecode.com/svn/trunk/src/native_client/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/trusted/service_runtime/nacl_config.h ('k') | src/trusted/service_runtime/sel_ldr.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009, Google Inc. 2 * Copyright 2009, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 EXTERN_C_BEGIN 72 EXTERN_C_BEGIN
73 73
74 #define NACL_SERVICE_PORT_DESCRIPTOR 3 74 #define NACL_SERVICE_PORT_DESCRIPTOR 3
75 #define NACL_SERVICE_ADDRESS_DESCRIPTOR 4 75 #define NACL_SERVICE_ADDRESS_DESCRIPTOR 4
76 76
77 #define NACL_DEFAULT_ALLOC_MAX (32 << 20) /* total brk and mmap allocs */ 77 #define NACL_DEFAULT_ALLOC_MAX (32 << 20) /* total brk and mmap allocs */
78 #define NACL_DEFAULT_STACK_MAX (16 << 20) /* main thread stack */ 78 #define NACL_DEFAULT_STACK_MAX (16 << 20) /* main thread stack */
79 79
80 #define NACL_SANDBOX_CHROOT_FD "SBX_D" 80 #define NACL_SANDBOX_CHROOT_FD "SBX_D"
81 81
82 /*
83 * Finds the lowest 1 bit in PF_MASKOS. Assumes that at least one
84 * bit is set, and that this bit is not the highest-order bit.
85 *
86 * Let us denote PF_MASKOS by n. Assume n \ne 2^{31}. Let the k^{th}
87 * bit be the lowest order bit that is set, i.e.,
88 * n = m \cdot 2^{k+1} + 2^k, with k,m integers, m \ge 0, and 0 \le k < 31.
89 * then (here lhs is C notation, rhs is LaTeX notation):
90 * n ^ (n-1) = (m \cdot 2^{k+1} + 2^k)
91 * \oplus (m \dot 2^{k+1} + 2^{k-1} + \ldots + 1)
92 * = 2^k + 2^{k-1} + \ldots + 1
93 * = (2^{k+1}-1)
94 * so
95 * ((n ^ (n-1)) + 1U) = 2^{k+1}, (since k < 31, no overflow occurs) and
96 * ((n ^ (n-1)) + 1U) >> 1 = 2^k. QED.
97 */
98 #define PF_OS_WILL_LOAD (((PF_MASKOS ^ (PF_MASKOS-1)) + 1U) >> 1)
99 #if PF_MASKOS == (1 << 31)
100 # error "PF_MASKOS too large, invariant needed for PF_OS_WILL_LOAD violated"
101 #endif
102
103 #if NACL_WINDOWS 82 #if NACL_WINDOWS
104 #define WINDOWS_EXCEPTION_TRY do { __try { 83 #define WINDOWS_EXCEPTION_TRY do { __try {
105 #define WINDOWS_EXCEPTION_CATCH } __except(EXCEPTION_EXECUTE_HANDLER) { \ 84 #define WINDOWS_EXCEPTION_CATCH } __except(EXCEPTION_EXECUTE_HANDLER) { \
106 NaClLog(LOG_ERROR, \ 85 NaClLog(LOG_ERROR, \
107 "Unhandled Windows exception\n"); \ 86 "Unhandled Windows exception\n"); \
108 exit(1); \ 87 exit(1); \
109 } \ 88 } \
110 } while (0) 89 } while (0)
111 #else 90 #else
112 #define WINDOWS_EXCEPTION_TRY do { 91 #define WINDOWS_EXCEPTION_TRY do {
113 #define WINDOWS_EXCEPTION_CATCH } while (0) 92 #define WINDOWS_EXCEPTION_CATCH } while (0)
114 #endif 93 #endif
115 94
116 struct NaClAppThread; 95 struct NaClAppThread;
117 96
118 struct NaClApp { 97 struct NaClApp {
119 /* 98 /*
120 * public, user settable. 99 * public, user settable.
121 */ 100 */
122 uint32_t addr_bits; 101 uint32_t addr_bits;
123 uint32_t max_data_alloc, stack_size; 102 uint32_t max_data_alloc;
103 uint32_t stack_size;
124 /* 104 /*
125 * max_data_alloc controls how much total data memory can be 105 * max_data_alloc controls how much total data memory can be
126 * allocated to the NaCl process; this is initialized data, 106 * allocated to the NaCl process; this is initialized data,
127 * uninitialized data, and heap and affects the brk system call. 107 * uninitialized data, and heap and affects the brk system call.
128 * the text size and rodata size are not included, even though in 108 * the text size and rodata size are not included, even though in
129 * NaCl the text and rodata pages are also backed by the pager 109 * NaCl the text and rodata pages are also backed by the pager
130 * since due to relocation the text pages and rodata contents 110 * since due to relocation the text pages and rodata contents
131 * cannot simply be memory mapped from the executable. 111 * cannot simply be memory mapped from the executable.
132 * 112 *
133 * stack_size is the maximum size of the (main) stack. The stack 113 * stack_size is the maximum size of the (main) stack. The stack
134 * memory is eager allocated (mapped in w/o MAP_NORESERVE) so 114 * memory is eager allocated (mapped in w/o MAP_NORESERVE) so
135 * there must be enough swap space; page table entries are not 115 * there must be enough swap space; page table entries are not
136 * populated (no MAP_POPULATE), so actual accesses will likely 116 * populated (no MAP_POPULATE), so actual accesses will likely
137 * incur page faults. 117 * incur page faults.
138 */ 118 */
139 119
140 /* determined at load time; OS-determined */ 120 /* determined at load time; OS-determined */
141 /* read-only */ 121 /* read-only */
142 uintptr_t mem_start; 122 uintptr_t mem_start;
143 123
144 /* only used for ET_EXEC: for CS restriction */ 124 /* only used for ET_EXEC: for CS restriction */
145 uint32_t text_region_bytes; /* ro. memsz */ 125 uint32_t text_region_bytes; /* ro. memsz */
146 126
147 uintptr_t data_end; 127 uintptr_t data_end;
148 /* see break_addr below */ 128 /* see break_addr below */
149 129
150 Elf32_Addr entry_pt; 130 uint32_t entry_pt;
151 131
152 /* 132 /*
153 * Alignment boundary for validation (16 or 32). 133 * Alignment boundary for validation (16 or 32).
154 */ 134 */
155 int align_boundary; 135 int align_boundary;
156 136
157 /* private */
158 Elf32_Ehdr elf_hdr;
159
160 /*
161 * phdrs and sections are mutually exclusive.
162 *
163 * phdrs non-NULL means that an ELF executable -- with starting text
164 * address of NACL_TRAMPOLINE_END -- is used. sections headers are
165 * still loaded, for things like bss size. ???? TODO(bsy)
166 *
167 * when phdrs is NULL, a relocatable object was used and sections
168 * will be non-NULL, with the loader performing relocation as part
169 * of the image load. This is insufficient for C++ since preinit
170 * and init code is not executed, so global constructors aren't run,
171 * and multiple section groups for template instantiation are not
172 * handled properly, among other issues.
173 */
174 Elf32_Phdr *phdrs; /* elf_hdr.e_phnum entries */
175
176 /* common to both ELF executables and relocatable load images */ 137 /* common to both ELF executables and relocatable load images */
177 138
178 uintptr_t springboard_addr; /* relative to mem_start */ 139 uintptr_t springboard_addr; /* relative to mem_start */
179 /* 140 /*
180 * springboard code addr for context switching into app sandbox, relative 141 * springboard code addr for context switching into app sandbox, relative
181 * to code sandbox CS 142 * to code sandbox CS
182 */ 143 */
183 144
184 /* 145 /*
185 * The socket at which the app should be accepting connections. The 146 * The socket at which the app should be accepting connections. The
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 */ 201 */
241 struct NaClMutex threads_mu; 202 struct NaClMutex threads_mu;
242 struct NaClCondVar threads_cv; 203 struct NaClCondVar threads_cv;
243 struct DynArray threads; /* NaClAppThread pointers */ 204 struct DynArray threads; /* NaClAppThread pointers */
244 int num_threads; /* number actually running */ 205 int num_threads; /* number actually running */
245 206
246 struct NaClMutex desc_mu; 207 struct NaClMutex desc_mu;
247 struct DynArray desc_tbl; /* NaClDesc pointers */ 208 struct DynArray desc_tbl; /* NaClDesc pointers */
248 }; 209 };
249 210
250 #define NACL_MAX_PROGRAM_HEADERS 128
251
252 enum NaClPhdrCheckAction {
253 PCA_NONE,
254 PCA_TEXT_CHECK,
255 PCA_IGNORE /* ignore this segment. currently used only for PT_PHDR. */
256 };
257
258 struct NaClPhdrChecks {
259 Elf32_Word p_type;
260 Elf32_Word p_flags; /* rwx */
261 enum NaClPhdrCheckAction action;
262 int required; /* only for text for now */
263 Elf32_Word p_vaddr; /* if non-zero, vaddr must be this */
264 };
265 211
266 212
267 void NaClAppIncrVerbosity(void); 213 void NaClAppIncrVerbosity(void);
268 214
269 int NaClAppCtor(struct NaClApp *nap) NACL_WUR; 215 int NaClAppCtor(struct NaClApp *nap) NACL_WUR;
270 216
271 void NaClAppDtor(struct NaClApp *nap); 217 void NaClAppDtor(struct NaClApp *nap);
272 218
273 void NaClAppFreeAllMemory(struct NaClApp *nap); 219 void NaClAppFreeAllMemory(struct NaClApp *nap);
274 220
(...skipping 13 matching lines...) Expand all
288 * detail string and hang that off the nap object, so that more 234 * detail string and hang that off the nap object, so that more
289 * details are available w/o incrementing verbosity (and polluting 235 * details are available w/o incrementing verbosity (and polluting
290 * stdout). 236 * stdout).
291 * 237 *
292 * note: it may be necessary to flush the icache if the memory 238 * note: it may be necessary to flush the icache if the memory
293 * allocated for use had already made it into the icache from another 239 * allocated for use had already made it into the icache from another
294 * NaCl application instance, and the icache does not detect 240 * NaCl application instance, and the icache does not detect
295 * self-modifying code / data writes and automatically invalidate the 241 * self-modifying code / data writes and automatically invalidate the
296 * cache lines. 242 * cache lines.
297 */ 243 */
298 244 enum NaClAbiCheckOption {
299 245 NACL_ABI_CHECK_OPTION_SKIP,
300 enum NaClAbiMismatchOption { 246 NACL_ABI_CHECK_OPTION_CHECK
301 NACL_ABI_MISMATCH_OPTION_ABORT,
302 NACL_ABI_MISMATCH_OPTION_IGNORE
303 }; 247 };
304 248
305 NaClErrorCode NaClAppLoadFile(struct Gio *gp, 249 NaClErrorCode NaClAppLoadFile(struct Gio *gp,
306 struct NaClApp *nap, 250 struct NaClApp *nap,
307 enum NaClAbiMismatchOption abi_mismatch_option) 251 enum NaClAbiCheckOption check_abi)
308 NACL_WUR; 252 NACL_WUR;
309 253
310 size_t NaClAlignPad(size_t val, 254 size_t NaClAlignPad(size_t val,
311 size_t align); 255 size_t align);
312 256
313 void NaClAppPrintDetails(struct NaClApp *nap, 257 void NaClAppPrintDetails(struct NaClApp *nap,
314 struct Gio *gp); 258 struct Gio *gp);
315 259
316 uint32_t NaClLoad32(uintptr_t addr); 260 uint32_t NaClLoad32(uintptr_t addr);
317 261
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 */ 457 */
514 458
515 return addr; 459 return addr;
516 } 460 }
517 #else 461 #else
518 #error Unknown platform! 462 #error Unknown platform!
519 #endif 463 #endif
520 464
521 EXTERN_C_END 465 EXTERN_C_END
522 466
523 #endif 467 #endif /* NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_SEL_LDR_H__ */
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/nacl_config.h ('k') | src/trusted/service_runtime/sel_ldr.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698