arch/addrenv: Change text write enable/disable to generic mprot

Implement a generic access rights modification procedure instead
of the procedures that only do one thing (enable/disable write)
to one section (text).
This commit is contained in:
Ville Juven
2022-05-12 11:55:50 +03:00
committed by Xiang Xiao
parent 072c28fe8e
commit 47e85b68fe
4 changed files with 71 additions and 88 deletions
+9 -2
View File
@@ -30,12 +30,17 @@
#include <nuttx/arch.h>
#include <nuttx/kmalloc.h>
#include <sys/mman.h>
#include "libelf.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ELF_TEXT_WRE (PROT_READ | PROT_WRITE | PROT_EXEC)
#define ELF_TEXT_WRD (PROT_READ | PROT_EXEC)
/****************************************************************************
* Private Constant Data
****************************************************************************/
@@ -175,7 +180,8 @@ int elf_addrenv_select(FAR struct elf_loadinfo_s *loadinfo)
/* Allow write access to .text */
ret = up_addrenv_text_enable_write(&loadinfo->addrenv);
ret = up_addrenv_mprot(&loadinfo->addrenv, loadinfo->textalloc,
loadinfo->textsize, ELF_TEXT_WRE);
if (ret < 0)
{
berr("ERROR: up_addrenv_text_enable_write failed: %d\n", ret);
@@ -207,7 +213,8 @@ int elf_addrenv_restore(FAR struct elf_loadinfo_s *loadinfo)
/* Remove write access to .text */
ret = up_addrenv_text_disable_write(&loadinfo->addrenv);
ret = up_addrenv_mprot(&loadinfo->addrenv, loadinfo->textalloc,
loadinfo->textsize, ELF_TEXT_WRD);
if (ret < 0)
{
berr("ERROR: up_addrenv_text_disable_write failed: %d\n", ret);