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

Fix several bugs in the fork() syscall.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/generic/hal_gpt.h

    r407 r408  
    3535//   dependent, and is defined as (CONFIG_USER_SPACE_SIZE / CONFIG_PPM_PAGE_SIZE).
    3636// - Each entry contains a Physical Page Number (ppn_t type), and a set of attributes,
    37 //   defined as masks on a 32 bits-vector.
     37//   defined as a 32 bits-vector.
    3838//
    3939// Any arch-specific implementation must implement this API.
     
    126126
    127127/****************************************************************************************
    128  * This function maps a page table entry identified by its VPN, from values defined
     128 * This function map a local GPT entry identified by its VPN, from values defined
    129129 * by the ppn and attr arguments. It allocates physical memory for the local generic
    130130 * page table itself if required.
     
    132132 * @ gpt       : [in] pointer on the page table
    133133 * @ vpn       : [in] virtual page number
     134 * @ attr      : [in] generic attributes
    134135 * @ ppn       : [in] physical page number
    135  * @ attr      : [in] generic attributes
    136136 * @ returns 0 if success / returns ENOMEM if error
    137137 ***************************************************************************************/
    138138error_t hal_gpt_set_pte( gpt_t    * gpt,
    139139                         vpn_t      vpn,
    140                          ppn_t      ppn,
    141                          uint32_t   attr );
     140                         uint32_t   attr,
     141                         ppn_t      ppn );
    142142
    143143/****************************************************************************************
     
    153153
    154154/****************************************************************************************
    155  * This function returns in the ppn and attr arguments the value of a page table
    156  * entry identified by its VPN.  It returns attr == 0 if the page is not mapped.
    157  ****************************************************************************************
    158  * @ gpt       : [in]  pointer on the page table
     155 * This function returns in the <attr> and <ppn> arguments the current values
     156 * stored in a GPT entry, identified by the <gpt> and <vpn> arguments.
     157 ****************************************************************************************
     158 * @ gpt_xp    : [in]  pointer on the page table
    159159 * @ vpn       : [in]  virtual page number
    160160 * @ attr      : [out] generic attributes
     
    167167
    168168/****************************************************************************************
    169  * This function is used to implement the "fork" system call: It copies all valid GPT
    170  * entries for a given vseg identified by the <vpn_base> and <vpn_size> arguments,
    171  * from the source <src_gpt> to the <dst_gpt>.
     169 * This function is used to implement the "fork" system call: It copies one GPT entry
     170 * identified by the <vpn> argument, from a remote <src_gpt_xp> to a local <dst_gpt>.
     171 * It does nothing if the source PTE is not MAPPED and SMALL.
    172172 * It optionnally activates the "Copy on Write" mechanism: when the <cow> argument is
    173  * true, the GPT_WRITABLE flag is reset, and the GPT_COW flag is set for each valid
    174  * entry in the destination GPT (The data page will be dynamically allocated an copied
    175  * when a write access is detected).
    176  ****************************************************************************************
    177  * @ dst_gpt   : [in]  pointer on the destination GPT.
    178  * @ src_gpt   : [in]  pointer on the source GPT.
    179  * @ vpn_base  : [in]  first vpn in vseg.
    180  * @ vpn_size  : [in]  number of pages in vseg.
    181  * @ cow       : [in]  activate the COPY-On-Write mechanism if true.
    182  ***************************************************************************************/
    183 error_t hal_gpt_copy( gpt_t    * dst_gpt,
    184                       gpt_t    * src_gpt,
    185                       vpn_t      vpn_base,
    186                       vpn_t      vpn_size,
    187                       bool_t     cow );
    188 
    189 /****************************************************************************************
    190  * This function returns GPT_COW flag for a PTE defined by <gpt> and <vpn> arguments.
     173 * true: the GPT_WRITABLE flag is reset, and the GPT_COW flag is set.
     174 * A new second level PT2(s) is allocated for destination GPT if required.
     175 * It returns in the <ppn> and <mapped> arguments the PPN value for the copied PTE,
     176 * and a boolean indicating if the PTE is mapped and small, and was actually copied.
     177 ****************************************************************************************
     178 * @ dst_gpt      : [in]  local pointer on the local destination GPT.
     179 * @ src_gpt_xp   : [in]  extended pointer on the remote source GPT.
     180 * @ vpn_base     : [in]  vpn defining the PTE to be copied.
     181 * @ cow          : [in]  activate the COPY-On-Write mechanism if true.
     182 * @ ppn          : [out] PPN value (only if mapped is true).
     183 * @ mapped       : [out] true if src_gpt[vpn] actually copied to dst_gpt[vpn].
     184 * @ return 0 if success / return -1 if no memory for a new PT2.
     185 ***************************************************************************************/
     186error_t hal_gpt_pte_copy( gpt_t    * dst_gpt,
     187                          xptr_t     src_gpt_xp,
     188                          vpn_t      vpn,
     189                          bool_t     cow,
     190                          ppn_t    * ppn,
     191                          bool_t   * mapped );
     192
     193/****************************************************************************************
     194 * This function returns true if the MAPPED and SMALL flags are both set
     195 * for a PTE defined by <gpt> and <vpn> arguments.
    191196 ****************************************************************************************
    192197 * @ gpt       : [in]  pointer on the page table
    193198 * @ vpn       : [in]  virtual page number
    194  * @ returns true if GPT_COW is set.
     199 * @ returns true if MAPPED is set.
     200 ***************************************************************************************/
     201bool_t hal_gpt_pte_is_mapped( gpt_t * gpt,
     202                              vpn_t   vpn );
     203
     204/****************************************************************************************
     205 * This function returns true if the MAPPED, SMALL, and COW flags are all set
     206 * for a PTE defined by <gpt> and <vpn> arguments.
     207 ****************************************************************************************
     208 * @ gpt       : [in]  pointer on the page table
     209 * @ vpn       : [in]  virtual page number
     210 * @ returns true if COW is set.
    195211 ***************************************************************************************/
    196212bool_t hal_gpt_pte_is_cow( gpt_t * gpt,
    197213                           vpn_t   vpn );
    198214
     215/****************************************************************************************
     216 * This function atomically flip the COW flag and WRITABLE flag for all PTEs
     217 * of a remote GPT identified by the <gpt_xp>, <vpn_base>, and <vpn_size arguments.
     218 * - it set COW and reset WRITABLE when <set_cow> argument is true and PTE is WRITABLE.
     219 * - it set WRITABLE and reset COW when <set_cow> is false and PTE is COW.
     220 * It does nothing if the remote PTE is not MAPPED and SMALL.
     221 * It is called when a fork is executed, or when a COW must be resolved.
     222 ****************************************************************************************
     223 * @ set_cow   : [in]  set COW & reset WRITABLE if true / do the opposite if false.
     224 * @ gpt_xp    : [in]  extended pointer on the remote GPT.
     225 * @ vpn_base  : [in]  first virtual page.
     226 * @ vpn_size  : [in]  number of pages.
     227 ***************************************************************************************/
     228void hal_gpt_flip_cow( bool_t  set_cow,
     229                       xptr_t  gpt_xp,
     230                       vpn_t   vpn_base,
     231                       vpn_t   vpn_size );
     232
     233/****************************************************************************************
     234 * This function is used to maintain coherence amongst the multiple GPT copies.
     235 * It modifies an existing entry identified by the <vpn> argument in a remote GPT
     236 * identified by the <gpt_xp> argument, using remote accesses.
     237 * It cannot fail, because only MAPPED & SMALL entries are modified.
     238 ****************************************************************************************
     239 * @ gpt_xp    : [in] extended pointer on the page table
     240 * @ vpn       : [in] virtual page number
     241 * @ attr      : [in] generic attributes
     242 * @ ppn       : [in] physical page number
     243 ***************************************************************************************/
     244void hal_gpt_update_pte( xptr_t     gpt_xp,
     245                         vpn_t      vpn,
     246                         uint32_t   attr,
     247                         ppn_t      ppn );
     248
    199249
    200250#endif  /* _GPT_H_ */
     251
Note: See TracChangeset for help on using the changeset viewer.