sys_process.c (27067774dce3388702a4cf744d7096c6fb71b688) | sys_process.c (e5574e096619bfaceff8d1a394c76c598a8885c4) |
---|---|
1/*- 2 * Copyright (c) 1994, Sean Eric Fagan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 679 unchanged lines hidden (view full) --- 688 (safe ? proc_write_ ## w ## 32(t, a) : EINVAL ) : \ 689 proc_write_ ## w (t, a) 690#else 691#define PROC_READ(w, t, a) proc_read_ ## w (t, a) 692#define PROC_WRITE(w, t, a) proc_write_ ## w (t, a) 693#endif 694 695void | 1/*- 2 * Copyright (c) 1994, Sean Eric Fagan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 679 unchanged lines hidden (view full) --- 688 (safe ? proc_write_ ## w ## 32(t, a) : EINVAL ) : \ 689 proc_write_ ## w (t, a) 690#else 691#define PROC_READ(w, t, a) proc_read_ ## w (t, a) 692#define PROC_WRITE(w, t, a) proc_write_ ## w (t, a) 693#endif 694 695void |
696proc_set_traced(struct proc *p) | 696proc_set_traced(struct proc *p, bool stop) |
697{ 698 699 PROC_LOCK_ASSERT(p, MA_OWNED); 700 p->p_flag |= P_TRACED; | 697{ 698 699 PROC_LOCK_ASSERT(p, MA_OWNED); 700 p->p_flag |= P_TRACED; |
701 p->p_flag2 |= P2_PTRACE_FSTP; | 701 if (stop) 702 p->p_flag2 |= P2_PTRACE_FSTP; |
702 p->p_ptevents = PTRACE_DEFAULT; 703 p->p_oppid = p->p_pptr->p_pid; 704} 705 706int 707kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) 708{ 709 struct iovec iov; --- 195 unchanged lines hidden (view full) --- 905 * Actually do the requests 906 */ 907 908 td->td_retval[0] = 0; 909 910 switch (req) { 911 case PT_TRACE_ME: 912 /* set my trace flag and "owner" so it can read/write me */ | 703 p->p_ptevents = PTRACE_DEFAULT; 704 p->p_oppid = p->p_pptr->p_pid; 705} 706 707int 708kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) 709{ 710 struct iovec iov; --- 195 unchanged lines hidden (view full) --- 906 * Actually do the requests 907 */ 908 909 td->td_retval[0] = 0; 910 911 switch (req) { 912 case PT_TRACE_ME: 913 /* set my trace flag and "owner" so it can read/write me */ |
913 proc_set_traced(p); | 914 proc_set_traced(p, false); |
914 if (p->p_flag & P_PPWAIT) 915 p->p_flag |= P_PPTRACE; 916 CTR1(KTR_PTRACE, "PT_TRACE_ME: pid %d", p->p_pid); 917 break; 918 919 case PT_ATTACH: 920 /* security check done above */ 921 /* 922 * It would be nice if the tracing relationship was separate 923 * from the parent relationship but that would require 924 * another set of links in the proc struct or for "wait" 925 * to scan the entire proc table. To make life easier, 926 * we just re-parent the process we're trying to trace. 927 * The old parent is remembered so we can put things back 928 * on a "detach". 929 */ | 915 if (p->p_flag & P_PPWAIT) 916 p->p_flag |= P_PPTRACE; 917 CTR1(KTR_PTRACE, "PT_TRACE_ME: pid %d", p->p_pid); 918 break; 919 920 case PT_ATTACH: 921 /* security check done above */ 922 /* 923 * It would be nice if the tracing relationship was separate 924 * from the parent relationship but that would require 925 * another set of links in the proc struct or for "wait" 926 * to scan the entire proc table. To make life easier, 927 * we just re-parent the process we're trying to trace. 928 * The old parent is remembered so we can put things back 929 * on a "detach". 930 */ |
930 proc_set_traced(p); | 931 proc_set_traced(p, true); |
931 if (p->p_pptr != td->td_proc) { 932 proc_reparent(p, td->td_proc); 933 } 934 data = SIGSTOP; 935 CTR2(KTR_PTRACE, "PT_ATTACH: pid %d, oppid %d", p->p_pid, 936 p->p_oppid); 937 goto sendsig; /* in PT_CONTINUE below */ 938 --- 511 unchanged lines hidden --- | 932 if (p->p_pptr != td->td_proc) { 933 proc_reparent(p, td->td_proc); 934 } 935 data = SIGSTOP; 936 CTR2(KTR_PTRACE, "PT_ATTACH: pid %d, oppid %d", p->p_pid, 937 p->p_oppid); 938 goto sendsig; /* in PT_CONTINUE below */ 939 --- 511 unchanged lines hidden --- |