Problem with mmap keyboard.

Emmanuel Gil Peyrot linkmauve at linkmauve.fr
Wed Oct 4 18:28:58 UTC 2023


On Wed, Oct 04, 2023 at 06:19:30PM +0000, Fred vS wrote:
> Hello.

Hi,

> 
> 
> I try to make work the "Keyboard event" step from the Wayland-book but the C demo crash at loading.
> 
> The problem comes from the mapping: with that error:
> 
> 
> Line 301: wl_keyboard_keymap: Assertion map_shm != MAP_FAILED' failed.
> 
> 
> Here is the function:
> 
> static void
> wl_keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
>              uint32_t format, int32_t fd, uint32_t size)
> {
>      struct client_state *client_state = data;
>      assert(format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1);
> 
>      // Line 301: Here problem with mapping
>      char *map_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);

We can read in the documentation of this protocol:
https://wayland.app/protocols/wayland#wl_keyboard:event:keymap

“From version 7 onwards, the fd must be mapped with MAP_PRIVATE by the
recipient, as MAP_SHARED may fail.”

I don’t know which wl_shell version you are using, but check that maybe.

>      assert(map_shm != MAP_FAILED);
> 
>      struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_string(
>                      client_state->xkb_context, map_shm,
>                      XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
>      munmap(map_shm, size);
>      close(fd);
> 
>      struct xkb_state *xkb_state = xkb_state_new(xkb_keymap);
>      xkb_keymap_unref(client_state->xkb_keymap);
>      xkb_state_unref(client_state->xkb_state);
>      client_state->xkb_keymap = xkb_keymap;
>      client_state->xkb_state = xkb_state;
> }
> 
> 
> 
> Why does the mapping fails, I did check fd and size and they are correctly assigned?
> 
> 
> Thanks.
> 

-- 
Link Mauve


More information about the wayland-devel mailing list