blob: 1fe4890952f7bdbee7e7cc9651c0042b3fe53bcc [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1993, 1994, 1995 Rick Sladkey <jrs@world.std.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * $Id$
28 */
29
30#include "defs.h"
31
32#ifdef SVR4
Wichert Akkermanea78f0f1999-11-29 15:34:02 +000033#ifndef HAVE_MP_PROCFS
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000034
Roland McGrathd9f816f2004-09-04 03:39:20 +000035static const struct xlat proc_status_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036 { PR_STOPPED, "PR_STOPPED" },
37 { PR_ISTOP, "PR_ISTOP" },
38 { PR_DSTOP, "PR_DSTOP" },
39 { PR_ASLEEP, "PR_ASLEEP" },
40 { PR_FORK, "PR_FORK" },
41 { PR_RLC, "PR_RLC" },
42 { PR_PTRACE, "PR_PTRACE" },
43 { PR_PCINVAL, "PR_PCINVAL" },
44 { PR_ISSYS, "PR_ISSYS" },
45#ifdef PR_STEP
46 { PR_STEP, "PR_STEP" },
47#endif
48#ifdef PR_KLC
49 { PR_KLC, "PR_KLC" },
50#endif
51#ifdef PR_ASYNC
52 { PR_ASYNC, "PR_ASYNC" },
53#endif
54#ifdef PR_PCOMPAT
55 { PR_PCOMPAT, "PR_PCOMPAT" },
56#endif
57 { 0, NULL },
58};
59
Roland McGrathd9f816f2004-09-04 03:39:20 +000060static const struct xlat proc_status_why[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000061 { PR_REQUESTED, "PR_REQUESTED" },
62 { PR_SIGNALLED, "PR_SIGNALLED" },
63 { PR_SYSENTRY, "PR_SYSENTRY" },
64 { PR_SYSEXIT, "PR_SYSEXIT" },
65 { PR_JOBCONTROL,"PR_JOBCONTROL" },
66 { PR_FAULTED, "PR_FAULTED" },
67#ifdef PR_SUSPENDED
68 { PR_SUSPENDED, "PR_SUSPENDED" },
69#endif
70#ifdef PR_CHECKPOINT
71 { PR_CHECKPOINT,"PR_CHECKPOINT" },
72#endif
73 { 0, NULL },
74};
75
Roland McGrathd9f816f2004-09-04 03:39:20 +000076static const struct xlat proc_run_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000077 { PRCSIG, "PRCSIG" },
78 { PRCFAULT, "PRCFAULT" },
79 { PRSTRACE, "PRSTRACE" },
80 { PRSHOLD, "PRSHOLD" },
81 { PRSFAULT, "PRSFAULT" },
82 { PRSVADDR, "PRSVADDR" },
83 { PRSTEP, "PRSTEP" },
84 { PRSABORT, "PRSABORT" },
85 { PRSTOP, "PRSTOP" },
86 { 0, NULL },
87};
88
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000089int
Denys Vlasenko12014262011-05-30 14:00:14 +020090proc_ioctl(struct tcb *tcp, int code, int arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000091{
92 int val;
93 prstatus_t status;
94 prrun_t run;
95
96 if (entering(tcp))
97 return 0;
98
99 switch (code) {
100 case PIOCSTATUS:
101 case PIOCSTOP:
102 case PIOCWSTOP:
103 if (arg == 0)
104 tprintf(", NULL");
105 else if (syserror(tcp))
106 tprintf(", %#x", arg);
107 else if (umove(tcp, arg, &status) < 0)
108 tprintf(", {...}");
109 else {
110 tprintf(", {pr_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000111 printflags(proc_status_flags, status.pr_flags, "PR_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000112 if (status.pr_why) {
113 tprintf(", pr_why=");
114 printxval(proc_status_why, status.pr_why,
115 "PR_???");
116 }
117 switch (status.pr_why) {
118 case PR_SIGNALLED:
119 case PR_JOBCONTROL:
120 tprintf(", pr_what=");
121 printsignal(status.pr_what);
122 break;
123 case PR_FAULTED:
124 tprintf(", pr_what=%d", status.pr_what);
125 break;
126 case PR_SYSENTRY:
127 case PR_SYSEXIT:
128 tprintf(", pr_what=SYS_%s",
129 sysent[status.pr_what].sys_name);
130 break;
131 }
132 tprintf(", ...}");
133 }
134 return 1;
135 case PIOCRUN:
136 if (arg == 0)
137 tprintf(", NULL");
138 else if (umove(tcp, arg, &run) < 0)
139 tprintf(", {...}");
140 else {
141 tprintf(", {pr_flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000142 printflags(proc_run_flags, run.pr_flags, "PR???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000143 tprintf(", ...}");
144 }
145 return 1;
146#ifdef PIOCSET
147 case PIOCSET:
148 case PIOCRESET:
149 if (umove(tcp, arg, &val) < 0)
150 tprintf(", [?]");
151 else {
152 tprintf(", [");
Roland McGrathb2dee132005-06-01 19:02:36 +0000153 printflags(proc_status_flags, val, "PR_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000154 tprintf("]");
155 }
156 return 1;
157#endif /* PIOCSET */
158 case PIOCKILL:
159 case PIOCUNKILL:
160 /* takes a pointer to a signal */
161 if (umove(tcp, arg, &val) < 0)
162 tprintf(", [?]");
163 else {
164 tprintf(", [");
165 printsignal(val);
166 tprintf("]");
167 }
168 return 1;
169 case PIOCSFORK:
170 case PIOCRFORK:
171 case PIOCSRLC:
172 case PIOCRRLC:
173 /* doesn't take an arg */
174 return 1;
175 default:
176 /* ad naseum */
177 return 0;
178 }
179}
180
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000181#endif /* HAVE_MP_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182#endif /* SVR4 */
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000183
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000184#ifdef FREEBSD
185#include <sys/pioctl.h>
186
Roland McGrathd9f816f2004-09-04 03:39:20 +0000187static const struct xlat proc_status_why[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000188 { S_EXEC, "S_EXEC" },
189 { S_SIG, "S_SIG" },
190 { S_SCE, "S_SCE" },
191 { S_SCX, "S_SCX" },
192 { S_CORE, "S_CORE" },
193 { S_EXIT, "S_EXIT" },
194 { 0, NULL }
195};
196
Roland McGrathd9f816f2004-09-04 03:39:20 +0000197static const struct xlat proc_status_flags[] = {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000198 { PF_LINGER, "PF_LINGER" },
199 { PF_ISUGID, "PF_ISUGID" },
200 { 0, NULL }
201};
202
203int
Denys Vlasenko12014262011-05-30 14:00:14 +0200204proc_ioctl(struct tcb *tcp, int code, int arg)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000205{
206 int val;
207 struct procfs_status status;
208
209 if (entering(tcp))
210 return 0;
211
212 switch (code) {
213 case PIOCSTATUS:
214 case PIOCWAIT:
215 if (arg == 0)
216 tprintf(", NULL");
217 else if (syserror(tcp))
218 tprintf(", %x", arg);
219 else if (umove(tcp, arg, &status) < 0)
220 tprintf(", {...}");
221 else {
222 tprintf(", {state=%d, flags=", status.state);
Roland McGrathb2dee132005-06-01 19:02:36 +0000223 printflags(proc_status_flags, status.flags, "PF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000224 tprintf(", events=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000225 printflags(proc_status_why, status.events, "S_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000226 tprintf(", why=");
227 printxval(proc_status_why, status.why, "S_???");
228 tprintf(", val=%lu}", status.val);
229 }
230 return 1;
231 case PIOCBIS:
Roland McGrathb2dee132005-06-01 19:02:36 +0000232 tprintf(", ");
233 printflags(proc_status_why, arg, "S_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000234 return 1;
235 return 1;
236 case PIOCSFL:
Roland McGrathb2dee132005-06-01 19:02:36 +0000237 tprintf(", ");
238 printflags(proc_status_flags, arg, "PF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000239 return 1;
240 case PIOCGFL:
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000241 if (syserror(tcp))
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000242 tprintf(", %#x", arg);
243 else if (umove(tcp, arg, &val) < 0)
244 tprintf(", {...}");
245 else {
246 tprintf(", [");
Roland McGrathb2dee132005-06-01 19:02:36 +0000247 printflags(proc_status_flags, val, "PF_???");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000248 tprintf("]");
249 }
250 return 1;
251 default:
252 /* ad naseum */
253 return 0;
254 }
255}
256#endif