Skip to content

Commit 4e405db

Browse files
committed
Add [start]wait command to ctl, first iteration
[currently only wakes up the debugger(s) when the child exits]
1 parent 706a007 commit 4e405db

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

fs/proc/base.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,24 @@ static int ctl_get_sigmask(const char __user *buf, int count) {
10241024
return retval;
10251025
}
10261026

1027-
static ssize_t ctl_write(struct file * file, const char __user *buf,
1027+
1028+
static int ctl_wait(struct task_struct *task, int start_the_task) {
1029+
DEFINE_WAIT(wait);
1030+
1031+
printk("PROCTRACE waiting %d task with %d\n", task->pid, current->pid);
1032+
1033+
if (start_the_task) {
1034+
wake_up_process(task);
1035+
}
1036+
1037+
prepare_to_wait(&task->wq_for_stop, &wait, TASK_INTERRUPTIBLE);
1038+
schedule();
1039+
finish_wait(&task->wq_for_stop, &wait);
1040+
1041+
return 0;
1042+
}
1043+
1044+
static ssize_t ctl_write(struct file *file, const char __user *buf,
10281045
size_t count, loff_t *ppos)
10291046
{
10301047
struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
@@ -1033,10 +1050,14 @@ static ssize_t ctl_write(struct file * file, const char __user *buf,
10331050
ctl_waitsignal(task, ctl_get_sigmask(buf + 11, count - 11), 0);
10341051
} else if (strncmp(buf, "startwaitsignal", 15) == 0) {
10351052
ctl_waitsignal(task, ctl_get_sigmask(buf + 16, count - 16), 1);
1053+
} else if (strncmp(buf, "startwait", 9) == 0) {
1054+
ctl_wait(task, 1);
10361055
} else if (strncmp(buf, "stop", 4) == 0) {
10371056
ctl_stop(task);
10381057
} else if (strncmp(buf, "start", 5) == 0) {
10391058
ctl_start(task);
1059+
} else if (strncmp(buf, "wait", 4) == 0) {
1060+
ctl_wait(task, 0);
10401061
}
10411062

10421063
return count;

include/linux/init_task.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ extern struct cred init_cred;
155155
INIT_PUSHABLE_TASKS(tsk) \
156156
.ptraced = LIST_HEAD_INIT(tsk.ptraced), \
157157
.ptrace_entry = LIST_HEAD_INIT(tsk.ptrace_entry), \
158+
.wq_for_stop = __WAIT_QUEUE_HEAD_INITIALIZER(tsk.wq_for_stop),\
158159
.sig_wait_list = LIST_HEAD_INIT(tsk.sig_wait_list), \
159160
.real_parent = &tsk, \
160161
.parent = &tsk, \

include/linux/sched.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,9 @@ struct task_struct {
13431343
struct list_head ptraced;
13441344
struct list_head ptrace_entry;
13451345

1346+
/* Debuggers waiting for child to stop or exit */
1347+
wait_queue_head_t wq_for_stop;
1348+
/* Debuggers waiting for child to get a signal or exit */
13461349
struct list_head sig_wait_list;
13471350

13481351
/* PID/PID hash table linkage. */

kernel/fork.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
13021302
p->pdeath_signal = 0;
13031303
p->exit_state = 0;
13041304

1305-
/* Initialize signal wait queue list */
1305+
/* Initialize proctrace data structures */
1306+
init_waitqueue_head(&p->wq_for_stop);
13061307
INIT_LIST_HEAD(&p->sig_wait_list);
13071308

13081309
/*

kernel/signal.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,7 @@ bool do_notify_parent(struct task_struct *tsk, int sig)
16661666
__wake_up_parent(tsk, tsk->parent);
16671667

16681668
/* also notify all the proctraces */
1669+
wake_up(&tsk->wq_for_stop);
16691670
list_for_each(p, &tsk->sig_wait_list) {
16701671
printk("PROCTRACE budim frajera jer je child umro\n");
16711672
wake_up(&list_entry(

0 commit comments

Comments
 (0)