Skip to content

Commit

Permalink
Auto merge of #2106 - coolreader18:uinput-structs, r=coolreader18
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Mar 13, 2021
2 parents 32457dd + ed45c26 commit 9bd8875
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 0 deletions.
11 changes: 11 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
}
});
Expand Down
132 changes: 132 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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] {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9bd8875

Please sign in to comment.