Skip to content

Commit f2b8fb9

Browse files
committed
refactor: change bitwidths of file off tys in l4re
This patch makes a few changes to the file offset types and routines that are made available under the `unix/linux_like/l4re` module. The current upstream definitions often use 64-bit suffixed types instead of their unsuffixed types. Under a default build with unchanged makefile settings, their memory representation is effectively equivalent. The `libc` crate is striving to remove support for suffixed file offset/`time_t`-related types that only serve aliasing purposes in favor of keeping a single, fixed-width, unsuffixed type. This patch does not introduce breaking changes even though entire records have been altogether changed. This is because the currently supported target triples using L4Re in upstream rustc only include `x86_64-unknown-l4re-uclibc`. The "breaking" changes have been made to aarch64-specific types. It is also for this reason that the patch does not introduce further changes regarding the modules where symbols are defined. There are a few records, such as `stat` and `statfs`, which are defined both upstream and in the L4Re forks of musl and uClibc as being equivalent. The current maintainer for this target triple may have other plans, so that has been left unmodified. Finally, and to round up changes submitted in other patches, this patch also deprecates various types in the top-level `unix/linux_like` and `unix/linux_like/linux_l4re_shared` modules. These have been deprecated after a few observations between shared deprecated items among prior patches to platforms whose target environment coincided with one of uClibc, musl or OhOS.
1 parent 413bb61 commit f2b8fb9

7 files changed

Lines changed: 351 additions & 98 deletions

File tree

src/unix/linux_like/l4re/mod.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ pub type pthread_t = *mut c_void;
1010
pub type dev_t = u64;
1111
pub type socklen_t = u32;
1212
pub type mode_t = u32;
13-
pub type ino64_t = u64;
14-
pub type off64_t = i64;
15-
pub type blkcnt64_t = i64;
16-
pub type rlim64_t = u64;
1713
pub type nfds_t = c_ulong;
1814
pub type nl_item = c_int;
1915
pub type idtype_t = c_uint;
@@ -22,6 +18,35 @@ pub type pthread_key_t = c_uint;
2218
pub type pthread_once_t = c_int;
2319
pub type pthread_spinlock_t = c_int;
2420

21+
#[deprecated(
22+
since = "0.2.187",
23+
note = "Use `ino_t` instead. This type is defined as either one of an alias to the unsuffixed \
24+
type (musl) or is the source of the unsuffixed type (uClibc). The `libc` crate is \
25+
phasing out support for suffixed variants of types."
26+
)]
27+
pub type ino64_t = u64;
28+
#[deprecated(
29+
since = "0.2.187",
30+
note = "Use `off_t` instead. This type is defined as either one of an alias to the unsuffixed \
31+
type (musl) or is the source of the unsuffixed type (uClibc). The `libc` crate is \
32+
phasing out support for suffixed variants of types."
33+
)]
34+
pub type off64_t = i64;
35+
#[deprecated(
36+
since = "0.2.187",
37+
note = "Use `blkcnt_t` instead. This type is defined as either one of an alias to the \
38+
unsuffixed type (musl) or is the source of the unsuffixed type (uClibc). The `libc` \
39+
crate is phasing out support for suffixed variants of types."
40+
)]
41+
pub type blkcnt64_t = i64;
42+
#[deprecated(
43+
since = "0.2.187",
44+
note = "Use `rlim_t` instead. This type is defined as either one of an alias to the unsuffixed \
45+
type (musl) or is the source of the unsuffixed type (uClibc). The `libc` crate is \
46+
phasing out support for suffixed variants of types."
47+
)]
48+
pub type rlim64_t = u64;
49+
2550
s! {
2651
/// CPU sets.
2752
pub struct l4_sched_cpu_set_t {

src/unix/linux_like/l4re/uclibc/aarch64/mod.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,42 @@ pub type suseconds_t = c_long;
1515
pub type blksize_t = c_long;
1616
pub type blkcnt_t = c_long;
1717

18+
#[deprecated(
19+
since = "0.2.187",
20+
note = "Use `fsblkcnt_t` instead. The unsuffixed type is defined in terms of the suffixed type \
21+
upstream under the current target architecture (x86_64,) and support for suffixed \
22+
types is phasing out in the `libc` crate."
23+
)]
1824
pub type fsblkcnt64_t = c_ulong;
25+
#[deprecated(
26+
since = "0.2.187",
27+
note = "Use `fsfilcnt_t` instead. The unsuffixed type is defined in terms of the suffixed type \
28+
upstream under the current target architecture (x86_64,) and support for suffixed \
29+
types is phasing out in the `libc` crate."
30+
)]
1931
pub type fsfilcnt64_t = c_ulong;
2032
pub type __u64 = c_ulong;
2133

34+
pub type flock64 = flock;
35+
pub type stat64 = stat;
36+
2237
s! {
2338
pub struct stat {
24-
pub st_dev: c_ulong,
25-
pub __pad1: c_ushort,
39+
pub st_dev: crate::dev_t,
2640
pub st_ino: crate::ino_t,
27-
pub st_mode: crate::mode_t,
2841
pub st_nlink: nlink_t,
29-
pub st_uid: crate::uid_t,
30-
pub st_gid: crate::gid_t,
31-
pub st_rdev: c_ulong,
32-
pub __pad2: c_ushort,
33-
pub st_size: crate::off64_t,
34-
pub st_blksize: blksize_t,
35-
pub st_blocks: crate::blkcnt64_t,
36-
pub st_atim: crate::timespec,
37-
pub st_mtim: crate::timespec,
38-
pub st_ctim: crate::timespec,
39-
pub __uclibc_unused4: c_ulong,
40-
pub __uclibc_unused5: c_ulong,
41-
}
42-
43-
pub struct stat64 {
44-
pub st_dev: c_ulong,
45-
pub __pad1: c_uint,
46-
pub __st_ino: crate::ino_t,
4742
pub st_mode: crate::mode_t,
48-
pub st_nlink: nlink_t,
4943
pub st_uid: crate::uid_t,
5044
pub st_gid: crate::gid_t,
51-
pub st_rdev: c_ulong,
52-
pub __pad2: c_uint,
53-
pub st_size: crate::off64_t,
54-
pub st_blksize: blksize_t,
55-
pub st_blocks: crate::blkcnt64_t,
45+
__pad0: c_int,
46+
pub st_rdev: crate::dev_t,
47+
pub st_size: crate::off_t,
48+
pub st_blksize: crate::blksize_t,
49+
pub st_blocks: crate::blkcnt_t,
5650
pub st_atim: crate::timespec,
5751
pub st_mtim: crate::timespec,
5852
pub st_ctim: crate::timespec,
59-
pub st_ino: crate::ino64_t,
53+
__uclibc_unused: [c_long; 3],
6054
}
6155

6256
pub struct shmid_ds {

src/unix/linux_like/l4re/uclibc/mod.rs

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

43
pub type shmatt_t = c_ulong;
@@ -10,6 +9,9 @@ pub type __priority_which_t = c_uint;
109
pub type _pthread_descr = *mut c_void;
1110
pub type __pthread_cond_align_t = c_long;
1211

12+
pub type statfs64 = statfs;
13+
pub type statvfs64 = statvfs;
14+
1315
cfg_if! {
1416
if #[cfg(doc)] {
1517
// Used in `linux::arch` to define ioctl constants.
@@ -44,48 +46,18 @@ s! {
4446
}
4547

4648
pub struct statfs {
47-
pub f_type: fsword_t,
48-
pub f_bsize: fsword_t,
49+
pub f_type: c_long,
50+
pub f_bsize: c_long,
4951
pub f_blocks: crate::fsblkcnt_t,
5052
pub f_bfree: crate::fsblkcnt_t,
5153
pub f_bavail: crate::fsblkcnt_t,
5254
pub f_files: crate::fsfilcnt_t,
5355
pub f_ffree: crate::fsfilcnt_t,
5456
pub f_fsid: crate::fsid_t,
55-
pub f_namelen: fsword_t,
56-
pub f_frsize: fsword_t,
57-
pub f_flags: fsword_t,
58-
pub f_spare: [fsword_t; 4],
59-
}
60-
61-
pub struct statfs64 {
62-
pub f_type: fsword_t,
63-
pub f_bsize: fsword_t,
64-
pub f_blocks: crate::fsblkcnt64_t,
65-
pub f_bfree: crate::fsblkcnt64_t,
66-
pub f_bavail: crate::fsblkcnt64_t,
67-
pub f_files: crate::fsfilcnt64_t,
68-
pub f_ffree: crate::fsfilcnt64_t,
69-
pub f_fsid: crate::fsid_t,
70-
pub f_namelen: fsword_t,
71-
pub f_frsize: fsword_t,
72-
pub f_flags: fsword_t,
73-
pub f_spare: [fsword_t; 4],
74-
}
75-
76-
pub struct statvfs64 {
77-
pub f_bsize: c_ulong,
78-
pub f_frsize: c_ulong,
79-
pub f_blocks: crate::fsfilcnt64_t,
80-
pub f_bfree: crate::fsfilcnt64_t,
81-
pub f_bavail: crate::fsfilcnt64_t,
82-
pub f_files: crate::fsfilcnt64_t,
83-
pub f_ffree: crate::fsfilcnt64_t,
84-
pub f_favail: crate::fsfilcnt64_t,
85-
pub f_fsid: c_ulong,
86-
pub f_flag: c_ulong,
87-
pub f_namemax: c_ulong,
88-
pub __f_spare: [c_int; 6],
57+
pub f_namelen: c_long,
58+
pub f_frsize: c_long,
59+
pub f_flags: c_long,
60+
pub f_spare: [c_long; 4],
8961
}
9062

9163
pub struct ipc_perm {
@@ -116,12 +88,9 @@ s! {
11688
pub f_files: crate::fsfilcnt_t,
11789
pub f_ffree: crate::fsfilcnt_t,
11890
pub f_favail: crate::fsfilcnt_t,
119-
#[cfg(target_endian = "little")]
12091
pub f_fsid: c_ulong,
12192
#[cfg(target_pointer_width = "32")]
12293
__f_unused: c_int,
123-
#[cfg(target_endian = "big")]
124-
pub f_fsid: c_ulong,
12594
pub f_flag: c_ulong,
12695
pub f_namemax: c_ulong,
12796
__f_spare: [c_int; 6],
@@ -513,10 +482,24 @@ extern "C" {
513482
flags: c_int,
514483
) -> c_int;
515484

516-
pub fn pwritev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int, offset: off64_t) -> ssize_t;
517-
pub fn preadv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int, offset: off64_t) -> ssize_t;
485+
pub fn pwritev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int, offset: off_t) -> ssize_t;
486+
pub fn preadv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int, offset: off_t) -> ssize_t;
518487

488+
#[deprecated(
489+
since = "0.2.187",
490+
note = "Use `getrlimit` instead. Upstream `#define`s the unsuffixed variants in terms of \
491+
the suffixed variants under builds that use the default configurations. Support for \
492+
suffixed symbols is being phased out in the `libc` crate."
493+
)]
494+
#[allow(deprecated)]
519495
pub fn getrlimit64(resource: crate::__rlimit_resource_t, rlim: *mut crate::rlimit64) -> c_int;
496+
#[deprecated(
497+
since = "0.2.187",
498+
note = "Use `setrlimit` instead. Upstream `#define`s the unsuffixed variants in terms of \
499+
the suffixed variants under builds that use the default configurations. Support for \
500+
suffixed symbols is being phased out in the `libc` crate."
501+
)]
502+
#[allow(deprecated)]
520503
pub fn setrlimit64(resource: crate::__rlimit_resource_t, rlim: *const crate::rlimit64)
521504
-> c_int;
522505
pub fn getrlimit(resource: crate::__rlimit_resource_t, rlim: *mut crate::rlimit) -> c_int;

src/unix/linux_like/l4re/uclibc/x86_64/mod.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,46 @@ pub type suseconds_t = c_long;
1717
pub type blksize_t = c_long;
1818
pub type blkcnt_t = c_long;
1919

20+
#[deprecated(
21+
since = "0.2.187",
22+
note = "Use `fsblkcnt_t` instead. The unsuffixed type is defined in terms of the suffixed type \
23+
upstream under the current target architecture (x86_64,) and support for suffixed \
24+
types is phasing out in the `libc` crate."
25+
)]
2026
pub type fsblkcnt64_t = c_ulong;
27+
#[deprecated(
28+
since = "0.2.187",
29+
note = "Use `fsfilcnt_t` instead. The unsuffixed type is defined in terms of the suffixed type \
30+
upstream under the current target architecture (x86_64,) and support for suffixed \
31+
types is phasing out in the `libc` crate."
32+
)]
2133
pub type fsfilcnt64_t = c_ulong;
2234

2335
pub type __u32 = c_uint;
2436
pub type __u64 = c_ulong;
2537

38+
pub type stat64 = stat;
39+
pub type flock64 = flock;
40+
2641
s! {
2742
pub struct stat {
28-
pub st_dev: c_ulong,
43+
pub st_dev: crate::dev_t,
2944
pub st_ino: crate::ino_t,
30-
// According to uclibc/libc/sysdeps/linux/x86_64/bits/stat.h, order of
31-
// nlink and mode are swapped on 64 bit systems.
3245
pub st_nlink: nlink_t,
3346
pub st_mode: crate::mode_t,
3447
pub st_uid: crate::uid_t,
3548
pub st_gid: crate::gid_t,
3649
__pad0: c_int,
37-
pub st_rdev: c_ulong,
50+
pub st_rdev: crate::dev_t,
3851
pub st_size: crate::off_t,
3952
pub st_blksize: crate::blksize_t,
40-
pub st_blocks: crate::blkcnt64_t,
53+
pub st_blocks: crate::blkcnt_t,
4154
pub st_atim: crate::timespec,
4255
pub st_mtim: crate::timespec,
4356
pub st_ctim: crate::timespec,
4457
__uclibc_unused: [c_long; 3],
4558
}
4659

47-
pub struct stat64 {
48-
pub st_dev: c_ulong,
49-
pub st_ino: crate::ino_t,
50-
pub st_nlink: nlink_t,
51-
pub st_mode: crate::mode_t,
52-
pub st_uid: crate::uid_t,
53-
pub st_gid: crate::gid_t,
54-
__pad0: c_int,
55-
pub st_rdev: c_ulong,
56-
pub st_size: crate::off_t,
57-
pub st_blksize: crate::blksize_t,
58-
pub st_blocks: crate::blkcnt64_t,
59-
pub st_atim: crate::timespec,
60-
pub st_mtim: crate::timespec,
61-
pub st_ctim: crate::timespec,
62-
st_pad4: [c_long; 3],
63-
}
64-
6560
pub struct shmid_ds {
6661
pub shm_perm: crate::ipc_perm,
6762
pub shm_segsz: crate::size_t,

src/unix/linux_like/linux/musl/lfs64.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(deprecated)]
2+
13
use crate::off64_t;
24
use crate::prelude::*;
35

src/unix/linux_like/linux_l4re_shared.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,17 @@ s! {
283283
pub val: c_int,
284284
}
285285

286+
#[cfg_attr(
287+
any(target_env = "uclibc", target_env = "musl", target_env = "ohos"),
288+
deprecated(
289+
since = "0.2.187",
290+
note = "Use `rlimit` instead. The unsuffixed type is defined as an alias to this type, \
291+
and their memory layout is effectively equivalent. The `libc` crate is phasing \
292+
out support for suffixed variants in favor of a single, unsuffixed, fixed \
293+
bitwidth symbol."
294+
),
295+
allow(deprecated)
296+
)]
286297
pub struct rlimit64 {
287298
pub rlim_cur: crate::rlim64_t,
288299
pub rlim_max: crate::rlim64_t,
@@ -305,6 +316,17 @@ s! {
305316
pub d_name: [c_char; 256],
306317
}
307318

319+
#[cfg_attr(
320+
any(target_env = "uclibc", target_env = "musl", target_env = "ohos"),
321+
deprecated(
322+
since = "0.2.187",
323+
note = "Use `dirent` instead. The unsuffixed type is defined as an alias to this type, \
324+
and their memory layout is effectively equivalent. The `libc` crate is phasing \
325+
out support for suffixed variants in favor of a single, unsuffixed, fixed \
326+
bitwidth symbol."
327+
),
328+
allow(deprecated)
329+
)]
308330
pub struct dirent64 {
309331
pub d_ino: crate::ino64_t,
310332
pub d_off: crate::off64_t,
@@ -1926,18 +1948,55 @@ extern "C" {
19261948
cfg_if! {
19271949
if #[cfg(not(any(target_env = "musl", target_env = "ohos")))] {
19281950
extern "C" {
1951+
#[cfg_attr(
1952+
target_env = "uclibc",
1953+
deprecated(
1954+
since = "0.2.187",
1955+
note = "Use `freopen` instead. The unsuffixed routine is `#define`d as an \
1956+
alias to the suffixed routine in default builds of uClibc. Support for \
1957+
suffixed variants is phasing out in the `libc` crate."
1958+
)
1959+
)]
19291960
pub fn freopen64(
19301961
filename: *const c_char,
19311962
mode: *const c_char,
19321963
file: *mut crate::FILE,
19331964
) -> *mut crate::FILE;
1965+
#[cfg_attr(
1966+
target_env = "uclibc",
1967+
deprecated(
1968+
since = "0.2.187",
1969+
note = "Use `fseeko` instead. The unsuffixed routine is `#define`d as an alias \
1970+
to the suffixed routine in default builds of uClibc. Support for \
1971+
suffixed variants is phasing out in the `libc` crate."
1972+
)
1973+
)]
19341974
pub fn fseeko64(
19351975
stream: *mut crate::FILE,
1936-
offset: crate::off64_t,
1976+
#[cfg(not(target_env = "uclibc"))] offset: crate::off64_t,
1977+
#[cfg(target_env = "uclibc")] offset: crate::off_t,
19371978
whence: c_int,
19381979
) -> c_int;
1980+
#[cfg_attr(
1981+
target_env = "uclibc",
1982+
deprecated(
1983+
since = "0.2.187",
1984+
note = "Use `fsetpos` instead. The unsuffixed routine is `#define`d as an \
1985+
alias to the suffixed routine in default builds of uClibc. Support for \
1986+
suffixed variants is phasing out in the `libc` crate."
1987+
)
1988+
)]
19391989
pub fn fsetpos64(stream: *mut crate::FILE, ptr: *const crate::fpos64_t) -> c_int;
1990+
#[cfg(not(target_env = "uclibc"))]
19401991
pub fn ftello64(stream: *mut crate::FILE) -> crate::off64_t;
1992+
#[cfg(target_env = "uclibc")]
1993+
#[deprecated(
1994+
since = "0.2.187",
1995+
note = "Use `ftello` instead. The unsuffixed routine is `#define`d as an alias \
1996+
to the suffixed routine in default builds of uClibc. Support for \
1997+
suffixed variants is phasing out in the `libc` crate."
1998+
)]
1999+
pub fn ftello64(stream: *mut crate::FILE) -> crate::off_t;
19412000
}
19422001
}
19432002
}

0 commit comments

Comments
 (0)