summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcus <marcus>2003-09-07 23:35:44 +0000
committermarcus <marcus>2003-09-07 23:35:44 +0000
commitaab24c2000254793beeb5bf8d1004510b3bf0d18 (patch)
tree382fdaf0e15adfb37ab4727baf67bc5ddc406e48
parent421980a4da2edc87e8658898c545b79d368d9c23 (diff)
Check for conflicts with laden itself, and with the GRUB MBI.
-rw-r--r--laden/ia32-cmain.c40
-rw-r--r--laden/laden.h6
-rw-r--r--laden/loader.c19
3 files changed, 56 insertions, 9 deletions
diff --git a/laden/ia32-cmain.c b/laden/ia32-cmain.c
index 29a6bd3..437cf8f 100644
--- a/laden/ia32-cmain.c
+++ b/laden/ia32-cmain.c
@@ -41,6 +41,10 @@ help_arch (void)
/* Check if the bit BIT in FLAGS is set. */
#define CHECK_FLAG(flags,bit) ((flags) & (1 << (bit)))
+/* The following must be defined and are used to calculate the extents
+ of the laden binary itself. */
+extern char _start;
+extern char _end;
/* Setup the argument vector and pass control over to the main
function. */
@@ -49,6 +53,9 @@ cmain (uint32_t magic, multiboot_info_t *mbi)
{
int argc = 0;
char **argv = 0;
+ l4_word_t start;
+ l4_word_t end;
+
/* Verify that we are booted by a Multiboot-compliant boot loader. */
if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
@@ -114,6 +121,39 @@ cmain (uint32_t magic, multiboot_info_t *mbi)
a later time. */
boot_info = (uint32_t) mbi;
+ /* Now protect ourselves and the mulitboot info (at least the module
+ configuration. */
+ loader_add_region ("laden", (l4_word_t) &_start, (l4_word_t) &_end, 1);
+
+ start = (l4_word_t) mbi;
+ end = start + sizeof (*mbi) - 1;
+ if (CHECK_FLAG (mbi->flags, 3))
+ {
+ module_t *mod = (module_t *) mbi->mods_addr;
+ int nr;
+
+ if (((l4_word_t) mod) < start)
+ start = (l4_word_t) mod;
+ if (((l4_word_t) mod) + mbi->mods_count * sizeof (*mod) > end)
+ end = ((l4_word_t) mod) + mbi->mods_count * sizeof (*mod);
+
+ for (nr = 0; nr < mbi->mods_count; nr++)
+ {
+ char *str = (char *) mod[nr].string;
+
+ if (str)
+ {
+ if (((l4_word_t) str) < start)
+ start = (l4_word_t) str;
+ while (*str)
+ str++;
+ if (((l4_word_t) str) > end)
+ end = (l4_word_t) str;
+ }
+ }
+ }
+ loader_add_region ("grub-mbi", start, end, 1);
+
/* Now invoke the main function. */
main (argc, argv);
diff --git a/laden/laden.h b/laden/laden.h
index 8702c31..3c7d3cc 100644
--- a/laden/laden.h
+++ b/laden/laden.h
@@ -92,6 +92,12 @@ extern int debug;
/* Print a debug message. */
#define debug(...) do { if (debug) printf (__VA_ARGS__); } while (0)
+/* Add the region with the name NAME from START to END to the table of
+ regions to check against. Before doing that, check for overlaps
+ with existing regions, unless FORCE is true. */
+void loader_add_region (char *name, l4_word_t start, l4_word_t end, int force);
+
+
/* Load the ELF images of the kernel and the initial servers into
memory, checking for overlaps. Update the start and end
information with the information from the ELF program, and fill in
diff --git a/laden/loader.c b/laden/loader.c
index 3589a36..33d2c6c 100644
--- a/laden/loader.c
+++ b/laden/loader.c
@@ -107,14 +107,15 @@ check_region (char *name, l4_word_t start, l4_word_t end)
/* Add the region with the name NAME from START to END to the table of
regions to check against. Before doing that, check for overlaps
- with existing regions. */
-static void
-add_region (char *name, l4_word_t start, l4_word_t end)
+ with existing regions, unless FORCE is true. */
+void
+loader_add_region (char *name, l4_word_t start, l4_word_t end, int force)
{
if (nr_regions == MAX_REGIONS)
panic ("Too many memory regions, region %s doesn't fit", name);
- check_region (name, start, end);
+ if (!force)
+ check_region (name, start, end);
used_regions[nr_regions].name = name;
used_regions[nr_regions].start = start;
@@ -204,7 +205,7 @@ elf_load (char *name, l4_word_t start, l4_word_t end,
/* FIXME: Add this as a bootloader specific memory type to L4's
memdesc list instead. */
- add_region (name, new_start, new_end);
+ loader_add_region (name, new_start, new_end, 0);
if (new_start_p)
*new_start_p = new_start;
@@ -224,18 +225,18 @@ load_components (void)
{
if (!kernel.low)
panic ("No L4 kernel found");
- add_region ("kernel-mod", kernel.low, kernel.high);
+ loader_add_region ("kernel-mod", kernel.low, kernel.high, 0);
if (!sigma0.low)
panic ("No sigma0 server found");
- add_region ("sigma0-mod", sigma0.low, sigma0.high);
+ loader_add_region ("sigma0-mod", sigma0.low, sigma0.high, 0);
if (sigma1.low)
- add_region ("sigma1-mod", sigma1.low, sigma1.high);
+ loader_add_region ("sigma1-mod", sigma1.low, sigma1.high, 0);
if (!rootserver.low)
panic ("No rootserver server found");
- add_region ("rootserver-mod", rootserver.low, rootserver.high);
+ loader_add_region ("rootserver-mod", rootserver.low, rootserver.high, 0);
elf_load ("kernel", kernel.low, kernel.high,
&kernel.low, &kernel.high, &kernel.ip);