int input(int dev, void *buf, int size) { ret = 0; #ifdef VERBOSE _entry: trl_(); trvd(size); #endif if (dev < 0 || wo) return 0; switch (io_type) { case mmap_io: memcpy(buf, mem, size); ret = size; break; case ioctl_io: ioctl(dev, _IOC(_IOC_READ, ioctl_type, ioctl_num, size & _IOC_SIZEMASK), buf); ret = size; break; case file_io: default: ret = read(dev, buf, size); } return ret; }
int main(int argc, char *argv[]) { int fd = 0; int handle = 0x0; unsigned long dir = 0; unsigned long size = 0; unsigned long type = 0; unsigned long nr = 0; printf("请输入参数:方向(dir[0,none,1为写,2为读]) 尺寸(size) (类型)type (序号)number\n"); if (argc != 5) { return -1; } dir = strtoul(argv[1], NULL, 10); size = strtoul(argv[2], NULL, 10); type = strtoul(argv[3], NULL, 10); nr = strtoul(argv[4], NULL, 10); printf("方向(dir):%d\n", dir); printf("尺寸(size):%d\n", size); printf("类型(type):%d\n", type); printf("索引(number):%d\n", nr); printf("结果(result):0x%08x\n", _IOC(dir,type,nr,size)); return 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)); } }
static long pps_cdev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct pps_device *pps = file->private_data; void __user *uarg = (void __user *) arg; cmd = _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(void *)); if (cmd == PPS_FETCH) { struct pps_fdata_compat compat; struct pps_fdata fdata; int err; dev_dbg(pps->dev, "PPS_FETCH\n"); err = copy_from_user(&compat, uarg, sizeof(struct pps_fdata_compat)); if (err) return -EFAULT; memcpy(&fdata.timeout, &compat.timeout, sizeof(struct pps_ktime_compat)); err = pps_cdev_pps_fetch(pps, &fdata); if (err) return err; /* Return the fetched timestamp */ spin_lock_irq(&pps->lock); compat.info.assert_sequence = pps->assert_sequence; compat.info.clear_sequence = pps->clear_sequence; compat.info.current_mode = pps->current_mode; memcpy(&compat.info.assert_tu, &pps->assert_tu, sizeof(struct pps_ktime_compat)); memcpy(&compat.info.clear_tu, &pps->clear_tu, sizeof(struct pps_ktime_compat)); spin_unlock_irq(&pps->lock); return copy_to_user(uarg, &compat, sizeof(struct pps_fdata_compat)) ? -EFAULT : 0; } return pps_cdev_ioctl(file, cmd, arg); }
static int ioctl_simplestruct_init_from_text(ioctl_tree * node, const char *data) { /* node->id is initialized at this point, but does not necessarily have the * correct length for data; this happens for variable length ioctls such as * EVIOCGBIT */ size_t data_len = strlen(data) / 2; node->data = malloc(data_len); if (NSIZE(node) != data_len) { DBG(DBG_IOCTL_TREE, "ioctl_simplestruct_init_from_text: adjusting ioctl ID %lX (size %lu) to actual data length %zu\n", node->id, NSIZE(node), data_len); node->id = _IOC(_IOC_DIR(node->id), _IOC_TYPE(node->id), _IOC_NR(node->id), data_len); } if (!read_hex(data, node->data, NSIZE(node))) { DBG(DBG_IOCTL_TREE, "ioctl_simplestruct_init_from_text: failed to parse '%s'\n", data); free(node->data); return FALSE; } return TRUE; }
/* Ver.3.20 Get Model name from deviceID */ static short GetModelName( char *device , char *model_name , short len) { char devid[1024]; char *des_p = NULL; short aaa = 0; short model_found = 0; int fd; /* File descriptor */ if ((fd = open(device, O_RDONLY)) >= 0) { memset( devid , 0x00 , 1024 ); model_found = 0; aaa = 0; des_p = NULL; /* Get DeviceID */ if (ioctl(fd, _IOC(_IOC_READ, 'P', 1, sizeof(devid)), devid) == 0){ /* Get "DES" from DeviceID */ des_p = strstr( devid+2 , "DES" ); if( des_p != NULL){ des_p+=4; while( *des_p != ';' ){ model_name[aaa] = *des_p; des_p++; aaa++; if( aaa >= (len-1) ) break; } model_found = 1; // printf("DES=%s\n", model_name ); } // printf("devid=%s\n", devid+2); } close(fd); /* 2.3.x and 2.4.x */ } return model_found; }
int output(int dev, void *buf, int size) { #ifdef VERBOSE _entry: trl_(); trvd(size); #endif ret = 0; if (dev < 0 || ro) return 0; switch (io_type) { case mmap_io: memcpy(mem, buf, size); ret = size; break; case ioctl_io: ioctl(dev, _IOC(_IOC_WRITE, ioctl_type, ioctl_num, size & _IOC_SIZEMASK), buf); break; case file_io: default: ret = write(dev, buf, size); } return ret; }
int main(void) { TEST_NULL_ARG(BLKBSZGET); TEST_NULL_ARG(BLKBSZSET); TEST_NULL_ARG(BLKFRAGET); TEST_NULL_ARG(BLKGETSIZE); TEST_NULL_ARG(BLKGETSIZE64); TEST_NULL_ARG(BLKPG); TEST_NULL_ARG(BLKRAGET); TEST_NULL_ARG(BLKROGET); TEST_NULL_ARG(BLKROSET); TEST_NULL_ARG(BLKSECTGET); TEST_NULL_ARG(BLKSECTGET); TEST_NULL_ARG(BLKSSZGET); #ifdef BLKALIGNOFF TEST_NULL_ARG(BLKALIGNOFF); #endif #ifdef BLKDISCARD TEST_NULL_ARG(BLKDISCARD); #endif #ifdef BLKDISCARDZEROES TEST_NULL_ARG(BLKDISCARDZEROES); #endif #ifdef BLKIOMIN TEST_NULL_ARG(BLKIOMIN); #endif #ifdef BLKIOOPT TEST_NULL_ARG(BLKIOOPT); #endif #ifdef BLKPBSZGET TEST_NULL_ARG(BLKPBSZGET); #endif #ifdef BLKROTATIONAL TEST_NULL_ARG(BLKROTATIONAL); #endif #ifdef BLKSECDISCARD TEST_NULL_ARG(BLKSECDISCARD); #endif #ifdef BLKZEROOUT TEST_NULL_ARG(BLKZEROOUT); #endif #if defined BLKTRACESETUP && defined HAVE_STRUCT_BLK_USER_TRACE_SETUP TEST_NULL_ARG(BLKTRACESETUP); #endif ioctl(-1, BLKRASET, lmagic); printf("ioctl(-1, BLKRASET, %lu) = -1 EBADF (%m)\n", lmagic); ioctl(-1, BLKFRASET, lmagic); printf("ioctl(-1, BLKFRASET, %lu) = -1 EBADF (%m)\n", lmagic); int *const val_int = tail_alloc(sizeof(*val_int)); *val_int = magic; ioctl(-1, BLKROSET, val_int); printf("ioctl(-1, BLKROSET, [%d]) = -1 EBADF (%m)\n", *val_int); ioctl(-1, BLKBSZSET, val_int); printf("ioctl(-1, BLKBSZSET, [%d]) = -1 EBADF (%m)\n", *val_int); uint64_t *pair_int64 = tail_alloc(sizeof(*pair_int64) * 2); pair_int64[0] = 0xdeadbeefbadc0dedULL; pair_int64[1] = 0xfacefeedcafef00dULL; #ifdef BLKDISCARD ioctl(-1, BLKDISCARD, pair_int64); printf("ioctl(-1, BLKDISCARD, [%" PRIu64 ", %" PRIu64 "])" " = -1 EBADF (%m)\n", pair_int64[0], pair_int64[1]); #endif #ifdef BLKSECDISCARD ioctl(-1, BLKSECDISCARD, pair_int64); printf("ioctl(-1, BLKSECDISCARD, [%" PRIu64 ", %" PRIu64 "])" " = -1 EBADF (%m)\n", pair_int64[0], pair_int64[1]); #endif #ifdef BLKZEROOUT ioctl(-1, BLKZEROOUT, pair_int64); printf("ioctl(-1, BLKZEROOUT, [%" PRIu64 ", %" PRIu64 "])" " = -1 EBADF (%m)\n", pair_int64[0], pair_int64[1]); #endif struct blkpg_ioctl_arg *const blkpg = tail_alloc(sizeof(*blkpg)); blkpg->op = 3; blkpg->flags = 0xdeadbeef; blkpg->datalen = 0xbadc0ded; blkpg->data = (void *) (unsigned long) 0xcafef00dfffffeedULL; ioctl(-1, BLKPG, blkpg); printf("ioctl(-1, BLKPG, {%s, flags=%d, datalen=%d" ", data=%#lx}) = -1 EBADF (%m)\n", "BLKPG_RESIZE_PARTITION", blkpg->flags, blkpg->datalen, (unsigned long) blkpg->data); struct blkpg_partition *const bp = tail_alloc(sizeof(*bp)); bp->start = 0xfac1fed2dad3bef4ULL; bp->length = 0xfac5fed6dad7bef8ULL; bp->pno = magic; memset(bp->devname, 'A', sizeof(bp->devname)); memset(bp->volname, 'B', sizeof(bp->volname)); blkpg->op = 1; blkpg->data = bp; ioctl(-1, BLKPG, blkpg); printf("ioctl(-1, BLKPG, {%s, flags=%d, datalen=%d" ", data={start=%lld, length=%lld, pno=%d" ", devname=\"%.*s\", volname=\"%.*s\"}})" " = -1 EBADF (%m)\n", "BLKPG_ADD_PARTITION", blkpg->flags, blkpg->datalen, bp->start, bp->length, bp->pno, (int) sizeof(bp->devname) - 1, bp->devname, (int) sizeof(bp->volname) - 1, bp->volname); #if defined BLKTRACESETUP && defined HAVE_STRUCT_BLK_USER_TRACE_SETUP struct blk_user_trace_setup *const buts = tail_alloc(sizeof(*buts)); fill_memory(buts, sizeof(*buts)); ioctl(-1, BLKTRACESETUP, buts); printf("ioctl(-1, BLKTRACESETUP, {act_mask=%hu, buf_size=%u, buf_nr=%u" ", start_lba=%" PRI__u64 ", end_lba=%" PRI__u64 ", pid=%u})" " = -1 EBADF (%m)\n", buts->act_mask, buts->buf_size, buts->buf_nr, buts->start_lba, buts->end_lba, buts->pid); #endif unsigned int i; for (i = 0; i < ARRAY_SIZE(block_argless); ++i) { ioctl(-1, (unsigned long) block_argless[i].val, lmagic); printf("ioctl(-1, %s) = -1 EBADF (%m)\n", block_argless[i].str); } ioctl(-1, _IOC(_IOC_READ, 0x12, 0xfe, 0xff), lmagic); printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n", "_IOC(_IOC_READ, 0x12, 0xfe, 0xff)", lmagic); puts("+++ exited with 0 +++"); return 0; }
int main(void) { TEST_NULL_ARG(EVIOCGVERSION); TEST_NULL_ARG(EVIOCGEFFECTS); TEST_NULL_ARG(EVIOCGID); TEST_NULL_ARG(EVIOCGKEYCODE); TEST_NULL_ARG(EVIOCSKEYCODE); TEST_NULL_ARG(EVIOCSFF); # ifdef EVIOCGKEYCODE_V2 TEST_NULL_ARG(EVIOCGKEYCODE_V2); # endif # ifdef EVIOCSKEYCODE_V2 TEST_NULL_ARG(EVIOCSKEYCODE_V2); # endif # ifdef EVIOCGREP TEST_NULL_ARG(EVIOCGREP); # endif # ifdef EVIOCSREP TEST_NULL_ARG(EVIOCSREP); # endif # ifdef EVIOCSCLOCKID TEST_NULL_ARG(EVIOCSCLOCKID); # endif TEST_NULL_ARG(EVIOCGNAME(0)); TEST_NULL_ARG(EVIOCGPHYS(0)); TEST_NULL_ARG(EVIOCGUNIQ(0)); TEST_NULL_ARG(EVIOCGKEY(0)); TEST_NULL_ARG(EVIOCGLED(0)); # ifdef EVIOCGMTSLOTS TEST_NULL_ARG(EVIOCGMTSLOTS(0)); # endif # ifdef EVIOCGPROP TEST_NULL_ARG(EVIOCGPROP(0)); # endif TEST_NULL_ARG(EVIOCGSND(0)); # ifdef EVIOCGSW TEST_NULL_ARG(EVIOCGSW(0)); # endif TEST_NULL_ARG(EVIOCGABS(ABS_X)); TEST_NULL_ARG(EVIOCSABS(ABS_X)); TEST_NULL_ARG(EVIOCGBIT(EV_SYN, 0)); TEST_NULL_ARG(EVIOCGBIT(EV_KEY, 1)); TEST_NULL_ARG(EVIOCGBIT(EV_REL, 2)); TEST_NULL_ARG(EVIOCGBIT(EV_ABS, 3)); TEST_NULL_ARG(EVIOCGBIT(EV_MSC, 4)); # ifdef EV_SW TEST_NULL_ARG(EVIOCGBIT(EV_SW, 5)); # endif TEST_NULL_ARG(EVIOCGBIT(EV_LED, 6)); TEST_NULL_ARG(EVIOCGBIT(EV_SND, 7)); TEST_NULL_ARG(EVIOCGBIT(EV_REP, 8)); TEST_NULL_ARG(EVIOCGBIT(EV_FF, 9)); TEST_NULL_ARG(EVIOCGBIT(EV_PWR, 10)); TEST_NULL_ARG(EVIOCGBIT(EV_FF_STATUS, 11)); ioctl(-1, EVIOCGBIT(EV_MAX, 42), 0); printf("ioctl(-1, EVIOCGBIT(%#x /* EV_??? */, 42), NULL)" " = -1 EBADF (%m)\n", EV_MAX); ioctl(-1, EVIOCRMFF, lmagic); printf("ioctl(-1, EVIOCRMFF, %d) = -1 EBADF (%m)\n", (int) lmagic); ioctl(-1, EVIOCGRAB, lmagic); printf("ioctl(-1, EVIOCGRAB, %lu) = -1 EBADF (%m)\n", lmagic); # ifdef EVIOCREVOKE ioctl(-1, EVIOCREVOKE, lmagic); printf("ioctl(-1, EVIOCREVOKE, %lu) = -1 EBADF (%m)\n", lmagic); # endif const unsigned int size = get_page_size(); void *const page = tail_alloc(size); fill_memory(page, size); int *const val_int = tail_alloc(sizeof(*val_int)); *val_int = magic; # ifdef EVIOCSCLOCKID ioctl(-1, EVIOCSCLOCKID, val_int); printf("ioctl(-1, EVIOCSCLOCKID, [%u]) = -1 EBADF (%m)\n", *val_int); # endif int *pair_int = tail_alloc(sizeof(*pair_int) * 2); pair_int[0] = 0xdeadbeef; pair_int[1] = 0xbadc0ded; # ifdef EVIOSGREP ioctl(-1, EVIOCSREP, pair_int); printf("ioctl(-1, EVIOCSREP, [%u, %u]) = -1 EBADF (%m)\n", pair_int[0], pair_int[1]); # endif pair_int[1] = 1; ioctl(-1, EVIOCSKEYCODE, pair_int); printf("ioctl(-1, EVIOCSKEYCODE, [%u, %s]) = -1 EBADF (%m)\n", pair_int[0], "KEY_ESC"); # ifdef EVIOCSKEYCODE_V2 struct input_keymap_entry *const ike = tail_alloc(sizeof(*ike)); fill_memory(ike, sizeof(*ike)); ike->keycode = 2; ioctl(-1, EVIOCSKEYCODE_V2, ike); printf("ioctl(-1, EVIOCSKEYCODE_V2, {flags=%" PRIu8 ", len=%" PRIu8 ", ", ike->flags, ike->len); # if VERBOSE printf("index=%" PRIu16 ", keycode=%s, scancode=[", ike->index, "KEY_1"); unsigned int i; for (i = 0; i < ARRAY_SIZE(ike->scancode); ++i) { if (i > 0) printf(", "); printf("%" PRIx8, ike->scancode[i]); } printf("]"); # else printf("..."); # endif errno = EBADF; printf("}) = -1 EBADF (%m)\n"); # endif struct ff_effect *const ffe = tail_alloc(sizeof(*ffe)); fill_memory(ffe, sizeof(*ffe)); ffe->type = FF_CONSTANT; ioctl(-1, EVIOCSFF, ffe); print_ffe_common(ffe, "FF_CONSTANT"); # if VERBOSE printf(", constant={level=%hd", ffe->u.constant.level); print_envelope(&ffe->u.constant.envelope); printf("}"); # else printf("..."); # endif errno = EBADF; printf("}) = -1 EBADF (%m)\n"); # if VERBOSE ffe->type = FF_RAMP; ioctl(-1, EVIOCSFF, ffe); print_ffe_common(ffe, "FF_RAMP"); printf(", ramp={start_level=%hd, end_level=%hd", ffe->u.ramp.start_level, ffe->u.ramp.end_level); print_envelope(&ffe->u.ramp.envelope); errno = EBADF; printf("}}) = -1 EBADF (%m)\n"); ffe->type = FF_PERIODIC; ioctl(-1, EVIOCSFF, ffe); print_ffe_common(ffe, "FF_PERIODIC"); printf(", periodic={waveform=%hu, period=%hu, magnitude=%hd" ", offset=%hd, phase=%hu", ffe->u.periodic.waveform, ffe->u.periodic.period, ffe->u.periodic.magnitude, ffe->u.periodic.offset, ffe->u.periodic.phase); print_envelope(&ffe->u.periodic.envelope); printf(", custom_len=%u, custom_data=%p}", ffe->u.periodic.custom_len, ffe->u.periodic.custom_data); errno = EBADF; printf("}) = -1 EBADF (%m)\n"); ffe->type = FF_RUMBLE; ioctl(-1, EVIOCSFF, ffe); print_ffe_common(ffe, "FF_RUMBLE"); printf(", rumble={strong_magnitude=%hu, weak_magnitude=%hu}", ffe->u.rumble.strong_magnitude, ffe->u.rumble.weak_magnitude); errno = EBADF; printf("}) = -1 EBADF (%m)\n"); ffe->type = 0xff; ioctl(-1, EVIOCSFF, ffe); print_ffe_common(ffe, "0xff /* FF_??? */"); errno = EBADF; printf("}) = -1 EBADF (%m)\n"); # endif ioctl(-1, _IOC(_IOC_READ, 0x45, 0x1, 0xff), lmagic); printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n", "_IOC(_IOC_READ, 0x45, 0x1, 0xff)", lmagic); ioctl(-1, _IOC(_IOC_WRITE, 0x45, 0x1, 0xff), lmagic); printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n", "_IOC(_IOC_WRITE, 0x45, 0x1, 0xff)", lmagic); ioctl(-1, _IOC(_IOC_READ|_IOC_WRITE, 0x45, 0xfe, 0xff), lmagic); printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n", "_IOC(_IOC_READ|_IOC_WRITE, 0x45, 0xfe, 0xff)", lmagic); ioctl(-1, _IOC(_IOC_READ|_IOC_WRITE, 0x45, 0, 0), lmagic); printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n", "_IOC(_IOC_READ|_IOC_WRITE, 0x45, 0, 0)", lmagic); puts("+++ exited with 0 +++"); return 0; }
/* * Process ioctls */ int procfs_ioctl(PFS_IOCTL_ARGS) { struct procfs_status *ps; #ifdef COMPAT_FREEBSD32 struct procfs_status32 *ps32; #endif int error, flags, sig; #ifdef COMPAT_FREEBSD6 int ival; #endif KASSERT(p != NULL, ("%s() called without a process", __func__)); PROC_LOCK_ASSERT(p, MA_OWNED); error = 0; switch (cmd) { #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IOC(IOC_IN, 'p', 1, 0): #endif #ifdef COMPAT_FREEBSD6 case _IO('p', 1): ival = IOCPARM_IVAL(data); data = &ival; #endif case PIOCBIS: p->p_stops |= *(unsigned int *)data; break; #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IOC(IOC_IN, 'p', 2, 0): #endif #ifdef COMPAT_FREEBSD6 case _IO('p', 2): ival = IOCPARM_IVAL(data); data = &ival; #endif case PIOCBIC: p->p_stops &= ~*(unsigned int *)data; break; #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IOC(IOC_IN, 'p', 3, 0): #endif #ifdef COMPAT_FREEBSD6 case _IO('p', 3): ival = IOCPARM_IVAL(data); data = &ival; #endif case PIOCSFL: flags = *(unsigned int *)data; if (flags & PF_ISUGID) { /* * XXXRW: Is this specific check required here, as * p_candebug() should implement it, or other checks * are missing. */ error = priv_check(td, PRIV_DEBUG_SUGID); if (error) break; } p->p_pfsflags = flags; break; case PIOCGFL: *(unsigned int *)data = p->p_pfsflags; break; case PIOCWAIT: while (p->p_step == 0 && (p->p_flag & P_WEXIT) == 0) { /* sleep until p stops */ _PHOLD(p); error = msleep(&p->p_stype, &p->p_mtx, PWAIT|PCATCH, "pioctl", 0); _PRELE(p); if (error != 0) break; } /* fall through to PIOCSTATUS */ case PIOCSTATUS: ps = (struct procfs_status *)data; ps->state = (p->p_step == 0); ps->flags = 0; /* nope */ ps->events = p->p_stops; ps->why = p->p_step ? p->p_stype : 0; ps->val = p->p_step ? p->p_xstat : 0; break; #ifdef COMPAT_FREEBSD32 case PIOCWAIT32: while (p->p_step == 0 && (p->p_flag & P_WEXIT) == 0) { /* sleep until p stops */ _PHOLD(p); error = msleep(&p->p_stype, &p->p_mtx, PWAIT|PCATCH, "pioctl", 0); _PRELE(p); if (error != 0) break; } /* fall through to PIOCSTATUS32 */ case PIOCSTATUS32: ps32 = (struct procfs_status32 *)data; ps32->state = (p->p_step == 0); ps32->flags = 0; /* nope */ ps32->events = p->p_stops; ps32->why = p->p_step ? p->p_stype : 0; ps32->val = p->p_step ? p->p_xstat : 0; break; #endif #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IOC(IOC_IN, 'p', 5, 0): #endif #ifdef COMPAT_FREEBSD6 case _IO('p', 5): ival = IOCPARM_IVAL(data); data = &ival; #endif case PIOCCONT: if (p->p_step == 0) break; sig = *(unsigned int *)data; if (sig != 0 && !_SIG_VALID(sig)) { error = EINVAL; break; } #if 0 p->p_step = 0; if (P_SHOULDSTOP(p)) { p->p_xstat = sig; p->p_flag &= ~(P_STOPPED_TRACE|P_STOPPED_SIG); PROC_SLOCK(p); thread_unsuspend(p); PROC_SUNLOCK(p); } else if (sig) kern_psignal(p, sig); #else if (sig) kern_psignal(p, sig); p->p_step = 0; wakeup(&p->p_step); #endif break; default: error = (ENOTTY); } return (error); }
static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) { char *name = ":0.0"; pioData data; uint32_t retval; //TODO use x11_common for X and window handling if(getenv("DISPLAY")) name = getenv("DISPLAY"); display = XOpenDisplay(name); screenwidth = XDisplayWidth(display,0); screenheight = XDisplayHeight(display,0); page_space = screenwidth*screenheight*screendepth; vidpage0offset = 0; vidpage1offset = page_space; // Use third and fourth pages vidpage2offset = page_space*2; signal(SIGALRM,sighup); //alarm(120); // Open driver device if ( fd == -1 ) { mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_3DFX_UnableToOpenDevice); return -1; } // Store sizes for later vidwidth = width; vidheight = height; is_fullscreen = fullscreen = 0; if (!is_fullscreen) create_window(display, title); // Ask 3dfx driver for base memory address 0 data.port = 0x10; // PCI_BASE_ADDRESS_0_LINUX; data.size = 4; data.value = &baseAddr0; data.device = 0; if ((retval = ioctl(fd,_IOC(_IOC_READ,'3',3,0),&data)) < 0) { mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_3DFX_Error,retval); return -1; } // Ask 3dfx driver for base memory address 1 data.port = 0x14; // PCI_BASE_ADDRESS_1_LINUX; data.size = 4; data.value = &baseAddr1; data.device = 0; if ((retval = ioctl(fd,_IOC(_IOC_READ,'3',3,0),&data)) < 0) { mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_3DFX_Error,retval); return -1; } // Map all 3dfx memory areas memBase0 = mmap(0,0x1000000,PROT_READ | PROT_WRITE,MAP_SHARED,fd,baseAddr0); memBase1 = mmap(0,3*page_space,PROT_READ | PROT_WRITE,MAP_SHARED,fd,baseAddr1); if (memBase0 == (uint32_t *) 0xFFFFFFFF || memBase1 == (uint32_t *) 0xFFFFFFFF) { mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_3DFX_CouldntMapMemoryArea, memBase0,memBase1,errno); } // Set up global pointers reg_IO = (void *)memBase0 + VOODOO_IO_REG_OFFSET; reg_2d = (void *)memBase0 + VOODOO_2D_REG_OFFSET; reg_YUV = (void *)memBase0 + VOODOO_YUV_REG_OFFSET; fb_YUV = (void *)memBase0 + VOODOO_YUV_PLANE_OFFSET; vidpage0 = (void *)memBase1 + (unsigned long int)vidpage0offset; vidpage1 = (void *)memBase1 + (unsigned long int)vidpage1offset; vidpage2 = (void *)memBase1 + (unsigned long int)vidpage2offset; // Clear pages 1,2,3 // leave page 0, that belongs to X. // So does part of 1. Oops. memset(vidpage1,0x00,page_space); memset(vidpage2,0x00,page_space); if (is_fullscreen) memset(vidpage0,0x00,page_space); #ifndef VOODOO_DEBUG // Show page 0 (unblanked) reg_IO->vidDesktopStartAddr = vidpage0offset; /* Stop X from messing with my video registers! Find a better way to do this? Currently I use DGA to tell XF86 to not screw with registers, but I can't really use it to do FB stuff because I need to know the absolute FB position and offset FB position to feed to BLT command */ //XF86DGADirectVideo(display,0,XF86DGADirectGraphics); //| XF86DGADirectMouse | XF86DGADirectKeyb); #endif atexit(restore); mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_3DFX_DisplayInitialized,memBase1); return 0; }
int main(int argc, char* argv[]) { printf("%u\n", _IOC_DIRSHIFT); printf("%u\n", _IOC_TYPESHIFT); printf("%u\n", _IOC_NRSHIFT); printf("%u\n", _IOC_SIZESHIFT); printf("%u\n\n", _IOC_SIZEBITS); printf("%X\n", _IOC(_IOC_READ, 0, 0, 0)); printf("%X\n", EVIOCGBIT(0, EV_MAX)); int fd = 0; int yalv = 0; if ((fd = open(argv[1], O_RDONLY)) < 0) { perror("evdev open"); exit(1); } unsigned char evtype_b[EV_MAX/8 + 1] = { }; memset(evtype_b, 0, sizeof(evtype_b)); if (ioctl(fd, EVIOCGBIT(0, EV_MAX), evtype_b) < 0) { perror("evdev ioctl"); } printf("Supported event types:\n"); for (yalv = 0; yalv < EV_MAX; yalv++) { if (test_bit(yalv, evtype_b)) { /* the bit is set in the event types list */ printf(" Event type 0x%02x ", yalv); switch ( yalv) { case EV_SYN : printf(" (Synch Events)\n"); break; case EV_KEY : printf(" (Keys or Buttons)\n"); break; case EV_REL : printf(" (Relative Axes)\n"); break; case EV_ABS : printf(" (Absolute Axes)\n"); break; case EV_MSC : printf(" (Miscellaneous)\n"); break; case EV_LED : printf(" (LEDs)\n"); break; case EV_SND : printf(" (Sounds)\n"); break; case EV_REP : printf(" (Repeat)\n"); break; case EV_FF : case EV_FF_STATUS: printf(" (Force Feedback)\n"); break; case EV_PWR: printf(" (Power Management)\n"); break; default: printf(" (Unknown: 0x%04hx)\n", yalv); } } } close(fd); }