Deleted Added
full compact
sys_generic.c (107839) sys_generic.c (107849)
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94
39 * $FreeBSD: head/sys/kern/sys_generic.c 107839 2002-12-13 22:41:47Z alfred $
39 * $FreeBSD: head/sys/kern/sys_generic.c 107849 2002-12-14 01:56:26Z alfred $
40 */
41
42#include "opt_ktrace.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/sysproto.h>
47#include <sys/filedesc.h>

--- 898 unchanged lines hidden (view full) ---

946{
947 caddr_t bits;
948 char smallbits[32 * sizeof(struct pollfd)];
949 struct timeval atv, rtv, ttv;
950 int error = 0, timo;
951 u_int ncoll, nfds;
952 size_t ni;
953
40 */
41
42#include "opt_ktrace.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/sysproto.h>
47#include <sys/filedesc.h>

--- 898 unchanged lines hidden (view full) ---

946{
947 caddr_t bits;
948 char smallbits[32 * sizeof(struct pollfd)];
949 struct timeval atv, rtv, ttv;
950 int error = 0, timo;
951 u_int ncoll, nfds;
952 size_t ni;
953
954 nfds = SCARG(uap, nfds);
954 nfds = uap->nfds;
955
956 mtx_lock(&Giant);
957 /*
958 * This is kinda bogus. We have fd limits, but that is not
959 * really related to the size of the pollfd array. Make sure
960 * we let the process use at least FD_SETSIZE entries and at
961 * least enough for the current limits. We want to be reasonably
962 * safe, but not overly restrictive.
963 */
964 if ((nfds > td->td_proc->p_rlimit[RLIMIT_NOFILE].rlim_cur) &&
965 (nfds > FD_SETSIZE)) {
966 error = EINVAL;
967 goto done2;
968 }
969 ni = nfds * sizeof(struct pollfd);
970 if (ni > sizeof(smallbits))
971 bits = malloc(ni, M_TEMP, M_WAITOK);
972 else
973 bits = smallbits;
955
956 mtx_lock(&Giant);
957 /*
958 * This is kinda bogus. We have fd limits, but that is not
959 * really related to the size of the pollfd array. Make sure
960 * we let the process use at least FD_SETSIZE entries and at
961 * least enough for the current limits. We want to be reasonably
962 * safe, but not overly restrictive.
963 */
964 if ((nfds > td->td_proc->p_rlimit[RLIMIT_NOFILE].rlim_cur) &&
965 (nfds > FD_SETSIZE)) {
966 error = EINVAL;
967 goto done2;
968 }
969 ni = nfds * sizeof(struct pollfd);
970 if (ni > sizeof(smallbits))
971 bits = malloc(ni, M_TEMP, M_WAITOK);
972 else
973 bits = smallbits;
974 error = copyin(SCARG(uap, fds), bits, ni);
974 error = copyin(uap->fds, bits, ni);
975 if (error)
976 goto done_nosellock;
975 if (error)
976 goto done_nosellock;
977 if (SCARG(uap, timeout) != INFTIM) {
978 atv.tv_sec = SCARG(uap, timeout) / 1000;
979 atv.tv_usec = (SCARG(uap, timeout) % 1000) * 1000;
977 if (uap->timeout != INFTIM) {
978 atv.tv_sec = uap->timeout / 1000;
979 atv.tv_usec = (uap->timeout % 1000) * 1000;
980 if (itimerfix(&atv)) {
981 error = EINVAL;
982 goto done_nosellock;
983 }
984 getmicrouptime(&rtv);
985 timevaladd(&atv, &rtv);
986 } else {
987 atv.tv_sec = 0;

--- 51 unchanged lines hidden (view full) ---

1039
1040done_nosellock:
1041 /* poll is not restarted after signals... */
1042 if (error == ERESTART)
1043 error = EINTR;
1044 if (error == EWOULDBLOCK)
1045 error = 0;
1046 if (error == 0) {
980 if (itimerfix(&atv)) {
981 error = EINVAL;
982 goto done_nosellock;
983 }
984 getmicrouptime(&rtv);
985 timevaladd(&atv, &rtv);
986 } else {
987 atv.tv_sec = 0;

--- 51 unchanged lines hidden (view full) ---

1039
1040done_nosellock:
1041 /* poll is not restarted after signals... */
1042 if (error == ERESTART)
1043 error = EINTR;
1044 if (error == EWOULDBLOCK)
1045 error = 0;
1046 if (error == 0) {
1047 error = copyout(bits, SCARG(uap, fds), ni);
1047 error = copyout(bits, uap->fds, ni);
1048 if (error)
1049 goto out;
1050 }
1051out:
1052 if (ni > sizeof(smallbits))
1053 free(bits, M_TEMP);
1054done2:
1055 mtx_unlock(&Giant);

--- 170 unchanged lines hidden ---
1048 if (error)
1049 goto out;
1050 }
1051out:
1052 if (ni > sizeof(smallbits))
1053 free(bits, M_TEMP);
1054done2:
1055 mtx_unlock(&Giant);

--- 170 unchanged lines hidden ---