Index: trunk/kernel/kern/process.h
===================================================================
--- trunk/kernel/kern/process.h	(revision 623)
+++ trunk/kernel/kern/process.h	(revision 625)
@@ -228,16 +228,20 @@
 
 /*********************************************************************************************
- * This function initializes a reference, user process descriptor from another process
+ * This function initializes a reference user process descriptor from another process
  * descriptor, defined by the <parent_xp> argument. The <process> and <pid> arguments 
  * are previously allocated by the caller. This function can be called by two functions:
- * 1) process_init_create() : process is the INIT process; parent is process-zero.
+ * 1) process_init_create() : process is the INIT process, and parent is process-zero.
  * 2) process_make_fork() : the parent process descriptor is generally remote.
  * The following fields are initialised :
  * - It set the pid / ppid / ref_xp / parent_xp / state fields.
- * - It initializes the VMM (register the kentry, args, envs vsegs in VSL)
+ * - It creates an empty GPT and an empty VSL.
+ * - It initializes the locks protecting the GPT and the VSL.
+ * - It registers the "kernel" vsegs in VSL, using the hal_vmm_kernel_update() function.
+ * - It registers the "args" and "envs" vsegs in VSL, using the vmm_user_init() function.
+ * - The "code and "data" must be registered later, using the elf_load_process() function.
  * - It initializes the FDT, defining the three pseudo files STDIN / STDOUT / STDERR.
  *   . if INIT process     => link to kernel TXT[0].
- *   . if KSH[i] process   => allocate a free TXT[i] and give TXT ownership.
- *   . if USER process     => same TXT[i] as parent process and give TXT ownership.
+ *   . if KSH[i] process   => allocate a free TXT[i].
+ *   . if USER process     => link to parent process TXT[i].
  * - It set the root_xp, bin_xp, cwd_xp fields.
  * - It reset the children list as empty, but does NOT register it in parent children list.
@@ -251,16 +255,19 @@
  * @ pid          : [in] process identifier.
  * @ parent_xp    : [in] extended pointer on parent process descriptor.
- ********************************************************************************************/
-void process_reference_init( process_t * process,
-                             pid_t       pid,
-                             xptr_t      parent_xp );
+ * @ return 0 if success / return -1 if failure
+ ********************************************************************************************/
+error_t process_reference_init( process_t * process,
+                                pid_t       pid,
+                                xptr_t      parent_xp );
 
 /*********************************************************************************************
  * This function initializes a copy process descriptor, in the local cluster,
  * from information defined in the reference remote process descriptor.
+ * As the VSL and the GPT of a process copy are handled as local caches, the GPT copy is 
+ * created empty, and the VSL copy contains only the "kernel", "args", and "envs" vsegs. 
  *********************************************************************************************
  * @ process              : [in] local pointer on process descriptor to initialize.
  * @ reference_process_xp : [in] extended pointer on reference process descriptor.
- * @ return 0 if success / return ENOMEM if failure
+ * @ return 0 if success / return -1 if failure
  ********************************************************************************************/
 error_t process_copy_init( process_t * local_process,
@@ -272,5 +279,5 @@
  * The local th_tbl[] array must be empty.
  *********************************************************************************************
- * @ process     : pointer on the process descriptor.
+ * @ process     : [in] pointer on the process descriptor.
  ********************************************************************************************/
 void process_destroy( process_t * process );
@@ -283,5 +290,5 @@
  * taken by the caller function. 
  *********************************************************************************************
- * @ process_xp : extended pointer on process descriptor.
+ * @ process_xp    : [in] extended pointer on process descriptor.
  ********************************************************************************************/
 void process_display( xptr_t process_xp );
@@ -396,13 +403,13 @@
 /*********************************************************************************************
  * This function implements the "fork" system call, and is called by the sys_fork() function,
- * likely throuch the RPC_PROCESS_MAKE_FORK. 
- * It allocates memory and initializes a new "child" process descriptor, and the associated
- * "child" thread descriptor in local cluster. It involves up to three different clusters :
+ * likely through the RPC_PROCESS_MAKE_FORK. 
+ * It allocates memory and initializes a new child process descriptor, and the associated
+ * child thread descriptor in local cluster. It involves up to three different clusters:
  * - the child (local) cluster can be any cluster selected by the sys_fork function.
  * - 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"
+ * The new child process descriptor is initialised from informations found in the parent
  * reference process descriptor, containing the complete process description.
- * The new "child" thread descriptor is initialised from informations found in the "parent"
+ * The new child thread descriptor is initialised from informations found in the parent
  * thread descriptor.
  *********************************************************************************************
@@ -504,10 +511,12 @@
 
 /*********************************************************************************************
- * This function atomically registers a new thread in the local process descriptor.
- * It checks that there is an available slot in the local th_tbl[] array, and allocates
- * a new LTID using the relevant lock depending on the kernel/user type.
- *********************************************************************************************
- * @ process  : pointer on the local process descriptor.
- * @ thread   : pointer on new thread to be registered.
+ * This function atomically registers a new thread identified by the <thread> argument 
+ * in the th_tbl[] array of the local process descriptor identified by the <process>
+ * argument. It checks that there is an available slot in the local th_tbl[] array,
+ * and allocates a new LTID using the relevant lock depending on the kernel/user type,
+ * and returns the global thread identifier in the <trdid> buffer.
+ *********************************************************************************************
+ * @ process  : [in]  pointer on the local process descriptor.
+ * @ thread   : [in]  pointer on new thread to be registered.
  * @ trdid    : [out] buffer for allocated trdid.
  * @ returns 0 if success / returns non zero if no slot available.
@@ -516,4 +525,14 @@
                                  struct thread_s * thread,
                                  trdid_t         * trdid );
+
+/*********************************************************************************************
+ * This function atomically removes a thread identified by the <thread> argument from 
+ * the local process descriptor th_tbl[] array, and returns the number of thread currently
+ * registered in th_tbl[] array before this remove.
+ *********************************************************************************************
+ * @ thread   : pointer on thread to be removed.
+ * @ returns number of threads registered in th_tbl before thread remove.
+ ********************************************************************************************/
+uint32_t process_remove_thread( struct thread_s * thread );
 
 
@@ -556,8 +575,8 @@
 
 /*********************************************************************************************
- * This function gives a process identified by the <process_xp> argument the exclusive
+ * This function gives a process identified by the <process_xp> argument the 
  * ownership of its attached TXT_RX terminal (i.e. put the process in foreground).
- * It can be called by a thread running in any cluster, but the <process_xp> must be the
- * owner cluster process descriptor. 
+ * It can be called by a thread running in any cluster, but the target process descriptor
+ * must be the process owner.
  *********************************************************************************************
  * @ owner_xp  : extended pointer on process descriptor in owner cluster.
@@ -566,9 +585,8 @@
 
 /*********************************************************************************************
- * When the process identified by the <owner_xp> argument has the exclusive ownership of
- * the TXT_RX terminal, this function transfer this ownership to another attached process.
- * The process descriptor must be the process owner.
- * This function does nothing if the process identified by the <process_xp> is not 
- * the TXT owner.
+ * When the target process identified by the <owner_xp> argument has the exclusive ownership
+ * of the TXT_RX terminal, this function transfer this ownership to another process attached
+ * to the same terminal. The target process descriptor must be the process owner.
+ * This function does nothing if the target process is not the TXT owner.
  * - If the current owner is not the KSH process, the new owner is the KSH process.
  * - If the current owner is the KSH process, the new owner is another attached process.
