Index: trunk/kernel/syscalls/sys_exec.c
===================================================================
--- trunk/kernel/syscalls/sys_exec.c	(revision 406)
+++ trunk/kernel/syscalls/sys_exec.c	(revision 407)
@@ -38,26 +38,4 @@
 
 ////////////////////////////////////////////////i//////////////////////////////////////
-// This static function is called by the sys_exec() function to register the .elf
-// pathname in the exec_info  structure, from a string stored in user space.
-////////////////////////////////////////////////i//////////////////////////////////////
-// @ exec_info : pointer on the exec_info structure.
-// @ pathname  : string containing the path to the .elf file (user space).
-// return 0 if success / non-zero if one string too long, or too many strings.
-///////////////////////////////////////////////////////////////////////////////////////
-static error_t process_exec_get_path( exec_info_t  * exec_info,
-                                      char         * pathname )
-{
-    error_t error;
-
-    // copy string to exec_info
-    error = hal_strcpy_from_uspace( &exec_info->path[0] , pathname ,
-                                    CONFIG_VFS_MAX_PATH_LENGTH );
-    if( error )
-        return EINVAL;
-
-    return 0;
-}
-
-////////////////////////////////////////////////i//////////////////////////////////////
 // This static function is called twice by the sys_exec() function :
 // - to register the main() arguments (args) in the exec_info structure.
@@ -71,7 +49,7 @@
 // to store the (args) and (envs) strings are configuration parameters.
 ///////////////////////////////////////////////////////////////////////////////////////
-// @ exec_info : pointer on the exec_info structure.
-// @ is_args   : true if called for (args) / false if called for (envs).
-// @ pointers  : array of pointers on the strings (in user space).
+// @ exec_info   : pointer on the exec_info structure.
+// @ is_args     : true if called for (args) / false if called for (envs).
+// @ u_pointers  : array of pointers on the strings (in user space).
 // @ return 0 if success / non-zero if too many strings or no more memory.
 ///////////////////////////////////////////////////////////////////////////////////////
@@ -173,112 +151,109 @@
 // This function build an exec_info_t structure containing all informations
 // required to create the new process descriptor and the associated thread.
-// It calls the static process_exec_get_path() and process_exec_get_strings() functions
-// to copy the .elf pathname, the main() arguments and the environment variables from
-// user buffers to the exec_info_t structure, and call the process_make_exec() function.
+// It calls the process_exec_get_strings() functions to copy the main() arguments and 
+// the environment variables from user buffers to the exec_info_t structure, allocate
+// and call the process_make_exec() function.
+// Finally, it destroys the calling thread and process. 
+// TODO : the args & envs arguments are not supported yet : both must be NULL 
 /////////////////////////////////////////////////////////////////////////////////////////
-int sys_exec( char  * filename,     // .elf file pathname
+int sys_exec( char  * pathname,     // .elf file pathname
               char ** args,         // process arguments
               char ** envs )        // environment variables
 {
-    exec_info_t  exec_info;         // structure to pass to process_make_exec()
-    error_t      error;
-    paddr_t      paddr;
-
+    exec_info_t   exec_info;        // structure to pass to process_make_exec()
+    error_t       error;
+
+	uint64_t      tm_start;
+	uint64_t      tm_end;
+
+	tm_start = hal_get_cycles();
+
+    // get pointers on parent process and thread
     thread_t   * this    = CURRENT_THREAD;
     process_t  * process = this->process;
-
-    // check argument fileme
-    error = vmm_v2p_translate( false , filename , &paddr );
+    pid_t        pid     = process->pid;
+
+exec_dmsg("\n[DBG] %s : core[%x,%d] enters for process %x / cycle %d\n",
+__FUNCTION__, local_cxy, this->core->lid, pid, (uint32_t)hal_get_cycles() );
+
+sched_display( 0 );
+
+    // check pathname length
+    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
+    {
+        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
+        this->errno = ENFILE;
+        return -1;
+    }
+
+    // copy pathname in exec_info structure (kernel space)
+    hal_strcpy_from_uspace( exec_info.path , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
+    // check args argument
+    assert( (args == NULL) , __FUNCTION__ , 
+    "args not supported yet\n" );
+
+    // check envs argument
+    assert( (envs == NULL) , __FUNCTION__ , 
+    "args not supported yet\n" );
+
+    // compute client_cxy (local cluster) and server_cxy (target cluster)
+    cxy_t     cxy_server = CXY_FROM_PID( pid );
+    cxy_t     cxy_client = local_cxy;
+
+    // register parent process in exec_info
+    exec_info.parent_xp   = process->ref_xp;
+
+    // new process keep the parent process PID
+    exec_info.keep_pid   = true;
+
+    // check and store args in exec_info structure if required
+    if( args != NULL )
+    {
+        if( process_exec_get_strings( &exec_info , true , args ) )
+        {
+            printk("\n[ERROR] in %s : cannot access args\n", __FUNCTION__ );
+            this->errno = error;
+            return -1;
+        }
+    }
+
+    // check and store envs in exec_info structure if required
+    if( envs != NULL )
+    {
+        if( process_exec_get_strings( &exec_info , false , envs ) )
+        {
+            printk("\n[ERROR] in %s : cannot access envs\n", __FUNCTION__ );
+            this->errno = error;
+            return -1;
+        }
+    }
+
+    // call process_make_exec (local or remote)
+    if( cxy_server == cxy_client )
+    {
+        error = process_make_exec( &exec_info );
+    }
+    else
+    {
+        rpc_process_exec_client( cxy_server , &exec_info , &error );
+    }
 
     if( error )
     {
-        printk("\n[ERROR] in %s : filename unmapped\n", __FUNCTION__ );
-        this->errno = EINVAL;
-        return -1;
-    }
-
-    // check argument fileme
-    error = vmm_v2p_translate( false , args , &paddr );
-
-    if( error )
-    {
-        printk("\n[ERROR] in %s : args unmapped\n", __FUNCTION__ );
-        this->errno = EINVAL;
-        return -1;
-    }
-
-    // check argument fileme
-    error = vmm_v2p_translate( false , envs , &paddr );
-
-    if( error )
-    {
-        printk("\n[ERROR] in %s : envs unmapped\n", __FUNCTION__ );
-        this->errno = EINVAL;
-        return -1;
-    }
-
-    // compute client_cxy (local cluster) and server_cxy (target cluster)
-    cxy_t     cxy_server = CXY_FROM_PID( process->pid );
-    cxy_t     cxy_client = local_cxy;
-    bool_t    is_local   = (cxy_server == cxy_client);
-
-    exec_dmsg("\n[DMSG] %s starts for process %x on core %d in cluster %x"
-                 " / target_cluster = %x / cycle %d\n",
-                 __FUNCTION__, process->pid , CURRENT_CORE->lid,
-                 cxy_client, cxy_server, hal_get_cycles());
-
-    // register reference parent process in exec_info
-    exec_info.parent_xp   = process->ref_xp;
-
-    // check pathname and store it in exec_info structure
-    error = process_exec_get_path( &exec_info , filename );
-
-    if ( error )
-    {
-        printk("\n[ERROR] in %s : elf pathname too long\n", __FUNCTION__ );
+        printk("\n[ERROR] in %s : cannot create new process %x in cluster %x\n",
+        __FUNCTION__, pid, cxy_server );
         this->errno = error;
         return -1;
     }
 
-    // check and store args in exec_info structure
-    error = process_exec_get_strings( &exec_info , true , args );
-
-    if( error )
-    {
-        printk("\n[ERROR] in %s : cannot access args\n", __FUNCTION__ );
-        this->errno = error;
-        return -1;
-    }
-
-    // check and store envs in exec_info structure
-    error = process_exec_get_strings( &exec_info , false , envs );
-
-    if( error )
-    {
-        printk("\n[ERROR] in %s : cannot access envs\n", __FUNCTION__ );
-        this->errno = error;
-        return -1;
-    }
-
-    exec_dmsg("\n[DMSG] %s starts exec for process %x at cycle %d\n",
-              __FUNCTION__, process->pid, hal_get_cycles() );
-
-    if( is_local )  error = process_make_exec( &exec_info );
-    else            rpc_process_exec_client( cxy_server , &exec_info , &error );
-
-    if( error )
-    {
-        printk("\n[ERROR] in %s : cannot create new process %x\n",
-               __FUNCTION__ , process->pid );
-        this->errno = error;
-        return -1;
-    }
-
-    exec_dmsg("\n[DMSG] %s completes exec for process %x at cycle %d\n",
-              __FUNCTION__, process->pid , hal_get_cycles() );
-
-    // delete the calling thread an process
-    thread_kill( CURRENT_THREAD );
-    process_kill( CURRENT_THREAD->process );
+    // FIXME delete the local process descriptor
+    // process_kill( process );
+
+    tm_end = hal_get_cycles();
+
+exec_dmsg("\n[DBG] %s : core[%x,%d] exit for process %x / cycle %d\n"
+"     pathname = %s / cost = %d\n",
+__FUNCTION__, local_cxy, this->core->lid, pid, (uint32_t)tm_start,
+exec_info.path , (uint32_t)(tm_end - tm_start) );
 
     return 0;
