Changeset 407 for trunk/kernel/mm/vmm.h


Ignore:
Timestamp:
Nov 7, 2017, 3:08:12 PM (7 years ago)
Author:
alain
Message:

First implementation of fork/exec.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/mm/vmm.h

    r406 r407  
    4040
    4141/*********************************************************************************************
    42  * This structure defines the STACK allocator used by the VMM to dynamically allocate
    43  * STACK vsegs requested or released by the user process.
    44  * This allocator handles a fixed size array of fixed size slots stores in the STACK zone.
     42 * This structure defines the STACK allocator used by the VMM to dynamically handle
     43 * a STACK vseg requested or released by an user process.
     44 * This allocator handles a fixed size array of fixed size slots in the STACK zone.
    4545 * The stack size and the number of slots are defined by the CONFIG_VMM_STACK_SIZE, and
    46  * CONFIG_THREAD
     46 * CONFIG_VMM_STACK_BASE parameters.
    4747 * Each slot can contain one user stack vseg. The first page in the slot is not allocated
    4848 * to detect stack overflow.
     
    5050 * All allocation / release operations are registered in the stack_bitmap, that completely
    5151 * define the STACK zone state.
    52  * In this implementation, the max number of slots is 32.
    5352 ********************************************************************************************/
    5453
     
    6261
    6362/*********************************************************************************************
    64  * This structure defines the MMAP allocator used by the VMM to dynamically allocate
     63 * This structure defines the MMAP allocator used by the VMM to dynamically handle 
    6564 * MMAP vsegs requested or released by an user process.
    6665 * This allocator should be only used in the reference cluster.
     
    9291 * This local VMM provides three main services:
    9392 * 1) It registers all vsegs statically or dynamically defined in the vseg list.
    94  * 2) It allocates virtual memory space for the STACKS and MMAP vsegs.
     93 * 2) It allocates virtual memory space for the STACKS and MMAP vsegs (FILE/ANON/REMOTE).
    9594 * 3) It contains the local copy of the generic page table descriptor.
    9695 ********************************************************************************************/
     
    9897typedef struct vmm_s
    9998{
    100         rwlock_t       vsegs_lock;         /*! lock protecting the vsegs list & radix tree      */
     99        rwlock_t       vsegs_lock;         /*! lock protecting the vsegs list                   */
    101100        list_entry_t   vsegs_root;         /*! all vsegs in same process and same cluster       */
    102101        uint32_t       vsegs_nr;           /*! total number of local vsegs                      */
     
    107106    mmap_mgr_t     mmap_mgr;           /*! embedded MMAP vsegs allocator                    */
    108107
    109         uint32_t       pgfault_nr;         /*! page fault counter                               */
     108        uint32_t       pgfault_nr;         /*! page fault counter (instrumentation)             */
    110109        uint32_t       u_err_nr;           /*! TODO ??? [AG]                                    */
    111110        uint32_t       m_err_nr;           /*! TODO ??? [AG]                                    */
     
    119118
    120119        intptr_t       entry_point;        /*! main thread entry point                          */
    121 
    122     vseg_t       * heap_vseg;          /*! pointer on local heap vseg descriptor            */
    123120}
    124121vmm_t;
    125122
    126123/*********************************************************************************************
    127  * This structure is used to store the arguments of the mmap() system call.
    128  ********************************************************************************************/
    129 
    130 typedef struct mmap_attr_s
    131 {
    132         void     * addr;            /*! requested virtual address (unused : should be NULL)     */
    133         uint32_t   length;          /*! requested vseg size (bytes)                             */
    134         uint32_t   prot;            /*! access modes                                            */
    135         uint32_t   flags;           /*! only MAP_FILE / MAP_ANON / MAP_PRIVATE / MAP_SHARED     */
    136         fdid_t     fdid;            /*! file descriptor index (if MAP_FILE is set)              */
    137         int32_t    offset;          /*! file offset (if MAP_FILE is set)                        */
    138 }
    139 mmap_attr_t;
    140 
    141 /*********************************************************************************************
    142124 * This function initialises the virtual memory manager attached to an user process.
    143  * - It registers the "kentry", "args", "envs" and "heap" vsegs in the vsegs list.
    144  *   The "code" and "data" vsegs are registered by the elf_load_process() function,
    145  *   the "stack" vsegs are registered by the thread_user_create() function, and the
    146  *   "mmap" vsegs are dynamically created by syscalls.
     125 * - It initializes the STACK and MMAP allocators.
     126 * - It registers the "kentry", "args", "envs" vsegs in the VSL.
     127 * - The "code" and "data" vsegs are registered by the elf_load_process() function.
     128 * - The "stack" vsegs are dynamically created by the thread_user_create() function.
     129 * - The "file", "anon", "remote" vsegs are dynamically created by the mmap() syscalls.
    147130 * - It initializes the generic page table, calling the HAL specific hal_gpt_init() function.
    148  *   For TSAR it map all pages for the "kentry" vseg, that must be identity mapping.
    149  * - It initializes the STAK and MMAP allocators.
     131 * - For TSAR it map all pages for the "kentry" vseg, that must be identity mapping.
    150132 * TODO : Any error in this function gives a kernel panic => improve error handling.
    151133 *********************************************************************************************
     
    155137
    156138/*********************************************************************************************
    157  * This function copies the content of a source VMM to a destination VMM.
     139 * This function displays on TXY0 the list or registered vsegs for a given <process>.
     140 * If the <mapping> argument is true, it displays for each vesg all mapped PTEs in GPT.
     141 *********************************************************************************************
     142 * @ process   : pointer on process descriptor.
     143 * @ mapping   : detailed mapping if true.
     144 ********************************************************************************************/
     145void vmm_display( struct process_s * process,
     146                  bool_t             mapping );
     147
     148/*********************************************************************************************
     149 * This function is called by the sys_fork() system call.
     150 * It copies the content of a parent process descriptor VMM to a child process VMM.
     151 * - All vsegs registered in the source VSL are copied in the destination VSL.
     152 * - All PTEs registered in the source GPT are copied in destination GPT. For all writable
     153 *   PTEs - but the FILE vsegs - the WRITABLE flag is reset and the COW flag is set in
     154 *   the destination GPT.
    158155 *********************************************************************************************
    159156 * @ dst_process   : pointer on destination process descriptor.
     
    187184/*********************************************************************************************
    188185 * This function allocates memory for a vseg descriptor, initialises it, and register it
    189  * in the VMM of the process. It checks the collision with pre-existing vsegs in VMM.
    190  * For STACK and MMAP types vseg, it does not use the base argument, but uses the VMM STACK
    191  * and MMAP specific allocators to get a base address in virtual space.
    192  * To comply with the "on-demand" paging policy, this function does NOT modify the
    193  * page table, and does not allocate physical memory for vseg data.
    194  *********************************************************************************************
    195  * @ vmm   : pointer on process descriptor.
    196  * @ base      : vseg base address
    197  * @ size      : vseg size (bytes)
    198  * @ type      : vseg type
    199  * @ returns pointer on vseg if success / returns NULL if no memory or conflict.
     186 * in the VMM of the local process descriptor, that should be the reference process.
     187 * For the 'stack", "file", "anon", & "remote" types, it does not use the <base> argument,
     188 * but uses the STACK and MMAP virtual memory allocators.
     189 * It checks collision with all pre-existing vsegs.
     190 * To comply with the "on-demand" paging policy, this function does NOT modify the page table,
     191 * and does not allocate physical memory for vseg data.
     192 * It should be called by a local thread (could be a RPC thread if the client thread is not
     193 * running in the regerence cluster).
     194 *********************************************************************************************
     195 * @ process     : pointer on local processor descriptor.
     196 * @ type        : vseg type.
     197 * @ base        : vseg base address (not used for dynamically allocated vsegs).
     198 * @ size        : vseg size (bytes).
     199 * @ file_offset : offset in file for CODE, DATA, FILE types.
     200 * @ file_size   : can be smaller than "size" for DATA type.
     201 * @ mapper_xp   : extended pointer on mapper for CODE, DATA, FILE types.
     202 * @ cxy         : physical mapping cluster (for non distributed vsegs).
     203 * @ returns pointer on vseg if success / returns NULL if no memory, or conflict.
    200204 ********************************************************************************************/
    201205vseg_t * vmm_create_vseg( struct process_s * process,
     206                          vseg_type_t        type,
    202207                          intptr_t           base,
    203                               intptr_t           size,
    204                               uint32_t           type );
     208                              uint32_t           size,
     209                          uint32_t           file_offset,
     210                          uint32_t           file_size,
     211                          xptr_t             mapper_xp,
     212                          cxy_t              cxy );
    205213
    206214/*********************************************************************************************
     
    245253/*********************************************************************************************
    246254 * This function removes a given region (defined by a base address and a size) from
    247  * the VMM of a given process descriptor. This can modify several vsegs:
     255 * the VMM of a given process descriptor. This can modify the number of vsegs:
    248256 * (a) if the region is not entirely mapped in an existing vseg, it's an error.
    249257 * (b) if the region has same base and size as an existing vseg, the vseg is removed.
     
    251259 * (d) if the removed region cut the vseg in three parts, it is modified, and a new
    252260 *     vseg is created with same type.
     261 * FIXME [AG] this function must be called by a thread running in the reference cluster,
     262 * and the VMM must be updated in all process descriptors copies.
    253263 *********************************************************************************************
    254264 * @ process   : pointer on process descriptor
     
    279289
    280290/*********************************************************************************************
    281  * This function is called by the generic exception handler when a page fault
     291 * This function is called by the generic exception handler when a page-fault event
    282292 * has been detected in a given cluster.
     293 * - If the local cluster is the reference, it call directly the vmm_get_pte() function.
    283294 * - If the local cluster is not the reference cluster, it send a RPC_VMM_GET_PTE
    284  *   to the reference cluster to get the missing PTE attributes and PPN, and update
    285  *   the local page table.
    286  * - If the local cluster is the reference, it call directly the vmm_get_pte() function.
     295 *   to the reference cluster to get the missing PTE attributes and PPN,
     296 *   and update the local page table.
    287297 *********************************************************************************************
    288298 * @ process   : pointer on process descriptor.
     
    294304
    295305/*********************************************************************************************
    296  * This function returns in the "attr" and "ppn" arguments the PTE associated to a given
    297  * VPN for a given process. This function must be called by a thread running in the
    298  * reference cluster. To get the PTE from another cluster, use the RPC_VMM_GET_PTE.
    299  * The vseg containing the searched VPN should be registered in the reference VMM.
    300  * If the PTE in the reference page table is unmapped, this function allocates the missing
    301  * physical page from the target cluster defined by the vseg type, initialize it,
    302  * and update the reference page table. It calls the RPC_PMEM_GET_PAGES to get and
    303  * initialize the missing physical page, if the target cluster is not the reference cluster.
     306 * This function is called by the generic exception handler when a copy-on-write event
     307 * has been detected in a given cluster.
     308 * - If the local cluster is the reference, it call directly the vmm_get_pte() function.
     309 * - If the local cluster is not the reference cluster, it send a RPC_VMM_GET_PTE
     310 *   to the reference cluster to get the missing PTE attributes and PPN,
     311 *   and update the local page table.
     312 *********************************************************************************************
     313 * @ process   : pointer on process descriptor.
     314 * @ vpn       : VPN of the missing PTE.
     315 * @ returns 0 if success / returns ENOMEM if no memory.
     316 ********************************************************************************************/
     317error_t vmm_copy_on_write( struct process_s * process,
     318                           vpn_t              vpn );
     319
     320/*********************************************************************************************
     321 * This function is called when a new PTE (GPT entry) is required because a "page-fault",
     322 * or "copy-on_write" event has been detected for a given <vpn> in a given <process>.
     323 * The <cow> argument defines the type of event to be handled.
     324 * This function must be called by a thread running in reference cluster, and the vseg
     325 * containing the searched VPN should be registered in the reference VMM.
     326 * - for an actual page-fault, it allocates the missing physical page from the target cluster
     327 *   defined by the vseg type, initialize it, and update the reference page table.
     328 * - for a copy-on-write, it allocates a new physical page from the target cluster,
     329 *   initialise it from the old physical page, and update the reference page table.
     330 * In both cases, it calls the RPC_PMEM_GET_PAGES to get the new physical page if the
     331 * target cluster is not the reference cluster.
     332 * It returns in the <attr> and <ppn> arguments the accessed or modified PTE.
    304333 *********************************************************************************************
    305334 * @ process   : [in] pointer on process descriptor.
    306335 * @ vpn       : [in] VPN defining the missing PTE.
     336 * @ cow       : [in] "copy_on_write" if true / "page_fault" if false.
    307337 * @ attr      : [out] PTE attributes.
    308338 * @ ppn       : [out] PTE ppn.
     
    311341error_t vmm_get_pte( struct process_s * process,
    312342                     vpn_t              vpn,
     343                     bool_t             cow,
    313344                     uint32_t         * attr,
    314345                     ppn_t            * ppn );
Note: See TracChangeset for help on using the changeset viewer.