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 Detect collisions from bootspac...
details: https://anonhg.NetBSD.org/src/rev/3872837b16ca
branches: trunk
changeset: 357449:3872837b16ca
user: maxv <maxv%NetBSD.org@localhost>
date: Sat Nov 11 13:50:57 2017 +0000
description:
Detect collisions from bootspace directly.
diffstat:
sys/arch/amd64/stand/prekern/mm.c | 28 +++++++++++-----------------
1 files changed, 11 insertions(+), 17 deletions(-)
diffs (64 lines):
diff -r 74123e81d12c -r 3872837b16ca sys/arch/amd64/stand/prekern/mm.c
--- a/sys/arch/amd64/stand/prekern/mm.c Sat Nov 11 12:51:05 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/mm.c Sat Nov 11 13:50:57 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mm.c,v 1.10 2017/11/11 12:51:06 maxv Exp $ */
+/* $NetBSD: mm.c,v 1.11 2017/11/11 13:50:57 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -238,18 +238,12 @@
static vaddr_t
mm_randva_kregion(size_t size)
{
- static struct {
- vaddr_t sva;
- vaddr_t eva;
- } regions[4];
- static size_t idx = 0;
+ vaddr_t sva, eva;
vaddr_t randva;
uint64_t rnd;
size_t i;
bool ok;
- ASSERT(idx < 4);
-
while (1) {
rnd = mm_rand_num64();
randva = rounddown(KASLR_WINDOW_BASE +
@@ -257,14 +251,18 @@
/* Detect collisions */
ok = true;
- for (i = 0; i < idx; i++) {
- if ((regions[i].sva <= randva) &&
- (randva < regions[i].eva)) {
+ for (i = 0; i < BTSPACE_NSEGS; i++) {
+ if (bootspace.segs[i].type == BTSEG_NONE) {
+ continue;
+ }
+ sva = bootspace.segs[i].va;
+ eva = sva + bootspace.segs[i].sz;
+
+ if ((sva <= randva) && (randva < eva)) {
ok = false;
break;
}
- if ((regions[i].sva < randva + size) &&
- (randva + size <= regions[i].eva)) {
+ if ((sva < randva + size) && (randva + size <= eva)) {
ok = false;
break;
}
@@ -274,10 +272,6 @@
}
}
- regions[idx].eva = randva;
- regions[idx].sva = randva + size;
- idx++;
-
mm_map_tree(randva, randva + size);
return randva;
Home |
Main Index |
Thread Index |
Old Index