Skip to content

Commit 4bd6e8b

Browse files
committed
fuchsia: fix record definitions
Remove uses of 32-bit target conditional compilation. Fuchsia does not support 32-bit targets [1]. This is unnecessary. Fix missing fields in records. No particular header file is targetted. All wrong records have been fixed. c.f. all headers under `sysroot/include` in the SDK. Fix `cpu_set_t` macros [2]. They were wrongly defined. They neither returned the right values. [1]: https://fuchsia.dev/fuchsia-src/contribute/governance/rfcs/0111_fuchsia_hardware_specifications#required_64-bit_cpu_and_platform [2]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/sched.h
1 parent 9c0eb2b commit 4bd6e8b

4 files changed

Lines changed: 51 additions & 62 deletions

File tree

src/fuchsia/aarch64.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ s! {
1717
pub st_uid: crate::uid_t,
1818
pub st_gid: crate::gid_t,
1919
pub st_rdev: crate::dev_t,
20-
__pad0: Padding<c_ulong>,
20+
__pad: Padding<c_ulong>,
2121
pub st_size: off_t,
2222
pub st_blksize: crate::blksize_t,
23-
__pad1: Padding<c_int>,
23+
__pad2: Padding<c_int>,
2424
pub st_blocks: crate::blkcnt_t,
2525
pub st_atime: crate::time_t,
2626
pub st_atime_nsec: c_long,

src/fuchsia/mod.rs

Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,8 @@ s! {
478478
pub gl_pathc: size_t,
479479
pub gl_pathv: *mut *mut c_char,
480480
pub gl_offs: size_t,
481-
pub gl_flags: c_int,
482-
483-
__unused1: Padding<*mut c_void>,
484-
__unused2: Padding<*mut c_void>,
485-
__unused3: Padding<*mut c_void>,
486-
__unused4: Padding<*mut c_void>,
487-
__unused5: Padding<*mut c_void>,
481+
__dummy1: Padding<c_int>,
482+
__dummy2: Padding<[*mut c_void; 5]>,
488483
}
489484

490485
pub struct ifaddrs {
@@ -528,15 +523,10 @@ s! {
528523
pub f_files: crate::fsfilcnt_t,
529524
pub f_ffree: crate::fsfilcnt_t,
530525
pub f_favail: crate::fsfilcnt_t,
531-
#[cfg(target_endian = "little")]
532-
pub f_fsid: c_ulong,
533-
#[cfg(all(target_pointer_width = "32", not(target_arch = "x86_64")))]
534-
__f_unused: Padding<c_int>,
535-
#[cfg(target_endian = "big")]
536526
pub f_fsid: c_ulong,
537527
pub f_flag: c_ulong,
538528
pub f_namemax: c_ulong,
539-
__f_spare: [c_int; 6],
529+
__f_spare: Padding<[c_int; 6]>,
540530
}
541531

542532
pub struct dqblk {
@@ -582,14 +572,11 @@ s! {
582572
}
583573

584574
pub struct fsid_t {
585-
__val: [c_int; 2],
575+
pub __val: [c_int; 2],
586576
}
587577

588578
pub struct cpu_set_t {
589-
#[cfg(all(target_pointer_width = "32", not(target_arch = "x86_64")))]
590-
bits: [u32; 32],
591-
#[cfg(not(all(target_pointer_width = "32", not(target_arch = "x86_64"))))]
592-
bits: [u64; 16],
579+
pub __bits: [c_ulonglong; 128 / size_of::<c_long>()],
593580
}
594581

595582
pub struct if_nameindex {
@@ -732,23 +719,10 @@ s! {
732719
}
733720

734721
pub struct dl_phdr_info {
735-
#[cfg(target_pointer_width = "64")]
736722
pub dlpi_addr: Elf64_Addr,
737-
#[cfg(target_pointer_width = "32")]
738-
pub dlpi_addr: Elf32_Addr,
739-
740723
pub dlpi_name: *const c_char,
741-
742-
#[cfg(target_pointer_width = "64")]
743724
pub dlpi_phdr: *const Elf64_Phdr,
744-
#[cfg(target_pointer_width = "32")]
745-
pub dlpi_phdr: *const Elf32_Phdr,
746-
747-
#[cfg(target_pointer_width = "64")]
748725
pub dlpi_phnum: Elf64_Half,
749-
#[cfg(target_pointer_width = "32")]
750-
pub dlpi_phnum: Elf32_Half,
751-
752726
pub dlpi_adds: c_ulonglong,
753727
pub dlpi_subs: c_ulonglong,
754728
pub dlpi_tls_modid: size_t,
@@ -807,7 +781,7 @@ s! {
807781
}
808782

809783
pub struct sigset_t {
810-
__val: [c_ulong; 16],
784+
pub __bits: [c_ulong; 128 / size_of::<c_long>()],
811785
}
812786

813787
pub struct shmid_ds {
@@ -872,15 +846,16 @@ s! {
872846
}
873847

874848
pub struct sem_t {
875-
__val: [c_int; 8],
849+
pub _s_value: c_int,
850+
pub _s_waiters: c_int,
876851
}
877852

853+
#[repr(align(8))]
878854
pub struct siginfo_t {
879855
pub si_signo: c_int,
880856
pub si_errno: c_int,
881857
pub si_code: c_int,
882-
pub _pad: [c_int; 29],
883-
_align: [usize; 0],
858+
pub __si_fields: [c_int; 28],
884859
}
885860

886861
#[deprecated(
@@ -951,21 +926,22 @@ s! {
951926

952927
pub struct sockaddr_storage {
953928
pub ss_family: sa_family_t,
954-
__ss_pad2: Padding<[u8; 128 - 2 - 8]>,
955-
__ss_align: size_t,
929+
__ss_padding:
930+
Padding<[c_char; 128 - size_of::<c_long>() - size_of::<crate::sa_family_t>()]>,
931+
__ss_align: c_ulong,
956932
}
957933

958934
pub struct utsname {
959935
pub sysname: [c_char; 65],
960-
pub nodename: [c_char; 65],
936+
pub nodename: [c_char; crate::HOST_NAME_MAX.cast_unsigned() as usize + 1],
961937
pub release: [c_char; 65],
962938
pub version: [c_char; 65],
963939
pub machine: [c_char; 65],
964940
pub domainname: [c_char; 65],
965941
}
966942

967943
pub struct dirent {
968-
pub d_ino: crate::ino_t,
944+
pub d_ino: ino_t,
969945
pub d_off: off_t,
970946
pub d_reclen: c_ushort,
971947
pub d_type: c_uchar,
@@ -1159,8 +1135,10 @@ cfg_if! {
11591135

11601136
// PUB_CONST
11611137

1162-
pub const INT_MIN: c_int = -2147483648;
1163-
pub const INT_MAX: c_int = 2147483647;
1138+
pub const HOST_NAME_MAX: c_int = 255;
1139+
1140+
pub const INT_MIN: c_int = -1 - 0x7fffffff;
1141+
pub const INT_MAX: c_int = 0x7fffffff;
11641142

11651143
pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
11661144
pub const SIG_IGN: sighandler_t = 1 as sighandler_t;
@@ -3141,31 +3119,43 @@ f! {
31413119
}
31423120

31433121
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
3144-
cpuset.bits.fill(0);
3122+
cpuset.__bits.fill(0);
31453123
}
31463124

3147-
pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () {
3148-
let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc
3149-
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
3150-
cpuset.bits[idx] |= 1 << offset;
3151-
()
3125+
pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> c_ulonglong {
3126+
(cpu / 8 >= size_of::<crate::cpu_set_t>())
3127+
.then_some(0)
3128+
.unwrap_or_else(|| {
3129+
let c = &mut cpuset.__bits[cpu / 8 / size_of::<c_long>()];
3130+
*c |= 1 << (cpu % (8 * size_of::<c_long>()));
3131+
3132+
*c
3133+
})
31523134
}
31533135

3154-
pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () {
3155-
let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc
3156-
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
3157-
cpuset.bits[idx] &= !(1 << offset);
3158-
()
3136+
pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> c_ulonglong {
3137+
(cpu / 8 >= size_of::<crate::cpu_set_t>())
3138+
.then_some(0)
3139+
.unwrap_or_else(|| {
3140+
let c = &mut cpuset.__bits[cpu / 8 / size_of::<c_long>()];
3141+
*c &= !(1 << (cpu % (8 * size_of::<c_long>())));
3142+
3143+
*c
3144+
})
31593145
}
31603146

31613147
pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool {
3162-
let size_in_bits = 8 * size_of_val(&cpuset.bits[0]);
3163-
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
3164-
0 != (cpuset.bits[idx] & (1 << offset))
3148+
(cpu / 8 >= size_of::<crate::cpu_set_t>())
3149+
.then_some(false)
3150+
.unwrap_or_else(|| {
3151+
(cpuset.__bits[cpu / 8 / size_of::<c_long>()]
3152+
& (1 << (cpu % (8 * size_of::<c_long>()))))
3153+
!= 0
3154+
})
31653155
}
31663156

31673157
pub fn CPU_EQUAL(set1: &cpu_set_t, set2: &cpu_set_t) -> bool {
3168-
set1.bits == set2.bits
3158+
set1.__bits == set2.__bits
31693159
}
31703160

31713161
pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {

src/fuchsia/riscv64.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::off_t;
21
use crate::prelude::*;
32

43
// From psABI Calling Convention for RV64
@@ -23,9 +22,9 @@ s! {
2322
pub st_mode: crate::mode_t,
2423
pub st_uid: crate::uid_t,
2524
pub st_gid: crate::gid_t,
26-
__pad0: Padding<c_int>,
25+
__pad0: Padding<c_uint>,
2726
pub st_rdev: crate::dev_t,
28-
pub st_size: off_t,
27+
pub st_size: crate::off_t,
2928
pub st_blksize: crate::blksize_t,
3029
pub st_blocks: crate::blkcnt_t,
3130
pub st_atime: crate::time_t,

src/fuchsia/x86_64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ s! {
1717
pub st_mode: crate::mode_t,
1818
pub st_uid: crate::uid_t,
1919
pub st_gid: crate::gid_t,
20-
__pad0: Padding<c_int>,
20+
__pad0: Padding<c_uint>,
2121
pub st_rdev: crate::dev_t,
2222
pub st_size: off_t,
2323
pub st_blksize: crate::blksize_t,

0 commit comments

Comments
 (0)