Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: src/platform-posix.cc

Issue 127643002: Convert some ifdefs to use their V8_OS_* macros equivalents. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 void OS::Free(void* address, const size_t size) { 176 void OS::Free(void* address, const size_t size) {
177 // TODO(1240712): munmap has a return value which is ignored here. 177 // TODO(1240712): munmap has a return value which is ignored here.
178 int result = munmap(address, size); 178 int result = munmap(address, size);
179 USE(result); 179 USE(result);
180 ASSERT(result == 0); 180 ASSERT(result == 0);
181 } 181 }
182 182
183 183
184 // Get rid of writable permission on code allocations. 184 // Get rid of writable permission on code allocations.
185 void OS::ProtectCode(void* address, const size_t size) { 185 void OS::ProtectCode(void* address, const size_t size) {
186 #if defined(__CYGWIN__) 186 #if V8_OS_CYGWIN
187 DWORD old_protect; 187 DWORD old_protect;
188 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect); 188 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect);
189 #elif defined(__native_client__) 189 #elif V8_OS_NACL
190 // The Native Client port of V8 uses an interpreter, so 190 // The Native Client port of V8 uses an interpreter, so
191 // code pages don't need PROT_EXEC. 191 // code pages don't need PROT_EXEC.
192 mprotect(address, size, PROT_READ); 192 mprotect(address, size, PROT_READ);
193 #else 193 #else
194 mprotect(address, size, PROT_READ | PROT_EXEC); 194 mprotect(address, size, PROT_READ | PROT_EXEC);
195 #endif 195 #endif
196 } 196 }
197 197
198 198
199 // Create guard pages. 199 // Create guard pages.
200 void OS::Guard(void* address, const size_t size) { 200 void OS::Guard(void* address, const size_t size) {
201 #if defined(__CYGWIN__) 201 #if V8_OS_CYGWIN
202 DWORD oldprotect; 202 DWORD oldprotect;
203 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect); 203 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect);
204 #else 204 #else
205 mprotect(address, size, PROT_NONE); 205 mprotect(address, size, PROT_NONE);
206 #endif 206 #endif
207 } 207 }
208 208
209 209
210 void* OS::GetRandomMmapAddr() { 210 void* OS::GetRandomMmapAddr() {
211 #if defined(__native_client__) 211 #if V8_OS_NACL
212 // TODO(bradchen): restore randomization once Native Client gets 212 // TODO(bradchen): restore randomization once Native Client gets
213 // smarter about using mmap address hints. 213 // smarter about using mmap address hints.
214 // See http://code.google.com/p/nativeclient/issues/3341 214 // See http://code.google.com/p/nativeclient/issues/3341
215 return NULL; 215 return NULL;
216 #endif 216 #endif
217 Isolate* isolate = Isolate::UncheckedCurrent(); 217 Isolate* isolate = Isolate::UncheckedCurrent();
218 // Note that the current isolate isn't set up in a call path via 218 // Note that the current isolate isn't set up in a call path via
219 // CpuFeatures::Probe. We don't care about randomization in this case because 219 // CpuFeatures::Probe. We don't care about randomization in this case because
220 // the code page is immediately freed. 220 // the code page is immediately freed.
221 if (isolate != NULL) { 221 if (isolate != NULL) {
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // Copy memory area. No restrictions. 485 // Copy memory area. No restrictions.
486 void OS::MemMove(void* dest, const void* src, size_t size) { 486 void OS::MemMove(void* dest, const void* src, size_t size) {
487 if (size == 0) return; 487 if (size == 0) return;
488 // Note: here we rely on dependent reads being ordered. This is true 488 // Note: here we rely on dependent reads being ordered. This is true
489 // on all architectures we currently support. 489 // on all architectures we currently support.
490 (*memmove_function)(dest, src, size); 490 (*memmove_function)(dest, src, size);
491 } 491 }
492 492
493 #elif defined(V8_HOST_ARCH_ARM) 493 #elif defined(V8_HOST_ARCH_ARM)
494 void OS::MemCopyUint16Uint8Wrapper(uint16_t* dest, 494 void OS::MemCopyUint16Uint8Wrapper(uint16_t* dest,
495 const uint8_t* src, 495 const uint8_t* src,
496 size_t chars) { 496 size_t chars) {
497 uint16_t *limit = dest + chars; 497 uint16_t *limit = dest + chars;
498 while (dest < limit) { 498 while (dest < limit) {
499 *dest++ = static_cast<uint16_t>(*src++); 499 *dest++ = static_cast<uint16_t>(*src++);
500 } 500 }
501 } 501 }
502 502
503 503
504 OS::MemCopyUint8Function OS::memcopy_uint8_function = &OS::MemCopyUint8Wrapper; 504 OS::MemCopyUint8Function OS::memcopy_uint8_function = &OS::MemCopyUint8Wrapper;
505 OS::MemCopyUint16Uint8Function OS::memcopy_uint16_uint8_function = 505 OS::MemCopyUint16Uint8Function OS::memcopy_uint16_uint8_function =
506 &OS::MemCopyUint16Uint8Wrapper; 506 &OS::MemCopyUint16Uint8Wrapper;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 set_name(options.name()); 572 set_name(options.name());
573 } 573 }
574 574
575 575
576 Thread::~Thread() { 576 Thread::~Thread() {
577 delete data_; 577 delete data_;
578 } 578 }
579 579
580 580
581 static void SetThreadName(const char* name) { 581 static void SetThreadName(const char* name) {
582 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) 582 #if V8_OS_DRAGONFLYBSD || V8_OS_FREEBSD || V8_OS_OPENBSD
583 pthread_set_name_np(pthread_self(), name); 583 pthread_set_name_np(pthread_self(), name);
584 #elif defined(__NetBSD__) 584 #elif V8_OS_NETBSD
585 STATIC_ASSERT(Thread::kMaxThreadNameLength <= PTHREAD_MAX_NAMELEN_NP); 585 STATIC_ASSERT(Thread::kMaxThreadNameLength <= PTHREAD_MAX_NAMELEN_NP);
586 pthread_setname_np(pthread_self(), "%s", name); 586 pthread_setname_np(pthread_self(), "%s", name);
587 #elif defined(__APPLE__) 587 #elif V8_OS_MACOSX
588 // pthread_setname_np is only available in 10.6 or later, so test 588 // pthread_setname_np is only available in 10.6 or later, so test
589 // for it at runtime. 589 // for it at runtime.
590 int (*dynamic_pthread_setname_np)(const char*); 590 int (*dynamic_pthread_setname_np)(const char*);
591 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = 591 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) =
592 dlsym(RTLD_DEFAULT, "pthread_setname_np"); 592 dlsym(RTLD_DEFAULT, "pthread_setname_np");
593 if (dynamic_pthread_setname_np == NULL) 593 if (dynamic_pthread_setname_np == NULL)
594 return; 594 return;
595 595
596 // Mac OS X does not expose the length limit of the name, so hardcode it. 596 // Mac OS X does not expose the length limit of the name, so hardcode it.
597 static const int kMaxNameLength = 63; 597 static const int kMaxNameLength = 63;
(...skipping 26 matching lines...) Expand all
624 } 624 }
625 625
626 626
627 void Thread::Start() { 627 void Thread::Start() {
628 int result; 628 int result;
629 pthread_attr_t attr; 629 pthread_attr_t attr;
630 memset(&attr, 0, sizeof(attr)); 630 memset(&attr, 0, sizeof(attr));
631 result = pthread_attr_init(&attr); 631 result = pthread_attr_init(&attr);
632 ASSERT_EQ(0, result); 632 ASSERT_EQ(0, result);
633 // Native client uses default stack size. 633 // Native client uses default stack size.
634 #if !defined(__native_client__) 634 #if !V8_OS_NACL
635 if (stack_size_ > 0) { 635 if (stack_size_ > 0) {
636 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); 636 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
637 ASSERT_EQ(0, result); 637 ASSERT_EQ(0, result);
638 } 638 }
639 #endif 639 #endif
640 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this); 640 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this);
641 ASSERT_EQ(0, result); 641 ASSERT_EQ(0, result);
642 result = pthread_attr_destroy(&attr); 642 result = pthread_attr_destroy(&attr);
643 ASSERT_EQ(0, result); 643 ASSERT_EQ(0, result);
644 ASSERT(data_->thread_ != kNoThread); 644 ASSERT(data_->thread_ != kNoThread);
645 USE(result); 645 USE(result);
646 } 646 }
647 647
648 648
649 void Thread::Join() { 649 void Thread::Join() {
650 pthread_join(data_->thread_, NULL); 650 pthread_join(data_->thread_, NULL);
651 } 651 }
652 652
653 653
654 void Thread::YieldCPU() { 654 void Thread::YieldCPU() {
655 int result = sched_yield(); 655 int result = sched_yield();
656 ASSERT_EQ(0, result); 656 ASSERT_EQ(0, result);
657 USE(result); 657 USE(result);
658 } 658 }
659 659
660 660
661 static Thread::LocalStorageKey PthreadKeyToLocalKey(pthread_key_t pthread_key) { 661 static Thread::LocalStorageKey PthreadKeyToLocalKey(pthread_key_t pthread_key) {
662 #if defined(__CYGWIN__) 662 #if V8_OS_CYGWIN
663 // We need to cast pthread_key_t to Thread::LocalStorageKey in two steps 663 // We need to cast pthread_key_t to Thread::LocalStorageKey in two steps
664 // because pthread_key_t is a pointer type on Cygwin. This will probably not 664 // because pthread_key_t is a pointer type on Cygwin. This will probably not
665 // work on 64-bit platforms, but Cygwin doesn't support 64-bit anyway. 665 // work on 64-bit platforms, but Cygwin doesn't support 64-bit anyway.
666 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); 666 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t));
667 intptr_t ptr_key = reinterpret_cast<intptr_t>(pthread_key); 667 intptr_t ptr_key = reinterpret_cast<intptr_t>(pthread_key);
668 return static_cast<Thread::LocalStorageKey>(ptr_key); 668 return static_cast<Thread::LocalStorageKey>(ptr_key);
669 #else 669 #else
670 return static_cast<Thread::LocalStorageKey>(pthread_key); 670 return static_cast<Thread::LocalStorageKey>(pthread_key);
671 #endif 671 #endif
672 } 672 }
673 673
674 674
675 static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key) { 675 static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key) {
676 #if defined(__CYGWIN__) 676 #if V8_OS_CYGWIN
677 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); 677 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t));
678 intptr_t ptr_key = static_cast<intptr_t>(local_key); 678 intptr_t ptr_key = static_cast<intptr_t>(local_key);
679 return reinterpret_cast<pthread_key_t>(ptr_key); 679 return reinterpret_cast<pthread_key_t>(ptr_key);
680 #else 680 #else
681 return static_cast<pthread_key_t>(local_key); 681 return static_cast<pthread_key_t>(local_key);
682 #endif 682 #endif
683 } 683 }
684 684
685 685
686 #ifdef V8_FAST_TLS_SUPPORTED 686 #ifdef V8_FAST_TLS_SUPPORTED
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 776
777 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { 777 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
778 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); 778 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
779 int result = pthread_setspecific(pthread_key, value); 779 int result = pthread_setspecific(pthread_key, value);
780 ASSERT_EQ(0, result); 780 ASSERT_EQ(0, result);
781 USE(result); 781 USE(result);
782 } 782 }
783 783
784 784
785 } } // namespace v8::internal 785 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698