Skip to content

Commit

Permalink
Merge pull request #40 from orhun/style/apply_formatting
Browse files Browse the repository at this point in the history
style: apply formatting via rustfmt
  • Loading branch information
JakWai01 committed May 27, 2024
2 parents 6d151d3 + ffdc33a commit 1a347d1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
6 changes: 2 additions & 4 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ pub fn read_bytes<'a>(pid: Pid, address: c_ulonglong, length: usize) -> Vec<u8>
pub fn ptrace_init_options(pid: Pid) -> nix::Result<()> {
ptrace::setoptions(
pid,
Options::PTRACE_O_TRACESYSGOOD
| Options::PTRACE_O_TRACEEXIT
| Options::PTRACE_O_TRACEEXEC,
Options::PTRACE_O_TRACESYSGOOD | Options::PTRACE_O_TRACEEXIT | Options::PTRACE_O_TRACEEXEC,
)
}

Expand Down Expand Up @@ -164,4 +162,4 @@ pub fn escape_to_string(buf: &Vec<u8>) -> String {
}
}
string
}
}
2 changes: 1 addition & 1 deletion src/arch/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ pub static SYSCALLS: [Option<(Sysno, [Option<SyscallArgType>; 6])>; 452] = [
syscall!(process_mrelease, INT, INT),
syscall!(futex_waitv, ADDR, INT, INT, ADDR, INT),
syscall!(set_mempolicy_home_node, INT, INT, INT, INT),
syscall!(cachestat, INT, INT, INT, INT)
syscall!(cachestat, INT, INT, INT, INT),
];

pub fn get_arg_value(registers: user_regs_struct, i: usize) -> c_ulonglong {
Expand Down
31 changes: 15 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ impl<W: Write> Tracer<W> {
WaitStatus::Exited(pid, _) => {
// If the process that exits is the original tracee, we can safely break here,
// but we need to continue if the process that exits is a child of the original tracee.
if self.pid == pid { break } else { continue };
if self.pid == pid {
break;
} else {
continue;
};
}
// The traced process was stopped by a `PTRACE_EVENT_*` event.
WaitStatus::PtraceEvent(pid, _, code) => {
Expand Down Expand Up @@ -292,7 +296,9 @@ impl<W: Write> Tracer<W> {
self.syscalls_pass.get(sysno),
self.syscalls_fail.get(sysno),
self.syscalls_time.get(sysno),
) else { continue };
) else {
continue;
};

let calls = pass + fail;
if calls == 0 {
Expand Down Expand Up @@ -414,26 +420,18 @@ impl<W: Write> Tracer<W> {

// Issue a PTRACE_SYSCALL request to the tracee, forwarding a signal if one is provided.
fn issue_ptrace_syscall_request(&self, pid: Pid, signal: Option<Signal>) -> Result<()> {
ptrace::syscall(pid, signal).map_err(|_|
anyhow!(
"Unable to issue a PTRACE_SYSCALL request in tracee {}",
pid
)
)
ptrace::syscall(pid, signal)
.map_err(|_| anyhow!("Unable to issue a PTRACE_SYSCALL request in tracee {}", pid))
}

// TODO: This is arch-specific code and should be modularized
fn get_registers(&self, pid: Pid) -> Result<user_regs_struct> {
ptrace::getregs(pid).map_err(|_|
anyhow!(
"Unable to get registers from tracee {}",
pid
)
)
ptrace::getregs(pid).map_err(|_| anyhow!("Unable to get registers from tracee {}", pid))
}

fn get_syscall(&self, registers: user_regs_struct) -> Result<Sysno> {
(registers.orig_rax as u32).try_into()
(registers.orig_rax as u32)
.try_into()
.map_err(|_| anyhow!("Invalid syscall number {}", registers.orig_rax))
}

Expand All @@ -447,7 +445,8 @@ impl<W: Write> Tracer<W> {

fn is_exit_syscall(&self, pid: Pid) -> Result<bool> {
self.get_registers(pid).map(|registers| {
registers.orig_rax == Sysno::exit as u64 || registers.orig_rax == Sysno::exit_group as u64
registers.orig_rax == Sysno::exit as u64
|| registers.orig_rax == Sysno::exit_group as u64
})
}
}
Expand Down

0 comments on commit 1a347d1

Please sign in to comment.