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 Small cleanup.
details: https://anonhg.NetBSD.org/src/rev/7eaa8c4e0379
branches: trunk
changeset: 357574:7eaa8c4e0379
user: maxv <maxv%NetBSD.org@localhost>
date: Wed Nov 15 20:45:16 2017 +0000
description:
Small cleanup.
diffstat:
sys/arch/amd64/stand/prekern/elf.c | 7 +------
sys/arch/amd64/stand/prekern/mm.c | 27 +++++++++++++++------------
sys/arch/amd64/stand/prekern/prekern.h | 3 +--
3 files changed, 17 insertions(+), 20 deletions(-)
diffs (121 lines):
diff -r 016ad0d9ec9c -r 7eaa8c4e0379 sys/arch/amd64/stand/prekern/elf.c
--- a/sys/arch/amd64/stand/prekern/elf.c Wed Nov 15 20:25:29 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/elf.c Wed Nov 15 20:45:16 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: elf.c,v 1.14 2017/11/15 18:02:36 maxv Exp $ */
+/* $NetBSD: elf.c,v 1.15 2017/11/15 20:45:16 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -372,11 +372,6 @@
print_state(true, "ELF info created");
/*
- * The loaded sections are: SHT_PROGBITS, SHT_NOBITS, SHT_STRTAB,
- * SHT_SYMTAB.
- */
-
- /*
* Update all symbol values with the appropriate offset.
*/
for (i = 0; i < eif.ehdr->e_shnum; i++) {
diff -r 016ad0d9ec9c -r 7eaa8c4e0379 sys/arch/amd64/stand/prekern/mm.c
--- a/sys/arch/amd64/stand/prekern/mm.c Wed Nov 15 20:25:29 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/mm.c Wed Nov 15 20:45:16 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mm.c,v 1.16 2017/11/15 20:25:29 maxv Exp $ */
+/* $NetBSD: mm.c,v 1.17 2017/11/15 20:45:16 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -36,6 +36,13 @@
#define ELFROUND 64
+static const int pads[4] = {
+ [BTSEG_NONE] = 0x00,
+ [BTSEG_TEXT] = 0xCC,
+ [BTSEG_RODATA] = 0x00,
+ [BTSEG_DATA] = 0x00
+};
+
#define MM_PROT_READ 0x00
#define MM_PROT_WRITE 0x01
#define MM_PROT_EXECUTE 0x02
@@ -107,7 +114,7 @@
}
static void
-mm_mprotect(vaddr_t startva, size_t size, int prot)
+mm_mprotect(vaddr_t startva, size_t size, pte_prot_t prot)
{
size_t i, npages;
vaddr_t va;
@@ -127,7 +134,7 @@
void
mm_bootspace_mprotect(void)
{
- int prot;
+ pte_prot_t prot;
size_t i;
/* Remap the kernel segments with proper permissions. */
@@ -242,7 +249,7 @@
}
static vaddr_t
-mm_randva_kregion(size_t size, size_t align)
+mm_randva_kregion(size_t size, size_t pagesz)
{
vaddr_t sva, eva;
vaddr_t randva;
@@ -253,7 +260,7 @@
while (1) {
rnd = mm_rand_num64();
randva = rounddown(KASLR_WINDOW_BASE +
- rnd % (KASLR_WINDOW_SIZE - size), align);
+ rnd % (KASLR_WINDOW_SIZE - size), pagesz);
/* Detect collisions */
ok = true;
@@ -329,6 +336,8 @@
elfalign = ELFROUND;
}
+ ASSERT(pagesz >= elfalign);
+ ASSERT(pagesz % elfalign == 0);
shiftsize = roundup(elfsz, pagesz) - roundup(elfsz, elfalign);
if (shiftsize == 0) {
return 0;
@@ -368,13 +377,7 @@
offset = mm_shift_segment(randva, pagesz, elfsz, elfalign);
ASSERT(offset + elfsz <= size);
- if (segtype == BTSEG_TEXT) {
- pad = PAD_TEXT;
- } else if (segtype == BTSEG_RODATA) {
- pad = PAD_RODATA;
- } else {
- pad = PAD_DATA;
- }
+ pad = pads[segtype];
memset((void *)randva, pad, offset);
memset((void *)(randva + offset + elfsz), pad, size - elfsz - offset);
diff -r 016ad0d9ec9c -r 7eaa8c4e0379 sys/arch/amd64/stand/prekern/prekern.h
--- a/sys/arch/amd64/stand/prekern/prekern.h Wed Nov 15 20:25:29 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/prekern.h Wed Nov 15 20:45:16 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: prekern.h,v 1.14 2017/11/15 18:44:34 maxv Exp $ */
+/* $NetBSD: prekern.h,v 1.15 2017/11/15 20:45:16 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -41,7 +41,6 @@
typedef uint64_t paddr_t;
typedef uint64_t vaddr_t;
typedef uint64_t pt_entry_t;
-typedef uint64_t pd_entry_t;
typedef uint64_t pte_prot_t;
#define WHITE_ON_BLACK 0x07
#define RED_ON_BLACK 0x04
Home |
Main Index |
Thread Index |
Old Index