[kdbus] sync with kdbus (kdbus.h - commit: 5ae1ecac44cb)
[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 #include <errno.h>
24
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.
27  *
28  * This allows us to use functionality regardless of if it was available
29  * when GLib was compiled or not.
30  *
31  * We take care not to define these things on non-Linux systems where
32  * certain numeric values could mean something different.
33  *
34  * This file is populated on an as-needed basis.
35  *
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.
39  *
40  * import: include this header LAST
41  */
42
43 #ifdef __linux__
44
45 #define GLIB_LINUX
46
47 #include <sys/syscall.h>
48
49 static inline int
50 glib_linux_enosys (void)
51 {
52   errno = ENOSYS;
53   return -1;
54 }
55
56 /* futex */
57 #include <linux/futex.h>
58
59 static inline int
60 glib_linux_futex (int                   *uaddr,
61                   int                    op,
62                   int                    val,
63                   const struct timespec *timeout,
64                   int                   *uaddr2,
65                   int                    val3)
66 {
67   return syscall (__NR_futex, uaddr, op, val, timeout, uaddr2, val3);
68 }
69
70 /* memfd */
71 #ifndef MFD_CLOEXEC
72 #define MFD_CLOEXEC             0x0001U
73 #endif
74
75 #ifndef MFD_ALLOW_SEALING
76 #define MFD_ALLOW_SEALING       0x0002U
77 #endif
78
79 #ifndef __NR_memfd_create
80 #  if defined __x86_64__
81 #    define __NR_memfd_create 319
82 #  elif defined i386
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
90 #    endif
91 #    if _MIPS_SIM == _MIPS_SIM_NABI32
92 #      define __NR_memfd_create 6318
93 #    endif
94 #    if _MIPS_SIM == _MIPS_SIM_ABI64
95 #      define __NR_memfd_create 5314
96 #    endif
97 #  endif
98 #endif
99
100 static inline int
101 glib_linux_memfd_create (const char   *name,
102                          unsigned int  flags)
103 {
104 #ifdef __NR_memfd_create
105   return syscall (__NR_memfd_create, name, flags);
106 #else
107   return glib_linux_enosys ();
108 #endif
109 }
110
111 /* Linux-specific fcntl() operations */
112 #ifndef F_LINUX_SPECIFIC_BASE
113 #define F_LINUX_SPECIFIC_BASE 1024
114 #endif
115
116 #ifndef F_ADD_SEALS
117 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
118 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
119
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 */
124 #endif
125
126 #endif /* __linux __ */
127
128 #endif /* __GLIB_LINUX_H__ */