arch/risc-v: Move ARCH_ADDRENV_VBASE to addrenv.h

Move the user address environment base address to a public header and
add riscv_uservaddr query
This commit is contained in:
Ville Juven 2023-05-23 16:39:16 +03:00 committed by Xiang Xiao
parent 0476e30a6d
commit 783f3f4c92
3 changed files with 33 additions and 12 deletions

View File

@ -44,6 +44,14 @@
# define ARCH_KERNEL_STACKSIZE STACK_ALIGN_UP(CONFIG_ARCH_KERNEL_STACKSIZE)
#endif
/* Base address for address environment */
#if CONFIG_ARCH_TEXT_VBASE != 0
# define ARCH_ADDRENV_VBASE (CONFIG_ARCH_TEXT_VBASE)
#else
# define ARCH_ADDRENV_VBASE (CONFIG_ARCH_DATA_VBASE)
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/

View File

@ -32,6 +32,8 @@
#include <stdint.h>
#include <string.h>
#include "addrenv.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@ -78,6 +80,24 @@ static inline uintptr_t riscv_pgvaddr(uintptr_t paddr)
}
#endif /* CONFIG_ARCH_PGPOOL_MAPPING */
/****************************************************************************
* Name: riscv_uservaddr
*
* Description:
* Return true if the virtual address, vaddr, lies in the user address
* space.
*
****************************************************************************/
static inline bool riscv_uservaddr(uintptr_t vaddr)
{
/* Check if this address is within the range of the virtualized .bss/.data,
* heap, or stack regions.
*/
return vaddr >= ARCH_ADDRENV_VBASE;
}
/****************************************************************************
* Name: riscv_pgwipe
*

View File

@ -68,6 +68,7 @@
#include <arch/barriers.h>
#include "addrenv.h"
#include "pgalloc.h"
#include "riscv_mmu.h"
@ -85,17 +86,9 @@
#define ENTRIES_PER_PGT (RV_MMU_PAGE_ENTRIES)
/* Base address for address environment */
#if CONFIG_ARCH_TEXT_VBASE != 0
# define ADDRENV_VBASE (CONFIG_ARCH_TEXT_VBASE)
#else
# define ADDRENV_VBASE (CONFIG_ARCH_DATA_VBASE)
#endif
/* Make sure the address environment virtual address boundary is valid */
static_assert((ADDRENV_VBASE & RV_MMU_SECTION_ALIGN) == 0,
static_assert((ARCH_ADDRENV_VBASE & RV_MMU_SECTION_ALIGN) == 0,
"Addrenv start address is not aligned to section boundary");
/****************************************************************************
@ -382,7 +375,7 @@ int up_addrenv_create(size_t textsize, size_t datasize, size_t heapsize,
uintptr_t heapbase;
DEBUGASSERT(addrenv);
DEBUGASSERT(MM_ISALIGNED(ADDRENV_VBASE));
DEBUGASSERT(MM_ISALIGNED(ARCH_ADDRENV_VBASE));
/* Make sure the address environment is wiped before doing anything */
@ -417,7 +410,7 @@ int up_addrenv_create(size_t textsize, size_t datasize, size_t heapsize,
database = resvbase + MM_PGALIGNUP(resvsize);
heapbase = CONFIG_ARCH_HEAP_VBASE;
#else
resvbase = ADDRENV_VBASE;
resvbase = ARCH_ADDRENV_VBASE;
resvsize = ARCH_DATA_RESERVE_SIZE;
textbase = resvbase + MM_PGALIGNUP(resvsize);
database = textbase + MM_PGALIGNUP(textsize);
@ -532,7 +525,7 @@ int up_addrenv_destroy(arch_addrenv_t *addrenv)
/* Things start from the beginning of the user virtual memory */
vaddr = ADDRENV_VBASE;
vaddr = ARCH_ADDRENV_VBASE;
pgsize = mmu_get_region_size(ARCH_SPGTS);
/* First destroy the allocated memory and the final level page table */