this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Let native libpthread set up its own small stack, but jump to our own as soon as possible (#250)

+9 -3
+9 -3
src/libdyld/threads.cpp
··· 75 75 pthread_once(&reaper_once, start_reaper); 76 76 77 77 pthread_attr_init(&attr); 78 - //pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 79 78 // pthread_attr_setstacksize(&attr, stack_size); 80 79 81 80 pth = ::mmap(nullptr, stack_size + pth_obj_size + 0x1000, PROT_READ | PROT_WRITE, 82 81 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 83 - pthread_attr_setstack(&attr, ((char*)pth) + pth_obj_size, stack_size - pth_obj_size - 0x1000); 82 + // pthread_attr_setstack is bugged. The documentation states we should provide the lowest 83 + // address of the stack, yet some versions regard it as the highest address instead. 84 + // Therefore it's better to just make the pthread stack as small as possible and then switch 85 + // to our own stack instead. 86 + //pthread_attr_setstack(&attr, ((char*)pth) + pth_obj_size, stack_size - pth_obj_size - 0x1000); 84 87 85 - // std::cout << "Allocated stack at " << pth << ", size " << stack_size << std::endl; 88 + //std::cout << "Allocated stack at " << pth << ", size " << stack_size << std::endl; 86 89 pth = static_cast<char*>(pth) + stack_size + 0x1000; 90 + pthread_attr_setstacksize(&attr, 4096); 87 91 88 92 args.pth = pth; 89 93 pthread_create(&nativeLibcThread, &attr, darling_thread_entry, &args); ··· 108 112 #ifdef __x86_64__ 109 113 __asm__ __volatile__ ( 110 114 "movq %1, %%rdi\n" 115 + "movq %%rdi, %%rsp\n" 111 116 "movq 40(%0), %%rsi\n" 112 117 "movq 8(%0), %%rdx\n" 113 118 "testq %%rdx, %%rdx\n" ··· 127 132 #elif defined(__i386__) // TODO: args in eax, ebx, ecx, edx, edi, esi 128 133 __asm__ __volatile__ ( 129 134 "movl (%0), %%eax\n" 135 + "movl (%1), %%esp\n" 130 136 "pushl %%eax\n" // address to be jumped to 131 137 "movl %1, 28(%0)\n" 132 138 "movl %1, %%eax\n" // 1st arg