153a5a1b3Sopenharmony_ci#ifndef foopulsememfdwrappershfoo
253a5a1b3Sopenharmony_ci#define foopulsememfdwrappershfoo
353a5a1b3Sopenharmony_ci
453a5a1b3Sopenharmony_ci/***
553a5a1b3Sopenharmony_ci  This file is part of PulseAudio.
653a5a1b3Sopenharmony_ci
753a5a1b3Sopenharmony_ci  Copyright 2016 Ahmed S. Darwish <darwish.07@gmail.com>
853a5a1b3Sopenharmony_ci
953a5a1b3Sopenharmony_ci  PulseAudio is free software; you can redistribute it and/or modify
1053a5a1b3Sopenharmony_ci  it under the terms of the GNU Lesser General Public License as
1153a5a1b3Sopenharmony_ci  published by the Free Software Foundation; either version 2.1 of the
1253a5a1b3Sopenharmony_ci  License, or (at your option) any later version.
1353a5a1b3Sopenharmony_ci
1453a5a1b3Sopenharmony_ci  PulseAudio is distributed in the hope that it will be useful, but
1553a5a1b3Sopenharmony_ci  WITHOUT ANY WARRANTY; without even the implied warranty of
1653a5a1b3Sopenharmony_ci  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1753a5a1b3Sopenharmony_ci  Lesser General Public License for more details.
1853a5a1b3Sopenharmony_ci
1953a5a1b3Sopenharmony_ci  You should have received a copy of the GNU Lesser General Public
2053a5a1b3Sopenharmony_ci  License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
2153a5a1b3Sopenharmony_ci***/
2253a5a1b3Sopenharmony_ci
2353a5a1b3Sopenharmony_ci#if defined(HAVE_MEMFD) && !defined(HAVE_MEMFD_CREATE)
2453a5a1b3Sopenharmony_ci
2553a5a1b3Sopenharmony_ci#include <sys/syscall.h>
2653a5a1b3Sopenharmony_ci#include <fcntl.h>
2753a5a1b3Sopenharmony_ci
2853a5a1b3Sopenharmony_ci/*
2953a5a1b3Sopenharmony_ci * Before glibc version 2.27 there was no wrapper for memfd_create(2),
3053a5a1b3Sopenharmony_ci * so we have to provide our own.
3153a5a1b3Sopenharmony_ci *
3253a5a1b3Sopenharmony_ci * Also define memfd fcntl sealing macros. While they are already
3353a5a1b3Sopenharmony_ci * defined in the kernel header file <linux/fcntl.h>, that file as
3453a5a1b3Sopenharmony_ci * a whole conflicts with the original glibc header <fnctl.h>.
3553a5a1b3Sopenharmony_ci */
3653a5a1b3Sopenharmony_ci
3753a5a1b3Sopenharmony_cistatic inline int memfd_create(const char *name, unsigned int flags) {
3853a5a1b3Sopenharmony_ci    return syscall(SYS_memfd_create, name, flags);
3953a5a1b3Sopenharmony_ci}
4053a5a1b3Sopenharmony_ci
4153a5a1b3Sopenharmony_ci/* memfd_create(2) flags */
4253a5a1b3Sopenharmony_ci
4353a5a1b3Sopenharmony_ci#ifndef MFD_CLOEXEC
4453a5a1b3Sopenharmony_ci#define MFD_CLOEXEC       0x0001U
4553a5a1b3Sopenharmony_ci#endif
4653a5a1b3Sopenharmony_ci
4753a5a1b3Sopenharmony_ci#ifndef MFD_ALLOW_SEALING
4853a5a1b3Sopenharmony_ci#define MFD_ALLOW_SEALING 0x0002U
4953a5a1b3Sopenharmony_ci#endif
5053a5a1b3Sopenharmony_ci
5153a5a1b3Sopenharmony_ci/* fcntl() seals-related flags */
5253a5a1b3Sopenharmony_ci
5353a5a1b3Sopenharmony_ci#ifndef F_LINUX_SPECIFIC_BASE
5453a5a1b3Sopenharmony_ci#define F_LINUX_SPECIFIC_BASE 1024
5553a5a1b3Sopenharmony_ci#endif
5653a5a1b3Sopenharmony_ci
5753a5a1b3Sopenharmony_ci#ifndef F_ADD_SEALS
5853a5a1b3Sopenharmony_ci#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
5953a5a1b3Sopenharmony_ci#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
6053a5a1b3Sopenharmony_ci
6153a5a1b3Sopenharmony_ci#define F_SEAL_SEAL     0x0001  /* prevent further seals from being set */
6253a5a1b3Sopenharmony_ci#define F_SEAL_SHRINK   0x0002  /* prevent file from shrinking */
6353a5a1b3Sopenharmony_ci#define F_SEAL_GROW     0x0004  /* prevent file from growing */
6453a5a1b3Sopenharmony_ci#define F_SEAL_WRITE    0x0008  /* prevent writes */
6553a5a1b3Sopenharmony_ci#endif
6653a5a1b3Sopenharmony_ci
6753a5a1b3Sopenharmony_ci#endif /* HAVE_MEMFD && !HAVE_MEMFD_CREATE */
6853a5a1b3Sopenharmony_ci
6953a5a1b3Sopenharmony_ci#endif
70