Skip to content

Commit 9bd8875

Browse files
committed
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.
2 parents 32457dd + ed45c26 commit 9bd8875

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed

libc-test/build.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,7 @@ fn test_linux(target: &str) {
24262426
"linux/rtnetlink.h",
24272427
"linux/seccomp.h",
24282428
"linux/sockios.h",
2429+
"linux/uinput.h",
24292430
"linux/vm_sockets.h",
24302431
"linux/wait.h",
24312432
"sys/fanotify.h",
@@ -2513,6 +2514,10 @@ fn test_linux(target: &str) {
25132514
if ty.starts_with("__c_anonymous_") {
25142515
return true;
25152516
}
2517+
// FIXME: musl CI has old headers
2518+
if (musl || sparc64) && ty.starts_with("uinput_") {
2519+
return true;
2520+
}
25162521
match ty {
25172522
// These cannot be tested when "resolv.h" is included and are tested
25182523
// in the `linux_elf.rs` file.
@@ -2674,6 +2679,12 @@ fn test_linux(target: &str) {
26742679
// FIXME: Requires recent kernel headers (5.8):
26752680
"STATX_MNT_ID" => true,
26762681

2682+
// FIXME: requires more recent kernel headers on CI
2683+
| "UINPUT_VERSION"
2684+
| "SW_MAX"
2685+
| "SW_CNT"
2686+
if musl || mips || ppc64 || riscv64 || sparc64 => true,
2687+
26772688
_ => false,
26782689
}
26792690
});

src/unix/linux_like/linux/mod.rs

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,24 @@ s! {
284284
pub u: [u32; 7],
285285
}
286286

287+
pub struct uinput_ff_upload {
288+
pub request_id: ::__u32,
289+
pub retval: ::__s32,
290+
pub effect: ff_effect,
291+
pub old: ff_effect,
292+
}
293+
294+
pub struct uinput_ff_erase {
295+
pub request_id: ::__u32,
296+
pub retval: ::__s32,
297+
pub effect_id: ::__u32,
298+
}
299+
300+
pub struct uinput_abs_setup {
301+
pub code: ::__u16,
302+
pub absinfo: input_absinfo,
303+
}
304+
287305
pub struct dl_phdr_info {
288306
#[cfg(target_pointer_width = "64")]
289307
pub dlpi_addr: Elf64_Addr,
@@ -557,6 +575,22 @@ s_no_extra_traits! {
557575
pub salg_name: [::c_uchar; 64],
558576
}
559577

578+
pub struct uinput_setup {
579+
pub id: input_id,
580+
pub name: [::c_char; UINPUT_MAX_NAME_SIZE],
581+
pub ff_effects_max: ::__u32,
582+
}
583+
584+
pub struct uinput_user_dev {
585+
pub name: [::c_char; UINPUT_MAX_NAME_SIZE],
586+
pub id: input_id,
587+
pub ff_effects_max: ::__u32,
588+
pub absmax: [::__s32; ABS_CNT],
589+
pub absmin: [::__s32; ABS_CNT],
590+
pub absfuzz: [::__s32; ABS_CNT],
591+
pub absflat: [::__s32; ABS_CNT],
592+
}
593+
560594
/// WARNING: The `PartialEq`, `Eq` and `Hash` implementations of this
561595
/// type are unsound and will be removed in the future.
562596
#[deprecated(
@@ -827,6 +861,72 @@ cfg_if! {
827861
}
828862
}
829863

864+
impl PartialEq for uinput_setup {
865+
fn eq(&self, other: &uinput_setup) -> bool {
866+
self.id == other.id
867+
&& self.name[..] == other.name[..]
868+
&& self.ff_effects_max == other.ff_effects_max
869+
}
870+
}
871+
impl Eq for uinput_setup {}
872+
873+
impl ::fmt::Debug for uinput_setup {
874+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
875+
f.debug_struct("uinput_setup")
876+
.field("id", &self.id)
877+
.field("name", &&self.name[..])
878+
.field("ff_effects_max", &self.ff_effects_max)
879+
.finish()
880+
}
881+
}
882+
883+
impl ::hash::Hash for uinput_setup {
884+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
885+
self.id.hash(state);
886+
self.name.hash(state);
887+
self.ff_effects_max.hash(state);
888+
}
889+
}
890+
891+
impl PartialEq for uinput_user_dev {
892+
fn eq(&self, other: &uinput_user_dev) -> bool {
893+
self.name[..] == other.name[..]
894+
&& self.id == other.id
895+
&& self.ff_effects_max == other.ff_effects_max
896+
&& self.absmax[..] == other.absmax[..]
897+
&& self.absmin[..] == other.absmin[..]
898+
&& self.absfuzz[..] == other.absfuzz[..]
899+
&& self.absflat[..] == other.absflat[..]
900+
}
901+
}
902+
impl Eq for uinput_user_dev {}
903+
904+
impl ::fmt::Debug for uinput_user_dev {
905+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
906+
f.debug_struct("uinput_setup")
907+
.field("name", &&self.name[..])
908+
.field("id", &self.id)
909+
.field("ff_effects_max", &self.ff_effects_max)
910+
.field("absmax", &&self.absmax[..])
911+
.field("absmin", &&self.absmin[..])
912+
.field("absfuzz", &&self.absfuzz[..])
913+
.field("absflat", &&self.absflat[..])
914+
.finish()
915+
}
916+
}
917+
918+
impl ::hash::Hash for uinput_user_dev {
919+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
920+
self.name.hash(state);
921+
self.id.hash(state);
922+
self.ff_effects_max.hash(state);
923+
self.absmax.hash(state);
924+
self.absmin.hash(state);
925+
self.absfuzz.hash(state);
926+
self.absflat.hash(state);
927+
}
928+
}
929+
830930
#[allow(deprecated)]
831931
impl af_alg_iv {
832932
fn as_slice(&self) -> &[u8] {
@@ -2471,6 +2571,38 @@ pub const IN_ALL_EVENTS: u32 = IN_ACCESS
24712571
pub const IN_CLOEXEC: ::c_int = O_CLOEXEC;
24722572
pub const IN_NONBLOCK: ::c_int = O_NONBLOCK;
24732573

2574+
// linux/input.h
2575+
pub const FF_MAX: ::__u16 = 0x7f;
2576+
pub const FF_CNT: usize = FF_MAX as usize + 1;
2577+
2578+
// linux/input-event-codes.h
2579+
pub const INPUT_PROP_MAX: ::__u16 = 0x1f;
2580+
pub const INPUT_PROP_CNT: usize = INPUT_PROP_MAX as usize + 1;
2581+
pub const EV_MAX: ::__u16 = 0x1f;
2582+
pub const EV_CNT: usize = EV_MAX as usize + 1;
2583+
pub const SYN_MAX: ::__u16 = 0xf;
2584+
pub const SYN_CNT: usize = SYN_MAX as usize + 1;
2585+
pub const KEY_MAX: ::__u16 = 0x2ff;
2586+
pub const KEY_CNT: usize = KEY_MAX as usize + 1;
2587+
pub const REL_MAX: ::__u16 = 0x0f;
2588+
pub const REL_CNT: usize = REL_MAX as usize + 1;
2589+
pub const ABS_MAX: ::__u16 = 0x3f;
2590+
pub const ABS_CNT: usize = ABS_MAX as usize + 1;
2591+
pub const SW_MAX: ::__u16 = 0x10;
2592+
pub const SW_CNT: usize = SW_MAX as usize + 1;
2593+
pub const MSC_MAX: ::__u16 = 0x07;
2594+
pub const MSC_CNT: usize = MSC_MAX as usize + 1;
2595+
pub const LED_MAX: ::__u16 = 0x0f;
2596+
pub const LED_CNT: usize = LED_MAX as usize + 1;
2597+
pub const REP_MAX: ::__u16 = 0x01;
2598+
pub const REP_CNT: usize = REP_MAX as usize + 1;
2599+
pub const SND_MAX: ::__u16 = 0x07;
2600+
pub const SND_CNT: usize = SND_MAX as usize + 1;
2601+
2602+
// linux/uinput.h
2603+
pub const UINPUT_VERSION: ::c_uint = 5;
2604+
pub const UINPUT_MAX_NAME_SIZE: usize = 80;
2605+
24742606
// uapi/linux/fanotify.h
24752607
pub const FAN_ACCESS: u64 = 0x0000_0001;
24762608
pub const FAN_MODIFY: u64 = 0x0000_0002;

0 commit comments

Comments
 (0)