Ignore:
Timestamp:
Dec 5, 2017, 4:20:07 PM (6 years ago)
Author:
alain
Message:

Fix several bugs in the fork() syscall.

File:
1 edited

Legend:

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

    r407 r408  
    3434#include <spinlock.h>
    3535#include <core.h>
     36#include <chdev.h>
    3637#include <cluster.h>
    3738#include <process.h>
     
    9697#define THREAD_BLOCKED_RPC       0x0200  /*! thread wait RPC completion               */
    9798
    98 #define THREAD_BLOCKED_DEV_QUEUE 0x2000  /*! thread DEV wait queue                    */
    9999#define THREAD_BLOCKED_DEV_ISR   0x4000  /*! thread DEV wait ISR                      */
    100100
     
    132132 * thread is registered in the local copy of the process descriptor.
    133133 *
    134  * WARNING : Don't modify the first 4 fields order, as this order is used by the
     134 * WARNING : Don't modify the first 3 fields order, as this order is used by the
    135135 * hal_kentry assembly code for the TSAR architecture.
    136136 **************************************************************************************/
     
    140140typedef struct thread_s
    141141{
    142         void              * cpu_context;     /*! used for context switch                  */
    143         void              * fpu_context;     /*! used for dynamic FPU allocation          */
     142        void              * cpu_context;     /*! pointer on CPU context switch            */
     143        void              * fpu_context;     /*! pointer on FPU context switch            */
     144    void              * uzone;           /*! pointer on uzone for hal_kentry          */
    144145
    145146        intptr_t            k_stack_base;    /*! kernel stack base address                */
     
    172173
    173174    uint32_t            flags;           /*! bit vector of flags                      */
    174     volatile uint32_t   blocked;         /*! bit vector of blocking causes            */
    175     volatile uint32_t   signals;         /*! bit vector of (KILL / SUICIDE) signals   */
     175    uint32_t            signals;         /*! bit vector of (KILL / SUICIDE) signals   */
     176    uint32_t            blocked;         /*! bit vector of blocking causes            */
    176177
    177178        error_t             errno;           /*! errno value set by last system call      */
     
    189190        list_entry_t        sched_list;      /*! member of threads attached to same core  */
    190191
    191     uint32_t            dev_channel;     /*! device channel for a DEV thread          */
     192    chdev_t           * chdev;           /*! chdev pointer (for a DEV thread only)    */
     193
     194    reg_t               save_sr;         /*! used by sched_yield() function           */
    192195
    193196    ioc_command_t       ioc_cmd;         /*! IOC device generic command               */
     
    222225
    223226/***************************************************************************************
    224  * This function allocates memory for a user thread descriptor in the local cluster,
    225  * and initializes it from information contained in the arguments.
    226  * It is used by the "pthread_create" system call.
    227  * The CPU context is initialized from scratch, and the "loadable" field is set.
    228  * The new thread is attached to the core specified in the <attr> argument.
     227 * This function is used by the pthread_create() system call to create a "new" thread
     228 * in an existing process. It allocates memory for an user thread descriptor in the
     229 * local cluster, and initializes it from information contained in the arguments.
     230 * The CPU context is initialized from scratch. If required by the <attr> argument,
     231 * the new thread is attached to the core specified in <attr>.
    229232 * It is registered in the local process descriptor specified by the <pid> argument.
    230233 * The thread descriptor pointer is returned to allow the parent thread to register it
     
    246249
    247250/***************************************************************************************
    248  * This function is used by the fork() system call to create the child process main
    249  * thread. It allocates memory for an user thread descriptor in the local cluster,
    250  * and initializes it from information contained in the calling thread descriptor.
     251 * This function is used by the sys_fork() system call to create the "child" thread
     252 * in the local cluster. It allocates memory for a thread descriptor, and initializes
     253 * it from the "parent" thread descriptor defined by the <parent_thread_xp> argument.
    251254 * The new thread is attached to the core that has the lowest load in local cluster.
    252  * It is registered in the child process descriptor defined by the <process> argument.
     255 * It is registered in the "child" process defined by the <child_process> argument.
    253256 * This new thread inherits its user stack from the parent thread, as it uses the
    254257 * Copy-On-Write mechanism to get a private stack when required.
     
    256259 * the Copy-On-Write mechanism cannot be used for kernel segments (because kernel
    257260 * uses physical addressing on some architectures).
    258  * The CPU and FPU execution contexts are created and linked to the new thread,
    259  * but the actual context copy is NOT done. The THREAD_BLOCKED_GLOBAL bit is set,
    260  * and the thread must be explicitely unblocked later to make the new thread runable.
    261  ***************************************************************************************
    262  * @ process      : local pointer on owner process descriptor.
    263  * @ stack_base   : user stack base address (from parent).
    264  * @ stack_size   : user stack size (from parent).
    265  * @ new_thread   : [out] address of buffer for new thread descriptor pointer.
    266  * @ returns 0 if success / returns ENOMEM if error.
    267  **************************************************************************************/
    268 error_t thread_user_fork( process_t * process,
    269                           intptr_t    stack_base,
    270                           uint32_t    stack_size,
    271                           thread_t ** new_thread );
     261 * The CPU and FPU execution contexts are created and linked to the new thread.
     262 * but the actual context copy is NOT done, and must be done by by the sys_fork().
     263 * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated to start.
     264 ***************************************************************************************
     265 * @ parent_thread_xp  : extended pointer on parent thread descriptor.
     266 * @ child_process     : local pointer on child process descriptor.
     267 * @ child_thread      : [out] address of buffer for child thread descriptor pointer.
     268 * @ returns 0 if success / returns -1 if error.
     269 **************************************************************************************/
     270error_t thread_user_fork( xptr_t      parent_thread_xp,
     271                          process_t * child_process,
     272                          thread_t ** child_thread );
    272273
    273274/***************************************************************************************
    274275 * This function allocates memory for a kernel thread descriptor in the local cluster,
    275  * and initializes it from arguments values, calling the thread_kernel_init() function,
    276  * that also allocates and initializes the CPU context.
     276 * and initializes it from arguments values.
     277 * It is called by kernel_init() to statically create all DEV server threads
     278 * It is also called to dynamically create RPC threads when required.
    277279 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.
    278280 ***************************************************************************************
     
    291293
    292294/***************************************************************************************
    293  * This function initializes an existing kernel thread descriptor from arguments values.
     295 * This function initializes an existing thread descriptor from arguments values.
    294296 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.
     297 * It is called by the kernel_init() function to initialize the IDLE thread.
    295298 ***************************************************************************************
    296299 * @ thread   : pointer on existing thread descriptor.
Note: See TracChangeset for help on using the changeset viewer.