1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
<html>
<head>
<title>~/src/firstworks/rudiments-0.31/include/rudiments/memorymap.h.html</title>
<meta name="Generator" content="Vim/7.0">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="#0000ff">// Copyright (c) 2004 David Muse</font>
<font color="#0000ff">// See the COPYING file for more information.</font>
<font color="#a020f0">#ifndef RUDIMENTS_MEMORYMAP_H</font>
<font color="#a020f0">#define RUDIMENTS_MEMORYMAP_H</font>
<font color="#a020f0">#include </font><font color="#ff00ff"><rudiments/private/memorymapincludes.h></font>
<font color="#0000ff">// The memorymap class provides methods for mapping a file (or file descriptor)</font>
<font color="#0000ff">// to a region of memory and manipulating the mapped region.</font>
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
<font color="#2e8b57"><b>namespace</b></font> rudiments {
<font color="#a020f0">#endif</font>
<font color="#2e8b57"><b>class</b></font> memorymapprivate;
<font color="#2e8b57"><b>class</b></font> memorymap {
<font color="#a52a2a"><b>public</b></font>:
memorymap();
<font color="#0000ff">// creates an unattached memorymap</font>
~memorymap();
<font color="#0000ff">// destroys the memorymap, detaching if necessary</font>
<font color="#2e8b57"><b>bool</b></font> attach(<font color="#2e8b57"><b>int</b></font> fd, off64_t offset, <font color="#2e8b57"><b>size_t</b></font> len,
<font color="#2e8b57"><b>int</b></font> protection, <font color="#2e8b57"><b>int</b></font> flags);
<font color="#0000ff">// Attaches the memorymap to file descriptor "fd" at</font>
<font color="#0000ff">// "offset" for "len" bytes.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// "protection" may be:</font>
<font color="#0000ff">// PROT_NONE - pages may not be accessed</font>
<font color="#0000ff">// or an or'ed combination of the following:</font>
<font color="#0000ff">// PROT_EXEC - pages may be excuted</font>
<font color="#0000ff">// PROT_READ - pages may be read</font>
<font color="#0000ff">// PROT_WRITE - pages may be written</font>
<font color="#0000ff">// "protection" may not conflict with the open mode</font>
<font color="#0000ff">// of the file. (eg. if the file was opened readonly</font>
<font color="#0000ff">// then PROT_WRITE may not be used).</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// flags may be:</font>
<font color="#0000ff">// MAP_SHARED</font>
<font color="#0000ff">// or</font>
<font color="#0000ff">// MAP_PRIVATE</font>
<font color="#0000ff">// and an or'ed combination of the following:</font>
<font color="#0000ff">// MAP_FIXED </font>
<font color="#0000ff">// MAP_DENYWRITE</font>
<font color="#0000ff">// MAP_EXECUTABLE</font>
<font color="#0000ff">// MAP_NORESERVE</font>
<font color="#0000ff">// MAP_LOCKED</font>
<font color="#0000ff">// MAP_GROWSDOWN</font>
<font color="#0000ff">// MAP_ANONYMOUS</font>
<font color="#0000ff">// MAP_ANON</font>
<font color="#0000ff">// MAP_32BIT</font>
<font color="#0000ff">// MAP_AUTOGROW</font>
<font color="#0000ff">// MAP_AUTORESRV</font>
<font color="#0000ff">// MAP_COPY</font>
<font color="#0000ff">// MAP_LOCAL</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#2e8b57"><b>bool</b></font> detach();
<font color="#0000ff">// detaches the memory map from the file descriptor</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#2e8b57"><b>bool</b></font> setProtection(<font color="#2e8b57"><b>int</b></font> protection);
<font color="#0000ff">// Sets the protection of the entire memory map to</font>
<font color="#0000ff">// "protection". See protect() below for more info.</font>
<font color="#2e8b57"><b>bool</b></font> setProtection(off64_t offset, <font color="#2e8b57"><b>size_t</b></font> len, <font color="#2e8b57"><b>int</b></font> protection);
<font color="#0000ff">// Sets the protection of the memory map to "protection"</font>
<font color="#0000ff">// for "len" bytes, starting at "offset".</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// "protection" may be:</font>
<font color="#0000ff">// PROT_NONE - pages may not be accessed</font>
<font color="#0000ff">// or an or'ed combination of the following:</font>
<font color="#0000ff">// PROT_EXEC - pages may be excuted</font>
<font color="#0000ff">// PROT_READ - pages may be read</font>
<font color="#0000ff">// PROT_WRITE - pages may be written</font>
<font color="#0000ff">// "protection" may not conflict with the open mode</font>
<font color="#0000ff">// of the file. (eg. if the file was opened readonly</font>
<font color="#0000ff">// then PROT_WRITE may not be used).</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#2e8b57"><b>void</b></font> *getData();
<font color="#0000ff">// Returns a pointer to the region of memory that the</font>
<font color="#0000ff">// file is mapped into.</font>
<font color="#2e8b57"><b>size_t</b></font> getLength();
<font color="#0000ff">// Returns the length of the region of memory that the</font>
<font color="#0000ff">// file is mapped into.</font>
<font color="#2e8b57"><b>bool</b></font> sync(<font color="#2e8b57"><b>bool</b></font> immediate, <font color="#2e8b57"><b>bool</b></font> invalidate);
<font color="#0000ff">// Make sure that changes made to the memory map have</font>
<font color="#0000ff">// been copied to the storage mediam that the mapped</font>
<font color="#0000ff">// file resides on. See sync() below for more info.</font>
<font color="#2e8b57"><b>bool</b></font> sync(off64_t offset, <font color="#2e8b57"><b>size_t</b></font> len,
<font color="#2e8b57"><b>bool</b></font> immediate, <font color="#2e8b57"><b>bool</b></font> invalidate);
<font color="#0000ff">// Make sure that changes made to the memory map for</font>
<font color="#0000ff">// "len" bytes, starting at "offset" have been copied</font>
<font color="#0000ff">// to the storage mediam that the mapped file resides</font>
<font color="#0000ff">// on.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// If "immediate" is true, the method will not return</font>
<font color="#0000ff">// until the synchronization has finished, if it is</font>
<font color="#0000ff">// false, the synchronization will occur in the</font>
<font color="#0000ff">// background.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// If "invalidate" is true, all other mappings of the</font>
<font color="#0000ff">// file will be invalidated.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#0000ff">// These methods allow you to advise the kernel that you are</font>
<font color="#0000ff">// going to access a region of a file in a particular manner.</font>
<font color="#0000ff">// The kernel can then perform some optimisations.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// In these methods, the region of the file begins at "offset"</font>
<font color="#0000ff">// and continues for "len" bytes.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// These methods return true on success and false on failure.</font>
<font color="#2e8b57"><b>bool</b></font> sequentialAccess(off64_t offset, <font color="#2e8b57"><b>size_t</b></font> len);
<font color="#0000ff">// The region will be accessed in sequential order.</font>
<font color="#2e8b57"><b>bool</b></font> randomAccess(off64_t offset, <font color="#2e8b57"><b>size_t</b></font> len);
<font color="#0000ff">// The region will be accessed in random order.</font>
<font color="#2e8b57"><b>bool</b></font> willNeed(off64_t offset, <font color="#2e8b57"><b>size_t</b></font> len);
<font color="#0000ff">// The region will be accessed in the near future.</font>
<font color="#2e8b57"><b>bool</b></font> wontNeed(off64_t offset, <font color="#2e8b57"><b>size_t</b></font> len);
<font color="#0000ff">// The region will not be accessed in the near future.</font>
<font color="#2e8b57"><b>bool</b></font> normalAccess(off64_t offset, <font color="#2e8b57"><b>size_t</b></font> len);
<font color="#0000ff">// Removes any advice that has previously been applied</font>
<font color="#0000ff">// to the region.</font>
<font color="#2e8b57"><b>bool</b></font> lock();
<font color="#0000ff">// Disables paging of the entire memory map.</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// On systems that don't support locking, this method</font>
<font color="#0000ff">// returns false;</font>
<font color="#2e8b57"><b>bool</b></font> lock(off64_t offset, <font color="#2e8b57"><b>size_t</b></font> len);
<font color="#0000ff">// Disables paging of data in the memory map, starting</font>
<font color="#0000ff">// at "offset", for "len" bytes.</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// On systems that don't support locking, this method</font>
<font color="#0000ff">// returns false;</font>
<font color="#2e8b57"><b>bool</b></font> unlock();
<font color="#0000ff">// Enables paging of the entire memory map.</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// On systems that don't support locking, this method</font>
<font color="#0000ff">// returns false;</font>
<font color="#2e8b57"><b>bool</b></font> unlock(off64_t offset, <font color="#2e8b57"><b>size_t</b></font> len);
<font color="#0000ff">// Enables paging of data in the memory map, starting</font>
<font color="#0000ff">// at "offset", for "len" bytes.</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// On systems that don't support locking, this method</font>
<font color="#0000ff">// returns false;</font>
<font color="#2e8b57"><b>bool</b></font> inMemory();
<font color="#0000ff">// Returns true if all pages of the memory map are</font>
<font color="#0000ff">// currently cached in system ram.</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// On systems that don't support checking whether</font>
<font color="#0000ff">// pages of the memory map are currently cached</font>
<font color="#0000ff">// in system ram, this method returns false.</font>
<font color="#2e8b57"><b>bool</b></font> inMemory(off64_t offset, <font color="#2e8b57"><b>size_t</b></font> len);
<font color="#0000ff">// Returns true if all pages of the memory map starting</font>
<font color="#0000ff">// at "offset", for "len" bytes are currently cached in</font>
<font color="#0000ff">// system ram.</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// On systems that don't support checking whether</font>
<font color="#0000ff">// pages of the memory map are currently cached</font>
<font color="#0000ff">// in system ram, this method returns false.</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>bool</b></font> lockAll();
<font color="#0000ff">// Disables paging (storing to swap partition)</font>
<font color="#0000ff">// of all pages of memory currently used for</font>
<font color="#0000ff">// memorymaps by the process and all newly</font>
<font color="#0000ff">// allocated pages.</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// On systems that don't support locking,</font>
<font color="#0000ff">// this method returns false;</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>bool</b></font> lockAllCurrent();
<font color="#0000ff">// Disables paging (storing to swap partition)</font>
<font color="#0000ff">// of all pages of memory currently used for</font>
<font color="#0000ff">// memorymaps by the process. Newly allocated</font>
<font color="#0000ff">// pages may still be paged out.</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// On systems that don't support locking,</font>
<font color="#0000ff">// this method returns false;</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>bool</b></font> lockAllFuture();
<font color="#0000ff">// Disables paging (storing to swap partition)</font>
<font color="#0000ff">// of all newly allocated pages of memory used</font>
<font color="#0000ff">// for memorymaps by the process. Currently</font>
<font color="#0000ff">// allocated pages may still be paged out.</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// On systems that don't support locking,</font>
<font color="#0000ff">// this method returns false;</font>
<font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>bool</b></font> unlockAll();
<font color="#0000ff">// Enables paging of data stored in all</font>
<font color="#0000ff">// memorymaps currently open by the process.</font>
<font color="#0000ff">// Returns true on success and false on failure.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// On systems that don't support locking,</font>
<font color="#0000ff">// this method returns false;</font>
<font color="#a020f0"> #include </font><font color="#ff00ff"><rudiments/private/memorymap.h></font>
};
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
}
<font color="#a020f0">#endif</font>
<font color="#a020f0">#endif</font>
</pre>
</body>
</html>
|