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 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <sys/types.h>
33 #include "libproc.h"
34
35 /*
36 * ioctl() system call -- executed by subject process.
37 */
38 int
pr_ioctl(struct ps_prochandle * Pr,int fd,int code,void * buf,size_t size)39 pr_ioctl(struct ps_prochandle *Pr, int fd, int code, void *buf, size_t size)
40 {
41 sysret_t rval; /* return value from ioctl() */
42 argdes_t argd[3]; /* arg descriptors for ioctl() */
43 argdes_t *adp = &argd[0]; /* first argument */
44 int error;
45
46 if (Pr == NULL) /* no subject process */
47 return (ioctl(fd, code, buf));
48
49 adp->arg_value = fd;
50 adp->arg_object = NULL;
51 adp->arg_type = AT_BYVAL;
52 adp->arg_inout = AI_INPUT;
53 adp->arg_size = 0;
54 adp++; /* move to code argument */
55
56 adp->arg_value = code;
57 adp->arg_object = NULL;
58 adp->arg_type = AT_BYVAL;
59 adp->arg_inout = AI_INPUT;
60 adp->arg_size = 0;
61 adp++; /* move to buffer argument */
62
63 if (size == 0) {
64 adp->arg_value = (long)buf;
65 adp->arg_object = NULL;
66 adp->arg_type = AT_BYVAL;
67 adp->arg_inout = AI_INPUT;
68 adp->arg_size = 0;
69 } else {
70 adp->arg_value = 0;
71 adp->arg_object = buf;
72 adp->arg_type = AT_BYREF;
73 adp->arg_inout = AI_INOUT;
74 adp->arg_size = size;
75 }
76
77 error = Psyscall(Pr, &rval, SYS_ioctl, 3, &argd[0]);
78
79 if (error) {
80 errno = (error > 0)? error : ENOSYS;
81 return (-1);
82 }
83 return (rval.sys_rval1);
84 }
85