2005-01-06 18:10:42 +00:00
|
|
|
/*-
|
1994-05-24 10:09:53 +00:00
|
|
|
* Copyright (c) 1993 Jan-Simon Pendry
|
|
|
|
* Copyright (c) 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Jan-Simon Pendry.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
|
|
|
*
|
1997-02-10 02:22:35 +00:00
|
|
|
* @(#)procfs_ctl.c 8.4 (Berkeley) 6/15/94
|
2002-02-16 05:59:26 +00:00
|
|
|
*
|
|
|
|
* From:
|
2004-04-07 20:46:16 +00:00
|
|
|
* $Id: procfs_ctl.c,v 1.51 2003/12/07 17:40:00 des Exp $
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/proc.h>
|
1995-03-16 18:17:34 +00:00
|
|
|
#include <sys/ptrace.h>
|
2001-12-04 01:35:06 +00:00
|
|
|
#include <sys/sbuf.h>
|
1995-03-16 18:17:34 +00:00
|
|
|
#include <sys/signalvar.h>
|
2001-03-28 11:52:56 +00:00
|
|
|
#include <sys/sx.h>
|
2001-12-04 01:35:06 +00:00
|
|
|
#include <sys/uio.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
|
2001-12-04 01:35:06 +00:00
|
|
|
#include <fs/pseudofs/pseudofs.h>
|
2001-05-23 09:42:29 +00:00
|
|
|
#include <fs/procfs/procfs.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1997-02-12 06:52:51 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* True iff process (p) is in trace wait state
|
|
|
|
* relative to process (curp)
|
|
|
|
*/
|
|
|
|
#define TRACE_WAIT_P(curp, p) \
|
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
|
|
|
(P_SHOULDSTOP(p) && \
|
1994-05-24 10:09:53 +00:00
|
|
|
(p)->p_pptr == (curp) && \
|
|
|
|
((p)->p_flag & P_TRACED))
|
|
|
|
|
|
|
|
#define PROCFS_CTL_ATTACH 1
|
|
|
|
#define PROCFS_CTL_DETACH 2
|
|
|
|
#define PROCFS_CTL_STEP 3
|
|
|
|
#define PROCFS_CTL_RUN 4
|
|
|
|
#define PROCFS_CTL_WAIT 5
|
|
|
|
|
2001-12-04 01:35:06 +00:00
|
|
|
struct namemap {
|
|
|
|
const char *nm_name;
|
|
|
|
int nm_val;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct namemap ctlnames[] = {
|
1994-05-24 10:09:53 +00:00
|
|
|
/* special /proc commands */
|
|
|
|
{ "attach", PROCFS_CTL_ATTACH },
|
|
|
|
{ "detach", PROCFS_CTL_DETACH },
|
|
|
|
{ "step", PROCFS_CTL_STEP },
|
|
|
|
{ "run", PROCFS_CTL_RUN },
|
|
|
|
{ "wait", PROCFS_CTL_WAIT },
|
|
|
|
{ 0 },
|
|
|
|
};
|
|
|
|
|
2001-12-04 01:35:06 +00:00
|
|
|
static struct namemap signames[] = {
|
1994-05-24 10:09:53 +00:00
|
|
|
/* regular signal names */
|
|
|
|
{ "hup", SIGHUP }, { "int", SIGINT },
|
|
|
|
{ "quit", SIGQUIT }, { "ill", SIGILL },
|
|
|
|
{ "trap", SIGTRAP }, { "abrt", SIGABRT },
|
|
|
|
{ "iot", SIGIOT }, { "emt", SIGEMT },
|
|
|
|
{ "fpe", SIGFPE }, { "kill", SIGKILL },
|
|
|
|
{ "bus", SIGBUS }, { "segv", SIGSEGV },
|
|
|
|
{ "sys", SIGSYS }, { "pipe", SIGPIPE },
|
|
|
|
{ "alrm", SIGALRM }, { "term", SIGTERM },
|
|
|
|
{ "urg", SIGURG }, { "stop", SIGSTOP },
|
|
|
|
{ "tstp", SIGTSTP }, { "cont", SIGCONT },
|
|
|
|
{ "chld", SIGCHLD }, { "ttin", SIGTTIN },
|
|
|
|
{ "ttou", SIGTTOU }, { "io", SIGIO },
|
|
|
|
{ "xcpu", SIGXCPU }, { "xfsz", SIGXFSZ },
|
|
|
|
{ "vtalrm", SIGVTALRM }, { "prof", SIGPROF },
|
|
|
|
{ "winch", SIGWINCH }, { "info", SIGINFO },
|
|
|
|
{ "usr1", SIGUSR1 }, { "usr2", SIGUSR2 },
|
|
|
|
{ 0 },
|
|
|
|
};
|
|
|
|
|
2002-04-13 23:19:13 +00:00
|
|
|
static int procfs_control(struct thread *td, struct proc *p, int op);
|
1995-12-03 14:54:48 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
static int
|
2002-04-13 23:19:13 +00:00
|
|
|
procfs_control(struct thread *td, struct proc *p, int op)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2001-03-28 11:52:56 +00:00
|
|
|
int error = 0;
|
2010-05-10 15:18:03 +00:00
|
|
|
struct thread *temp;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach - attaches the target process for debugging
|
|
|
|
* by the calling process.
|
|
|
|
*/
|
|
|
|
if (op == PROCFS_CTL_ATTACH) {
|
2001-03-28 11:52:56 +00:00
|
|
|
sx_xlock(&proctree_lock);
|
2001-03-07 03:09:40 +00:00
|
|
|
PROC_LOCK(p);
|
2002-05-19 00:14:50 +00:00
|
|
|
if ((error = p_candebug(td, p)) != 0)
|
2002-04-13 23:19:13 +00:00
|
|
|
goto out;
|
2001-03-07 03:09:40 +00:00
|
|
|
if (p->p_flag & P_TRACED) {
|
2001-03-28 11:52:56 +00:00
|
|
|
error = EBUSY;
|
|
|
|
goto out;
|
2001-03-07 03:09:40 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2001-03-29 18:10:46 +00:00
|
|
|
/* Can't trace yourself! */
|
2002-04-13 23:19:13 +00:00
|
|
|
if (p->p_pid == td->td_proc->p_pid) {
|
2001-03-28 11:52:56 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
2001-03-07 03:09:40 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Go ahead and set the trace flag.
|
|
|
|
* Save the old parent (it's reset in
|
|
|
|
* _DETACH, and also in kern_exit.c:wait4()
|
|
|
|
* Reparent the process so that the tracing
|
|
|
|
* proc gets to see all the action.
|
|
|
|
* Stop the target.
|
|
|
|
*/
|
|
|
|
p->p_flag |= P_TRACED;
|
1995-02-20 15:53:33 +00:00
|
|
|
faultin(p);
|
1994-05-24 10:09:53 +00:00
|
|
|
p->p_xstat = 0; /* XXX ? */
|
2002-04-13 23:19:13 +00:00
|
|
|
if (p->p_pptr != td->td_proc) {
|
1994-05-24 10:09:53 +00:00
|
|
|
p->p_oppid = p->p_pptr->p_pid;
|
2002-04-13 23:19:13 +00:00
|
|
|
proc_reparent(p, td->td_proc);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2011-09-16 13:58:51 +00:00
|
|
|
kern_psignal(p, SIGSTOP);
|
2001-03-29 18:10:46 +00:00
|
|
|
out:
|
2001-03-07 03:09:40 +00:00
|
|
|
PROC_UNLOCK(p);
|
2001-03-28 11:52:56 +00:00
|
|
|
sx_xunlock(&proctree_lock);
|
2001-03-29 18:10:46 +00:00
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-04-13 23:19:13 +00:00
|
|
|
* Authorization check: rely on normal debugging protection, except
|
|
|
|
* allow processes to disengage debugging on a process onto which
|
|
|
|
* they have previously attached, but no longer have permission to
|
|
|
|
* debug.
|
|
|
|
*/
|
|
|
|
PROC_LOCK(p);
|
|
|
|
if (op != PROCFS_CTL_DETACH &&
|
2002-05-19 00:14:50 +00:00
|
|
|
((error = p_candebug(td, p)))) {
|
2002-04-13 23:19:13 +00:00
|
|
|
PROC_UNLOCK(p);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Target process must be stopped, owned by (td) and
|
1994-05-24 10:09:53 +00:00
|
|
|
* be set up for tracing (P_TRACED flag set).
|
|
|
|
* Allow DETACH to take place at any time for sanity.
|
|
|
|
* Allow WAIT any time, of course.
|
|
|
|
*/
|
|
|
|
switch (op) {
|
|
|
|
case PROCFS_CTL_DETACH:
|
|
|
|
case PROCFS_CTL_WAIT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-04-13 23:19:13 +00:00
|
|
|
if (!TRACE_WAIT_P(td->td_proc, p)) {
|
2001-03-07 03:09:40 +00:00
|
|
|
PROC_UNLOCK(p);
|
1994-05-24 10:09:53 +00:00
|
|
|
return (EBUSY);
|
2000-12-02 01:58:15 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1996-01-24 18:41:41 +00:00
|
|
|
|
|
|
|
#ifdef FIX_SSTEP
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* do single-step fixup if needed
|
|
|
|
*/
|
2008-03-12 10:12:01 +00:00
|
|
|
FIX_SSTEP(FIRST_THREAD_IN_PROC(p));
|
1996-01-24 18:41:41 +00:00
|
|
|
#endif
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't deliver any signal by default.
|
|
|
|
* To continue with a signal, just send
|
|
|
|
* the signal name to the ctl file
|
|
|
|
*/
|
|
|
|
p->p_xstat = 0;
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
/*
|
|
|
|
* Detach. Cleans up the target process, reparent it if possible
|
|
|
|
* and set it running once more.
|
|
|
|
*/
|
|
|
|
case PROCFS_CTL_DETACH:
|
|
|
|
/* if not being traced, then this is a painless no-op */
|
2001-03-07 03:09:40 +00:00
|
|
|
if ((p->p_flag & P_TRACED) == 0) {
|
|
|
|
PROC_UNLOCK(p);
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
2001-03-07 03:09:40 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/* not being traced any more */
|
2010-05-10 15:18:03 +00:00
|
|
|
p->p_flag &= ~(P_TRACED | P_STOPPED_TRACE);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1994-12-31 12:26:50 +00:00
|
|
|
/* remove pending SIGTRAP, else the process will die */
|
1. Change prototype of trapsignal and sendsig to use ksiginfo_t *, most
changes in MD code are trivial, before this change, trapsignal and
sendsig use discrete parameters, now they uses member fields of
ksiginfo_t structure. For sendsig, this change allows us to pass
POSIX realtime signal value to user code.
2. Remove cpu_thread_siginfo, it is no longer needed because we now always
generate ksiginfo_t data and feed it to libpthread.
3. Add p_sigqueue to proc structure to hold shared signals which were
blocked by all threads in the proc.
4. Add td_sigqueue to thread structure to hold all signals delivered to
thread.
5. i386 and amd64 now return POSIX standard si_code, other arches will
be fixed.
6. In this sigqueue implementation, pending signal set is kept as before,
an extra siginfo list holds additional siginfo_t data for signals.
kernel code uses psignal() still behavior as before, it won't be failed
even under memory pressure, only exception is when deleting a signal,
we should call sigqueue_delete to remove signal from sigqueue but
not SIGDELSET. Current there is no kernel code will deliver a signal
with additional data, so kernel should be as stable as before,
a ksiginfo can carry more information, for example, allow signal to
be delivered but throw away siginfo data if memory is not enough.
SIGKILL and SIGSTOP have fast path in sigqueue_add, because they can
not be caught or masked.
The sigqueue() syscall allows user code to queue a signal to target
process, if resource is unavailable, EAGAIN will be returned as
specification said.
Just before thread exits, signal queue memory will be freed by
sigqueue_flush.
Current, all signals are allowed to be queued, not only realtime signals.
Earlier patch reviewed by: jhb, deischen
Tested on: i386, amd64
2005-10-14 12:43:47 +00:00
|
|
|
sigqueue_delete_proc(p, SIGTRAP);
|
2010-05-10 15:18:03 +00:00
|
|
|
FOREACH_THREAD_IN_PROC(p, temp)
|
|
|
|
temp->td_dbgflags &= ~TDB_SUSPEND;
|
2001-03-07 03:09:40 +00:00
|
|
|
PROC_UNLOCK(p);
|
1994-12-31 12:26:50 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/* give process back to original parent */
|
2001-03-28 11:52:56 +00:00
|
|
|
sx_xlock(&proctree_lock);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (p->p_oppid != p->p_pptr->p_pid) {
|
|
|
|
struct proc *pp;
|
|
|
|
|
|
|
|
pp = pfind(p->p_oppid);
|
2001-03-07 03:09:40 +00:00
|
|
|
PROC_LOCK(p);
|
2002-02-23 11:12:57 +00:00
|
|
|
if (pp) {
|
|
|
|
PROC_UNLOCK(pp);
|
1994-05-24 10:09:53 +00:00
|
|
|
proc_reparent(p, pp);
|
2002-02-23 11:12:57 +00:00
|
|
|
}
|
2001-03-07 03:09:40 +00:00
|
|
|
} else
|
|
|
|
PROC_LOCK(p);
|
1994-05-24 10:09:53 +00:00
|
|
|
p->p_oppid = 0;
|
|
|
|
p->p_flag &= ~P_WAITED; /* XXX ? */
|
2001-03-28 11:52:56 +00:00
|
|
|
sx_xunlock(&proctree_lock);
|
2001-03-07 03:09:40 +00:00
|
|
|
|
2003-03-02 15:13:06 +00:00
|
|
|
wakeup(td->td_proc); /* XXX for CTL_WAIT below ? */
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Step. Let the target process execute a single instruction.
|
2003-12-07 17:40:00 +00:00
|
|
|
* What does it mean to single step a threaded program?
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
case PROCFS_CTL_STEP:
|
2008-03-12 10:12:01 +00:00
|
|
|
error = proc_sstep(FIRST_THREAD_IN_PROC(p));
|
2010-05-10 15:19:12 +00:00
|
|
|
if (error) {
|
|
|
|
PROC_UNLOCK(p);
|
1997-02-10 02:22:35 +00:00
|
|
|
return (error);
|
2010-05-10 15:19:12 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run. Let the target process continue running until a breakpoint
|
|
|
|
* or some other trap.
|
|
|
|
*/
|
|
|
|
case PROCFS_CTL_RUN:
|
2002-09-05 07:30:18 +00:00
|
|
|
p->p_flag &= ~P_STOPPED_SIG; /* this uses SIGSTOP */
|
1994-05-24 10:09:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the target process to stop.
|
|
|
|
* If the target is not being traced then just wait
|
|
|
|
* to enter
|
|
|
|
*/
|
|
|
|
case PROCFS_CTL_WAIT:
|
|
|
|
if (p->p_flag & P_TRACED) {
|
|
|
|
while (error == 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
|
|
|
(P_SHOULDSTOP(p)) &&
|
1994-05-24 10:09:53 +00:00
|
|
|
(p->p_flag & P_TRACED) &&
|
2002-04-13 23:19:13 +00:00
|
|
|
(p->p_pptr == td->td_proc))
|
2003-03-02 15:13:06 +00:00
|
|
|
error = msleep(p, &p->p_mtx,
|
1994-05-24 10:09:53 +00:00
|
|
|
PWAIT|PCATCH, "procfsx", 0);
|
2002-04-13 23:19:13 +00:00
|
|
|
if (error == 0 && !TRACE_WAIT_P(td->td_proc, p))
|
1994-05-24 10:09:53 +00:00
|
|
|
error = EBUSY;
|
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
|
|
|
} else {
|
|
|
|
while (error == 0 && P_SHOULDSTOP(p))
|
2003-03-02 15:13:06 +00:00
|
|
|
error = msleep(p, &p->p_mtx,
|
1994-05-24 10:09:53 +00:00
|
|
|
PWAIT|PCATCH, "procfs", 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
|
|
|
}
|
2002-04-13 23:19:13 +00:00
|
|
|
PROC_UNLOCK(p);
|
1994-05-24 10:09:53 +00:00
|
|
|
return (error);
|
|
|
|
default:
|
|
|
|
panic("procfs_control");
|
|
|
|
}
|
|
|
|
|
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);
|
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
|
|
|
thread_unsuspend(p); /* If it can run, let it do so. */
|
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);
|
2010-05-10 15:19:12 +00:00
|
|
|
PROC_UNLOCK(p);
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-12-04 01:35:06 +00:00
|
|
|
static struct namemap *
|
|
|
|
findname(struct namemap *nm, char *buf, int buflen)
|
|
|
|
{
|
|
|
|
|
|
|
|
for (; nm->nm_name; nm++)
|
|
|
|
if (bcmp(buf, nm->nm_name, buflen+1) == 0)
|
|
|
|
return (nm);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
int
|
2001-12-04 01:35:06 +00:00
|
|
|
procfs_doprocctl(PFS_FILL_ARGS)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
int error;
|
2001-12-04 01:35:06 +00:00
|
|
|
struct namemap *nm;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2001-12-04 01:35:06 +00:00
|
|
|
if (uio == NULL || uio->uio_rw != UIO_WRITE)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map signal names into signal generation
|
|
|
|
* or debug control. Unknown commands and/or signals
|
|
|
|
* return EOPNOTSUPP.
|
|
|
|
*
|
|
|
|
* Sending a signal while the process is being debugged
|
|
|
|
* also has the side effect of letting the target continue
|
|
|
|
* to run. There is no way to single-step a signal delivery.
|
|
|
|
*/
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
|
2001-12-04 01:35:06 +00:00
|
|
|
sbuf_trim(sb);
|
|
|
|
sbuf_finish(sb);
|
|
|
|
nm = findname(ctlnames, sbuf_data(sb), sbuf_len(sb));
|
1994-05-24 10:09:53 +00:00
|
|
|
if (nm) {
|
2001-12-04 01:35:06 +00:00
|
|
|
printf("procfs: got a %s command\n", sbuf_data(sb));
|
2002-04-13 23:19:13 +00:00
|
|
|
error = procfs_control(td, p, nm->nm_val);
|
1994-05-24 10:09:53 +00:00
|
|
|
} else {
|
2001-12-04 01:35:06 +00:00
|
|
|
nm = findname(signames, sbuf_data(sb), sbuf_len(sb));
|
1994-05-24 10:09:53 +00:00
|
|
|
if (nm) {
|
2001-12-04 01:35:06 +00:00
|
|
|
printf("procfs: got a sig%s\n", sbuf_data(sb));
|
2001-03-07 03:09:40 +00:00
|
|
|
PROC_LOCK(p);
|
2002-02-07 20:58:47 +00:00
|
|
|
|
2001-12-04 01:35:06 +00:00
|
|
|
if (TRACE_WAIT_P(td->td_proc, p)) {
|
1994-05-24 10:09:53 +00:00
|
|
|
p->p_xstat = nm->nm_val;
|
1996-01-24 18:41:41 +00:00
|
|
|
#ifdef FIX_SSTEP
|
2002-02-16 05:59:26 +00:00
|
|
|
FIX_SSTEP(FIRST_THREAD_IN_PROC(p));
|
1996-01-24 18:41:41 +00:00
|
|
|
#endif
|
2002-09-05 07:30:18 +00:00
|
|
|
p->p_flag &= ~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);
|
2002-04-13 23:19:13 +00:00
|
|
|
} else
|
2011-09-16 13:58:51 +00:00
|
|
|
kern_psignal(p, nm->nm_val);
|
2001-03-07 03:09:40 +00:00
|
|
|
PROC_UNLOCK(p);
|
1994-05-24 10:09:53 +00:00
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|