Ignore:
Timestamp:
Nov 19, 2020, 11:44:34 PM (3 years ago)
Author:
alain
Message:

1) Introduce up to 4 command lines arguments in the KSH "load" command.
These arguments are transfered to the user process through the
argc/argv mechanism, using the user space "args" vseg.

2) Introduce the named and anonymous "pipes", for inter-process communication
through the pipe() and mkfifo() syscalls.

3) Introduce the "chat" application to validate the two above mechanisms.

4) Improve printk() and assert() fonctions in printk.c.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/process.h

    r662 r669  
    7171 * This structure defines an array of extended pointers on the open file descriptors
    7272 * for a given process. The file descriptors are always stored in the same cluster
    73  * as the inode associated to the file. A free entry in this array contains XPTR_NULL.
     73 * as the object associated to the file descriptor (inode, socket, pipe, etc).
     74 * A free entry in this array contains XPTR_NULL.
    7475 * The array size is defined by the CONFIG_PROCESS_FILE_MAX_NR parameter.
    7576 *
    76  * NOTE: - Only the fd_array[] in the reference process contains the complete list of open
    77  *         files, and is protected by the lock against concurrent access.
    78  *       - the fd_array[] in a process copy is not used.
    79  *         open files to speed the fdid to xptr translation, but the "lock" and "max"
    80  *         fields are not significant for these copies.
     77 * NOTE: - Only the fd_array[] in the owner cluster process contains the complete list
     78 *         of open files, and is protected by the lock against concurrent access.
     79 *       - the fd_array[] in a process copy is only used to speed the fdid -> xptr
     80 *         translation, but the "lock" and "max" fields are not significant in these copies.
    8181 *       - The modifications made by the process_fd_register() function are only done
    8282 *         in the owner cluster.
    8383 *       - The modifications made by the process_fd_remove() function are done in the
    8484 *         owner cluster, and in all process_copies.
    85  *       - In case of miss on the local fd_array, the process_fd_get_xptr() access the
     85 *       - In case of miss on a local fd_array, the process_fd_get_xptr() access the
    8686 *         owner cluster fd_array, and update the fd_array local copy.
    8787 ********************************************************************************************/
     
    9494}
    9595fd_array_t;
     96
     97/*********************************************************************************************
     98 * This structure defines the information required by the process_make_exec() function
     99 * to create a new reference process descriptor, and the associated main thread.
     100 * All fields in this structure are filled by the sys_exec() function, using the
     101 * process_exec_get_strings() function.
     102 *
     103 * It contains three parts:
     104 * - the "path" field is a string defining the pathname of the .elf file.
     105 * - the "args_pointers" & "args_nr" fields define the arguments (one arg == one string).
     106 * - the "envs_pointers" & "envs_nr" fields define the env variables (one env == one string).
     107 *
     108 * For both the arguments, and the environment variables, the array of pointers and the
     109 * strings themselve are stored in kernel space in the same kernel buffer containing
     110 * an integer number of pages, defined by CONFIG_VMM_ARGS_SIZE and CONFIG_VMM_ENVS_SIZE.
     111 * This aligned kernel buffer (one or several contiguous physical pages) contains :
     112 * - in the first bytes, a fixed size kernel array of pointers on the strings.
     113 * - in the following bytes, the strings themselves.
     114 * The size of these arrays of pointers is defined by CONFIG_PROCESS_ARGS_MAX_NR
     115 * and CONFIG¨PROCESS_ENVS_MAX_NR.
     116 *
     117 * WARNING: The "args_pointers" & "envs_pointers" kernel buffer are directly mapped to
     118 *          the "args" and "envs" user vsegs to be accessed by the user process.
     119 *          Therefore, the arrays of pointers build by the sys_exec() function contain
     120 *          kernel pointers, but the process_make_exec() function replace these pointers
     121 *          by user pointers in the new process user space.
     122 ********************************************************************************************/
     123
     124typedef struct exec_info_s
     125{
     126    char           path[CONFIG_VFS_MAX_PATH_LENGTH];  /*! .elf file path in kernel space    */
     127
     128    char        ** args_pointers;  /*! pointer on array of pointers on strings              */
     129    uint32_t       args_nr;        /*! actual number of arguments                           */
     130
     131    char        ** envs_pointers;  /*! pointer on array of pointers on strings              */
     132    uint32_t       envs_nr;        /*! actual number of environment variables               */
     133    char         * envs_buf_free;  /*! local pointer on first free slot in strings buffer   */
     134}
     135exec_info_t;
    96136
    97137/*********************************************************************************************
     
    112152 *    are actually use as read-only caches.
    113153 * 3) the <fd_array>, containing extended pointers on the open file descriptors, is only
    114  *    complete in the reference process cluster, other copies are read-only caches.
     154 *    complete in the owner process cluster, other copies are read-only caches.
    115155 * 4) The <sem_root>, <mutex_root>, <barrier_root>, <condvar_root>, and the associated
    116156 *    <sync_lock>, dynamically allocated, are only defined in the reference cluster.
     
    129169    fd_array_t         fd_array;         /*! embedded open file descriptors array            */
    130170
     171    exec_info_t        exec_info;        /*! embedded structure for args & envs              */
     172
    131173    xptr_t             vfs_root_xp;      /*! extended pointer on VFS root inode              */
    132174    xptr_t             vfs_bin_xp;       /*! extended pointer on .elf file descriptor        */
     
    165207}
    166208process_t;
    167 
    168 /*********************************************************************************************
    169  * This structure defines the information required by the process_make_exec() function
    170  * to create a new reference process descriptor, and the associated main thread.
    171  ********************************************************************************************/
    172 
    173 typedef struct exec_info_s
    174 {
    175     char               path[CONFIG_VFS_MAX_PATH_LENGTH];   /*!  .elf file path              */
    176 
    177     char            ** args_pointers;  /*! physical base address of array of pointers       */
    178     char             * args_buf_base;  /*! physical base address of kernel args buffer      */
    179     uint32_t           args_nr;        /*! actual number of arguments                       */
    180 
    181     char            ** envs_pointers;  /*! physical base address of array of pointers       */
    182     char             * envs_buf_base;  /*! physical base address of kernel args buffer      */
    183     char             * envs_buf_free;  /*! physical address of first free slot in envs_buf  */
    184     uint32_t           envs_nr;        /*! actual number of environment variables           */
    185 }
    186 exec_info_t;
    187209
    188210/***************   Process Descriptor Operations    *****************************************/
     
    393415
    394416/*********************************************************************************************
    395  * This function implements the "exec" system call, and is called by the sys_exec() function.
     417 * This function is called twice by the sys_exec() function :
     418 * - to register the main() arguments (args) in the process <exec_info> structure.
     419 * - to register the environment variables (envs) in the <exec_info> structure.
     420 * In both cases the input is an array of NULL terminated string pointers in user space,
     421 * identified by the <u_pointers> argument. The strings can be dispatched anywhere in
     422 * the calling user process space. The max number of envs, and the max number of args are
     423 * defined by the CONFIG_PROCESS_ARGS_NR and CONFIG_PROCESS_ENVS_MAX_NR parameters.
     424 *********************************************************************************************
     425 * Implementation Note:
     426 * Both the array of pointers and the strings themselve are stored in kernel space in one
     427 * single, dynamically allocated, kernel buffer containing an integer number of pages,
     428 * defined by the CONFIG_VMM_ENVS_SIZE and CONFIG_VMM_STACK_SIZE parameters.
     429 * This aligned kernel buffer (one or several contiguous physical pages) contains :
     430 * - in the first bytes a fixed size kernel array of kernel pointers on the strings.
     431 * - in the following bytes the strings themselves.
     432 * All the pointers, and the actual number of strings are stored in the process exec_info
     433 * structure defined in the <process.h> file.
     434 *********************************************************************************************
     435 * @ is_args     : [in]    true if called for (args) / false if called for (envs).
     436 * @ u_pointers  : [in]    array of pointers on the strings (in user space).
     437 * @ exec_info   : [inout] pointer on the exec_info structure.
     438 * @ return 0 if success / non-zero if too many strings or no memory.
     439 ********************************************************************************************/
     440error_t process_exec_get_strings( bool_t         is_args,
     441                                  char        ** u_pointers,
     442                                  exec_info_t  * exec_info );
     443
     444/*********************************************************************************************
     445 * This function implements the "execve" system call, and is called by sys_exec() function.
     446 * It must be called by the main thread of the calling "old" process.
     447 * The <exec_info> structure in process descriptor contains all informations required
     448 * to update both the calling process descriptor and the calling thread descriptor.
    396449 * The "new" process keep the "old" process PID and PPID, all open files, and env variables,
    397  * the vfs_root and vfs_cwd, but build a brand new memory image (new VMM from the new .elf).
     450 * the vfs_root and vfs_cwd, but build a brand new memory image (new VMM from the .elf file).
    398451 * It is executed in the local cluster, that becomes both the "owner" and the "reference"
    399452 * cluster for the "new" process.
    400453 *********************************************************************************************
    401  * @ exec_info   : [in]  pointer on the exec_info structure.
     454 * Implementation note:
     455 * It executes the following sequence:
     456 * 1) it creates a file descriptor for the .elf file (pathname in exec_info).
     457 * 2) it deletes all other threads than the main thread, in all clusters.
     458 * 3) it reset the existing VMM (remove all user vsegs).
     459 * 4) it build the "args" user vseg from process exec_info, and registers in the VMM.
     460 * 5) TODO it build the "envs" user vseg from process exec_info, and registers in the VMM.
     461 * 6) it get the "code" and "data" user vsegs from the .elf file, and registers in the VMM.
     462 * 7) it allocates an user "stack" vseg, and registers in the VMM
     463 * 8) it calls thread_user_exec() to complete thread initialisation and jumps to user code.
     464 *********************************************************************************************
    402465 * @ return 0 if success / return non-zero if error.
    403466 ********************************************************************************************/
    404 error_t process_make_exec( exec_info_t * exec_info );
     467error_t process_make_exec( void );
    405468
    406469/*********************************************************************************************
     
    452515 * and return the slot index in the <fdid> buffer.
    453516 * It can be called by any thread in any cluster.
    454  * It takes the lock protecting the fd_array against concurrent accesses.
    455  * Note: we must use the owner process descriptor, because this fd_array must
    456  * contain all files open by a given process.
    457  *********************************************************************************************
    458  * @ process_xp : [in]  extended pointer on client reference process.
     517 * It takes the lock protecting the fd_array against concurrent slot allocations.
     518 * Note: we must use the owner process descriptor, because only this fd_array contains
     519 * all files open by a given process.
     520 *********************************************************************************************
     521 * @ process_xp : [in]  extended pointer on owner process.
    459522 * @ file_xp    : [in]  extended pointer on the file descriptor to be registered.
    460523 * @ fdid       : [out] buffer for allocated fd_array slot index.
     
    470533 * process descriptor, identified by the <process_xp> argument.
    471534 * It can be called by any thread in any cluster.
    472  * It takes the lock protecting the fd_array against concurrent accesses.
     535 * It takes the lock protecting the list of copies.
    473536 * Note: we must use the owner process descriptor, because only this owner cluster contains
    474537 * the complete list of process copies.
     
    523586
    524587/*********************************************************************************************
    525  * This function copies all non-zero entries (other than the three first stdin/stdout/stderr)
    526  * from a remote <src_xp> fd_array, embedded in a process descriptor, to another remote
    527  * <dst_xp> fd_array, embedded in another process descriptor.
    528  * The calling thread can be running in any cluster.
    529  * It takes the lock protecting the reference fd_array against concurrent accesses.
    530  * For each involved file descriptor, the refcount is incremented.
    531  *********************************************************************************************
    532  * @ dst_xp   : extended pointer on the destination fd_array_t.
    533  * @ src_xp   : extended pointer on the source fd_array_t.
    534  ********************************************************************************************/
    535 void process_fd_remote_copy( xptr_t dst_xp,
    536                              xptr_t src_xp );
     588 * This function scans all entries in a fd_array, identified by the <src_xp> argument, that
     589 * must be the process descriptor in owner cluster. For each non-zero entry, it allocates a
     590 * new file descriptor in the cluster containing the involved inode, and registers it in the
     591 * fd_array identified by the <dst_xp> argument, that must also be the process descriptor in
     592 * owner cluster. The calling thread itself can be running in any cluster.
     593 * It takes the lock protecting the <src_xp> fd_array against concurrent accesses.
     594 *********************************************************************************************
     595 * @ dst_xp   : extended pointer on the source process descriptor (in owner cluster).
     596 * @ src_xp   : extended pointer on the destination process descriptor (in owner cluster).
     597 ********************************************************************************************/
     598void process_fd_replicate( xptr_t dst_xp,
     599                           xptr_t src_xp );
    537600
    538601/*********************************************************************************************
     
    598661
    599662/*********************************************************************************************
    600  * This function attach a process, identified by the <process> argument to a TXT terminal,
     663 * This function attach a process, identified by the <process_xp> argument to a TXT terminal,
    601664 * identified by the <txt_id> channel index argument.
    602  * The process descriptor identified by the <process> argument must be in the owner cluster. 
    603  * It insert the process descriptor in the xlist rooted in the TXT_RX device.
     665 * The process descriptor identified by the <process_xp> argument must be in the owner
     666 * cluster. It insert the process descriptor in the xlist rooted in the TXT_RX device.
    604667 * It is called by the process_reference_init() function.
    605668 *********************************************************************************************
    606  * @ process  : local pointer on process descriptor.
    607  * @ txt_id   : TXT channel index.
    608  ********************************************************************************************/
    609 void process_txt_attach( process_t * process,
    610                          uint32_t    txt_id );
     669 * @ process_xp : extended pointer on process descriptor in owner cluster.
     670 * @ txt_id     : TXT channel index.
     671 ********************************************************************************************/
     672void process_txt_attach( xptr_t    process_xp,
     673                         uint32_t  txt_id );
    611674
    612675/*********************************************************************************************
     
    617680 * cluster, but the calling thread can be running in any cluster.
    618681 *********************************************************************************************
    619  * @ process_xp  : extended pointer on process descriptor.
     682 * @ process_xp  : extended pointer on process descriptor in owner cluster.
    620683 ********************************************************************************************/
    621684void process_txt_detach( xptr_t  process_xp );                     
     685
     686/*********************************************************************************************
     687 * This function returns the TXT terminal index allocated to a process identified by the
     688 * <process_xp> argument. The process descriptor identified by the <process_xp> argument
     689 * must be in the owner cluster, but the calling thread can be running in any cluster.
     690 *********************************************************************************************
     691 * @ process_xp  : extended pointer on process descriptor in owner cluster.
     692 ********************************************************************************************/
     693uint32_t process_txt_get_index( xptr_t process_xp );
    622694
    623695/*********************************************************************************************
     
    625697 * ownership of its attached TXT_RX terminal (i.e. put the process in foreground).
    626698 * It can be called by a thread running in any cluster, but the target process descriptor
    627  * must be the process owner.
     699 * must be in the owner cluster.
    628700 *********************************************************************************************
    629701 * @ owner_xp  : extended pointer on process descriptor in owner cluster.
     
    654726
    655727/*********************************************************************************************
    656  * This function returns an extended ponter on the current TXT owner process,
     728 * This function returns an extended pointer on the current TXT owner process,
    657729 * for the TXT terminal identified by the <channel> index.
    658730 *********************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.