mem: set READWRITE flags

This commit is contained in:
Wim Taymans 2019-07-24 10:58:00 +02:00
parent bae1426615
commit e5778b8745
5 changed files with 17 additions and 5 deletions

View file

@ -1209,6 +1209,7 @@ static void node_initialized(void *data)
size = sizeof(struct spa_io_buffers) * MAX_AREAS; size = sizeof(struct spa_io_buffers) * MAX_AREAS;
if (pw_mempool_alloc(impl->core->pool, if (pw_mempool_alloc(impl->core->pool,
PW_MEMBLOCK_FLAG_READWRITE |
PW_MEMBLOCK_FLAG_MAP | PW_MEMBLOCK_FLAG_MAP |
PW_MEMBLOCK_FLAG_SEAL, PW_MEMBLOCK_FLAG_SEAL,
size, &impl->io_areas) < 0) size, &impl->io_areas) < 0)

View file

@ -184,6 +184,7 @@ int pw_control_add_link(struct pw_control *control, uint32_t cmix,
if (impl->mem == NULL) { if (impl->mem == NULL) {
if ((res = pw_mempool_alloc(control->core->pool, if ((res = pw_mempool_alloc(control->core->pool,
PW_MEMBLOCK_FLAG_READWRITE |
PW_MEMBLOCK_FLAG_SEAL | PW_MEMBLOCK_FLAG_SEAL |
PW_MEMBLOCK_FLAG_MAP, PW_MEMBLOCK_FLAG_MAP,
size, &impl->mem)) < 0) size, &impl->mem)) < 0)

View file

@ -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); bp = SPA_MEMBER(buffers, n_buffers * sizeof(struct spa_buffer *), struct spa_buffer);
if ((res = pw_mempool_alloc(this->core->pool, if ((res = pw_mempool_alloc(this->core->pool,
PW_MEMBLOCK_FLAG_READWRITE |
PW_MEMBLOCK_FLAG_SEAL | PW_MEMBLOCK_FLAG_SEAL |
PW_MEMBLOCK_FLAG_MAP, PW_MEMBLOCK_FLAG_MAP,
n_buffers * info.mem_size, &m)) < 0) n_buffers * info.mem_size, &m)) < 0)

View file

@ -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); b->this.fd = memfd_create("pipewire-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING);
if (b->this.fd == -1) { if (b->this.fd == -1) {
res = -errno; res = -errno;
pw_log_error("Failed to create memfd: %s\n", strerror(errno)); pw_log_error("Failed to create memfd: %m");
goto error_free; goto error_free;
} }
#else #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); b->this.fd = mkostemp(filename, O_CLOEXEC);
if (b->this.fd == -1) { if (b->this.fd == -1) {
res = -errno; 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; goto error_free;
} }
unlink(filename); 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) { if (ftruncate(b->this.fd, size) < 0) {
res = -errno; 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; goto error_close;
} }
#ifdef USE_MEMFD #ifdef USE_MEMFD
if (flags & PW_MEMBLOCK_FLAG_SEAL) { if (flags & PW_MEMBLOCK_FLAG_SEAL) {
unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL; unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL;
if (fcntl(b->this.fd, F_ADD_SEALS, seals) == -1) { 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 #endif
b->this.type = SPA_DATA_MemFd; b->this.type = SPA_DATA_MemFd;
if (flags & PW_MEMBLOCK_FLAG_MAP && size > 0) { 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) { if (b->this.map == NULL) {
res = -errno; res = -errno;
pw_log_warn("Failed to map: %m");
goto error_close; goto error_close;
} }
} }

View file

@ -863,6 +863,7 @@ struct pw_node *pw_node_new(struct pw_core *core,
size = sizeof(struct pw_node_activation); size = sizeof(struct pw_node_activation);
if ((res = pw_mempool_alloc(this->core->pool, if ((res = pw_mempool_alloc(this->core->pool,
PW_MEMBLOCK_FLAG_READWRITE |
PW_MEMBLOCK_FLAG_SEAL | PW_MEMBLOCK_FLAG_SEAL |
PW_MEMBLOCK_FLAG_MAP, PW_MEMBLOCK_FLAG_MAP,
size, &this->activation)) < 0) size, &this->activation)) < 0)