casaroli commented on code in PR #19772:
URL: https://github.com/apache/nuttx/pull/19772#discussion_r3757989412
##########
arch/xtensa/src/esp32s3/esp32s3_addrenv.c:
##########
@@ -577,6 +579,153 @@ int up_addrenv_clone(const arch_addrenv_t *src,
arch_addrenv_t *dest)
return OK;
}
+/****************************************************************************
+ * Name: copy_region
+ *
+ * Description:
+ * Copy one region's pages from a parent environment into a child's. Both
+ * sides are reached through the kernel's scratch region, which is why it
+ * has two slots: source and destination are mapped at the same time so
+ * this is one memcpy rather than a bounce through kernel memory.
+ *
+ * sched_lock() is held across each page pair for the reason every scratch
+ * mapping is: those addresses are ordinary external memory to the
+ * permission control, so no unprivileged task may run while a page of
+ * somebody's memory is parked at one.
+ *
+ ****************************************************************************/
+
+static int copy_region(const uintptr_t *src, uintptr_t *dest, uint16_t count)
+{
+ uint16_t i;
+
+ for (i = 0; i < count; i++)
+ {
+ uintptr_t svaddr;
+ uintptr_t dvaddr;
+
+ sched_lock();
+
+ svaddr = esp32s3_pgmap(src[i]);
+ dvaddr = esp32s3_pgmap(dest[i]);
+
+ if (svaddr == 0 || dvaddr == 0)
+ {
+ if (svaddr != 0)
+ {
+ esp32s3_pgunmap(svaddr);
+ }
+
+ if (dvaddr != 0)
+ {
+ esp32s3_pgunmap(dvaddr);
+ }
+
+ sched_unlock();
+ berr("ERROR: no scratch mapping for page %u\n", i);
+ return -EFAULT;
+ }
+
+ memcpy((void *)dvaddr, (const void *)svaddr, MM_PGSIZE);
+
+ esp32s3_pgunmap(dvaddr);
+ esp32s3_pgunmap(svaddr);
+
+ sched_unlock();
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * Name: up_addrenv_fork
+ *
+ * Description:
+ * Duplicate an address environment for fork(): allocate the child pages
+ * to match the parent's regions and copy the parent's contents into them.
+ *
+ * The copy is eager and complete. There is no copy-on-write and no demand
+ * fill, because this chip provides no synchronous restartable write fault
+ * to build them on -- proven, not assumed. So a fork costs a full copy of
+ * the process image.
+ *
+ * The child's pages land at the same *virtual* addresses as the parent's,
+ * which is the property the whole thing rests on: a copied stack is full
+ * of pointers into itself, and they are only still correct because the
+ * copy is addressed identically.
+ *
+ ****************************************************************************/
+
+int up_addrenv_fork(const arch_addrenv_t *src, arch_addrenv_t *dest)
Review Comment:
the ESP32 has no instruction-bus path to external RAM, so no page-backed
text. Looks like this is specific to esp32s3 (and maybe possibly esp32s2)
--
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]