ptrace: unify flags PT_TRACE_SYSCALL_ENTER and PT_TRACE_SYSCALL_EXIT to PT_TRACE_SYSCALL

refs #961
This commit is contained in:
Tomoki Shirasawa
2017-10-11 15:43:57 +09:00
parent 6b60dee890
commit 99da5b6484
4 changed files with 11 additions and 30 deletions

View File

@ -965,7 +965,7 @@ void ptrace_report_signal(struct thread *thread, int sig)
proc->status = PS_TRACED; proc->status = PS_TRACED;
#endif /* POSTK_DEBUG_TEMP_FIX_41 */ #endif /* POSTK_DEBUG_TEMP_FIX_41 */
thread->status = PS_TRACED; thread->status = PS_TRACED;
proc->ptrace &= ~PT_TRACE_SYSCALL_MASK; proc->ptrace &= ~PT_TRACE_SYSCALL;
if (sig == SIGSTOP || sig == SIGTSTP || if (sig == SIGSTOP || sig == SIGTSTP ||
sig == SIGTTIN || sig == SIGTTOU) { sig == SIGTTIN || sig == SIGTTOU) {
proc->signal_flags |= SIGNAL_STOP_STOPPED; proc->signal_flags |= SIGNAL_STOP_STOPPED;

View File

@ -537,7 +537,7 @@ void ptrace_report_signal(struct thread *thread, int sig)
/* Transition thread state */ /* Transition thread state */
proc->status = PS_TRACED; proc->status = PS_TRACED;
thread->status = PS_TRACED; thread->status = PS_TRACED;
proc->ptrace &= ~PT_TRACE_SYSCALL_MASK; proc->ptrace &= ~PT_TRACE_SYSCALL;
if (sig == SIGSTOP || sig == SIGTSTP || if (sig == SIGSTOP || sig == SIGTSTP ||
sig == SIGTTIN || sig == SIGTTOU) { sig == SIGTTIN || sig == SIGTTOU) {
proc->signal_flags |= SIGNAL_STOP_STOPPED; proc->signal_flags |= SIGNAL_STOP_STOPPED;

View File

@ -78,9 +78,7 @@
// struct process.ptrace // struct process.ptrace
#define PT_TRACED 0x80 /* The process is ptraced */ #define PT_TRACED 0x80 /* The process is ptraced */
#define PT_TRACE_EXEC 0x100 /* Trace execve(2) */ #define PT_TRACE_EXEC 0x100 /* Trace execve(2) */
#define PT_TRACE_SYSCALL_ENTER 0x200 /* Trace syscall enter */ #define PT_TRACE_SYSCALL 0x200 /* Trace syscall enter */
#define PT_TRACE_SYSCALL_EXIT 0x400 /* Trace syscall exit */
#define PT_TRACE_SYSCALL_MASK (PT_TRACE_SYSCALL_ENTER | PT_TRACE_SYSCALL_EXIT)
// ptrace(2) request // ptrace(2) request
#define PTRACE_TRACEME 0 #define PTRACE_TRACEME 0

View File

@ -2005,28 +2005,11 @@ static int ptrace_report_exec(struct thread *thread)
return 0; return 0;
} }
static void ptrace_syscall_event(struct thread *thread)
static void ptrace_syscall_enter(struct thread *thread)
{
int ptrace = thread->proc->ptrace;
struct mcs_rwlock_node_irqsave lock;
if (ptrace & PT_TRACE_SYSCALL_ENTER) {
int sig = (SIGTRAP | ((ptrace & PTRACE_O_TRACESYSGOOD) ? 0x80 : 0));
ptrace_report_signal(thread, sig);
mcs_rwlock_writer_lock(&thread->proc->update_lock, &lock);
if (thread->proc->ptrace & PT_TRACE_SYSCALL_ENTER) {
thread->proc->ptrace |= PT_TRACE_SYSCALL_EXIT;
}
mcs_rwlock_writer_unlock(&thread->proc->update_lock, &lock);
}
}
static void ptrace_syscall_exit(struct thread *thread)
{ {
int ptrace = thread->proc->ptrace; int ptrace = thread->proc->ptrace;
if (ptrace & PT_TRACE_SYSCALL_EXIT) { if (ptrace & PT_TRACE_SYSCALL) {
int sig = (SIGTRAP | ((ptrace & PTRACE_O_TRACESYSGOOD) ? 0x80 : 0)); int sig = (SIGTRAP | ((ptrace & PTRACE_O_TRACESYSGOOD) ? 0x80 : 0));
ptrace_report_signal(thread, sig); ptrace_report_signal(thread, sig);
} }
@ -2076,7 +2059,7 @@ static int ptrace_report_clone(struct thread *thread, struct thread *new, int ev
thread->proc->status = PS_TRACED; thread->proc->status = PS_TRACED;
thread->status = PS_TRACED; thread->status = PS_TRACED;
thread->proc->ptrace_eventmsg = new->tid; thread->proc->ptrace_eventmsg = new->tid;
thread->proc->ptrace &= ~PT_TRACE_SYSCALL_MASK; thread->proc->ptrace &= ~PT_TRACE_SYSCALL; /** ??? **/
parent_pid = thread->proc->parent->pid; parent_pid = thread->proc->parent->pid;
mcs_rwlock_writer_unlock_noirq(&thread->proc->update_lock, &lock); mcs_rwlock_writer_unlock_noirq(&thread->proc->update_lock, &lock);
@ -2275,7 +2258,7 @@ SYSCALL_DECLARE(execve)
if (cpu_local_var(current)->proc->ptrace) { if (cpu_local_var(current)->proc->ptrace) {
ihk_mc_syscall_ret(ctx) = 0; ihk_mc_syscall_ret(ctx) = 0;
ptrace_syscall_exit(cpu_local_var(current)); ptrace_syscall_event(cpu_local_var(current));
} }
/* Unmap all memory areas of the process, userspace will be gone */ /* Unmap all memory areas of the process, userspace will be gone */
@ -5682,9 +5665,9 @@ static int ptrace_wakeup_sig(int pid, long request, long data) {
set_single_step(child); set_single_step(child);
} }
mcs_rwlock_writer_lock(&child->proc->update_lock, &lock); mcs_rwlock_writer_lock(&child->proc->update_lock, &lock);
child->proc->ptrace &= ~PT_TRACE_SYSCALL_MASK; child->proc->ptrace &= ~PT_TRACE_SYSCALL;
if (request == PTRACE_SYSCALL) { if (request == PTRACE_SYSCALL) {
child->proc->ptrace |= PT_TRACE_SYSCALL_ENTER; child->proc->ptrace |= PT_TRACE_SYSCALL;
} }
mcs_rwlock_writer_unlock(&child->proc->update_lock, &lock); mcs_rwlock_writer_unlock(&child->proc->update_lock, &lock);
if(data != 0 && data != SIGSTOP) { if(data != 0 && data != SIGSTOP) {
@ -9985,7 +9968,7 @@ long syscall(int num, ihk_mc_user_context_t *ctx)
if (cpu_local_var(current)->proc->ptrace) { if (cpu_local_var(current)->proc->ptrace) {
ihk_mc_syscall_ret(ctx) = -ENOSYS; ihk_mc_syscall_ret(ctx) = -ENOSYS;
ptrace_syscall_enter(cpu_local_var(current)); ptrace_syscall_event(cpu_local_var(current));
num = ihk_mc_syscall_number(ctx); num = ihk_mc_syscall_number(ctx);
} }
@ -10032,7 +10015,7 @@ long syscall(int num, ihk_mc_user_context_t *ctx)
if (cpu_local_var(current)->proc->ptrace && l != -ENOSYS) { if (cpu_local_var(current)->proc->ptrace && l != -ENOSYS) {
ihk_mc_syscall_ret(ctx) = l; ihk_mc_syscall_ret(ctx) = l;
ptrace_syscall_exit(cpu_local_var(current)); ptrace_syscall_event(cpu_local_var(current));
l = ihk_mc_syscall_ret(ctx); l = ihk_mc_syscall_ret(ctx);
} }