Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sysconf(SC_PTHREAD_STACK_MIN) for macOS 14 #96

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions sysconf_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,32 @@ const (
_HOST_NAME_MAX = _MAXHOSTNAMELEN - 1
_LOGIN_NAME_MAX = _MAXLOGNAME
_SYMLOOP_MAX = _MAXSYMLINKS

// _PTHREAD_STACK_MIN changed in macOS 14
_PTHREAD_STACK_MIN_LT_MACOS14 = 0x2000
_PTHREAD_STACK_MIN_GE_MACOS14 = 0x4000
)

var uname struct {
sync.Once
macOSMajor int
}

func getMacOSMajor() int {
uname.Once.Do(func() {
var u unix.Utsname
err := unix.Uname(&u)
if err != nil {
return
}
rel := unix.ByteSliceToString(u.Release[:])
ver := strings.Split(rel, ".")
maj, _ := strconv.Atoi(ver[0])
uname.macOSMajor = maj
})
return uname.macOSMajor
}

// sysconf implements sysconf(4) as in the Darwin libc (derived from the FreeBSD
// libc), version 1534.81.1.
// See https://github.com/apple-oss-distributions/Libc/tree/Libc-1534.81.1.
Expand Down Expand Up @@ -91,7 +110,10 @@ func sysconf(name int) (int64, error) {
case SC_THREAD_PRIO_PROTECT:
return _POSIX_THREAD_PRIO_PROTECT, nil
case SC_THREAD_STACK_MIN:
return _PTHREAD_STACK_MIN, nil
if getMacOSMajor() < 23 {
return _PTHREAD_STACK_MIN_LT_MACOS14, nil
}
return _PTHREAD_STACK_MIN_GE_MACOS14, nil
case SC_THREAD_THREADS_MAX:
return -1, nil
case SC_TIMER_MAX:
Expand Down Expand Up @@ -140,18 +162,7 @@ func sysconf(name int) (int64, error) {
}
return _POSIX_SEMAPHORES, nil
case SC_SPAWN:
uname.Once.Do(func() {
var u unix.Utsname
err := unix.Uname(&u)
if err != nil {
return
}
rel := unix.ByteSliceToString(u.Release[:])
ver := strings.Split(rel, ".")
maj, _ := strconv.Atoi(ver[0])
uname.macOSMajor = maj
})
if uname.macOSMajor < 22 {
if getMacOSMajor() < 22 {
return -1, nil
}
// macOS 13 (Ventura) and later
Expand Down
1 change: 0 additions & 1 deletion sysconf_defs_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ const (

_PTHREAD_DESTRUCTOR_ITERATIONS = C.PTHREAD_DESTRUCTOR_ITERATIONS
_PTHREAD_KEYS_MAX = C.PTHREAD_KEYS_MAX
_PTHREAD_STACK_MIN = C.PTHREAD_STACK_MIN
)

// pathconf
Expand Down
1 change: 0 additions & 1 deletion zsysconf_defs_darwin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading