From 5fa9680246ae47f5a2cdb62a672fcc3ddc0a629e Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Fri, 21 Aug 2015 16:15:25 +0200 Subject: [PATCH] glib-unix: add new internal header glib-linux.h This defines some constants and syscall wrappers for features which may not yet have appeared in the libc. https://bugzilla.gnome.org/show_bug.cgi?id=721861 Change-Id: I7e83dadf8be9121f91fa0743bb8c1c612f923e13 --- glib/Makefile.am | 1 + glib/glib-linux.h | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 glib/glib-linux.h diff --git a/glib/Makefile.am b/glib/Makefile.am index 9c728f8..b5f6a15 100644 --- a/glib/Makefile.am +++ b/glib/Makefile.am @@ -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 index 0000000..e417584 --- /dev/null +++ b/glib/glib-linux.h @@ -0,0 +1,128 @@ +/* + * 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 . + * + * Author: Ryan Lortie + */ + +#ifndef __GLIB_LINUX_H__ +#define __GLIB_LINUX_H__ + +#include + +/* 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 + +static inline int +glib_linux_enosys (void) +{ + errno = ENOSYS; + return -1; +} + +/* futex */ +#include + +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 +# if defined __x86_64__ +# define __NR_memfd_create 319 +# elif defined i386 +# define __NR_memfd_create 356 +# elif defined __arm__ + /* arm and arm64 have the same value */ +# define __NR_memfd_create 385 +# elif defined _MIPS_SIM +# if _MIPS_SIM == _MIPS_SIM_ABI32 +# define __NR_memfd_create 4354 +# endif +# if _MIPS_SIM == _MIPS_SIM_NABI32 +# define __NR_memfd_create 6318 +# endif +# if _MIPS_SIM == _MIPS_SIM_ABI64 +# define __NR_memfd_create 5314 +# endif +# endif +#endif + +static inline int +glib_linux_memfd_create (const char *name, + unsigned int flags) +{ +#ifdef __NR_memfd_create + return syscall (__NR_memfd_create, name, flags); +#else + return glib_linux_enosys (); +#endif +} + +/* 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__ */ -- 2.7.4