Skip to content

Commit 2b3cffc

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 9f799ad commit 2b3cffc

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
@@ -777,7 +777,15 @@ s! {
777777
}
778778

779779
pub struct pthread_attr_t {
780-
__size: [u64; 7],
780+
__name: *const c_char,
781+
__c11: c_int,
782+
_a_stacksize: crate::size_t,
783+
_a_guardsize: crate::size_t,
784+
_a_stackaddr: *mut c_void,
785+
_a_detach: c_int,
786+
_a_sched: c_int,
787+
_a_policy: c_int,
788+
_a_prio: c_int,
781789
}
782790

783791
pub struct sigset_t {
@@ -878,27 +886,16 @@ s! {
878886
pub ipi6_ifindex: c_uint,
879887
}
880888

881-
#[cfg_attr(
882-
any(target_pointer_width = "32", target_arch = "x86_64"),
883-
repr(align(4))
884-
)]
885-
#[cfg_attr(
886-
not(any(target_pointer_width = "32", target_arch = "x86_64")),
887-
repr(align(8))
888-
)]
889889
pub struct pthread_mutexattr_t {
890-
size: [u8; crate::__SIZEOF_PTHREAD_MUTEXATTR_T],
890+
pub __attr: c_uint,
891891
}
892892

893-
#[cfg_attr(target_pointer_width = "32", repr(align(4)))]
894-
#[cfg_attr(target_pointer_width = "64", repr(align(8)))]
895893
pub struct pthread_rwlockattr_t {
896-
size: [u8; crate::__SIZEOF_PTHREAD_RWLOCKATTR_T],
894+
pub __attr: [c_uint; 2],
897895
}
898896

899-
#[repr(align(4))]
900897
pub struct pthread_condattr_t {
901-
size: [u8; crate::__SIZEOF_PTHREAD_CONDATTR_T],
898+
pub __attr: c_uint,
902899
}
903900

904901
#[deprecated(since = "0.2.187", note = "This type doesn't exist upstream.")]
@@ -1006,53 +1003,28 @@ s! {
10061003
pub sigev_value: crate::sigval,
10071004
pub sigev_signo: c_int,
10081005
pub sigev_notify: c_int,
1009-
pub sigev_notify_function: fn(crate::sigval),
1006+
pub sigev_notify_function: Option<extern "C" fn(crate::sigval)>,
10101007
pub sigev_notify_attributes: *mut pthread_attr_t,
1011-
pub __pad: [c_char; 56 - 3 * 8],
1008+
__pad: Padding<[c_char; 56 - 3 * size_of::<c_long>()]>,
10121009
}
10131010

1014-
#[cfg_attr(
1015-
all(
1016-
target_pointer_width = "32",
1017-
any(target_arch = "arm", target_arch = "x86_64")
1018-
),
1019-
repr(align(4))
1020-
)]
1021-
#[cfg_attr(
1022-
any(
1023-
target_pointer_width = "64",
1024-
not(any(target_arch = "arm", target_arch = "x86_64"))
1025-
),
1026-
repr(align(8))
1027-
)]
10281011
pub struct pthread_mutex_t {
1029-
size: [u8; crate::__SIZEOF_PTHREAD_MUTEX_T],
1012+
pub _m_attr: c_uint,
1013+
pub _m_lock: c_int,
1014+
pub _m_waiters: c_int,
1015+
pub _m_count: c_int,
10301016
}
10311017

1032-
#[cfg_attr(
1033-
all(
1034-
target_pointer_width = "32",
1035-
any(target_arch = "arm", target_arch = "x86_64")
1036-
),
1037-
repr(align(4))
1038-
)]
1039-
#[cfg_attr(
1040-
any(
1041-
target_pointer_width = "64",
1042-
not(any(target_arch = "arm", target_arch = "x86_64"))
1043-
),
1044-
repr(align(8))
1045-
)]
10461018
pub struct pthread_rwlock_t {
1047-
size: [u8; crate::__SIZEOF_PTHREAD_RWLOCK_T],
1019+
pub _rw_lock: c_int,
1020+
pub _rw_waiters: c_int,
10481021
}
10491022

1050-
#[cfg_attr(target_pointer_width = "32", repr(align(4)))]
1051-
#[cfg_attr(target_pointer_width = "64", repr(align(8)))]
1052-
#[cfg_attr(target_arch = "x86", repr(align(4)))]
1053-
#[cfg_attr(not(target_arch = "x86"), repr(align(8)))]
10541023
pub struct pthread_cond_t {
1055-
size: [u8; crate::__SIZEOF_PTHREAD_COND_T],
1024+
pub _c_head: *mut c_void,
1025+
pub _c_clock: c_int,
1026+
pub _c_tail: *mut c_void,
1027+
pub _c_lock: c_int,
10561028
}
10571029
}
10581030

@@ -2152,20 +2124,32 @@ pub const RTLD_NOW: c_int = 0x2;
21522124
pub const TCP_MD5SIG: c_int = 14;
21532125

21542126
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
2155-
size: [0; __SIZEOF_PTHREAD_MUTEX_T],
2127+
_m_attr: 0,
2128+
_m_lock: 0,
2129+
_m_waiters: 0,
2130+
_m_count: 0,
21562131
};
21572132
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
2158-
size: [0; __SIZEOF_PTHREAD_COND_T],
2133+
_c_head: ptr::null_mut(),
2134+
_c_clock: 0,
2135+
_c_tail: ptr::null_mut(),
2136+
_c_lock: 0,
21592137
};
21602138
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
2161-
size: [0; __SIZEOF_PTHREAD_RWLOCK_T],
2139+
_rw_lock: 0,
2140+
_rw_waiters: 0,
21622141
};
21632142
pub const PTHREAD_MUTEX_NORMAL: c_int = 0;
21642143
pub const PTHREAD_MUTEX_RECURSIVE: c_int = 1;
21652144
pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 2;
21662145
pub const PTHREAD_MUTEX_DEFAULT: c_int = PTHREAD_MUTEX_NORMAL;
21672146
pub const PTHREAD_PROCESS_PRIVATE: c_int = 0;
21682147
pub const PTHREAD_PROCESS_SHARED: c_int = 1;
2148+
2149+
#[deprecated(
2150+
since = "0.2.187",
2151+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2152+
)]
21692153
pub const __SIZEOF_PTHREAD_COND_T: usize = 48;
21702154

21712155
pub const RENAME_NOREPLACE: c_int = 1;
@@ -2687,8 +2671,22 @@ pub const TCP_TIMESTAMP: c_int = 24;
26872671

26882672
pub const SIGUNUSED: c_int = crate::SIGSYS;
26892673

2674+
#[deprecated(
2675+
since = "0.2.187",
2676+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2677+
)]
26902678
pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
2679+
2680+
#[deprecated(
2681+
since = "0.2.187",
2682+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2683+
)]
26912684
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
2685+
2686+
#[deprecated(
2687+
since = "0.2.187",
2688+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2689+
)]
26922690
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
26932691

26942692
pub const CPU_SETSIZE: c_int = 128;
@@ -2827,7 +2825,16 @@ pub const B3000000: crate::speed_t = 0o010015;
28272825
pub const B3500000: crate::speed_t = 0o010016;
28282826
pub const B4000000: crate::speed_t = 0o010017;
28292827

2828+
#[deprecated(
2829+
since = "0.2.187",
2830+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2831+
)]
28302832
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
2833+
2834+
#[deprecated(
2835+
since = "0.2.187",
2836+
note = "This type doesn't exist. It's not part of the Fuchsia SDK."
2837+
)]
28312838
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
28322839

28332840
pub const O_ASYNC: c_int = 0x00000400;

0 commit comments

Comments
 (0)