Debian Codegraph @

src/ptracer.rs

raw symbols SCIP
1 //! Types for attaching to processes, managing tracees, and interpreting tracing events.
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/;
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#;
7 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/process/::CommandExtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/process/CommandExt#;
8 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::{Childrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Child#, Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#};
9 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#;
10
11 use nixrust-analyzer cargo nix 0.30.1 crate/::{
12 errnorust-analyzer cargo nix 0.30.1 errno/::Errnorust-analyzer cargo nix 0.30.1 errno/consts/Errno#,
13 sysrust-analyzer cargo nix 0.30.1 sys/::{
14 ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/,
15 waitrust-analyzer cargo nix 0.30.1 sys/wait/::{selfrust-analyzer cargo nix 0.30.1 sys/wait/, WaitPidFlagrust-analyzer cargo nix 0.30.1 sys/wait/WaitPidFlag#, WaitStatusrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#},
16 },
17 };
18 use tracingrust-analyzer cargo tracing 0.1.41 crate/::{debugrust-analyzer cargo tracing 0.1.41 macros/debug!, inforust-analyzer cargo tracing 0.1.41 macros/info!, tracerust-analyzer cargo tracing 0.1.41 macros/trace!};
19
20 use craterust-analyzer cargo pete 0.13.0 crate/::errorrust-analyzer cargo pete 0.13.0 error/::{Errorrust-analyzer cargo pete 0.13.0 error/Error#, Resultrust-analyzer cargo pete 0.13.0 error/Result#, ResultExtrust-analyzer cargo pete 0.13.0 error/ResultExt#};
21
22 #[cfg(target_arch = "aarch64")]
23 use craterust-analyzer cargo pete 0.13.0 crate/::aarch64;
24
25 #[cfg(target_arch = "x86_64")]
26 use craterust-analyzer cargo pete 0.13.0 crate/::x86rust-analyzer cargo pete 0.13.0 x86/;
27
28 #[cfg(target_arch = "x86_64")]
29 use x86rust-analyzer cargo pete 0.13.0 x86/::DebugRegisterrust-analyzer cargo pete 0.13.0 x86/DebugRegister#;
30
31 #[cfg(target_arch = "aarch64")]
32 pub type DebugRegisters = aarch64::user_hwdebug_state;
33
34 pub use nixrust-analyzer cargo nix 0.30.1 crate/::unistdrust-analyzer cargo nix 0.30.1 unistd/::Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#;
35 pub use nixrust-analyzer cargo nix 0.30.1 crate/::sysrust-analyzer cargo nix 0.30.1 sys/::ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::Optionsrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/Options#;
36
37 /// POSIX signal.
38 pub use nixrust-analyzer cargo nix 0.30.1 crate/::sysrust-analyzer cargo nix 0.30.1 sys/::signalrust-analyzer cargo nix 0.30.1 sys/signal/::Signalrust-analyzer cargo nix 0.30.1 sys/signal/Signal#;
39
40 /// Register state of a tracee.
41 #[cfg(target_arch = "aarch64")]
42 pub type Registers = aarch64::user_pt_regs;
43
44 /// Register state of a tracee.
45 #[cfg(target_arch = "x86_64")]
46 pub type Registersrust-analyzer cargo pete 0.13.0 ptracer/Registers# = libcrust-analyzer cargo libc 0.2.176 crate/::user_regs_structrust-analyzer cargo libc 0.2.176 unix/linux_like/linux/gnu/b64/x86_64/user_regs_struct#;
47
48 /// Extra signal info, such as its cause.
49 pub type Siginforust-analyzer cargo pete 0.13.0 ptracer/Siginfo# = libcrust-analyzer cargo libc 0.2.176 crate/::siginfo_trust-analyzer cargo libc 0.2.176 unix/linux_like/linux/gnu/b64/x86_64/siginfo_t#;
50
51 /// Linux constant defined in `include/uapi/linux/elf.h`.
52 #[cfg(target_arch = "aarch64")]
53 const NT_PRSTATUS: i32 = 0x1;
54
55 /// A _ptrace-stop_, a tracee state in which it is stopped and ready to accept ptrace
56 /// commands.
57 ///
58 /// These ptrace-stops may carry data obtained via additional (internal) ptrace requests
59 /// to `PTRACE_GETEVENTMSG`. Requests to `PTRACE_GETSIGINFO` may be made to disambiguate
60 /// stops.
61 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
62 pub enum Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop# {
63 Attachrust-analyzer cargo pete 0.13.0 ptracer/Stop#Attach#,
64
65 // signal-delivery-stop
66 SignalDeliveryrust-analyzer cargo pete 0.13.0 ptracer/Stop#SignalDelivery# { signalrust-analyzer cargo pete 0.13.0 ptracer/Stop#SignalDelivery#signal.: Signalrust-analyzer cargo nix 0.30.1 sys/signal/Signal# },
67
68 // group-stop
69 Grouprust-analyzer cargo pete 0.13.0 ptracer/Stop#Group# { signalrust-analyzer cargo pete 0.13.0 ptracer/Stop#Group#signal.: Signalrust-analyzer cargo nix 0.30.1 sys/signal/Signal# },
70
71 // syscall-stops
72 SyscallEnterrust-analyzer cargo pete 0.13.0 ptracer/Stop#SyscallEnter#,
73 SyscallExitrust-analyzer cargo pete 0.13.0 ptracer/Stop#SyscallExit#,
74
75 // ptrace-event-stops
76 Clonerust-analyzer cargo pete 0.13.0 ptracer/Stop#Clone# { newrust-analyzer cargo pete 0.13.0 ptracer/Stop#Clone#new.: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid# },
77 Forkrust-analyzer cargo pete 0.13.0 ptracer/Stop#Fork# { newrust-analyzer cargo pete 0.13.0 ptracer/Stop#Fork#new.: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid# },
78 Execrust-analyzer cargo pete 0.13.0 ptracer/Stop#Exec# { oldrust-analyzer cargo pete 0.13.0 ptracer/Stop#Exec#old.: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid# },
79 Exitingrust-analyzer cargo pete 0.13.0 ptracer/Stop#Exiting# { exit_coderust-analyzer cargo pete 0.13.0 ptracer/Stop#Exiting#exit_code.: i32 },
80 Signalingrust-analyzer cargo pete 0.13.0 ptracer/Stop#Signaling# {
81 signalrust-analyzer cargo pete 0.13.0 ptracer/Stop#Signaling#signal.: Signalrust-analyzer cargo nix 0.30.1 sys/signal/Signal#,
82 core_dumpedrust-analyzer cargo pete 0.13.0 ptracer/Stop#Signaling#core_dumped.: bool,
83 },
84 Vforkrust-analyzer cargo pete 0.13.0 ptracer/Stop#Vfork# { newrust-analyzer cargo pete 0.13.0 ptracer/Stop#Vfork#new.: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid# },
85 VforkDonerust-analyzer cargo pete 0.13.0 ptracer/Stop#VforkDone# { newrust-analyzer cargo pete 0.13.0 ptracer/Stop#VforkDone#new.: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid# },
86 Seccomprust-analyzer cargo pete 0.13.0 ptracer/Stop#Seccomp# { datarust-analyzer cargo pete 0.13.0 ptracer/Stop#Seccomp#data.: u16 },
87 }
88
89 /// Restart requests, which resume stopped tracees.
90 ///
91 /// The restart mode determines the possible subsequent stops of the restarted tracee.
92 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
93 pub enum Restartrust-analyzer cargo pete 0.13.0 ptracer/Restart# {
94 Steprust-analyzer cargo pete 0.13.0 ptracer/Restart#Step#,
95 Continuerust-analyzer cargo pete 0.13.0 ptracer/Restart#Continue#,
96 Syscallrust-analyzer cargo pete 0.13.0 ptracer/Restart#Syscall#,
97 }
98
99 /// Tracee task in ptrace-stop, with an optional pending signal.
100 ///
101 /// **Warning:** the underlying tracee is not guaranteed to exist, and
102 /// operations on it may fail between calls to [`Ptracer::wait()`].
103 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
104 pub struct Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee# {
105 pub pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid.: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#,
106 pub pendingrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pending.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Signalrust-analyzer cargo nix 0.30.1 sys/signal/Signal#>,
107 pub stoprust-analyzer cargo pete 0.13.0 ptracer/Tracee#stop.: Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#,
108
109 #[doc(hidden)]
110 _not_sendrust-analyzer cargo pete 0.13.0 ptracer/Tracee#_not_send.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<*const ()>,
111 }
112
113 impl Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee# {
114 pub fn newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#, pending: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Signalrust-analyzer cargo nix 0.30.1 sys/signal/Signal#>>, stop: Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#) -> Selfrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee] {
115 let pending = pending.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().();
116 let _not_send = PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#;
117
118 Selfrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee] { pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid., pendingrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pending., stoprust-analyzer cargo pete 0.13.0 ptracer/Tracee#stop., _not_sendrust-analyzer cargo pete 0.13.0 ptracer/Tracee#_not_send. }
119 }
120
121 /// Set a signal to deliver to the stopped process upon restart.
122 pub fn injectrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]inject().(&mut self, pending: Signalrust-analyzer cargo nix 0.30.1 sys/signal/Signal#) {
123 self.pendingrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pending. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pending);
124 }
125
126 /// Remove any signal scheduled for delivery to `pid` upon restart.
127 pub fn suppressrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]suppress().(&mut self) {
128 self.pendingrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pending. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
129 }
130
131 /// Set custom tracing options on the tracee.
132 pub fn set_optionsrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]set_options().(&mut self, options: Optionsrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/Options#) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<()> {
133 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::setoptionsrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/setoptions().(self.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid., options).died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(self.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)
134 }
135
136 #[cfg(target_arch = "x86_64")]
137 pub fn registersrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]registers().(&self) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<Registersrust-analyzer cargo pete 0.13.0 ptracer/Registers#> {
138 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::getregsrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/getregs().(self.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid.).died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(self.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)
139 }
140
141 #[cfg(target_arch = "aarch64")]
142 pub fn registers(&self) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<Registersrust-analyzer cargo pete 0.13.0 ptracer/Registers#> {
143
144 let mut data = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::uninit();
145 let mut rv = libcrust-analyzer cargo libc 0.2.176 crate/::iovecrust-analyzer cargo libc 0.2.176 unix/iovec# {
146 iov_base: &mut data as *mut _ as *mut libcrust-analyzer cargo libc 0.2.176 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#,
147 iov_len: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<Registersrust-analyzer cargo pete 0.13.0 ptracer/Registers#>(),
148 };
149
150 let res = unsafe {
151 libcrust-analyzer cargo libc 0.2.176 crate/::ptracerust-analyzer cargo libc 0.2.176 ptrace().(libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_GETREGSETrust-analyzer cargo libc 0.2.176 unix/linux_like/linux/gnu/PTRACE_GETREGSET., selfrust-analyzer cargo pete 0.13.0 ptracer/.pid, NT_PRSTATUS, &mut rv as *mut _ as *mut libcrust-analyzer cargo libc 0.2.176 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#)
152 };
153
154 Errnorust-analyzer cargo nix 0.30.1 errno/consts/Errno#::result(res)?;
155
156 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#( unsafe { data.assume_init() } )
157 }
158
159 #[cfg(target_arch = "x86_64")]
160 pub fn set_registersrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]set_registers().(&mut self, regs: Registersrust-analyzer cargo pete 0.13.0 ptracer/Registers#) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<()> {
161 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::setregsrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/setregs().(self.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid., regs).died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(self.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)
162 }
163
164 #[cfg(target_arch = "aarch64")]
165 pub fn set_registers(&mut self, regs: Registersrust-analyzer cargo pete 0.13.0 ptracer/Registers#) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<()> {
166 let mut rv = libcrust-analyzer cargo libc 0.2.176 crate/::iovecrust-analyzer cargo libc 0.2.176 unix/iovec# {
167 iov_base: &regs as *const _ as *const libcrust-analyzer cargo libc 0.2.176 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void# as *mut libcrust-analyzer cargo libc 0.2.176 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#,
168 iov_len: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<Registersrust-analyzer cargo pete 0.13.0 ptracer/Registers#>(),
169 };
170
171 let res = unsafe {
172 libcrust-analyzer cargo libc 0.2.176 crate/::ptracerust-analyzer cargo libc 0.2.176 ptrace().(libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_SETREGSETrust-analyzer cargo libc 0.2.176 unix/linux_like/linux/gnu/PTRACE_SETREGSET., selfrust-analyzer cargo pete 0.13.0 ptracer/.pid, NT_PRSTATUS, &mut rv as *mut _ as *mut libcrust-analyzer cargo libc 0.2.176 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#)
173 };
174
175 Errnorust-analyzer cargo nix 0.30.1 errno/consts/Errno#::result(res)?;
176
177 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
178 }
179
180 pub fn read_memoryrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]read_memory().(&mut self, addr: u64, len: usize) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> {
181 let mut data = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(len);
182 data.resizerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]resize().(len, 0);
183 let len_read = self.read_memory_mutrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]read_memory_mut().(addr, &mut data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
184 data.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(len_read);
185 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(data)
186 }
187
188 pub fn read_memory_mutrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]read_memory_mut().(&self, addr: u64, data: &mut [u8]) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<usize> {
189 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/::FileExtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/FileExt#;
190
191 let mem = self.memoryrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]memory().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
192 let len = mem.read_atrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/impl#[`fs::File`][FileExt]read_at().(data, addr)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
193 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(len)
194 }
195
196 pub fn write_memoryrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]write_memory().(&mut self, addr: u64, data: &[u8]) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<usize> {
197 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/::FileExtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/FileExt#;
198
199 let mem = fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::OpenOptionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/OpenOptions#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]new().()
200 .readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]read().(true)
201 .writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]write().(true)
202 .openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().(self.proc_mem_pathrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]proc_mem_path().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
203
204 let len = mem.write_atrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/impl#[`fs::File`][FileExt]write_at().(data, addr)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
205
206 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(len)
207 }
208
209 fn proc_mem_pathrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]proc_mem_path().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
210 let tid = self.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid..as_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]as_raw().() as u32;
211 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("/proc/{}/mem", tid)
212 }
213
214 pub fn memoryrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]memory().(&self) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#> {
215 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(self.proc_mem_pathrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]proc_mem_path().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)
216 }
217
218 pub fn siginforust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]siginfo().(&self) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Siginforust-analyzer cargo pete 0.13.0 ptracer/Siginfo#>> {
219 let info = if let Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::SignalDeliveryrust-analyzer cargo pete 0.13.0 ptracer/Stop#SignalDelivery# { .. } = self.stoprust-analyzer cargo pete 0.13.0 ptracer/Tracee#stop. {
220 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::getsiginforust-analyzer cargo nix 0.30.1 sys/ptrace/linux/getsiginfo().(self.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid.).died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(self.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)
221 } else {
222 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
223 };
224
225 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(info)
226 }
227
228 #[cfg(target_arch = "x86_64")]
229 pub fn debug_registerrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]debug_register().(&self, dr: DebugRegisterrust-analyzer cargo pete 0.13.0 x86/DebugRegister#) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<u64> {
230 let index = 8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().u64::fromrust-analyzer cargo pete 0.13.0 x86/impl#[u64][`From<DebugRegister>`]from().(dr);
231
232 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(off) = DebugRegisterrust-analyzer cargo pete 0.13.0 x86/DebugRegister#::user_offsetrust-analyzer cargo pete 0.13.0 x86/impl#[DebugRegister]user_offset().().checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_add().(index) {
233 self.peek_userrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]peek_user().(off)
234 } else {
235 internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error!!("unreachable overflow")
236 }
237 }
238
239 #[cfg(target_arch = "aarch64")]
240 pub fn debug_registers(&self, regtype: aarch64::DebugRegisterType) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<DebugRegisters> {
241 let mut data = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::uninit();
242 let mut rv = libcrust-analyzer cargo libc 0.2.176 crate/::iovecrust-analyzer cargo libc 0.2.176 unix/iovec# {
243 iov_base: &mut data as *mut _ as *mut libcrust-analyzer cargo libc 0.2.176 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#,
244 iov_len: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<aarch64::user_hwdebug_state>(),
245 };
246 let res = unsafe {
247 libcrust-analyzer cargo libc 0.2.176 crate/::ptracerust-analyzer cargo libc 0.2.176 ptrace().(libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_GETREGSETrust-analyzer cargo libc 0.2.176 unix/linux_like/linux/gnu/PTRACE_GETREGSET., selfrust-analyzer cargo pete 0.13.0 ptracer/.pid, regtype, &mut rv as *mut _ as *mut libcrust-analyzer cargo libc 0.2.176 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#)
248 };
249
250 Errnorust-analyzer cargo nix 0.30.1 errno/consts/Errno#::result(res)?;
251
252 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(unsafe { data.assume_init() })
253 }
254
255 #[cfg(target_arch = "x86_64")]
256 pub fn set_debug_registerrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]set_debug_register().(&self, dr: DebugRegisterrust-analyzer cargo pete 0.13.0 x86/DebugRegister#, data: u64) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<()> {
257 let index = 8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().u64::fromrust-analyzer cargo pete 0.13.0 x86/impl#[u64][`From<DebugRegister>`]from().(dr);
258
259 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(off) = DebugRegisterrust-analyzer cargo pete 0.13.0 x86/DebugRegister#::user_offsetrust-analyzer cargo pete 0.13.0 x86/impl#[DebugRegister]user_offset().().checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_add().(index) {
260 self.poke_userrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]poke_user().(off, data)
261 } else {
262 internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error!!("unreachable overflow")
263 }
264 }
265
266 #[cfg(target_arch = "aarch64")]
267 pub fn set_debug_registers(&self, regtype: aarch64::DebugRegisterType, mut state: DebugRegisters) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<()> {
268 let mut rv = libcrust-analyzer cargo libc 0.2.176 crate/::iovecrust-analyzer cargo libc 0.2.176 unix/iovec# {
269 iov_base: &mut state as *mut _ as *mut libcrust-analyzer cargo libc 0.2.176 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#,
270 iov_len: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<aarch64::user_hwdebug_state>(),
271 };
272 let res = unsafe {
273 libcrust-analyzer cargo libc 0.2.176 crate/::ptracerust-analyzer cargo libc 0.2.176 ptrace().(libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_SETREGSETrust-analyzer cargo libc 0.2.176 unix/linux_like/linux/gnu/PTRACE_SETREGSET., selfrust-analyzer cargo pete 0.13.0 ptracer/.pid, regtype, &mut rv as *mut _ as *mut libcrust-analyzer cargo libc 0.2.176 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#)
274 };
275
276 Errnorust-analyzer cargo nix 0.30.1 errno/consts/Errno#::result(res)?;
277
278 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
279 }
280
281 #[cfg(target_arch = "x86_64")]
282 fn peek_userrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]peek_user().(&self, off: u64) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<u64> {
283 // SAFETY: `off` does not require validation, because it is not actually used as a
284 // pointer offset by the kernel.
285 //
286 // See: https://github.com/torvalds/linux/blob/v4.9/arch/x86/kernel/ptrace.c#L774-L791
287
288 let data = unsafe {
289 libcrust-analyzer cargo libc 0.2.176 crate/::ptracerust-analyzer cargo libc 0.2.176 ptrace().(
290 libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_PEEKUSERrust-analyzer cargo libc 0.2.176 unix/linux_like/linux/gnu/PTRACE_PEEKUSER.,
291 self.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid.,
292 off,
293 0,
294 )
295 };
296
297 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(data as u64)
298 }
299
300 #[cfg(target_arch = "x86_64")]
301 fn poke_userrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]poke_user().(&self, off: u64, data: u64) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<()> {
302 // SAFETY: `off` does not require validation, because it is not actually used as a
303 // pointer offset by the kernel.
304 //
305 // See: https://github.com/torvalds/linux/blob/v4.9/arch/x86/kernel/ptrace.c#L774-L791
306
307 unsafe {
308 libcrust-analyzer cargo libc 0.2.176 crate/::ptracerust-analyzer cargo libc 0.2.176 ptrace().(
309 libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_POKEUSERrust-analyzer cargo libc 0.2.176 unix/linux_like/linux/gnu/PTRACE_POKEUSER.,
310 self.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid.,
311 off,
312 data,
313 )
314 };
315
316 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
317 }
318 }
319
320 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
321 enum Staterust-analyzer cargo pete 0.13.0 ptracer/State# {
322 // Traced, no special expectation for next stop.
323 Tracedrust-analyzer cargo pete 0.13.0 ptracer/State#Traced#,
324
325 // Newly-attached, expecting a SIGSTOP.
326 Attachingrust-analyzer cargo pete 0.13.0 ptracer/State#Attaching#,
327
328 // Self-attached, via `spawn()` with a pre-exec `TRACEME` request.
329 Spawnedrust-analyzer cargo pete 0.13.0 ptracer/State#Spawned#,
330
331 // After a syscall-exit-stop or seccomp-stop.
332 Syscallingrust-analyzer cargo pete 0.13.0 ptracer/State#Syscalling#,
333
334 // Stopped mid-exit (but not yet reaped) and pending detach.
335 Exitingrust-analyzer cargo pete 0.13.0 ptracer/State#Exiting#,
336 }
337
338 /// Tracer for a Linux process.
339 ///
340 /// By default, [spawning](Ptracer::spawn()) a child tracee will follow calls to `fork()`,
341 /// `clone()`, and `exec()`, tracing any child tasks (both threads and processes).
342 ///
343 /// This can be configured for any stopped tracee via [`Tracee::set_options()`].
344 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
345 pub struct Ptracerrust-analyzer cargo pete 0.13.0 ptracer/Ptracer# {
346 /// Ptrace options that will be applied to tracees, by default.
347 optionsrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#options.: Optionsrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/Options#,
348
349 /// Time to sleep for before polling tracees for new events.
350 poll_delayrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#poll_delay.: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#,
351
352 /// Known tracees, and their state.
353 traceesrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#tracees.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<i32, Staterust-analyzer cargo pete 0.13.0 ptracer/State#>,
354 }
355
356 const DEFAULT_POLL_DELAYrust-analyzer cargo pete 0.13.0 ptracer/DEFAULT_POLL_DELAY.: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration# = Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_microsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_micros().(1);
357
358 impl Ptracerrust-analyzer cargo pete 0.13.0 ptracer/Ptracer# {
359 pub fn newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]new().() -> Selfrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer] {
360 let options = Optionsrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/Options#::allrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/impl#[Options]all().();
361 let poll_delay = DEFAULT_POLL_DELAYrust-analyzer cargo pete 0.13.0 ptracer/DEFAULT_POLL_DELAY.;
362 let tracees = BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V>`]new().();
363
364 Selfrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer] { optionsrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#options., poll_delayrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#poll_delay., traceesrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#tracees. }
365 }
366
367 /// Return the default ptrace options applied to newly-spawned tracees.
368 pub fn default_optionsrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]default_options().(&self) -> Optionsrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/Options# {
369 self.optionsrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#options.
370 }
371
372 /// Set the default ptrace options applied to newly-spawned tracees.
373 pub fn set_default_optionsrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]set_default_options().(&mut self, options: Optionsrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/Options#) {
374 self.optionsrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#options. = options;
375 }
376
377 /// Return the initial tracee poll delay.
378 pub fn poll_delayrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]poll_delay().(&self) -> Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration# {
379 self.poll_delayrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#poll_delay.
380 }
381
382 /// Set the initial tracee poll delay.
383 pub fn set_poll_delayrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]set_poll_delay().(&mut self, poll_delay: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#) {
384 self.poll_delayrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#poll_delay. = poll_delay;
385 }
386
387 /// Resume the stopped tracee, delivering any pending signal.
388 pub fn restartrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]restart().(&mut self, tracee: Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#, restart: Restartrust-analyzer cargo pete 0.13.0 ptracer/Restart#) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<()> {
389 let Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee# { pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid., pendingrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pending., .. } = tracee;
390
391 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Exitingrust-analyzer cargo pete 0.13.0 ptracer/State#Exiting#) = self.tracee_staterust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]tracee_state().(tracee.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid.) {
392 // Override restart request with a detach.
393 let r = ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::detachrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/detach().(tracee.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid., tracee.pendingrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pending.);
394 r.died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(tracee.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
395
396 // We must not wait on this PID again, or we will reap it and break `std::process::Child`.
397 self.remove_traceerust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]remove_tracee().(tracee.pidrust-analyzer cargo pete 0.13.0 ptracer/Tracee#pid.);
398
399 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
400 }
401
402 let r = match restart {
403 Restartrust-analyzer cargo pete 0.13.0 ptracer/Restart#::Steprust-analyzer cargo pete 0.13.0 ptracer/Restart#Step# =>
404 ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::steprust-analyzer cargo nix 0.30.1 sys/ptrace/linux/step().(pid, pending),
405 Restartrust-analyzer cargo pete 0.13.0 ptracer/Restart#::Continuerust-analyzer cargo pete 0.13.0 ptracer/Restart#Continue# =>
406 ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::contrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/cont().(pid, pending),
407 Restartrust-analyzer cargo pete 0.13.0 ptracer/Restart#::Syscallrust-analyzer cargo pete 0.13.0 ptracer/Restart#Syscall# =>
408 ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::syscallrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/syscall().(pid, pending),
409 };
410
411 r.died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(pid)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
412
413 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
414 }
415
416 /// Spawn `cmd` for tracing.
417 ///
418 /// The command will be configured to request `PTRACE_TRACEME` after `fork()` and
419 /// pre-`exec()`. The caller will use this to avoid races and missed events.
420 pub fn spawnrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]spawn().(&mut self, mut cmd: Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<Childrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Child#> {
421 // On fork, request `PTRACE_TRACEME`.
422 unsafe {
423 cmd.pre_execrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/process/impl#[`process::Command`][CommandExt]pre_exec().(|| ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::tracemerust-analyzer cargo nix 0.30.1 sys/ptrace/linux/traceme().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::from_raw_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]from_raw_os_error().(err as i32)))
424 };
425
426 let child = cmd.spawnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]spawn().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
427
428 // Register the tracee as having been spawned with a pre-exec `TRACEME` request.
429 // This lets us interpret the `SIGTRAP` that will be issued for `execve()`, set
430 // the desired trace options, &c.
431 let pid = Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#::from_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]from_raw().(child.idrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Child]id().() as i32);
432 self.set_tracee_staterust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]set_tracee_state().(pid, Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Spawnedrust-analyzer cargo pete 0.13.0 ptracer/State#Spawned#);
433
434 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(child)
435 }
436
437 /// Attach to a running tracee. This will deliver a `SIGSTOP`.
438 ///
439 /// **Warning:** the tracee may not be considered stopped until it has been seen to
440 /// stop via `wait()`.
441 pub fn attachrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]attach().(&mut self, pid: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<()> {
442 let r = ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::attachrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/attach().(pid);
443 let r = r.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|source| Errorrust-analyzer cargo pete 0.13.0 error/Error#::Attachrust-analyzer cargo pete 0.13.0 error/Error#Attach# { pidrust-analyzer cargo pete 0.13.0 error/Error#Attach#pid., sourcerust-analyzer cargo pete 0.13.0 error/Error#Attach#source. });
444
445 self.mark_traceerust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]mark_tracee().(pid);
446
447 r
448 }
449
450 // Poll tracees for a `wait(2)` status change.
451 fn poll_traceesrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]poll_tracees().(&self) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<WaitStatusrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#>> {
452 let flag = WaitPidFlagrust-analyzer cargo nix 0.30.1 sys/wait/WaitPidFlag#::__WALLrust-analyzer cargo nix 0.30.1 sys/wait/impl#[WaitPidFlag]__WALL. rust-analyzer cargo nix 0.30.1 sys/wait/impl#[WaitPidFlag][`BitOr<Self>`]bitor().|rust-analyzer cargo nix 0.30.1 sys/wait/impl#[WaitPidFlag][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/wait/impl#[WaitPidFlag][`BitOr<Self>`]bitor().WaitPidFlagrust-analyzer cargo nix 0.30.1 sys/wait/WaitPidFlag#::WNOHANGrust-analyzer cargo nix 0.30.1 sys/wait/impl#[WaitPidFlag]WNOHANG.;
453
454 for tracee in self.traceesrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#tracees..keysrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]keys().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().() {
455 let pid = Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#::from_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]from_raw().(tracee);
456
457 match waitrust-analyzer cargo nix 0.30.1 sys/wait/::waitpidrust-analyzer cargo nix 0.30.1 sys/wait/waitpid().(pid, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(flag)) {
458 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(WaitStatusrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#::StillAliverust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#StillAlive#) => {
459 // Alive, no state change. Check remaining tracees.
460 continue;
461 },
462 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(status) => {
463 // One of our tracees changed state.
464 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(status));
465 },
466 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errno) if errno rust-analyzer cargo nix 0.30.1 errno/consts/impl#[Errno][`PartialEq<Self>`]eq().==rust-analyzer cargo nix 0.30.1 errno/consts/impl#[Errno][`PartialEq<Self>`]eq(). rust-analyzer cargo nix 0.30.1 errno/consts/impl#[Errno][`PartialEq<Self>`]eq().Errnorust-analyzer cargo nix 0.30.1 errno/consts/Errno#::ECHILDrust-analyzer cargo nix 0.30.1 errno/consts/Errno#ECHILD# => {
467 // No more children to wait on: we're done.
468 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
469 },
470 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => {
471 // Something else went wrong.
472 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
473 },
474 };
475 }
476
477 // No tracee changed state.
478 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
479 }
480
481 /// Wait for some running tracee process to stop.
482 ///
483 /// If there are no tracees to wait on, returns `None`.
484 pub fn waitrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]wait().(&mut self) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#>> {
485 use Signalrust-analyzer cargo nix 0.30.1 sys/signal/Signal#::*;
486
487 let mut poll_delay = self.poll_delayrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#poll_delay.;
488
489 // Wait on known tracees with exponential backoff.
490 let status = loop {
491 if self.traceesrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#tracees..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]is_empty().() {
492 debugrust-analyzer cargo tracing 0.1.41 macros/debug!!("no tracees to wait on");
493
494 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
495 }
496
497 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(status) = self.poll_traceesrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]poll_tracees().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
498 // A tracee changed state; examine its `wait(2)` status.
499 break status;
500 } else {
501 tracerust-analyzer cargo tracing 0.1.41 macros/trace!!(tracees = self.traceesrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#tracees..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]len().(), ?poll_delay, "no tracee updates, backing off");
502
503 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::sleeprust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/sleep().(poll_delay);
504
505 // Back off before next attempt.
506 poll_delay rust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration][`MulAssign<u32>`]mul_assign().*=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration][`MulAssign<u32>`]mul_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration][`MulAssign<u32>`]mul_assign().2;
507 }
508 };
509
510 let tracee = match status {
511 WaitStatusrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#::Exitedrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#Exited#(_pid, _exit_code) => {
512 internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error!!("consumed wait status for exited tracee");
513 },
514 WaitStatusrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#::Signaledrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#Signaled#(_pid, _sig, _is_core_dump) => {
515 internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error!!("consumed wait status for signaled tracee");
516 },
517 WaitStatusrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#::Stoppedrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#Stopped#(pid, SIGTRAPrust-analyzer cargo nix 0.30.1 sys/signal/Signal#SIGTRAP#) => {
518 let state = self.tracee_state_mutrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]tracee_state_mut().(pid);
519
520 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(state @ Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Spawnedrust-analyzer cargo pete 0.13.0 ptracer/State#Spawned#) = state {
521 // A `SIGTRAP` for a tracee in the `Spawned` state means it has returned from a
522 // successful `execve()` after requesting `PTRACE_TRACEME`. From the manual:
523 //
524 // If the `PTRACE_O_TRACEEXEC` option is not in effect, all successful calls
525 // to `execve(2)` by the traced process will cause it to be sent a `SIGTRAP`
526 // signal, giving the parent a chance to gain control before the new program
527 // begins execution.
528 //
529 // `PTRACE_O_TRACEEXEC` is not set by default, so it is not set when the child
530 // requests the attach. We will thus see its exec as a `SIGTRAP`, no matter what
531 // is set in `self.options`.
532 let stop = Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::SyscallExitrust-analyzer cargo pete 0.13.0 ptracer/Stop#SyscallExit#;
533 let mut tracee = Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, stop);
534
535 // Update the tracee state so subsequent traps are interpreted correctly.
536 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().state = Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Tracedrust-analyzer cargo pete 0.13.0 ptracer/State#Traced#;
537
538 // Set global tracing options on this root tracee. Auto-attached tracees from
539 // fork, clone, and exec will inherit them.
540 tracee.set_optionsrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]set_options().(self.optionsrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#options.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
541
542 tracee
543 } else {
544 let stop = Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::SignalDeliveryrust-analyzer cargo pete 0.13.0 ptracer/Stop#SignalDelivery# { signalrust-analyzer cargo pete 0.13.0 ptracer/Stop#SignalDelivery#signal.: SIGTRAPrust-analyzer cargo nix 0.30.1 sys/signal/Signal#SIGTRAP# };
545 Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, stop)
546 }
547 },
548 WaitStatusrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#::Stoppedrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#Stopped#(pid, signal) => {
549 if signal rust-analyzer cargo nix 0.30.1 sys/signal/impl#[Signal][`PartialEq<Self>`]eq().==rust-analyzer cargo nix 0.30.1 sys/signal/impl#[Signal][`PartialEq<Self>`]eq(). rust-analyzer cargo nix 0.30.1 sys/signal/impl#[Signal][`PartialEq<Self>`]eq().SIGSTOPrust-analyzer cargo nix 0.30.1 sys/signal/Signal#SIGSTOP# {
550 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(state) = self.tracee_state_mutrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]tracee_state_mut().(pid) {
551 if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().state rust-analyzer cargo pete 0.13.0 ptracer/impl#[State][`PartialEq<Self>`]eq().==rust-analyzer cargo pete 0.13.0 ptracer/impl#[State][`PartialEq<Self>`]eq(). rust-analyzer cargo pete 0.13.0 ptracer/impl#[State][`PartialEq<Self>`]eq().Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Attachingrust-analyzer cargo pete 0.13.0 ptracer/State#Attaching# {
552 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().state = Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Tracedrust-analyzer cargo pete 0.13.0 ptracer/State#Traced#;
553 let stop = Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::Attachrust-analyzer cargo pete 0.13.0 ptracer/Stop#Attach#;
554 let tracee = Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, stop);
555 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tracee));
556 }
557 }
558 else {
559 // We may see an attach-stop out-of-order, before the ptrace-event-stop
560 // which would otherwise have us mark it as `Attaching`. Since `Attaching`
561 // only exists to let us know that the next stop (i.e. this stop) is an
562 // attach-stop, we can directly initialize this tracee as `Traced`.
563 self.set_tracee_staterust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]set_tracee_state().(pid, Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Tracedrust-analyzer cargo pete 0.13.0 ptracer/State#Traced#);
564 let stop = Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::Attachrust-analyzer cargo pete 0.13.0 ptracer/Stop#Attach#;
565 let tracee = Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, stop);
566 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tracee));
567 }
568 }
569
570 let stop = if is_group_stoprust-analyzer cargo pete 0.13.0 ptracer/is_group_stop().(pid, signal)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
571 Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::Grouprust-analyzer cargo pete 0.13.0 ptracer/Stop#Group# { signalrust-analyzer cargo pete 0.13.0 ptracer/Stop#Group#signal. }
572 } else {
573 Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::SignalDeliveryrust-analyzer cargo pete 0.13.0 ptracer/Stop#SignalDelivery# { signalrust-analyzer cargo pete 0.13.0 ptracer/Stop#SignalDelivery#signal. }
574 };
575
576 Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, signal, stop)
577 },
578 WaitStatusrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#::PtraceEventrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#PtraceEvent#(pid, signal, code) => {
579 match code {
580 libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_EVENT_FORKrust-analyzer cargo libc 0.2.176 unix/linux_like/PTRACE_EVENT_FORK. => {
581 let evt_data = ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::geteventrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/getevent().(pid).died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(pid)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
582 let new = Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#::from_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]from_raw().(evt_data as u32 as i32);
583
584 // When we return, `new` will start as a tracee, but will be delivered a
585 // `SIGSTOP`. Mark it so we can recognize the `SIGSTOP` as an attach-stop.
586 self.mark_traceerust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]mark_tracee().(new);
587
588 let stop = Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::Forkrust-analyzer cargo pete 0.13.0 ptracer/Stop#Fork# { newrust-analyzer cargo pete 0.13.0 ptracer/Stop#Fork#new. };
589 Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, signal, stop)
590 },
591 libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_EVENT_CLONErust-analyzer cargo libc 0.2.176 unix/linux_like/PTRACE_EVENT_CLONE. => {
592 let evt_data = ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::geteventrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/getevent().(pid).died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(pid)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
593 let new = Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#::from_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]from_raw().(evt_data as u32 as i32);
594
595 // When we return, `new` will start as a tracee, but will be delivered a
596 // `SIGSTOP`. Mark it so we can recognize the `SIGSTOP` as an attach-stop.
597 self.mark_traceerust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]mark_tracee().(new);
598
599 let stop = Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::Clonerust-analyzer cargo pete 0.13.0 ptracer/Stop#Clone# { newrust-analyzer cargo pete 0.13.0 ptracer/Stop#Clone#new. };
600 Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, signal, stop)
601 },
602 libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_EVENT_EXECrust-analyzer cargo libc 0.2.176 unix/linux_like/PTRACE_EVENT_EXEC. => {
603 // We are in one of two cases. The exec has either occurred on the main
604 // thread of the thread group, or not. In either case, the new tid of the
605 // execing thread will be equal to the tgid. In the off-main case, this is
606 // a change, and the old state for the tid == tgid will be invalid.
607
608 // The current `pid` is now equal to the tgid of `old`.
609 let evt_data = ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::geteventrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/getevent().(pid).died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(pid)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
610 let old = Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#::from_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]from_raw().(evt_data as u32 as i32);
611
612 if old rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().pid {
613 // We exec'd off-thread, and previous tid state is now invalid.
614 self.remove_traceerust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]remove_tracee().(old);
615 }
616
617 // We know we are in a syscall. Make sure we can correctly label the next
618 // syscall-stop as an exit-stop.
619 //
620 // Important: if we trace all the syscall-stops, we will report the syscall-
621 // enter-stop as occurring on `old`, but its matching syscall-exit-stop as
622 // occurring on `pid`. This is correct, but might look odd.
623 self.set_tracee_staterust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]set_tracee_state().(pid, Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Syscallingrust-analyzer cargo pete 0.13.0 ptracer/State#Syscalling#);
624
625 let stop = Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::Execrust-analyzer cargo pete 0.13.0 ptracer/Stop#Exec# { oldrust-analyzer cargo pete 0.13.0 ptracer/Stop#Exec#old. };
626
627 Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, signal, stop)
628 },
629 libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_EVENT_EXITrust-analyzer cargo libc 0.2.176 unix/linux_like/PTRACE_EVENT_EXIT. => {
630 // In this context, `PTRACE_GETEVENTMSG` returns the pending wait status
631 // as an `unsigned long`. We are only interested in the low 16-bit word.
632 let status = ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::geteventrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/getevent().(pid).died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(pid)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). as u16;
633
634 // Mark the tracee as exiting so we can detach on next restart.
635 self.set_tracee_staterust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]set_tracee_state().(pid, Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Exitingrust-analyzer cargo pete 0.13.0 ptracer/State#Exiting#);
636
637 let stop = match ExitTyperust-analyzer cargo pete 0.13.0 ptracer/ExitType#::parserust-analyzer cargo pete 0.13.0 ptracer/impl#[ExitType]parse().(status)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
638 ExitTyperust-analyzer cargo pete 0.13.0 ptracer/ExitType#::Exitrust-analyzer cargo pete 0.13.0 ptracer/ExitType#Exit#(exit_code) =>
639 Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::Exitingrust-analyzer cargo pete 0.13.0 ptracer/Stop#Exiting# { exit_coderust-analyzer cargo pete 0.13.0 ptracer/Stop#Exiting#exit_code. },
640 ExitTyperust-analyzer cargo pete 0.13.0 ptracer/ExitType#::Signaledrust-analyzer cargo pete 0.13.0 ptracer/ExitType#Signaled#(signal, core_dumped) =>
641 Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::Signalingrust-analyzer cargo pete 0.13.0 ptracer/Stop#Signaling# { signalrust-analyzer cargo pete 0.13.0 ptracer/Stop#Signaling#signal., core_dumpedrust-analyzer cargo pete 0.13.0 ptracer/Stop#Signaling#core_dumped. },
642 };
643
644 Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, signal, stop)
645 },
646 libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_EVENT_VFORKrust-analyzer cargo libc 0.2.176 unix/linux_like/PTRACE_EVENT_VFORK. => {
647 let evt_data = ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::geteventrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/getevent().(pid).died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(pid)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
648 let new = Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#::from_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]from_raw().(evt_data as u32 as i32);
649 self.mark_traceerust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]mark_tracee().(new);
650
651 let stop = Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::Vforkrust-analyzer cargo pete 0.13.0 ptracer/Stop#Vfork# { newrust-analyzer cargo pete 0.13.0 ptracer/Stop#Vfork#new. };
652
653 Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, signal, stop)
654 },
655 libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_EVENT_VFORK_DONErust-analyzer cargo libc 0.2.176 unix/linux_like/PTRACE_EVENT_VFORK_DONE. => {
656 let evt_data = ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::geteventrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/getevent().(pid).died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(pid)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
657 let new = Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#::from_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]from_raw().(evt_data as u32 as i32);
658 let stop = Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::VforkDonerust-analyzer cargo pete 0.13.0 ptracer/Stop#VforkDone# {newrust-analyzer cargo pete 0.13.0 ptracer/Stop#VforkDone#new. };
659
660 Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, signal, stop)
661 },
662 libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_EVENT_SECCOMPrust-analyzer cargo libc 0.2.176 unix/linux_like/PTRACE_EVENT_SECCOMP. => {
663 // `SECCOMP_RET_DATA`, which is the low 16 bits of an int.
664 let data = ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::geteventrust-analyzer cargo nix 0.30.1 sys/ptrace/linux/getevent().(pid).died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(pid)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). as u16;
665 let stop = Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::Seccomprust-analyzer cargo pete 0.13.0 ptracer/Stop#Seccomp# { datarust-analyzer cargo pete 0.13.0 ptracer/Stop#Seccomp#data. };
666
667 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(state) = self.tracee_state_mutrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]tracee_state_mut().(pid) {
668 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().state = Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Syscallingrust-analyzer cargo pete 0.13.0 ptracer/State#Syscalling#;
669 } else {
670 internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error!!("seccomp ptrace-event-stop for non-tracee");
671 }
672
673 Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, signal, stop)
674 },
675 libcrust-analyzer cargo libc 0.2.176 crate/::PTRACE_EVENT_STOPrust-analyzer cargo libc 0.2.176 unix/linux_like/linux/PTRACE_EVENT_STOP. => {
676 // Unreachable by us, since we do not expose `PTRACE_SEIZE` &c.
677 internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error!!("unreachable ptrace-event-stop")
678 },
679 _ => {
680 // All kernel-delivered `event` values are matched above.
681 internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error!!("unexpected ptrace-event-stop code")
682 },
683 }
684 },
685 // A signal-delivery-stop never happens between syscall-enter-stop and syscall-exit-stop.
686 // It will always happen _after_ syscall-exit-stop, and not necessarily immediately. We
687 // may observe ptrace-event-stops in-between -enter and -exit.
688 //
689 // From the manual:
690 //
691 // No matter which method caused the syscall-entry-stop, if the tracer restarts
692 // the tracee with PTRACE_SYSCALL, the tracee enters syscall-exit-stop
693 // when the system call is finished, or if it is interrupted by a sig‐
694 // nal. (That is, signal-delivery-stop never happens between syscall-
695 // enter-stop and syscall-exit-stop; it happens after syscall-exit-
696 // stop.). If the tracee is continued using any other method (including
697 // PTRACE_SYSEMU), no syscall-exit-stop occurs.
698 //
699 // [...]
700 //
701 // Syscall-enter-stop and syscall-exit-stop are indistinguishable from
702 // each other by the tracer. The tracer needs to keep track of the
703 // sequence of ptrace-stops in order to not misinterpret syscall-enter-
704 // stop as syscall-exit-stop or vice versa. In general, a syscall-
705 // enter-stop is always followed by syscall-exit-stop, PTRACE_EVENT
706 // stop, or the tracee's death; no other kinds of ptrace-stop can occur
707 // in between. However, note that seccomp stops (see below) can cause
708 // syscall-exit-stops, without preceding syscall-entry-stops. If sec‐
709 // comp is in use, care needs to be taken not to misinterpret such stops
710 // as syscall-entry-stops.
711 //
712 WaitStatusrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#::PtraceSyscallrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#PtraceSyscall#(pid) => {
713 let stop = match self.tracee_state_mutrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]tracee_state_mut().(pid) {
714 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(state) => {
715 match state {
716 Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Syscallingrust-analyzer cargo pete 0.13.0 ptracer/State#Syscalling# => {
717 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().state = Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Tracedrust-analyzer cargo pete 0.13.0 ptracer/State#Traced#;
718 Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::SyscallExitrust-analyzer cargo pete 0.13.0 ptracer/Stop#SyscallExit#
719 },
720 Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Tracedrust-analyzer cargo pete 0.13.0 ptracer/State#Traced# => {
721 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().state = Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Syscallingrust-analyzer cargo pete 0.13.0 ptracer/State#Syscalling#;
722 Stoprust-analyzer cargo pete 0.13.0 ptracer/Stop#::SyscallEnterrust-analyzer cargo pete 0.13.0 ptracer/Stop#SyscallEnter#
723 },
724 Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Attachingrust-analyzer cargo pete 0.13.0 ptracer/State#Attaching# => {
725 // A tracee in this state is waiting for a `SIGSTOP`, which is an
726 // artifact of `PTRACE_ATTACH`. The next wait status will thus be
727 // either a `SIGSTOP`, `SIGKILL`, or a `PTRACE_EVENT_EXIT`.
728 internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error!!("syscall-stop for `Attaching` tracee")
729 },
730 Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Spawnedrust-analyzer cargo pete 0.13.0 ptracer/State#Spawned# => {
731 // We only set the tracee state to `Spawned` after a successful call
732 // to `Command::spawn()` with a pre-exec `TRACEME` request.
733 //
734 // The self-attached tracee will continue until `execve()`. Since it
735 // can only self-attach with default options, the `execve()` will be
736 // seen as a `SIGTRAP` signal-delivery-stop, not a syscall-stop or
737 // ptrace-event-stop, and so we can never reach this case.
738 internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error!!("syscall-stop for `Spawning` tracee")
739 },
740 Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Exitingrust-analyzer cargo pete 0.13.0 ptracer/State#Exiting# => {
741 // If the tracee was in the `Exiting` state, we should have detached on
742 // the next restart request.
743 internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error!!("unexpected event for detached tracee")
744 },
745 }
746 },
747 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
748 // Assumes any pid we are tracing is also indexed in `self.tracees`.
749 internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error!!("syscall-stop for unregistered tracee")
750 },
751 };
752
753 Traceerust-analyzer cargo pete 0.13.0 ptracer/Tracee#::newrust-analyzer cargo pete 0.13.0 ptracer/impl#[Tracee]new().(pid, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, stop)
754 },
755 // Assume `!WNOHANG`, `!WCONTINUED`.
756 WaitStatusrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#::Continuedrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#Continued#(_) |
757 WaitStatusrust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#::StillAliverust-analyzer cargo nix 0.30.1 sys/wait/WaitStatus#StillAlive# =>
758 internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error!!("unreachable `wait()` status"),
759 };
760
761 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tracee))
762 }
763
764 fn remove_traceerust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]remove_tracee().(&mut self, pid: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Staterust-analyzer cargo pete 0.13.0 ptracer/State#> {
765 inforust-analyzer cargo tracing 0.1.41 macros/info!!(pid = pid.as_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]as_raw().(), "removing tracee");
766 self.traceesrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#tracees..removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]remove().(&pid.as_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]as_raw().())
767 }
768
769 fn tracee_staterust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]tracee_state().(&self, pid: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Staterust-analyzer cargo pete 0.13.0 ptracer/State#> {
770 self.traceesrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#tracees..getrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]get().(&pid.as_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]as_raw().()).copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]copied().()
771 }
772
773 fn set_tracee_staterust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]set_tracee_state().(&mut self, pid: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#, state: Staterust-analyzer cargo pete 0.13.0 ptracer/State#) {
774 debugrust-analyzer cargo tracing 0.1.41 macros/debug!!(pid = pid.as_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]as_raw().(), ?state, "setting tracee state");
775
776 self.traceesrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#tracees..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(pid.as_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]as_raw().(), state);
777 }
778
779 fn tracee_state_mutrust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]tracee_state_mut().(&mut self, pid: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut Staterust-analyzer cargo pete 0.13.0 ptracer/State#> {
780 self.traceesrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#tracees..get_mutrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]get_mut().(&pid.as_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]as_raw().())
781 }
782
783 // Mark `pid` as a new tracee pending attach-stop, if it isn't already known.
784 fn mark_traceerust-analyzer cargo pete 0.13.0 ptracer/impl#[Ptracer]mark_tracee().(&mut self, pid: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#) {
785 debugrust-analyzer cargo tracing 0.1.41 macros/debug!!(pid = pid.as_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]as_raw().(), "marking tracee as attaching if unknown");
786
787 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.traceesrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#tracees..contains_keyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]contains_key().(&pid.as_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]as_raw().()) {
788 inforust-analyzer cargo tracing 0.1.41 macros/info!!(pid = pid.as_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]as_raw().(), "attaching to new tracee");
789 }
790
791 self.traceesrust-analyzer cargo pete 0.13.0 ptracer/Ptracer#tracees..entryrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]entry().(pid.as_rawrust-analyzer cargo nix 0.30.1 unistd/impl#[Pid]as_raw().()).or_insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/entry/impl#[`Entry<'a, K, V, A>`]or_insert().(Staterust-analyzer cargo pete 0.13.0 ptracer/State#::Attachingrust-analyzer cargo pete 0.13.0 ptracer/State#Attaching#);
792 }
793 }
794
795 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
796 enum ExitTyperust-analyzer cargo pete 0.13.0 ptracer/ExitType# {
797 Exitrust-analyzer cargo pete 0.13.0 ptracer/ExitType#Exit#(i32),
798 Signaledrust-analyzer cargo pete 0.13.0 ptracer/ExitType#Signaled#(Signalrust-analyzer cargo nix 0.30.1 sys/signal/Signal#, bool),
799 }
800
801 impl ExitTyperust-analyzer cargo pete 0.13.0 ptracer/ExitType# {
802 fn parserust-analyzer cargo pete 0.13.0 ptracer/impl#[ExitType]parse().(status: u16) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<Selfrust-analyzer cargo pete 0.13.0 ptracer/impl#[ExitType]> {
803 // The bit layout of the word `status` is:
804 //
805 // 15 8 7 0
806 // +-------------------------+---+---------------------+
807 // | exit_code | c | sig_no |
808 // +-------------------------+---+---------------------+
809 //
810 // If `status[6:0]` is nonzero, then `pid` is being signaled with `sig_no`,
811 // and a set `status[7]` bit flags a core dump. Otherwise, it is a normal
812 // exit with exit code `status[15:8]`.
813 let sig_no = status rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().0x7f;
814 let exiting = sig_no rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().0;
815
816 let ty = if exiting {
817 // Extract, zero-extend, cast.
818 let exit_code = (status rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().8) as u8 as u32 as i32;
819
820 ExitTyperust-analyzer cargo pete 0.13.0 ptracer/ExitType#::Exitrust-analyzer cargo pete 0.13.0 ptracer/ExitType#Exit#(exit_code)
821 } else {
822 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#;
823
824 let core_dump = (status rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl().7)) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().7;
825 let signal = Signalrust-analyzer cargo nix 0.30.1 sys/signal/Signal#::try_fromrust-analyzer cargo nix 0.30.1 sys/signal/impl#[Signal][`TryFrom<i32>`]try_from().(sig_no as i32)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
826 let core_dump = core_dump rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().0;
827
828 ExitTyperust-analyzer cargo pete 0.13.0 ptracer/ExitType#::Signaledrust-analyzer cargo pete 0.13.0 ptracer/ExitType#Signaled#(signal, core_dump)
829 };
830
831 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ty)
832 }
833 }
834
835 // Check if a wait stop with signal delivery is a group-stop.
836 //
837 // Assumes attach-stop has already been ruled out.
838 fn is_group_stoprust-analyzer cargo pete 0.13.0 ptracer/is_group_stop().(pid: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#, sig: Signalrust-analyzer cargo nix 0.30.1 sys/signal/Signal#) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<bool> {
839 use Signalrust-analyzer cargo nix 0.30.1 sys/signal/Signal#::*;
840
841 match sig {
842 SIGSTOPrust-analyzer cargo nix 0.30.1 sys/signal/Signal#SIGSTOP# | SIGTSTPrust-analyzer cargo nix 0.30.1 sys/signal/Signal#SIGTSTP# | SIGTTINrust-analyzer cargo nix 0.30.1 sys/signal/Signal#SIGTTIN# | SIGTTOUrust-analyzer cargo nix 0.30.1 sys/signal/Signal#SIGTTOU# => {
843 // Possible group-stop. Check `siginfo` to disambiguate.
844 //
845 // From the manual:
846 //
847 // If PTRACE_GETSIGINFO fails with EINVAL, then it is definitely a
848 // group-stop. (Other failure codes are possible, such as ESRCH
849 // ("no such process") if a SIGKILL killed the tracee.)
850 //
851 match ptracerust-analyzer cargo nix 0.30.1 sys/ptrace/::getsiginforust-analyzer cargo nix 0.30.1 sys/ptrace/linux/getsiginfo().(pid) {
852 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errnorust-analyzer cargo nix 0.30.1 errno/consts/Errno#::EINVALrust-analyzer cargo nix 0.30.1 errno/consts/Errno#EINVAL#) =>
853 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true),
854 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) =>
855 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
856 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) =>
857 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false)
858 }
859 },
860 _ => {
861 // Definitely not a group-stop.
862 //
863 // From the manual:
864 //
865 // The call can be avoided if the signal is not SIGSTOP, SIGTSTP,
866 // SIGTTIN, or SIGTTOU; only these four signals are stopping signals.
867 // If the tracer sees something else, it can't be a group-stop.
868 //
869 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false)
870 },
871 }
872 }