casaroli commented on code in PR #19775:
URL: https://github.com/apache/nuttx/pull/19775#discussion_r4345600660


##########
arch/Kconfig:
##########
@@ -497,6 +497,7 @@ config ARCH_HAVE_VFORK
 
 config ARCH_HAVE_FORK
        bool
+       default y if ARCH_ARMV7A && ARCH_USE_MMU && !BUILD_PROTECTED

Review Comment:
   Done.



##########
arch/arm/Kconfig:
##########
@@ -1156,6 +1156,7 @@ config ARCH_CORTEXM7
 config ARCH_ARMV7A
        bool
        default n
+       select ARCH_HAVE_FORK if BUILD_KERNEL && ARCH_ADDRENV

Review Comment:
   Done.



##########
arch/arm/src/armv7-a/arm_addrenv.c:
##########
@@ -255,6 +255,125 @@ int up_addrenv_create(size_t textsize, size_t datasize, 
size_t heapsize,
   return ret;
 }
 
+#ifdef CONFIG_ARCH_HAVE_FORK
+/****************************************************************************
+ * Name: up_addrenv_fork
+ *
+ * Description:
+ *   Duplicate an address environment for POSIX fork().  The destination is
+ *   backed by fresh pages holding a copy of the source's contents, mapped at
+ *   the same virtual addresses.
+ *
+ *   Only the pages the source actually has mapped are duplicated, so the
+ *   cost is the size of the process, not the size of its address space.
+ *   There is no copy-on-write, so this needs as much free page memory as
+ *   the parent occupies and returns -ENOMEM when that is not available.
+ *
+ * Input Parameters:
+ *   src  - The address environment to be duplicated.
+ *   dest - The location to receive the duplicate.
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int up_addrenv_fork(FAR const arch_addrenv_t *src, FAR arch_addrenv_t *dest)

Review Comment:
   `up_addrenv_fork()` in include/nuttx/arch.h takes (src, dest), as 
`up_addrenv_clone()` does; arm64, x86_64 and esp32s3 use this order.



##########
arch/arm/src/armv7-a/arm_addrenv_utils.c:
##########
@@ -149,6 +149,132 @@ int arm_addrenv_create_region(uintptr_t *l1table, 
unsigned int listlen,
   return npages;
 }
 
+#ifdef CONFIG_ARCH_HAVE_FORK
+/****************************************************************************
+ * Name: arm_addrenv_fork_region
+ *
+ * Description:
+ *   Duplicate one memory region of an address environment for fork().
+ *
+ *   The destination gets its own L2 page tables and, unless `share' is
+ *   requested, its own physical pages holding a copy of the source's
+ *   contents.  Both are mapped at the same virtual addresses as the source,
+ *   which is what makes the duplicate an exact copy:  a pointer the parent
+ *   held into its own memory means the same thing in the child.
+ *
+ *   Only the sections the source actually has mapped are duplicated, so the
+ *   copy is the size of the parent, not the size of the region.
+ *
+ *   `share' maps the source's own pages into the destination rather than
+ *   copying them.  It is used for the shared memory region, which POSIX says
+ *   remains shared across fork().
+ *
+ * Input Parameters:
+ *   srcl1    - The L1 page table of the address environment to duplicate
+ *   destl1   - The L1 page table receiving the duplicate
+ *   listlen  - Number of sections in the region
+ *   vaddr    - Virtual base address of the region
+ *   mmuflags - L2 flags for the duplicated pages
+ *   share    - Map the source's pages rather than copying them
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.  On failure the
+ *   caller is expected to tear the destination down with
+ *   up_addrenv_destroy(), which copes with a partially built environment.
+ *
+ ****************************************************************************/
+
+int arm_addrenv_fork_region(uintptr_t *srcl1, uintptr_t *destl1,

Review Comment:
   It uses the order of `up_addrenv_fork(src, dest)`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to