Commit 40fb16a3 authored by Tom Spink's avatar Tom Spink Committed by Linus Torvalds

uml: deal with inaccessible address space start

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.

[jdike@addtoit.com: changed the name to reflect that this function is
supposed to return the top of the process address space, not its size and
changed the return value to reflect that.  Also some minor formatting
changes]
Signed-off-by: default avatarTom Spink <tspink@gmail.com>
Signed-off-by: default avatarJeff Dike <jdike@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 9f31287b
...@@ -299,6 +299,6 @@ extern int os_arch_prctl(int pid, int code, unsigned long *addr); ...@@ -299,6 +299,6 @@ extern int os_arch_prctl(int pid, int code, unsigned long *addr);
extern int get_pty(void); extern int get_pty(void);
/* sys-$ARCH/task_size.c */ /* sys-$ARCH/task_size.c */
extern unsigned long os_get_task_size(void); extern unsigned long os_get_top_address(void);
#endif #endif
...@@ -274,7 +274,7 @@ int __init linux_main(int argc, char **argv) ...@@ -274,7 +274,7 @@ int __init linux_main(int argc, char **argv)
if (have_root == 0) if (have_root == 0)
add_arg(DEFAULT_COMMAND_LINE); add_arg(DEFAULT_COMMAND_LINE);
host_task_size = os_get_task_size(); host_task_size = os_get_top_address();
/* /*
* TASK_SIZE needs to be PGDIR_SIZE aligned or else exit_mmap craps * TASK_SIZE needs to be PGDIR_SIZE aligned or else exit_mmap craps
* out * out
......
...@@ -63,7 +63,7 @@ static int page_ok(unsigned long page) ...@@ -63,7 +63,7 @@ static int page_ok(unsigned long page)
return ok; return ok;
} }
unsigned long os_get_task_size(void) unsigned long os_get_top_address(void)
{ {
struct sigaction sa, old; struct sigaction sa, old;
unsigned long bottom = 0; unsigned long bottom = 0;
...@@ -76,9 +76,9 @@ unsigned long os_get_task_size(void) ...@@ -76,9 +76,9 @@ unsigned long os_get_task_size(void)
* hosts, but shouldn't hurt otherwise. * hosts, but shouldn't hurt otherwise.
*/ */
unsigned long top = 0xffffd000 >> UM_KERN_PAGE_SHIFT; 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); fflush(stdout);
/* /*
...@@ -89,16 +89,31 @@ unsigned long os_get_task_size(void) ...@@ -89,16 +89,31 @@ unsigned long os_get_task_size(void)
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_NODEFER; sa.sa_flags = SA_NODEFER;
if (sigaction(SIGSEGV, &sa, &old)) { if (sigaction(SIGSEGV, &sa, &old)) {
perror("os_get_task_size"); perror("os_get_top_address");
exit(1); exit(1);
} }
if (!page_ok(bottom)) { /* Manually scan the address space, bottom-up, until we find
fprintf(stderr, "Address 0x%x no good?\n", * the first valid page (or run out of them).
bottom << UM_KERN_PAGE_SHIFT); */
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); exit(1);
} }
printf("0x%x\n", bottom << UM_KERN_PAGE_SHIFT);
printf("Locating the top of the address space ... ");
fflush(stdout);
original = bottom;
/* This could happen with a 4G/4G split */ /* This could happen with a 4G/4G split */
if (page_ok(top)) if (page_ok(top))
goto out; goto out;
...@@ -114,7 +129,7 @@ unsigned long os_get_task_size(void) ...@@ -114,7 +129,7 @@ unsigned long os_get_task_size(void)
out: out:
/* Restore the old SIGSEGV handling */ /* Restore the old SIGSEGV handling */
if (sigaction(SIGSEGV, &old, NULL)) { if (sigaction(SIGSEGV, &old, NULL)) {
perror("os_get_task_size"); perror("os_get_top_address");
exit(1); exit(1);
} }
top <<= UM_KERN_PAGE_SHIFT; top <<= UM_KERN_PAGE_SHIFT;
......
unsigned long os_get_task_size(unsigned long shift) unsigned long os_get_top_address(unsigned long shift)
{ {
/* The old value of CONFIG_TOP_ADDR */ /* The old value of CONFIG_TOP_ADDR */
return 0x7fc0000000; return 0x7fc0000000;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment