Skip to content

Commit

Permalink
Refactor task OS-name setting
Browse files Browse the repository at this point in the history
Task::copy_state sets the OS name of a task in the same fashion that
persistent checkpointing sets name. Refactored this functionality into
Task::set_name.

Also removed the unnecessary `update_prname` from Task::copy_state.

update_prname is not a "write to tracee"-operation but a "read from tracee"-operation; and since
we already know what name we want to set Task::prname to, we skip this reading from the tracee
in Task::copy_state and just set it to the parameter passed in to Task::set_name
  • Loading branch information
theIDinside committed Mar 7, 2023
1 parent d4a69ea commit b29ff57
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
8 changes: 3 additions & 5 deletions src/ReplaySession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2157,11 +2157,11 @@ void ReplaySession::load_checkpoint(
Task* child = Task::os_clone(Task::SESSION_CLONE_LEADER, this, remote,
taskInfo.getRecTid(), taskInfo.getSerial(),
SIGCHLD, nullptr);
cloned_leaders.push_back((ReplayTask*)child);
cloned_leaders.push_back(static_cast<ReplayTask*>(child));
}

auto clone_leader_index = 0;

LOG(debug) << "Restoring " << addr_spaces.size() << " clone leaders";
for (const auto& as : addr_spaces) {
ReplayTask* leader = cloned_leaders[clone_leader_index++];
const auto proc_space = as.getProcessSpace();
Expand Down Expand Up @@ -2272,9 +2272,7 @@ void ReplaySession::load_checkpoint(
auto index = original_exe_name.rfind('/');
auto name = "rr:" + original_exe_name.substr(
index == std::string::npos ? 0 : index + 1);
AutoRestoreMem mem(remote, name.c_str());
remote.infallible_syscall(syscall_number_for_prctl(leader->arch()),
PR_SET_NAME, mem.get());
leader->set_name(remote, name);
}

ASSERT(leader, scratch_mem != nullptr)
Expand Down
22 changes: 12 additions & 10 deletions src/Task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2578,21 +2578,23 @@ Task::CapturedState Task::capture_state() {
return state;
}

void Task::set_name(AutoRemoteSyscalls& remote, const std::string& name) {
char prname[17];
strncpy(prname, name.c_str(), sizeof(prname));
prname[16] = 0;
AutoRestoreMem remote_prname(remote, (const uint8_t*)prname, 16);
LOG(debug) << " setting name to " << prname;
remote.infallible_syscall(syscall_number_for_prctl(arch()), PR_SET_NAME,
remote_prname.get().as_int());
this->prname = name;
}

void Task::copy_state(const CapturedState& state) {
set_regs(state.regs);
set_extra_regs(state.extra_regs);
{
AutoRemoteSyscalls remote(this);
{
char prname[17];
strncpy(prname, state.prname.c_str(), sizeof(prname));
prname[16] = 0;
AutoRestoreMem remote_prname(remote, (const uint8_t*)prname, 16);
LOG(debug) << " setting name to " << prname;
remote.infallible_syscall(syscall_number_for_prctl(arch()), PR_SET_NAME,
remote_prname.get().as_int());
update_prname(remote_prname.get());
}
set_name(remote, state.prname);

copy_tls(state, remote);
thread_areas_ = state.thread_areas;
Expand Down
6 changes: 6 additions & 0 deletions src/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,12 @@ class Task {
*/
void forget();

/**
* Sets the OS-name of this task by injecting system call for PR_SET_NAME.
* Also updates |prname| to |name|.
*/
void set_name(AutoRemoteSyscalls& remote_syscalls, const std::string& name);

// Used on aarch64 to detect whether we've recorded x0 and x8 on syscall entry
Ticks ticks_at_last_syscall_entry;
remote_code_ptr ip_at_last_syscall_entry;
Expand Down

0 comments on commit b29ff57

Please sign in to comment.