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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 return limit.rlim_cur; | 74 return limit.rlim_cur; |
75 } | 75 } |
76 | 76 |
77 | 77 |
78 intptr_t OS::CommitPageSize() { | 78 intptr_t OS::CommitPageSize() { |
79 static intptr_t page_size = getpagesize(); | 79 static intptr_t page_size = getpagesize(); |
80 return page_size; | 80 return page_size; |
81 } | 81 } |
82 | 82 |
83 | 83 |
84 #ifndef __CYGWIN__ | 84 void OS::Free(void* address, const size_t size) { |
| 85 // TODO(1240712): munmap has a return value which is ignored here. |
| 86 int result = munmap(address, size); |
| 87 USE(result); |
| 88 ASSERT(result == 0); |
| 89 } |
| 90 |
| 91 |
85 // Get rid of writable permission on code allocations. | 92 // Get rid of writable permission on code allocations. |
86 void OS::ProtectCode(void* address, const size_t size) { | 93 void OS::ProtectCode(void* address, const size_t size) { |
87 #if defined(__native_client__) | 94 #if defined(__CYGWIN__) |
| 95 DWORD old_protect; |
| 96 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect); |
| 97 #elif defined(__native_client__) |
88 // The Native Client port of V8 uses an interpreter, so | 98 // The Native Client port of V8 uses an interpreter, so |
89 // code pages don't need PROT_EXEC. | 99 // code pages don't need PROT_EXEC. |
90 mprotect(address, size, PROT_READ); | 100 mprotect(address, size, PROT_READ); |
91 #else | 101 #else |
92 mprotect(address, size, PROT_READ | PROT_EXEC); | 102 mprotect(address, size, PROT_READ | PROT_EXEC); |
93 #endif | 103 #endif |
94 } | 104 } |
95 | 105 |
96 | 106 |
97 // Create guard pages. | 107 // Create guard pages. |
98 void OS::Guard(void* address, const size_t size) { | 108 void OS::Guard(void* address, const size_t size) { |
| 109 #if defined(__CYGWIN__) |
| 110 DWORD oldprotect; |
| 111 VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect); |
| 112 #else |
99 mprotect(address, size, PROT_NONE); | 113 mprotect(address, size, PROT_NONE); |
| 114 #endif |
100 } | 115 } |
101 #endif // __CYGWIN__ | |
102 | 116 |
103 | 117 |
104 void* OS::GetRandomMmapAddr() { | 118 void* OS::GetRandomMmapAddr() { |
105 #if defined(__native_client__) | 119 #if defined(__native_client__) |
106 // TODO(bradchen): restore randomization once Native Client gets | 120 // TODO(bradchen): restore randomization once Native Client gets |
107 // smarter about using mmap address hints. | 121 // smarter about using mmap address hints. |
108 // See http://code.google.com/p/nativeclient/issues/3341 | 122 // See http://code.google.com/p/nativeclient/issues/3341 |
109 return NULL; | 123 return NULL; |
110 #endif | 124 #endif |
111 Isolate* isolate = Isolate::UncheckedCurrent(); | 125 Isolate* isolate = Isolate::UncheckedCurrent(); |
(...skipping 16 matching lines...) Expand all Loading... |
128 // 10.6 and 10.7. | 142 // 10.6 and 10.7. |
129 raw_addr &= 0x3ffff000; | 143 raw_addr &= 0x3ffff000; |
130 raw_addr += 0x20000000; | 144 raw_addr += 0x20000000; |
131 #endif | 145 #endif |
132 return reinterpret_cast<void*>(raw_addr); | 146 return reinterpret_cast<void*>(raw_addr); |
133 } | 147 } |
134 return NULL; | 148 return NULL; |
135 } | 149 } |
136 | 150 |
137 | 151 |
| 152 size_t OS::AllocateAlignment() { |
| 153 return getpagesize(); |
| 154 } |
| 155 |
| 156 |
| 157 void OS::Sleep(int milliseconds) { |
| 158 useconds_t ms = static_cast<useconds_t>(milliseconds); |
| 159 usleep(1000 * ms); |
| 160 } |
| 161 |
| 162 |
| 163 int OS::NumberOfCores() { |
| 164 return sysconf(_SC_NPROCESSORS_ONLN); |
| 165 } |
| 166 |
| 167 |
| 168 void OS::Abort() { |
| 169 // Redirect to std abort to signal abnormal program termination. |
| 170 if (FLAG_break_on_abort) { |
| 171 DebugBreak(); |
| 172 } |
| 173 abort(); |
| 174 } |
| 175 |
| 176 |
| 177 void OS::DebugBreak() { |
| 178 #if V8_HOST_ARCH_ARM |
| 179 asm("bkpt 0"); |
| 180 #elif V8_HOST_ARCH_MIPS |
| 181 asm("break"); |
| 182 #elif V8_HOST_ARCH_IA32 |
| 183 #if defined(__native_client__) |
| 184 asm("hlt"); |
| 185 #else |
| 186 asm("int $3"); |
| 187 #endif // __native_client__ |
| 188 #elif V8_HOST_ARCH_X64 |
| 189 asm("int $3"); |
| 190 #else |
| 191 #error Unsupported host architecture. |
| 192 #endif |
| 193 } |
| 194 |
| 195 |
138 // ---------------------------------------------------------------------------- | 196 // ---------------------------------------------------------------------------- |
139 // Math functions | 197 // Math functions |
140 | 198 |
141 double modulo(double x, double y) { | 199 double modulo(double x, double y) { |
142 return fmod(x, y); | 200 return fmod(x, y); |
143 } | 201 } |
144 | 202 |
145 | 203 |
146 #define UNARY_MATH_FUNCTION(name, generator) \ | 204 #define UNARY_MATH_FUNCTION(name, generator) \ |
147 static UnaryMathFunction fast_##name##_function = NULL; \ | 205 static UnaryMathFunction fast_##name##_function = NULL; \ |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 OS::MemCopyUint16Uint8Function OS::memcopy_uint16_uint8_function = | 422 OS::MemCopyUint16Uint8Function OS::memcopy_uint16_uint8_function = |
365 &OS::MemCopyUint16Uint8Wrapper; | 423 &OS::MemCopyUint16Uint8Wrapper; |
366 // Defined in codegen-arm.cc. | 424 // Defined in codegen-arm.cc. |
367 OS::MemCopyUint8Function CreateMemCopyUint8Function( | 425 OS::MemCopyUint8Function CreateMemCopyUint8Function( |
368 OS::MemCopyUint8Function stub); | 426 OS::MemCopyUint8Function stub); |
369 OS::MemCopyUint16Uint8Function CreateMemCopyUint16Uint8Function( | 427 OS::MemCopyUint16Uint8Function CreateMemCopyUint16Uint8Function( |
370 OS::MemCopyUint16Uint8Function stub); | 428 OS::MemCopyUint16Uint8Function stub); |
371 #endif | 429 #endif |
372 | 430 |
373 | 431 |
374 void POSIXPostSetUp() { | 432 void OS::PostSetUp() { |
375 #if V8_TARGET_ARCH_IA32 | 433 #if V8_TARGET_ARCH_IA32 |
376 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); | 434 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); |
377 if (generated_memmove != NULL) { | 435 if (generated_memmove != NULL) { |
378 memmove_function = generated_memmove; | 436 memmove_function = generated_memmove; |
379 } | 437 } |
380 #elif defined(V8_HOST_ARCH_ARM) | 438 #elif defined(V8_HOST_ARCH_ARM) |
381 OS::memcopy_uint8_function = | 439 OS::memcopy_uint8_function = |
382 CreateMemCopyUint8Function(&OS::MemCopyUint8Wrapper); | 440 CreateMemCopyUint8Function(&OS::MemCopyUint8Wrapper); |
383 OS::memcopy_uint16_uint8_function = | 441 OS::memcopy_uint16_uint8_function = |
384 CreateMemCopyUint16Uint8Function(&OS::MemCopyUint16Uint8Wrapper); | 442 CreateMemCopyUint16Uint8Function(&OS::MemCopyUint16Uint8Wrapper); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 return ntohl(value); | 707 return ntohl(value); |
650 } | 708 } |
651 | 709 |
652 | 710 |
653 Socket* OS::CreateSocket() { | 711 Socket* OS::CreateSocket() { |
654 return new POSIXSocket(); | 712 return new POSIXSocket(); |
655 } | 713 } |
656 | 714 |
657 | 715 |
658 } } // namespace v8::internal | 716 } } // namespace v8::internal |
OLD | NEW |