Ejemplo n.º 1
0
static int
so_ioctl (rtems_libio_t *iop, struct socket *so, uint32_t   command, void *buffer)
{
	switch (command) {
	case FIONBIO:
		if (*(int *)buffer) {
			iop->flags |= O_NONBLOCK;
			so->so_state |= SS_NBIO;
		}
		else {
			iop->flags &= ~O_NONBLOCK;
			so->so_state &= ~SS_NBIO;
		}
		return 0;

	case FIONREAD:
		*(int *)buffer = so->so_rcv.sb_cc;
		return 0;
	}

	if (IOCGROUP(command) == 'i')
		return ifioctl (so, command, buffer, NULL);
	if (IOCGROUP(command) == 'r')
		return rtioctl (command, buffer, NULL);
	return (*so->so_proto->pr_usrreqs->pru_control)(so, command, buffer, 0);
}
Ejemplo n.º 2
0
int
soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p)
{
	struct socket *so = (struct socket *)fp->f_data;

	switch (cmd) {

	case FIONBIO:
		if (*(int *)data)
			so->so_state |= SS_NBIO;
		else
			so->so_state &= ~SS_NBIO;
		return (0);

	case FIOASYNC:
		if (*(int *)data) {
			so->so_state |= SS_ASYNC;
			so->so_rcv.sb_flags |= SB_ASYNC;
			so->so_snd.sb_flags |= SB_ASYNC;
		} else {
			so->so_state &= ~SS_ASYNC;
			so->so_rcv.sb_flags &= ~SB_ASYNC;
			so->so_snd.sb_flags &= ~SB_ASYNC;
		}
		return (0);

	case FIONREAD:
		*(int *)data = so->so_rcv.sb_datacc;
		return (0);

	case SIOCSPGRP:
		so->so_pgid = *(int *)data;
		so->so_siguid = p->p_cred->p_ruid;
		so->so_sigeuid = p->p_ucred->cr_uid;
		return (0);

	case SIOCGPGRP:
		*(int *)data = so->so_pgid;
		return (0);

	case SIOCATMARK:
		*(int *)data = (so->so_state&SS_RCVATMARK) != 0;
		return (0);
	}
	/*
	 * Interface/routing/protocol specific ioctls:
	 * interface and routing ioctls should have a
	 * different entry since a socket's unnecessary
	 */
	if (IOCGROUP(cmd) == 'i')
		return (ifioctl(so, cmd, data, p));
	if (IOCGROUP(cmd) == 'r')
		return (rtioctl(cmd, data, p));
	return ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL, 
	    (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)0, p));
}
Ejemplo n.º 3
0
static int bsd_ioctl     (struct CYG_FILE_TAG *fp, CYG_ADDRWORD cmd,
                                CYG_ADDRWORD data)
{
	register struct socket *so = (struct socket *)fp->f_data;
        void *p = 0;

	switch (cmd) {

	case FIONBIO:
		if (*(int *)data)
			so->so_state |= SS_NBIO;
		else
			so->so_state &= ~SS_NBIO;
		return (0);

	case FIOASYNC:
		if (*(int *)data) {
			so->so_state |= SS_ASYNC;
			so->so_rcv.sb_flags |= SB_ASYNC;
			so->so_snd.sb_flags |= SB_ASYNC;
		} else {
			so->so_state &= ~SS_ASYNC;
			so->so_rcv.sb_flags &= ~SB_ASYNC;
			so->so_snd.sb_flags &= ~SB_ASYNC;
		}
		return (0);

	case FIONREAD:
		*(int *)data = so->so_rcv.sb_cc;
		return (0);

	case SIOCATMARK:
		*(int *)data = (so->so_state&SS_RCVATMARK) != 0;
		return (0);
	}
	/*
	 * Interface/routing/protocol specific ioctls:
	 * interface and routing ioctls should have a
	 * different entry since a socket's unnecessary
	 */
	if (IOCGROUP(cmd) == 'i')
		return (ifioctl(so, (u_long)cmd, (caddr_t)data, p));
	if (IOCGROUP(cmd) == 'r')
		return (rtioctl((u_long)cmd, (caddr_t)data, p));
	return ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL, 
	    (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)0));

}
Ejemplo n.º 4
0
static int
netioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
{
	struct ifnet *ifp;
	int error, idx;

	/* only support interface specific ioctls */
	if (IOCGROUP(cmd) != 'i')
		return (EOPNOTSUPP);
	idx = minor(dev);
	if (idx == 0) {
		/*
		 * special network device, not interface.
		 */
		if (cmd == SIOCGIFCONF)
			return (ifconf(cmd, data));	/* XXX remove cmd */
		return (EOPNOTSUPP);
	}

	ifp = ifnet_byindex(idx);
	if (ifp == NULL)
		return (ENXIO);

	error = ifhwioctl(cmd, ifp, data, td);
	if (error == ENOIOCTL)
		error = EOPNOTSUPP;
	return (error);
}
Ejemplo n.º 5
0
int
_oss_ioctl(int fd, unsigned long com, ...)
{
	va_list ap;
	void *argp;

	va_start(ap, com);
	argp = va_arg(ap, void *);
	va_end(ap);
	if (IOCGROUP(com) == 'P')
		return audio_ioctl(fd, com, argp);
	else if (IOCGROUP(com) == 'M')
		return mixer_ioctl(fd, com, argp);
	else
		return ioctl(fd, com, argp);
}
Ejemplo n.º 6
0
int ioctl(int fd, int request, ...) {
    void *data;
    va_list args;

    va_start(args, request);
    data = (request & IOC_INOUT) ? va_arg(args, void *) : NULL;
    va_end(args);

    if(data == NULL && (request & IOC_INOUT) && IOCPARM_LEN(request) != 0) {
        errno = EFAULT;
        return -1;
    }

    fd = request != FIONBIO ? _socketGetFd(fd) : fd;
    if(fd == -1)
        return -1;

    switch(request) {
        case FIONBIO: {
            // See note in fcntl (below)
            int flags = fcntl(fd, F_GETFL, 0);
            if(flags == -1)
                return -1;
            flags = *(int *)data != 0 ? (flags | O_NONBLOCK) : (flags & ~O_NONBLOCK);
            return fcntl(fd, F_SETFL, flags);
        }
        case BIOCSETF:
        case BIOCSETWF:
        case BIOCSETFNR: {
            int ret;
            struct bpf_program *prog = (struct bpf_program *)data;
            if(prog->bf_len > BPF_MAXBUFSIZE) {
                errno = EINVAL;
                return -1;
            }

            struct bpf_program_serialized *prog_ser = (struct bpf_program_serialized *)malloc(sizeof(struct bpf_program_serialized));
            if(prog_ser == NULL) {
                errno = ENOMEM;
                return -1;
            }

            prog_ser->bf_len = prog->bf_len;
            memcpy(prog_ser->bf_insns, prog->bf_insns, prog->bf_len);

            request = _IOC(request & IOC_DIRMASK, IOCGROUP(request), IOCBASECMD(request), sizeof(struct bpf_program_serialized));
            ret = bsdIoctl(fd, request, prog_ser);
            free(prog_ser);
            return _socketParseBsdResult(NULL, ret);
        }
        default:
            return _socketParseBsdResult(NULL, bsdIoctl(fd, request, data));
    }
}
Ejemplo n.º 7
0
int
uts_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *l)
{
    int error = 0;
    struct uts_softc *sc = v;
    struct wsmouse_calibcoords *wsmc = (struct wsmouse_calibcoords *)data;

    DPRINTF(("uts_ioctl(%d, '%c', %d)\n",
             IOCPARM_LEN(cmd), IOCGROUP(cmd), cmd & 0xff));

    switch (cmd) {
    case WSMOUSEIO_SCALIBCOORDS:
        if (!(wsmc->minx >= 0 && wsmc->maxx >= 0 &&
                wsmc->miny >= 0 && wsmc->maxy >= 0 &&
                wsmc->resx >= 0 && wsmc->resy >= 0 &&
                wsmc->minx < 32768 && wsmc->maxx < 32768 &&
                wsmc->miny < 32768 && wsmc->maxy < 32768 &&
                (wsmc->maxx - wsmc->minx) != 0 &&
                (wsmc->maxy - wsmc->miny) != 0 &&
                wsmc->resx < 32768 && wsmc->resy < 32768 &&
                wsmc->swapxy >= 0 && wsmc->swapxy <= 1 &&
                wsmc->samplelen >= 0 && wsmc->samplelen <= 1))
            return (EINVAL);

        sc->sc_tsscale.minx = wsmc->minx;
        sc->sc_tsscale.maxx = wsmc->maxx;
        sc->sc_tsscale.miny = wsmc->miny;
        sc->sc_tsscale.maxy = wsmc->maxy;
        sc->sc_tsscale.swapxy = wsmc->swapxy;
        sc->sc_tsscale.resx = wsmc->resx;
        sc->sc_tsscale.resy = wsmc->resy;
        sc->sc_rawmode = wsmc->samplelen;
        break;
    case WSMOUSEIO_GCALIBCOORDS:
        wsmc->minx = sc->sc_tsscale.minx;
        wsmc->maxx = sc->sc_tsscale.maxx;
        wsmc->miny = sc->sc_tsscale.miny;
        wsmc->maxy = sc->sc_tsscale.maxy;
        wsmc->swapxy = sc->sc_tsscale.swapxy;
        wsmc->resx = sc->sc_tsscale.resx;
        wsmc->resy = sc->sc_tsscale.resy;
        wsmc->samplelen = sc->sc_rawmode;
        break;
    case WSMOUSEIO_GTYPE:
        *(u_int *)data = WSMOUSE_TYPE_TPANEL;
        break;
    default:
        error = ENOTTY;
        break;
    }

    return (error);
}
Ejemplo n.º 8
0
int
main(int ac, char **av)
{
	unsigned long cmd;
	const char *name;
	char *cp;
	int group, i;

	if (ac < 2)
		usage(av);
	printf("  command :  dir  group num  len name\n");
	for (i = 1; i < ac; i++) {
		errno = 0;
		cmd = strtoul(av[i], &cp, 0);
		if (*cp != '\0' || errno != 0) {
			fprintf(stderr, "Invalid integer: %s\n", av[i]);
			usage(av);
		}
		printf("0x%08lx: ", cmd);
		switch (cmd & IOC_DIRMASK) {
		case IOC_VOID:
			printf("VOID ");
			break;
		case IOC_OUT:
			printf("OUT  ");
			break;
		case IOC_IN:
			printf("IN   ");
			break;
		case IOC_INOUT:
			printf("INOUT");
			break;
		default:
			printf("%01lx ???", (cmd & IOC_DIRMASK) >> 29);
			break;
		}
		printf(" ");
		group = IOCGROUP(cmd);
		if (isprint(group))
			printf(" '%c' ", group);
		else
			printf(" 0x%02x", group);
		printf(" %3lu %4lu", cmd & 0xff, IOCPARM_LEN(cmd));
		name = sysdecode_ioctlname(cmd);
		if (name != NULL)
			printf(" %s", name);
		printf("\n");
	}
	return (0);
}
Ejemplo n.º 9
0
static int
consolectl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag,
    struct thread *td)
{

	switch (cmd) {
	case CONS_GETVERS: 
		*(int*)data = 0x200;
		return 0;
	case CONS_MOUSECTL: {
		mouse_info_t *mi = (mouse_info_t*)data;

		sysmouse_process_event(mi);
		return (0);
	}
	default:
		printf("consolectl: unknown ioctl: %c:%lx\n",
		    (char)IOCGROUP(cmd), IOCBASECMD(cmd));
		return (ENOIOCTL);
	}
}
Ejemplo n.º 10
0
static int
soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
    struct thread *td)
{
	struct socket *so = fp->f_data;
	int error = 0;

	switch (cmd) {
	case FIONBIO:
		SOCK_LOCK(so);
		if (*(int *)data)
			so->so_state |= SS_NBIO;
		else
			so->so_state &= ~SS_NBIO;
		SOCK_UNLOCK(so);
		break;

	case FIOASYNC:
		/*
		 * XXXRW: This code separately acquires SOCK_LOCK(so) and
		 * SOCKBUF_LOCK(&so->so_rcv) even though they are the same
		 * mutex to avoid introducing the assumption that they are
		 * the same.
		 */
		if (*(int *)data) {
			SOCK_LOCK(so);
			so->so_state |= SS_ASYNC;
			SOCK_UNLOCK(so);
			SOCKBUF_LOCK(&so->so_rcv);
			so->so_rcv.sb_flags |= SB_ASYNC;
			SOCKBUF_UNLOCK(&so->so_rcv);
			SOCKBUF_LOCK(&so->so_snd);
			so->so_snd.sb_flags |= SB_ASYNC;
			SOCKBUF_UNLOCK(&so->so_snd);
		} else {
			SOCK_LOCK(so);
			so->so_state &= ~SS_ASYNC;
			SOCK_UNLOCK(so);
			SOCKBUF_LOCK(&so->so_rcv);
			so->so_rcv.sb_flags &= ~SB_ASYNC;
			SOCKBUF_UNLOCK(&so->so_rcv);
			SOCKBUF_LOCK(&so->so_snd);
			so->so_snd.sb_flags &= ~SB_ASYNC;
			SOCKBUF_UNLOCK(&so->so_snd);
		}
		break;

	case FIONREAD:
		/* Unlocked read. */
		*(int *)data = sbavail(&so->so_rcv);
		break;

	case FIONWRITE:
		/* Unlocked read. */
		*(int *)data = sbavail(&so->so_snd);
		break;

	case FIONSPACE:
		/* Unlocked read. */
		if ((so->so_snd.sb_hiwat < sbused(&so->so_snd)) ||
		    (so->so_snd.sb_mbmax < so->so_snd.sb_mbcnt))
			*(int *)data = 0;
		else
			*(int *)data = sbspace(&so->so_snd);
		break;

	case FIOSETOWN:
		error = fsetown(*(int *)data, &so->so_sigio);
		break;

	case FIOGETOWN:
		*(int *)data = fgetown(&so->so_sigio);
		break;

	case SIOCSPGRP:
		error = fsetown(-(*(int *)data), &so->so_sigio);
		break;

	case SIOCGPGRP:
		*(int *)data = -fgetown(&so->so_sigio);
		break;

	case SIOCATMARK:
		/* Unlocked read. */
		*(int *)data = (so->so_rcv.sb_state & SBS_RCVATMARK) != 0;
		break;
	default:
		/*
		 * Interface/routing/protocol specific ioctls: interface and
		 * routing ioctls should have a different entry since a
		 * socket is unnecessary.
		 */
		if (IOCGROUP(cmd) == 'i')
			error = ifioctl(so, cmd, data, td);
		else if (IOCGROUP(cmd) == 'r') {
			CURVNET_SET(so->so_vnet);
			error = rtioctl_fib(cmd, data, so->so_fibnum);
			CURVNET_RESTORE();
		} else {
			CURVNET_SET(so->so_vnet);
			error = ((*so->so_proto->pr_usrreqs->pru_control)
			    (so, cmd, data, 0, td));
			CURVNET_RESTORE();
		}
		break;
	}
	return (error);
}
Ejemplo n.º 11
0
/*
 * MPSAFE
 */
int
soo_ioctl(struct file *fp, u_long cmd, caddr_t data,
	  struct ucred *cred, struct sysmsg *msg)
{
	struct socket *so;
	int error;

	so = (struct socket *)fp->f_data;

	switch (cmd) {
	case FIOASYNC:
		if (*(int *)data) {
			sosetstate(so, SS_ASYNC);
			atomic_set_int(&so->so_rcv.ssb_flags,  SSB_ASYNC);
			atomic_set_int(&so->so_snd.ssb_flags, SSB_ASYNC);
		} else {
			soclrstate(so, SS_ASYNC);
			atomic_clear_int(&so->so_rcv.ssb_flags, SSB_ASYNC);
			atomic_clear_int(&so->so_snd.ssb_flags, SSB_ASYNC);
		}
		error = 0;
		break;
	case FIONREAD:
		*(int *)data = so->so_rcv.ssb_cc;
		error = 0;
		break;
	case FIOSETOWN:
		error = fsetown(*(int *)data, &so->so_sigio);
		break;
	case FIOGETOWN:
		*(int *)data = fgetown(&so->so_sigio);
		error = 0;
		break;
	case SIOCSPGRP:
		error = fsetown(-(*(int *)data), &so->so_sigio);
		break;
	case SIOCGPGRP:
		*(int *)data = -fgetown(&so->so_sigio);
		error = 0;
		break;
	case SIOCATMARK:
		*(int *)data = (so->so_state&SS_RCVATMARK) != 0;
		error = 0;
		break;
	default:
		/*
		 * Interface/routing/protocol specific ioctls:
		 * interface and routing ioctls should have a
		 * different entry since a socket's unnecessary
		 */
		if (IOCGROUP(cmd) == 'i') {
			error = ifioctl(so, cmd, data, cred);
		} else if (IOCGROUP(cmd) == 'r') {
			error = rtioctl(cmd, data, cred);
		} else {
			error = so_pru_control_direct(so, cmd, data, NULL);
		}
		break;
	}
	return (error);
}
Ejemplo n.º 12
0
int
soo_ioctl(file_t *fp, u_long cmd, void *data)
{
	struct socket *so = fp->f_data;
	int error = 0;

	switch (cmd) {

	case FIONBIO:
		solock(so);
		if (*(int *)data)
			so->so_state |= SS_NBIO;
		else 
			so->so_state &= ~SS_NBIO; 
		sounlock(so);
		break;

	case FIOASYNC:
		solock(so);
		if (*(int *)data) {
			so->so_state |= SS_ASYNC;
			so->so_rcv.sb_flags |= SB_ASYNC;
			so->so_snd.sb_flags |= SB_ASYNC;
		} else {
			so->so_state &= ~SS_ASYNC;
			so->so_rcv.sb_flags &= ~SB_ASYNC;
			so->so_snd.sb_flags &= ~SB_ASYNC;
		}
		sounlock(so);
		break;

	case FIONREAD:
		*(int *)data = so->so_rcv.sb_cc;
		break;

	case FIONWRITE:
		*(int *)data = so->so_snd.sb_cc;
		break;

	case FIONSPACE:
		/*
		 * See the comment around sbspace()'s definition
		 * in sys/socketvar.h in face of counts about maximum
		 * to understand the following test. We detect overflow
		 * and return zero.
		 */
		solock(so);
		if ((so->so_snd.sb_hiwat < so->so_snd.sb_cc)
		    || (so->so_snd.sb_mbmax < so->so_snd.sb_mbcnt))
			*(int *)data = 0;
		else
			*(int *)data = sbspace(&so->so_snd);
		sounlock(so);
		break;

	case SIOCSPGRP:
	case FIOSETOWN:
	case TIOCSPGRP:
		error = fsetown(&so->so_pgid, cmd, data);
		break;

	case SIOCGPGRP:
	case FIOGETOWN:
	case TIOCGPGRP:
		error = fgetown(so->so_pgid, cmd, data);
		break;

	case SIOCATMARK:
		*(int *)data = (so->so_state&SS_RCVATMARK) != 0;
		break;

	default:
		/*
		 * Interface/routing/protocol specific ioctls:
		 * interface and routing ioctls should have a
		 * different entry since a socket's unnecessary
		 */
		KERNEL_LOCK(1, NULL);
		if (IOCGROUP(cmd) == 'i')
			error = ifioctl(so, cmd, data, curlwp);
		else if (IOCGROUP(cmd) == 'r')
			error = rtioctl(cmd, data, curlwp);
		else {
			error = (*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
			    (struct mbuf *)cmd, (struct mbuf *)data, NULL,
			     curlwp);
		}
		KERNEL_UNLOCK_ONE(NULL);
		break;
	}


	return error;
}
Ejemplo n.º 13
0
int
videoioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
{
    struct video_softc *sc;
    int unit, error;

    unit = VIDEOUNIT(dev);
    if (unit >= video_cd.cd_ndevs ||
            (sc = video_cd.cd_devs[unit]) == NULL || sc->hw_if == NULL)
        return (ENXIO);

    DPRINTF(("video_ioctl(%d, '%c', %d)\n",
             IOCPARM_LEN(cmd), IOCGROUP(cmd), cmd & 0xff));

    error = EOPNOTSUPP;
    switch (cmd) {
    case VIDIOC_QUERYCAP:
        if (sc->hw_if->querycap)
            error = (sc->hw_if->querycap)(sc->hw_hdl,
                                          (struct v4l2_capability *)data);
        break;
    case VIDIOC_ENUM_FMT:
        if (sc->hw_if->enum_fmt)
            error = (sc->hw_if->enum_fmt)(sc->hw_hdl,
                                          (struct v4l2_fmtdesc *)data);
        break;
    case VIDIOC_ENUM_FRAMESIZES:
        if (sc->hw_if->enum_fsizes)
            error = (sc->hw_if->enum_fsizes)(sc->hw_hdl,
                                             (struct v4l2_frmsizeenum *)data);
        break;
    case VIDIOC_ENUM_FRAMEINTERVALS:
        if (sc->hw_if->enum_fivals)
            error = (sc->hw_if->enum_fivals)(sc->hw_hdl,
                                             (struct v4l2_frmivalenum *)data);
        break;
    case VIDIOC_S_FMT:
        if (!(flags & FWRITE))
            return (EACCES);
        if (sc->hw_if->s_fmt)
            error = (sc->hw_if->s_fmt)(sc->hw_hdl,
                                       (struct v4l2_format *)data);
        break;
    case VIDIOC_G_FMT:
        if (sc->hw_if->g_fmt)
            error = (sc->hw_if->g_fmt)(sc->hw_hdl,
                                       (struct v4l2_format *)data);
        break;
    case VIDIOC_S_PARM:
        if (sc->hw_if->s_parm)
            error = (sc->hw_if->s_parm)(sc->hw_hdl,
                                        (struct v4l2_streamparm *)data);
        break;
    case VIDIOC_G_PARM:
        if (sc->hw_if->g_parm)
            error = (sc->hw_if->g_parm)(sc->hw_hdl,
                                        (struct v4l2_streamparm *)data);
        break;
    case VIDIOC_ENUMINPUT:
        if (sc->hw_if->enum_input)
            error = (sc->hw_if->enum_input)(sc->hw_hdl,
                                            (struct v4l2_input *)data);
        break;
    case VIDIOC_S_INPUT:
        if (sc->hw_if->s_input)
            error = (sc->hw_if->s_input)(sc->hw_hdl,
                                         (int)*data);
        break;
    case VIDIOC_REQBUFS:
        if (sc->hw_if->reqbufs)
            error = (sc->hw_if->reqbufs)(sc->hw_hdl,
                                         (struct v4l2_requestbuffers *)data);
        break;
    case VIDIOC_QUERYBUF:
        if (sc->hw_if->querybuf)
            error = (sc->hw_if->querybuf)(sc->hw_hdl,
                                          (struct v4l2_buffer *)data);
        break;
    case VIDIOC_QBUF:
        if (sc->hw_if->qbuf)
            error = (sc->hw_if->qbuf)(sc->hw_hdl,
                                      (struct v4l2_buffer *)data);
        break;
    case VIDIOC_DQBUF:
        if (!sc->hw_if->dqbuf)
            break;
        /* should have called mmap() before now */
        if (sc->sc_vidmode != VIDMODE_MMAP) {
            error = EINVAL;
            break;
        }
        error = (sc->hw_if->dqbuf)(sc->hw_hdl,
                                   (struct v4l2_buffer *)data);
        sc->sc_frames_ready--;
        break;
    case VIDIOC_STREAMON:
        if (sc->hw_if->streamon)
            error = (sc->hw_if->streamon)(sc->hw_hdl,
                                          (int)*data);
        break;
    case VIDIOC_STREAMOFF:
        if (sc->hw_if->streamoff)
            error = (sc->hw_if->streamoff)(sc->hw_hdl,
                                           (int)*data);
        break;
    case VIDIOC_TRY_FMT:
        if (sc->hw_if->try_fmt)
            error = (sc->hw_if->try_fmt)(sc->hw_hdl,
                                         (struct v4l2_format *)data);
        break;
    case VIDIOC_QUERYCTRL:
        if (sc->hw_if->queryctrl)
            error = (sc->hw_if->queryctrl)(sc->hw_hdl,
                                           (struct v4l2_queryctrl *)data);
        break;
    case VIDIOC_G_CTRL:
        if (sc->hw_if->g_ctrl)
            error = (sc->hw_if->g_ctrl)(sc->hw_hdl,
                                        (struct v4l2_control *)data);
        break;
    case VIDIOC_S_CTRL:
        if (sc->hw_if->s_ctrl)
            error = (sc->hw_if->s_ctrl)(sc->hw_hdl,
                                        (struct v4l2_control *)data);
        break;
    default:
        error = (ENOTTY);
    }

    return (error);
}
Ejemplo n.º 14
0
__private_extern__ int
soioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p)
{
	int error = 0;
	int int_arg;

	socket_lock(so, 1);

	/* call the socket filter's ioctl handler anything but ours */
	if (IOCGROUP(cmd) != 'i' && IOCGROUP(cmd) != 'r') {
		switch (cmd) {
		case SIOCGASSOCIDS32:
		case SIOCGASSOCIDS64:
		case SIOCGCONNIDS32:
		case SIOCGCONNIDS64:
		case SIOCGCONNINFO32:
		case SIOCGCONNINFO64:
		case SIOCSCONNORDER:
		case SIOCGCONNORDER:
			/* don't pass to filter */
			break;

		default:
			error = sflt_ioctl(so, cmd, data);
			if (error != 0)
				goto out;
			break;
		}
	}

	switch (cmd) {
	case FIONBIO:			/* int */
		bcopy(data, &int_arg, sizeof (int_arg));
		if (int_arg)
			so->so_state |= SS_NBIO;
		else
			so->so_state &= ~SS_NBIO;

		goto out;

	case FIOASYNC:			/* int */
		bcopy(data, &int_arg, sizeof (int_arg));
		if (int_arg) {
			so->so_state |= SS_ASYNC;
			so->so_rcv.sb_flags |= SB_ASYNC;
			so->so_snd.sb_flags |= SB_ASYNC;
		} else {
			so->so_state &= ~SS_ASYNC;
			so->so_rcv.sb_flags &= ~SB_ASYNC;
			so->so_snd.sb_flags &= ~SB_ASYNC;
		}
		goto out;

	case FIONREAD:			/* int */
		bcopy(&so->so_rcv.sb_cc, data, sizeof (u_int32_t));
		goto out;

	case SIOCSPGRP:			/* int */
		bcopy(data, &so->so_pgid, sizeof (pid_t));
		goto out;

	case SIOCGPGRP:			/* int */
		bcopy(&so->so_pgid, data, sizeof (pid_t));
		goto out;

	case SIOCATMARK:		/* int */
		int_arg = (so->so_state & SS_RCVATMARK) != 0;
		bcopy(&int_arg, data, sizeof (int_arg));
		goto out;

	case SIOCSETOT:			/* int; deprecated */
		error = EOPNOTSUPP;
		goto out;

	case SIOCGASSOCIDS32:		/* so_aidreq32 */
	case SIOCGASSOCIDS64:		/* so_aidreq64 */
	case SIOCGCONNIDS32:		/* so_cidreq32 */
	case SIOCGCONNIDS64:		/* so_cidreq64 */
	case SIOCGCONNINFO32:		/* so_cinforeq32 */
	case SIOCGCONNINFO64:		/* so_cinforeq64 */
	case SIOCSCONNORDER:		/* so_cordreq */
	case SIOCGCONNORDER:		/* so_cordreq */
		error = (*so->so_proto->pr_usrreqs->pru_control)(so,
		    cmd, data, NULL, p);
		goto out;
	}

	/*
	 * Interface/routing/protocol specific ioctls:
	 * interface and routing ioctls should have a
	 * different entry since a socket's unnecessary
	 */
	if (IOCGROUP(cmd) == 'i') {
		error = ifioctllocked(so, cmd, data, p);
	} else {
		if (IOCGROUP(cmd) == 'r')
			error = rtioctl(cmd, data, p);
		else
			error = (*so->so_proto->pr_usrreqs->pru_control)(so,
			    cmd, data, NULL, p);
	}

out:
	socket_unlock(so, 1);

	if (error == EJUSTRETURN)
		error = 0;

	return (error);
}
Ejemplo n.º 15
0
__private_extern__ int
soioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p)
{
    struct sockopt sopt;
    int error = 0;
    int dropsockref = -1;

    socket_lock(so, 1);

    sopt.sopt_level = cmd;
    sopt.sopt_name = (int)data;
    sopt.sopt_p = p;

    /* Call the socket filter's ioctl handler for most ioctls */
    if (IOCGROUP(cmd) != 'i' && IOCGROUP(cmd) != 'r') {
        int filtered = 0;
        struct socket_filter_entry *filter;

        for (filter = so->so_filt; filter && error == 0;
                filter = filter->sfe_next_onsocket) {
            if (filter->sfe_filter->sf_filter.sf_ioctl) {
                if (filtered == 0) {
                    sflt_use(so);
                    socket_unlock(so, 0);
                    filtered = 1;
                }
                error = filter->sfe_filter->sf_filter.
                        sf_ioctl(filter->sfe_cookie, so, cmd, data);
            }
        }

        if (filtered) {
            socket_lock(so, 0);
            sflt_unuse(so);
        }

        if (error != 0)
            goto out;
    }

    switch (cmd) {

    case FIONBIO:
        if (*(int *)data)
            so->so_state |= SS_NBIO;
        else
            so->so_state &= ~SS_NBIO;

        goto out;

    case FIOASYNC:
        if (*(int *)data) {
            so->so_state |= SS_ASYNC;
            so->so_rcv.sb_flags |= SB_ASYNC;
            so->so_snd.sb_flags |= SB_ASYNC;
        } else {
            so->so_state &= ~SS_ASYNC;
            so->so_rcv.sb_flags &= ~SB_ASYNC;
            so->so_snd.sb_flags &= ~SB_ASYNC;
        }
        goto out;

    case FIONREAD:
        *(int *)data = so->so_rcv.sb_cc;
        goto out;

    case SIOCSPGRP:
        so->so_pgid = *(int *)data;
        goto out;

    case SIOCGPGRP:
        *(int *)data = so->so_pgid;
        goto out;

    case SIOCATMARK:
        *(int *)data = (so->so_state&SS_RCVATMARK) != 0;
        goto out;

    case SIOCSETOT: {
        /*
         * Set socket level options here and then call protocol
         * specific routine.
         */
        struct socket *cloned_so = NULL;
        int cloned_fd = *(int *)data;

        /* let's make sure it's either -1 or a valid file descriptor */
        if (cloned_fd != -1) {
            error = file_socket(cloned_fd, &cloned_so);
            if (error) {
                goto out;
            }
            dropsockref = cloned_fd;
        }

        /* Always set socket non-blocking for OT */
        so->so_state |= SS_NBIO;
        so->so_options |= SO_DONTTRUNC | SO_WANTMORE;
        so->so_flags |= SOF_NOSIGPIPE;

        if (cloned_so && so != cloned_so) {
            /* Flags options */
            so->so_options |=
                cloned_so->so_options & ~SO_ACCEPTCONN;

            /* SO_LINGER */
            if (so->so_options & SO_LINGER)
                so->so_linger = cloned_so->so_linger;

            /* SO_SNDBUF, SO_RCVBUF */
            if (cloned_so->so_snd.sb_hiwat > 0) {
                if (sbreserve(&so->so_snd,
                              cloned_so->so_snd.sb_hiwat) == 0) {
                    error = ENOBUFS;
                    goto out;
                }
            }
            if (cloned_so->so_rcv.sb_hiwat > 0) {
                if (sbreserve(&so->so_rcv,
                              cloned_so->so_rcv.sb_hiwat) == 0) {
                    error = ENOBUFS;
                    goto out;
                }
            }

            /* SO_SNDLOWAT, SO_RCVLOWAT */
            so->so_snd.sb_lowat =
                (cloned_so->so_snd.sb_lowat > so->so_snd.sb_hiwat) ?
                so->so_snd.sb_hiwat : cloned_so->so_snd.sb_lowat;
            so->so_rcv.sb_lowat =
                (cloned_so->so_rcv.sb_lowat > so->so_rcv.sb_hiwat) ?
                so->so_rcv.sb_hiwat : cloned_so->so_rcv.sb_lowat;

            /* SO_SNDTIMEO, SO_RCVTIMEO */
            so->so_snd.sb_timeo = cloned_so->so_snd.sb_timeo;
            so->so_rcv.sb_timeo = cloned_so->so_rcv.sb_timeo;
        }

        error = (*so->so_proto->pr_usrreqs->pru_control)(so, cmd,
                data, 0, p);
        /* Just ignore protocols that do not understand it */
        if (error == EOPNOTSUPP)
            error = 0;

        goto out;
    }
    }
    /*
     * Interface/routing/protocol specific ioctls:
     * interface and routing ioctls should have a
     * different entry since a socket's unnecessary
     */
    if (IOCGROUP(cmd) == 'i') {
        error = ifioctllocked(so, cmd, data, p);
    } else {
        if (IOCGROUP(cmd) == 'r')
            error = rtioctl(cmd, data, p);
        else
            error = (*so->so_proto->pr_usrreqs->pru_control)(so,
                    cmd, data, 0, p);
    }

out:
    if (dropsockref != -1)
        file_drop(dropsockref);
    socket_unlock(so, 1);

    if (error == EJUSTRETURN)
        error = 0;

    return (error);
}
Ejemplo n.º 16
0
static int
vesa_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
{
	scr_stat *scp;
	int mode;

	scp = SC_STAT(tp);

	switch (cmd) {

	/* generic text modes */
	case SW_TEXT_132x25: case SW_TEXT_132x30:
	case SW_TEXT_132x43: case SW_TEXT_132x50:
	case SW_TEXT_132x60:
		if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
			return ENODEV;
		return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0, 0);

	/* text modes */
	case SW_VESA_C80x60:
	case SW_VESA_C132x25:
	case SW_VESA_C132x43:
	case SW_VESA_C132x50:
	case SW_VESA_C132x60:
		if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
			return ENODEV;
		mode = (cmd & 0xff) + M_VESA_BASE;
		return sc_set_text_mode(scp, tp, mode, 0, 0, 0, 0);

	/* graphics modes */
	case SW_VESA_32K_320: 	case SW_VESA_64K_320: 
	case SW_VESA_FULL_320:

	case SW_VESA_CG640x400:

	case SW_VESA_CG640x480:
	case SW_VESA_32K_640:	case SW_VESA_64K_640:
	case SW_VESA_FULL_640:

	case SW_VESA_800x600:	case SW_VESA_CG800x600:
	case SW_VESA_32K_800:	case SW_VESA_64K_800:
	case SW_VESA_FULL_800:

	case SW_VESA_1024x768:	case SW_VESA_CG1024x768:
	case SW_VESA_32K_1024:	case SW_VESA_64K_1024:
	case SW_VESA_FULL_1024:

	case SW_VESA_1280x1024:	case SW_VESA_CG1280x1024:
	case SW_VESA_32K_1280:	case SW_VESA_64K_1280:
	case SW_VESA_FULL_1280:
		if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
			return ENODEV;
		mode = (cmd & 0xff) + M_VESA_BASE;
		return sc_set_graphics_mode(scp, tp, mode);
	default:
		if (IOCGROUP(cmd) == 'V') {
			if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
				return ENODEV;

			mode = (cmd & 0xff) + M_VESA_BASE;

			if (((cmd & IOC_DIRMASK) == IOC_VOID) &&
			    (mode > M_VESA_FULL_1280) &&
			    (mode < M_VESA_MODE_MAX))
				return sc_set_graphics_mode(scp, tp, mode);
		}
	}

	if (prev_user_ioctl)
		return (*prev_user_ioctl)(tp, cmd, data, td);
	else
		return ENOIOCTL;
}
Ejemplo n.º 17
0
char *
print_arg(struct syscall_args *sc, unsigned long *args, long retval,
    struct trussinfo *trussinfo)
{
	char *tmp;
	pid_t pid;

	tmp = NULL;
	pid = trussinfo->pid;
	switch (sc->type & ARG_MASK) {
	case Hex:
		asprintf(&tmp, "0x%x", (int)args[sc->offset]);
		break;
	case Octal:
		asprintf(&tmp, "0%o", (int)args[sc->offset]);
		break;
	case Int:
		asprintf(&tmp, "%d", (int)args[sc->offset]);
		break;
	case Name: {
		/* NULL-terminated string. */
		char *tmp2;
		tmp2 = get_string(pid, (void*)args[sc->offset], 0);
		asprintf(&tmp, "\"%s\"", tmp2);
		free(tmp2);
		break;
	}
	case BinString: {
		/* Binary block of data that might have printable characters.
		   XXX If type|OUT, assume that the length is the syscall's
		   return value.  Otherwise, assume that the length of the block
		   is in the next syscall argument. */
		int max_string = trussinfo->strsize;
		char tmp2[max_string+1], *tmp3;
		int len;
		int truncated = 0;

		if (sc->type & OUT)
			len = retval;
		else
			len = args[sc->offset + 1];

		/* Don't print more than max_string characters, to avoid word
		   wrap.  If we have to truncate put some ... after the string.
		*/
		if (len > max_string) {
			len = max_string;
			truncated = 1;
		}
		if (len && get_struct(pid, (void*)args[sc->offset], &tmp2, len)
		    != -1) {
			tmp3 = malloc(len * 4 + 1);
			while (len) {
				if (strvisx(tmp3, tmp2, len,
				    VIS_CSTYLE|VIS_TAB|VIS_NL) <= max_string)
					break;
				len--;
				truncated = 1;
			};
			asprintf(&tmp, "\"%s\"%s", tmp3, truncated ?
			    "..." : "");
			free(tmp3);
		} else {
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		}
		break;
	}
	case StringArray: {
		int num, size, i;
		char *tmp2;
		char *string;
		char *strarray[100];	/* XXX This is ugly. */

		if (get_struct(pid, (void *)args[sc->offset],
		    (void *)&strarray, sizeof(strarray)) == -1)
			err(1, "get_struct %p", (void *)args[sc->offset]);
		num = 0;
		size = 0;

		/* Find out how large of a buffer we'll need. */
		while (strarray[num] != NULL) {
			string = get_string(pid, (void*)strarray[num], 0);
			size += strlen(string);
			free(string);
			num++;
		}
		size += 4 + (num * 4);
		tmp = (char *)malloc(size);
		tmp2 = tmp;

		tmp2 += sprintf(tmp2, " [");
		for (i = 0; i < num; i++) {
			string = get_string(pid, (void*)strarray[i], 0);
			tmp2 += sprintf(tmp2, " \"%s\"%c", string,
			    (i + 1 == num) ? ' ' : ',');
			free(string);
		}
		tmp2 += sprintf(tmp2, "]");
		break;
	}
#ifdef __LP64__
	case Quad:
		asprintf(&tmp, "0x%lx", args[sc->offset]);
		break;
#else
	case Quad: {
		unsigned long long ll;
		ll = *(unsigned long long *)(args + sc->offset);
		asprintf(&tmp, "0x%llx", ll);
		break;
	}
#endif
	case Ptr:
		asprintf(&tmp, "0x%lx", args[sc->offset]);
		break;
	case Readlinkres: {
		char *tmp2;
		if (retval == -1) {
			tmp = strdup("");
			break;
		}
		tmp2 = get_string(pid, (void*)args[sc->offset], retval);
		asprintf(&tmp, "\"%s\"", tmp2);
		free(tmp2);
		break;
	}
	case Ioctl: {
		const char *temp = ioctlname(args[sc->offset]);
		if (temp)
			tmp = strdup(temp);
		else {
			unsigned long arg = args[sc->offset];
			asprintf(&tmp, "0x%lx { IO%s%s 0x%lx('%c'), %lu, %lu }",
			    arg, arg & IOC_OUT ? "R" : "",
			    arg & IOC_IN ? "W" : "", IOCGROUP(arg),
			    isprint(IOCGROUP(arg)) ? (char)IOCGROUP(arg) : '?',
			    arg & 0xFF, IOCPARM_LEN(arg));
		}
		break;
	}
	case Umtx: {
		struct umtx umtx;
		if (get_struct(pid, (void *)args[sc->offset], &umtx,
		    sizeof(umtx)) != -1)
			asprintf(&tmp, "{ 0x%lx }", (long)umtx.u_owner);
		else
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		break;
	}
	case Timespec: {
		struct timespec ts;
		if (get_struct(pid, (void *)args[sc->offset], &ts,
		    sizeof(ts)) != -1)
			asprintf(&tmp, "{%ld.%09ld }", (long)ts.tv_sec,
			    ts.tv_nsec);
		else
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		break;
	}
	case Timeval: {
		struct timeval tv;
		if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv))
		    != -1)
			asprintf(&tmp, "{%ld.%06ld }", (long)tv.tv_sec,
			    tv.tv_usec);
		else
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		break;
	}
	case Timeval2: {
		struct timeval tv[2];
		if (get_struct(pid, (void *)args[sc->offset], &tv, sizeof(tv))
		    != -1)
			asprintf(&tmp, "{%ld.%06ld, %ld.%06ld }",
			    (long)tv[0].tv_sec, tv[0].tv_usec,
			    (long)tv[1].tv_sec, tv[1].tv_usec);
		else
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		break;
	}
	case Itimerval: {
		struct itimerval itv;
		if (get_struct(pid, (void *)args[sc->offset], &itv,
		    sizeof(itv)) != -1)
			asprintf(&tmp, "{%ld.%06ld, %ld.%06ld }",
			    (long)itv.it_interval.tv_sec,
			    itv.it_interval.tv_usec,
			    (long)itv.it_value.tv_sec,
			    itv.it_value.tv_usec);
		else
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		break;
	}
	case LinuxSockArgs:
	{
		struct linux_socketcall_args largs;
		if (get_struct(pid, (void *)args[sc->offset], (void *)&largs,
		    sizeof(largs)) == -1) {
			err(1, "get_struct %p", (void *)args[sc->offset]);
		}
		const char *what;
		char buf[30];

		switch (largs.what) {
		case LINUX_SOCKET:
			what = "LINUX_SOCKET";
			break;
		case LINUX_BIND:
			what = "LINUX_BIND";
			break;
		case LINUX_CONNECT:
			what = "LINUX_CONNECT";
			break;
		case LINUX_LISTEN:
			what = "LINUX_LISTEN";
			break;
		case LINUX_ACCEPT:
			what = "LINUX_ACCEPT";
			break;
		case LINUX_GETSOCKNAME:
			what = "LINUX_GETSOCKNAME";
			break;
		case LINUX_GETPEERNAME:
			what = "LINUX_GETPEERNAME";
			break;
		case LINUX_SOCKETPAIR:
			what = "LINUX_SOCKETPAIR";
			break;
		case LINUX_SEND:   
			what = "LINUX_SEND";
			break;
		case LINUX_RECV: 
			what = "LINUX_RECV";
			break;
		case LINUX_SENDTO:
			what = "LINUX_SENDTO";
			break;
		case LINUX_RECVFROM:
			what = "LINUX_RECVFROM";
			break;
		case LINUX_SHUTDOWN:
			what = "LINUX_SHUTDOWN";
			break;
		case LINUX_SETSOCKOPT:
			what = "LINUX_SETSOCKOPT";
			break;
		case LINUX_GETSOCKOPT:
			what = "LINUX_GETSOCKOPT";
			break;
		case LINUX_SENDMSG:
			what = "LINUX_SENDMSG";
			break;
		case LINUX_RECVMSG:
			what = "LINUX_RECVMSG";
			break;
		default:
			sprintf(buf, "%d", largs.what);
			what = buf;
			break;
		}
		asprintf(&tmp, "(0x%lx)%s, 0x%lx", args[sc->offset], what, (long unsigned int)largs.args);
		break;
	}
	case Pollfd: {
		/*
		 * XXX: A Pollfd argument expects the /next/ syscall argument
		 * to be the number of fds in the array. This matches the poll
		 * syscall.
		 */
		struct pollfd *pfd;
		int numfds = args[sc->offset+1];
		int bytes = sizeof(struct pollfd) * numfds;
		int i, tmpsize, u, used;
		const int per_fd = 100;

		if ((pfd = malloc(bytes)) == NULL)
			err(1, "Cannot malloc %d bytes for pollfd array",
			    bytes);
		if (get_struct(pid, (void *)args[sc->offset], pfd, bytes)
		    != -1) {
			used = 0;
			tmpsize = 1 + per_fd * numfds + 2;
			if ((tmp = malloc(tmpsize)) == NULL)
				err(1, "Cannot alloc %d bytes for poll output",
				    tmpsize);

			tmp[used++] = '{';
			for (i = 0; i < numfds; i++) {

				u = snprintf(tmp + used, per_fd, "%s%d/%s",
				    i > 0 ? " " : "", pfd[i].fd,
				    xlookup_bits(poll_flags, pfd[i].events));
				if (u > 0)
					used += u < per_fd ? u : per_fd;
			}
			tmp[used++] = '}';
			tmp[used++] = '\0';
		} else {
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		}
		free(pfd);
		break;
	}
	case Fd_set: {
		/*
		 * XXX: A Fd_set argument expects the /first/ syscall argument
		 * to be the number of fds in the array.  This matches the
		 * select syscall.
		 */
		fd_set *fds;
		int numfds = args[0];
		int bytes = _howmany(numfds, _NFDBITS) * _NFDBITS;
		int i, tmpsize, u, used;
		const int per_fd = 20;

		if ((fds = malloc(bytes)) == NULL)
			err(1, "Cannot malloc %d bytes for fd_set array",
			    bytes);
		if (get_struct(pid, (void *)args[sc->offset], fds, bytes)
		    != -1) {
			used = 0;
			tmpsize = 1 + numfds * per_fd + 2;
			if ((tmp = malloc(tmpsize)) == NULL)
				err(1, "Cannot alloc %d bytes for fd_set "
				    "output", tmpsize);

			tmp[used++] = '{';
			for (i = 0; i < numfds; i++) {
				if (FD_ISSET(i, fds)) {
					u = snprintf(tmp + used, per_fd, "%d ",
					    i);
					if (u > 0)
						used += u < per_fd ? u : per_fd;
				}
			}
			if (tmp[used-1] == ' ')
				used--;
			tmp[used++] = '}';
			tmp[used++] = '\0';
		} else
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		free(fds);
		break;
	}
	case Signal:
		tmp = strsig2(args[sc->offset]);
		break;
	case Sigset: {
		long sig;
		sigset_t ss;
		int i, used;
		char *signame;

		sig = args[sc->offset];
		if (get_struct(pid, (void *)args[sc->offset], (void *)&ss,
		    sizeof(ss)) == -1) {
			asprintf(&tmp, "0x%lx", args[sc->offset]);
			break;
		}
		tmp = malloc(sys_nsig * 8); /* 7 bytes avg per signal name */
		used = 0;
		for (i = 1; i < sys_nsig; i++) {
			if (sigismember(&ss, i)) {
				signame = strsig(i);
				used += sprintf(tmp + used, "%s|", signame);
				free(signame);
			}
		}
		if (used)
			tmp[used-1] = 0;
		else
			strcpy(tmp, "0x0");
		break;
	}
	case Sigprocmask: {
		switch (args[sc->offset]) {
#define	S(a)	case a: tmp = strdup(#a); break;
			S(SIG_BLOCK);
			S(SIG_UNBLOCK);
			S(SIG_SETMASK);
#undef S
		}
		if (tmp == NULL)
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		break;
	}
	case Fcntlflag: {
		/* XXX output depends on the value of the previous argument */
		switch (args[sc->offset-1]) {
		case F_SETFD:
			tmp = strdup(xlookup_bits(fcntlfd_arg,
			    args[sc->offset]));
			break;
		case F_SETFL:
			tmp = strdup(xlookup_bits(fcntlfl_arg,
			    args[sc->offset]));
			break;
		case F_GETFD:
		case F_GETFL:
		case F_GETOWN:
			tmp = strdup("");
			break;
		default:
			asprintf(&tmp, "0x%lx", args[sc->offset]);
			break;
		}
		break;
	}
	case Open:
		tmp = strdup(xlookup_bits(open_flags, args[sc->offset]));
		break;
	case Fcntl:
		tmp = strdup(xlookup(fcntl_arg, args[sc->offset]));
		break;
	case Mprot:
		tmp = strdup(xlookup_bits(mprot_flags, args[sc->offset]));
		break;
	case Mmapflags: {
		char *base, *alignstr;
		int align, flags;

		/*
		 * MAP_ALIGNED can't be handled by xlookup_bits(), so
		 * generate that string manually and prepend it to the
		 * string from xlookup_bits().  Have to be careful to
		 * avoid outputting MAP_ALIGNED|0 if MAP_ALIGNED is
		 * the only flag.
		 */
		flags = args[sc->offset] & ~MAP_ALIGNMENT_MASK;
		align = args[sc->offset] & MAP_ALIGNMENT_MASK;
		if (align != 0) {
			if (align == MAP_ALIGNED_SUPER)
				alignstr = strdup("MAP_ALIGNED_SUPER");
			else
				asprintf(&alignstr, "MAP_ALIGNED(%d)",
				    align >> MAP_ALIGNMENT_SHIFT);
			if (flags == 0) {
				tmp = alignstr;
				break;
			}
		} else
			alignstr = NULL;
		base = strdup(xlookup_bits(mmap_flags, flags));
		if (alignstr == NULL) {
			tmp = base;
			break;
		}
		asprintf(&tmp, "%s|%s", alignstr, base);
		free(alignstr);
		free(base);
		break;
	}
	case Whence:
		tmp = strdup(xlookup(whence_arg, args[sc->offset]));
		break;
	case Sockdomain:
		tmp = strdup(xlookup(sockdomain_arg, args[sc->offset]));
		break;
	case Socktype:
		tmp = strdup(xlookup(socktype_arg, args[sc->offset]));
		break;
	case Shutdown:
		tmp = strdup(xlookup(shutdown_arg, args[sc->offset]));
		break;
	case Resource:
		tmp = strdup(xlookup(resource_arg, args[sc->offset]));
		break;
	case Pathconf:
		tmp = strdup(xlookup(pathconf_arg, args[sc->offset]));
		break;
	case Rforkflags:
		tmp = strdup(xlookup_bits(rfork_flags, args[sc->offset]));
		break;
	case Sockaddr: {
		struct sockaddr_storage ss;
		char addr[64];
		struct sockaddr_in *lsin;
		struct sockaddr_in6 *lsin6;
		struct sockaddr_un *sun;
		struct sockaddr *sa;
		char *p;
		u_char *q;
		int i;

		if (args[sc->offset] == 0) {
			asprintf(&tmp, "NULL");
			break;
		}

		/* yuck: get ss_len */
		if (get_struct(pid, (void *)args[sc->offset], (void *)&ss,
		    sizeof(ss.ss_len) + sizeof(ss.ss_family)) == -1)
			err(1, "get_struct %p", (void *)args[sc->offset]);
		/*
		 * If ss_len is 0, then try to guess from the sockaddr type.
		 * AF_UNIX may be initialized incorrectly, so always frob
		 * it by using the "right" size.
		 */
		if (ss.ss_len == 0 || ss.ss_family == AF_UNIX) {
			switch (ss.ss_family) {
			case AF_INET:
				ss.ss_len = sizeof(*lsin);
				break;
			case AF_UNIX:
				ss.ss_len = sizeof(*sun);
				break;
			default:
				/* hurrrr */
				break;
			}
		}
		if (get_struct(pid, (void *)args[sc->offset], (void *)&ss,
		    ss.ss_len) == -1) {
			err(2, "get_struct %p", (void *)args[sc->offset]);
		}

		switch (ss.ss_family) {
		case AF_INET:
			lsin = (struct sockaddr_in *)&ss;
			inet_ntop(AF_INET, &lsin->sin_addr, addr, sizeof addr);
			asprintf(&tmp, "{ AF_INET %s:%d }", addr,
			    htons(lsin->sin_port));
			break;
		case AF_INET6:
			lsin6 = (struct sockaddr_in6 *)&ss;
			inet_ntop(AF_INET6, &lsin6->sin6_addr, addr,
			    sizeof addr);
			asprintf(&tmp, "{ AF_INET6 [%s]:%d }", addr,
			    htons(lsin6->sin6_port));
			break;
		case AF_UNIX:
			sun = (struct sockaddr_un *)&ss;
			asprintf(&tmp, "{ AF_UNIX \"%s\" }", sun->sun_path);
			break;
		default:
			sa = (struct sockaddr *)&ss;
			asprintf(&tmp, "{ sa_len = %d, sa_family = %d, sa_data "
			    "= {%n%*s } }", (int)sa->sa_len, (int)sa->sa_family,
			    &i, 6 * (int)(sa->sa_len - ((char *)&sa->sa_data -
			    (char *)sa)), "");
			if (tmp != NULL) {
				p = tmp + i;
				for (q = (u_char *)&sa->sa_data;
				    q < (u_char *)sa + sa->sa_len; q++)
					p += sprintf(p, " %#02x,", *q);
			}
		}
		break;
	}
	case Sigaction: {
		struct sigaction sa;
		char *hand;
		const char *h;

		if (get_struct(pid, (void *)args[sc->offset], &sa, sizeof(sa))
		    != -1) {
			asprintf(&hand, "%p", sa.sa_handler);
			if (sa.sa_handler == SIG_DFL)
				h = "SIG_DFL";
			else if (sa.sa_handler == SIG_IGN)
				h = "SIG_IGN";
			else
				h = hand;

			asprintf(&tmp, "{ %s %s ss_t }", h,
			    xlookup_bits(sigaction_flags, sa.sa_flags));
			free(hand);
		} else
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		break;
	}
	case Kevent: {
		/*
		 * XXX XXX: the size of the array is determined by either the
		 * next syscall argument, or by the syscall returnvalue,
		 * depending on which argument number we are.  This matches the
		 * kevent syscall, but luckily that's the only syscall that uses
		 * them.
		 */
		struct kevent *ke;
		int numevents = -1;
		int bytes = 0;
		int i, tmpsize, u, used;
		const int per_ke = 100;

		if (sc->offset == 1)
			numevents = args[sc->offset+1];
		else if (sc->offset == 3 && retval != -1)
			numevents = retval;

		if (numevents >= 0)
			bytes = sizeof(struct kevent) * numevents;
		if ((ke = malloc(bytes)) == NULL)
			err(1, "Cannot malloc %d bytes for kevent array",
			    bytes);
		if (numevents >= 0 && get_struct(pid, (void *)args[sc->offset],
		    ke, bytes) != -1) {
			used = 0;
			tmpsize = 1 + per_ke * numevents + 2;
			if ((tmp = malloc(tmpsize)) == NULL)
				err(1, "Cannot alloc %d bytes for kevent "
				    "output", tmpsize);

			tmp[used++] = '{';
			for (i = 0; i < numevents; i++) {
				u = snprintf(tmp + used, per_ke,
				    "%s%p,%s,%s,%d,%p,%p",
				    i > 0 ? " " : "",
				    (void *)ke[i].ident,
				    xlookup(kevent_filters, ke[i].filter),
				    xlookup_bits(kevent_flags, ke[i].flags),
				    ke[i].fflags,
				    (void *)ke[i].data,
				    (void *)ke[i].udata);
				if (u > 0)
					used += u < per_ke ? u : per_ke;
			}
			tmp[used++] = '}';
			tmp[used++] = '\0';
		} else {
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		}
		free(ke);
		break;
	}
	case Stat: {
		struct stat st;
		if (get_struct(pid, (void *)args[sc->offset], &st, sizeof(st))
		    != -1) {
			char mode[12];
			strmode(st.st_mode, mode);
			asprintf(&tmp,
			    "{ mode=%s,inode=%jd,size=%jd,blksize=%ld }", mode,
			    (intmax_t)st.st_ino, (intmax_t)st.st_size,
			    (long)st.st_blksize);
		} else {
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		}
		break;
	}
	case Rusage: {
		struct rusage ru;
		if (get_struct(pid, (void *)args[sc->offset], &ru, sizeof(ru))
		    != -1) {
			asprintf(&tmp,
			    "{ u=%ld.%06ld,s=%ld.%06ld,in=%ld,out=%ld }",
			    (long)ru.ru_utime.tv_sec, ru.ru_utime.tv_usec,
			    (long)ru.ru_stime.tv_sec, ru.ru_stime.tv_usec,
			    ru.ru_inblock, ru.ru_oublock);
		} else
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		break;
	}
	case Rlimit: {
		struct rlimit rl;
		if (get_struct(pid, (void *)args[sc->offset], &rl, sizeof(rl))
		    != -1) {
			asprintf(&tmp, "{ cur=%ju,max=%ju }",
			    rl.rlim_cur, rl.rlim_max);
		} else
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		break;
	}
	case ExitStatus: {
		char *signame;
		int status;
		signame = NULL;
		if (get_struct(pid, (void *)args[sc->offset], &status,
		    sizeof(status)) != -1) {
			if (WIFCONTINUED(status))
				tmp = strdup("{ CONTINUED }");
			else if (WIFEXITED(status))
				asprintf(&tmp, "{ EXITED,val=%d }",
				    WEXITSTATUS(status));
			else if (WIFSIGNALED(status))
				asprintf(&tmp, "{ SIGNALED,sig=%s%s }",
				    signame = strsig2(WTERMSIG(status)),
				    WCOREDUMP(status) ? ",cored" : "");
			else
				asprintf(&tmp, "{ STOPPED,sig=%s }",
				    signame = strsig2(WTERMSIG(status)));
		} else
			asprintf(&tmp, "0x%lx", args[sc->offset]);
		free(signame);
		break;
	}
	case Waitoptions:
		tmp = strdup(xlookup_bits(wait_options, args[sc->offset]));
		break;
	case Idtype:
		tmp = strdup(xlookup(idtype_arg, args[sc->offset]));
		break;
	case Procctl:
		tmp = strdup(xlookup(procctl_arg, args[sc->offset]));
		break;
	default:
		errx(1, "Invalid argument type %d\n", sc->type & ARG_MASK);
	}
Ejemplo n.º 18
0
/*===========================================================================*
 *				do_svrctl				     *
 *===========================================================================*/
int do_svrctl(void)
{
    unsigned long req;
    int s;
    vir_bytes ptr;
#define MAX_LOCAL_PARAMS 2
    static struct {
        char name[30];
        char value[30];
    } local_param_overrides[MAX_LOCAL_PARAMS];
    static int local_params = 0;

    req = m_in.m_lc_svrctl.request;
    ptr = m_in.m_lc_svrctl.arg;

    /* Is the request indeed for the PM? ('M' is old and being phased out) */
    if (IOCGROUP(req) != 'P' && IOCGROUP(req) != 'M') return(EINVAL);

    /* Control operations local to the PM. */
    switch(req) {
    case OPMSETPARAM:
    case OPMGETPARAM:
    case PMSETPARAM:
    case PMGETPARAM: {
        struct sysgetenv sysgetenv;
        char search_key[64];
        char *val_start;
        size_t val_len;
        size_t copy_len;

        /* Copy sysgetenv structure to PM. */
        if (sys_datacopy(who_e, ptr, SELF, (vir_bytes) &sysgetenv,
                         sizeof(sysgetenv)) != OK) return(EFAULT);

        /* Set a param override? */
        if (req == PMSETPARAM || req == OPMSETPARAM) {
            if (local_params >= MAX_LOCAL_PARAMS) return ENOSPC;
            if (sysgetenv.keylen <= 0
                    || sysgetenv.keylen >=
                    sizeof(local_param_overrides[local_params].name)
                    || sysgetenv.vallen <= 0
                    || sysgetenv.vallen >=
                    sizeof(local_param_overrides[local_params].value))
                return EINVAL;

            if ((s = sys_datacopy(who_e, (vir_bytes) sysgetenv.key,
                                  SELF, (vir_bytes) local_param_overrides[local_params].name,
                                  sysgetenv.keylen)) != OK)
                return s;
            if ((s = sys_datacopy(who_e, (vir_bytes) sysgetenv.val,
                                  SELF, (vir_bytes) local_param_overrides[local_params].value,
                                  sysgetenv.vallen)) != OK)
                return s;
            local_param_overrides[local_params].name[sysgetenv.keylen] = '\0';
            local_param_overrides[local_params].value[sysgetenv.vallen] = '\0';

            local_params++;

            return OK;
        }

        if (sysgetenv.keylen == 0) {	/* copy all parameters */
            val_start = monitor_params;
            val_len = sizeof(monitor_params);
        }
        else {				/* lookup value for key */
            int p;
            /* Try to get a copy of the requested key. */
            if (sysgetenv.keylen > sizeof(search_key)) return(EINVAL);
            if ((s = sys_datacopy(who_e, (vir_bytes) sysgetenv.key,
                                  SELF, (vir_bytes) search_key, sysgetenv.keylen)) != OK)
                return(s);

            /* Make sure key is null-terminated and lookup value.
             * First check local overrides.
             */
            search_key[sysgetenv.keylen-1]= '\0';
            for(p = 0; p < local_params; p++) {
                if (!strcmp(search_key, local_param_overrides[p].name)) {
                    val_start = local_param_overrides[p].value;
                    break;
                }
            }
            if (p >= local_params && (val_start = find_param(search_key)) == NULL)
                return(ESRCH);
            val_len = strlen(val_start) + 1;
        }

        /* See if it fits in the client's buffer. */
        if (val_len > sysgetenv.vallen)
            return E2BIG;

        /* Value found, make the actual copy (as far as possible). */
        copy_len = MIN(val_len, sysgetenv.vallen);
        if ((s=sys_datacopy(SELF, (vir_bytes) val_start,
                            who_e, (vir_bytes) sysgetenv.val, copy_len)) != OK)
            return(s);

        return OK;
    }

    default:
        return(EINVAL);
    }
}
Ejemplo n.º 19
0
Archivo: hpcfb.c Proyecto: MarginC/kame
int
hpcfb_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
{
	struct hpcfb_softc *sc = v;
	struct hpcfb_devconfig *dc = sc->sc_dc;
	struct wsdisplay_fbinfo *wdf;

	DPRINTF(("hpcfb_ioctl(cmd=0x%lx)\n", cmd));
	switch (cmd) {
	case WSKBDIO_BELL:
		return (0);
		break;

	case WSDISPLAYIO_GTYPE:
		*(u_int *)data = WSDISPLAY_TYPE_HPCFB;
		return (0);

	case WSDISPLAYIO_GINFO:
		wdf = (void *)data;
		wdf->height = dc->dc_rinfo.ri_height;
		wdf->width = dc->dc_rinfo.ri_width;
		wdf->depth = dc->dc_rinfo.ri_depth;
		wdf->cmsize = 256;	/* XXXX */
		return (0);
	
	case WSDISPLAYIO_SMODE:
		if (*(int *)data == WSDISPLAYIO_MODE_EMUL){ 
			if (sc->sc_mapping){
				sc->sc_mapping = 0;
				if (dc->dc_state&HPCFB_DC_DRAWING)
					dc->dc_state &= ~HPCFB_DC_ABORT;
#ifdef HPCFB_FORCE_REDRAW
				hpcfb_refresh_screen(sc);
#else
				dc->dc_state |= HPCFB_DC_UPDATEALL;
#endif
			}
		} else {
			if (!sc->sc_mapping) {
				sc->sc_mapping = 1;
				dc->dc_state |= HPCFB_DC_ABORT;
			}
			sc->sc_mapping = 1;
		}
		if (sc && sc->sc_accessops->iodone)
			(*sc->sc_accessops->iodone)(sc->sc_accessctx);
		return (0);	

	case WSDISPLAYIO_GETCMAP:
	case WSDISPLAYIO_PUTCMAP:
	case WSDISPLAYIO_GETPARAM:
	case WSDISPLAYIO_SETPARAM:
	case HPCFBIO_GCONF:
	case HPCFBIO_SCONF:
	case HPCFBIO_GDSPCONF:
	case HPCFBIO_SDSPCONF:
	case HPCFBIO_GOP:
	case HPCFBIO_SOP:
		return ((*sc->sc_accessops->ioctl)(sc->sc_accessctx,
		    cmd, data, flag, p));

	default:
		if (IOCGROUP(cmd) != 't')
			DPRINTF(("%s(%d): hpcfb_ioctl(%lx, %lx) grp=%c num=%ld\n",
			    __FILE__, __LINE__,
			    cmd, (u_long)data, (char)IOCGROUP(cmd), cmd&0xff));
		break;
	}

	return (EPASSTHROUGH); /* Inappropriate ioctl for device */
}