Skip to content

Commit 0b8b2e6

Browse files
committed
fuchsia: fix pthread.h definitions
Remove opaque types. Replace with proper fields. Remove conditional defintion for 32-bit targets. Fuchsia has no 32-bit targets. Static initializers needed modification. They are specified as `{ 0 }` in POSIX for C. The new definition replicates that. It zeroes/nullifies the new fields. Constants were used to initialize the previous opaque array. These have been deprecated. These are declared in [1]. [1]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/pthread.h
1 parent f8368a1 commit 0b8b2e6

1 file changed

Lines changed: 62 additions & 55 deletions

File tree

src/fuchsia/mod.rs

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,15 @@ s! {
770770
}
771771

772772
pub struct pthread_attr_t {
773-
__size: [u64; 7],
773+
pub __name: *const c_char,
774+
pub __c11: c_int,
775+
pub _a_stacksize: crate::size_t,
776+
pub _a_guardsize: crate::size_t,
777+
pub _a_stackaddr: *mut c_void,
778+
pub _a_detach: c_int,
779+
pub _a_sched: c_int,
780+
pub _a_policy: c_int,
781+
pub _a_prio: c_int,
774782
}
775783

776784
pub struct sigset_t {
@@ -871,27 +879,16 @@ s! {
871879
pub ipi6_ifindex: c_uint,
872880
}
873881

874-
#[cfg_attr(
875-
any(target_pointer_width = "32", target_arch = "x86_64"),
876-
repr(align(4))
877-
)]
878-
#[cfg_attr(
879-
not(any(target_pointer_width = "32", target_arch = "x86_64")),
880-
repr(align(8))
881-
)]
882882
pub struct pthread_mutexattr_t {
883-
size: [u8; crate::__SIZEOF_PTHREAD_MUTEXATTR_T],
883+
pub __attr: c_uint,
884884
}
885885

886-
#[cfg_attr(target_pointer_width = "32", repr(align(4)))]
887-
#[cfg_attr(target_pointer_width = "64", repr(align(8)))]
888886
pub struct pthread_rwlockattr_t {
889-
size: [u8; crate::__SIZEOF_PTHREAD_RWLOCKATTR_T],
887+
pub __attr: [c_uint; 2],
890888
}
891889

892-
#[repr(align(4))]
893890
pub struct pthread_condattr_t {
894-
size: [u8; crate::__SIZEOF_PTHREAD_CONDATTR_T],
891+
pub __attr: c_uint,
895892
}
896893

897894
#[deprecated(since = "0.2.187", note = "This type doesn't exist upstream.")]
@@ -999,53 +996,28 @@ s! {
999996
pub sigev_value: crate::sigval,
1000997
pub sigev_signo: c_int,
1001998
pub sigev_notify: c_int,
1002-
pub sigev_notify_function: fn(crate::sigval),
999+
pub sigev_notify_function: Option<extern "C" fn(crate::sigval)>,
10031000
pub sigev_notify_attributes: *mut pthread_attr_t,
1004-
pub __pad: [c_char; 56 - 3 * 8],
1001+
__pad: Padding<[c_char; 56 - 3 * size_of::<c_long>()]>,
10051002
}
10061003

1007-
#[cfg_attr(
1008-
all(
1009-
target_pointer_width = "32",
1010-
any(target_arch = "arm", target_arch = "x86_64")
1011-
),
1012-
repr(align(4))
1013-
)]
1014-
#[cfg_attr(
1015-
any(
1016-
target_pointer_width = "64",
1017-
not(any(target_arch = "arm", target_arch = "x86_64"))
1018-
),
1019-
repr(align(8))
1020-
)]
10211004
pub struct pthread_mutex_t {
1022-
size: [u8; crate::__SIZEOF_PTHREAD_MUTEX_T],
1005+
pub _m_attr: c_uint,
1006+
pub _m_lock: c_int,
1007+
pub _m_waiters: c_int,
1008+
pub _m_count: c_int,
10231009
}
10241010

1025-
#[cfg_attr(
1026-
all(
1027-
target_pointer_width = "32",
1028-
any(target_arch = "arm", target_arch = "x86_64")
1029-
),
1030-
repr(align(4))
1031-
)]
1032-
#[cfg_attr(
1033-
any(
1034-
target_pointer_width = "64",
1035-
not(any(target_arch = "arm", target_arch = "x86_64"))
1036-
),
1037-
repr(align(8))
1038-
)]
10391011
pub struct pthread_rwlock_t {
1040-
size: [u8; crate::__SIZEOF_PTHREAD_RWLOCK_T],
1012+
pub _rw_lock: c_int,
1013+
pub _rw_waiters: c_int,
10411014
}
10421015

1043-
#[cfg_attr(target_pointer_width = "32", repr(align(4)))]
1044-
#[cfg_attr(target_pointer_width = "64", repr(align(8)))]
1045-
#[cfg_attr(target_arch = "x86", repr(align(4)))]
1046-
#[cfg_attr(not(target_arch = "x86"), repr(align(8)))]
10471016
pub struct pthread_cond_t {
1048-
size: [u8; crate::__SIZEOF_PTHREAD_COND_T],
1017+
pub _c_head: *mut c_void,
1018+
pub _c_clock: c_int,
1019+
pub _c_tail: *mut c_void,
1020+
pub _c_lock: c_int,
10491021
}
10501022
}
10511023

@@ -2155,20 +2127,32 @@ pub const RTLD_NOW: c_int = 0x2;
21552127
pub const TCP_MD5SIG: c_int = 14;
21562128

21572129
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
2158-
size: [0; __SIZEOF_PTHREAD_MUTEX_T],
2130+
_m_attr: 0,
2131+
_m_lock: 0,
2132+
_m_waiters: 0,
2133+
_m_count: 0,
21592134
};
21602135
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
2161-
size: [0; __SIZEOF_PTHREAD_COND_T],
2136+
_c_head: ptr::null_mut(),
2137+
_c_clock: 0,
2138+
_c_tail: ptr::null_mut(),
2139+
_c_lock: 0,
21622140
};
21632141
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
2164-
size: [0; __SIZEOF_PTHREAD_RWLOCK_T],
2142+
_rw_lock: 0,
2143+
_rw_waiters: 0,
21652144
};
21662145
pub const PTHREAD_MUTEX_NORMAL: c_int = 0;
21672146
pub const PTHREAD_MUTEX_RECURSIVE: c_int = 1;
21682147
pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 2;
21692148
pub const PTHREAD_MUTEX_DEFAULT: c_int = PTHREAD_MUTEX_NORMAL;
21702149
pub const PTHREAD_PROCESS_PRIVATE: c_int = 0;
21712150
pub const PTHREAD_PROCESS_SHARED: c_int = 1;
2151+
2152+
#[deprecated(
2153+
since = "0.2.187",
2154+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2155+
)]
21722156
pub const __SIZEOF_PTHREAD_COND_T: usize = 48;
21732157

21742158
pub const RENAME_NOREPLACE: c_int = 1;
@@ -2690,8 +2674,22 @@ pub const TCP_TIMESTAMP: c_int = 24;
26902674

26912675
pub const SIGUNUSED: c_int = crate::SIGSYS;
26922676

2677+
#[deprecated(
2678+
since = "0.2.187",
2679+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2680+
)]
26932681
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
2682+
2683+
#[deprecated(
2684+
since = "0.2.187",
2685+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2686+
)]
26942687
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
2688+
2689+
#[deprecated(
2690+
since = "0.2.187",
2691+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2692+
)]
26952693
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
26962694

26972695
pub const CPU_SETSIZE: c_int = 128;
@@ -2830,7 +2828,16 @@ pub const B3000000: crate::speed_t = 0o010015;
28302828
pub const B3500000: crate::speed_t = 0o010016;
28312829
pub const B4000000: crate::speed_t = 0o010017;
28322830

2831+
#[deprecated(
2832+
since = "0.2.187",
2833+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2834+
)]
28332835
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
2836+
2837+
#[deprecated(
2838+
since = "0.2.187",
2839+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2840+
)]
28342841
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
28352842

28362843
pub const O_ASYNC: c_int = 0x00000400;

0 commit comments

Comments
 (0)