From 8f9430f3fefc8feb9e9c3e2ddb9c7aa6f7999569 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 6 Mar 2017 23:32:42 +0100 Subject: [PATCH] move architecture dependent part to a subdirectory of arch --- arch/x86/include/asm/page.h | 3 +++ arch/x86/mm/Makefile | 2 +- {mm => arch/x86/mm}/memory.c | 0 include/hermit/vma.h | 12 ++++++++- mm/Makefile | 2 +- mm/malloc.c | 10 ++------ mm/shm.c | 50 ------------------------------------ mm/vma.c | 21 ++++----------- 8 files changed, 23 insertions(+), 77 deletions(-) rename {mm => arch/x86/mm}/memory.c (100%) delete mode 100644 mm/shm.c diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index bb6932f28..cac2e633b 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -36,6 +36,7 @@ #include #include +#include #ifndef __PAGE_H__ #define __PAGE_H__ @@ -144,6 +145,8 @@ static inline size_t sign_extend(ssize_t addr, int bits) /// Disable execution for this page #define PG_XD (1L << 63) +#define PG_NX (has_nx() ? PG_XD : 0) + /** @brief Converts a virtual address to a physical * * A non mapped virtual address causes a pagefault! diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile index 2f9b1834a..116c73106 100644 --- a/arch/x86/mm/Makefile +++ b/arch/x86/mm/Makefile @@ -1,4 +1,4 @@ -C_source := page.c +C_source := memory.c vma.c page.c MODULE := arch_x86_mm include $(TOPDIR)/Makefile.inc diff --git a/mm/memory.c b/arch/x86/mm/memory.c similarity index 100% rename from mm/memory.c rename to arch/x86/mm/memory.c diff --git a/include/hermit/vma.h b/include/hermit/vma.h index fb17c5975..1965f4ca4 100644 --- a/include/hermit/vma.h +++ b/include/hermit/vma.h @@ -96,7 +96,17 @@ typedef struct vma { */ int vma_init(void); -/** @brief Add a new virtual memory area to the list of VMAs +/** @brief Initalize the kernelspace VMA list + * + * Reserves several architecture-relevant virtual memory regions + * + * @return + * - 0 on success + * - <0 on failure + */ +int vma_arch_init(void); + +/** @brief Add a new virtual memory area to the list of VMAs * * @param start Start address of the new area * @param end End address of the new area diff --git a/mm/Makefile b/mm/Makefile index dbcf4aabe..709fdd5fd 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -1,4 +1,4 @@ -C_source := memory.c malloc.c vma.c shm.c hbmemory.c +C_source := malloc.c vma.c hbmemory.c MODULE := mm include $(TOPDIR)/Makefile.inc diff --git a/mm/malloc.c b/mm/malloc.c index 65b04d0a5..7bdafc67d 100644 --- a/mm/malloc.c +++ b/mm/malloc.c @@ -152,10 +152,7 @@ void* palloc(size_t sz, uint32_t flags) } //TODO: interpretation of from (vma) flags is missing - bits = PG_RW|PG_GLOBAL; - // protect heap by the NX flag - if (has_nx()) - bits |= PG_XD; + bits = PG_RW|PG_GLOBAL|PG_NX; // map physical pages to VMA err = page_map(viraddr, phyaddr, npages, bits); @@ -191,10 +188,7 @@ void* create_stack(size_t sz) return NULL; } - bits = PG_RW|PG_GLOBAL; - // protect heap by the NX flag - if (has_nx()) - bits |= PG_XD; + bits = PG_RW|PG_GLOBAL|PG_NX; // map physical pages to VMA err = page_map(viraddr+PAGE_SIZE, phyaddr, npages, bits); diff --git a/mm/shm.c b/mm/shm.c deleted file mode 100644 index 983d6d9b1..000000000 --- a/mm/shm.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2015, Stefan Lankes, RWTH Aachen University - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#if 0 -int shmget(key_t key, size_t size, int shmflg) -{ - return 0; -} - -void *shmat(int shmid, const void *shmaddr, int shmflg) -{ - return NULL; -} - -int shmdt(const void *shmaddr) -{ - return 0; -} - -int shmctl(int shmid, int cmd, struct shmid_ds *buf) -{ - return 0; -} -#endif diff --git a/mm/vma.c b/mm/vma.c index f2e1ba652..3f9691aef 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -32,9 +32,8 @@ #include #include #include -#include -/* +/* * Note that linker symbols are not variables, they have no memory allocated for * maintaining a value, rather their address is their value. */ @@ -43,7 +42,7 @@ extern const void kernel_end; /* * Kernel space VMA list and lock - * + * * For bootstrapping we initialize the VMA list with one empty VMA * (start == end) and expand this VMA by calls to vma_alloc() */ @@ -51,8 +50,6 @@ static vma_t vma_boot = { VMA_MIN, VMA_MIN, VMA_HEAP }; static vma_t* vma_list = &vma_boot; static spinlock_irqsave_t vma_lock = SPINLOCK_IRQSAVE_INIT; -// TODO: we might move the architecture specific VMA regions to a -// seperate function arch_vma_init() int vma_init(void) { int ret; @@ -73,17 +70,9 @@ int vma_init(void) if (BUILTIN_EXPECT(ret, 0)) goto out; - if (mb_info) { - ret = vma_add((size_t)mb_info & PAGE_MASK, ((size_t)mb_info & PAGE_MASK) + PAGE_SIZE, VMA_READ|VMA_WRITE); - if (BUILTIN_EXPECT(ret, 0)) - goto out; - - if ((mb_info->cmdline & PAGE_MASK) != ((size_t) mb_info & PAGE_MASK)) { - ret = vma_add((size_t)mb_info->cmdline & PAGE_MASK, ((size_t)mb_info->cmdline & PAGE_MASK) + PAGE_SIZE, VMA_READ|VMA_WRITE); - if (BUILTIN_EXPECT(ret, 0)) - goto out; - } - } + // we might move the architecture specific VMA regions to a + // seperate function vma_arch_init() + ret = vma_arch_init(); out: return ret;