Disable check for OSABI field, now that I have changed it to 0 in binutils
[nativeclient.git] / service_runtime / nacl_memory_object.h
blobee8090a43e77b3ff491f21c8e5ff7bae59abfa6c
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 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"
47 EXTERN_C_BEGIN
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
60 * lock.
63 struct NaClMemObj {
64 struct NaClDesc *ndp;
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
68 * handled especially:
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
81 * burn at that point.
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.
100 off_t offset;
104 * base class ctor and dtor. NULL != ndp must hold.
106 int NaClMemObjCtor(struct NaClMemObj *nmop,
107 struct NaClDesc *ndp,
108 off_t nbytes,
109 off_t offset);
111 int NaClMemObjCopyCtorOff(struct NaClMemObj *nmop,
112 struct NaClMemObj *src,
113 off_t additional);
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,
121 off_t nbytes,
122 off_t offset);
124 struct NaClMemObj *NaClMemObjSplit(struct NaClMemObj *nmop,
125 off_t additional);
127 void NaClMemObjIncOffset(struct NaClMemObj *nmop,
128 off_t additional);
130 EXTERN_C_END
132 #endif