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
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to