Add new internal header glib-linux.h
[platform/upstream/glib.git] / glib / glib-linux.h
1 /*
2  * Copyright © 2014 Canonical Limited
3  *
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.
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  * Lesser General Public License for more details.
13  *
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/>.
16  *
17  * Author: Ryan Lortie <desrt@desrt.ca>
18  */
19
20 #ifndef __GLIB_LINUX_H__
21 #define __GLIB_LINUX_H__
22
23 /* If we know that we are on Linux, add some features, even if they are
24  * not (yet) advertised in the glibc or kernel headers.
25  *
26  * This allows us to use functionality regardless of if it was available
27  * when GLib was compiled or not.
28  *
29  * We take care not to define these things on non-Linux systems where
30  * certain numeric values could mean something different.
31  *
32  * This file is populated on an as-needed basis.
33  *
34  * As things in this file filter into glibc and the distributions we can
35  * remove them from this file and add unconditional dependencies.  Never
36  * add a configure.ac check in order to remove something from this file.
37  *
38  * import: include this header LAST
39  */
40
41 #ifdef __linux__
42
43 #define GLIB_LINUX
44
45 #include <sys/syscall.h>
46
47 /* futex */
48 #include <linux/futex.h>
49
50 static inline int
51 glib_linux_futex (int                   *uaddr,
52                   int                    op,
53                   int                    val,
54                   const struct timespec *timeout,
55                   int                   *uaddr2,
56                   int                    val3)
57 {
58   return syscall (__NR_futex, uaddr, op, val, timeout, uaddr2, val3);
59 }
60
61 /* memfd */
62 #ifndef MFD_CLOEXEC
63 #define MFD_CLOEXEC             0x0001U
64 #endif
65
66 #ifndef MFD_ALLOW_SEALING
67 #define MFD_ALLOW_SEALING       0x0002U
68 #endif
69
70 #ifndef __NR_memfd_create
71   #ifdef __x86_64__
72     #define __NR_memfd_create 319
73   #elif defined __arm__
74     #define __NR_memfd_create 385
75   #else
76     #define __NR_memfd_create 356
77   #endif
78 #endif
79
80 static inline int
81 glib_linux_memfd_create (const char   *name,
82                          unsigned int  flags)
83 {
84   return syscall (__NR_memfd_create, name, flags);
85 }
86
87 /* Linux-specific fcntl() operations */
88 #ifndef F_LINUX_SPECIFIC_BASE
89 #define F_LINUX_SPECIFIC_BASE 1024
90 #endif
91
92 #ifndef F_ADD_SEALS
93 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
94 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
95
96 #define F_SEAL_SEAL     0x0001  /* prevent further seals from being set */
97 #define F_SEAL_SHRINK   0x0002  /* prevent file from shrinking */
98 #define F_SEAL_GROW     0x0004  /* prevent file from growing */
99 #define F_SEAL_WRITE    0x0008  /* prevent writes */
100 #endif
101
102 #endif /* __linux __ */
103
104 #endif /* __GLIB_LINUX_H__ */