Commit feaf7565 authored by Sven Schnelle's avatar Sven Schnelle Committed by Paul E. McKenney
Browse files

nolibc: fix fd_set type



The kernel uses unsigned long for the fd_set bitmap,
but nolibc use u32. This works fine on little endian
machines, but fails on big endian. Convert to unsigned
long to fix this.

Signed-off-by: default avatarSven Schnelle <svens@linux.ibm.com>
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
parent 1b929c02
Loading
Loading
Loading
Loading
+30 −23
Original line number Diff line number Diff line
@@ -89,23 +89,28 @@
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1

#define FD_SETIDXMASK (8 * sizeof(unsigned long))
#define FD_SETBITMASK (8 * sizeof(unsigned long)-1)

/* for select() */
typedef struct {
	uint32_t fd32[(FD_SETSIZE + 31) / 32];
	unsigned long fds[(FD_SETSIZE + FD_SETBITMASK) / FD_SETIDXMASK];
} fd_set;

#define FD_CLR(fd, set) do {						\
		fd_set *__set = (set);					\
		int __fd = (fd);					\
		if (__fd >= 0)						\
			__set->fd32[__fd / 32] &= ~(1U << (__fd & 31)); \
			__set->fds[__fd / FD_SETIDXMASK] &=		\
				~(1U << (__fd & FX_SETBITMASK));	\
	} while (0)

#define FD_SET(fd, set) do {						\
		fd_set *__set = (set);					\
		int __fd = (fd);					\
		if (__fd >= 0)						\
			__set->fd32[__fd / 32] |= 1U << (__fd & 31);    \
			__set->fds[__fd / FD_SETIDXMASK] |=		\
				1 << (__fd & FD_SETBITMASK);		\
	} while (0)

#define FD_ISSET(fd, set) ({						\
@@ -113,15 +118,17 @@ typedef struct {
			int __fd = (fd);				\
		int __r = 0;						\
		if (__fd >= 0)						\
			__r = !!(__set->fd32[__fd / 32] & 1U << (__fd & 31)); \
			__r = !!(__set->fds[__fd / FD_SETIDXMASK] &	\
1U << (__fd & FD_SET_BITMASK));						\
		__r;							\
	})

#define FD_ZERO(set) do {						\
		fd_set *__set = (set);					\
		int __idx;						\
		for (__idx = 0; __idx < (FD_SETSIZE+31) / 32; __idx ++) \
			__set->fd32[__idx] = 0;                         \
		int __size = (FD_SETSIZE+FD_SETBITMASK) / FD_SETIDXMASK;\
		for (__idx = 0; __idx < __size; __idx++)		\
			__set->fds[__idx] = 0;				\
	} while (0)

/* for poll() */