forge
Explore
Log in

Don't you dare go Hollow

Dlsym set_default_max_buffer_size() to avoid wayland-server 1.23 requirement

Browse files at this commit

c814c656c53ea9d69f5afb45c88f4dc4d25338cdIvan MolodetskikhParent: 82d4c75
Ubuntu 24.04 users rejoice
.github/workflows/ci.ymlmodified+4 -10
@@ -20,9 +20,6 @@ jobs:
20 20
21 name: test21 name: test
22 runs-on: ubuntu-24.0422 runs-on: ubuntu-24.04
23- # FIXME: remove once it's available in runs-on.
24- # This is necessary for libwayland-server v1.23.
25- container: ubuntu:26.04
26 23
27 steps:24 steps:
28 - uses: actions/checkout@v625 - uses: actions/checkout@v6
@@ -31,8 +28,8 @@ jobs:
31 28
32 - name: Install dependencies29 - name: Install dependencies
33 run: |30 run: |
34- apt-get update -y31+ sudo apt-get update -y
35- apt-get install -y ${{ env.DEPS_APT }}32+ sudo apt-get install -y ${{ env.DEPS_APT }}
36 33
37 - uses: dtolnay/rust-toolchain@stable34 - uses: dtolnay/rust-toolchain@stable
38 35
@@ -114,9 +111,6 @@ jobs:
114 111
115 name: randomized and slow tests112 name: randomized and slow tests
116 runs-on: ubuntu-24.04113 runs-on: ubuntu-24.04
117- # FIXME: remove once it's available in runs-on.
118- # This is necessary for libwayland-server v1.23.
119- container: ubuntu:26.04
120 114
121 env:115 env:
122 RUST_BACKTRACE: 1116 RUST_BACKTRACE: 1
@@ -133,8 +127,8 @@ jobs:
133 127
134 - name: Install dependencies128 - name: Install dependencies
135 run: |129 run: |
136- apt-get update -y130+ sudo apt-get update -y
137- apt-get install -y ${{ env.DEPS_APT }}131+ sudo apt-get install -y ${{ env.DEPS_APT }}
138 132
139 - uses: dtolnay/rust-toolchain@stable133 - uses: dtolnay/rust-toolchain@stable
140 134
Cargo.tomlmodified+1 -1
@@ -96,7 +96,7 @@ tracing.workspace = true
96 tracy-client.workspace = true96 tracy-client.workspace = true
97 wayland-backend = "0.3.15"97 wayland-backend = "0.3.15"
98 wayland-scanner = "0.31.10"98 wayland-scanner = "0.31.10"
99-wayland-server = { version = "0.31.13", features = ["libwayland_1_23"] }99+wayland-server = "0.31.13"
100 xcursor = "0.3.10"100 xcursor = "0.3.10"
101 zbus = { version = "5.13.2", optional = true }101 zbus = { version = "5.13.2", optional = true }
102 102
src/main.rsmodified+36 -1
@@ -172,7 +172,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
172 let display = Display::new().unwrap();172 let display = Display::new().unwrap();
173 173
174 // Increase the buffer size so that it's harder to crash a frozen client with a 1000 Hz mouse.174 // Increase the buffer size so that it's harder to crash a frozen client with a 1000 Hz mouse.
175- display.handle().set_default_max_buffer_size(1024 * 1024);175+ set_default_max_buffer_size(&display, 1024 * 1024);
176 176
177 let mut state = State::new(177 let mut state = State::new(
178 config,178 config,
@@ -374,3 +374,38 @@ fn notify_fd() -> anyhow::Result<()> {
374 notif.write_all(b"READY=1\n")?;374 notif.write_all(b"READY=1\n")?;
375 Ok(())375 Ok(())
376 }376 }
377+
378+// The wayland-server crate has set_default_max_buffer_size() under a libwayland_1_23 feature, but
379+// this hard-requires libwayland-server >= 1.23 which is not present on e.g. Ubuntu 24.04. Since
380+// calling this is an optional enhancement, do it optionally at runtime.
381+fn set_default_max_buffer_size(display: &Display<State>, size: usize) {
382+ use std::ffi::c_void;
383+
384+ unsafe {
385+ // RTLD_NOLOAD ensures we only get a handle to the libwayland-server that wayland-rs has
386+ // already loaded into this process, rather than potentially pulling in a different copy.
387+ let lib = libc::dlopen(
388+ c"libwayland-server.so.0".as_ptr(),
389+ libc::RTLD_LAZY | libc::RTLD_NOLOAD,
390+ );
391+ if lib.is_null() {
392+ // It's not really expected that this can happen, maybe if some distro changes the
393+ // library name?
394+ warn!("cannot set default max buffer size: libwayland-server.so.0 is not loaded");
395+ return;
396+ }
397+
398+ let sym = libc::dlsym(lib, c"wl_display_set_default_max_buffer_size".as_ptr());
399+ if sym.is_null() {
400+ // Expected on libwayland-server < 1.23.
401+ trace!("wl_display_set_default_max_buffer_size is missing; skipping");
402+ return;
403+ } else {
404+ let func: unsafe extern "C" fn(*mut c_void, libc::size_t) = std::mem::transmute(sym);
405+ let display_ptr = display.handle().backend_handle().display_ptr();
406+ func(display_ptr.cast(), size);
407+ }
408+
409+ libc::dlclose(lib);
410+ }
411+}