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:
2020
2121 name: test
2222 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
2623
2724 steps:
2825 - uses: actions/checkout@v6
@@ -31,8 +28,8 @@ jobs:
3128
3229 - name: Install dependencies
3330 run: |
34- apt-get update -y
35- apt-get install -y ${{ env.DEPS_APT }}
31+ sudo apt-get update -y
32+ sudo apt-get install -y ${{ env.DEPS_APT }}
3633
3734 - uses: dtolnay/rust-toolchain@stable
3835
@@ -114,9 +111,6 @@ jobs:
114111
115112 name: randomized and slow tests
116113 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
120114
121115 env:
122116 RUST_BACKTRACE: 1
@@ -133,8 +127,8 @@ jobs:
133127
134128 - name: Install dependencies
135129 run: |
136- apt-get update -y
137- apt-get install -y ${{ env.DEPS_APT }}
130+ sudo apt-get update -y
131+ sudo apt-get install -y ${{ env.DEPS_APT }}
138132
139133 - uses: dtolnay/rust-toolchain@stable
140134
Cargo.tomlmodified+1 -1
@@ -96,7 +96,7 @@ tracing.workspace = true
9696 tracy-client.workspace = true
9797 wayland-backend = "0.3.15"
9898 wayland-scanner = "0.31.10"
99-wayland-server = { version = "0.31.13", features = ["libwayland_1_23"] }
99+wayland-server = "0.31.13"
100100 xcursor = "0.3.10"
101101 zbus = { version = "5.13.2", optional = true }
102102
src/main.rsmodified+36 -1
@@ -172,7 +172,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
172172 let display = Display::new().unwrap();
173173
174174 // 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);
176176
177177 let mut state = State::new(
178178 config,
@@ -374,3 +374,38 @@ fn notify_fd() -> anyhow::Result<()> {
374374 notif.write_all(b"READY=1\n")?;
375375 Ok(())
376376 }
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+}