mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	mem: set READWRITE flags
This commit is contained in:
		
							parent
							
								
									bae1426615
								
							
						
					
					
						commit
						e5778b8745
					
				
					 5 changed files with 17 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -1209,6 +1209,7 @@ static void node_initialized(void *data)
 | 
			
		|||
	size = sizeof(struct spa_io_buffers) * MAX_AREAS;
 | 
			
		||||
 | 
			
		||||
	if (pw_mempool_alloc(impl->core->pool,
 | 
			
		||||
				PW_MEMBLOCK_FLAG_READWRITE |
 | 
			
		||||
				PW_MEMBLOCK_FLAG_MAP |
 | 
			
		||||
				PW_MEMBLOCK_FLAG_SEAL,
 | 
			
		||||
				size, &impl->io_areas) < 0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -184,6 +184,7 @@ int pw_control_add_link(struct pw_control *control, uint32_t cmix,
 | 
			
		|||
 | 
			
		||||
	if (impl->mem == NULL) {
 | 
			
		||||
		if ((res = pw_mempool_alloc(control->core->pool,
 | 
			
		||||
						PW_MEMBLOCK_FLAG_READWRITE |
 | 
			
		||||
						PW_MEMBLOCK_FLAG_SEAL |
 | 
			
		||||
						PW_MEMBLOCK_FLAG_MAP,
 | 
			
		||||
						size, &impl->mem)) < 0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -446,6 +446,7 @@ static int alloc_buffers(struct pw_link *this,
 | 
			
		|||
	bp = SPA_MEMBER(buffers, n_buffers * sizeof(struct spa_buffer *), struct spa_buffer);
 | 
			
		||||
 | 
			
		||||
	if ((res = pw_mempool_alloc(this->core->pool,
 | 
			
		||||
					PW_MEMBLOCK_FLAG_READWRITE |
 | 
			
		||||
					PW_MEMBLOCK_FLAG_SEAL |
 | 
			
		||||
					PW_MEMBLOCK_FLAG_MAP,
 | 
			
		||||
					n_buffers * info.mem_size, &m)) < 0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -418,7 +418,7 @@ int pw_mempool_alloc(struct pw_mempool *pool, enum pw_memblock_flags flags,
 | 
			
		|||
	b->this.fd = memfd_create("pipewire-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING);
 | 
			
		||||
	if (b->this.fd == -1) {
 | 
			
		||||
		res = -errno;
 | 
			
		||||
		pw_log_error("Failed to create memfd: %s\n", strerror(errno));
 | 
			
		||||
		pw_log_error("Failed to create memfd: %m");
 | 
			
		||||
		goto error_free;
 | 
			
		||||
	}
 | 
			
		||||
#else
 | 
			
		||||
| 
						 | 
				
			
			@ -426,7 +426,7 @@ int pw_mempool_alloc(struct pw_mempool *pool, enum pw_memblock_flags flags,
 | 
			
		|||
	b->this.fd = mkostemp(filename, O_CLOEXEC);
 | 
			
		||||
	if (b->this.fd == -1) {
 | 
			
		||||
		res = -errno;
 | 
			
		||||
		pw_log_error("Failed to create temporary file: %s\n", strerror(errno));
 | 
			
		||||
		pw_log_error("Failed to create temporary file: %m");
 | 
			
		||||
		goto error_free;
 | 
			
		||||
	}
 | 
			
		||||
	unlink(filename);
 | 
			
		||||
| 
						 | 
				
			
			@ -434,23 +434,31 @@ int pw_mempool_alloc(struct pw_mempool *pool, enum pw_memblock_flags flags,
 | 
			
		|||
 | 
			
		||||
	if (ftruncate(b->this.fd, size) < 0) {
 | 
			
		||||
		res = -errno;
 | 
			
		||||
		pw_log_warn("Failed to truncate temporary file: %s", strerror(errno));
 | 
			
		||||
		pw_log_warn("Failed to truncate temporary file: %m");
 | 
			
		||||
		goto error_close;
 | 
			
		||||
	}
 | 
			
		||||
#ifdef USE_MEMFD
 | 
			
		||||
	if (flags & PW_MEMBLOCK_FLAG_SEAL) {
 | 
			
		||||
		unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL;
 | 
			
		||||
		if (fcntl(b->this.fd, F_ADD_SEALS, seals) == -1) {
 | 
			
		||||
			pw_log_warn("Failed to add seals: %s", strerror(errno));
 | 
			
		||||
			pw_log_warn("Failed to add seals: %m");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
#endif
 | 
			
		||||
	b->this.type = SPA_DATA_MemFd;
 | 
			
		||||
 | 
			
		||||
	if (flags & PW_MEMBLOCK_FLAG_MAP && size > 0) {
 | 
			
		||||
		b->this.map = pw_memblock_map(&b->this, PROT_READ|PROT_WRITE, 0, size);
 | 
			
		||||
		enum pw_memmap_flags fl = 0;
 | 
			
		||||
 | 
			
		||||
		if (flags & PW_MEMBLOCK_FLAG_READABLE)
 | 
			
		||||
			fl |= PW_MEMMAP_FLAG_READ;
 | 
			
		||||
		if (flags & PW_MEMBLOCK_FLAG_WRITABLE)
 | 
			
		||||
			fl |= PW_MEMMAP_FLAG_WRITE;
 | 
			
		||||
 | 
			
		||||
		b->this.map = pw_memblock_map(&b->this, fl, 0, size);
 | 
			
		||||
		if (b->this.map == NULL) {
 | 
			
		||||
			res = -errno;
 | 
			
		||||
			pw_log_warn("Failed to map: %m");
 | 
			
		||||
			goto error_close;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -863,6 +863,7 @@ struct pw_node *pw_node_new(struct pw_core *core,
 | 
			
		|||
	size = sizeof(struct pw_node_activation);
 | 
			
		||||
 | 
			
		||||
	if ((res = pw_mempool_alloc(this->core->pool,
 | 
			
		||||
					PW_MEMBLOCK_FLAG_READWRITE |
 | 
			
		||||
					PW_MEMBLOCK_FLAG_SEAL |
 | 
			
		||||
					PW_MEMBLOCK_FLAG_MAP,
 | 
			
		||||
					size, &this->activation)) < 0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue