Add new internal header glib-linux.h
authorRyan Lortie <desrt@desrt.ca>
Wed, 3 Dec 2014 22:15:31 +0000 (17:15 -0500)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Fri, 10 Jul 2015 09:47:43 +0000 (11:47 +0200)
This defines some constants and syscall wrappers for features which may
not yet have appeared in the libc.

glib/Makefile.am
glib/glib-linux.h [new file with mode: 0644]

index 2c4b878..6b8e629 100644 (file)
@@ -134,6 +134,7 @@ libglib_2_0_la_SOURCES =    \
        glib_trace.h            \
        glib-init.h             \
        glib-init.c             \
+       glib-linux.h            \
        glib-private.h          \
        glib-private.c          \
        glist.c                 \
diff --git a/glib/glib-linux.h b/glib/glib-linux.h
new file mode 100644 (file)
index 0000000..b9009e5
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright © 2014 Canonical Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the licence, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Ryan Lortie <desrt@desrt.ca>
+ */
+
+#ifndef __GLIB_LINUX_H__
+#define __GLIB_LINUX_H__
+
+/* If we know that we are on Linux, add some features, even if they are
+ * not (yet) advertised in the glibc or kernel headers.
+ *
+ * This allows us to use functionality regardless of if it was available
+ * when GLib was compiled or not.
+ *
+ * We take care not to define these things on non-Linux systems where
+ * certain numeric values could mean something different.
+ *
+ * This file is populated on an as-needed basis.
+ *
+ * As things in this file filter into glibc and the distributions we can
+ * remove them from this file and add unconditional dependencies.  Never
+ * add a configure.ac check in order to remove something from this file.
+ *
+ * import: include this header LAST
+ */
+
+#ifdef __linux__
+
+#define GLIB_LINUX
+
+#include <sys/syscall.h>
+
+/* futex */
+#include <linux/futex.h>
+
+static inline int
+glib_linux_futex (int                   *uaddr,
+                  int                    op,
+                  int                    val,
+                  const struct timespec *timeout,
+                  int                   *uaddr2,
+                  int                    val3)
+{
+  return syscall (__NR_futex, uaddr, op, val, timeout, uaddr2, val3);
+}
+
+/* memfd */
+#ifndef MFD_CLOEXEC
+#define MFD_CLOEXEC             0x0001U
+#endif
+
+#ifndef MFD_ALLOW_SEALING
+#define MFD_ALLOW_SEALING       0x0002U
+#endif
+
+#ifndef __NR_memfd_create
+  #ifdef __x86_64__
+    #define __NR_memfd_create 319
+  #elif defined __arm__
+    #define __NR_memfd_create 385
+  #else
+    #define __NR_memfd_create 356
+  #endif
+#endif
+
+static inline int
+glib_linux_memfd_create (const char   *name,
+                         unsigned int  flags)
+{
+  return syscall (__NR_memfd_create, name, flags);
+}
+
+/* Linux-specific fcntl() operations */
+#ifndef F_LINUX_SPECIFIC_BASE
+#define F_LINUX_SPECIFIC_BASE 1024
+#endif
+
+#ifndef F_ADD_SEALS
+#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
+#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
+
+#define F_SEAL_SEAL     0x0001  /* prevent further seals from being set */
+#define F_SEAL_SHRINK   0x0002  /* prevent file from shrinking */
+#define F_SEAL_GROW     0x0004  /* prevent file from growing */
+#define F_SEAL_WRITE    0x0008  /* prevent writes */
+#endif
+
+#endif /* __linux __ */
+
+#endif /* __GLIB_LINUX_H__ */