Lock the procfs functions for doing a single step and reading/writing

registers better.  Hold sched_lock not only for checking the flag but
also while performing the actual operation to ensure the process doesn't
get swapped out by another CPU while we the operation is being performed.
This commit is contained in:
John Baldwin 2001-05-16 00:47:27 +00:00
parent 3dce60fd35
commit f0ba29575d
4 changed files with 67 additions and 132 deletions

View File

@ -81,19 +81,25 @@
#include <vm/pmap.h>
#include <vm/vm_map.h>
#define PROCFS_ACTION(action) do { \
int error; \
\
mtx_lock_spin(&sched_lock); \
if ((p->p_sflag & PS_INMEM) == 0) \
error = EIO; \
else \
error = (action); \
mtx_unlock_spin(&sched_lock); \
return (error); \
} while(0)
int
procfs_read_regs(p, regs)
struct proc *p;
struct reg *regs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (fill_regs(p, regs));
PROCFS_ACTION(fill_regs(p, regs));
}
int
@ -102,13 +108,7 @@ procfs_write_regs(p, regs)
struct reg *regs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (set_regs(p, regs));
PROCFS_ACTION(set_regs(p, regs));
}
/*
@ -122,13 +122,7 @@ procfs_read_fpregs(p, fpregs)
struct fpreg *fpregs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (fill_fpregs(p, fpregs));
PROCFS_ACTION(fill_fpregs(p, fpregs));
}
int
@ -137,13 +131,7 @@ procfs_write_fpregs(p, fpregs)
struct fpreg *fpregs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (set_fpregs(p, fpregs));
PROCFS_ACTION(set_fpregs(p, fpregs));
}
int

View File

@ -83,19 +83,25 @@
#include <vm/pmap.h>
#include <vm/vm_map.h>
#define PROCFS_ACTION(action) do { \
int error; \
\
mtx_lock_spin(&sched_lock); \
if ((p->p_sflag & PS_INMEM) == 0) \
error = EIO; \
else \
error = (action); \
mtx_unlock_spin(&sched_lock); \
return (error); \
} while(0)
int
procfs_read_regs(p, regs)
struct proc *p;
struct reg *regs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (fill_regs(p, regs));
PROCFS_ACTION(fill_regs(p, regs));
}
int
@ -104,13 +110,7 @@ procfs_write_regs(p, regs)
struct reg *regs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (set_regs(p, regs));
PROCFS_ACTION(set_regs(p, regs));
}
int
@ -119,13 +119,7 @@ procfs_read_dbregs(p, dbregs)
struct dbreg *dbregs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (fill_dbregs(p, dbregs));
PROCFS_ACTION(fill_dbregs(p, dbregs));
}
int
@ -134,13 +128,7 @@ procfs_write_dbregs(p, dbregs)
struct dbreg *dbregs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (set_dbregs(p, dbregs));
PROCFS_ACTION(set_dbregs(p, dbregs));
}
/*
@ -154,13 +142,7 @@ procfs_read_fpregs(p, fpregs)
struct fpreg *fpregs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (fill_fpregs(p, fpregs));
PROCFS_ACTION(fill_fpregs(p, fpregs));
}
int
@ -169,13 +151,7 @@ procfs_write_fpregs(p, fpregs)
struct fpreg *fpregs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (set_fpregs(p, fpregs));
PROCFS_ACTION(set_fpregs(p, fpregs));
}
int
@ -183,11 +159,5 @@ procfs_sstep(p)
struct proc *p;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (ptrace_single_step(p));
PROCFS_ACTION(ptrace_single_step(p));
}

View File

@ -81,19 +81,25 @@
#include <sys/user.h>
#define PROCFS_ACTION(action) do { \
int error; \
\
mtx_lock_spin(&sched_lock); \
if ((p->p_sflag & PS_INMEM) == 0) \
error = EIO; \
else \
error = (action); \
mtx_unlock_spin(&sched_lock); \
return (error); \
} while(0)
int
procfs_read_regs(p, regs)
struct proc *p;
struct reg *regs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (fill_regs(p, regs));
PROCFS_ACTION(fill_regs(p, regs));
}
int
@ -102,13 +108,7 @@ procfs_write_regs(p, regs)
struct reg *regs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (set_regs(p, regs));
PROCFS_ACTION(set_regs(p, regs));
}
/*
@ -122,12 +122,7 @@ procfs_read_fpregs(p, fpregs)
struct fpreg *fpregs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
return (fill_fpregs(p, fpregs));
PROCFS_ACTION(fill_fpregs(p, fpregs));
}
int
@ -136,13 +131,7 @@ procfs_write_fpregs(p, fpregs)
struct fpreg *fpregs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (set_fpregs(p, fpregs));
PROCFS_ACTION(set_fpregs(p, fpregs));
}
int

View File

@ -81,19 +81,25 @@
#include <vm/pmap.h>
#include <vm/vm_map.h>
#define PROCFS_ACTION(action) do { \
int error; \
\
mtx_lock_spin(&sched_lock); \
if ((p->p_sflag & PS_INMEM) == 0) \
error = EIO; \
else \
error = (action); \
mtx_unlock_spin(&sched_lock); \
return (error); \
} while(0)
int
procfs_read_regs(p, regs)
struct proc *p;
struct reg *regs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (fill_regs(p, regs));
PROCFS_ACTION(fill_regs(p, regs));
}
int
@ -102,13 +108,7 @@ procfs_write_regs(p, regs)
struct reg *regs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (set_regs(p, regs));
PROCFS_ACTION(set_regs(p, regs));
}
/*
@ -122,13 +122,7 @@ procfs_read_fpregs(p, fpregs)
struct fpreg *fpregs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (fill_fpregs(p, fpregs));
PROCFS_ACTION(fill_fpregs(p, fpregs));
}
int
@ -137,13 +131,7 @@ procfs_write_fpregs(p, fpregs)
struct fpreg *fpregs;
{
mtx_lock_spin(&sched_lock);
if ((p->p_sflag & PS_INMEM) == 0) {
mtx_unlock_spin(&sched_lock);
return (EIO);
}
mtx_unlock_spin(&sched_lock);
return (set_fpregs(p, fpregs));
PROCFS_ACTION(set_fpregs(p, fpregs));
}
int