blob: fbcad8f6d161063fbbe280b3a242de2fe887e661 [file] [log] [blame]
ulan@chromium.org2efb9002012-01-19 15:36:35 +00001// Copyright 2012 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
machenbach@chromium.orge014e5b2014-01-28 07:51:38 +000028// Platform-specific code for Linux goes here. For the POSIX-compatible
29// parts, the implementation is in platform-posix.cc.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000030
31#include <pthread.h>
32#include <semaphore.h>
33#include <signal.h>
lrn@chromium.org5d00b602011-01-05 09:51:43 +000034#include <sys/prctl.h>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000035#include <sys/time.h>
36#include <sys/resource.h>
lrn@chromium.org303ada72010-10-27 09:33:13 +000037#include <sys/syscall.h>
ager@chromium.org381abbb2009-02-25 13:23:22 +000038#include <sys/types.h>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000039#include <stdlib.h>
40
41// Ubuntu Dapper requires memory pages to be marked as
42// executable. Otherwise, OS raises an exception when executing code
43// in that page.
44#include <sys/types.h> // mmap & munmap
ager@chromium.org236ad962008-09-25 09:45:57 +000045#include <sys/mman.h> // mmap & munmap
46#include <sys/stat.h> // open
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000047#include <fcntl.h> // open
48#include <unistd.h> // sysconf
ager@chromium.org236ad962008-09-25 09:45:57 +000049#include <strings.h> // index
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000050#include <errno.h>
51#include <stdarg.h>
52
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +000053// GLibc on ARM defines mcontext_t has a typedef for 'struct sigcontext'.
54// Old versions of the C library <signal.h> didn't define the type.
55#if defined(__ANDROID__) && !defined(__BIONIC_HAVE_UCONTEXT_T) && \
56 defined(__arm__) && !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT)
57#include <asm/sigcontext.h>
58#endif
59
machenbach@chromium.orge31286d2014-01-15 10:29:52 +000060#if defined(LEAK_SANITIZER)
61#include <sanitizer/lsan_interface.h>
62#endif
63
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000064#undef MAP_TYPE
65
66#include "v8.h"
67
68#include "platform.h"
ager@chromium.orga1645e22009-09-09 19:27:10 +000069#include "v8threads.h"
kasperl@chromium.orga5551262010-12-07 12:49:48 +000070#include "vm-state-inl.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000071
72
kasperl@chromium.org71affb52009-05-26 05:44:31 +000073namespace v8 {
74namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000075
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000076
ager@chromium.orgc4c92722009-11-18 14:12:51 +000077#ifdef __arm__
danno@chromium.org169691d2013-07-15 08:01:13 +000078
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +000079bool OS::ArmUsingHardFloat() {
yangguo@chromium.orgc74d6742012-06-29 15:15:45 +000080 // GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
81 // the Floating Point ABI used (PCS stands for Procedure Call Standard).
82 // We use these as well as a couple of other defines to statically determine
83 // what FP ABI used.
84 // GCC versions 4.4 and below don't support hard-fp.
85 // GCC versions 4.5 may support hard-fp without defining __ARM_PCS or
86 // __ARM_PCS_VFP.
87
88#define GCC_VERSION (__GNUC__ * 10000 \
89 + __GNUC_MINOR__ * 100 \
90 + __GNUC_PATCHLEVEL__)
91#if GCC_VERSION >= 40600
92#if defined(__ARM_PCS_VFP)
93 return true;
94#else
95 return false;
96#endif
97
98#elif GCC_VERSION < 40500
99 return false;
100
101#else
102#if defined(__ARM_PCS_VFP)
103 return true;
danno@chromium.org59400602013-08-13 17:09:37 +0000104#elif defined(__ARM_PCS) || defined(__SOFTFP__) || defined(__SOFTFP) || \
105 !defined(__VFP_FP__)
yangguo@chromium.orgc74d6742012-06-29 15:15:45 +0000106 return false;
107#else
108#error "Your version of GCC does not report the FP ABI compiled for." \
109 "Please report it on this issue" \
110 "http://code.google.com/p/v8/issues/detail?id=2140"
111
112#endif
113#endif
114#undef GCC_VERSION
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000115}
yangguo@chromium.orgc74d6742012-06-29 15:15:45 +0000116
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000117#endif // def __arm__
118
119
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000120const char* OS::LocalTimezone(double time) {
ulan@chromium.org77ca49a2013-04-22 09:43:56 +0000121 if (std::isnan(time)) return "";
machenbach@chromium.orge31286d2014-01-15 10:29:52 +0000122 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond));
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000123 struct tm* t = localtime(&tv);
124 if (NULL == t) return "";
125 return t->tm_zone;
126}
127
128
129double OS::LocalTimeOffset() {
130 time_t tv = time(NULL);
131 struct tm* t = localtime(&tv);
132 // tm_gmtoff includes any daylight savings offset, so subtract it.
133 return static_cast<double>(t->tm_gmtoff * msPerSecond -
134 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
135}
136
137
kasper.lund7276f142008-07-30 08:49:36 +0000138void* OS::Allocate(const size_t requested,
139 size_t* allocated,
kasperl@chromium.orgf5aa8372009-03-24 14:47:14 +0000140 bool is_executable) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000141 const size_t msize = RoundUp(requested, AllocateAlignment());
kasperl@chromium.orgf5aa8372009-03-24 14:47:14 +0000142 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000143 void* addr = OS::GetRandomMmapAddr();
ricow@chromium.org9fa09672011-07-25 11:05:35 +0000144 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000145 if (mbase == MAP_FAILED) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000146 LOG(i::Isolate::Current(),
147 StringEvent("OS::Allocate", "mmap failed"));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000148 return NULL;
149 }
150 *allocated = msize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000151 return mbase;
152}
153
154
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000155class PosixMemoryMappedFile : public OS::MemoryMappedFile {
156 public:
157 PosixMemoryMappedFile(FILE* file, void* memory, int size)
158 : file_(file), memory_(memory), size_(size) { }
159 virtual ~PosixMemoryMappedFile();
160 virtual void* memory() { return memory_; }
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000161 virtual int size() { return size_; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000162 private:
163 FILE* file_;
164 void* memory_;
165 int size_;
166};
167
168
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000169OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +0000170 FILE* file = fopen(name, "r+");
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000171 if (file == NULL) return NULL;
172
173 fseek(file, 0, SEEK_END);
174 int size = ftell(file);
175
176 void* memory =
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000177 mmap(OS::GetRandomMmapAddr(),
178 size,
179 PROT_READ | PROT_WRITE,
180 MAP_SHARED,
181 fileno(file),
182 0);
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000183 return new PosixMemoryMappedFile(file, memory, size);
184}
185
186
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000187OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
188 void* initial) {
189 FILE* file = fopen(name, "w+");
190 if (file == NULL) return NULL;
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000191 int result = fwrite(initial, size, 1, file);
192 if (result < 1) {
193 fclose(file);
194 return NULL;
195 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000196 void* memory =
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000197 mmap(OS::GetRandomMmapAddr(),
198 size,
199 PROT_READ | PROT_WRITE,
200 MAP_SHARED,
201 fileno(file),
202 0);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000203 return new PosixMemoryMappedFile(file, memory, size);
204}
205
206
207PosixMemoryMappedFile::~PosixMemoryMappedFile() {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000208 if (memory_) OS::Free(memory_, size_);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000209 fclose(file_);
210}
211
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000212
dslomov@chromium.orge97852d2013-09-12 09:02:59 +0000213void OS::LogSharedLibraryAddresses(Isolate* isolate) {
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000214 // This function assumes that the layout of the file is as follows:
215 // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name]
216 // If we encounter an unexpected situation we abort scanning further entries.
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000217 FILE* fp = fopen("/proc/self/maps", "r");
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000218 if (fp == NULL) return;
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000219
220 // Allocate enough room to be able to store a full file name.
221 const int kLibNameLen = FILENAME_MAX + 1;
222 char* lib_name = reinterpret_cast<char*>(malloc(kLibNameLen));
223
224 // This loop will terminate once the scanning hits an EOF.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000225 while (true) {
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000226 uintptr_t start, end;
227 char attr_r, attr_w, attr_x, attr_p;
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000228 // Parse the addresses and permission bits at the beginning of the line.
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000229 if (fscanf(fp, "%" V8PRIxPTR "-%" V8PRIxPTR, &start, &end) != 2) break;
230 if (fscanf(fp, " %c%c%c%c", &attr_r, &attr_w, &attr_x, &attr_p) != 4) break;
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000231
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000232 int c;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000233 if (attr_r == 'r' && attr_w != 'w' && attr_x == 'x') {
234 // Found a read-only executable entry. Skip characters until we reach
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000235 // the beginning of the filename or the end of the line.
236 do {
237 c = getc(fp);
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000238 } while ((c != EOF) && (c != '\n') && (c != '/') && (c != '['));
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000239 if (c == EOF) break; // EOF: Was unexpected, just exit.
240
241 // Process the filename if found.
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000242 if ((c == '/') || (c == '[')) {
243 // Push the '/' or '[' back into the stream to be read below.
244 ungetc(c, fp);
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000245
246 // Read to the end of the line. Exit if the read fails.
247 if (fgets(lib_name, kLibNameLen, fp) == NULL) break;
248
249 // Drop the newline character read by fgets. We do not need to check
250 // for a zero-length string because we know that we at least read the
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000251 // '/' or '[' character.
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000252 lib_name[strlen(lib_name) - 1] = '\0';
253 } else {
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000254 // No library name found, just record the raw address range.
255 snprintf(lib_name, kLibNameLen,
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000256 "%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end);
257 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000258 LOG(isolate, SharedLibraryEvent(lib_name, start, end));
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000259 } else {
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000260 // Entry not describing executable data. Skip to end of line to set up
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000261 // reading the next entry.
262 do {
263 c = getc(fp);
264 } while ((c != EOF) && (c != '\n'));
265 if (c == EOF) break;
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000266 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000267 }
sgjesse@chromium.orgb9d7da12009-08-05 08:38:10 +0000268 free(lib_name);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000269 fclose(fp);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000270}
271
272
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000273void OS::SignalCodeMovingGC() {
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000274 // Support for ll_prof.py.
275 //
276 // The Linux profiler built into the kernel logs all mmap's with
277 // PROT_EXEC so that analysis tools can properly attribute ticks. We
278 // do a mmap with a name known by ll_prof.py and immediately munmap
279 // it. This injects a GC marker into the stream of events generated
280 // by the kernel and allows us to synchronize V8 code log and the
281 // kernel log.
282 int size = sysconf(_SC_PAGESIZE);
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +0000283 FILE* f = fopen(FLAG_gc_fake_mmap, "w+");
rossberg@chromium.orgb99c7542013-05-31 11:40:45 +0000284 if (f == NULL) {
285 OS::PrintError("Failed to open %s\n", FLAG_gc_fake_mmap);
286 OS::Abort();
287 }
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000288 void* addr = mmap(OS::GetRandomMmapAddr(),
289 size,
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000290#if defined(__native_client__)
291 // The Native Client port of V8 uses an interpreter,
292 // so code pages don't need PROT_EXEC.
293 PROT_READ,
294#else
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000295 PROT_READ | PROT_EXEC,
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000296#endif
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000297 MAP_PRIVATE,
298 fileno(f),
299 0);
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000300 ASSERT(addr != MAP_FAILED);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000301 OS::Free(addr, size);
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000302 fclose(f);
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000303}
304
305
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000306// Constants used for mmap.
307static const int kMmapFd = -1;
308static const int kMmapFdOffset = 0;
309
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000310
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000311VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000312
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000313
314VirtualMemory::VirtualMemory(size_t size)
315 : address_(ReserveRegion(size)), size_(size) { }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000316
317
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000318VirtualMemory::VirtualMemory(size_t size, size_t alignment)
319 : address_(NULL), size_(0) {
320 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment())));
321 size_t request_size = RoundUp(size + alignment,
322 static_cast<intptr_t>(OS::AllocateAlignment()));
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000323 void* reservation = mmap(OS::GetRandomMmapAddr(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000324 request_size,
325 PROT_NONE,
326 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
327 kMmapFd,
328 kMmapFdOffset);
329 if (reservation == MAP_FAILED) return;
330
331 Address base = static_cast<Address>(reservation);
332 Address aligned_base = RoundUp(base, alignment);
333 ASSERT_LE(base, aligned_base);
334
335 // Unmap extra memory reserved before and after the desired block.
336 if (aligned_base != base) {
337 size_t prefix_size = static_cast<size_t>(aligned_base - base);
338 OS::Free(base, prefix_size);
339 request_size -= prefix_size;
340 }
341
342 size_t aligned_size = RoundUp(size, OS::AllocateAlignment());
343 ASSERT_LE(aligned_size, request_size);
344
345 if (aligned_size != request_size) {
346 size_t suffix_size = request_size - aligned_size;
347 OS::Free(aligned_base + aligned_size, suffix_size);
348 request_size -= suffix_size;
349 }
350
351 ASSERT(aligned_size == request_size);
352
353 address_ = static_cast<void*>(aligned_base);
354 size_ = aligned_size;
machenbach@chromium.orge31286d2014-01-15 10:29:52 +0000355#if defined(LEAK_SANITIZER)
356 __lsan_register_root_region(address_, size_);
357#endif
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000358}
359
360
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000361VirtualMemory::~VirtualMemory() {
362 if (IsReserved()) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000363 bool result = ReleaseRegion(address(), size());
364 ASSERT(result);
365 USE(result);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000366 }
367}
368
369
370bool VirtualMemory::IsReserved() {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000371 return address_ != NULL;
372}
373
374
375void VirtualMemory::Reset() {
376 address_ = NULL;
377 size_ = 0;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000378}
379
380
kasperl@chromium.orgf5aa8372009-03-24 14:47:14 +0000381bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000382 return CommitRegion(address, size, is_executable);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000383}
384
385
386bool VirtualMemory::Uncommit(void* address, size_t size) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000387 return UncommitRegion(address, size);
388}
389
390
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +0000391bool VirtualMemory::Guard(void* address) {
392 OS::Guard(address, OS::CommitPageSize());
393 return true;
394}
395
396
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000397void* VirtualMemory::ReserveRegion(size_t size) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000398 void* result = mmap(OS::GetRandomMmapAddr(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000399 size,
400 PROT_NONE,
401 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
402 kMmapFd,
403 kMmapFdOffset);
404
405 if (result == MAP_FAILED) return NULL;
406
machenbach@chromium.orge31286d2014-01-15 10:29:52 +0000407#if defined(LEAK_SANITIZER)
408 __lsan_register_root_region(result, size);
409#endif
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000410 return result;
411}
412
413
414bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000415#if defined(__native_client__)
416 // The Native Client port of V8 uses an interpreter,
417 // so code pages don't need PROT_EXEC.
418 int prot = PROT_READ | PROT_WRITE;
419#else
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000420 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
jkummerow@chromium.orgba72ec82013-07-22 09:21:20 +0000421#endif
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000422 if (MAP_FAILED == mmap(base,
423 size,
424 prot,
425 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
426 kMmapFd,
427 kMmapFdOffset)) {
428 return false;
429 }
430
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000431 return true;
432}
433
434
435bool VirtualMemory::UncommitRegion(void* base, size_t size) {
436 return mmap(base,
437 size,
438 PROT_NONE,
ager@chromium.orga1645e22009-09-09 19:27:10 +0000439 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000440 kMmapFd,
441 kMmapFdOffset) != MAP_FAILED;
442}
443
444
445bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
machenbach@chromium.orge31286d2014-01-15 10:29:52 +0000446#if defined(LEAK_SANITIZER)
447 __lsan_unregister_root_region(base, size);
448#endif
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000449 return munmap(base, size) == 0;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000450}
451
452
danno@chromium.org72204d52012-10-31 10:02:10 +0000453bool VirtualMemory::HasLazyCommits() {
454 return true;
455}
456
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000457} } // namespace v8::internal