1 #ifndef foopulsememfdwrappershfoo 2 #define foopulsememfdwrappershfoo 3 4 /*** 5 This file is part of PulseAudio. 6 7 Copyright 2016 Ahmed S. Darwish <darwish.07@gmail.com> 8 9 PulseAudio is free software; you can redistribute it and/or modify 10 it under the terms of the GNU Lesser General Public License as 11 published by the Free Software Foundation; either version 2.1 of the 12 License, or (at your option) any later version. 13 14 PulseAudio is distributed in the hope that it will be useful, but 15 WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 Lesser General Public License for more details. 18 19 You should have received a copy of the GNU Lesser General Public 20 License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 21 ***/ 22 23 #if defined(HAVE_MEMFD) && !defined(HAVE_MEMFD_CREATE) 24 25 #include <sys/syscall.h> 26 #include <fcntl.h> 27 28 /* 29 * Before glibc version 2.27 there was no wrapper for memfd_create(2), 30 * so we have to provide our own. 31 * 32 * Also define memfd fcntl sealing macros. While they are already 33 * defined in the kernel header file <linux/fcntl.h>, that file as 34 * a whole conflicts with the original glibc header <fnctl.h>. 35 */ 36 memfd_create(const char * name,unsigned int flags)37static inline int memfd_create(const char *name, unsigned int flags) { 38 return syscall(SYS_memfd_create, name, flags); 39 } 40 41 /* memfd_create(2) flags */ 42 43 #ifndef MFD_CLOEXEC 44 #define MFD_CLOEXEC 0x0001U 45 #endif 46 47 #ifndef MFD_ALLOW_SEALING 48 #define MFD_ALLOW_SEALING 0x0002U 49 #endif 50 51 /* fcntl() seals-related flags */ 52 53 #ifndef F_LINUX_SPECIFIC_BASE 54 #define F_LINUX_SPECIFIC_BASE 1024 55 #endif 56 57 #ifndef F_ADD_SEALS 58 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) 59 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) 60 61 #define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */ 62 #define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ 63 #define F_SEAL_GROW 0x0004 /* prevent file from growing */ 64 #define F_SEAL_WRITE 0x0008 /* prevent writes */ 65 #endif 66 67 #endif /* HAVE_MEMFD && !HAVE_MEMFD_CREATE */ 68 69 #endif 70