| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* | 
 | 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 Akkerman | ea78f0f | 1999-11-29 15:34:02 +0000 | [diff] [blame] | 33 | #ifndef HAVE_MP_PROCFS | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 34 |  | 
| Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 35 | static const struct xlat proc_status_flags[] = { | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | 	{ 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 McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 60 | static const struct xlat proc_status_why[] = { | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 61 | 	{ 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 McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 76 | static const struct xlat proc_run_flags[] = { | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 77 | 	{ 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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 89 | int | 
| Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 90 | proc_ioctl(struct tcb *tcp, int code, int arg) | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 91 | { | 
 | 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) | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 104 | 			tprints(", NULL"); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 105 | 		else if (syserror(tcp)) | 
 | 106 | 			tprintf(", %#x", arg); | 
 | 107 | 		else if (umove(tcp, arg, &status) < 0) | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 108 | 			tprints(", {...}"); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 109 | 		else { | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 110 | 			tprints(", {pr_flags="); | 
| Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 111 | 			printflags(proc_status_flags, status.pr_flags, "PR_???"); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 112 | 			if (status.pr_why) { | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 113 | 				tprints(", pr_why="); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 114 | 				printxval(proc_status_why, status.pr_why, | 
 | 115 | 					  "PR_???"); | 
 | 116 | 			} | 
 | 117 | 			switch (status.pr_why) { | 
 | 118 | 			case PR_SIGNALLED: | 
 | 119 | 			case PR_JOBCONTROL: | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 120 | 				tprints(", pr_what="); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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 | 			} | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 132 | 			tprints(", ...}"); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 133 | 		} | 
 | 134 | 		return 1; | 
 | 135 | 	case PIOCRUN: | 
 | 136 | 		if (arg == 0) | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 137 | 			tprints(", NULL"); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 138 | 		else if (umove(tcp, arg, &run) < 0) | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 139 | 			tprints(", {...}"); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 140 | 		else { | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 141 | 			tprints(", {pr_flags="); | 
| Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 142 | 			printflags(proc_run_flags, run.pr_flags, "PR???"); | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 143 | 			tprints(", ...}"); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 144 | 		} | 
 | 145 | 		return 1; | 
 | 146 | #ifdef PIOCSET | 
 | 147 | 	case PIOCSET: | 
 | 148 | 	case PIOCRESET: | 
 | 149 | 		if (umove(tcp, arg, &val) < 0) | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 150 | 			tprints(", [?]"); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 151 | 		else { | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 152 | 			tprints(", ["); | 
| Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 153 | 			printflags(proc_status_flags, val, "PR_???"); | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 154 | 			tprints("]"); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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) | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 162 | 			tprints(", [?]"); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 163 | 		else { | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 164 | 			tprints(", ["); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 165 | 			printsignal(val); | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 166 | 			tprints("]"); | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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 Akkerman | ea78f0f | 1999-11-29 15:34:02 +0000 | [diff] [blame] | 181 | #endif /* HAVE_MP_PROCFS */ | 
| Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 182 | #endif /* SVR4 */ | 
| Wichert Akkerman | 5daa028 | 1999-03-15 19:49:42 +0000 | [diff] [blame] | 183 |  | 
| Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 184 | #ifdef FREEBSD | 
 | 185 | #include <sys/pioctl.h> | 
 | 186 |  | 
| Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 187 | static const struct xlat proc_status_why[] = { | 
| Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 188 | 	{ 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 McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 197 | static const struct xlat proc_status_flags[] = { | 
| Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 198 | 	{ PF_LINGER,	"PF_LINGER"	}, | 
 | 199 | 	{ PF_ISUGID,	"PF_ISUGID"	}, | 
 | 200 | 	{ 0,		NULL		} | 
 | 201 | }; | 
 | 202 |  | 
 | 203 | int | 
| Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 204 | proc_ioctl(struct tcb *tcp, int code, int arg) | 
| Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 205 | { | 
 | 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) | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 216 | 			tprints(", NULL"); | 
| Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 217 | 		else if (syserror(tcp)) | 
 | 218 | 			tprintf(", %x", arg); | 
 | 219 | 		else if (umove(tcp, arg, &status) < 0) | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 220 | 			tprints(", {...}"); | 
| Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 221 | 		else { | 
 | 222 | 			tprintf(", {state=%d, flags=", status.state); | 
| Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 223 | 			printflags(proc_status_flags, status.flags, "PF_???"); | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 224 | 			tprints(", events="); | 
| Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 225 | 			printflags(proc_status_why, status.events, "S_???"); | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 226 | 			tprints(", why="); | 
| Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 227 | 			printxval(proc_status_why, status.why, "S_???"); | 
 | 228 | 			tprintf(", val=%lu}", status.val); | 
 | 229 | 		} | 
 | 230 | 		return 1; | 
 | 231 | 	case PIOCBIS: | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 232 | 		tprints(", "); | 
| Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 233 | 		printflags(proc_status_why, arg, "S_???"); | 
| Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 234 | 		return 1; | 
 | 235 | 		return 1; | 
 | 236 | 	case PIOCSFL: | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 237 | 		tprints(", "); | 
| Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 238 | 		printflags(proc_status_flags, arg, "PF_???"); | 
| Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 239 | 		return 1; | 
 | 240 | 	case PIOCGFL: | 
| Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 241 | 		if (syserror(tcp)) | 
| Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 242 | 			tprintf(", %#x", arg); | 
 | 243 | 		else if (umove(tcp, arg, &val) < 0) | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 244 | 			tprints(", {...}"); | 
| Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 245 | 		else { | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 246 | 			tprints(", ["); | 
| Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 247 | 			printflags(proc_status_flags, val, "PF_???"); | 
| Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 248 | 			tprints("]"); | 
| Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 249 | 		} | 
 | 250 | 		return 1; | 
 | 251 | 	default: | 
 | 252 | 		/* ad naseum */ | 
 | 253 | 		return 0; | 
 | 254 | 	} | 
 | 255 | } | 
 | 256 | #endif |