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>
2016-03-13 01:04:18 +02:00
|
|
|
#ifndef foopulsememfdwrappershfoo
|
|
|
|
|
#define foopulsememfdwrappershfoo
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
This file is part of PulseAudio.
|
|
|
|
|
|
|
|
|
|
Copyright 2016 Ahmed S. Darwish <darwish.07@gmail.com>
|
|
|
|
|
|
|
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
***/
|
|
|
|
|
|
2018-01-24 03:51:49 +02:00
|
|
|
#if defined(HAVE_MEMFD) && !defined(HAVE_MEMFD_CREATE)
|
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>
2016-03-13 01:04:18 +02:00
|
|
|
|
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
|
/*
|
2018-01-24 03:51:49 +02:00
|
|
|
* Before glibc version 2.27 there was no wrapper for memfd_create(2),
|
|
|
|
|
* so we have to provide our own.
|
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>
2016-03-13 01:04:18 +02:00
|
|
|
*
|
|
|
|
|
* Also define memfd fcntl sealing macros. While they are already
|
|
|
|
|
* defined in the kernel header file <linux/fcntl.h>, that file as
|
|
|
|
|
* a whole conflicts with the original glibc header <fnctl.h>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static inline int memfd_create(const char *name, unsigned int flags) {
|
|
|
|
|
return syscall(SYS_memfd_create, name, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* memfd_create(2) flags */
|
|
|
|
|
|
|
|
|
|
#ifndef MFD_CLOEXEC
|
|
|
|
|
#define MFD_CLOEXEC 0x0001U
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef MFD_ALLOW_SEALING
|
|
|
|
|
#define MFD_ALLOW_SEALING 0x0002U
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* fcntl() seals-related flags */
|
|
|
|
|
|
|
|
|
|
#ifndef F_LINUX_SPECIFIC_BASE
|
|
|
|
|
#define F_LINUX_SPECIFIC_BASE 1024
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef F_ADD_SEALS
|
|
|
|
|
#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
|
|
|
|
|
#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
|
|
|
|
|
|
|
|
|
|
#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
|
|
|
|
|
#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
|
|
|
|
|
#define F_SEAL_GROW 0x0004 /* prevent file from growing */
|
|
|
|
|
#define F_SEAL_WRITE 0x0008 /* prevent writes */
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-01-24 03:51:49 +02:00
|
|
|
#endif /* HAVE_MEMFD && !HAVE_MEMFD_CREATE */
|
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>
2016-03-13 01:04:18 +02:00
|
|
|
|
|
|
|
|
#endif
|