Skip to content

Commit

Permalink
Fix Sysconf(SC_PTHREAD_STACK_MIN) for macOS 14
Browse files Browse the repository at this point in the history
This changed from 0x2000 to 0x4000 in macOS 14.
  • Loading branch information
tklauser committed Jan 30, 2024
1 parent 0c10d3a commit 47e14bd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
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.

0 comments on commit 47e14bd

Please sign in to comment.