| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "vm-state-inl.h" | 57 #include "vm-state-inl.h" |
| 58 | 58 |
| 59 | 59 |
| 60 namespace v8 { | 60 namespace v8 { |
| 61 namespace internal { | 61 namespace internal { |
| 62 | 62 |
| 63 | 63 |
| 64 static Mutex* limit_mutex = NULL; | 64 static Mutex* limit_mutex = NULL; |
| 65 | 65 |
| 66 | 66 |
| 67 static void* GetRandomMmapAddr() { | |
| 68 Isolate* isolate = Isolate::UncheckedCurrent(); | |
| 69 // Note that the current isolate isn't set up in a call path via | |
| 70 // CpuFeatures::Probe. We don't care about randomization in this case because | |
| 71 // the code page is immediately freed. | |
| 72 if (isolate != NULL) { | |
| 73 #if V8_TARGET_ARCH_X64 | |
| 74 uint64_t rnd1 = V8::RandomPrivate(isolate); | |
| 75 uint64_t rnd2 = V8::RandomPrivate(isolate); | |
| 76 uint64_t raw_addr = (rnd1 << 32) ^ rnd2; | |
| 77 // Currently available CPUs have 48 bits of virtual addressing. Truncate | |
| 78 // the hint address to 46 bits to give the kernel a fighting chance of | |
| 79 // fulfilling our placement request. | |
| 80 raw_addr &= V8_UINT64_C(0x3ffffffff000); | |
| 81 #else | |
| 82 uint32_t raw_addr = V8::RandomPrivate(isolate); | |
| 83 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a | |
| 84 // variety of ASLR modes (PAE kernel, NX compat mode, etc). | |
| 85 raw_addr &= 0x3ffff000; | |
| 86 raw_addr += 0x20000000; | |
| 87 #endif | |
| 88 return reinterpret_cast<void*>(raw_addr); | |
| 89 } | |
| 90 return NULL; | |
| 91 } | |
| 92 | |
| 93 | |
| 94 int OS::ActivationFrameAlignment() { | 67 int OS::ActivationFrameAlignment() { |
| 95 // With gcc 4.4 the tree vectorization optimizer can generate code | 68 // With gcc 4.4 the tree vectorization optimizer can generate code |
| 96 // that requires 16 byte alignment such as movdqa on x86. | 69 // that requires 16 byte alignment such as movdqa on x86. |
| 97 return 16; | 70 return 16; |
| 98 } | 71 } |
| 99 | 72 |
| 100 | 73 |
| 101 const char* OS::LocalTimezone(double time) { | 74 const char* OS::LocalTimezone(double time) { |
| 102 if (std::isnan(time)) return ""; | 75 if (std::isnan(time)) return ""; |
| 103 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); | 76 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 bool OS::IsOutsideAllocatedSpace(void* address) { | 112 bool OS::IsOutsideAllocatedSpace(void* address) { |
| 140 return address < lowest_ever_allocated || address >= highest_ever_allocated; | 113 return address < lowest_ever_allocated || address >= highest_ever_allocated; |
| 141 } | 114 } |
| 142 | 115 |
| 143 | 116 |
| 144 void* OS::Allocate(const size_t requested, | 117 void* OS::Allocate(const size_t requested, |
| 145 size_t* allocated, | 118 size_t* allocated, |
| 146 bool is_executable) { | 119 bool is_executable) { |
| 147 const size_t msize = RoundUp(requested, AllocateAlignment()); | 120 const size_t msize = RoundUp(requested, AllocateAlignment()); |
| 148 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); | 121 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); |
| 149 void* addr = GetRandomMmapAddr(); | 122 void* addr = OS::GetRandomMmapAddr(); |
| 150 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0); | 123 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0); |
| 151 if (mbase == MAP_FAILED) { | 124 if (mbase == MAP_FAILED) { |
| 152 LOG(i::Isolate::Current(), | 125 LOG(i::Isolate::Current(), |
| 153 StringEvent("OS::Allocate", "mmap failed")); | 126 StringEvent("OS::Allocate", "mmap failed")); |
| 154 return NULL; | 127 return NULL; |
| 155 } | 128 } |
| 156 *allocated = msize; | 129 *allocated = msize; |
| 157 UpdateAllocatedSpaceLimits(mbase, msize); | 130 UpdateAllocatedSpaceLimits(mbase, msize); |
| 158 return mbase; | 131 return mbase; |
| 159 } | 132 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 307 |
| 335 VirtualMemory::VirtualMemory(size_t size) | 308 VirtualMemory::VirtualMemory(size_t size) |
| 336 : address_(ReserveRegion(size)), size_(size) { } | 309 : address_(ReserveRegion(size)), size_(size) { } |
| 337 | 310 |
| 338 | 311 |
| 339 VirtualMemory::VirtualMemory(size_t size, size_t alignment) | 312 VirtualMemory::VirtualMemory(size_t size, size_t alignment) |
| 340 : address_(NULL), size_(0) { | 313 : address_(NULL), size_(0) { |
| 341 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); | 314 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); |
| 342 size_t request_size = RoundUp(size + alignment, | 315 size_t request_size = RoundUp(size + alignment, |
| 343 static_cast<intptr_t>(OS::AllocateAlignment())); | 316 static_cast<intptr_t>(OS::AllocateAlignment())); |
| 344 void* reservation = mmap(GetRandomMmapAddr(), | 317 void* reservation = mmap(OS::GetRandomMmapAddr(), |
| 345 request_size, | 318 request_size, |
| 346 PROT_NONE, | 319 PROT_NONE, |
| 347 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, | 320 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, |
| 348 kMmapFd, | 321 kMmapFd, |
| 349 kMmapFdOffset); | 322 kMmapFdOffset); |
| 350 if (reservation == MAP_FAILED) return; | 323 if (reservation == MAP_FAILED) return; |
| 351 | 324 |
| 352 Address base = static_cast<Address>(reservation); | 325 Address base = static_cast<Address>(reservation); |
| 353 Address aligned_base = RoundUp(base, alignment); | 326 Address aligned_base = RoundUp(base, alignment); |
| 354 ASSERT_LE(base, aligned_base); | 327 ASSERT_LE(base, aligned_base); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 } | 379 } |
| 407 | 380 |
| 408 | 381 |
| 409 bool VirtualMemory::Guard(void* address) { | 382 bool VirtualMemory::Guard(void* address) { |
| 410 OS::Guard(address, OS::CommitPageSize()); | 383 OS::Guard(address, OS::CommitPageSize()); |
| 411 return true; | 384 return true; |
| 412 } | 385 } |
| 413 | 386 |
| 414 | 387 |
| 415 void* VirtualMemory::ReserveRegion(size_t size) { | 388 void* VirtualMemory::ReserveRegion(size_t size) { |
| 416 void* result = mmap(GetRandomMmapAddr(), | 389 void* result = mmap(OS::GetRandomMmapAddr(), |
| 417 size, | 390 size, |
| 418 PROT_NONE, | 391 PROT_NONE, |
| 419 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, | 392 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, |
| 420 kMmapFd, | 393 kMmapFd, |
| 421 kMmapFdOffset); | 394 kMmapFdOffset); |
| 422 | 395 |
| 423 if (result == MAP_FAILED) return NULL; | 396 if (result == MAP_FAILED) return NULL; |
| 424 | 397 |
| 425 return result; | 398 return result; |
| 426 } | 399 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 limit_mutex = CreateMutex(); | 512 limit_mutex = CreateMutex(); |
| 540 } | 513 } |
| 541 | 514 |
| 542 | 515 |
| 543 void OS::TearDown() { | 516 void OS::TearDown() { |
| 544 delete limit_mutex; | 517 delete limit_mutex; |
| 545 } | 518 } |
| 546 | 519 |
| 547 | 520 |
| 548 } } // namespace v8::internal | 521 } } // namespace v8::internal |
| OLD | NEW |