Rainer Orth <r...@cebitec.uni-bielefeld.de> writes:

> While debugging why several libgo tests on Solaris 2/SPARC were hanging
> in select (cf. PR go/48242, go/48243), I found that fd_set is
>
> typedef struct fd_set {
>         long    fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)];
> } fd_set;
>
> The current implementation of the FD* funcs in sysfile_posix.go assumes
> 64-bit fds_bits.  While this doesn't make a difference on little-endian
> hosts, on big-endian SPARC the wrong bits are set, leading to the
> observed hang since there is no activity on those random fds.
>
> The following patch fixes this by moving the FD* implementation to two
> new sysfile_fdset{32, 64}.go files to fix this.  There's almost
> certainly a cleaner/shorter implemenation, but this worked for me.
> While the affected tests don't hang anymore now, they still don't finish
> successfully, among others due to PR go/48222.

Thanks.  I'm going to try gambling that every uses the type "long" for
the fds_bits array.  If so, I think this patch will work.  Bootstrapped
and ran Go testsuite on x86_64-unknown-linux-gnu (forcing the use of
select).  Committed to mainline.

Ian

diff -r bc59115c58cf libgo/syscalls/sysfile_posix.go
--- a/libgo/syscalls/sysfile_posix.go	Thu Mar 31 09:48:32 2011 -0700
+++ b/libgo/syscalls/sysfile_posix.go	Thu Mar 31 13:35:30 2011 -0700
@@ -181,20 +181,22 @@
   return;
 }
 
+const nfdbits = unsafe.Sizeof(_C_long) * 8
+
 type FdSet_t struct {
-	Fds_bits [(FD_SETSIZE + 63) / 64]int64;
+	Fds_bits [(FD_SETSIZE + nfdbits - 1) / nfdbits]_C_long
 }
 
 func FDSet(fd int, set *FdSet_t) {
-	set.Fds_bits[fd / 64] |= (1 << (uint)(fd % 64))
+	set.Fds_bits[fd / nfdbits] |= (1 << (uint)(fd % nfdbits))
 }
 
 func FDClr(fd int, set *FdSet_t) {
-	set.Fds_bits[fd / 64] &= ^(1 << (uint)(fd % 64))
+	set.Fds_bits[fd / nfdbits] &^= (1 << (uint)(fd % nfdbits))
 }
 
 func FDIsSet(fd int, set *FdSet_t) bool {
-	if set.Fds_bits[fd / 64] & (1 << (uint)(fd % 64)) != 0 {
+	if set.Fds_bits[fd / nfdbits] & (1 << (uint)(fd % nfdbits)) != 0 {
 		return true
 	} else {
 		return false
@@ -202,7 +204,7 @@
 }
 
 func FDZero(set *FdSet_t) {
-	for i := 0; i < ((FD_SETSIZE + 63) / 64); i++ {
+	for i := range set.Fds_bits {
 		set.Fds_bits[i] = 0
 	}
 }

Reply via email to