forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Elf loader: give temporary write access to user .text memory
When the .elf file is loaded from disk, the kernel must be given write access to the allocated .text section in the task's address environment. The access is removed after the elf is loaded and relocations are done. NOTE: The reason this works for the ARM implementation, is that the ARM MMU can be configured to give write access for the privileged mode, but revoke write access for the user mode. Regardless, it would be smart to revoke write access even for the kernel, when the kernel does not need it. This framework allows doing that, if someone wishes to take up the task.
- Loading branch information
Showing
5 changed files
with
224 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/**************************************************************************** | ||
* arch/risc-v/src/common/riscv_addrenv_perms.c | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
|
||
#include <errno.h> | ||
#include <assert.h> | ||
|
||
#include <nuttx/addrenv.h> | ||
#include <nuttx/arch.h> | ||
|
||
#include <arch/barriers.h> | ||
|
||
#include "pgalloc.h" | ||
#include "riscv_mmu.h" | ||
|
||
/**************************************************************************** | ||
* 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. | ||
* | ||
****************************************************************************/ | ||
|
||
int up_addrenv_text_enable_write(FAR group_addrenv_t *addrenv) | ||
{ | ||
#if 0 | ||
uintptr_t pgt; | ||
uintptr_t pte; | ||
int npages; | ||
int i; | ||
|
||
DEBUGASSERT(addrenv); | ||
DEBUGASSERT(MM_ISALIGNED(addrenv->textvbase)); | ||
DEBUGASSERT(MM_ISALIGNED(addrenv->datavbase)); | ||
|
||
/* Size of text region is base(data) - base(text) */ | ||
|
||
npages = MM_NPAGES(addrenv->datavbase - addrenv->textvbase); | ||
|
||
for (; npages > 0; npages--) | ||
{ | ||
|
||
} | ||
#endif | ||
UNUSED(addrenv); | ||
return OK; | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: up_addrenv_text_disable_write | ||
* | ||
* Description: | ||
* Disable write access to the .text section. This must be called after the | ||
* process code is loaded into memory. | ||
* | ||
* Input Parameters: | ||
* addrenv - The address environment to be modified. | ||
* | ||
* Returned Value: | ||
* Zero (OK) on success; a negated errno value on failure. | ||
* | ||
****************************************************************************/ | ||
|
||
int up_addrenv_text_disable_write(FAR group_addrenv_t *addrenv) | ||
{ | ||
UNUSED(addrenv); | ||
return OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters