1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 1997-2000 by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 #include <stdlib.h> 28 #include <unistd.h> 29 #include <errno.h> 30 #include <sys/types.h> 31 #include "libproc.h" 32 33 /* 34 * ioctl() system call -- executed by subject process. 35 */ 36 int 37 pr_ioctl(struct ps_prochandle *Pr, int fd, int code, void *buf, size_t size) 38 { 39 sysret_t rval; /* return value from ioctl() */ 40 argdes_t argd[3]; /* arg descriptors for ioctl() */ 41 argdes_t *adp = &argd[0]; /* first argument */ 42 int error; 43 44 if (Pr == NULL) /* no subject process */ 45 return (ioctl(fd, code, buf)); 46 47 adp->arg_value = fd; 48 adp->arg_object = NULL; 49 adp->arg_type = AT_BYVAL; 50 adp->arg_inout = AI_INPUT; 51 adp->arg_size = 0; 52 adp++; /* move to code argument */ 53 54 adp->arg_value = code; 55 adp->arg_object = NULL; 56 adp->arg_type = AT_BYVAL; 57 adp->arg_inout = AI_INPUT; 58 adp->arg_size = 0; 59 adp++; /* move to buffer argument */ 60 61 if (size == 0) { 62 adp->arg_value = (long)buf; 63 adp->arg_object = NULL; 64 adp->arg_type = AT_BYVAL; 65 adp->arg_inout = AI_INPUT; 66 adp->arg_size = 0; 67 } else { 68 adp->arg_value = 0; 69 adp->arg_object = buf; 70 adp->arg_type = AT_BYREF; 71 adp->arg_inout = AI_INOUT; 72 adp->arg_size = size; 73 } 74 75 error = Psyscall(Pr, &rval, SYS_ioctl, 3, &argd[0]); 76 77 if (error) { 78 errno = (error > 0)? error : ENOSYS; 79 return (-1); 80 } 81 return (rval.sys_rval1); 82 } 83