2 * Copyright © 2014 Canonical Limited
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the licence, or (at your option) any later version.
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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 * Author: Ryan Lortie <desrt@desrt.ca>
20 #ifndef __GLIB_LINUX_H__
21 #define __GLIB_LINUX_H__
25 /* If we know that we are on Linux, add some features, even if they are
26 * not (yet) advertised in the glibc or kernel headers.
28 * This allows us to use functionality regardless of if it was available
29 * when GLib was compiled or not.
31 * We take care not to define these things on non-Linux systems where
32 * certain numeric values could mean something different.
34 * This file is populated on an as-needed basis.
36 * As things in this file filter into glibc and the distributions we can
37 * remove them from this file and add unconditional dependencies. Never
38 * add a configure.ac check in order to remove something from this file.
40 * import: include this header LAST
47 #include <sys/syscall.h>
50 glib_linux_enosys (void)
57 #include <linux/futex.h>
60 glib_linux_futex (int *uaddr,
63 const struct timespec *timeout,
67 return syscall (__NR_futex, uaddr, op, val, timeout, uaddr2, val3);
72 #define MFD_CLOEXEC 0x0001U
75 #ifndef MFD_ALLOW_SEALING
76 #define MFD_ALLOW_SEALING 0x0002U
79 #ifndef __NR_memfd_create
80 # if defined __x86_64__
81 # define __NR_memfd_create 319
83 # define __NR_memfd_create 356
84 # elif defined __arm__
85 /* arm and arm64 have the same value */
86 # define __NR_memfd_create 385
87 # elif defined _MIPS_SIM
88 # if _MIPS_SIM == _MIPS_SIM_ABI32
89 # define __NR_memfd_create 4354
91 # if _MIPS_SIM == _MIPS_SIM_NABI32
92 # define __NR_memfd_create 6318
94 # if _MIPS_SIM == _MIPS_SIM_ABI64
95 # define __NR_memfd_create 5314
101 glib_linux_memfd_create (const char *name,
104 #ifdef __NR_memfd_create
105 return syscall (__NR_memfd_create, name, flags);
107 return glib_linux_enosys ();
111 /* Linux-specific fcntl() operations */
112 #ifndef F_LINUX_SPECIFIC_BASE
113 #define F_LINUX_SPECIFIC_BASE 1024
117 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
118 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
120 #define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
121 #define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
122 #define F_SEAL_GROW 0x0004 /* prevent file from growing */
123 #define F_SEAL_WRITE 0x0008 /* prevent writes */
126 #endif /* __linux __ */
128 #endif /* __GLIB_LINUX_H__ */