Changeset View
Changeset View
Standalone View
Standalone View
head/graphics/wayland/files/patch-src_wayland-shm.c
--- src/wayland-shm.c.orig 2018-04-09 17:19:26 UTC | --- src/wayland-shm.c.orig 2020-02-11 23:46:03 UTC | ||||
+++ src/wayland-shm.c | +++ src/wayland-shm.c | ||||
@@ -30,6 +30,8 @@ | @@ -32,6 +32,8 @@ | ||||
#define _GNU_SOURCE | #include "config.h" | ||||
+#include "../config.h" | +#include "../config.h" | ||||
+ | + | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
@@ -59,6 +61,9 @@ struct wl_shm_pool { | @@ -64,6 +66,9 @@ struct wl_shm_pool { | ||||
char *data; | |||||
int32_t size; | int32_t size; | ||||
int32_t new_size; | int32_t new_size; | ||||
bool sigbus_is_impossible; | |||||
+#ifdef HAVE_SYS_UCRED_H | +#ifdef HAVE_SYS_UCRED_H | ||||
+ int fd; | + int fd; | ||||
+#endif | +#endif | ||||
}; | }; | ||||
struct wl_shm_buffer { | struct wl_shm_buffer { | ||||
@@ -76,15 +81,24 @@ struct wl_shm_sigbus_data { | @@ -81,15 +86,24 @@ struct wl_shm_sigbus_data { | ||||
int fallback_mapping_used; | int fallback_mapping_used; | ||||
}; | }; | ||||
+static void *mremap_compat_maymove(void *, size_t, size_t, int, int, int); | +static void *mremap_compat_maymove(void *, size_t, size_t, int, int, int); | ||||
+ | + | ||||
static void | static void | ||||
shm_pool_finish_resize(struct wl_shm_pool *pool) | shm_pool_finish_resize(struct wl_shm_pool *pool) | ||||
{ | { | ||||
Show All 9 Lines | |||||
+#endif | +#endif | ||||
+ | + | ||||
+ data = mremap_compat_maymove(pool->data, pool->size, pool->new_size, | + data = mremap_compat_maymove(pool->data, pool->size, pool->new_size, | ||||
+ PROT_READ | PROT_WRITE, MAP_SHARED, fd); | + PROT_READ | PROT_WRITE, MAP_SHARED, fd); | ||||
+ | + | ||||
if (data == MAP_FAILED) { | if (data == MAP_FAILED) { | ||||
wl_resource_post_error(pool->resource, | wl_resource_post_error(pool->resource, | ||||
WL_SHM_ERROR_INVALID_FD, | WL_SHM_ERROR_INVALID_FD, | ||||
@@ -110,6 +124,10 @@ shm_pool_unref(struct wl_shm_pool *pool, bool external | @@ -115,6 +129,10 @@ shm_pool_unref(struct wl_shm_pool *pool, bool external | ||||
if (pool->internal_refcount + pool->external_refcount) | if (pool->internal_refcount + pool->external_refcount) | ||||
return; | return; | ||||
+#ifdef HAVE_SYS_UCRED_H | +#ifdef HAVE_SYS_UCRED_H | ||||
+ close(pool->fd); | + close(pool->fd); | ||||
+#endif | +#endif | ||||
+ | + | ||||
munmap(pool->data, pool->size); | munmap(pool->data, pool->size); | ||||
free(pool); | free(pool); | ||||
} | } | ||||
@@ -223,6 +241,73 @@ shm_pool_destroy(struct wl_client *client, struct wl_r | @@ -228,6 +246,73 @@ shm_pool_destroy(struct wl_client *client, struct wl_r | ||||
wl_resource_destroy(resource); | wl_resource_destroy(resource); | ||||
} | } | ||||
+#ifdef HAVE_MREMAP | +#ifdef HAVE_MREMAP | ||||
+static void * | +static void * | ||||
+mremap_compat_maymove(void *old_address, size_t old_size, size_t new_size, | +mremap_compat_maymove(void *old_address, size_t old_size, size_t new_size, | ||||
+ int old_prot, int old_flags, int old_fd) | + int old_prot, int old_flags, int old_fd) | ||||
+{ | +{ | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
+ /* Unreachable. */ | + /* Unreachable. */ | ||||
+ return MAP_FAILED; | + return MAP_FAILED; | ||||
+} | +} | ||||
+#endif | +#endif | ||||
+ | + | ||||
static void | static void | ||||
shm_pool_resize(struct wl_client *client, struct wl_resource *resource, | shm_pool_resize(struct wl_client *client, struct wl_resource *resource, | ||||
int32_t size) | int32_t size) | ||||
@@ -284,7 +369,14 @@ shm_create_pool(struct wl_client *client, struct wl_re | @@ -300,7 +385,14 @@ shm_create_pool(struct wl_client *client, struct wl_re | ||||
"failed mmap fd %d: %m", fd); | strerror(errno)); | ||||
goto err_free; | goto err_free; | ||||
} | } | ||||
+ | + | ||||
+#ifdef HAVE_SYS_UCRED_H | +#ifdef HAVE_SYS_UCRED_H | ||||
+ /* We need to keep the FD around on FreeBSD so we can implement | + /* We need to keep the FD around on FreeBSD so we can implement | ||||
+ * mremap(). See: mremap_compat_maymove(). */ | + * mremap(). See: mremap_compat_maymove(). */ | ||||
+ pool->fd = fd; | + pool->fd = fd; | ||||
+#else | +#else | ||||
close(fd); | close(fd); | ||||
+#endif | +#endif | ||||
pool->resource = | pool->resource = | ||||
wl_resource_create(client, &wl_shm_pool_interface, 1, id); | wl_resource_create(client, &wl_shm_pool_interface, 1, id); |