Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Mar 2017 16:18:20 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r316031 - head/sys/i386/include
Message-ID:  <201703271618.v2RGIKtl063579@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Mon Mar 27 16:18:19 2017
New Revision: 316031
URL: https://svnweb.freebsd.org/changeset/base/316031

Log:
  Adjust the constraint for "src" in atomic_(f)cmpset_8.
  
  "r" is not sufficient to prevent the use of invalid byte-width registers
  with at least gcc.
  
  Reported and reviewed by:	bde
  X-MFC-With:	r315718

Modified:
  head/sys/i386/include/atomic.h

Modified: head/sys/i386/include/atomic.h
==============================================================================
--- head/sys/i386/include/atomic.h	Mon Mar 27 16:01:44 2017	(r316030)
+++ head/sys/i386/include/atomic.h	Mon Mar 27 16:18:19 2017	(r316031)
@@ -182,7 +182,7 @@ struct __hack
  *
  * Returns 0 on failure, non-zero on success.
  */
-#define	ATOMIC_CMPSET(TYPE)				\
+#define	ATOMIC_CMPSET(TYPE, CONS)			\
 static __inline int					\
 atomic_cmpset_##TYPE(volatile u_##TYPE *dst, u_##TYPE expect, u_##TYPE src) \
 {							\
@@ -196,7 +196,7 @@ atomic_cmpset_##TYPE(volatile u_##TYPE *
 	: "=q" (res),			/* 0 */		\
 	  "+m" (*dst),			/* 1 */		\
 	  "+a" (expect)			/* 2 */		\
-	: "r" (src)			/* 3 */		\
+	: CONS (src)			/* 3 */		\
 	: "memory", "cc");				\
 	return (res);					\
 }							\
@@ -214,14 +214,14 @@ atomic_fcmpset_##TYPE(volatile u_##TYPE 
 	: "=q" (res),			/* 0 */		\
 	  "+m" (*dst),			/* 1 */		\
 	  "+a" (*expect)		/* 2 */		\
-	: "r" (src)			/* 3 */		\
+	: CONS (src)			/* 3 */		\
 	: "memory", "cc");				\
 	return (res);					\
 }
 
-ATOMIC_CMPSET(char);
-ATOMIC_CMPSET(short);
-ATOMIC_CMPSET(int);
+ATOMIC_CMPSET(char, "q");
+ATOMIC_CMPSET(short, "r");
+ATOMIC_CMPSET(int, "r");
 
 /*
  * Atomically add the value of v to the integer pointed to by p and return



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703271618.v2RGIKtl063579>