mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	shm: use mremap on pool resize
This commit is contained in:
		
							parent
							
								
									d860f0cbec
								
							
						
					
					
						commit
						086b4e2c1a
					
				
					 1 changed files with 5 additions and 7 deletions
				
			
		| 
						 | 
					@ -25,6 +25,8 @@
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define _GNU_SOURCE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
| 
						 | 
					@ -38,7 +40,6 @@ struct wl_shm_pool {
 | 
				
			||||||
	int refcount;
 | 
						int refcount;
 | 
				
			||||||
	char *data;
 | 
						char *data;
 | 
				
			||||||
	int size;
 | 
						int size;
 | 
				
			||||||
	int fd;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wl_shm_buffer {
 | 
					struct wl_shm_buffer {
 | 
				
			||||||
| 
						 | 
					@ -57,7 +58,6 @@ shm_pool_unref(struct wl_shm_pool *pool)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	munmap(pool->data, pool->size);
 | 
						munmap(pool->data, pool->size);
 | 
				
			||||||
	close(pool->fd);
 | 
					 | 
				
			||||||
	free(pool);
 | 
						free(pool);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -160,17 +160,15 @@ shm_pool_resize(struct wl_client *client, struct wl_resource *resource,
 | 
				
			||||||
	struct wl_shm_pool *pool = resource->data;
 | 
						struct wl_shm_pool *pool = resource->data;
 | 
				
			||||||
	void *data;
 | 
						void *data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
 | 
						data = mremap(pool->data, pool->size, size, MREMAP_MAYMOVE);
 | 
				
			||||||
		    pool->fd, 0);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (data == MAP_FAILED) {
 | 
						if (data == MAP_FAILED) {
 | 
				
			||||||
		wl_resource_post_error(resource,
 | 
							wl_resource_post_error(resource,
 | 
				
			||||||
				       WL_SHM_ERROR_INVALID_FD,
 | 
									       WL_SHM_ERROR_INVALID_FD,
 | 
				
			||||||
				       "failed mmap fd %d", pool->fd);
 | 
									       "failed mremap");
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	munmap(pool->data, pool->size);
 | 
					 | 
				
			||||||
	pool->data = data;
 | 
						pool->data = data;
 | 
				
			||||||
	pool->size = size;
 | 
						pool->size = size;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -203,10 +201,10 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pool->refcount = 1;
 | 
						pool->refcount = 1;
 | 
				
			||||||
	pool->fd = fd;
 | 
					 | 
				
			||||||
	pool->size = size;
 | 
						pool->size = size;
 | 
				
			||||||
	pool->data = mmap(NULL, size,
 | 
						pool->data = mmap(NULL, size,
 | 
				
			||||||
			  PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 | 
								  PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 | 
				
			||||||
 | 
						close(fd);
 | 
				
			||||||
	if (pool->data == MAP_FAILED) {
 | 
						if (pool->data == MAP_FAILED) {
 | 
				
			||||||
		wl_resource_post_error(resource,
 | 
							wl_resource_post_error(resource,
 | 
				
			||||||
				       WL_SHM_ERROR_INVALID_FD,
 | 
									       WL_SHM_ERROR_INVALID_FD,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue