[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

libxshmfence: Changes to 'upstream-unstable'



 autogen.sh            |    4 ++-
 configure.ac          |   22 ++++++++++++++++----
 src/xshmfence_alloc.c |   53 ++++++++++++++++++++++++++++++++++++++++++--------
 src/xshmfence_futex.h |   24 ++++++++++++++++++++++
 4 files changed, 90 insertions(+), 13 deletions(-)

New commits:
commit fe2d6dbba6356ff275649017dd516f0270d79595
Author: Keith Packard <keithp@keithp.com>
Date:   Fri Jan 2 10:44:39 2015 -0800

    Bump version to 1.2
    
    Release with memfd support
    
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/configure.ac b/configure.ac
index 84b49de..0c98875 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,7 +23,7 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ([2.60])
-AC_INIT([libxshmfence], [1.1],
+AC_INIT([libxshmfence], [1.2],
         [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [libxshmfence])
 AC_CONFIG_SRCDIR([Makefile.am])
 AC_CONFIG_HEADERS([config.h])

commit b63ea144a0439c54a3a147274afeeb115caced5a
Author: Keith Packard <keithp@keithp.com>
Date:   Thu Oct 9 14:01:21 2014 +0200

    Use linux 3.17 memfd_create syscall when available
    
    Linux 3.17 introduces a new anonymous memory allocation that returns a
    file descriptor which we can pass around. Use this in preference to
    creating a file in the filesystem where available.
    
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/configure.ac b/configure.ac
index ddf63dc..84b49de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -89,6 +89,12 @@ AC_SUBST([XPROTO_CFLAGS])
 
 CFLAGS="$CFLAGS $XPROTO_CFLAGS"
 
+AC_CHECK_FUNCS(memfd_create)
+
+AC_CHECK_DECLS([__NR_memfd_create], [], [], [[#include <asm/unistd.h>]])
+
+AC_CHECK_HEADERS([sys/memfd.h], [AC_DEFINE([HAVE_MEMFD_H], 1, [Has sys/memfd.h header])])
+
 AC_ARG_ENABLE(visibility,     AC_HELP_STRING([--enable-visibility], [Enable symbol visibility (default: auto)]),
 				[SYMBOL_VISIBILITY=$enableval],
 				[SYMBOL_VISIBILITY=auto])
diff --git a/src/xshmfence_alloc.c b/src/xshmfence_alloc.c
index 58416cd..05cf953 100644
--- a/src/xshmfence_alloc.c
+++ b/src/xshmfence_alloc.c
@@ -26,6 +26,34 @@
 
 #include "xshmfenceint.h"
 
+#if !HAVE_MEMFD_CREATE
+#if HAVE_DECL___NR_MEMFD_CREATE
+#include <asm/unistd.h>
+static int memfd_create(const char *name,
+			    unsigned int flags)
+{
+	return syscall(__NR_memfd_create, name, flags);
+}
+#define HAVE_MEMFD_CREATE	1
+#endif
+#endif
+
+#if HAVE_MEMFD_CREATE
+
+/* Get defines for the memfd_create syscall, using the
+ * header if available, or just defining the constants otherwise
+ */
+
+#if HAVE_MEMFD_H
+#include <sys/memfd.h>
+#else
+/* flags for memfd_create(2) (unsigned int) */
+#define MFD_CLOEXEC		0x0001U
+#define MFD_ALLOW_SEALING	0x0002U
+#endif
+
+#endif
+
 /**
  * xshmfence_alloc_shm:
  *
@@ -41,16 +69,22 @@ xshmfence_alloc_shm(void)
 	char	template[] = SHMDIR "/shmfd-XXXXXX";
 	int	fd;
 
-#ifdef O_TMPFILE
-	fd = open(SHMDIR, O_TMPFILE|O_RDWR|O_CLOEXEC|O_EXCL, 0666);
+#if HAVE_MEMFD_CREATE
+	fd = memfd_create("xshmfence", MFD_CLOEXEC|MFD_ALLOW_SEALING);
 	if (fd < 0)
 #endif
-        {
-            fd = mkstemp(template);
-            if (fd < 0)
-		return fd;
-            unlink(template);
-        }
+	{
+#ifdef O_TMPFILE
+		fd = open(SHMDIR, O_TMPFILE|O_RDWR|O_CLOEXEC|O_EXCL, 0666);
+		if (fd < 0)
+#endif
+		{
+			fd = mkstemp(template);
+			if (fd < 0)
+				return fd;
+			unlink(template);
+		}
+	}
 	if (ftruncate(fd, sizeof (struct xshmfence)) < 0) {
             close(fd);
             return -1;

commit 9c4f070e1304a3503cfab08f68573443025fc4c9
Author: Keith Packard <keithp@keithp.com>
Date:   Tue Jun 17 13:45:24 2014 -0700

    Use /dev/shm as an optional shared memory directory
    
    This is the path coded into glibc, so it should exist and be useful on
    any glibc-based system
    
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/configure.ac b/configure.ac
index 74b70e0..ddf63dc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -130,7 +130,7 @@ AC_ARG_WITH(shared-memory-dir, AS_HELP_STRING([--with-shared-memory-dir=PATH], [
 [],
 [with_shared_memory_dir=yes])
 
-shmdirs="/run/shm /var/tmp /tmp"
+shmdirs="/run/shm /dev/shm /var/tmp /tmp"
 
 case x"$with_shared_memory_dir" in
 xyes)

commit d3efccb33fa599d48004b22f2e07a19da4aaf789
Author: Jung-uk Kim <jkim@FreeBSD.org>
Date:   Mon Dec 9 18:35:45 2013 -0500

    Add support for FreeBSD using umtx (v3).
    
    This fixes a sign-extension bug in the previous versions.
    
    Signed-off-by: Jung-uk Kim <jkim@FreeBSD.org>
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/configure.ac b/configure.ac
index b855029..74b70e0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,7 +53,16 @@ AC_ARG_ENABLE(futex,	AS_HELP_STRING([--enable-futex], [Enable futexes (default:
 		[FUTEX=$enableval], [FUTEX=auto])
 
 if test "x$FUTEX" = "xauto"; then
-	AC_CHECK_HEADER([linux/futex.h], [FUTEX=yes], [FUTEX=no])
+	AC_CHECK_HEADER([linux/futex.h], [FUTEX=yes])
+fi
+
+if test "x$FUTEX" = "xauto"; then
+	AC_CHECK_HEADER([sys/umtx.h], [FUTEX=yes], [FUTEX=no],
+	    [#include <errno.h>
+	     #include <sys/types.h>])
+	if test "x$FUTEX" = "xyes"; then
+		AC_DEFINE(HAVE_UMTX, 1, [Use umtx])
+	fi
 fi
 
 if test "x$FUTEX" = "xyes"; then
diff --git a/src/xshmfence_futex.h b/src/xshmfence_futex.h
index ed60b6d..ea96cf4 100644
--- a/src/xshmfence_futex.h
+++ b/src/xshmfence_futex.h
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2013 Keith Packard
+ * Copyright © 2013 Jung-uk Kim <jkim@FreeBSD.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -24,6 +25,27 @@
 #define _XSHMFENCE_FUTEX_H_
 
 #include <errno.h>
+
+#ifdef HAVE_UMTX
+
+#include <sys/types.h>
+#include <sys/umtx.h>
+
+static inline int sys_futex(void *addr, int op, int32_t val)
+{
+	return _umtx_op(addr, op, (uint32_t)val, NULL, NULL) == -1 ? errno : 0;
+}
+
+static inline int futex_wake(int32_t *addr) {
+	return sys_futex(addr, UMTX_OP_WAKE, INT_MAX);
+}
+
+static inline int futex_wait(int32_t *addr, int32_t value) {
+	return sys_futex(addr, UMTX_OP_WAIT_UINT, value);
+}
+
+#else
+
 #include <stdint.h>
 #include <values.h>
 #include <linux/futex.h>
@@ -43,6 +65,8 @@ static inline int futex_wait(int32_t *addr, int32_t value) {
 	return sys_futex(addr, FUTEX_WAIT, value, NULL, NULL, 0);
 }
 
+#endif
+
 #define barrier() __asm__ __volatile__("": : :"memory")
 
 static inline void atomic_store(int32_t *f, int32_t v)

commit 2b3415a32d44b9b51bf57877bb61d982667c10f0
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date:   Sat May 31 21:39:32 2014 -0700

    autogen.sh: Honor NOCONFIGURE=1
    
    See http://people.gnome.org/~walters/docs/build-api.txt
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>

diff --git a/autogen.sh b/autogen.sh
index 354f254..fc34bd5 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -9,4 +9,6 @@ cd $srcdir
 autoreconf -v --install || exit 1
 cd $ORIGDIR || exit $?
 
-$srcdir/configure "$@"
+if test -z "$NOCONFIGURE"; then
+    $srcdir/configure "$@"
+fi

commit 9089c55ac4433bc79b6f3951c71dda9691ab5c29
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date:   Sat May 31 21:38:41 2014 -0700

    configure: Drop AM_MAINTAINER_MODE
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>

diff --git a/autogen.sh b/autogen.sh
index 904cd67..354f254 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -9,4 +9,4 @@ cd $srcdir
 autoreconf -v --install || exit 1
 cd $ORIGDIR || exit $?
 
-$srcdir/configure --enable-maintainer-mode "$@"
+$srcdir/configure "$@"
diff --git a/configure.ac b/configure.ac
index 8a39f22..b855029 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,7 +30,6 @@ AC_CONFIG_HEADERS([config.h])
 
 # Initialize Automake
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
-AM_MAINTAINER_MODE
 
 # Initialize libtool
 AC_PROG_LIBTOOL

commit ca4ef282b55f3f05acc29a7c76b624f130cc74de
Author: Julien Cristau <jcristau@debian.org>
Date:   Tue Dec 3 20:14:38 2013 +0100

    Check return value from ftruncate
    
    Silences compiler warning:
    
    xshmfence_alloc.c: In function 'xshmfence_alloc_shm':
    xshmfence_alloc.c:54:11: warning: ignoring return value of 'ftruncate', declared with attribute warn_unused_result [-Wunused-result]
      ftruncate(fd, sizeof (struct xshmfence));
               ^
    
    Signed-off-by: Julien Cristau <jcristau@debian.org>
    Reviewed-by: Keith Packard <keithp@keithp.com>

diff --git a/src/xshmfence_alloc.c b/src/xshmfence_alloc.c
index d8d4a40..58416cd 100644
--- a/src/xshmfence_alloc.c
+++ b/src/xshmfence_alloc.c
@@ -51,7 +51,10 @@ xshmfence_alloc_shm(void)
 		return fd;
             unlink(template);
         }
-	ftruncate(fd, sizeof (struct xshmfence));
+	if (ftruncate(fd, sizeof (struct xshmfence)) < 0) {
+            close(fd);
+            return -1;
+        }
         xshmfence_init(fd);
 	return fd;
 }


Reply to: