summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-03-13 05:14:24 +0000
committerbors <bors@rust-lang.org>2021-03-13 05:14:24 +0000
commit9bd88759e0bfa68e19cd88028f9d7ee422aca615 (patch)
tree6585743974a719f5aaf03b305aef0159a7f68068
parent32457ddd8f7446b336d87d6c5f2c64416021e055 (diff)
parented45c2649b848bc2df48ba10d68194d45da03b75 (diff)
downloadrust-libc-9bd88759e0bfa68e19cd88028f9d7ee422aca615.tar.gz
Auto merge of #2106 - coolreader18:uinput-structs, r=coolreader18
Add structs from linux/uinput.h + a couple of input-related constants I could also add the full constant list from `input-event-codes.h`, but that's about 1000 lines of constants and it's not necessary to interact with the ioctls, just to interpret the values they return/accept. Also, I made the `_CNT` constants usize instead of u16 since they're intended to be buffer lengths, not actual `input_event.code` (or whatever else) values.
-rwxr-xr-xlibc-test/build.rs11
-rw-r--r--src/unix/linux_like/linux/mod.rs132
2 files changed, 143 insertions, 0 deletions
diff --git a/libc-test/build.rs b/libc-test/build.rs
index 978aec7781..4155040464 100755
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -2426,6 +2426,7 @@ fn test_linux(target: &str) {
"linux/rtnetlink.h",
"linux/seccomp.h",
"linux/sockios.h",
+ "linux/uinput.h",
"linux/vm_sockets.h",
"linux/wait.h",
"sys/fanotify.h",
@@ -2513,6 +2514,10 @@ fn test_linux(target: &str) {
if ty.starts_with("__c_anonymous_") {
return true;
}
+ // FIXME: musl CI has old headers
+ if (musl || sparc64) && ty.starts_with("uinput_") {
+ return true;
+ }
match ty {
// These cannot be tested when "resolv.h" is included and are tested
// in the `linux_elf.rs` file.
@@ -2674,6 +2679,12 @@ fn test_linux(target: &str) {
// FIXME: Requires recent kernel headers (5.8):
"STATX_MNT_ID" => true,
+ // FIXME: requires more recent kernel headers on CI
+ | "UINPUT_VERSION"
+ | "SW_MAX"
+ | "SW_CNT"
+ if musl || mips || ppc64 || riscv64 || sparc64 => true,
+
_ => false,
}
});
diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs
index ce71f1c7ef..c526d0207a 100644
--- a/src/unix/linux_like/linux/mod.rs
+++ b/src/unix/linux_like/linux/mod.rs
@@ -284,6 +284,24 @@ s! {
pub u: [u32; 7],
}
+ pub struct uinput_ff_upload {
+ pub request_id: ::__u32,
+ pub retval: ::__s32,
+ pub effect: ff_effect,
+ pub old: ff_effect,
+ }
+
+ pub struct uinput_ff_erase {
+ pub request_id: ::__u32,
+ pub retval: ::__s32,
+ pub effect_id: ::__u32,
+ }
+
+ pub struct uinput_abs_setup {
+ pub code: ::__u16,
+ pub absinfo: input_absinfo,
+ }
+
pub struct dl_phdr_info {
#[cfg(target_pointer_width = "64")]
pub dlpi_addr: Elf64_Addr,
@@ -557,6 +575,22 @@ s_no_extra_traits! {
pub salg_name: [::c_uchar; 64],
}
+ pub struct uinput_setup {
+ pub id: input_id,
+ pub name: [::c_char; UINPUT_MAX_NAME_SIZE],
+ pub ff_effects_max: ::__u32,
+ }
+
+ pub struct uinput_user_dev {
+ pub name: [::c_char; UINPUT_MAX_NAME_SIZE],
+ pub id: input_id,
+ pub ff_effects_max: ::__u32,
+ pub absmax: [::__s32; ABS_CNT],
+ pub absmin: [::__s32; ABS_CNT],
+ pub absfuzz: [::__s32; ABS_CNT],
+ pub absflat: [::__s32; ABS_CNT],
+ }
+
/// WARNING: The `PartialEq`, `Eq` and `Hash` implementations of this
/// type are unsound and will be removed in the future.
#[deprecated(
@@ -827,6 +861,72 @@ cfg_if! {
}
}
+ impl PartialEq for uinput_setup {
+ fn eq(&self, other: &uinput_setup) -> bool {
+ self.id == other.id
+ && self.name[..] == other.name[..]
+ && self.ff_effects_max == other.ff_effects_max
+ }
+ }
+ impl Eq for uinput_setup {}
+
+ impl ::fmt::Debug for uinput_setup {
+ fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
+ f.debug_struct("uinput_setup")
+ .field("id", &self.id)
+ .field("name", &&self.name[..])
+ .field("ff_effects_max", &self.ff_effects_max)
+ .finish()
+ }
+ }
+
+ impl ::hash::Hash for uinput_setup {
+ fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
+ self.id.hash(state);
+ self.name.hash(state);
+ self.ff_effects_max.hash(state);
+ }
+ }
+
+ impl PartialEq for uinput_user_dev {
+ fn eq(&self, other: &uinput_user_dev) -> bool {
+ self.name[..] == other.name[..]
+ && self.id == other.id
+ && self.ff_effects_max == other.ff_effects_max
+ && self.absmax[..] == other.absmax[..]
+ && self.absmin[..] == other.absmin[..]
+ && self.absfuzz[..] == other.absfuzz[..]
+ && self.absflat[..] == other.absflat[..]
+ }
+ }
+ impl Eq for uinput_user_dev {}
+
+ impl ::fmt::Debug for uinput_user_dev {
+ fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
+ f.debug_struct("uinput_setup")
+ .field("name", &&self.name[..])
+ .field("id", &self.id)
+ .field("ff_effects_max", &self.ff_effects_max)
+ .field("absmax", &&self.absmax[..])
+ .field("absmin", &&self.absmin[..])
+ .field("absfuzz", &&self.absfuzz[..])
+ .field("absflat", &&self.absflat[..])
+ .finish()
+ }
+ }
+
+ impl ::hash::Hash for uinput_user_dev {
+ fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
+ self.name.hash(state);
+ self.id.hash(state);
+ self.ff_effects_max.hash(state);
+ self.absmax.hash(state);
+ self.absmin.hash(state);
+ self.absfuzz.hash(state);
+ self.absflat.hash(state);
+ }
+ }
+
#[allow(deprecated)]
impl af_alg_iv {
fn as_slice(&self) -> &[u8] {
@@ -2471,6 +2571,38 @@ pub const IN_ALL_EVENTS: u32 = IN_ACCESS
pub const IN_CLOEXEC: ::c_int = O_CLOEXEC;
pub const IN_NONBLOCK: ::c_int = O_NONBLOCK;
+// linux/input.h
+pub const FF_MAX: ::__u16 = 0x7f;
+pub const FF_CNT: usize = FF_MAX as usize + 1;
+
+// linux/input-event-codes.h
+pub const INPUT_PROP_MAX: ::__u16 = 0x1f;
+pub const INPUT_PROP_CNT: usize = INPUT_PROP_MAX as usize + 1;
+pub const EV_MAX: ::__u16 = 0x1f;
+pub const EV_CNT: usize = EV_MAX as usize + 1;
+pub const SYN_MAX: ::__u16 = 0xf;
+pub const SYN_CNT: usize = SYN_MAX as usize + 1;
+pub const KEY_MAX: ::__u16 = 0x2ff;
+pub const KEY_CNT: usize = KEY_MAX as usize + 1;
+pub const REL_MAX: ::__u16 = 0x0f;
+pub const REL_CNT: usize = REL_MAX as usize + 1;
+pub const ABS_MAX: ::__u16 = 0x3f;
+pub const ABS_CNT: usize = ABS_MAX as usize + 1;
+pub const SW_MAX: ::__u16 = 0x10;
+pub const SW_CNT: usize = SW_MAX as usize + 1;
+pub const MSC_MAX: ::__u16 = 0x07;
+pub const MSC_CNT: usize = MSC_MAX as usize + 1;
+pub const LED_MAX: ::__u16 = 0x0f;
+pub const LED_CNT: usize = LED_MAX as usize + 1;
+pub const REP_MAX: ::__u16 = 0x01;
+pub const REP_CNT: usize = REP_MAX as usize + 1;
+pub const SND_MAX: ::__u16 = 0x07;
+pub const SND_CNT: usize = SND_MAX as usize + 1;
+
+// linux/uinput.h
+pub const UINPUT_VERSION: ::c_uint = 5;
+pub const UINPUT_MAX_NAME_SIZE: usize = 80;
+
// uapi/linux/fanotify.h
pub const FAN_ACCESS: u64 = 0x0000_0001;
pub const FAN_MODIFY: u64 = 0x0000_0002;