exit(1)
}
- // Set the stack size we want to use. 64KB for now.
- // TODO: just use OS default size?
- const stackSize = 1 << 16
- if pthread_attr_setstacksize(&attr, stackSize) != 0 {
+ // Find out OS stack size for our own stack guard.
+ var stacksize uintptr
+ if pthread_attr_getstacksize(&attr, &stacksize) != 0 {
write(2, unsafe.Pointer(&failthreadcreate[0]), int32(len(failthreadcreate)))
exit(1)
}
- //mSysStatInc(&memstats.stacks_sys, stackSize) //TODO: do this?
+ mp.g0.stack.hi = stacksize // for mstart
+ //mSysStatInc(&memstats.stacks_sys, stacksize) //TODO: do this?
// Tell the pthread library we won't join with this thread.
if pthread_attr_setdetachstate(&attr, _PTHREAD_CREATE_DETACHED) != 0 {
exit(1)
}
- // Set the stack we want to use.
- if pthread_attr_setstacksize(&attr, stacksize) != 0 {
+ // The caller passes in a suggested stack size,
+ // from when we allocated the stack and thread ourselves,
+ // without libpthread. Now that we're using libpthread,
+ // we use the OS default stack size instead of the suggestion.
+ // Find out that stack size for our own stack guard.
+ if pthread_attr_getstacksize(&attr, &stacksize) != 0 {
write(2, unsafe.Pointer(&failthreadcreate[0]), int32(len(failthreadcreate)))
exit(1)
}
+ g0.stack.hi = stacksize // for mstart
mSysStatInc(&memstats.stacks_sys, stacksize)
// Tell the pthread library we won't join with this thread.
//go:nosplit
//go:cgo_unsafe_args
-func pthread_attr_setstacksize(attr *pthreadattr, size uintptr) int32 {
- return libcCall(unsafe.Pointer(funcPC(pthread_attr_setstacksize_trampoline)), unsafe.Pointer(&attr))
+func pthread_attr_getstacksize(attr *pthreadattr, size *uintptr) int32 {
+ return libcCall(unsafe.Pointer(funcPC(pthread_attr_getstacksize_trampoline)), unsafe.Pointer(&attr))
}
-func pthread_attr_setstacksize_trampoline()
+func pthread_attr_getstacksize_trampoline()
//go:nosplit
//go:cgo_unsafe_args
// in a system library, with the libc_ prefix missing.
//go:cgo_import_dynamic libc_pthread_attr_init pthread_attr_init "/usr/lib/libSystem.B.dylib"
-//go:cgo_import_dynamic libc_pthread_attr_setstacksize pthread_attr_setstacksize "/usr/lib/libSystem.B.dylib"
+//go:cgo_import_dynamic libc_pthread_attr_getstacksize pthread_attr_getstacksize "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_pthread_attr_setdetachstate pthread_attr_setdetachstate "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_pthread_create pthread_create "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_exit exit "/usr/lib/libSystem.B.dylib"
POPL BP
RET
-TEXT runtime·pthread_attr_setstacksize_trampoline(SB),NOSPLIT,$0
+TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$0
PUSHL BP
MOVL SP, BP
SUBL $8, SP
MOVL AX, 0(SP)
MOVL 4(CX), AX // arg 2 size
MOVL AX, 4(SP)
- CALL libc_pthread_attr_setstacksize(SB)
+ CALL libc_pthread_attr_getstacksize(SB)
MOVL BP, SP
POPL BP
RET
POPQ BP
RET
-TEXT runtime·pthread_attr_setstacksize_trampoline(SB),NOSPLIT,$0
+TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 size
MOVQ 0(DI), DI // arg 1 attr
- CALL libc_pthread_attr_setstacksize(SB)
+ CALL libc_pthread_attr_getstacksize(SB)
POPQ BP
RET
BL libc_exit(SB)
RET
-TEXT runtime·pthread_attr_setstacksize_trampoline(SB),NOSPLIT,$0
+TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$0
MOVW $46, R0
BL libc_exit(SB)
RET
BL libc_pthread_attr_init(SB)
RET
-TEXT runtime·pthread_attr_setstacksize_trampoline(SB),NOSPLIT,$0
+TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$0
MOVD 8(R0), R1 // arg 2 size
MOVD 0(R0), R0 // arg 1 attr
- BL libc_pthread_attr_setstacksize(SB)
+ BL libc_pthread_attr_getstacksize(SB)
RET
TEXT runtime·pthread_attr_setdetachstate_trampoline(SB),NOSPLIT,$0