Index: trunk/kernel/kern/process.h
===================================================================
--- trunk/kernel/kern/process.h	(revision 408)
+++ trunk/kernel/kern/process.h	(revision 409)
@@ -54,4 +54,15 @@
 
 /*********************************************************************************************
+ * This enum defines the actions that can be executed by the process_signal() function.
+ ********************************************************************************************/
+
+enum process_sigactions
+{
+    BLOCK_ALL_THREADS,
+    UNBLOCK_ALL_THREADS,
+    DELETE_ALL_THREADS,
+};
+
+/*********************************************************************************************
  * This structure defines an array of extended pointers on the open file descriptors
  * for a given process. We use an extended pointer because the open file descriptor
@@ -76,15 +87,15 @@
  * - The PID 16 LSB bits contain the LPID (Local Process Index)
  * - The PID 16 MSB bits contain the owner cluster CXY.
- * In each cluster, the process manager allocates LPID values for the process that are
- * allocated to this cluster.
- * The process descriptor for a PID process is replicated in all clusters containing
- * at least one thread of the PID process, with the following rules :
- *
+ * In each cluster, the process manager allocates  the LPID values for the process that
+ * are owned by this cluster.
+ * The process descriptor is replicated in all clusters containing at least one thread 
+ * of the PID process, with the following rules :
  * 1) The <pid>, <ppid>, <ref_xp>, <vfs_root_xp>, <vfs_bin_xp>  fields are defined
  *    in all process descriptor copies.
  * 2) The <vfs_cwd_xp> and associated <cwd_lock>, that can be dynamically modified,
  *    are only defined in the reference process descriptor.
- * 2) The <vmm>, containing the list of registered vsegs, and the page table, are only
- *    complete in the reference process cluster, other copies are read-only caches.
+ * 2) The <vmm>, containing the VSL (list of registered vsegs), and the GPT (generic
+ *    page table), are only complete in the reference process cluster, other copies 
+ *    are actually use as read-only caches.
  * 3) the <fd_array>, containing extended pointers on the open file descriptors, is only
  *    complete in the reference process cluster, other copies are read-only caches.
@@ -95,5 +106,4 @@
  * 6) The <brothers_list>, <local_list>, <copies_list>, <th_tbl>, <th_nr>, <th_lock> fields
  *    are defined in all process descriptors copies.
- * 7) The <sig_mgr> field is only defined in the reference cluster. TODO
  ********************************************************************************************/
 
@@ -130,6 +140,4 @@
 
     remote_spinlock_t sync_lock;        /*! lock protecting sem,mutex,barrier,condvar lists */
-
-	sig_mgr_t         sig_mgr;          /*! embedded signal manager TODO [AG]               */
 }
 process_t;
@@ -137,6 +145,5 @@
 /*********************************************************************************************
  * This structure defines the information required by the process_make_exec() function
- * to create a new reference process descriptor, and the associated main thread,
- * in the parent process owner cluster.
+ * to create a new reference process descriptor, and the associated main thread.
  ********************************************************************************************/
 
@@ -176,11 +183,11 @@
 /*********************************************************************************************
  * This function allocates memory and initializes the "process_init" descriptor and the
- * associated "thread_init" descriptor in the local cluster. It is called once at the end
- * of the kernel initialisation procedure, by the local kernel process.
+ * associated "thread_init" descriptor. It is called once at the end of the kernel 
+ * initialisation procedure, by the kernel process in cluster_IO.
  * The "process_init" is the first user process, and all other user processes will be forked
  * from this process. The code executed by "process_init" is stored in a .elf file, whose
- * pathname is defined by the CONFIG_PROCESS_INIT_PATH argument. 
- * Practically, it builds the exec_info structure, and calls the process_make_exec() 
- * function, that make the real job.
+ * pathname is defined by the CONFIG_PROCESS_INIT_PATH configuration variable. 
+ * The process_init streams are defined  by the CONFIG_INIT_[STDIN/STDOUT/STDERR] variables.
+ * Its local process identifier is 1, and parent process is the local kernel process_zero.
  ********************************************************************************************/
 void process_init_create();
@@ -200,15 +207,16 @@
  * descriptor, defined by the <model_xp> argument. The <process> descriptor, the <pid>, and
  * the <ppid> arguments must be previously defined by the caller.
- * It can be called by three functions, depending on the process type:
- * 1) if "process" is the user "process_init", the parent is the kernel process. It is
+ * It can be called by two functions, depending on the process type:
+ * 1) if "process" is the "process_init", the parent is the kernel process. It is
  *    called once, by the process_init_create() function in cluster[xmax-1][ymax-1].
  * 2) if the caller is the process_make_fork() function, the model is generally a remote
  *    process, that is also the parent process.
+
  * 3) if the caller is the process_make_exec() function, the model is always a local process,
- *    but the parent is the parent of the model process.
- *
+ *    and the parent is the parent of the model process. DEPRECATED [AG]
+
  * The following fields are initialised (for all process but process_zero).
  * - It set the pid / ppid / ref_xp fields.
- * - It initializes an empty VMM (no vsegs registered in VSL and GPT).
+ * - It initializes the VMM (register the kentry, args, envs vsegs in VSL)
  * - It initializes the FDT, defining the three pseudo files STDIN / STDOUT / STDERR.
  * - It set the root_xp, bin_xp, cwd_xp fields.
@@ -251,14 +259,79 @@
 
 /*********************************************************************************************
- * This function kills a user process in a given cluster.
- * It can be directly called in the reference cluster, or it can be called through the
- * PROCESS_KILL RPC.
- * - In a first loop, it set the THREAD_SIG_KILL signal to all threads of process.
- * - In a second loop, it wait, for each thread the reset of the THREAD_SIG_KILL signal
- *   by the scheduler, and completes the thread descriptor destruction.
+ * This function returns a printable string defining the action for process_signa().
+ *********************************************************************************************
+ * @ action_type   : BLOCK_ALL_THREADS / UNBLOCK_ALL_THREADS / DELETE_ALL_THREADS
+ * @ return a string pointer.
+ ********************************************************************************************/
+char * process_action_str( uint32_t action_type );
+
+/*********************************************************************************************
+ * This function allows any thread running in any cluster to block, unblock  or delete
+ * all threads of a given process identified by the <process> argument, dependig on the
+ * <acion_type> argument. 
+ * It can be called by the sys_kill() or sys_exit() functions to handle the "kill" & "exit"
+ * system calls, or by the process_make_exec() function to handle the "exec" system call.
+ * It must be executed in the owner cluster for the target process (using the relevant RPC
+ * (RPC_PROCESS_SIGNAL or RPC_PROCESS_EXEC) if the client thread in not running in the
+ * owner cluster.
+ * It uses the multicast, non blocking, RPC_PROCESS_KILL to send the signal to all process
+ * copies in parallel, block & deschedule when all signals have been sent, and finally
+ * returns only when all responses have been received and the operation is completed. 
  *********************************************************************************************
  * @ process     : pointer on the process descriptor.
- ********************************************************************************************/
-void process_kill( process_t * process );
+ * @ action_type   : BLOCK_ALL_THREADS / UNBLOCK_ALL_THREADS / DELETE_ALL_THREADS
+ ********************************************************************************************/
+void process_sigaction( process_t * process,
+                        uint32_t    action_type );
+
+/*********************************************************************************************
+ * This function blocks all threads of a given user process in a given cluster.
+ * It is always called by a local RPC thread, through the multicast RPC_PROCESS_KILL.
+ * It loop on all local threads of the process, requesting the relevant schedulers to
+ * block and deschedule these threads, using IPI if required. The threads are not detached 
+ * from the scheduler, and not detached from the local process.
+ * It acknowledges the client thread in the owner cluster only when all process threads
+ * are descheduled and blocked on the BLOCKED_GLOBAL condition, using the <rsp_xp> argument.
+ *********************************************************************************************
+ * @ process     : pointer on the target process descriptor.
+ * @ rsp_xp      : extended pointer on the response counter. 
+ * # client_xp   : extended pointer on client thread descriptor.
+ ********************************************************************************************/
+void process_block( process_t * process,
+                    xptr_t      rsp_xp,
+                    xptr_t      client_xp );
+
+/*********************************************************************************************
+ * This function unblocks all threads of a given user process in a given cluster.
+ * It is always called by a local RPC thread, through the multicast RPC_PROCESS_KILL.
+ * It loops on local threads of the process, to reset the BLOCKED_GLOBAL bit in all threads.
+ * It acknowledges directly the client thread in the owner cluster when this is done, 
+ * using the <rsp_xp> argument.
+ *********************************************************************************************
+ * @ process     : pointer on the process descriptor.
+ * @ rsp_xp      : extended pointer on the response counter. 
+ * # client_xp   : extended pointer on client thread descriptor.
+ ********************************************************************************************/
+void process_unblock( process_t * process,
+                      xptr_t      rsp_xp,
+                      xptr_t      client_xp );
+
+/*********************************************************************************************
+ * This function delete all threads descriptors, of given user process in a given cluster.
+ * It is always called by a local RPC thread, through the multicast RPC_PROCESS_KILL.
+ * It detach all process threads from the scheduler, detach the threads from the local
+ * process, and release the local memory allocated to threads descriptors (including the 
+ * associated structures such as CPU and FPU context). Finally, it release the memory
+ * allocated to the local process descriptor itself, but only when the local cluster
+ * is NOT the process owner, but only a copy.  It acknowledges directly the client thread 
+ * in the owner cluster, using ithe <rsp_xp> argument.
+ *********************************************************************************************
+ * @ process     : pointer on the process descriptor.
+ * @ rsp_xp      : extended pointer on the response counter. 
+ * # client_xp   : extended pointer on client thread descriptor.
+ ********************************************************************************************/
+void process_delete( process_t * process,
+                     xptr_t      rsp_xp,
+                     xptr_t      client_xp );
 
 /*********************************************************************************************
@@ -274,14 +347,13 @@
 
 /*********************************************************************************************
- * This function implements the exec() system call, and is called by the sys_exec() function.
- * It is also called by the process_init_create() function to build the "init" process.
+ * This function implements the "exec" system call, and is called by the sys_exec() function.
  * The "new" process keep the "old" process PID and PPID, all open files, and env variables,
  * the vfs_root and vfs_cwd, but build a brand new memory image (new VMM from the new .elf).
- * It actually creates a "new" reference process descriptor, saves all relevant information
- * from the "old" reference process descriptor to the "new" process descriptor.
+ * It actually creates a "new" reference process descriptor, and copies all relevant 
+ * information from the "old" process descriptor to the "new" process descriptor.
  * It completes the "new" process descriptor, from information found in the <exec_info> 
  * structure (defined in the process.h file), that must be built by the caller.
  * It creates and initializes the associated main thread. It finally destroys all copies 
- * of the "old" process in all clusters, and all the old associated threads.
+ * of the "old" process in all clusters, and destroys all old associated threads.
  * It is executed in the local cluster, that becomes both the "owner" and the "reference"
  * cluster for the "new" process.
@@ -293,11 +365,11 @@
 
 /*********************************************************************************************
- * This function implement the fork() system call, and is called by the sys_fork() function. 
+ * This function implements the "fork" system call, and is called by the sys_fork() function. 
  * It allocates memory and initializes a new "child" process descriptor, and the
  * associated "child" thread descriptor in the local cluster. This function can involve
  * up to three different clusters :
  * - the local (child) cluster can be any cluster defined by the sys_fork function.
- * - the parent cluster must be the reference clusterfor the parent process.
- * - the client cluster containing the thread requestingthe fork can be any cluster.
+ * - the parent cluster must be the reference cluster for the parent process.
+ * - the client cluster containing the thread requesting the fork can be any cluster.
  * The new "child" process descriptor is initialised from informations found in the "parent"
  * reference process descriptor, containing the complete process description.
@@ -315,4 +387,31 @@
                             pid_t            * child_pid, 
                             struct thread_s ** child_thread_ptr );
+
+/*********************************************************************************************
+ * This function implement the "exit" system call, and is called by the sys_exit() function.
+ * It must be executed by a thread running in the calling process owner cluster.
+ * It uses twice the multicast RPC_PROCESS_SIGNAL to first block all process threads
+ * in all clusters, and then delete all thread  and process descriptors.
+ *********************************************************************************************
+ * @ process  : pointer on process descriptor in owner cluster.
+ * @ status   : exit return value.
+ ********************************************************************************************/
+void process_make_exit( process_t * process,
+                        uint32_t    status );
+
+/*********************************************************************************************
+ * This function implement the "kill" system call, and is called by the sys_kill() function.
+ * It must be executed by a thread running in the target process owner cluster.
+ * Only the SIGKILL, SIGSTOP, and SIGCONT signals are supported.
+ * User defined handlers are not supported.
+ * It uses once or twice the multicast RPC_PROCESS_SIGNAL to block, unblock or delete
+ * all process threads in all clusters, and then delete process descriptors.
+ *********************************************************************************************
+ * @ process  : pointer on process descriptor in owner cluster.
+ * @ sig_id   : signal type.
+ ********************************************************************************************/
+void process_make_kill( process_t * process,
+                        uint32_t    sig_id );
+
 
 /********************   File Management Operations   ****************************************/
@@ -376,7 +475,8 @@
 
 /*********************************************************************************************
- * This function copies all non-zero entries from a remote <src_xp> fd_array,
- * embedded in a process descriptor, to another remote <dst_xp> fd_array, embedded
- * in another process descriptor. The calling thread can be running in any cluster.
+ * This function copies all non-zero entries (other than the three first stdin/stdout/stderr)
+ * from a remote <src_xp> fd_array, embedded in a process descriptor, to another remote 
+ * <dst_xp> fd_array, embedded in another process descriptor. 
+ * The calling thread can be running in any cluster.
  * It takes the remote lock protecting the <src_xp> fd_array during the copy.
  * For each involved file descriptor, the refcount is incremented.
