Wed Jun 17 20:49:00 2009 UTC ()
Pull up following revision(s) (requested by rmind in ticket #811):
	sys/kern/sys_generic.c: revision 1.122 via patch
Updates to f_flag need to be made with atomics.


(bouyer)
diff -r1.120 -r1.120.6.1 src/sys/kern/sys_generic.c

cvs diff -r1.120 -r1.120.6.1 src/sys/kern/sys_generic.c (expand / switch to unified diff)

--- src/sys/kern/sys_generic.c 2008/07/02 16:45:20 1.120
+++ src/sys/kern/sys_generic.c 2009/06/17 20:49:00 1.120.6.1
@@ -1,17 +1,17 @@ @@ -1,17 +1,17 @@
1/* $NetBSD: sys_generic.c,v 1.120 2008/07/02 16:45:20 matt Exp $ */ 1/* $NetBSD: sys_generic.c,v 1.120.6.1 2009/06/17 20:49:00 bouyer Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
@@ -60,45 +60,46 @@ @@ -60,45 +60,46 @@
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE. 63 * SUCH DAMAGE.
64 * 64 *
65 * @(#)sys_generic.c 8.9 (Berkeley) 2/14/95 65 * @(#)sys_generic.c 8.9 (Berkeley) 2/14/95
66 */ 66 */
67 67
68/* 68/*
69 * System calls relating to files. 69 * System calls relating to files.
70 */ 70 */
71 71
72#include <sys/cdefs.h> 72#include <sys/cdefs.h>
73__KERNEL_RCSID(0, "$NetBSD: sys_generic.c,v 1.120 2008/07/02 16:45:20 matt Exp $"); 73__KERNEL_RCSID(0, "$NetBSD: sys_generic.c,v 1.120.6.1 2009/06/17 20:49:00 bouyer Exp $");
74 74
75#include <sys/param.h> 75#include <sys/param.h>
76#include <sys/systm.h> 76#include <sys/systm.h>
77#include <sys/filedesc.h> 77#include <sys/filedesc.h>
78#include <sys/ioctl.h> 78#include <sys/ioctl.h>
79#include <sys/file.h> 79#include <sys/file.h>
80#include <sys/proc.h> 80#include <sys/proc.h>
81#include <sys/socketvar.h> 81#include <sys/socketvar.h>
82#include <sys/signalvar.h> 82#include <sys/signalvar.h>
83#include <sys/uio.h> 83#include <sys/uio.h>
84#include <sys/kernel.h> 84#include <sys/kernel.h>
85#include <sys/stat.h> 85#include <sys/stat.h>
86#include <sys/kmem.h> 86#include <sys/kmem.h>
87#include <sys/poll.h> 87#include <sys/poll.h>
88#include <sys/vnode.h> 88#include <sys/vnode.h>
89#include <sys/mount.h> 89#include <sys/mount.h>
90#include <sys/syscallargs.h> 90#include <sys/syscallargs.h>
91#include <sys/ktrace.h> 91#include <sys/ktrace.h>
 92#include <sys/atomic.h>
92 93
93#include <uvm/uvm_extern.h> 94#include <uvm/uvm_extern.h>
94 95
95/* 96/*
96 * Read system call. 97 * Read system call.
97 */ 98 */
98/* ARGSUSED */ 99/* ARGSUSED */
99int 100int
100sys_read(struct lwp *l, const struct sys_read_args *uap, register_t *retval) 101sys_read(struct lwp *l, const struct sys_read_args *uap, register_t *retval)
101{ 102{
102 /* { 103 /* {
103 syscallarg(int) fd; 104 syscallarg(int) fd;
104 syscallarg(void *) buf; 105 syscallarg(void *) buf;
@@ -583,42 +584,40 @@ sys_ioctl(struct lwp *l, const struct sy @@ -583,42 +584,40 @@ sys_ioctl(struct lwp *l, const struct sy
583 *(void **)data = SCARG(uap, data); 584 *(void **)data = SCARG(uap, data);
584 } else if ((com&IOC_OUT) && size) 585 } else if ((com&IOC_OUT) && size)
585 /* 586 /*
586 * Zero the buffer so the user always 587 * Zero the buffer so the user always
587 * gets back something deterministic. 588 * gets back something deterministic.
588 */ 589 */
589 memset(data, 0, size); 590 memset(data, 0, size);
590 else if (com&IOC_VOID) 591 else if (com&IOC_VOID)
591 *(void **)data = SCARG(uap, data); 592 *(void **)data = SCARG(uap, data);
592 593
593 switch (com) { 594 switch (com) {
594 595
595 case FIONBIO: 596 case FIONBIO:
596 FILE_LOCK(fp); 597 /* XXX Code block is not atomic */
597 if (*(int *)data != 0) 598 if (*(int *)data != 0)
598 fp->f_flag |= FNONBLOCK; 599 atomic_or_uint(&fp->f_flag, FNONBLOCK);
599 else 600 else
600 fp->f_flag &= ~FNONBLOCK; 601 atomic_and_uint(&fp->f_flag, ~FNONBLOCK);
601 FILE_UNLOCK(fp); 
602 error = (*fp->f_ops->fo_ioctl)(fp, FIONBIO, data); 602 error = (*fp->f_ops->fo_ioctl)(fp, FIONBIO, data);
603 break; 603 break;
604 604
605 case FIOASYNC: 605 case FIOASYNC:
606 FILE_LOCK(fp); 606 /* XXX Code block is not atomic */
607 if (*(int *)data != 0) 607 if (*(int *)data != 0)
608 fp->f_flag |= FASYNC; 608 atomic_or_uint(&fp->f_flag, FASYNC);
609 else 609 else
610 fp->f_flag &= ~FASYNC; 610 atomic_and_uint(&fp->f_flag, ~FASYNC);
611 FILE_UNLOCK(fp); 
612 error = (*fp->f_ops->fo_ioctl)(fp, FIOASYNC, data); 611 error = (*fp->f_ops->fo_ioctl)(fp, FIOASYNC, data);
613 break; 612 break;
614 613
615 default: 614 default:
616 error = (*fp->f_ops->fo_ioctl)(fp, com, data); 615 error = (*fp->f_ops->fo_ioctl)(fp, com, data);
617 /* 616 /*
618 * Copy any data to user, size was 617 * Copy any data to user, size was
619 * already set and checked above. 618 * already set and checked above.
620 */ 619 */
621 if (error == 0 && (com&IOC_OUT) && size) { 620 if (error == 0 && (com&IOC_OUT) && size) {
622 error = copyout(data, SCARG(uap, data), size); 621 error = copyout(data, SCARG(uap, data), size);
623 ktrgenio(SCARG(uap, fd), UIO_READ, SCARG(uap, data), 622 ktrgenio(SCARG(uap, fd), UIO_READ, SCARG(uap, data),
624 size, error); 623 size, error);