From 3cc24ddaeec2dc91ea52cd272f63b8a54e7eb98f Mon Sep 17 00:00:00 2001 From: auronandace Date: Fri, 26 Jun 2026 12:42:35 +0100 Subject: [PATCH] fix TTS_DTOR_ITERATIONS with bits file --- src/header/bits_limits_ptdi/cbindgen.toml | 13 +++++++++++++ src/header/bits_limits_ptdi/mod.rs | 12 ++++++++++++ src/header/limits/cbindgen.toml | 3 +++ src/header/limits/mod.rs | 8 ++++++-- src/header/mod.rs | 1 + src/header/threads/cbindgen.toml | 5 ++++- src/header/threads/mod.rs | 4 ++-- 7 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 src/header/bits_limits_ptdi/cbindgen.toml create mode 100644 src/header/bits_limits_ptdi/mod.rs diff --git a/src/header/bits_limits_ptdi/cbindgen.toml b/src/header/bits_limits_ptdi/cbindgen.toml new file mode 100644 index 0000000000..f766e450ba --- /dev/null +++ b/src/header/bits_limits_ptdi/cbindgen.toml @@ -0,0 +1,13 @@ +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/limits.h.html +# +# These types are split out to avoid importing all of limits.h into other headers. +# +# POSIX headers that require PTHREAD_DESTRUCTOR_ITERATIONS: +# - limits.h (where it should be defined) +# - threads.h (for TSS_DTOR_ITERATIONS) +include_guard = "_RELIBC_BITS_LIMITS_PTDI_H" +language = "C" +no_includes = true +cpp_compat = true +[enum] +prefix_with_name = true diff --git a/src/header/bits_limits_ptdi/mod.rs b/src/header/bits_limits_ptdi/mod.rs new file mode 100644 index 0000000000..04d11e029c --- /dev/null +++ b/src/header/bits_limits_ptdi/mod.rs @@ -0,0 +1,12 @@ +//! `PTHREAD_DESTRUCTOR_ITERATIONS` for `limits.h` implementation. +//! +//! See . + +use crate::platform::types::c_long; + +/// Minimum required value for `PTHREAD_DESTRUCTOR_ITERATIONS`. +pub const _POSIX_THREAD_DESTRUCTOR_ITERATIONS: c_long = 4; + +/// Maximum number of attempts made to destroy a thread's thread-specific data +/// values on thread exit. +pub const PTHREAD_DESTRUCTOR_ITERATIONS: c_long = _POSIX_THREAD_DESTRUCTOR_ITERATIONS; diff --git a/src/header/limits/cbindgen.toml b/src/header/limits/cbindgen.toml index bb22970e84..03570d6235 100644 --- a/src/header/limits/cbindgen.toml +++ b/src/header/limits/cbindgen.toml @@ -2,6 +2,9 @@ # # There are no spec quotations relating to includes include_guard = "_RELIBC_LIMITS_H" +after_includes = """ +#include // for PTHREAD_DESTRUCTOR_ITERATIONS +""" language = "C" no_includes = true cpp_compat = true diff --git a/src/header/limits/mod.rs b/src/header/limits/mod.rs index 462a76f5cb..36cefe02d6 100644 --- a/src/header/limits/mod.rs +++ b/src/header/limits/mod.rs @@ -7,6 +7,10 @@ use crate::platform::types::{ c_ushort, ssize_t, }; +pub use crate::header::bits_limits_ptdi::{ + _POSIX_THREAD_DESTRUCTOR_ITERATIONS, PTHREAD_DESTRUCTOR_ITERATIONS, +}; + /// Maximum number of bytes in a filename (not including the terminating null /// of a filename string). pub const NAME_MAX: usize = 255; @@ -103,7 +107,7 @@ pub const _POSIX_STREAM_MAX: c_long = 8; pub const _POSIX_SYMLINK_MAX: c_long = 255; /// Minimum required value for `SYMLOOP_MAX`. pub const _POSIX_SYMLOOP_MAX: c_long = 8; -pub const _POSIX_THREAD_DESTRUCTOR_ITERATIONS: c_long = 4; +// _POSIX_THREAD_DESTRUCTOR_ITERATIONS defined in bits file pub const _POSIX_THREAD_KEYS_MAX: c_long = 128; pub const _POSIX_THREAD_THREADS_MAX: c_long = 64; pub const _POSIX_TIMER_MAX: c_long = 32; @@ -142,7 +146,7 @@ pub const MAX_INPUT: c_long = _POSIX_MAX_INPUT; pub const SYMLINK_MAX: c_long = _POSIX_SYMLINK_MAX; pub const POSIX_ALLOC_SIZE_MIN: c_long = 4096; -pub const PTHREAD_DESTRUCTOR_ITERATIONS: c_long = _POSIX_THREAD_DESTRUCTOR_ITERATIONS; +// PTHREAD_DESTRUCTOR_ITERATIONS defined in bits file // TODO: What should this limit be? Both glibc and musl have it as 1024 pub const PTHREAD_KEYS_MAX: c_long = 4096 * 32; pub const PTHREAD_STACK_MIN: c_long = 65536; diff --git a/src/header/mod.rs b/src/header/mod.rs index 5dbf59b857..344fb8fbe0 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -23,6 +23,7 @@ pub mod bits_intptr_t; pub mod bits_iovec; #[path = "bits_key-t/mod.rs"] pub mod bits_key_t; +pub mod bits_limits_ptdi; #[path = "bits_locale-t/mod.rs"] pub mod bits_locale_t; #[path = "bits_mode-t/mod.rs"] diff --git a/src/header/threads/cbindgen.toml b/src/header/threads/cbindgen.toml index 115b6cece0..af983fffdb 100644 --- a/src/header/threads/cbindgen.toml +++ b/src/header/threads/cbindgen.toml @@ -3,6 +3,8 @@ # Spec quotations relating to includes: # - "Inclusion of the header shall make symbols defined in the header visible." # +# TODO split out required pthread types +# # time.h brings in features.h # features.h required for Rust never type (no return) sys_includes = ["time.h"] @@ -12,7 +14,8 @@ style = "tag" no_includes = true cpp_compat = true after_includes = """ -#include // for pthread-related types +#include // for pthread-related types +#include // for PTHREAD_DESTRUCTOR_ITERATIONS #ifndef __cplusplus #define thread_local _Thread_local diff --git a/src/header/threads/mod.rs b/src/header/threads/mod.rs index 83a3a0f8f6..eb67ba5596 100644 --- a/src/header/threads/mod.rs +++ b/src/header/threads/mod.rs @@ -5,9 +5,9 @@ #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] use super::{ + bits_limits_ptdi::PTHREAD_DESTRUCTOR_ITERATIONS, bits_pthread::{self, pthread_cond_t, pthread_key_t, pthread_mutex_t, pthread_mutexattr_t}, errno::{EBUSY, EINTR, ENOMEM, ETIMEDOUT}, - limits, pthread::{ self, PTHREAD_MUTEX_NORMAL, PTHREAD_MUTEX_RECURSIVE, RlctCond, pthread_cond_broadcast, pthread_cond_destroy, pthread_cond_signal, pthread_cond_timedwait, pthread_cond_wait, @@ -45,7 +45,7 @@ pub const mtx_plain: c_int = 0; pub const mtx_recursive: c_int = 1; pub const mtx_timed: c_int = 2; -pub const TSS_DTOR_ITERATIONS: c_long = limits::PTHREAD_DESTRUCTOR_ITERATIONS; +pub const TSS_DTOR_ITERATIONS: c_long = PTHREAD_DESTRUCTOR_ITERATIONS; /// See . #[unsafe(no_mangle)]