Index: trunk/kernel/kern/process.h
===================================================================
--- trunk/kernel/kern/process.h	(revision 407)
+++ trunk/kernel/kern/process.h	(revision 408)
@@ -137,11 +137,11 @@
 /*********************************************************************************************
  * This structure defines the information required by the process_make_exec() function
- * to create a new reference process descriptor, and the associated main thread.
+ * to create a new reference process descriptor, and the associated main thread,
+ * in the parent process owner cluster.
  ********************************************************************************************/
 
 typedef struct exec_info_s
 {
-    xptr_t             parent_xp;      /*! extended pointer on parent process descriptor    */
-    bool_t             keep_pid;       /*! keep parent PID if true / new PID if false       */
+    pid_t              pid;            /*! process identifier (both parent and child)       */
 
     char               path[CONFIG_VFS_MAX_PATH_LENGTH];   /*!  .elf file path              */
@@ -187,21 +187,46 @@
 
 /*********************************************************************************************
- * This function initializes a new process descriptor, in the reference cluster.
- * The PID value must have been defined previously by the owner cluster manager.
- * The reference cluster can be different from the owner cluster.
- * It set the pid / ppid / ref_xp fields.
- * It registers this process descriptor in three lists:
- * - the children_list in the parent reference process descriptor.
- * - the local_list, rooted in the reference cluster manager.
- * - the copies_list, rooted in the owner cluster manager.
- * It resets the embedded structures such as the VMM or the file descriptor array.
- *********************************************************************************************
- * @ process      : [in] pointer on process descriptor to initialize.
- * @ pid          : [in] process identifier defined by owner cluster.
- * @ parent_xp    : [in] extended pointer on parent process.
+ * This function initialize, in each cluster, the kernel "process_zero", that is the owner
+ * of all kernel threads in a given cluster. It is called by the kernel_init() function.
+ * Both the PID and PPID fields are set to zero, and the ref_xp is the local process_zero.
+ * The th_tbl[] is initialized as empty.
+ *********************************************************************************************
+ * @ process      : [in] pointer on local process descriptor to initialize.
+ ********************************************************************************************/
+void process_zero_init( process_t * process );
+
+/*********************************************************************************************
+ * This function initializes a local, reference user process descriptor from another process
+ * 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
+ *    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.
+ *
+ * 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 FDT, defining the three pseudo files STDIN / STDOUT / STDERR.
+ * - 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.
+ * - It reset the TH_TBL list of threads as empty.
+ * - It reset the semaphore / mutex / barrier / condvar lists as empty.
+ * - It registers the process in the local_list, rooted in the local cluster manager.
+ * - It registers the process in the copies_list, rooted in the owner cluster manager.
+ * - It registers the process extended pointer in the local pref_tbl[] array.
+ *********************************************************************************************
+ * @ process      : [in] pointer on local process descriptor to initialize.
+ * @ pid          : [in] process identifier.
+ * @ ppid         : [in] parent process identifier.
+ * @ model_xp     : [in] extended pointer on model process descriptor (local or remote).
  ********************************************************************************************/
 void process_reference_init( process_t * process,
                              pid_t       pid,
-                             xptr_t      parent_xp );
+                             pid_t       ppid,
+                             xptr_t      model_xp );
 
 /*********************************************************************************************
@@ -249,17 +274,16 @@
 
 /*********************************************************************************************
- * This function allocates memory and initializes a new user process descriptor,
- * and the associated main thread, from information found in the <exec_info> structure
- * (defined in the process.h file), that must be built by the caller.
- * - If the <keep_pid> field is true, the new process inherits its PID from the parent PID.
- * - If the <keep_pid> field is false, a new PID is allocated from the local cluster manager.
- * The new process inherits from the parent process (i) the open file descriptors, (ii) the
- * vfs_root and the vfs_cwd inodes.
- * It accesses the .elf file to get the size of the code and data segments, and initializes
- * the vsegs list in the VMM.
- * It is executed in the local cluster, that becomes both "owner" and "reference".
- * - It can be called by the process_init_create() function to build the "init" process.
- * - It can be called directly by the sys_exec() function in case of local exec.
- * - It can be called through the rpc_process_exec_server() function in case of remote exec.
+ * 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.
+ * 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 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.
+ * It is executed in the local cluster, that becomes both the "owner" and the "reference"
+ * cluster for the "new" process.
  *********************************************************************************************
  * @ exec_info   : [in]  pointer on the exec_info structure.
@@ -268,4 +292,27 @@
 error_t process_make_exec( exec_info_t * exec_info );
 
+/*********************************************************************************************
+ * This function implement 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 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"
+ * thread descriptor.
+ *********************************************************************************************
+ * @ parent_process_xp  : extended pointer on the reference parent process.
+ * @ parent_thread_xp   : extended pointer on the parent thread requesting the fork.
+ * @ child_pid          : [out] child process identifier.
+ * @ child_thread_ptr   : [out] local pointer on child thread in target cluster.
+ * @ return 0 if success / return non-zero if error.
+ ********************************************************************************************/
+error_t process_make_fork(  xptr_t             parent_process_xp,
+                            xptr_t             parent_thread_xp,
+                            pid_t            * child_pid, 
+                            struct thread_s ** child_thread_ptr );
 
 /********************   File Management Operations   ****************************************/
