Subject: Re: Wine & NetBSD?
To: Thomas Klausner <wiz@danbala.ifoer.tuwien.ac.at>
From: Bang Jun-Young <bjy@mogua.org>
List: tech-kern
Date: 11/14/2001 12:35:05
On Sat, Nov 10, 2001 at 07:14:04PM +0900, Bang Jun-Young wrote:
> On Fri, Nov 09, 2001 at 12:11:55PM +0100, Thomas Klausner wrote:
> > Hi!
> > 
> > I think you were working on making Wine run on NetBSD at one time.
> > Is NetBSD-current now in a state where one can use Wine?
> 
> It compiles, but doesn't work. Recently I found the reason that 
> caused it to segfault, so now I'm examining it further. More details
> soon to tech-kern. ;) It's related with the way our poll(2) handles
> POLLNVAL. FreeBSD and Linux seem to never issue such a bit, so
> they don't have problem.

I think I finally have fixed the problem. It's a bug of pollscan()
function:

Index: sys_generic.c
===================================================================
RCS file: /cvsroot/syssrc/sys/kern/sys_generic.c,v
retrieving revision 1.59
diff -u -r1.59 sys_generic.c
--- sys_generic.c	2001/11/12 15:25:23	1.59
+++ sys_generic.c	2001/11/14 03:21:04
@@ -871,9 +871,11 @@
 	fdp = p->p_fd;
 	n = 0;
 	for (i = 0; i < nfd; i++, fds++) {
-		if ((u_int)fds->fd >= fdp->fd_nfiles) {
+		if (fds->fd >= fdp->fd_nfiles) {
 			fds->revents = POLLNVAL;
 			n++;
+		} else if (fds->fd < 0) {
+			fds->revents = 0;
 		} else {
 			if ((fp = fd_getfile(fdp, fds->fd)) == NULL) {
 				fds->revents = POLLNVAL;

struct pollfd->fd is defined as 'int' type in poll.h, but as you
see above, pollscan tries to compare unsigned fd with fdp->fd_nfiles.
This causes a problem if fds->fd is smaller than 0. FreeBSD people
found that earlier, so they have fixed it.

After applying the patch, wine successfully ran some of Win32
binaries, with no more annoying segfault. :)

Would you commit this fix to the mainline, or do we need to review
it further?

Jun-Young

-- 
Bang Jun-Young <bjy@mogua.org>