Re: UML fails to locate address space

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Tom Spink
Date: Wednesday, May 21, 2008 - 5:02 am

2008/5/21 Jeff Dike <jdike@addtoit.com>:

Hi Jeff,

Here is the revised version - I cheered Dijkstra up by getting rid of that goto.

-- Tom

--

From: Tom Spink <tspink@gmail.com>
Date: Wed, 21 May 2008 00:53:54 +0100
Subject: [PATCH] Locate the bottom of the address space

This patch makes os_get_task_size locate the bottom of the address space,
as well as the top.  This is for systems which put a lower limit on mmap
addresses.  It works by manually scanning pages from zero onwards until a
valid page is found.

Because the bottom of the address space may not be zero, it's not sufficient
to assume the top of the address space is the size of the address space.  The
size is the difference between the top address and bottom address.

Signed-off-by: Tom Spink <tspink@gmail.com>
---
 arch/um/os-Linux/sys-i386/task_size.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/arch/um/os-Linux/sys-i386/task_size.c
b/arch/um/os-Linux/sys-i386/task_size.c
index ccb49b0..d1e3604 100644
--- a/arch/um/os-Linux/sys-i386/task_size.c
+++ b/arch/um/os-Linux/sys-i386/task_size.c
@@ -1,6 +1,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
+#include <fcntl.h>
+#include <unistd.h>
 #include <sys/mman.h>
 #include "longjmp.h"
 #include "kern_constants.h"
@@ -76,9 +78,9 @@ unsigned long os_get_task_size(void)
 	 * hosts, but shouldn't hurt otherwise.
 	 */
 	unsigned long top = 0xffffd000 >> UM_KERN_PAGE_SHIFT;
-	unsigned long test;
+	unsigned long test, original;

-	printf("Locating the top of the address space ... ");
+	printf("Locating the bottom of the address space ... ");
 	fflush(stdout);

 	/*
@@ -93,13 +95,26 @@ unsigned long os_get_task_size(void)
 		exit(1);
 	}

-	if (!page_ok(bottom)) {
-		fprintf(stderr, "Address 0x%x no good?\n",
-			bottom << UM_KERN_PAGE_SHIFT);
+	/* Manually scan the address space, bottom-up, until we find
+	 * the first valid page (or run out of them).
+	 */
+	for (bottom = 0; bottom < top; bottom++) {
+		if (page_ok(bottom))
+			break;
+	}
+
+	/* If we've got this far, we ran out of pages. */
+	if (bottom == top) {
+		fprintf(stderr, "Unable to determine bottom of address space.\n");
 		exit(1);
 	}
+	
+	printf("0x%x\n", bottom << UM_KERN_PAGE_SHIFT);
+	printf("Locating the top of the address space ... ");
+	fflush(stdout);

 	/* This could happen with a 4G/4G split */
+	original = bottom;
 	if (page_ok(top))
 		goto out;

@@ -117,8 +132,7 @@ out:
 		perror("os_get_task_size");
 		exit(1);
 	}
-	top <<= UM_KERN_PAGE_SHIFT;
-	printf("0x%x\n", top);
+	printf("0x%x\n", top << UM_KERN_PAGE_SHIFT);

-	return top;
+	return (top - original) << UM_KERN_PAGE_SHIFT;
 }
-- 
1.5.4.3
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
UML fails to locate address space, Tom Spink, (Tue May 20, 4:08 am)
Re: UML fails to locate address space, Jeff Dike, (Tue May 20, 6:52 am)
Re: UML fails to locate address space, Tom Spink, (Tue May 20, 6:59 am)
Re: UML fails to locate address space, linux-os (Dick Johnson), (Tue May 20, 8:22 am)
Re: UML fails to locate address space, Jeff Dike, (Tue May 20, 9:10 am)
Re: UML fails to locate address space, Tom Spink, (Tue May 20, 9:43 am)
Re: UML fails to locate address space, Jeff Dike, (Tue May 20, 10:35 am)
Re: UML fails to locate address space, Jeff Dike, (Tue May 20, 10:56 am)
Re: UML fails to locate address space, Tom Spink, (Tue May 20, 11:01 am)
Re: UML fails to locate address space, Jeff Dike, (Tue May 20, 12:24 pm)
Re: UML fails to locate address space, Tom Spink, (Tue May 20, 12:42 pm)
Re: UML fails to locate address space, Jeff Dike, (Tue May 20, 2:27 pm)
Re: UML fails to locate address space, linux-os (Dick Johnson), (Tue May 20, 2:54 pm)
Re: UML fails to locate address space, linux-os (Dick Johnson), (Tue May 20, 2:58 pm)
Re: UML fails to locate address space, Tom Spink, (Tue May 20, 3:03 pm)
Re: UML fails to locate address space, Tom Spink, (Tue May 20, 4:57 pm)
Re: UML fails to locate address space, Jeff Dike, (Tue May 20, 6:58 pm)
Re: UML fails to locate address space, Jeff Dike, (Tue May 20, 7:15 pm)
Re: UML fails to locate address space, Tom Spink, (Wed May 21, 5:02 am)
Re: UML fails to locate address space, Tom Spink, (Wed May 21, 5:04 am)
Re: UML fails to locate address space, Jeff Dike, (Wed May 21, 10:58 am)
Re: UML fails to locate address space, Tom Spink, (Wed May 21, 12:01 pm)