PipeWire  0.1.4
memfd-wrappers.h
Go to the documentation of this file.
1 /* PipeWire
2  * Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #include <sys/syscall.h>
21 #include <fcntl.h>
22 
23 /*
24  * No glibc wrappers exist for memfd_create(2), so provide our own.
25  *
26  * Also define memfd fcntl sealing macros. While they are already
27  * defined in the kernel header file <linux/fcntl.h>, that file as
28  * a whole conflicts with the original glibc header <fnctl.h>.
29  */
30 
31 static inline int
32 memfd_create(const char *name, unsigned int flags) {
33  return syscall(SYS_memfd_create, name, flags);
34 }
35 
36 /* memfd_create(2) flags */
37 
38 #ifndef MFD_CLOEXEC
39 #define MFD_CLOEXEC 0x0001U
40 #endif
41 
42 #ifndef MFD_ALLOW_SEALING
43 #define MFD_ALLOW_SEALING 0x0002U
44 #endif
45 
46 /* fcntl() seals-related flags */
47 
48 #ifndef F_LINUX_SPECIFIC_BASE
49 #define F_LINUX_SPECIFIC_BASE 1024
50 #endif
51 
52 #ifndef F_ADD_SEALS
53 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
54 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
55 
56 #define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
57 #define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
58 #define F_SEAL_GROW 0x0004 /* prevent file from growing */
59 #define F_SEAL_WRITE 0x0008 /* prevent writes */
60 #endif