Skip to content

Commit 8802703

Browse files
committed
Auto merge of #2550 - de-vri-es:restore-ioctl-types, r=JohnTitor
Use libc specific type for architecture specific ioctl defines on Linux. This PR should fix the type change of some ioctl constants on Linux introduced by #2530. It does this by adding a `#[doc(hidden)]` type called `Ioctl`, which is defined in libc specific modules and used in arch specific modules. However, when doing this I noticed that when I added `TCGETS2`, `TCSETS2`, ... in #2508, I unconditionally used `c_ulong`. This is inconsistent with the other ioctl constants for `musl` and `uclibc`. This PR also changes those to use the libc specific types. However, PR #2508 has already been released in 0.2.107, so technically that is also a semver incompatible change. The impact is limited to new constants introduced in the last release, and only on `musl` and `uclibc` targets. So what is more important here? Consistency in the type of ioctl constants, or being very strict with backwards compatibility? If it is the latter, I'll revert `TCGETS2` etc to `c_ulong` for this PR.
2 parents fd4fe30 + 7c95819 commit 8802703

File tree

8 files changed

+67
-28
lines changed

8 files changed

+67
-28
lines changed

libc-test/build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,6 +2741,9 @@ fn test_linux(target: &str) {
27412741
| "Elf64_Shdr" | "Elf32_Sym" | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr"
27422742
| "Elf32_Chdr" | "Elf64_Chdr" => ty.to_string(),
27432743

2744+
"Ioctl" if gnu => "unsigned long".to_string(),
2745+
"Ioctl" => "int".to_string(),
2746+
27442747
t if is_union => format!("union {}", t),
27452748

27462749
t if t.ends_with("_t") => t.to_string(),
@@ -2798,6 +2801,9 @@ fn test_linux(target: &str) {
27982801
// on Linux, this is a volatile int
27992802
"pthread_spinlock_t" => true,
28002803

2804+
// For internal use only, to define architecture specific ioctl constants with a libc specific type.
2805+
"Ioctl" => true,
2806+
28012807
_ => false,
28022808
}
28032809
});
@@ -3228,6 +3234,7 @@ fn test_linux(target: &str) {
32283234
// This function tests APIs that are incompatible to test when other APIs
32293235
// are included (e.g. because including both sets of headers clashes)
32303236
fn test_linux_like_apis(target: &str) {
3237+
let gnu = target.contains("gnu");
32313238
let musl = target.contains("musl");
32323239
let linux = target.contains("linux");
32333240
let emscripten = target.contains("emscripten");
@@ -3294,6 +3301,8 @@ fn test_linux_like_apis(target: &str) {
32943301
})
32953302
.skip_struct(|s| s != "termios2")
32963303
.type_name(move |ty, is_struct, is_union| match ty {
3304+
"Ioctl" if gnu => "unsigned long".to_string(),
3305+
"Ioctl" => "int".to_string(),
32973306
t if is_struct => format!("struct {}", t),
32983307
t if is_union => format!("union {}", t),
32993308
t => t.to_string(),

src/unix/linux_like/linux/arch/generic/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ cfg_if! {
112112
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
113113
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;
114114

115-
pub const TIOCMGET: ::c_ulong = 0x5415;
116-
pub const TIOCMBIS: ::c_ulong = 0x5416;
117-
pub const TIOCMBIC: ::c_ulong = 0x5417;
118-
pub const TIOCMSET: ::c_ulong = 0x5418;
119-
pub const TCGETS2: ::c_ulong = 0x802c542a;
120-
pub const TCSETS2: ::c_ulong = 0x402c542b;
121-
pub const TCSETSW2: ::c_ulong = 0x402c542c;
122-
pub const TCSETSF2: ::c_ulong = 0x402c542d;
115+
pub const TIOCMGET: ::Ioctl = 0x5415;
116+
pub const TIOCMBIS: ::Ioctl = 0x5416;
117+
pub const TIOCMBIC: ::Ioctl = 0x5417;
118+
pub const TIOCMSET: ::Ioctl = 0x5418;
119+
pub const TCGETS2: ::Ioctl = 0x802c542a;
120+
pub const TCSETS2: ::Ioctl = 0x402c542b;
121+
pub const TCSETSW2: ::Ioctl = 0x402c542c;
122+
pub const TCSETSF2: ::Ioctl = 0x402c542d;
123123

124124
pub const TIOCM_LE: ::c_int = 0x001;
125125
pub const TIOCM_DTR: ::c_int = 0x002;

src/unix/linux_like/linux/arch/mips/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ pub const SO_TIMESTAMPING: ::c_int = 37;
108108
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
109109
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;
110110

111-
pub const TIOCMGET: ::c_ulong = 0x741d;
112-
pub const TIOCMBIS: ::c_ulong = 0x741b;
113-
pub const TIOCMBIC: ::c_ulong = 0x741c;
114-
pub const TIOCMSET: ::c_ulong = 0x741a;
115-
pub const TCGETS2: ::c_ulong = 0x4030542a;
116-
pub const TCSETS2: ::c_ulong = 0x8030542b;
117-
pub const TCSETSW2: ::c_ulong = 0x8030542c;
118-
pub const TCSETSF2: ::c_ulong = 0x8030542d;
111+
pub const TIOCMGET: ::Ioctl = 0x741d;
112+
pub const TIOCMBIS: ::Ioctl = 0x741b;
113+
pub const TIOCMBIC: ::Ioctl = 0x741c;
114+
pub const TIOCMSET: ::Ioctl = 0x741a;
115+
pub const TCGETS2: ::Ioctl = 0x4030542a;
116+
pub const TCSETS2: ::Ioctl = 0x8030542b;
117+
pub const TCSETSW2: ::Ioctl = 0x8030542c;
118+
pub const TCSETSF2: ::Ioctl = 0x8030542d;
119119

120120
pub const TIOCM_LE: ::c_int = 0x001;
121121
pub const TIOCM_DTR: ::c_int = 0x002;

src/unix/linux_like/linux/arch/powerpc/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ pub const SO_BINDTOIFINDEX: ::c_int = 62;
9090
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
9191
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;
9292

93-
pub const TIOCMGET: ::c_int = 0x5415;
94-
pub const TIOCMBIS: ::c_int = 0x5416;
95-
pub const TIOCMBIC: ::c_int = 0x5417;
96-
pub const TIOCMSET: ::c_int = 0x5418;
93+
pub const TIOCMGET: ::Ioctl = 0x5415;
94+
pub const TIOCMBIS: ::Ioctl = 0x5416;
95+
pub const TIOCMBIC: ::Ioctl = 0x5417;
96+
pub const TIOCMSET: ::Ioctl = 0x5418;
9797

9898
pub const TIOCM_LE: ::c_int = 0x001;
9999
pub const TIOCM_DTR: ::c_int = 0x002;

src/unix/linux_like/linux/arch/sparc/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ pub const SO_TIMESTAMPING: ::c_int = 0x0023;
100100
pub const SCM_TIMESTAMPNS: ::c_int = SO_TIMESTAMPNS;
101101
pub const SCM_TIMESTAMPING: ::c_int = SO_TIMESTAMPING;
102102

103-
pub const TIOCMGET: ::c_ulong = 0x4004746a;
104-
pub const TIOCMBIS: ::c_ulong = 0x8004746c;
105-
pub const TIOCMBIC: ::c_ulong = 0x8004746b;
106-
pub const TIOCMSET: ::c_ulong = 0x8004746d;
107-
pub const TCGETS2: ::c_ulong = 0x402c540c;
108-
pub const TCSETS2: ::c_ulong = 0x802c540d;
109-
pub const TCSETSW2: ::c_ulong = 0x802c540e;
110-
pub const TCSETSF2: ::c_ulong = 0x802c540f;
103+
pub const TIOCMGET: ::Ioctl = 0x4004746a;
104+
pub const TIOCMBIS: ::Ioctl = 0x8004746c;
105+
pub const TIOCMBIC: ::Ioctl = 0x8004746b;
106+
pub const TIOCMSET: ::Ioctl = 0x8004746d;
107+
pub const TCGETS2: ::Ioctl = 0x402c540c;
108+
pub const TCSETS2: ::Ioctl = 0x802c540d;
109+
pub const TCSETSW2: ::Ioctl = 0x802c540e;
110+
pub const TCSETSF2: ::Ioctl = 0x802c540f;
111111

112112
pub const TIOCM_LE: ::c_int = 0x001;
113113
pub const TIOCM_DTR: ::c_int = 0x002;

src/unix/linux_like/linux/gnu/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ pub type __rlimit_resource_t = ::c_uint;
44
pub type Lmid_t = ::c_long;
55
pub type regoff_t = ::c_int;
66

7+
cfg_if! {
8+
if #[cfg(doc)] {
9+
// Used in `linux::arch` to define ioctl constants.
10+
pub(crate) type Ioctl = ::c_ulong;
11+
} else {
12+
#[doc(hidden)]
13+
pub type Ioctl = ::c_ulong;
14+
}
15+
}
16+
717
s! {
818
pub struct statx {
919
pub stx_mask: u32,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ pub type rlim_t = ::c_ulonglong;
2424

2525
pub type flock64 = flock;
2626

27+
cfg_if! {
28+
if #[cfg(doc)] {
29+
// Used in `linux::arch` to define ioctl constants.
30+
pub(crate) type Ioctl = ::c_int;
31+
} else {
32+
#[doc(hidden)]
33+
pub type Ioctl = ::c_int;
34+
}
35+
}
36+
2737
impl siginfo_t {
2838
pub unsafe fn si_addr(&self) -> *mut ::c_void {
2939
#[repr(C)]

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ pub type regoff_t = ::c_int;
55
pub type __rlimit_resource_t = ::c_uint;
66
pub type __priority_which_t = ::c_uint;
77

8+
cfg_if! {
9+
if #[cfg(doc)] {
10+
// Used in `linux::arch` to define ioctl constants.
11+
pub(crate) type Ioctl = ::c_int;
12+
} else {
13+
#[doc(hidden)]
14+
pub type Ioctl = ::c_int;
15+
}
16+
}
17+
818
s! {
919
pub struct statvfs { // Different than GNU!
1020
pub f_bsize: ::c_ulong,

0 commit comments

Comments
 (0)