1994-08-08 13:00:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994, Sean Eric Fagan
|
|
|
|
* All rights reserved.
|
1994-05-24 10:09:53 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1994-08-08 13:00:27 +00:00
|
|
|
* This product includes software developed by Sean Eric Fagan.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
1994-05-24 10:09:53 +00:00
|
|
|
*
|
1994-08-08 13:00:27 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
1994-05-24 10:09:53 +00:00
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
1994-08-08 13:00:27 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
1994-05-24 10:09:53 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/param.h>
|
1994-08-18 22:36:09 +00:00
|
|
|
#include <sys/systm.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2002-09-05 01:02:50 +00:00
|
|
|
#include <sys/syscallsubr.h>
|
1995-11-12 06:43:28 +00:00
|
|
|
#include <sys/sysproto.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/proc.h>
|
1994-08-08 13:00:27 +00:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/ptrace.h>
|
2001-03-28 11:52:56 +00:00
|
|
|
#include <sys/sx.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/user.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
#include <machine/reg.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
#include <vm/vm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/pmap.h>
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
#include <vm/vm_extern.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_map.h>
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
#include <vm/vm_kern.h>
|
|
|
|
#include <vm/vm_object.h>
|
1994-08-08 13:00:27 +00:00
|
|
|
#include <vm/vm_page.h>
|
|
|
|
|
2002-02-21 04:37:55 +00:00
|
|
|
/*
|
|
|
|
* Functions implemented using PROC_ACTION():
|
|
|
|
*
|
|
|
|
* proc_read_regs(proc, regs)
|
|
|
|
* Get the current user-visible register set from the process
|
|
|
|
* and copy it into the regs structure (<machine/reg.h>).
|
|
|
|
* The process is stopped at the time read_regs is called.
|
|
|
|
*
|
|
|
|
* proc_write_regs(proc, regs)
|
|
|
|
* Update the current register set from the passed in regs
|
|
|
|
* structure. Take care to avoid clobbering special CPU
|
|
|
|
* registers or privileged bits in the PSL.
|
|
|
|
* Depending on the architecture this may have fix-up work to do,
|
|
|
|
* especially if the IAR or PCW are modified.
|
|
|
|
* The process is stopped at the time write_regs is called.
|
|
|
|
*
|
|
|
|
* proc_read_fpregs, proc_write_fpregs
|
|
|
|
* deal with the floating point register set, otherwise as above.
|
|
|
|
*
|
|
|
|
* proc_read_dbregs, proc_write_dbregs
|
|
|
|
* deal with the processor debug register set, otherwise as above.
|
|
|
|
*
|
|
|
|
* proc_sstep(proc)
|
|
|
|
* Arrange for the process to trap after executing a single instruction.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define PROC_ACTION(action) do { \
|
2001-10-21 23:57:24 +00:00
|
|
|
int error; \
|
|
|
|
\
|
2003-04-22 20:01:56 +00:00
|
|
|
PROC_LOCK_ASSERT(td->td_proc, MA_OWNED); \
|
2002-02-21 04:37:55 +00:00
|
|
|
if ((td->td_proc->p_sflag & PS_INMEM) == 0) \
|
|
|
|
error = EIO; \
|
|
|
|
else \
|
|
|
|
error = (action); \
|
2001-10-21 23:57:24 +00:00
|
|
|
return (error); \
|
2002-02-21 04:37:55 +00:00
|
|
|
} while(0)
|
2003-03-19 00:33:38 +00:00
|
|
|
|
2002-02-21 04:37:55 +00:00
|
|
|
int
|
|
|
|
proc_read_regs(struct thread *td, struct reg *regs)
|
|
|
|
{
|
|
|
|
|
|
|
|
PROC_ACTION(fill_regs(td, regs));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
proc_write_regs(struct thread *td, struct reg *regs)
|
|
|
|
{
|
|
|
|
|
|
|
|
PROC_ACTION(set_regs(td, regs));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
proc_read_dbregs(struct thread *td, struct dbreg *dbregs)
|
|
|
|
{
|
|
|
|
|
|
|
|
PROC_ACTION(fill_dbregs(td, dbregs));
|
2001-10-21 23:57:24 +00:00
|
|
|
}
|
|
|
|
|
2002-02-21 04:37:55 +00:00
|
|
|
int
|
|
|
|
proc_write_dbregs(struct thread *td, struct dbreg *dbregs)
|
|
|
|
{
|
|
|
|
|
|
|
|
PROC_ACTION(set_dbregs(td, dbregs));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ptrace doesn't support fpregs at all, and there are no security holes
|
|
|
|
* or translations for fpregs, so we can just copy them.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
proc_read_fpregs(struct thread *td, struct fpreg *fpregs)
|
|
|
|
{
|
|
|
|
|
|
|
|
PROC_ACTION(fill_fpregs(td, fpregs));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
proc_write_fpregs(struct thread *td, struct fpreg *fpregs)
|
|
|
|
{
|
|
|
|
|
|
|
|
PROC_ACTION(set_fpregs(td, fpregs));
|
|
|
|
}
|
2001-10-21 23:57:24 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
proc_sstep(struct thread *td)
|
|
|
|
{
|
|
|
|
|
2002-02-21 04:37:55 +00:00
|
|
|
PROC_ACTION(ptrace_single_step(td));
|
2001-10-21 23:57:24 +00:00
|
|
|
}
|
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
int
|
|
|
|
proc_rwmem(struct proc *p, struct uio *uio)
|
2001-10-04 16:35:44 +00:00
|
|
|
{
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
struct vmspace *vm;
|
|
|
|
vm_map_t map;
|
2003-06-11 06:43:48 +00:00
|
|
|
vm_object_t backing_object, object = NULL;
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
vm_offset_t pageno = 0; /* page number */
|
|
|
|
vm_prot_t reqprot;
|
|
|
|
vm_offset_t kva;
|
2002-02-21 04:47:38 +00:00
|
|
|
int error, writing;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
GIANT_REQUIRED;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
/*
|
|
|
|
* if the vmspace is in the midst of being deallocated or the
|
|
|
|
* process is exiting, don't try to grab anything. The page table
|
|
|
|
* usage in that process can be messed up.
|
|
|
|
*/
|
|
|
|
vm = p->p_vmspace;
|
|
|
|
if ((p->p_flag & P_WEXIT))
|
|
|
|
return (EFAULT);
|
|
|
|
if (vm->vm_refcnt < 1)
|
|
|
|
return (EFAULT);
|
|
|
|
++vm->vm_refcnt;
|
|
|
|
/*
|
|
|
|
* The map we want...
|
|
|
|
*/
|
|
|
|
map = &vm->vm_map;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
writing = uio->uio_rw == UIO_WRITE;
|
|
|
|
reqprot = writing ? (VM_PROT_WRITE | VM_PROT_OVERRIDE_WRITE) :
|
|
|
|
VM_PROT_READ;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
kva = kmem_alloc_pageable(kernel_map, PAGE_SIZE);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
/*
|
|
|
|
* Only map in one page at a time. We don't have to, but it
|
|
|
|
* makes things easier. This way is trivial - right?
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
vm_map_t tmap;
|
|
|
|
vm_offset_t uva;
|
|
|
|
int page_offset; /* offset into page */
|
|
|
|
vm_map_entry_t out_entry;
|
|
|
|
vm_prot_t out_prot;
|
|
|
|
boolean_t wired;
|
|
|
|
vm_pindex_t pindex;
|
|
|
|
u_int len;
|
|
|
|
vm_page_t m;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
object = NULL;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
uva = (vm_offset_t)uio->uio_offset;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
/*
|
|
|
|
* Get the page number of this segment.
|
|
|
|
*/
|
|
|
|
pageno = trunc_page(uva);
|
|
|
|
page_offset = uva - pageno;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
/*
|
|
|
|
* How many bytes to copy
|
|
|
|
*/
|
|
|
|
len = min(PAGE_SIZE - page_offset, uio->uio_resid);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fault the page on behalf of the process
|
|
|
|
*/
|
|
|
|
error = vm_fault(map, pageno, reqprot, VM_FAULT_NORMAL);
|
|
|
|
if (error) {
|
|
|
|
error = EFAULT;
|
|
|
|
break;
|
1994-08-08 13:00:27 +00:00
|
|
|
}
|
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
/*
|
|
|
|
* Now we need to get the page. out_entry, out_prot, wired,
|
|
|
|
* and single_use aren't used. One would think the vm code
|
|
|
|
* would be a *bit* nicer... We use tmap because
|
|
|
|
* vm_map_lookup() can change the map argument.
|
|
|
|
*/
|
|
|
|
tmap = map;
|
|
|
|
error = vm_map_lookup(&tmap, pageno, reqprot, &out_entry,
|
|
|
|
&object, &pindex, &out_prot, &wired);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
if (error) {
|
|
|
|
error = EFAULT;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that there is no residue in 'object' from
|
|
|
|
* an error return on vm_map_lookup.
|
|
|
|
*/
|
|
|
|
object = NULL;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-06-11 06:43:48 +00:00
|
|
|
VM_OBJECT_LOCK(object);
|
|
|
|
while ((m = vm_page_lookup(object, pindex)) == NULL &&
|
|
|
|
!writing &&
|
|
|
|
(backing_object = object->backing_object) != NULL) {
|
|
|
|
/*
|
|
|
|
* Allow fallback to backing objects if we are reading.
|
|
|
|
*/
|
|
|
|
VM_OBJECT_LOCK(backing_object);
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
pindex += OFF_TO_IDX(object->backing_object_offset);
|
2003-06-11 06:43:48 +00:00
|
|
|
VM_OBJECT_UNLOCK(object);
|
|
|
|
object = backing_object;
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
}
|
2003-06-11 06:43:48 +00:00
|
|
|
VM_OBJECT_UNLOCK(object);
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
if (m == NULL) {
|
|
|
|
error = EFAULT;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that there is no residue in 'object' from
|
|
|
|
* an error return on vm_map_lookup.
|
|
|
|
*/
|
|
|
|
object = NULL;
|
|
|
|
|
|
|
|
vm_map_lookup_done(tmap, out_entry);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
1994-08-08 13:00:27 +00:00
|
|
|
|
|
|
|
/*
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
* Wire the page into memory
|
1994-08-08 13:00:27 +00:00
|
|
|
*/
|
2002-07-12 17:21:22 +00:00
|
|
|
vm_page_lock_queues();
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
vm_page_wire(m);
|
2002-07-12 17:21:22 +00:00
|
|
|
vm_page_unlock_queues();
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
/*
|
|
|
|
* We're done with tmap now.
|
|
|
|
* But reference the object first, so that we won't loose
|
|
|
|
* it.
|
|
|
|
*/
|
|
|
|
vm_object_reference(object);
|
|
|
|
vm_map_lookup_done(tmap, out_entry);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
2002-03-17 00:56:41 +00:00
|
|
|
pmap_qenter(kva, &m, 1);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
/*
|
|
|
|
* Now do the i/o move.
|
|
|
|
*/
|
|
|
|
error = uiomove((caddr_t)(kva + page_offset), len, uio);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
2002-03-17 00:56:41 +00:00
|
|
|
pmap_qremove(kva, 1);
|
1995-05-30 08:16:23 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
/*
|
|
|
|
* release the page and the object
|
|
|
|
*/
|
2002-07-12 17:21:22 +00:00
|
|
|
vm_page_lock_queues();
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
vm_page_unwire(m, 1);
|
2002-07-12 17:21:22 +00:00
|
|
|
vm_page_unlock_queues();
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
vm_object_deallocate(object);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
object = NULL;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
} while (error == 0 && uio->uio_resid > 0);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
if (object)
|
|
|
|
vm_object_deallocate(object);
|
1995-05-30 08:16:23 +00:00
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
kmem_free(kernel_map, kva, PAGE_SIZE);
|
|
|
|
vmspace_free(vm);
|
|
|
|
return (error);
|
1994-08-08 13:00:27 +00:00
|
|
|
}
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Process debugging system call.
|
|
|
|
*/
|
1995-11-12 06:43:28 +00:00
|
|
|
#ifndef _SYS_SYSPROTO_H_
|
1994-05-24 10:09:53 +00:00
|
|
|
struct ptrace_args {
|
|
|
|
int req;
|
|
|
|
pid_t pid;
|
|
|
|
caddr_t addr;
|
|
|
|
int data;
|
|
|
|
};
|
1995-11-12 06:43:28 +00:00
|
|
|
#endif
|
1994-08-08 13:00:27 +00:00
|
|
|
|
2003-04-25 20:02:16 +00:00
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
ptrace(struct thread *td, struct ptrace_args *uap)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2002-02-21 04:47:38 +00:00
|
|
|
/*
|
|
|
|
* XXX this obfuscation is to reduce stack usage, but the register
|
|
|
|
* structs may be too large to put on the stack anyway.
|
|
|
|
*/
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
union {
|
2002-03-16 02:40:02 +00:00
|
|
|
struct ptrace_io_desc piod;
|
2002-02-21 04:47:38 +00:00
|
|
|
struct dbreg dbreg;
|
|
|
|
struct fpreg fpreg;
|
|
|
|
struct reg reg;
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
} r;
|
2002-09-05 01:02:50 +00:00
|
|
|
void *addr;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
addr = &r;
|
|
|
|
switch (uap->req) {
|
|
|
|
case PT_GETREGS:
|
|
|
|
case PT_GETFPREGS:
|
|
|
|
case PT_GETDBREGS:
|
|
|
|
break;
|
|
|
|
case PT_SETREGS:
|
|
|
|
error = copyin(uap->addr, &r.reg, sizeof r.reg);
|
|
|
|
break;
|
|
|
|
case PT_SETFPREGS:
|
|
|
|
error = copyin(uap->addr, &r.fpreg, sizeof r.fpreg);
|
|
|
|
break;
|
|
|
|
case PT_SETDBREGS:
|
|
|
|
error = copyin(uap->addr, &r.dbreg, sizeof r.dbreg);
|
|
|
|
break;
|
|
|
|
case PT_IO:
|
|
|
|
error = copyin(uap->addr, &r.piod, sizeof r.piod);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
addr = uap->addr;
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
error = kern_ptrace(td, uap->req, uap->pid, addr, uap->data);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
switch (uap->req) {
|
|
|
|
case PT_IO:
|
|
|
|
(void)copyout(&r.piod, uap->addr, sizeof r.piod);
|
|
|
|
break;
|
|
|
|
case PT_GETREGS:
|
|
|
|
error = copyout(&r.reg, uap->addr, sizeof r.reg);
|
|
|
|
break;
|
|
|
|
case PT_GETFPREGS:
|
|
|
|
error = copyout(&r.fpreg, uap->addr, sizeof r.fpreg);
|
|
|
|
break;
|
|
|
|
case PT_GETDBREGS:
|
|
|
|
error = copyout(&r.dbreg, uap->addr, sizeof r.dbreg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
|
|
|
|
{
|
|
|
|
struct iovec iov;
|
|
|
|
struct uio uio;
|
2002-04-14 17:12:55 +00:00
|
|
|
struct proc *curp, *p, *pp;
|
2002-02-21 04:47:38 +00:00
|
|
|
struct thread *td2;
|
2002-09-05 01:02:50 +00:00
|
|
|
struct ptrace_io_desc *piod;
|
2002-07-12 16:48:05 +00:00
|
|
|
int error, write, tmp;
|
2002-04-12 21:17:37 +00:00
|
|
|
int proctree_locked = 0;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
2002-04-14 17:12:55 +00:00
|
|
|
curp = td->td_proc;
|
|
|
|
|
2002-09-05 01:02:50 +00:00
|
|
|
/* Lock proctree before locking the process. */
|
|
|
|
switch (req) {
|
2002-04-12 21:17:37 +00:00
|
|
|
case PT_TRACE_ME:
|
|
|
|
case PT_ATTACH:
|
|
|
|
case PT_STEP:
|
|
|
|
case PT_CONTINUE:
|
|
|
|
case PT_DETACH:
|
|
|
|
sx_xlock(&proctree_lock);
|
|
|
|
proctree_locked = 1;
|
|
|
|
break;
|
|
|
|
default:
|
2002-04-20 21:56:42 +00:00
|
|
|
break;
|
2002-04-12 21:17:37 +00:00
|
|
|
}
|
2003-03-19 00:33:38 +00:00
|
|
|
|
1999-07-01 22:52:40 +00:00
|
|
|
write = 0;
|
2002-09-05 01:02:50 +00:00
|
|
|
if (req == PT_TRACE_ME) {
|
2002-04-12 21:17:37 +00:00
|
|
|
p = td->td_proc;
|
2001-04-24 00:51:53 +00:00
|
|
|
PROC_LOCK(p);
|
|
|
|
} else {
|
2002-09-05 01:02:50 +00:00
|
|
|
if ((p = pfind(pid)) == NULL) {
|
2002-04-12 21:17:37 +00:00
|
|
|
if (proctree_locked)
|
|
|
|
sx_xunlock(&proctree_lock);
|
2001-10-04 16:09:22 +00:00
|
|
|
return (ESRCH);
|
2002-04-12 21:17:37 +00:00
|
|
|
}
|
1994-08-08 13:00:27 +00:00
|
|
|
}
|
2002-07-20 22:44:39 +00:00
|
|
|
if ((error = p_cansee(td, p)) != 0)
|
2002-04-12 21:17:37 +00:00
|
|
|
goto fail;
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
|
2002-05-19 00:14:50 +00:00
|
|
|
if ((error = p_candebug(td, p)) != 0)
|
2002-04-12 21:17:37 +00:00
|
|
|
goto fail;
|
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
/*
|
2002-02-21 04:47:38 +00:00
|
|
|
* System processes can't be debugged.
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
*/
|
|
|
|
if ((p->p_flag & P_SYSTEM) != 0) {
|
2002-04-12 21:17:37 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto fail;
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
}
|
2003-03-19 00:33:38 +00:00
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
/*
|
|
|
|
* Permissions check
|
|
|
|
*/
|
2002-09-05 01:02:50 +00:00
|
|
|
switch (req) {
|
1996-01-24 18:29:00 +00:00
|
|
|
case PT_TRACE_ME:
|
|
|
|
/* Always legal. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PT_ATTACH:
|
|
|
|
/* Self */
|
2002-04-12 21:17:37 +00:00
|
|
|
if (p->p_pid == td->td_proc->p_pid) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto fail;
|
2001-04-24 00:51:53 +00:00
|
|
|
}
|
1996-01-24 18:29:00 +00:00
|
|
|
|
|
|
|
/* Already traced */
|
2001-03-07 03:06:18 +00:00
|
|
|
if (p->p_flag & P_TRACED) {
|
2002-04-12 21:17:37 +00:00
|
|
|
error = EBUSY;
|
|
|
|
goto fail;
|
2001-03-07 03:06:18 +00:00
|
|
|
}
|
1996-01-24 18:29:00 +00:00
|
|
|
|
2002-04-14 17:12:55 +00:00
|
|
|
/* Can't trace an ancestor if you're being traced. */
|
|
|
|
if (curp->p_flag & P_TRACED) {
|
|
|
|
for (pp = curp->p_pptr; pp != NULL; pp = pp->p_pptr) {
|
|
|
|
if (pp == p) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
/* OK */
|
|
|
|
break;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
case PT_READ_I:
|
|
|
|
case PT_READ_D:
|
|
|
|
case PT_WRITE_I:
|
|
|
|
case PT_WRITE_D:
|
2002-03-16 02:40:02 +00:00
|
|
|
case PT_IO:
|
1996-01-24 18:29:00 +00:00
|
|
|
case PT_CONTINUE:
|
|
|
|
case PT_KILL:
|
|
|
|
case PT_STEP:
|
|
|
|
case PT_DETACH:
|
|
|
|
case PT_GETREGS:
|
|
|
|
case PT_SETREGS:
|
|
|
|
case PT_GETFPREGS:
|
|
|
|
case PT_SETFPREGS:
|
1999-07-09 04:16:00 +00:00
|
|
|
case PT_GETDBREGS:
|
|
|
|
case PT_SETDBREGS:
|
1996-01-24 18:29:00 +00:00
|
|
|
/* not being traced... */
|
2001-03-07 03:06:18 +00:00
|
|
|
if ((p->p_flag & P_TRACED) == 0) {
|
2002-04-12 21:17:37 +00:00
|
|
|
error = EPERM;
|
|
|
|
goto fail;
|
2001-03-07 03:06:18 +00:00
|
|
|
}
|
1996-01-24 18:29:00 +00:00
|
|
|
|
|
|
|
/* not being traced by YOU */
|
2002-04-12 21:17:37 +00:00
|
|
|
if (p->p_pptr != td->td_proc) {
|
|
|
|
error = EBUSY;
|
|
|
|
goto fail;
|
2000-12-23 19:43:10 +00:00
|
|
|
}
|
1996-01-24 18:29:00 +00:00
|
|
|
|
|
|
|
/* not currently stopped */
|
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) || (p->p_flag & P_WAITED) == 0) {
|
2002-04-12 21:17:37 +00:00
|
|
|
error = EBUSY;
|
|
|
|
goto fail;
|
2000-12-02 01:32:51 +00:00
|
|
|
}
|
1996-01-24 18:29:00 +00:00
|
|
|
|
|
|
|
/* OK */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-04-12 21:17:37 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto fail;
|
1994-08-08 13:00:27 +00:00
|
|
|
}
|
1996-01-24 18:29:00 +00:00
|
|
|
|
2002-02-08 08:56:01 +00:00
|
|
|
td2 = FIRST_THREAD_IN_PROC(p);
|
1996-01-24 18:29:00 +00:00
|
|
|
#ifdef FIX_SSTEP
|
|
|
|
/*
|
|
|
|
* Single step fixup ala procfs
|
|
|
|
*/
|
2002-02-21 04:47:38 +00:00
|
|
|
FIX_SSTEP(td2); /* XXXKSE */
|
1994-08-08 13:00:27 +00:00
|
|
|
#endif
|
1996-01-24 18:29:00 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
1996-01-24 18:29:00 +00:00
|
|
|
* Actually do the requests
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1994-08-08 13:00:27 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
td->td_retval[0] = 0;
|
1994-08-08 13:00:27 +00:00
|
|
|
|
2002-09-05 01:02:50 +00:00
|
|
|
switch (req) {
|
1996-01-24 18:29:00 +00:00
|
|
|
case PT_TRACE_ME:
|
|
|
|
/* set my trace flag and "owner" so it can read/write me */
|
1994-08-08 13:00:27 +00:00
|
|
|
p->p_flag |= P_TRACED;
|
1996-01-24 18:29:00 +00:00
|
|
|
p->p_oppid = p->p_pptr->p_pid;
|
2001-03-07 03:06:18 +00:00
|
|
|
PROC_UNLOCK(p);
|
2001-03-28 11:52:56 +00:00
|
|
|
sx_xunlock(&proctree_lock);
|
2001-10-04 16:09:22 +00:00
|
|
|
return (0);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
case PT_ATTACH:
|
|
|
|
/* security check done above */
|
2001-03-07 03:06:18 +00:00
|
|
|
p->p_flag |= P_TRACED;
|
1996-01-24 18:29:00 +00:00
|
|
|
p->p_oppid = p->p_pptr->p_pid;
|
2002-04-12 21:17:37 +00:00
|
|
|
if (p->p_pptr != td->td_proc)
|
|
|
|
proc_reparent(p, td->td_proc);
|
2002-09-05 01:02:50 +00:00
|
|
|
data = SIGSTOP;
|
1996-01-24 18:29:00 +00:00
|
|
|
goto sendsig; /* in PT_CONTINUE below */
|
|
|
|
|
|
|
|
case PT_STEP:
|
|
|
|
case PT_CONTINUE:
|
1994-08-08 13:00:27 +00:00
|
|
|
case PT_DETACH:
|
2002-09-05 01:02:50 +00:00
|
|
|
/* XXX data is used even in the PT_STEP case. */
|
|
|
|
if (req != PT_STEP && (unsigned)data > _SIG_MAXSIG) {
|
2002-04-12 21:17:37 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
1996-01-24 18:29:00 +00:00
|
|
|
|
2002-04-12 21:17:37 +00:00
|
|
|
_PHOLD(p);
|
1996-01-24 18:29:00 +00:00
|
|
|
|
2002-09-05 01:02:50 +00:00
|
|
|
if (req == PT_STEP) {
|
2002-02-08 08:56:01 +00:00
|
|
|
error = ptrace_single_step(td2);
|
2002-02-07 23:05:40 +00:00
|
|
|
if (error) {
|
2002-04-12 21:17:37 +00:00
|
|
|
_PRELE(p);
|
|
|
|
goto fail;
|
1996-01-24 18:29:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-05 01:02:50 +00:00
|
|
|
if (addr != (void *)1) {
|
|
|
|
error = ptrace_set_pc(td2, (u_long)(uintfptr_t)addr);
|
2002-02-07 23:05:40 +00:00
|
|
|
if (error) {
|
2002-04-12 21:17:37 +00:00
|
|
|
_PRELE(p);
|
|
|
|
goto fail;
|
1996-01-24 18:29:00 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-12 21:17:37 +00:00
|
|
|
_PRELE(p);
|
1996-01-24 18:29:00 +00:00
|
|
|
|
2002-09-05 01:02:50 +00:00
|
|
|
if (req == PT_DETACH) {
|
1996-01-24 18:29:00 +00:00
|
|
|
/* reset process parent */
|
|
|
|
if (p->p_oppid != p->p_pptr->p_pid) {
|
|
|
|
struct proc *pp;
|
|
|
|
|
2002-04-12 21:17:37 +00:00
|
|
|
PROC_UNLOCK(p);
|
1996-01-24 18:29:00 +00:00
|
|
|
pp = pfind(p->p_oppid);
|
2002-02-23 11:12:57 +00:00
|
|
|
if (pp == NULL)
|
2001-05-04 18:13:11 +00:00
|
|
|
pp = initproc;
|
2002-02-23 11:12:57 +00:00
|
|
|
else
|
|
|
|
PROC_UNLOCK(pp);
|
2001-05-04 18:13:11 +00:00
|
|
|
PROC_LOCK(p);
|
|
|
|
proc_reparent(p, pp);
|
2002-04-12 21:17:37 +00:00
|
|
|
}
|
1996-01-24 18:29:00 +00:00
|
|
|
p->p_flag &= ~(P_TRACED | P_WAITED);
|
|
|
|
p->p_oppid = 0;
|
2001-03-07 03:06:18 +00:00
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
/* should we send SIGCHLD? */
|
|
|
|
}
|
|
|
|
|
|
|
|
sendsig:
|
2002-04-12 21:17:37 +00:00
|
|
|
if (proctree_locked)
|
|
|
|
sx_xunlock(&proctree_lock);
|
1996-01-24 18:29:00 +00:00
|
|
|
/* deliver or queue signal */
|
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)) {
|
2002-09-05 01:02:50 +00:00
|
|
|
p->p_xstat = data;
|
2002-09-05 07:30:18 +00:00
|
|
|
p->p_flag &= ~(P_STOPPED_TRACE|P_STOPPED_SIG);
|
2003-04-17 22:31:54 +00:00
|
|
|
mtx_lock_spin(&sched_lock);
|
2002-09-11 08:13:56 +00:00
|
|
|
thread_unsuspend(p);
|
2002-02-21 04:47:38 +00:00
|
|
|
setrunnable(td2); /* XXXKSE */
|
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
|
|
|
/* Need foreach kse in proc, ... make_kse_queued(). */
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock_spin(&sched_lock);
|
2002-09-05 01:02:50 +00:00
|
|
|
} else if (data)
|
|
|
|
psignal(p, data);
|
2001-03-07 03:06:18 +00:00
|
|
|
PROC_UNLOCK(p);
|
2003-03-19 00:33:38 +00:00
|
|
|
|
2001-10-04 16:09:22 +00:00
|
|
|
return (0);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
|
|
|
case PT_WRITE_I:
|
|
|
|
case PT_WRITE_D:
|
1996-01-24 18:29:00 +00:00
|
|
|
write = 1;
|
2002-08-25 13:23:09 +00:00
|
|
|
/* FALLTHROUGH */
|
1996-01-24 18:29:00 +00:00
|
|
|
case PT_READ_I:
|
|
|
|
case PT_READ_D:
|
2002-04-12 21:17:37 +00:00
|
|
|
PROC_UNLOCK(p);
|
2002-07-12 16:48:05 +00:00
|
|
|
tmp = 0;
|
1996-01-24 18:29:00 +00:00
|
|
|
/* write = 0 set above */
|
2002-09-05 01:02:50 +00:00
|
|
|
iov.iov_base = write ? (caddr_t)&data : (caddr_t)&tmp;
|
1996-01-24 18:29:00 +00:00
|
|
|
iov.iov_len = sizeof(int);
|
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
2002-09-05 01:02:50 +00:00
|
|
|
uio.uio_offset = (off_t)(uintptr_t)addr;
|
1996-01-24 18:29:00 +00:00
|
|
|
uio.uio_resid = sizeof(int);
|
2002-02-21 04:47:38 +00:00
|
|
|
uio.uio_segflg = UIO_SYSSPACE; /* i.e.: the uap */
|
1996-01-24 18:29:00 +00:00
|
|
|
uio.uio_rw = write ? UIO_WRITE : UIO_READ;
|
2001-09-12 08:38:13 +00:00
|
|
|
uio.uio_td = td;
|
2003-04-25 20:02:16 +00:00
|
|
|
mtx_lock(&Giant);
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
error = proc_rwmem(p, &uio);
|
2003-04-25 20:02:16 +00:00
|
|
|
mtx_unlock(&Giant);
|
1996-03-30 15:02:58 +00:00
|
|
|
if (uio.uio_resid != 0) {
|
|
|
|
/*
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
* XXX proc_rwmem() doesn't currently return ENOSPC,
|
1996-03-30 15:02:58 +00:00
|
|
|
* so I think write() can bogusly return 0.
|
|
|
|
* XXX what happens for short writes? We don't want
|
|
|
|
* to write partial data.
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
* XXX proc_rwmem() returns EPERM for other invalid
|
1996-03-30 15:02:58 +00:00
|
|
|
* addresses. Convert this to EINVAL. Does this
|
|
|
|
* clobber returns of EPERM for other reasons?
|
|
|
|
*/
|
|
|
|
if (error == 0 || error == ENOSPC || error == EPERM)
|
|
|
|
error = EINVAL; /* EOF */
|
|
|
|
}
|
2002-07-12 16:48:05 +00:00
|
|
|
if (!write)
|
|
|
|
td->td_retval[0] = tmp;
|
1996-03-30 15:02:58 +00:00
|
|
|
return (error);
|
1994-08-08 13:00:27 +00:00
|
|
|
|
2002-03-16 02:40:02 +00:00
|
|
|
case PT_IO:
|
2002-10-16 16:28:33 +00:00
|
|
|
PROC_UNLOCK(p);
|
2002-09-05 01:02:50 +00:00
|
|
|
piod = addr;
|
|
|
|
iov.iov_base = piod->piod_addr;
|
|
|
|
iov.iov_len = piod->piod_len;
|
2002-03-16 02:40:02 +00:00
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
2002-09-05 01:02:50 +00:00
|
|
|
uio.uio_offset = (off_t)(uintptr_t)piod->piod_offs;
|
|
|
|
uio.uio_resid = piod->piod_len;
|
2002-03-16 02:40:02 +00:00
|
|
|
uio.uio_segflg = UIO_USERSPACE;
|
|
|
|
uio.uio_td = td;
|
2002-09-05 01:02:50 +00:00
|
|
|
switch (piod->piod_op) {
|
2002-03-16 02:40:02 +00:00
|
|
|
case PIOD_READ_D:
|
|
|
|
case PIOD_READ_I:
|
|
|
|
uio.uio_rw = UIO_READ;
|
|
|
|
break;
|
|
|
|
case PIOD_WRITE_D:
|
|
|
|
case PIOD_WRITE_I:
|
|
|
|
uio.uio_rw = UIO_WRITE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2003-04-25 20:02:16 +00:00
|
|
|
mtx_lock(&Giant);
|
2002-03-16 02:40:02 +00:00
|
|
|
error = proc_rwmem(p, &uio);
|
2003-04-25 20:02:16 +00:00
|
|
|
mtx_unlock(&Giant);
|
2002-09-05 01:02:50 +00:00
|
|
|
piod->piod_len -= uio.uio_resid;
|
2002-03-16 02:40:02 +00:00
|
|
|
return (error);
|
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
case PT_KILL:
|
2002-09-05 01:02:50 +00:00
|
|
|
data = SIGKILL;
|
1996-01-24 18:29:00 +00:00
|
|
|
goto sendsig; /* in PT_CONTINUE above */
|
|
|
|
|
|
|
|
case PT_SETREGS:
|
2002-04-12 21:17:37 +00:00
|
|
|
_PHOLD(p);
|
2002-09-05 01:02:50 +00:00
|
|
|
error = proc_write_regs(td2, addr);
|
2002-04-12 21:17:37 +00:00
|
|
|
_PRELE(p);
|
|
|
|
PROC_UNLOCK(p);
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
return (error);
|
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
case PT_GETREGS:
|
2002-04-12 21:17:37 +00:00
|
|
|
_PHOLD(p);
|
2002-09-05 01:02:50 +00:00
|
|
|
error = proc_read_regs(td2, addr);
|
2002-04-12 21:17:37 +00:00
|
|
|
_PRELE(p);
|
|
|
|
PROC_UNLOCK(p);
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
return (error);
|
1996-01-24 18:29:00 +00:00
|
|
|
|
|
|
|
case PT_SETFPREGS:
|
2002-04-12 21:17:37 +00:00
|
|
|
_PHOLD(p);
|
2002-09-05 01:02:50 +00:00
|
|
|
error = proc_write_fpregs(td2, addr);
|
2002-04-12 21:17:37 +00:00
|
|
|
_PRELE(p);
|
|
|
|
PROC_UNLOCK(p);
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
return (error);
|
|
|
|
|
1996-01-24 18:29:00 +00:00
|
|
|
case PT_GETFPREGS:
|
2002-04-12 21:17:37 +00:00
|
|
|
_PHOLD(p);
|
2002-09-05 01:02:50 +00:00
|
|
|
error = proc_read_fpregs(td2, addr);
|
2002-04-12 21:17:37 +00:00
|
|
|
_PRELE(p);
|
|
|
|
PROC_UNLOCK(p);
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
return (error);
|
1996-01-24 18:29:00 +00:00
|
|
|
|
1999-07-09 04:16:00 +00:00
|
|
|
case PT_SETDBREGS:
|
2002-04-12 21:17:37 +00:00
|
|
|
_PHOLD(p);
|
2002-09-05 01:02:50 +00:00
|
|
|
error = proc_write_dbregs(td2, addr);
|
2002-04-12 21:17:37 +00:00
|
|
|
_PRELE(p);
|
|
|
|
PROC_UNLOCK(p);
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
return (error);
|
2002-03-15 20:17:12 +00:00
|
|
|
|
1999-07-09 04:16:00 +00:00
|
|
|
case PT_GETDBREGS:
|
2002-04-12 21:17:37 +00:00
|
|
|
_PHOLD(p);
|
2002-09-05 01:02:50 +00:00
|
|
|
error = proc_read_dbregs(td2, addr);
|
2002-04-12 21:17:37 +00:00
|
|
|
_PRELE(p);
|
|
|
|
PROC_UNLOCK(p);
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
return (error);
|
1999-07-09 04:16:00 +00:00
|
|
|
|
1994-08-08 13:00:27 +00:00
|
|
|
default:
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
KASSERT(0, ("unreachable code\n"));
|
1994-08-08 13:00:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
KASSERT(0, ("unreachable code\n"));
|
2001-10-04 16:09:22 +00:00
|
|
|
return (0);
|
2002-04-12 21:17:37 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
PROC_UNLOCK(p);
|
|
|
|
if (proctree_locked)
|
|
|
|
sx_xunlock(&proctree_lock);
|
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
1997-12-06 04:11:14 +00:00
|
|
|
/*
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
* Stop a process because of a debugging event;
|
1997-12-06 04:11:14 +00:00
|
|
|
* stay stopped until p->p_step is cleared
|
|
|
|
* (cleared by PIOCCONT in procfs).
|
|
|
|
*/
|
|
|
|
void
|
Dissociate ptrace from procfs.
Until now, the ptrace syscall was implemented as a wrapper that called
various functions in procfs depending on which ptrace operation was
requested. Most of these functions were themselves wrappers around
procfs_{read,write}_{,db,fp}regs(), with only some extra error checks,
which weren't necessary in the ptrace case anyway.
This commit moves procfs_rwmem() from procfs_mem.c into sys_process.c
(renaming it to proc_rwmem() in the process), and implements ptrace()
directly in terms of procfs_{read,write}_{,db,fp}regs() instead of
having it fake up a struct uio and then call procfs_do{,db,fp}regs().
It also moves the prototypes for procfs_{read,write}_{,db,fp}regs()
and proc_rwmem() from proc.h to ptrace.h, and marks all procfs files
except procfs_machdep.c as "optional procfs" instead of "standard".
2001-10-07 20:08:42 +00:00
|
|
|
stopevent(struct proc *p, unsigned int event, unsigned int val)
|
2001-01-24 11:15:24 +00:00
|
|
|
{
|
|
|
|
|
2003-04-17 22:31:54 +00:00
|
|
|
PROC_LOCK_ASSERT(p, MA_OWNED);
|
1997-12-06 04:11:14 +00:00
|
|
|
p->p_step = 1;
|
|
|
|
do {
|
|
|
|
p->p_xstat = val;
|
|
|
|
p->p_stype = event; /* Which event caused the stop? */
|
|
|
|
wakeup(&p->p_stype); /* Wake up any PIOCWAIT'ing procs */
|
2001-01-24 11:15:24 +00:00
|
|
|
msleep(&p->p_step, &p->p_mtx, PWAIT, "stopevent", 0);
|
1997-12-06 04:11:14 +00:00
|
|
|
} while (p->p_step);
|
|
|
|
}
|