2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
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
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"
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
57 * The simple data structure that we use is a sorted array of valid
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 */
70 struct NaClVmmapEntry
**vmentry
; /* must not overlap */
75 void NaClVmmapDebug(struct NaClVmmap
*self
,
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
,
99 struct NaClMemObj
*nmop
);
101 void NaClVmmapUpdate(struct NaClVmmap
*self
,
105 struct NaClMemObj
*nmop
,
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
,
115 struct NaClVmmapIter
*NaClVmmapFindPageIter(struct NaClVmmap
*self
,
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
),
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
,
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
,
142 uintptr_t NaClVmmapFindMapSpaceAboveHint(struct NaClVmmap
*self
,
146 void NaClVmmapMakeSorted(struct NaClVmmap
*self
);