Skip to content

Commit

Permalink
Make diversion session gettid/getpid namespace aware.
Browse files Browse the repository at this point in the history
  • Loading branch information
khuey committed Mar 29, 2021
1 parent 35d477f commit 0bc6138
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/DiversionSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ static void process_syscall_arch(Task* t, int syscallno) {

case Arch::gettid: {
Registers r = t->regs();
r.set_syscall_result(t->rec_tid);
r.set_syscall_result(t->own_namespace_tid());
t->set_regs(r);
return;
}

case Arch::getpid: {
Registers r = t->regs();
r.set_syscall_result(t->tgid());
r.set_syscall_result(t->thread_group()->tgid_own_namespace);
t->set_regs(r);
return;
}
Expand Down
1 change: 0 additions & 1 deletion src/RecordTask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ RecordTask::RecordTask(RecordSession& session, pid_t _tid, uint32_t serial,
delay_syscallbuf_reset_for_seccomp_trap(false),
prctl_seccomp_status(0),
robust_futex_list_len(0),
own_namespace_rec_tid(0),
termination_signal(0),
tsc_mode(PR_TSC_ENABLE),
cpuid_mode(1),
Expand Down
3 changes: 0 additions & 3 deletions src/RecordTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class RecordTask : public Task {
virtual void will_resume_execution(ResumeRequest, WaitRequest, TicksRequest,
int /*sig*/) override;
virtual void did_wait() override;
virtual pid_t own_namespace_tid() override { return own_namespace_rec_tid; }

std::vector<remote_code_ptr> syscallbuf_syscall_entry_breakpoints();
bool is_at_syscallbuf_syscall_entry_breakpoint();
Expand Down Expand Up @@ -713,8 +712,6 @@ class RecordTask : public Task {
// The memory cell the kernel will clear and notify on exit,
// if our clone parent requested it.
remote_ptr<int> tid_futex;
/* This is the recorded tid of the tracee *in its own pid namespace*. */
pid_t own_namespace_rec_tid;
// Signal delivered by the kernel when this task terminates, or zero
int termination_signal;

Expand Down
1 change: 1 addition & 0 deletions src/Task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Task::Task(Session& session, pid_t _tid, pid_t _rec_tid, uint32_t serial,
hpc(_tid, session.ticks_semantics()),
tid(_tid),
rec_tid(_rec_tid > 0 ? _rec_tid : _tid),
own_namespace_rec_tid(_rec_tid > 0 ? _rec_tid: _tid),
syscallbuf_size(0),
serial(serial),
prname("???"),
Expand Down
7 changes: 5 additions & 2 deletions src/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,10 @@ class Task {
virtual void did_wait() {}
/**
* Return the pid of the task in its own pid namespace.
* Only RecordTasks actually change pid namespaces.
* Only RecordTasks actually change pid namespaces, but
* this value is stored and present during replay too.
*/
virtual pid_t own_namespace_tid() { return tid; }
pid_t own_namespace_tid() { return own_namespace_rec_tid; }

/**
* Assuming ip() is just past a breakpoint instruction, adjust
Expand Down Expand Up @@ -839,6 +840,8 @@ class Task {
* recording, it's synonymous with |tid|, and during replay
* it's the tid that was recorded. */
pid_t rec_tid;
/* This is the recorded tid of the tracee *in its own pid namespace*. */
pid_t own_namespace_rec_tid;

size_t syscallbuf_size;
/* Points at the tracee's mapping of the buffer. */
Expand Down
1 change: 1 addition & 0 deletions src/replay_syscall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ template <typename Arch> static void prepare_clone(ReplayTask* t) {
ReplayTask* new_task = static_cast<ReplayTask*>(
t->session().clone(t, clone_flags_to_task_flags(flags), params.stack,
params.tls, params.ctid, new_tid, rec_tid));
new_task->own_namespace_rec_tid = tte.own_ns_tid();

if (Arch::clone == t->regs().original_syscallno()) {
/* FIXME: what if registers are non-null and contain an
Expand Down

0 comments on commit 0bc6138

Please sign in to comment.