diff options
author | Tom Spink <tspink@gmail.com> | 2008-06-06 01:46:12 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-06-06 14:29:10 -0400 |
commit | 40fb16a360d9c6459afee91dc793c1e3374feb94 (patch) | |
tree | bbe5f8a4185ac6784d82ee8c938bb246518f6791 /arch/um | |
parent | 9f31287b443f30a591539e448fb628e3827a8f61 (diff) |
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: Tom Spink <tspink@gmail.com>
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/um')
-rw-r--r-- | arch/um/include/os.h | 2 | ||||
-rw-r--r-- | arch/um/kernel/um_arch.c | 2 | ||||
-rw-r--r-- | arch/um/os-Linux/sys-i386/task_size.c | 31 | ||||
-rw-r--r-- | arch/um/os-Linux/sys-x86_64/task_size.c | 2 |
4 files changed, 26 insertions, 11 deletions
diff --git a/arch/um/include/os.h b/arch/um/include/os.h index e2716ac8889a..db5be46e3e18 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h | |||
@@ -299,6 +299,6 @@ extern int os_arch_prctl(int pid, int code, unsigned long *addr); | |||
299 | extern int get_pty(void); | 299 | extern int get_pty(void); |
300 | 300 | ||
301 | /* sys-$ARCH/task_size.c */ | 301 | /* sys-$ARCH/task_size.c */ |
302 | extern unsigned long os_get_task_size(void); | 302 | extern unsigned long os_get_top_address(void); |
303 | 303 | ||
304 | #endif | 304 | #endif |
diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c index 9db85b2ce698..8d84250324b3 100644 --- a/arch/um/kernel/um_arch.c +++ b/arch/um/kernel/um_arch.c | |||
@@ -274,7 +274,7 @@ int __init linux_main(int argc, char **argv) | |||
274 | if (have_root == 0) | 274 | if (have_root == 0) |
275 | add_arg(DEFAULT_COMMAND_LINE); | 275 | add_arg(DEFAULT_COMMAND_LINE); |
276 | 276 | ||
277 | host_task_size = os_get_task_size(); | 277 | host_task_size = os_get_top_address(); |
278 | /* | 278 | /* |
279 | * TASK_SIZE needs to be PGDIR_SIZE aligned or else exit_mmap craps | 279 | * TASK_SIZE needs to be PGDIR_SIZE aligned or else exit_mmap craps |
280 | * out | 280 | * out |
diff --git a/arch/um/os-Linux/sys-i386/task_size.c b/arch/um/os-Linux/sys-i386/task_size.c index ccb49b0aff59..be04c1e183bf 100644 --- a/arch/um/os-Linux/sys-i386/task_size.c +++ b/arch/um/os-Linux/sys-i386/task_size.c | |||
@@ -63,7 +63,7 @@ static int page_ok(unsigned long page) | |||
63 | return ok; | 63 | return ok; |
64 | } | 64 | } |
65 | 65 | ||
66 | unsigned long os_get_task_size(void) | 66 | unsigned long os_get_top_address(void) |
67 | { | 67 | { |
68 | struct sigaction sa, old; | 68 | struct sigaction sa, old; |
69 | unsigned long bottom = 0; | 69 | unsigned long bottom = 0; |
@@ -76,9 +76,9 @@ unsigned long os_get_task_size(void) | |||
76 | * hosts, but shouldn't hurt otherwise. | 76 | * hosts, but shouldn't hurt otherwise. |
77 | */ | 77 | */ |
78 | unsigned long top = 0xffffd000 >> UM_KERN_PAGE_SHIFT; | 78 | unsigned long top = 0xffffd000 >> UM_KERN_PAGE_SHIFT; |
79 | unsigned long test; | 79 | unsigned long test, original; |
80 | 80 | ||
81 | printf("Locating the top of the address space ... "); | 81 | printf("Locating the bottom of the address space ... "); |
82 | fflush(stdout); | 82 | fflush(stdout); |
83 | 83 | ||
84 | /* | 84 | /* |
@@ -89,16 +89,31 @@ unsigned long os_get_task_size(void) | |||
89 | sigemptyset(&sa.sa_mask); | 89 | sigemptyset(&sa.sa_mask); |
90 | sa.sa_flags = SA_NODEFER; | 90 | sa.sa_flags = SA_NODEFER; |
91 | if (sigaction(SIGSEGV, &sa, &old)) { | 91 | if (sigaction(SIGSEGV, &sa, &old)) { |
92 | perror("os_get_task_size"); | 92 | perror("os_get_top_address"); |
93 | exit(1); | 93 | exit(1); |
94 | } | 94 | } |
95 | 95 | ||
96 | if (!page_ok(bottom)) { | 96 | /* Manually scan the address space, bottom-up, until we find |
97 | fprintf(stderr, "Address 0x%x no good?\n", | 97 | * the first valid page (or run out of them). |
98 | bottom << UM_KERN_PAGE_SHIFT); | 98 | */ |
99 | for (bottom = 0; bottom < top; bottom++) { | ||
100 | if (page_ok(bottom)) | ||
101 | break; | ||
102 | } | ||
103 | |||
104 | /* If we've got this far, we ran out of pages. */ | ||
105 | if (bottom == top) { | ||
106 | fprintf(stderr, "Unable to determine bottom of address " | ||
107 | "space.\n"); | ||
99 | exit(1); | 108 | exit(1); |
100 | } | 109 | } |
101 | 110 | ||
111 | printf("0x%x\n", bottom << UM_KERN_PAGE_SHIFT); | ||
112 | printf("Locating the top of the address space ... "); | ||
113 | fflush(stdout); | ||
114 | |||
115 | original = bottom; | ||
116 | |||
102 | /* This could happen with a 4G/4G split */ | 117 | /* This could happen with a 4G/4G split */ |
103 | if (page_ok(top)) | 118 | if (page_ok(top)) |
104 | goto out; | 119 | goto out; |
@@ -114,7 +129,7 @@ unsigned long os_get_task_size(void) | |||
114 | out: | 129 | out: |
115 | /* Restore the old SIGSEGV handling */ | 130 | /* Restore the old SIGSEGV handling */ |
116 | if (sigaction(SIGSEGV, &old, NULL)) { | 131 | if (sigaction(SIGSEGV, &old, NULL)) { |
117 | perror("os_get_task_size"); | 132 | perror("os_get_top_address"); |
118 | exit(1); | 133 | exit(1); |
119 | } | 134 | } |
120 | top <<= UM_KERN_PAGE_SHIFT; | 135 | top <<= UM_KERN_PAGE_SHIFT; |
diff --git a/arch/um/os-Linux/sys-x86_64/task_size.c b/arch/um/os-Linux/sys-x86_64/task_size.c index fad6f57f8ee3..26a0dd1f349c 100644 --- a/arch/um/os-Linux/sys-x86_64/task_size.c +++ b/arch/um/os-Linux/sys-x86_64/task_size.c | |||
@@ -1,4 +1,4 @@ | |||
1 | unsigned long os_get_task_size(unsigned long shift) | 1 | unsigned long os_get_top_address(unsigned long shift) |
2 | { | 2 | { |
3 | /* The old value of CONFIG_TOP_ADDR */ | 3 | /* The old value of CONFIG_TOP_ADDR */ |
4 | return 0x7fc0000000; | 4 | return 0x7fc0000000; |