Index: trunk/kernel/syscalls/sys_kill.c
===================================================================
--- trunk/kernel/syscalls/sys_kill.c	(revision 421)
+++ trunk/kernel/syscalls/sys_kill.c	(revision 433)
@@ -38,32 +38,35 @@
 {
     uint32_t    save_sr;       // required to enable IRQs
-    xptr_t      process_xp;    // extended pointer on target reference process
-    cxy_t       process_cxy;   // target process cluster
-    process_t * process_ptr;   // local pointer on target process
+    xptr_t      owner_xp;      // extended pointer on target reference process
+    cxy_t       owner_cxy;     // target process cluster
+    process_t * owner_ptr;     // local pointer on target process
     xptr_t      parent_xp;     // extended pointer on parent process
     cxy_t       parent_cxy;    // parent process cluster
     process_t * parent_ptr;    // local pointer on parent process
     pid_t       ppid;          // parent process PID
+    uint32_t    retval;        // return value for the switch
 
     thread_t  * this    = CURRENT_THREAD;
 
-#if CONFIG_SYSCALL_DEBUG
+#if CONFIG_DEBUG_SYS_KILL
 uint64_t    tm_start;
 uint64_t    tm_end;
 tm_start = hal_get_cycles();
-printk("\n[DBG] %s : core[%x,%d] enter / process %x / sig %d / cycle %d\n",
-__FUNCTION__ , local_cxy , this->core->lid , pid, sig_id, (uint32_t)tm_start );
+if( CONFIG_DEBUG_SYS_KILL < tm_start )
+printk("\n[DBG] %s : thread %x enter / process %x / sig %d / cycle %d\n",
+__FUNCTION__ , this, pid, sig_id, (uint32_t)tm_start );
 #endif
 
-    // get cluster and pointers on reference process
-    process_xp  = cluster_get_reference_process_from_pid( pid );
-    process_cxy = GET_CXY( process_xp );
-    process_ptr = (process_t *)GET_PTR( process_xp );
+    // get cluster and pointers on owner process
+    owner_xp  = cluster_get_owner_process_from_pid( pid );
+    owner_cxy = GET_CXY( owner_xp );
+    owner_ptr = GET_PTR( owner_xp );
 
     // check process existence
-    if( process_xp == XPTR_NULL )
+    if( owner_xp == XPTR_NULL )
     {
-        syscall_dmsg("\n[ERROR] in %s : process %x not found\n",
-        __FUNCTION__ , pid );
+
+syscall_dmsg("\n[ERROR] in %s : process %x not found\n", __FUNCTION__ , pid );
+
         this->errno = EINVAL;
         return -1;
@@ -71,5 +74,5 @@
     
     // get parent process PID
-    parent_xp  = hal_remote_lwd( XPTR( process_cxy , &process_ptr->parent_xp ) );
+    parent_xp  = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->parent_xp ) );
     parent_cxy = GET_CXY( parent_xp );
     parent_ptr = GET_PTR( parent_xp );
@@ -79,18 +82,7 @@
     if( ppid < 2 )
     {
-        syscall_dmsg("\n[ERROR] in %s : process %x cannot be killed\n",
-        __FUNCTION__ , pid );
-		this->errno = EINVAL;
-        return -1;
-    }
 
-    // does nothing if sig_id == 0
-    if( sig_id == 0 )  return 0;
-    
-    // check sig_id
-    if( (sig_id != SIGSTOP) && (sig_id != SIGCONT) && (sig_id != SIGKILL) ) 
-    {
-        syscall_dmsg("\n[ERROR] in %s : illegal signal type for process %x\n",
-        __FUNCTION__ , sig_id , pid );
+syscall_dmsg("\n[ERROR] in %s : process %x cannot be killed\n", __FUNCTION__ , pid );
+
 		this->errno = EINVAL;
         return -1;
@@ -100,14 +92,64 @@
     hal_enable_irq( &save_sr );
 
-    // execute process_make_kill() function in owner cluster
-    if( local_cxy == process_cxy )                            // owner cluster is local 
+    // analyse signal type
+    // supported values are : 0, SIGSTOP, SIGCONT, SIGKILL
+    switch( sig_id )
     {
-        process_make_kill( pid , sig_id );
+        case 0 :
+        {
+            // does nothing
+            retval = 0;
+            break;
+        }
+        case SIGSTOP:     
+        {
+            // remove TXT ownership from target process 
+            process_txt_reset_ownership( owner_xp );
+
+            // block all threads in all clusters
+            process_sigaction( owner_ptr , BLOCK_ALL_THREADS );
+
+            // atomically update reference process termination state
+            hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) ,
+                                  PROCESS_FLAG_BLOCK );
+ 
+            retval = 0;
+            break;
+        }
+        case SIGCONT:
+        {
+            // unblock all threads in all clusters
+            process_sigaction( owner_ptr , UNBLOCK_ALL_THREADS );
+
+            // atomically update reference process termination state
+            hal_remote_atomic_and( XPTR( owner_cxy , &owner_ptr->term_state ) ,
+                                   ~PROCESS_FLAG_BLOCK );
+            retval = 0;
+            break;
+        }
+        break;
+        case SIGKILL:
+        {
+            // the process_make_kill() function must be executed
+            // by an RPC thread in process owner cluster
+            // It deletes all target process threads in all clusters, 
+            // and updates the process termination state 
+            rpc_process_make_kill_client( owner_cxy , owner_ptr , false , 0 );
+
+            retval = 0;
+            break;
+        }
+        default:
+        {
+
+syscall_dmsg("\n[ERROR] in %s : illegal signal type %d for process %x\n",
+__FUNCTION__ , sig_id , pid );
+
+    	    this->errno = EINVAL;
+            retval = -1;
+            break;
+        }
     }
-    else                                                      // owner cluster is remote
-    {
-        rpc_process_make_kill_client( process_cxy , pid , sig_id );
-    }
-
+    
     // restore IRQs
     hal_restore_irq( save_sr );
@@ -115,11 +157,12 @@
     hal_fence();
 
-#if CONFIG_SYSCALL_DEBUG 
+#if CONFIG_DEBUG_SYS_KILL
 tm_end = hal_get_cycles();
-printk("\n[DBG] %s : core[%x,%d] exit / process %x / sig %d / cost = %d\n",
-__FUNCTION__ , local_cxy , this->core->lid , pid, sig_id, (uint32_t)(tm_end - tm_start) );
+if( CONFIG_DEBUG_SYS_KILL < tm_end )
+printk("\n[DBG] %s : thread %x enter / process %x / sig %d / cost = %d / cycle %d\n",
+__FUNCTION__ , this, pid, sig_id, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
 #endif
- 
-	return 0;
+
+	return retval;
 
 }  // end sys_kill()
