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 object.
36 #ifndef NATIVE_CLIENT_SERVICE_RUNTIME_MEMORY_OBJECT_H_
37 #define NATIVE_CLIENT_SERVICE_RUNTIME_MEMORY_OBJECT_H_
39 #include "native_client/include/nacl_base.h"
40 #include "native_client/include/portability.h"
42 #include "native_client/service_runtime/nacl_sync.h"
43 #include "native_client/service_runtime/nacl_desc_base.h"
45 #include "native_client/intermodule_comm/nacl_imc_c.h"
50 * Memory object for the virtual memory map. We map in 64KB chunks,
51 * and we need this so that we can recreate the memory from the
52 * original source should we need to move the address space.
54 * This also means that once a descriptor / handle is used to map in
55 * memory, we cannot close it unless we know how to recreate it.
56 * Thus, the NaClDesc objects are reference counted.
58 * Any splitting of NaClMemObj objects should be done with the VM map
59 * lock held, so these NaClMemObj objects do not themselves contain a
66 * The size of the memory object when the mapping took place. This
67 * is important becaues the last page in the mapping has to be
70 * If the object ends in the middle of an allocation, the kernel
71 * will zero pad the allocation. The zero bytes are writable, but
72 * are not reflected back into the file. First, assume that the
73 * file size does not change. This means that for a shared mapping,
74 * when an address space move occurs we have to re-map the file at
75 * the new position, and then copy the contents of the rest of the
76 * allocation to the new location.
78 * If the file has shrunk, then the shared portion between the new
79 * end of file and the original end of file is impossible to
80 * duplicate as a shared mapping -- we may need to just crash and
83 * If the file has grown, then the unshared portion between the old
84 * end-of-file and end of that page (assuming it has grown past the
85 * page boundary) probably should not get overwritten -- and we may
86 * need to crash and burn at this point as well.
88 * On linux, we could use mremap, but then there's no need: the race
89 * condition with not being able to atomically update the memory
90 * mappings doesn't exist.
92 * TODO: figure out exactly what we need to do.
94 off_t nbytes
; /* stat member is off_t st_size */
96 * All memory objects that back virtual memory must support
97 * offset/nbytes mapping. NB: the VM map code may split a
98 * NaClMemObj into two if some middle page got unmapped, etc.
104 * base class ctor and dtor. NULL != ndp must hold.
106 int NaClMemObjCtor(struct NaClMemObj
*nmop
,
107 struct NaClDesc
*ndp
,
111 int NaClMemObjCopyCtorOff(struct NaClMemObj
*nmop
,
112 struct NaClMemObj
*src
,
115 void NaClMemObjDtor(struct NaClMemObj
*nmop
);
118 * Allocating Ctor. Increments refcount on ndp, which must not be NULL.
120 struct NaClMemObj
*NaClMemObjMake(struct NaClDesc
*ndp
,
124 struct NaClMemObj
*NaClMemObjSplit(struct NaClMemObj
*nmop
,
127 void NaClMemObjIncOffset(struct NaClMemObj
*nmop
,