Date: Wed, 30 Jun 2004 23:05:13 GMT From: David Xu <davidxu@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 56172 for review Message-ID: <200406302305.i5UN5Dtj055376@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=56172 Change 56172 by davidxu@davidxu_alona on 2004/06/30 23:04:22 Let ptrace deal with lwpid as pid. remove ttrace. Affected files ... .. //depot/projects/davidxu_ksedbg/src/sys/kern/init_sysent.c#3 edit .. //depot/projects/davidxu_ksedbg/src/sys/kern/sys_process.c#3 edit .. //depot/projects/davidxu_ksedbg/src/sys/kern/syscalls.c#3 edit .. //depot/projects/davidxu_ksedbg/src/sys/kern/syscalls.master#3 edit .. //depot/projects/davidxu_ksedbg/src/sys/sys/signalvar.h#2 edit .. //depot/projects/davidxu_ksedbg/src/sys/sys/syscall.h#3 edit .. //depot/projects/davidxu_ksedbg/src/sys/sys/syscall.mk#3 edit .. //depot/projects/davidxu_ksedbg/src/sys/sys/sysproto.h#3 edit Differences ... ==== //depot/projects/davidxu_ksedbg/src/sys/kern/init_sysent.c#3 (text+ko) ==== @@ -472,5 +472,4 @@ { SYF_MPSAFE | AS(ksem_timedwait_args), (sy_call_t *)lkmressys }, /* 441 = ksem_timedwait */ { SYF_MPSAFE | AS(thr_suspend_args), (sy_call_t *)thr_suspend }, /* 442 = thr_suspend */ { SYF_MPSAFE | AS(thr_wake_args), (sy_call_t *)thr_wake }, /* 443 = thr_wake */ - { AS(ttrace_args), (sy_call_t *)ttrace }, /* 444 = ttrace */ }; ==== //depot/projects/davidxu_ksedbg/src/sys/kern/sys_process.c#3 (text+ko) ==== @@ -55,9 +55,6 @@ #include <vm/vm_object.h> #include <vm/vm_page.h> -static int kern_ttrace(struct thread *td, int req, pid_t pid, lwpid_t tid, - void *addr, int data); - /* * Functions implemented using PROC_ACTION(): * @@ -363,97 +360,17 @@ return (error); } -#ifndef _SYS_SYSPROTO_H_ -struct ttrace_args { - int req; - pid_t pid; - lwpid_t tid; - caddr_t addr; - int data; -}; -#endif - -int -ttrace(struct thread *td, struct ttrace_args * uap) -{ - /* - * XXX this obfuscation is to reduce stack usage, but the register - * structs may be too large to put on the stack anyway. - */ - union { - struct ptrace_io_desc piod; - struct dbreg dbreg; - struct fpreg fpreg; - struct reg reg; - } r; - 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; - break; - } - if (error) - return (error); - - error = kern_ttrace(td, uap->req, uap->pid, uap->tid, 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) { - return kern_ttrace(td, req, pid, 0, addr, data); -} - -int -kern_ttrace(struct thread *td, int req, pid_t pid, lwpid_t tid, void *addr, - int data) -{ struct iovec iov; struct uio uio; struct proc *curp, *p, *pp; - struct thread *td2; struct ptrace_io_desc *piod; int error, write, tmp, num; int proctree_locked = 0; - lwpid_t *buf, tid2; + struct thread *td2 = NULL; + lwpid_t tid = 0, tid2, *buf; curp = td->td_proc; @@ -478,10 +395,35 @@ p = td->td_proc; PROC_LOCK(p); } else { - if ((p = pfind(pid)) == NULL) { - if (proctree_locked) - sx_xunlock(&proctree_lock); - return (ESRCH); + if (pid <= PID_MAX) { + if ((p = pfind(pid)) == NULL) { + if (proctree_locked) + sx_xunlock(&proctree_lock); + return (ESRCH); + } + } else { + /* this is slow, should be optimized */ + sx_slock(&allproc_lock); + FOREACH_PROC_IN_SYSTEM(p) { + PROC_LOCK(p); + mtx_lock_spin(&sched_lock); + FOREACH_THREAD_IN_PROC(p, td2) { + if (td2->td_tid == pid) + break; + } + mtx_unlock_spin(&sched_lock); + if (td2 != NULL) + break; /* proc lock held */ + PROC_UNLOCK(p); + } + sx_sunlock(&allproc_lock); + if (p == NULL) { + if (proctree_locked) + sx_xunlock(&proctree_lock); + return (ESRCH); + } + tid = pid; + pid = p->p_pid; } } if ((error = p_cansee(td, p)) != 0) @@ -498,6 +440,11 @@ goto fail; } + if (tid == 0) { + td2 = FIRST_THREAD_IN_PROC(p); + tid = td2->td_tid; + } + /* * Permissions check */ @@ -563,19 +510,6 @@ break; } - if (tid == 0) - td2 = FIRST_THREAD_IN_PROC(p); - else { - FOREACH_THREAD_IN_PROC(p, td2) { - if (td2->td_tid == tid) - break; - } - if (td2 == NULL) { - error = ESRCH; - goto fail; - } - } - #ifdef FIX_SSTEP /* * Single step fixup ala procfs ==== //depot/projects/davidxu_ksedbg/src/sys/kern/syscalls.c#3 (text+ko) ==== @@ -451,5 +451,4 @@ "ksem_timedwait", /* 441 = ksem_timedwait */ "thr_suspend", /* 442 = thr_suspend */ "thr_wake", /* 443 = thr_wake */ - "ttrace", /* 444 = ttrace */ }; ==== //depot/projects/davidxu_ksedbg/src/sys/kern/syscalls.master#3 (text+ko) ==== @@ -631,7 +631,5 @@ 441 MNOSTD { int ksem_timedwait(semid_t id, struct timespec *abstime); } 442 MSTD { int thr_suspend(const struct timespec *timeout); } 443 MSTD { int thr_wake(thr_id_t id); } -444 STD { int ttrace(int req, pid_t pid, lwpid_t tid, \ - caddr_t addr, int data); } ; Please copy any additions and changes to the following compatability tables: ; sys/compat/freebsd32/syscalls.master ==== //depot/projects/davidxu_ksedbg/src/sys/sys/signalvar.h#2 (text+ko) ==== @@ -271,7 +271,7 @@ void signotify(struct thread *td); void tdsignal(struct thread *td, int sig, sigtarget_t target); void trapsignal(struct thread *td, int sig, u_long code); -void ptracestop(struct thread *td, int sig); +int ptracestop(struct thread *td, int sig); /* * Machine-dependent functions: ==== //depot/projects/davidxu_ksedbg/src/sys/sys/syscall.h#3 (text+ko) ==== @@ -356,5 +356,4 @@ #define SYS_ksem_timedwait 441 #define SYS_thr_suspend 442 #define SYS_thr_wake 443 -#define SYS_ttrace 444 -#define SYS_MAXSYSCALL 445 +#define SYS_MAXSYSCALL 444 ==== //depot/projects/davidxu_ksedbg/src/sys/sys/syscall.mk#3 (text+ko) ==== @@ -297,5 +297,4 @@ kse_switchin.o \ ksem_timedwait.o \ thr_suspend.o \ - thr_wake.o \ - ttrace.o + thr_wake.o ==== //depot/projects/davidxu_ksedbg/src/sys/sys/sysproto.h#3 (text+ko) ==== @@ -1302,13 +1302,6 @@ struct thr_wake_args { char id_l_[PADL_(thr_id_t)]; thr_id_t id; char id_r_[PADR_(thr_id_t)]; }; -struct ttrace_args { - char req_l_[PADL_(int)]; int req; char req_r_[PADR_(int)]; - char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; - char tid_l_[PADL_(lwpid_t)]; lwpid_t tid; char tid_r_[PADR_(lwpid_t)]; - char addr_l_[PADL_(caddr_t)]; caddr_t addr; char addr_r_[PADR_(caddr_t)]; - char data_l_[PADL_(int)]; int data; char data_r_[PADR_(int)]; -}; int nosys(struct thread *, struct nosys_args *); void sys_exit(struct thread *, struct sys_exit_args *); int fork(struct thread *, struct fork_args *); @@ -1603,7 +1596,6 @@ int ksem_timedwait(struct thread *, struct ksem_timedwait_args *); int thr_suspend(struct thread *, struct thr_suspend_args *); int thr_wake(struct thread *, struct thr_wake_args *); -int ttrace(struct thread *, struct ttrace_args *); #ifdef COMPAT_43
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200406302305.i5UN5Dtj055376>