summaryrefslogtreecommitdiff
path: root/sys/lib/libsa
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2015-05-19 20:39:13 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2015-05-19 20:39:13 +0000
commit60a000a861e81742782a8fc5125bb73e9dc735ce (patch)
treed36e1ffdde652c851c8d05a67910c1f1ba27d6fb /sys/lib/libsa
parent6b6152a27046c8f30dbcc9a56cde9a173caab6e4 (diff)
Extend the libsa loadfile(9) granularity to tell apart randomness from the rest
of the kernel, and extend the array filled by loadfile to report the location of the randomness area. This doesn't introduce any change for bootblocks (save for a slightly larger stack usage due to the larger array), for the new {LOAD,COUNT}_RANDOM bits are included in the {LOAD,COUNT}_ALL masks everything uses or computes from.
Diffstat (limited to 'sys/lib/libsa')
-rw-r--r--sys/lib/libsa/loadfile.h12
-rw-r--r--sys/lib/libsa/loadfile_elf.c9
2 files changed, 15 insertions, 6 deletions
diff --git a/sys/lib/libsa/loadfile.h b/sys/lib/libsa/loadfile.h
index 2c05e5a2a21..8cac6af5349 100644
--- a/sys/lib/libsa/loadfile.h
+++ b/sys/lib/libsa/loadfile.h
@@ -1,5 +1,5 @@
/* $NetBSD: loadfile.h,v 1.1 1999/04/28 09:08:50 christos Exp $ */
-/* $OpenBSD: loadfile.h,v 1.3 2008/06/26 05:42:20 ray Exp $ */
+/* $OpenBSD: loadfile.h,v 1.4 2015/05/19 20:39:12 miod Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -38,7 +38,9 @@
#define MARK_NSYM 2
#define MARK_SYM 3
#define MARK_END 4
-#define MARK_MAX 5
+#define MARK_RANDOM 5
+#define MARK_ERANDOM 6
+#define MARK_MAX 7
/*
* Bit flags for sections to load
@@ -49,7 +51,8 @@
#define LOAD_BSS 0x0008
#define LOAD_SYM 0x0010
#define LOAD_HDR 0x0020
-#define LOAD_ALL 0x003f
+#define LOAD_RANDOM 0x0040
+#define LOAD_ALL 0x007f
#define COUNT_TEXT 0x0100
#define COUNT_TEXTA 0x0200
@@ -57,7 +60,8 @@
#define COUNT_BSS 0x0800
#define COUNT_SYM 0x1000
#define COUNT_HDR 0x2000
-#define COUNT_ALL 0x3f00
+#define COUNT_RANDOM 0x4000
+#define COUNT_ALL 0x7f00
int loadfile(const char *, u_long *, int);
diff --git a/sys/lib/libsa/loadfile_elf.c b/sys/lib/libsa/loadfile_elf.c
index 083a286d5b0..432f977e712 100644
--- a/sys/lib/libsa/loadfile_elf.c
+++ b/sys/lib/libsa/loadfile_elf.c
@@ -1,5 +1,5 @@
/* $NetBSD: loadfile.c,v 1.10 2000/12/03 02:53:04 tsutsui Exp $ */
-/* $OpenBSD: loadfile_elf.c,v 1.10 2014/10/26 10:33:48 miod Exp $ */
+/* $OpenBSD: loadfile_elf.c,v 1.11 2015/05/19 20:39:12 miod Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -99,7 +99,7 @@ ELFNAME(exec)(int fd, Elf_Ehdr *elf, u_long *marks, int flags)
int m;
/* Fill segment if asked for. */
- if (flags & LOAD_DATA) {
+ if (flags & LOAD_RANDOM) {
for (pos = 0; pos < phdr[i].p_filesz;
pos += m) {
m = MIN(phdr[i].p_filesz - pos,
@@ -108,6 +108,11 @@ ELFNAME(exec)(int fd, Elf_Ehdr *elf, u_long *marks, int flags)
m);
}
}
+ if (flags & (LOAD_RANDOM | COUNT_RANDOM)) {
+ marks[MARK_RANDOM] = LOADADDR(phdr[i].p_paddr);
+ marks[MARK_ERANDOM] =
+ marks[MARK_RANDOM] + phdr[i].p_filesz;
+ }
continue;
}