From 185b49b73e02256502ae79576ae7bc4ac302ac53 Mon Sep 17 00:00:00 2001 From: auronandace Date: Sat, 4 Jul 2026 17:16:08 +0100 Subject: [PATCH] split out pthread_attr_t --- src/header/_aio/cbindgen.toml | 5 ++- src/header/bits_pthread/cbindgen.toml | 8 ++--- src/header/bits_pthread/mod.rs | 36 +++++++++------------ src/header/bits_pthreadattr-t/cbindgen.toml | 17 ++++++++++ src/header/bits_pthreadattr-t/mod.rs | 17 ++++++++++ src/header/mod.rs | 2 ++ src/header/signal/cbindgen.toml | 15 ++++----- 7 files changed, 63 insertions(+), 37 deletions(-) create mode 100644 src/header/bits_pthreadattr-t/cbindgen.toml create mode 100644 src/header/bits_pthreadattr-t/mod.rs diff --git a/src/header/_aio/cbindgen.toml b/src/header/_aio/cbindgen.toml index a60a49b7b7..357e702b68 100644 --- a/src/header/_aio/cbindgen.toml +++ b/src/header/_aio/cbindgen.toml @@ -6,11 +6,10 @@ # - "The header shall define the sigevent structure and sigval union as described in ." # - "Inclusion of the header may make visible symbols defined in the headers , , and ." # -# TODO don't bring in all of bits/pthread.h -# # signal.h brings in sigevent and sigval # signal.h brings in bits/timespec.h for timespec from time.h -# signal.h brings in bits/pthread.h bringing in pthread_attr_t from sys/types.h +# signal.h brings in bits/pthread-t.h bringing in pthread_t from sys/types.h +# signal.h brings in bits/pthreadattr-t.h bringing in pthread_attr_t from sys/types.h # signal.h brings in size_t from sys/types.h sys_includes = ["signal.h"] after_includes = """ diff --git a/src/header/bits_pthread/cbindgen.toml b/src/header/bits_pthread/cbindgen.toml index de6f305aa2..9fc60c2f24 100644 --- a/src/header/bits_pthread/cbindgen.toml +++ b/src/header/bits_pthread/cbindgen.toml @@ -5,10 +5,8 @@ # POSIX headers that require them: # - aio.h (pthread_attr_t only) # - pthread.h (all of them) -# - signal (pthread_t and pthread_attr_t only) +# - signal.h (pthread_t and pthread_attr_t only) # - sys/types.h (where they should be defined) -# -# TODO split out pthread_attr_t include_guard = "_RELIBC_BITS_PTHREAD_H" language = "C" style = "type" @@ -16,7 +14,8 @@ no_includes = true cpp_compat = true # TODO split out PTHREAD_ONCE_INIT for threads.h after_includes = """ -#include // for pthread_t from sys/types.h +#include // for pthread_t from sys/types.h +#include // for pthread_attr_t from sys/types.h #define PTHREAD_ONCE_INIT ((pthread_once_t){0}) @@ -24,7 +23,6 @@ after_includes = """ [export] include = [ - "pthread_attr_t", "pthread_rwlockattr_t", "pthread_rwlock_t", "pthread_barrier_t", diff --git a/src/header/bits_pthread/mod.rs b/src/header/bits_pthread/mod.rs index be621547a5..615e964425 100644 --- a/src/header/bits_pthread/mod.rs +++ b/src/header/bits_pthread/mod.rs @@ -1,8 +1,8 @@ #![allow(non_camel_case_types)] -use crate::platform::types::{c_int, c_uchar, c_ulong, size_t}; +use crate::platform::types::{c_int, c_uchar, c_ulong}; -pub use crate::header::bits_pthread_t::pthread_t; +pub use crate::header::{bits_pthread_t::pthread_t, bits_pthreadattr_t::pthread_attr_t}; // XXX: https://github.com/eqrion/cbindgen/issues/685 // @@ -10,12 +10,6 @@ pub use crate::header::bits_pthread_t::pthread_t; // expanding macros! Instead, we rely on checking that the lengths are correct, when these headers // are parsed in the regular compilation phase. -/// The `pthread_attr_t` type provided in [`sys/types.h`](crate::header::sys_types). -#[repr(C)] -pub union pthread_attr_t { - __relibc_internal_size: [c_uchar; 32], - __relibc_internal_align: size_t, -} /// The `pthread_rwlockattr_t` type provided in [`sys/types.h`](crate::header::sys_types). #[repr(C)] pub union pthread_rwlockattr_t { @@ -77,10 +71,11 @@ pub union pthread_once_t { __relibc_internal_align: c_int, } -macro_rules! assert_equal_size( +#[macro_export] +macro_rules! pthread_assert_equal_size( ($export:ident, $wrapped:ident) => { const _: () = unsafe { - type Wrapped = crate::header::pthread::$wrapped; + type Wrapped = $crate::header::pthread::$wrapped; // Fail at compile-time if sizes differ. @@ -107,17 +102,16 @@ macro_rules! assert_equal_size( }; } ); -assert_equal_size!(pthread_attr_t, RlctAttr); -assert_equal_size!(pthread_rwlock_t, RlctRwlock); -assert_equal_size!(pthread_rwlockattr_t, RlctRwlockAttr); -assert_equal_size!(pthread_barrier_t, RlctBarrier); -assert_equal_size!(pthread_barrierattr_t, RlctBarrierAttr); -assert_equal_size!(pthread_mutex_t, RlctMutex); -assert_equal_size!(pthread_mutexattr_t, RlctMutexAttr); -assert_equal_size!(pthread_cond_t, RlctCond); -assert_equal_size!(pthread_condattr_t, RlctCondAttr); -assert_equal_size!(pthread_spinlock_t, RlctSpinlock); -assert_equal_size!(pthread_once_t, RlctOnce); +pthread_assert_equal_size!(pthread_rwlock_t, RlctRwlock); +pthread_assert_equal_size!(pthread_rwlockattr_t, RlctRwlockAttr); +pthread_assert_equal_size!(pthread_barrier_t, RlctBarrier); +pthread_assert_equal_size!(pthread_barrierattr_t, RlctBarrierAttr); +pthread_assert_equal_size!(pthread_mutex_t, RlctMutex); +pthread_assert_equal_size!(pthread_mutexattr_t, RlctMutexAttr); +pthread_assert_equal_size!(pthread_cond_t, RlctCond); +pthread_assert_equal_size!(pthread_condattr_t, RlctCondAttr); +pthread_assert_equal_size!(pthread_spinlock_t, RlctSpinlock); +pthread_assert_equal_size!(pthread_once_t, RlctOnce); /// The `pthread_key_t` type provided in [`sys/types.h`](crate::header::sys_types). pub type pthread_key_t = c_ulong; diff --git a/src/header/bits_pthreadattr-t/cbindgen.toml b/src/header/bits_pthreadattr-t/cbindgen.toml new file mode 100644 index 0000000000..e64151fb08 --- /dev/null +++ b/src/header/bits_pthreadattr-t/cbindgen.toml @@ -0,0 +1,17 @@ +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_types.h.html +# +# This type is split out to prevent importing all of sys/types.h into other headers. +# +# POSIX headers that require pthread_attr_t: +# - aio.h +# - pthread.h +# - signal.h +# - sys/types.h (where it should be defined) +include_guard = "_RELIBC_BITS_PTHREADATTR_T_H" +language = "C" +no_includes = true +cpp_compat = true +[export] +include = ["pthread_attr_t"] +[enum] +prefix_with_name = true diff --git a/src/header/bits_pthreadattr-t/mod.rs b/src/header/bits_pthreadattr-t/mod.rs new file mode 100644 index 0000000000..091d8b1fae --- /dev/null +++ b/src/header/bits_pthreadattr-t/mod.rs @@ -0,0 +1,17 @@ +//! `pthread_attr_t` from `sys/types.h` implementation. +//! +//! See . + +use crate::{ + platform::types::{c_uchar, size_t}, + pthread_assert_equal_size, +}; + +/// Used to identify a thread attribute object. +#[repr(C)] +pub union pthread_attr_t { + __relibc_internal_size: [c_uchar; 32], + __relibc_internal_align: size_t, +} + +pthread_assert_equal_size!(pthread_attr_t, RlctAttr); diff --git a/src/header/mod.rs b/src/header/mod.rs index 83265bc1ff..666f173066 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -40,6 +40,8 @@ pub mod bits_pid_t; pub mod bits_pthread; #[path = "bits_pthread-t/mod.rs"] pub mod bits_pthread_t; +#[path = "bits_pthreadattr-t/mod.rs"] +pub mod bits_pthreadattr_t; #[path = "bits_reclen-t/mod.rs"] pub mod bits_reclen_t; #[path = "bits_safamily-t/mod.rs"] diff --git a/src/header/signal/cbindgen.toml b/src/header/signal/cbindgen.toml index bda280435c..15e483c441 100644 --- a/src/header/signal/cbindgen.toml +++ b/src/header/signal/cbindgen.toml @@ -11,18 +11,17 @@ # POSIX states signal.h may include time.h and time.h may include signal.h. # To prevent a cycle between both headers we only import the needed types through bits. # -# TODO split out types from bits/pthread.h -# # features.h required for deprecated annotations sys_includes = ["features.h"] include_guard = "_RELIBC_SIGNAL_H" after_includes = """ -#include // for size_t from sys/types.h -#include // for pid_t from sys/types.h -#include // for uid_t from sys/types.h -#include // for pthread_t and pthread_attr_t from sys/types.h -#include // for sigset_t -#include // for timespec from time.h +#include // for size_t from sys/types.h +#include // for pid_t from sys/types.h +#include // for uid_t from sys/types.h +#include // for pthread_t from sys/types.h +#include // for pthread_attr_t from sys/types.h +#include // for sigset_t +#include // for timespec from time.h // Request for default signal handling. #define SIG_DFL ((void (*)(int))0)