7878#include  <linux/cpuset.h> 
7979#include  <linux/audit.h> 
8080#include  <linux/poll.h> 
81+ #include  <linux/ptrace.h> 
8182#include  <linux/nsproxy.h> 
8283#include  <linux/oom.h> 
8384#include  <linux/elf.h> 
@@ -959,47 +960,44 @@ static const struct file_operations proc_mem_operations = {
959960.open =  mem_open ,
960961};
961962
962- static  int  ctl_stop (struct  task_struct  * task )
963- {
964- printk ("PROCTRACE stopping %d task with %d\n" , task -> pid , current -> pid );
965- send_sig_info (SIGSTOP , SEND_SIG_FORCED , task );
966- return  0 ;
967- }
968- 
969- static  int  ctl_start (struct  task_struct  * task ) {
970- printk ("PROCTRACE continuing %d task with %d\n" , task -> pid , current -> pid );
971- wake_up_process (task );
972- return  0 ;
973- }
974- 
975- static  int  ctl_waitsignal (struct  task_struct  * task , int  sigmask , int  start_the_task ) {
963+ static  int  wait_waitsignal (struct  task_struct  * task , unsigned long long  mask ) {
976964struct  sig_wait_queue_struct  * sig_wait ;
977965DEFINE_WAIT (wait );
978966int  retval  =  0 ;
979967
980- printk ("PROCTRACE waiting %d task with %d. sigmask %d \n" , task -> pid , current -> pid , sigmask );
968+ printk ("PROCTRACE waiting %d task with %d. mask %lld \n" , task -> pid , current -> pid , mask );
981969
982970printk ("Allocating new signal wait queue\n" );
983971sig_wait  =  kmalloc (sizeof (struct  sig_wait_queue_struct ), GFP_KERNEL );
984972if  (!sig_wait ) {
985973retval  =  - ENOMEM ;
986974goto done ;
987975}
988- sig_wait -> sigmask  =  sigmask ;
976+ sig_wait -> sigmask  =  mask ;
989977init_waitqueue_head (& sig_wait -> wait_queue );
990978
991979write_lock (& tasklist_lock );
992980list_add (& sig_wait -> list , & task -> sig_wait_list );
993981write_unlock (& tasklist_lock );
994982
995- if  (start_the_task ) {
983+ if  (mask  &  (1ULL  << PROCTRACE_SYSTEM_CALLS )) {
984+ set_tsk_thread_flag (task , TIF_SYSCALL_TRACE );
985+ }
986+ 
987+ if  (mask  &  (1ULL  << PROCTRACE_START_TASK )) {
996988wake_up_process (task );
989+ // we don't need this flag anymore 
990+ mask  ^= 1ULL  << PROCTRACE_START_TASK ;
997991}
998992
999993prepare_to_wait (& sig_wait -> wait_queue , & wait , TASK_INTERRUPTIBLE );
1000994schedule ();
1001995finish_wait (& sig_wait -> wait_queue , & wait );
1002996
997+ if  (mask  &  (1ULL  << PROCTRACE_SYSTEM_CALLS )) {
998+ clear_tsk_thread_flag (task , TIF_SYSCALL_TRACE );
999+ }
1000+ 
10031001write_lock (& tasklist_lock );
10041002list_del (& sig_wait -> list );
10051003write_unlock (& tasklist_lock );
@@ -1010,34 +1008,36 @@ static int ctl_waitsignal(struct task_struct *task, int sigmask, int start_the_t
10101008return  retval ;
10111009}
10121010
1013- static  int  ctl_get_sigmask (const  char  __user  * buf , int  count ) {
1014- int  i , retval  =  0 ;
1011+ static  ssize_t  wait_write (struct  file  * file , const  char  __user  * buf ,
1012+  size_t  count , loff_t  * ppos ) {
1013+ unsigned long long  mask  =  0 ;
1014+ int  i  =  0 ;
1015+ struct  task_struct  * task  =  get_proc_task (file -> f_path .dentry -> d_inode );
10151016
1016- for  (i  =  0 ; i  <  count ; ++ i ) {
1017- if  (buf [i ] ==  '1'  ||  buf [i ] ==  '0' ) {
1018- retval  =  retval  *  2  +  (int )(buf [i ]- '0' );
1019- } else  if  (buf [i ] !=  ' ' ) {
1020- break ;
1021- }
1017+ for  (i  =  0 ; i  <  count  &&  i  <  8 ; ++ i ) {
1018+ mask  <<= 8 ;
1019+ mask  |= buf [i ];
10221020}
10231021
1024- return  retval ;
1025- }
1022+ wait_waitsignal (task , mask );
10261023
1024+ return  count ;
1025+ }
10271026
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- }
1027+ static  const  struct  file_operations  proc_wait_operations  =  {
1028+ .write =  wait_write ,
1029+ };
10361030
1037- prepare_to_wait (& task -> wq_for_stop , & wait , TASK_INTERRUPTIBLE );
1038- schedule ();
1039- finish_wait (& task -> wq_for_stop , & wait );
1031+ static  int  ctl_stop (struct  task_struct  * task )
1032+ {
1033+ printk ("PROCTRACE stopping %d task with %d\n" , task -> pid , current -> pid );
1034+ send_sig_info (SIGSTOP , SEND_SIG_FORCED , task );
1035+ return  0 ;
1036+ }
10401037
1038+ static  int  ctl_start (struct  task_struct  * task ) {
1039+ printk ("PROCTRACE continuing %d task with %d\n" , task -> pid , current -> pid );
1040+ wake_up_process (task );
10411041return  0 ;
10421042}
10431043
@@ -1046,31 +1046,15 @@ static ssize_t ctl_write(struct file *file, const char __user *buf,
10461046{
10471047struct  task_struct  * task  =  get_proc_task (file -> f_path .dentry -> d_inode );
10481048
1049- if  (strncmp (buf , "waitsignal" , 10 ) ==  0 ) {
1050- ctl_waitsignal (task , ctl_get_sigmask (buf  +  11 , count  -  11 ), 0 );
1051- } else  if  (strncmp (buf , "startwaitsignal" , 15 ) ==  0 ) {
1052- ctl_waitsignal (task , ctl_get_sigmask (buf  +  16 , count  -  16 ), 1 );
1053- } else  if  (strncmp (buf , "waitsyscall" , 9 ) ==  0 ) {
1054- set_tsk_thread_flag (task , TIF_SYSCALL_TRACE );
1055- ctl_waitsignal (task , 1  << SIGTRAP , 0 );
1056- clear_tsk_thread_flag (task , TIF_SYSCALL_TRACE );
1057- } else  if  (strncmp (buf , "startwaitsyscall" , 9 ) ==  0 ) {
1058- set_tsk_thread_flag (task , TIF_SYSCALL_TRACE );
1059- ctl_waitsignal (task , 1  << SIGTRAP , 1 );
1060- clear_tsk_thread_flag (task , TIF_SYSCALL_TRACE );
1061- } else  if  (strncmp (buf , "startwait" , 9 ) ==  0 ) {
1062- ctl_wait (task , 1 );
1063- } else  if  (strncmp (buf , "stop" , 4 ) ==  0 ) {
1049+ if  (strncmp (buf , "stop" , 4 ) ==  0 ) {
10641050ctl_stop (task );
10651051} else  if  (strncmp (buf , "start" , 5 ) ==  0 ) {
10661052ctl_start (task );
1067- } else  if  (strncmp (buf , "wait" , 4 ) ==  0 ) {
1068- ctl_wait (task , 0 );
10691053} else  if  (strncmp (buf , "step" , 4 ) ==  0 ) {
10701054if  (unlikely (!arch_has_block_step ()))
10711055return  - EIO ;
10721056user_enable_block_step (task );
1073- ctl_waitsignal (task , 1  << SIGTRAP ,  1 );
1057+ wait_waitsignal (task , ( 1ULL  << SIGTRAP ) | ( 1ULL  <<  PROCTRACE_START_TASK ) );
10741058user_disable_single_step (task );
10751059}
10761060
@@ -1081,6 +1065,7 @@ static const struct file_operations proc_ctl_operations = {
10811065.write =  ctl_write ,
10821066};
10831067
1068+ 
10841069static  ssize_t  environ_read (struct  file  * file , char  __user  * buf ,
10851070size_t  count , loff_t  * ppos )
10861071{
@@ -2929,6 +2914,7 @@ static const struct pid_entry tgid_base_stuff[] = {
29292914#endif 
29302915REG ("mem" , S_IRUSR |S_IWUSR , proc_mem_operations ),
29312916REG ("ctl" , S_IWUSR , proc_ctl_operations ),
2917+ REG ("wait" , S_IWUSR , proc_wait_operations ),
29322918LNK ("cwd" , proc_cwd_link ),
29332919LNK ("root" , proc_root_link ),
29342920LNK ("exe" , proc_exe_link ),
0 commit comments