| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 | 72 |
| 73 double ceiling(double x) { | 73 double ceiling(double x) { |
| 74 return ceil(x); | 74 return ceil(x); |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 static Mutex* limit_mutex = NULL; | 78 static Mutex* limit_mutex = NULL; |
| 79 | 79 |
| 80 | 80 |
| 81 static void* GetRandomMmapAddr() { |
| 82 Isolate* isolate; |
| 83 // Note that the current isolate isn't set up in a call path via |
| 84 // CpuFeatures::Probe. We don't care about randomization in this case because |
| 85 // the code page is immediately freed. |
| 86 if (sizeof(void*) == 8 && (isolate = Isolate::UncheckedCurrent())) { |
| 87 uint32_t rnd1 = V8::RandomPrivate(isolate); |
| 88 uint32_t rnd2 = V8::RandomPrivate(isolate); |
| 89 uint64_t raw_addr = (static_cast<uint64_t>(rnd1) << 33) | |
| 90 (static_cast<uint64_t>(rnd2) << 2); |
| 91 raw_addr &= 0x00003ffffffff000ULL; |
| 92 return reinterpret_cast<void*>(raw_addr); |
| 93 } else { |
| 94 return NULL; |
| 95 } |
| 96 } |
| 97 |
| 98 |
| 81 void OS::Setup() { | 99 void OS::Setup() { |
| 82 // Seed the random number generator. | 100 // Seed the random number generator. |
| 83 // Convert the current time to a 64-bit integer first, before converting it | 101 // Convert the current time to a 64-bit integer first, before converting it |
| 84 // to an unsigned. Going directly can cause an overflow and the seed to be | 102 // to an unsigned. Going directly can cause an overflow and the seed to be |
| 85 // set to all ones. The seed will be identical for different instances that | 103 // set to all ones. The seed will be identical for different instances that |
| 86 // call this setup code within the same millisecond. | 104 // call this setup code within the same millisecond. |
| 87 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); | 105 uint64_t seed = Ticks() | (getpid() << 16); |
| 88 srandom(static_cast<unsigned int>(seed)); | 106 srandom(static_cast<unsigned int>(seed)); |
| 89 limit_mutex = CreateMutex(); | 107 limit_mutex = CreateMutex(); |
| 90 | 108 |
| 91 #ifdef __arm__ | 109 #ifdef __arm__ |
| 92 // When running on ARM hardware check that the EABI used by V8 and | 110 // When running on ARM hardware check that the EABI used by V8 and |
| 93 // by the C code is the same. | 111 // by the C code is the same. |
| 94 bool hard_float = OS::ArmUsingHardFloat(); | 112 bool hard_float = OS::ArmUsingHardFloat(); |
| 95 if (hard_float) { | 113 if (hard_float) { |
| 96 #if !USE_EABI_HARDFLOAT | 114 #if !USE_EABI_HARDFLOAT |
| 97 PrintF("ERROR: Binary compiled with -mfloat-abi=hard but without " | 115 PrintF("ERROR: Binary compiled with -mfloat-abi=hard but without " |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 378 |
| 361 | 379 |
| 362 size_t OS::AllocateAlignment() { | 380 size_t OS::AllocateAlignment() { |
| 363 return sysconf(_SC_PAGESIZE); | 381 return sysconf(_SC_PAGESIZE); |
| 364 } | 382 } |
| 365 | 383 |
| 366 | 384 |
| 367 void* OS::Allocate(const size_t requested, | 385 void* OS::Allocate(const size_t requested, |
| 368 size_t* allocated, | 386 size_t* allocated, |
| 369 bool is_executable) { | 387 bool is_executable) { |
| 370 // TODO(805): Port randomization of allocated executable memory to Linux. | |
| 371 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE)); | 388 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE)); |
| 372 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); | 389 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); |
| 373 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 390 void* addr = GetRandomMmapAddr(); |
| 391 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 374 if (mbase == MAP_FAILED) { | 392 if (mbase == MAP_FAILED) { |
| 375 LOG(i::Isolate::Current(), | 393 LOG(i::Isolate::Current(), |
| 376 StringEvent("OS::Allocate", "mmap failed")); | 394 StringEvent("OS::Allocate", "mmap failed")); |
| 377 return NULL; | 395 return NULL; |
| 378 } | 396 } |
| 379 *allocated = msize; | 397 *allocated = msize; |
| 380 UpdateAllocatedSpaceLimits(mbase, msize); | 398 UpdateAllocatedSpaceLimits(mbase, msize); |
| 381 return mbase; | 399 return mbase; |
| 382 } | 400 } |
| 383 | 401 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 #endif // ndef __GLIBC__ | 597 #endif // ndef __GLIBC__ |
| 580 } | 598 } |
| 581 | 599 |
| 582 | 600 |
| 583 // Constants used for mmap. | 601 // Constants used for mmap. |
| 584 static const int kMmapFd = -1; | 602 static const int kMmapFd = -1; |
| 585 static const int kMmapFdOffset = 0; | 603 static const int kMmapFdOffset = 0; |
| 586 | 604 |
| 587 | 605 |
| 588 VirtualMemory::VirtualMemory(size_t size) { | 606 VirtualMemory::VirtualMemory(size_t size) { |
| 589 address_ = mmap(NULL, size, PROT_NONE, | 607 address_ = mmap(GetRandomMmapAddr(), size, PROT_NONE, |
| 590 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, | 608 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, |
| 591 kMmapFd, kMmapFdOffset); | 609 kMmapFd, kMmapFdOffset); |
| 592 size_ = size; | 610 size_ = size; |
| 593 } | 611 } |
| 594 | 612 |
| 595 | 613 |
| 596 VirtualMemory::~VirtualMemory() { | 614 VirtualMemory::~VirtualMemory() { |
| 597 if (IsReserved()) { | 615 if (IsReserved()) { |
| 598 if (0 == munmap(address(), size())) address_ = MAP_FAILED; | 616 if (0 == munmap(address(), size())) address_ = MAP_FAILED; |
| 599 } | 617 } |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 | 1138 |
| 1121 | 1139 |
| 1122 void Sampler::Stop() { | 1140 void Sampler::Stop() { |
| 1123 ASSERT(IsActive()); | 1141 ASSERT(IsActive()); |
| 1124 SignalSender::RemoveActiveSampler(this); | 1142 SignalSender::RemoveActiveSampler(this); |
| 1125 SetActive(false); | 1143 SetActive(false); |
| 1126 } | 1144 } |
| 1127 | 1145 |
| 1128 | 1146 |
| 1129 } } // namespace v8::internal | 1147 } } // namespace v8::internal |
| OLD | NEW |