Subject: port-i386/121: endian.h uses X in byte swap macros
To: None <gnats-admin>
From: None <thomas@mathematik.uni-Bremen.de>
List: netbsd-bugs
Date: 02/11/1994 15:05:02
>Number:         121
>Category:       port-i386
>Synopsis:       endian.h uses X in byte swap macros
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 11 15:05:01 1994
>Originator:     Thomas Eberhardt
>Organization:
CeVis, University of Bremen, Germany
>Release:        
>Environment:
	
Machine: i386
>Description:
	endian.h uses X in his byte swap macros.  This causes problems
	if applications #define X as, for example, 0.
>How-To-Repeat:
	#define X 0
	and use ntohl etc. macros => BOOM
>Fix:

Replace X with __x:

*** sys/arch/i386/include/endian.h-	Mon Dec 20 12:22:08 1993
--- sys/arch/i386/include/endian.h	Fri Feb 11 22:09:24 1994
***************
*** 71,119 ****
  
  #if defined(KERNEL) && ((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU))
  #define __byte_swap_long(x) \
! ({ register unsigned long X = (x); \
     asm ("bswap %1" \
! 	: "=q" (X) \
! 	: "0" (X)); \
!    X; })
  #else
  #define __byte_swap_long(x) \
! ({ register unsigned long X = (x); \
     asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1" \
! 	: "=q" (X) \
! 	: "0" (X)); \
!    X; })
  #endif	/* KERNEL && ... */
  #define __byte_swap_word(x) \
! ({ register unsigned short X = (x); \
     asm ("xchgb %h1, %b1" \
! 	: "=q" (X) \
! 	: "0" (X)); \
!    X; })
  
  #else	/* __GNUC__ >= 2 */
  
  #if defined(KERNEL) && ((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU))
  #define __byte_swap_long(x) \
! ({ register unsigned long X = (x); \
     asm ("bswap %1" \
! 	: "=r" (X) \
! 	: "0" (X)); \
!    X; })
  #else
  #define __byte_swap_long(x) \
! ({ register u_long X = (x); \
     asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \
! 	: "=r" (X) \
! 	: "0" (X)); \
!    X; })
  #endif	/* KERNEL && ... */
  #define __byte_swap_word(x) \
! ({ register u_short X = (x); \
     asm ("rorw $8, %w1" \
! 	: "=r" (X) \
! 	: "0" (X)); \
!    X; })
  
  #endif	/* __GNUC__ >= 2 */
  
--- 71,119 ----
  
  #if defined(KERNEL) && ((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU))
  #define __byte_swap_long(x) \
! ({ register unsigned long __x = (x); \
     asm ("bswap %1" \
! 	: "=q" (__x) \
! 	: "0" (__x)); \
!    __x; })
  #else
  #define __byte_swap_long(x) \
! ({ register unsigned long __x = (x); \
     asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1" \
! 	: "=q" (__x) \
! 	: "0" (__x)); \
!    __x; })
  #endif	/* KERNEL && ... */
  #define __byte_swap_word(x) \
! ({ register unsigned short __x = (x); \
     asm ("xchgb %h1, %b1" \
! 	: "=q" (__x) \
! 	: "0" (__x)); \
!    __x; })
  
  #else	/* __GNUC__ >= 2 */
  
  #if defined(KERNEL) && ((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU))
  #define __byte_swap_long(x) \
! ({ register unsigned long __x = (x); \
     asm ("bswap %1" \
! 	: "=r" (__x) \
! 	: "0" (__x)); \
!    __x; })
  #else
  #define __byte_swap_long(x) \
! ({ register u_long __x = (x); \
     asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \
! 	: "=r" (__x) \
! 	: "0" (__x)); \
!    __x; })
  #endif	/* KERNEL && ... */
  #define __byte_swap_word(x) \
! ({ register u_short __x = (x); \
     asm ("rorw $8, %w1" \
! 	: "=r" (__x) \
! 	: "0" (__x)); \
!    __x; })
  
  #endif	/* __GNUC__ >= 2 */
  
>Audit-Trail:
>Unformatted:

SUP 8.26 (4.3 BSD) for file NetBSD-current/supfile at Feb 11 22:25:24
Last update occurred at Fri Feb 11 11:28:46 1994 for collection current
Last update occurred at Thu Feb 10 12:29:24 1994 for collection current
Last update occurred at Thu Feb 10 12:29:24 1994 for collection current

------------------------------------------------------------------------------