pulsecore: Introduce memfd support

Memfd is a simple memory sharing mechanism, added by the systemd/kdbus
developers, to share pages between processes in an anonymous, no global
registry needed, no mount-point required, relatively secure, manner.

This patch introduces the necessary building blocks for using memfd
shared memory transfers in PulseAudio.

Memfd support shall also help us in laying out the necessary (but not
yet sufficient) groundwork for application sandboxing, protecting PA
from its clients, and protecting clients data from each other.

We plan to exclusively use memfds, instead of POSIX SHM, on the way
forward.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
This commit is contained in:
Ahmed S. Darwish 2016-03-13 01:04:18 +02:00 committed by David Henningsson
parent 1c3a2bcaf1
commit 73e86b1cb1
5 changed files with 231 additions and 66 deletions

View file

@ -30,7 +30,19 @@ typedef struct pa_shm {
unsigned id;
void *ptr;
size_t size;
/* Only for type = PA_MEM_TYPE_SHARED_POSIX */
bool do_unlink:1;
/* Only for type = PA_MEM_TYPE_SHARED_MEMFD
*
* To avoid fd leaks, we keep this fd open only until we pass it
* to the other PA endpoint over unix domain socket.
*
* When we don't have ownership for the memfd fd in question (e.g.
* pa_shm_attach()), or the file descriptor has now been closed,
* this is set to -1. */
int fd;
} pa_shm;
int pa_shm_create_rw(pa_shm *m, pa_mem_type_t type, size_t size, mode_t mode);