2 * Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "opt_compat.h"
33 #include <sys/param.h>
35 #include <sys/mutex.h>
36 #include <sys/pioctl.h>
38 #include <sys/signalvar.h>
39 #include <sys/systm.h>
41 #include <fs/pseudofs/pseudofs.h>
42 #include <fs/procfs/procfs.h>
45 struct procfs_status32 {
46 int state; /* Running, stopped, something else? */
47 int flags; /* Any flags */
48 unsigned int events; /* Events to stop on */
49 int why; /* What event, if any, proc stopped on */
50 unsigned int val; /* Any extra data */
53 #define PIOCWAIT32 _IOR('p', 4, struct procfs_status32)
54 #define PIOCSTATUS32 _IOR('p', 6, struct procfs_status32)
61 procfs_ioctl(PFS_IOCTL_ARGS)
63 struct procfs_status *ps;
65 struct procfs_status32 *ps32;
67 int error, flags, sig;
72 #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
73 case _IOC(IOC_IN, 'p', 1, 0):
76 p->p_stops |= *(uintptr_t *)data;
78 #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
79 case _IOC(IOC_IN, 'p', 2, 0):
82 p->p_stops &= ~*(uintptr_t *)data;
84 #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
85 case _IOC(IOC_IN, 'p', 3, 0):
88 flags = *(uintptr_t *)data;
89 if (flags & PF_ISUGID && (error = suser(td)) != 0)
91 p->p_pfsflags = flags;
94 *(unsigned int *)data = p->p_pfsflags;
97 while (p->p_step == 0) {
98 /* sleep until p stops */
99 error = msleep(&p->p_stype, &p->p_mtx,
100 PWAIT|PCATCH, "pioctl", 0);
104 /* fall through to PIOCSTATUS */
106 ps = (struct procfs_status *)data;
107 ps->state = (p->p_step == 0);
108 ps->flags = 0; /* nope */
109 ps->events = p->p_stops;
110 ps->why = p->p_step ? p->p_stype : 0;
111 ps->val = p->p_step ? p->p_xstat : 0;
115 while (p->p_step == 0) {
116 /* sleep until p stops */
117 error = msleep(&p->p_stype, &p->p_mtx,
118 PWAIT|PCATCH, "pioctl", 0);
122 /* fall through to PIOCSTATUS32 */
124 ps32 = (struct procfs_status32 *)data;
125 ps32->state = (p->p_step == 0);
126 ps32->flags = 0; /* nope */
127 ps32->events = p->p_stops;
128 ps32->why = p->p_step ? p->p_stype : 0;
129 ps32->val = p->p_step ? p->p_xstat : 0;
132 #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
133 case _IOC(IOC_IN, 'p', 5, 0):
138 sig = *(uintptr_t *)data;
139 if (sig != 0 && !_SIG_VALID(sig)) {
145 if (P_SHOULDSTOP(p)) {
147 p->p_flag &= ~(P_STOPPED_TRACE|P_STOPPED_SIG);
148 mtx_lock_spin(&sched_lock);
150 mtx_unlock_spin(&sched_lock);
169 * Clean up on last close
172 procfs_close(PFS_CLOSE_ARGS)
174 if (p != NULL && (p->p_pfsflags & PF_LINGER) == 0) {
175 PROC_LOCK_ASSERT(p, MA_OWNED);