| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Platform-specific code for Linux goes here. For the POSIX-compatible | 5 // Platform-specific code for Linux goes here. For the POSIX-compatible |
| 6 // parts, the implementation is in platform-posix.cc. | 6 // parts, the implementation is in platform-posix.cc. |
| 7 | 7 |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 #include <semaphore.h> | 9 #include <semaphore.h> |
| 10 #include <signal.h> | 10 #include <signal.h> |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 #if defined(__native_client__) | 265 #if defined(__native_client__) |
| 266 // The Native Client port of V8 uses an interpreter, | 266 // The Native Client port of V8 uses an interpreter, |
| 267 // so code pages don't need PROT_EXEC. | 267 // so code pages don't need PROT_EXEC. |
| 268 PROT_READ, | 268 PROT_READ, |
| 269 #else | 269 #else |
| 270 PROT_READ | PROT_EXEC, | 270 PROT_READ | PROT_EXEC, |
| 271 #endif | 271 #endif |
| 272 MAP_PRIVATE, | 272 MAP_PRIVATE, |
| 273 fileno(f), | 273 fileno(f), |
| 274 0); | 274 0); |
| 275 ASSERT(addr != MAP_FAILED); | 275 DCHECK(addr != MAP_FAILED); |
| 276 OS::Free(addr, size); | 276 OS::Free(addr, size); |
| 277 fclose(f); | 277 fclose(f); |
| 278 } | 278 } |
| 279 | 279 |
| 280 | 280 |
| 281 // Constants used for mmap. | 281 // Constants used for mmap. |
| 282 static const int kMmapFd = -1; | 282 static const int kMmapFd = -1; |
| 283 static const int kMmapFdOffset = 0; | 283 static const int kMmapFdOffset = 0; |
| 284 | 284 |
| 285 | 285 |
| 286 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } | 286 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } |
| 287 | 287 |
| 288 | 288 |
| 289 VirtualMemory::VirtualMemory(size_t size) | 289 VirtualMemory::VirtualMemory(size_t size) |
| 290 : address_(ReserveRegion(size)), size_(size) { } | 290 : address_(ReserveRegion(size)), size_(size) { } |
| 291 | 291 |
| 292 | 292 |
| 293 VirtualMemory::VirtualMemory(size_t size, size_t alignment) | 293 VirtualMemory::VirtualMemory(size_t size, size_t alignment) |
| 294 : address_(NULL), size_(0) { | 294 : address_(NULL), size_(0) { |
| 295 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); | 295 DCHECK(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); |
| 296 size_t request_size = RoundUp(size + alignment, | 296 size_t request_size = RoundUp(size + alignment, |
| 297 static_cast<intptr_t>(OS::AllocateAlignment())); | 297 static_cast<intptr_t>(OS::AllocateAlignment())); |
| 298 void* reservation = mmap(OS::GetRandomMmapAddr(), | 298 void* reservation = mmap(OS::GetRandomMmapAddr(), |
| 299 request_size, | 299 request_size, |
| 300 PROT_NONE, | 300 PROT_NONE, |
| 301 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, | 301 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, |
| 302 kMmapFd, | 302 kMmapFd, |
| 303 kMmapFdOffset); | 303 kMmapFdOffset); |
| 304 if (reservation == MAP_FAILED) return; | 304 if (reservation == MAP_FAILED) return; |
| 305 | 305 |
| 306 uint8_t* base = static_cast<uint8_t*>(reservation); | 306 uint8_t* base = static_cast<uint8_t*>(reservation); |
| 307 uint8_t* aligned_base = RoundUp(base, alignment); | 307 uint8_t* aligned_base = RoundUp(base, alignment); |
| 308 ASSERT_LE(base, aligned_base); | 308 DCHECK_LE(base, aligned_base); |
| 309 | 309 |
| 310 // Unmap extra memory reserved before and after the desired block. | 310 // Unmap extra memory reserved before and after the desired block. |
| 311 if (aligned_base != base) { | 311 if (aligned_base != base) { |
| 312 size_t prefix_size = static_cast<size_t>(aligned_base - base); | 312 size_t prefix_size = static_cast<size_t>(aligned_base - base); |
| 313 OS::Free(base, prefix_size); | 313 OS::Free(base, prefix_size); |
| 314 request_size -= prefix_size; | 314 request_size -= prefix_size; |
| 315 } | 315 } |
| 316 | 316 |
| 317 size_t aligned_size = RoundUp(size, OS::AllocateAlignment()); | 317 size_t aligned_size = RoundUp(size, OS::AllocateAlignment()); |
| 318 ASSERT_LE(aligned_size, request_size); | 318 DCHECK_LE(aligned_size, request_size); |
| 319 | 319 |
| 320 if (aligned_size != request_size) { | 320 if (aligned_size != request_size) { |
| 321 size_t suffix_size = request_size - aligned_size; | 321 size_t suffix_size = request_size - aligned_size; |
| 322 OS::Free(aligned_base + aligned_size, suffix_size); | 322 OS::Free(aligned_base + aligned_size, suffix_size); |
| 323 request_size -= suffix_size; | 323 request_size -= suffix_size; |
| 324 } | 324 } |
| 325 | 325 |
| 326 ASSERT(aligned_size == request_size); | 326 DCHECK(aligned_size == request_size); |
| 327 | 327 |
| 328 address_ = static_cast<void*>(aligned_base); | 328 address_ = static_cast<void*>(aligned_base); |
| 329 size_ = aligned_size; | 329 size_ = aligned_size; |
| 330 #if defined(LEAK_SANITIZER) | 330 #if defined(LEAK_SANITIZER) |
| 331 __lsan_register_root_region(address_, size_); | 331 __lsan_register_root_region(address_, size_); |
| 332 #endif | 332 #endif |
| 333 } | 333 } |
| 334 | 334 |
| 335 | 335 |
| 336 VirtualMemory::~VirtualMemory() { | 336 VirtualMemory::~VirtualMemory() { |
| 337 if (IsReserved()) { | 337 if (IsReserved()) { |
| 338 bool result = ReleaseRegion(address(), size()); | 338 bool result = ReleaseRegion(address(), size()); |
| 339 ASSERT(result); | 339 DCHECK(result); |
| 340 USE(result); | 340 USE(result); |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 | 343 |
| 344 | 344 |
| 345 bool VirtualMemory::IsReserved() { | 345 bool VirtualMemory::IsReserved() { |
| 346 return address_ != NULL; | 346 return address_ != NULL; |
| 347 } | 347 } |
| 348 | 348 |
| 349 | 349 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 #endif | 423 #endif |
| 424 return munmap(base, size) == 0; | 424 return munmap(base, size) == 0; |
| 425 } | 425 } |
| 426 | 426 |
| 427 | 427 |
| 428 bool VirtualMemory::HasLazyCommits() { | 428 bool VirtualMemory::HasLazyCommits() { |
| 429 return true; | 429 return true; |
| 430 } | 430 } |
| 431 | 431 |
| 432 } } // namespace v8::base | 432 } } // namespace v8::base |
| OLD | NEW |