Changeset 74360 in webkit for trunk/JavaScriptCore/runtime/Collector.cpp
- Timestamp:
- Dec 20, 2010, 1:16:14 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/Collector.cpp
r73623 r74360 390 390 } 391 391 392 #if OS(WINCE)393 JS_EXPORTDATA void* g_stackBase = 0;394 395 inline bool isPageWritable(void* page)396 {397 MEMORY_BASIC_INFORMATION memoryInformation;398 DWORD result = VirtualQuery(page, &memoryInformation, sizeof(memoryInformation));399 400 // return false on error, including ptr outside memory401 if (result != sizeof(memoryInformation))402 return false;403 404 DWORD protect = memoryInformation.Protect & ~(PAGE_GUARD | PAGE_NOCACHE);405 return protect == PAGE_READWRITE406 || protect == PAGE_WRITECOPY407 || protect == PAGE_EXECUTE_READWRITE408 || protect == PAGE_EXECUTE_WRITECOPY;409 }410 411 static void* getStackBase(void* previousFrame)412 {413 // find the address of this stack frame by taking the address of a local variable414 bool isGrowingDownward;415 void* thisFrame = (void*)(&isGrowingDownward);416 417 isGrowingDownward = previousFrame < &thisFrame;418 static DWORD pageSize = 0;419 if (!pageSize) {420 SYSTEM_INFO systemInfo;421 GetSystemInfo(&systemInfo);422 pageSize = systemInfo.dwPageSize;423 }424 425 // scan all of memory starting from this frame, and return the last writeable page found426 register char* currentPage = (char*)((DWORD)thisFrame & ~(pageSize - 1));427 if (isGrowingDownward) {428 while (currentPage > 0) {429 // check for underflow430 if (currentPage >= (char*)pageSize)431 currentPage -= pageSize;432 else433 currentPage = 0;434 if (!isPageWritable(currentPage))435 return currentPage + pageSize;436 }437 return 0;438 } else {439 while (true) {440 // guaranteed to complete because isPageWritable returns false at end of memory441 currentPage += pageSize;442 if (!isPageWritable(currentPage))443 return currentPage;444 }445 }446 }447 #endif448 449 #if OS(QNX)450 static inline void *currentThreadStackBaseQNX()451 {452 static void* stackBase = 0;453 static size_t stackSize = 0;454 static pthread_t stackThread;455 pthread_t thread = pthread_self();456 if (stackBase == 0 || thread != stackThread) {457 struct _debug_thread_info threadInfo;458 memset(&threadInfo, 0, sizeof(threadInfo));459 threadInfo.tid = pthread_self();460 int fd = open("/proc/self", O_RDONLY);461 if (fd == -1) {462 LOG_ERROR("Unable to open /proc/self (errno: %d)", errno);463 return 0;464 }465 devctl(fd, DCMD_PROC_TIDSTATUS, &threadInfo, sizeof(threadInfo), 0);466 close(fd);467 stackBase = reinterpret_cast<void*>(threadInfo.stkbase);468 stackSize = threadInfo.stksize;469 ASSERT(stackBase);470 stackThread = thread;471 }472 return static_cast<char*>(stackBase) + stackSize;473 }474 #endif475 476 static inline void* currentThreadStackBase()477 {478 #if OS(DARWIN)479 pthread_t thread = pthread_self();480 return pthread_get_stackaddr_np(thread);481 #elif OS(WINDOWS) && CPU(X86) && COMPILER(MSVC)482 // offset 0x18 from the FS segment register gives a pointer to483 // the thread information block for the current thread484 NT_TIB* pTib;485 __asm {486 MOV EAX, FS:[18h]487 MOV pTib, EAX488 }489 return static_cast<void*>(pTib->StackBase);490 #elif OS(WINDOWS) && CPU(X86) && COMPILER(GCC)491 // offset 0x18 from the FS segment register gives a pointer to492 // the thread information block for the current thread493 NT_TIB* pTib;494 asm ( "movl %%fs:0x18, %0\n"495 : "=r" (pTib)496 );497 return static_cast<void*>(pTib->StackBase);498 #elif OS(WINDOWS) && CPU(X86_64)499 PNT_TIB64 pTib = reinterpret_cast<PNT_TIB64>(NtCurrentTeb());500 return reinterpret_cast<void*>(pTib->StackBase);501 #elif OS(QNX)502 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);503 MutexLocker locker(mutex);504 return currentThreadStackBaseQNX();505 #elif OS(SOLARIS)506 stack_t s;507 thr_stksegment(&s);508 return s.ss_sp;509 #elif OS(OPENBSD)510 pthread_t thread = pthread_self();511 stack_t stack;512 pthread_stackseg_np(thread, &stack);513 return stack.ss_sp;514 #elif OS(SYMBIAN)515 TThreadStackInfo info;516 RThread thread;517 thread.StackInfo(info);518 return (void*)info.iBase;519 #elif OS(HAIKU)520 thread_info threadInfo;521 get_thread_info(find_thread(NULL), &threadInfo);522 return threadInfo.stack_end;523 #elif OS(UNIX)524 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);525 MutexLocker locker(mutex);526 static void* stackBase = 0;527 static size_t stackSize = 0;528 static pthread_t stackThread;529 pthread_t thread = pthread_self();530 if (stackBase == 0 || thread != stackThread) {531 pthread_attr_t sattr;532 pthread_attr_init(&sattr);533 #if HAVE(PTHREAD_NP_H) || OS(NETBSD)534 // e.g. on FreeBSD 5.4, [email protected]535 pthread_attr_get_np(thread, &sattr);536 #else537 // FIXME: this function is non-portable; other POSIX systems may have different np alternatives538 pthread_getattr_np(thread, &sattr);539 #endif540 int rc = pthread_attr_getstack(&sattr, &stackBase, &stackSize);541 (void)rc; // FIXME: Deal with error code somehow? Seems fatal.542 ASSERT(stackBase);543 pthread_attr_destroy(&sattr);544 stackThread = thread;545 }546 return static_cast<char*>(stackBase) + stackSize;547 #elif OS(WINCE)548 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);549 MutexLocker locker(mutex);550 if (g_stackBase)551 return g_stackBase;552 else {553 int dummy;554 return getStackBase(&dummy);555 }556 #else557 #error Need a way to get the stack base on this platform558 #endif559 }560 561 392 #if ENABLE(JSC_MULTIPLE_THREADS) 562 393 … … 588 419 589 420 pthread_setspecific(m_currentThreadRegistrar, this); 590 Heap::Thread* thread = new Heap::Thread(pthread_self(), getCurrentPlatformThread(), currentThreadStackBase());421 Heap::Thread* thread = new Heap::Thread(pthread_self(), getCurrentPlatformThread(), m_globalData->stack().origin()); 591 422 592 423 MutexLocker lock(m_registeredThreadsMutex); … … 655 486 void Heap::markConservatively(MarkStack& markStack, void* start, void* end) 656 487 { 488 #if OS(WINCE) 657 489 if (start > end) { 658 490 void* tmp = start; … … 660 492 end = tmp; 661 493 } 494 #else 495 ASSERT(start <= end); 496 #endif 662 497 663 498 ASSERT((static_cast<char*>(end) - static_cast<char*>(start)) < 0x1000000); … … 693 528 void NEVER_INLINE Heap::markCurrentThreadConservativelyInternal(MarkStack& markStack) 694 529 { 695 void* dummy; 696 void* stackPointer = &dummy; 697 void* stackBase = currentThreadStackBase(); 698 markConservatively(markStack, stackPointer, stackBase); 530 markConservatively(markStack, m_globalData->stack().current(), m_globalData->stack().origin()); 699 531 markStack.drain(); 700 532 }
Note:
See TracChangeset
for help on using the changeset viewer.