2001-12-04 01:35:06 +00:00
|
|
|
/*-
|
2017-11-27 15:15:37 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2012-01-15 13:23:18 +00:00
|
|
|
* Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
|
2001-12-04 01:35:06 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer
|
|
|
|
* in this position and unchanged.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/pioctl.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
2001-12-04 01:35:06 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
|
|
|
|
#include <fs/pseudofs/pseudofs.h>
|
|
|
|
#include <fs/procfs/procfs.h>
|
|
|
|
|
2010-03-11 14:49:06 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2005-06-30 07:49:22 +00:00
|
|
|
struct procfs_status32 {
|
|
|
|
int state; /* Running, stopped, something else? */
|
|
|
|
int flags; /* Any flags */
|
|
|
|
unsigned int events; /* Events to stop on */
|
|
|
|
int why; /* What event, if any, proc stopped on */
|
|
|
|
unsigned int val; /* Any extra data */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PIOCWAIT32 _IOR('p', 4, struct procfs_status32)
|
|
|
|
#define PIOCSTATUS32 _IOR('p', 6, struct procfs_status32)
|
|
|
|
#endif
|
|
|
|
|
2001-12-04 01:35:06 +00:00
|
|
|
/*
|
|
|
|
* Process ioctls
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
procfs_ioctl(PFS_IOCTL_ARGS)
|
|
|
|
{
|
|
|
|
struct procfs_status *ps;
|
2010-03-11 14:49:06 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2005-06-30 07:49:22 +00:00
|
|
|
struct procfs_status32 *ps32;
|
|
|
|
#endif
|
2001-12-09 00:35:30 +00:00
|
|
|
int error, flags, sig;
|
2006-09-27 19:57:02 +00:00
|
|
|
#ifdef COMPAT_FREEBSD6
|
|
|
|
int ival;
|
|
|
|
#endif
|
2001-12-04 01:35:06 +00:00
|
|
|
|
2007-05-01 12:59:20 +00:00
|
|
|
KASSERT(p != NULL,
|
|
|
|
("%s() called without a process", __func__));
|
|
|
|
PROC_LOCK_ASSERT(p, MA_OWNED);
|
|
|
|
|
2001-12-04 01:35:06 +00:00
|
|
|
error = 0;
|
|
|
|
switch (cmd) {
|
2005-06-30 00:19:08 +00:00
|
|
|
#if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
|
|
|
|
case _IOC(IOC_IN, 'p', 1, 0):
|
2006-09-27 19:57:02 +00:00
|
|
|
#endif
|
|
|
|
#ifdef COMPAT_FREEBSD6
|
|
|
|
case _IO('p', 1):
|
|
|
|
ival = IOCPARM_IVAL(data);
|
|
|
|
data = &ival;
|
2005-06-30 00:19:08 +00:00
|
|
|
#endif
|
2001-12-04 01:35:06 +00:00
|
|
|
case PIOCBIS:
|
2006-09-27 19:57:02 +00:00
|
|
|
p->p_stops |= *(unsigned int *)data;
|
2001-12-04 01:35:06 +00:00
|
|
|
break;
|
2005-06-30 00:19:08 +00:00
|
|
|
#if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
|
|
|
|
case _IOC(IOC_IN, 'p', 2, 0):
|
2006-09-27 19:57:02 +00:00
|
|
|
#endif
|
|
|
|
#ifdef COMPAT_FREEBSD6
|
|
|
|
case _IO('p', 2):
|
|
|
|
ival = IOCPARM_IVAL(data);
|
|
|
|
data = &ival;
|
2005-06-30 00:19:08 +00:00
|
|
|
#endif
|
2001-12-04 01:35:06 +00:00
|
|
|
case PIOCBIC:
|
2006-09-27 19:57:02 +00:00
|
|
|
p->p_stops &= ~*(unsigned int *)data;
|
2001-12-04 01:35:06 +00:00
|
|
|
break;
|
2005-06-30 00:19:08 +00:00
|
|
|
#if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
|
|
|
|
case _IOC(IOC_IN, 'p', 3, 0):
|
2006-09-27 19:57:02 +00:00
|
|
|
#endif
|
|
|
|
#ifdef COMPAT_FREEBSD6
|
|
|
|
case _IO('p', 3):
|
|
|
|
ival = IOCPARM_IVAL(data);
|
|
|
|
data = &ival;
|
2005-06-30 00:19:08 +00:00
|
|
|
#endif
|
2001-12-04 01:35:06 +00:00
|
|
|
case PIOCSFL:
|
2006-09-27 19:57:02 +00:00
|
|
|
flags = *(unsigned int *)data;
|
2006-11-06 13:42:10 +00:00
|
|
|
if (flags & PF_ISUGID) {
|
|
|
|
/*
|
|
|
|
* XXXRW: Is this specific check required here, as
|
|
|
|
* p_candebug() should implement it, or other checks
|
|
|
|
* are missing.
|
|
|
|
*/
|
2007-06-12 00:12:01 +00:00
|
|
|
error = priv_check(td, PRIV_DEBUG_SUGID);
|
2006-11-06 13:42:10 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
2001-12-09 00:35:30 +00:00
|
|
|
p->p_pfsflags = flags;
|
2001-12-04 01:35:06 +00:00
|
|
|
break;
|
|
|
|
case PIOCGFL:
|
2001-12-09 00:35:30 +00:00
|
|
|
*(unsigned int *)data = p->p_pfsflags;
|
2001-12-04 01:35:06 +00:00
|
|
|
break;
|
|
|
|
case PIOCWAIT:
|
2006-11-17 14:52:38 +00:00
|
|
|
while (p->p_step == 0 && (p->p_flag & P_WEXIT) == 0) {
|
2001-12-04 01:35:06 +00:00
|
|
|
/* sleep until p stops */
|
2007-05-01 12:59:20 +00:00
|
|
|
_PHOLD(p);
|
2001-12-04 01:35:06 +00:00
|
|
|
error = msleep(&p->p_stype, &p->p_mtx,
|
|
|
|
PWAIT|PCATCH, "pioctl", 0);
|
2007-05-01 12:59:20 +00:00
|
|
|
_PRELE(p);
|
2001-12-04 01:35:06 +00:00
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through to PIOCSTATUS */
|
|
|
|
case PIOCSTATUS:
|
|
|
|
ps = (struct procfs_status *)data;
|
|
|
|
ps->state = (p->p_step == 0);
|
|
|
|
ps->flags = 0; /* nope */
|
|
|
|
ps->events = p->p_stops;
|
|
|
|
ps->why = p->p_step ? p->p_stype : 0;
|
2015-07-18 09:02:50 +00:00
|
|
|
ps->val = p->p_step ? p->p_xsig : 0;
|
2001-12-04 01:35:06 +00:00
|
|
|
break;
|
2010-03-11 14:49:06 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2005-06-30 07:49:22 +00:00
|
|
|
case PIOCWAIT32:
|
2006-11-17 14:52:38 +00:00
|
|
|
while (p->p_step == 0 && (p->p_flag & P_WEXIT) == 0) {
|
2005-06-30 07:49:22 +00:00
|
|
|
/* sleep until p stops */
|
2007-05-01 12:59:20 +00:00
|
|
|
_PHOLD(p);
|
2005-06-30 07:49:22 +00:00
|
|
|
error = msleep(&p->p_stype, &p->p_mtx,
|
|
|
|
PWAIT|PCATCH, "pioctl", 0);
|
2007-05-01 12:59:20 +00:00
|
|
|
_PRELE(p);
|
2005-06-30 07:49:22 +00:00
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through to PIOCSTATUS32 */
|
|
|
|
case PIOCSTATUS32:
|
|
|
|
ps32 = (struct procfs_status32 *)data;
|
|
|
|
ps32->state = (p->p_step == 0);
|
|
|
|
ps32->flags = 0; /* nope */
|
|
|
|
ps32->events = p->p_stops;
|
|
|
|
ps32->why = p->p_step ? p->p_stype : 0;
|
2015-07-18 09:02:50 +00:00
|
|
|
ps32->val = p->p_step ? p->p_xsig : 0;
|
2005-06-30 07:49:22 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2005-06-30 00:19:08 +00:00
|
|
|
#if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
|
|
|
|
case _IOC(IOC_IN, 'p', 5, 0):
|
2006-09-27 19:57:02 +00:00
|
|
|
#endif
|
|
|
|
#ifdef COMPAT_FREEBSD6
|
|
|
|
case _IO('p', 5):
|
|
|
|
ival = IOCPARM_IVAL(data);
|
|
|
|
data = &ival;
|
2005-06-30 00:19:08 +00:00
|
|
|
#endif
|
2001-12-04 01:35:06 +00:00
|
|
|
case PIOCCONT:
|
2001-12-09 00:35:30 +00:00
|
|
|
if (p->p_step == 0)
|
2001-12-04 01:35:06 +00:00
|
|
|
break;
|
2006-09-27 19:57:02 +00:00
|
|
|
sig = *(unsigned int *)data;
|
2001-12-09 00:35:30 +00:00
|
|
|
if (sig != 0 && !_SIG_VALID(sig)) {
|
2001-12-04 01:35:06 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
p->p_step = 0;
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
if (P_SHOULDSTOP(p)) {
|
2015-07-18 09:02:50 +00:00
|
|
|
p->p_xsig = sig;
|
2002-09-05 07:30:18 +00:00
|
|
|
p->p_flag &= ~(P_STOPPED_TRACE|P_STOPPED_SIG);
|
Commit 14/14 of sched_lock decomposition.
- Use thread_lock() rather than sched_lock for per-thread scheduling
sychronization.
- Use the per-process spinlock rather than the sched_lock for per-process
scheduling synchronization.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-05 00:00:57 +00:00
|
|
|
PROC_SLOCK(p);
|
2002-09-11 08:13:56 +00:00
|
|
|
thread_unsuspend(p);
|
Commit 14/14 of sched_lock decomposition.
- Use thread_lock() rather than sched_lock for per-thread scheduling
sychronization.
- Use the per-process spinlock rather than the sched_lock for per-process
scheduling synchronization.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-05 00:00:57 +00:00
|
|
|
PROC_SUNLOCK(p);
|
2003-04-17 22:13:46 +00:00
|
|
|
} else if (sig)
|
2011-09-16 13:58:51 +00:00
|
|
|
kern_psignal(p, sig);
|
2001-12-04 01:35:06 +00:00
|
|
|
#else
|
|
|
|
if (sig)
|
2011-09-16 13:58:51 +00:00
|
|
|
kern_psignal(p, sig);
|
2001-12-09 00:35:30 +00:00
|
|
|
p->p_step = 0;
|
2001-12-04 01:35:06 +00:00
|
|
|
wakeup(&p->p_step);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = (ENOTTY);
|
|
|
|
}
|
2003-12-07 17:40:00 +00:00
|
|
|
|
2001-12-04 01:35:06 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up on last close
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
procfs_close(PFS_CLOSE_ARGS)
|
|
|
|
{
|
|
|
|
if (p != NULL && (p->p_pfsflags & PF_LINGER) == 0) {
|
2003-04-17 22:13:46 +00:00
|
|
|
PROC_LOCK_ASSERT(p, MA_OWNED);
|
2001-12-04 01:35:06 +00:00
|
|
|
p->p_pfsflags = 0;
|
|
|
|
p->p_stops = 0;
|
|
|
|
p->p_step = 0;
|
|
|
|
wakeup(&p->p_step);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|