[05/29] Allow fd_mask type not be an array of long.

Message ID 1414396793-9005-6-git-send-email-apinski@cavium.com
State New, archived
Headers

Commit Message

Andrew Pinski Oct. 27, 2014, 7:59 a.m. UTC
  Even though XPG4.2 requires fd_set member be a long, AARCH64:ILP32
needs it to be the same size as AARCH64:LP64 for big-endian so we
need it to be long long.

* misc/sys/select.h (__FD_MASK_TYPE): Define.
(__FD_MASK_CONST): Define.
(__fd_mask): Change to base on __FD_MASK_TYPE.
(__FD_MASK): Use __FD_MASK_CONST.
---
 misc/sys/select.h |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
  

Comments

Chris Metcalf Oct. 27, 2014, 4:32 p.m. UTC | #1
On 10/27/2014 3:59 AM, Andrew Pinski wrote:
> +/* The fd_set member is required to be an array of longs by XPG4.2.  */

So on aarch64 compat it's now an array of long longs.  Is this a problem?  Would it be better to make it an array of longs but twice as many longs on ILP32 as on LP64?  I suppose this becomes problematic when supporting big-endian, though.  But it would be good to address the XPG4.2 issue somewhere in the headers.
  
Will Newton Nov. 18, 2014, 11:24 a.m. UTC | #2
On 27 October 2014 16:32, Chris Metcalf <cmetcalf@tilera.com> wrote:
> On 10/27/2014 3:59 AM, Andrew Pinski wrote:
>>
>> +/* The fd_set member is required to be an array of longs by XPG4.2.  */
>
>
> So on aarch64 compat it's now an array of long longs.  Is this a problem?
> Would it be better to make it an array of longs but twice as many longs on
> ILP32 as on LP64?  I suppose this becomes problematic when supporting
> big-endian, though.  But it would be good to address the XPG4.2 issue
> somewhere in the headers.

Yes, this seems strange to me. Maybe it might be best handled by a
wrapper in the kernel?
  

Patch

diff --git a/misc/sys/select.h b/misc/sys/select.h
index 941588d..0ca660e 100644
--- a/misc/sys/select.h
+++ b/misc/sys/select.h
@@ -49,16 +49,20 @@  typedef __suseconds_t suseconds_t;
 # define __suseconds_t_defined
 #endif
 
+/* The fd_set member is required to be an array of longs by XPG4.2.  */
+#ifndef __FD_MASK_TYPE
+#define __FD_MASK_TYPE long
+#define __FD_MASK_CONST(a) a##ul
+#endif
 
-/* The fd_set member is required to be an array of longs.  */
-typedef long int __fd_mask;
+typedef __FD_MASK_TYPE __fd_mask;
 
 /* Some versions of <linux/posix_types.h> define this macros.  */
 #undef	__NFDBITS
 /* It's easier to assume 8-bit bytes than to get CHAR_BIT.  */
 #define __NFDBITS	(8 * (int) sizeof (__fd_mask))
 #define	__FD_ELT(d)	((d) / __NFDBITS)
-#define	__FD_MASK(d)	((__fd_mask) (1UL << ((d) % __NFDBITS)))
+#define	__FD_MASK(d)	((__fd_mask) (__FD_MASK_CONST(1) << ((d) % __NFDBITS)))
 
 /* fd_set for select and pselect.  */
 typedef struct