xiaoxiang781216 commented on code in PR #6193:
URL: https://github.com/apache/incubator-nuttx/pull/6193#discussion_r863722914
##########
binfmt/libelf/libelf_addrenv.c:
##########
@@ -145,6 +145,92 @@ int elf_addrenv_alloc(FAR struct elf_loadinfo_s *loadinfo,
size_t textsize,
#endif
}
+/****************************************************************************
+ * Name: elf_addrenv_restore
+ *
+ * Description:
+ * Restore the address environment before elf_addrenv_select() was called..
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_ADDRENV
+int elf_addrenv_select(FAR struct elf_loadinfo_s *loadinfo)
+{
+ int ret;
+
+ /* Instantiate the new address environment */
+
+ ret = up_addrenv_select(&loadinfo->addrenv, &loadinfo->oldenv);
+ if (ret < 0)
+ {
+ berr("ERROR: up_addrenv_select failed: %d\n", ret);
+ return ret;
+ }
+
+ /* Allow write access to .text */
+
+ ret = up_addrenv_text_enable_write(&loadinfo->addrenv);
+ if (ret < 0)
+ {
+ berr("ERROR: up_addrenv_text_enable_write failed: %d\n", ret);
+ return ret;
+ }
+
+ return OK;
+}
+#endif
+
+/****************************************************************************
+ * Name: elf_addrenv_free
Review Comment:
correct the comment
##########
binfmt/libelf/libelf_addrenv.c:
##########
@@ -145,6 +145,92 @@ int elf_addrenv_alloc(FAR struct elf_loadinfo_s *loadinfo,
size_t textsize,
#endif
}
+/****************************************************************************
+ * Name: elf_addrenv_restore
Review Comment:
correct comment too
##########
include/nuttx/arch.h:
##########
@@ -1185,6 +1185,44 @@ int up_addrenv_attach(FAR struct task_group_s *group,
FAR struct tcb_s *tcb);
int up_addrenv_detach(FAR struct task_group_s *group, FAR struct tcb_s *tcb);
#endif
+/****************************************************************************
+ * Name: up_addrenv_text_enable_write
+ *
+ * Description:
+ * Temporarily enable write access to the .text section. This must be
+ * called prior to loading the process code into memory.
+ *
+ * Input Parameters:
+ * addrenv - The address environment to be modified.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_ADDRENV
+int up_addrenv_text_enable_write(FAR group_addrenv_t *addrenv);
Review Comment:
Since it's very useful to modify the permission for a memory region in other
case(e.g. mprotect/mmap). Could you generalize arch like
this(https://man7.org/linux/man-pages/man2/mprotect.2.html):
```
int up_addrenv_protect(FAR group_addrenv_t *addrenv, FAR void *addr, size_t
len, int prot);
```
and call this function from binfmt instead.
--
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]