sel_ldr: Remove support for rodata segment at start of executable
[nativeclient.git] / service_runtime / sel_mem.h
blobd62d99f207e0fb319b3958239db44c70d45726ff
1 /*
2 * Copyright 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * NaCl Simple/secure ELF loader (NaCl SEL) memory map.
36 #ifndef NATIVE_CLIENT_SERVICE_RUNTIME_SEL_MEM_H_
37 #define NATIVE_CLIENT_SERVICE_RUNTIME_SEL_MEM_H_
39 #include "native_client/include/portability.h"
40 #include "native_client/include/nacl_base.h"
41 #include "native_client/service_runtime/nacl_memory_object.h"
43 EXTERN_C_BEGIN
46 * Interface is based on setting properties and query properties by
47 * page numbers (addr >> NACL_PAGESHIFT) and the number of pages
48 * affected (for setting properties).
50 * Initially, the address space is empty, with all memory
51 * inaccessible. As the program is loaded, pages are marked
52 * accessible -- text pages are non-writable, data and stack are
53 * writable. At runtime, shared memory buffers are allocated by
54 * looking at the first memory hole that fits, starting down from the
55 * stack.
57 * The simple data structure that we use is a sorted array of valid
58 * memory regions.
61 struct NaClVmmapEntry {
62 uintptr_t page_num; /* base virtual address >> NACL_PAGESHIFT */
63 size_t npages; /* number of pages */
64 int prot; /* mprotect attribute */
65 struct NaClMemObj *nmop; /* how to get memory for move/remap */
66 int removed; /* flag set in NaClVmmapUpdate */
69 struct NaClVmmap {
70 struct NaClVmmapEntry **vmentry; /* must not overlap */
71 size_t nvalid, size;
72 int is_sorted;
75 void NaClVmmapDebug(struct NaClVmmap *self,
76 char *msg);
79 * iterators methods are final for now.
81 struct NaClVmmapIter {
82 struct NaClVmmap *vmmap;
83 unsigned int entry_ix;
86 int NaClVmmapIterAtEnd(struct NaClVmmapIter *nvip);
87 struct NaClVmmapEntry *NaClVmmapIterStar(struct NaClVmmapIter *nvip);
88 void NaClVmmapIterIncr(struct NaClVmmapIter *nvip);
89 void NaClVmmapIterErase(struct NaClVmmapIter *nvip);
91 int NaClVmmapCtor(struct NaClVmmap *self);
93 void NaClVmmapDtor(struct NaClVmmap *self);
95 int NaClVmmapAdd(struct NaClVmmap *self,
96 uintptr_t page_num,
97 size_t npages,
98 int prot,
99 struct NaClMemObj *nmop);
101 void NaClVmmapUpdate(struct NaClVmmap *self,
102 uintptr_t page_num,
103 size_t npages,
104 int prot,
105 struct NaClMemObj *nmop,
106 int remove);
109 * NaClVmmapFindPage and NaClVmmapFindPageIter only works if pnum is
110 * in the NaClVmmap. If not, NULL and an AtEnd iterator is returned.
112 struct NaClVmmapEntry const *NaClVmmapFindPage(struct NaClVmmap *self,
113 uintptr_t pnum);
115 struct NaClVmmapIter *NaClVmmapFindPageIter(struct NaClVmmap *self,
116 uintptr_t pnum,
117 struct NaClVmmapIter *space);
120 * Visitor pattern, call fn on every entry.
122 void NaClVmmapVisit(struct NaClVmmap *self,
123 void (*fn)(void *state,
124 struct NaClVmmapEntry *entry),
125 void *state);
128 * Returns page number starting at which there is a hole of at least
129 * num_pages in size. Linear search from high addresses on down.
131 uintptr_t NaClVmmapFindSpace(struct NaClVmmap *self,
132 size_t num_pages);
135 * Just lke NaClVmmapFindSpace, except usage is intended for
136 * NaClHostDescMap, so the starting address of the region found must
137 * be NACL_MAP_PAGESIZE aligned.
139 uintptr_t NaClVmmapFindMapSpace(struct NaClVmmap *self,
140 size_t num_pages);
142 uintptr_t NaClVmmapFindMapSpaceAboveHint(struct NaClVmmap *self,
143 uintptr_t uaddr,
144 size_t num_pages);
146 void NaClVmmapMakeSorted(struct NaClVmmap *self);
148 int NaClVmmapContainsExecutablePages(struct NaClVmmap *self, uintptr_t page_num,
149 size_t npages);
151 EXTERN_C_END
153 #endif