Deleted Added
full compact
sys_generic.c (160192) sys_generic.c (162711)
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.

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

30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94
35 */
36
37#include <sys/cdefs.h>
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.

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

30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/kern/sys_generic.c 160192 2006-07-08 20:12:14Z jhb $");
38__FBSDID("$FreeBSD: head/sys/kern/sys_generic.c 162711 2006-09-27 19:57:02Z ru $");
39
40#include "opt_compat.h"
41#include "opt_ktrace.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/sysproto.h>
46#include <sys/filedesc.h>

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

519/*
520 * MPSAFE
521 */
522/* ARGSUSED */
523int
524ioctl(struct thread *td, struct ioctl_args *uap)
525{
526 u_long com;
39
40#include "opt_compat.h"
41#include "opt_ktrace.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/sysproto.h>
46#include <sys/filedesc.h>

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

519/*
520 * MPSAFE
521 */
522/* ARGSUSED */
523int
524ioctl(struct thread *td, struct ioctl_args *uap)
525{
526 u_long com;
527 int error;
527 int arg, error;
528 u_int size;
528 u_int size;
529 caddr_t data, memp;
529 caddr_t data;
530
531 if (uap->com > 0xffffffff) {
532 printf(
533 "WARNING pid %d (%s): ioctl sign-extension ioctl %lx\n",
534 td->td_proc->p_pid, td->td_proc->p_comm, uap->com);
535 uap->com &= 0xffffffff;
536 }
537 com = uap->com;

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

543 size = IOCPARM_LEN(com);
544 if ((size > IOCPARM_MAX) ||
545 ((com & (IOC_VOID | IOC_IN | IOC_OUT)) == 0) ||
546#if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
547 ((com & IOC_OUT) && size == 0) ||
548#else
549 ((com & (IOC_IN | IOC_OUT)) && size == 0) ||
550#endif
530
531 if (uap->com > 0xffffffff) {
532 printf(
533 "WARNING pid %d (%s): ioctl sign-extension ioctl %lx\n",
534 td->td_proc->p_pid, td->td_proc->p_comm, uap->com);
535 uap->com &= 0xffffffff;
536 }
537 com = uap->com;

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

543 size = IOCPARM_LEN(com);
544 if ((size > IOCPARM_MAX) ||
545 ((com & (IOC_VOID | IOC_IN | IOC_OUT)) == 0) ||
546#if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
547 ((com & IOC_OUT) && size == 0) ||
548#else
549 ((com & (IOC_IN | IOC_OUT)) && size == 0) ||
550#endif
551 ((com & IOC_VOID) && size > 0))
551 ((com & IOC_VOID) && size > 0 && size != sizeof(int)))
552 return (ENOTTY);
553
554 if (size > 0) {
552 return (ENOTTY);
553
554 if (size > 0) {
555 memp = malloc((u_long)size, M_IOCTLOPS, M_WAITOK);
556 data = memp;
557 } else {
558 memp = NULL;
555 if (!(com & IOC_VOID))
556 data = malloc((u_long)size, M_IOCTLOPS, M_WAITOK);
557 else {
558 /* Integer argument. */
559 arg = (intptr_t)uap->data;
560 data = (void *)&arg;
561 size = 0;
562 }
563 } else
559 data = (void *)&uap->data;
564 data = (void *)&uap->data;
560 }
561 if (com & IOC_IN) {
562 error = copyin(uap->data, data, (u_int)size);
563 if (error) {
565 if (com & IOC_IN) {
566 error = copyin(uap->data, data, (u_int)size);
567 if (error) {
564 free(memp, M_IOCTLOPS);
568 free(data, M_IOCTLOPS);
565 return (error);
566 }
567 } else if (com & IOC_OUT) {
568 /*
569 * Zero the buffer so the user always
570 * gets back something deterministic.
571 */
572 bzero(data, size);
573 }
574
575 error = kern_ioctl(td, uap->fd, com, data);
576
577 if (error == 0 && (com & IOC_OUT))
578 error = copyout(data, uap->data, (u_int)size);
579
569 return (error);
570 }
571 } else if (com & IOC_OUT) {
572 /*
573 * Zero the buffer so the user always
574 * gets back something deterministic.
575 */
576 bzero(data, size);
577 }
578
579 error = kern_ioctl(td, uap->fd, com, data);
580
581 if (error == 0 && (com & IOC_OUT))
582 error = copyout(data, uap->data, (u_int)size);
583
580 if (memp != NULL)
581 free(memp, M_IOCTLOPS);
584 if (size > 0)
585 free(data, M_IOCTLOPS);
582 return (error);
583}
584
585int
586kern_ioctl(struct thread *td, int fd, u_long com, caddr_t data)
587{
588 struct file *fp;
589 struct filedesc *fdp;

--- 588 unchanged lines hidden ---
586 return (error);
587}
588
589int
590kern_ioctl(struct thread *td, int fd, u_long com, caddr_t data)
591{
592 struct file *fp;
593 struct filedesc *fdp;

--- 588 unchanged lines hidden ---