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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 static Mutex* limit_mutex = NULL; | 73 static Mutex* limit_mutex = NULL; |
74 | 74 |
75 | 75 |
76 static void* GetRandomMmapAddr() { | 76 static void* GetRandomMmapAddr() { |
77 Isolate* isolate = Isolate::UncheckedCurrent(); | 77 Isolate* isolate = Isolate::UncheckedCurrent(); |
78 // Note that the current isolate isn't set up in a call path via | 78 // Note that the current isolate isn't set up in a call path via |
79 // CpuFeatures::Probe. We don't care about randomization in this case because | 79 // CpuFeatures::Probe. We don't care about randomization in this case because |
80 // the code page is immediately freed. | 80 // the code page is immediately freed. |
81 if (isolate != NULL) { | 81 if (isolate != NULL) { |
82 #ifdef V8_TARGET_ARCH_X64 | 82 #if V8_TARGET_ARCH_X64 |
83 uint64_t rnd1 = V8::RandomPrivate(isolate); | 83 uint64_t rnd1 = V8::RandomPrivate(isolate); |
84 uint64_t rnd2 = V8::RandomPrivate(isolate); | 84 uint64_t rnd2 = V8::RandomPrivate(isolate); |
85 uint64_t raw_addr = (rnd1 << 32) ^ rnd2; | 85 uint64_t raw_addr = (rnd1 << 32) ^ rnd2; |
86 // Currently available CPUs have 48 bits of virtual addressing. Truncate | 86 // Currently available CPUs have 48 bits of virtual addressing. Truncate |
87 // the hint address to 46 bits to give the kernel a fighting chance of | 87 // the hint address to 46 bits to give the kernel a fighting chance of |
88 // fulfilling our placement request. | 88 // fulfilling our placement request. |
89 raw_addr &= V8_UINT64_C(0x3ffffffff000); | 89 raw_addr &= V8_UINT64_C(0x3ffffffff000); |
90 #else | 90 #else |
91 uint32_t raw_addr = V8::RandomPrivate(isolate); | 91 uint32_t raw_addr = V8::RandomPrivate(isolate); |
92 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a | 92 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 while (true) { | 713 while (true) { |
714 int result = sem_trywait(&sem_); | 714 int result = sem_trywait(&sem_); |
715 if (result == 0) return true; // Successfully got semaphore. | 715 if (result == 0) return true; // Successfully got semaphore. |
716 if (!to) return false; // Timeout. | 716 if (!to) return false; // Timeout. |
717 CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup. | 717 CHECK(result == -1 && errno == EINTR); // Signal caused spurious wakeup. |
718 usleep(ts.tv_nsec / 1000); | 718 usleep(ts.tv_nsec / 1000); |
719 to--; | 719 to--; |
720 } | 720 } |
721 } | 721 } |
722 | 722 |
| 723 |
723 Semaphore* OS::CreateSemaphore(int count) { | 724 Semaphore* OS::CreateSemaphore(int count) { |
724 return new OpenBSDSemaphore(count); | 725 return new OpenBSDSemaphore(count); |
725 } | 726 } |
726 | 727 |
727 | 728 |
728 void OS::SetUp() { | 729 void OS::SetUp() { |
729 // Seed the random number generator. We preserve microsecond resolution. | 730 // Seed the random number generator. We preserve microsecond resolution. |
730 uint64_t seed = Ticks() ^ (getpid() << 16); | 731 uint64_t seed = Ticks() ^ (getpid() << 16); |
731 srandom(static_cast<unsigned int>(seed)); | 732 srandom(static_cast<unsigned int>(seed)); |
732 limit_mutex = CreateMutex(); | 733 limit_mutex = CreateMutex(); |
733 } | 734 } |
734 | 735 |
735 | 736 |
736 void OS::TearDown() { | 737 void OS::TearDown() { |
737 delete limit_mutex; | 738 delete limit_mutex; |
738 } | 739 } |
739 | 740 |
740 | 741 |
741 } } // namespace v8::internal | 742 } } // namespace v8::internal |
OLD | NEW |