Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux_wayland (uinput) doesn't work on 32-bit linux systems #12

Open
BrianHoldsworth opened this issue Jan 18, 2024 · 5 comments
Open

Comments

@BrianHoldsworth
Copy link

BrianHoldsworth commented Jan 18, 2024

Hi. I've only tested on ARMv7, but I'd assume the problem exists with any 32-bit linux. On 32-bit linux, the timeval struct, which is part of the input_event struct, uses 32-bit longs. However, the struct is hard-coded for 64-bit longs.

I fixed this for ARMv7 with the following change:

diff --git a/src/linux_wayland/ffi/input.rs b/src/linux_wayland/ffi/input.rs
index a8c6b08..3447684 100644
--- a/src/linux_wayland/ffi/input.rs
+++ b/src/linux_wayland/ffi/input.rs
@@ -1,11 +1,13 @@
 // https://github.com/torvalds/linux/blob/master/include/uapi/linux/input.h
 
+use std::ffi::c_long;
+
 #[repr(C)]
 #[allow(non_camel_case_types)]
 pub struct timeval {
     // Not quite sure if these should be 32 or 64
-    pub tv_sec: i64,
-    pub tv_usec: i64,
+    pub tv_sec: c_long,
+    pub tv_usec: c_long,
 }
 
 #[repr(C)]
@indianakernick
Copy link
Owner

Digging through the headers, it kind of seems like timeval could be using 64-bit integers even on a 32-bit system. If the intent is 32-bit int on 32-bit system and 64-bit int on 64-bit system then isize is another option. I'm not 100% convinced that this is correct but I don't know how to do it better. It almost seems like it needs to be another feature flag.

@indianakernick
Copy link
Owner

I thought about it and realised that I was probably over-analysing the problem. I pushed up a fix.

@BrianHoldsworth
Copy link
Author

BrianHoldsworth commented Jan 20, 2024

I see. Unfortunately, using isize in place of c_long doesn't work with my Raspberry Pi target.

The target description (taken from the output of the linux file command) is ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV)

@indianakernick
Copy link
Owner

So isize is 64 bits on a 32-bit target? That's unexpected! I switched it to c_long.

@BrianHoldsworth
Copy link
Author

It seems like isize is about the architecture's maximum address range. Whereas the c types are data range. But I'm also not sure and it is hard to know without testing on more archs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants