Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/amd64/stand/prekern Fill in the page padding. Only ...
details: https://anonhg.NetBSD.org/src/rev/845d6eac7f84
branches: trunk
changeset: 827700:845d6eac7f84
user: maxv <maxv%NetBSD.org@localhost>
date: Thu Nov 09 15:24:39 2017 +0000
description:
Fill in the page padding. Only .text is pre-filled by the ld script, but
this will change in the future.
diffstat:
sys/arch/amd64/stand/prekern/elf.c | 8 ++++----
sys/arch/amd64/stand/prekern/mm.c | 26 +++++++++++++++++++++-----
sys/arch/amd64/stand/prekern/prekern.h | 16 +++++++++++++---
3 files changed, 38 insertions(+), 12 deletions(-)
diffs (165 lines):
diff -r 08f8032e2fb2 -r 845d6eac7f84 sys/arch/amd64/stand/prekern/elf.c
--- a/sys/arch/amd64/stand/prekern/elf.c Thu Nov 09 15:03:01 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/elf.c Thu Nov 09 15:24:39 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: elf.c,v 1.7 2017/11/05 16:26:15 maxv Exp $ */
+/* $NetBSD: elf.c,v 1.8 2017/11/09 15:24:39 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -345,7 +345,7 @@
ASSERT(minpa % PAGE_SIZE == 0);
*pa = minpa;
- *sz = roundup(maxpa - minpa, PAGE_SIZE);
+ *sz = maxpa - minpa;
}
void
@@ -392,7 +392,7 @@
ASSERT(minpa % PAGE_SIZE == 0);
*pa = minpa;
- *sz = roundup(maxpa - minpa, PAGE_SIZE);
+ *sz = maxpa - minpa;
}
void
@@ -439,7 +439,7 @@
ASSERT(minpa % PAGE_SIZE == 0);
*pa = minpa;
- *sz = roundup(maxpa - minpa, PAGE_SIZE);
+ *sz = maxpa - minpa;
}
void
diff -r 08f8032e2fb2 -r 845d6eac7f84 sys/arch/amd64/stand/prekern/mm.c
--- a/sys/arch/amd64/stand/prekern/mm.c Thu Nov 09 15:03:01 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/mm.c Thu Nov 09 15:24:39 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mm.c,v 1.8 2017/11/05 16:26:15 maxv Exp $ */
+/* $NetBSD: mm.c,v 1.9 2017/11/09 15:24:39 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -30,6 +30,10 @@
#include "prekern.h"
+#define PAD_TEXT 0xCC
+#define PAD_RODATA 0x00
+#define PAD_DATA 0x00
+
static const pt_entry_t protection_codes[3] = {
[MM_PROT_READ] = PG_RO | PG_NX,
[MM_PROT_WRITE] = PG_RW | PG_NX,
@@ -275,14 +279,15 @@
static void
mm_map_segments()
{
- size_t i, npages, size;
+ size_t i, npages, size, elfsz;
vaddr_t randva;
paddr_t pa;
/*
* Kernel text segment.
*/
- elf_get_text(&pa, &size);
+ elf_get_text(&pa, &elfsz);
+ size = roundup(elfsz, PAGE_SIZE);
randva = mm_randva_kregion(size);
npages = size / PAGE_SIZE;
@@ -293,6 +298,9 @@
}
elf_build_text(randva, pa);
+ /* Fill in the padding */
+ memset((void *)(randva + elfsz), PAD_TEXT, size - elfsz);
+
/* Register the values in bootspace */
bootspace.text.va = randva;
bootspace.text.pa = pa;
@@ -301,7 +309,8 @@
/*
* Kernel rodata segment.
*/
- elf_get_rodata(&pa, &size);
+ elf_get_rodata(&pa, &elfsz);
+ size = roundup(elfsz, PAGE_SIZE);
randva = mm_randva_kregion(size);
npages = size / PAGE_SIZE;
@@ -312,6 +321,9 @@
}
elf_build_rodata(randva, pa);
+ /* Fill in the padding */
+ memset((void *)(randva + elfsz), PAD_RODATA, size - elfsz);
+
/* Register the values in bootspace */
bootspace.rodata.va = randva;
bootspace.rodata.pa = pa;
@@ -320,7 +332,8 @@
/*
* Kernel data segment.
*/
- elf_get_data(&pa, &size);
+ elf_get_data(&pa, &elfsz);
+ size = roundup(elfsz, PAGE_SIZE);
randva = mm_randva_kregion(size);
npages = size / PAGE_SIZE;
@@ -331,6 +344,9 @@
}
elf_build_data(randva, pa);
+ /* Fill in the padding */
+ memset((void *)(randva + elfsz), PAD_DATA, size - elfsz);
+
/* Register the values in bootspace */
bootspace.data.va = randva;
bootspace.data.pa = pa;
diff -r 08f8032e2fb2 -r 845d6eac7f84 sys/arch/amd64/stand/prekern/prekern.h
--- a/sys/arch/amd64/stand/prekern/prekern.h Thu Nov 09 15:03:01 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/prekern.h Thu Nov 09 15:24:39 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: prekern.h,v 1.4 2017/11/05 16:26:15 maxv Exp $ */
+/* $NetBSD: prekern.h,v 1.5 2017/11/09 15:24:39 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -41,7 +41,6 @@
#define MM_PROT_EXECUTE 0x02
#define ASSERT(a) if (!(a)) fatal("ASSERT");
-#define memset(d, v, l) __builtin_memset(d, v, l)
#define memcpy(d, v, l) __builtin_memcpy(d, v, l)
typedef uint64_t paddr_t;
typedef uint64_t vaddr_t;
@@ -60,6 +59,18 @@
/* -------------------------------------------------------------------------- */
+static inline void
+memset(void *dst, char c, size_t sz)
+{
+ char *bdst = dst;
+ while (sz > 0) {
+ *bdst = c;
+ bdst++, sz--;
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+
struct bootspace {
struct {
vaddr_t va;
@@ -123,4 +134,3 @@
/* prekern.c */
void fatal(char *);
-
Home |
Main Index |
Thread Index |
Old Index