Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) |
| 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Jeff Dike | 8e36706 | 2006-03-27 01:14:32 -0800 | [diff] [blame] | 6 | #include <pty.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <stdio.h> |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | #include <stdarg.h> |
| 10 | #include <stdlib.h> |
| 11 | #include <string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <unistd.h> |
| 13 | #include <signal.h> |
| 14 | #include <sched.h> |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 15 | #include <fcntl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <sys/time.h> |
| 18 | #include <sys/wait.h> |
| 19 | #include <sys/mman.h> |
| 20 | #include <asm/unistd.h> |
| 21 | #include <asm/page.h> |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 22 | #include <sys/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "user_util.h" |
| 24 | #include "kern_util.h" |
| 25 | #include "user.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "signal_kern.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "sysdep/ptrace.h" |
| 28 | #include "sysdep/sigcontext.h" |
| 29 | #include "irq_user.h" |
| 30 | #include "ptrace_user.h" |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 31 | #include "mem_user.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "init.h" |
| 33 | #include "os.h" |
| 34 | #include "uml-config.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "choose-mode.h" |
| 36 | #include "mode.h" |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 37 | #include "tempfile.h" |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 38 | #include "kern_constants.h" |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #ifdef UML_CONFIG_MODE_SKAS |
| 41 | #include "skas.h" |
| 42 | #include "skas_ptrace.h" |
| 43 | #include "registers.h" |
| 44 | #endif |
| 45 | |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 46 | static int ptrace_child(void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
| 48 | int ret; |
| 49 | int pid = os_getpid(), ppid = getppid(); |
| 50 | int sc_result; |
| 51 | |
Jeff Dike | 43b00fd | 2006-02-07 12:58:42 -0800 | [diff] [blame] | 52 | change_sig(SIGWINCH, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){ |
| 54 | perror("ptrace"); |
| 55 | os_kill_process(pid, 0); |
| 56 | } |
Jeff Dike | 73c8f44 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 57 | kill(pid, SIGSTOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | /*This syscall will be intercepted by the parent. Don't call more than |
| 60 | * once, please.*/ |
| 61 | sc_result = os_getpid(); |
| 62 | |
| 63 | if (sc_result == pid) |
| 64 | ret = 1; /*Nothing modified by the parent, we are running |
| 65 | normally.*/ |
| 66 | else if (sc_result == ppid) |
| 67 | ret = 0; /*Expected in check_ptrace and check_sysemu when they |
| 68 | succeed in modifying the stack frame*/ |
| 69 | else |
| 70 | ret = 2; /*Serious trouble! This could be caused by a bug in |
| 71 | host 2.6 SKAS3/2.6 patch before release -V6, together |
| 72 | with a bug in the UML code itself.*/ |
| 73 | _exit(ret); |
| 74 | } |
| 75 | |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 76 | static void fatal_perror(char *str) |
| 77 | { |
| 78 | perror(str); |
| 79 | exit(1); |
| 80 | } |
| 81 | |
| 82 | static void fatal(char *fmt, ...) |
| 83 | { |
| 84 | va_list list; |
| 85 | |
| 86 | va_start(list, fmt); |
| 87 | vprintf(fmt, list); |
| 88 | va_end(list); |
| 89 | fflush(stdout); |
| 90 | |
| 91 | exit(1); |
| 92 | } |
| 93 | |
| 94 | static void non_fatal(char *fmt, ...) |
| 95 | { |
| 96 | va_list list; |
| 97 | |
| 98 | va_start(list, fmt); |
| 99 | vprintf(fmt, list); |
| 100 | va_end(list); |
| 101 | fflush(stdout); |
| 102 | } |
| 103 | |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 104 | static int start_ptraced_child(void **stack_out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 106 | void *stack; |
| 107 | unsigned long sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | int pid, n, status; |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 109 | |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 110 | stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, |
| 111 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 112 | if(stack == MAP_FAILED) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 113 | fatal_perror("check_ptrace : mmap failed"); |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 114 | sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *); |
| 115 | pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | if(pid < 0) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 117 | fatal_perror("start_ptraced_child : clone failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); |
| 119 | if(n < 0) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 120 | fatal_perror("check_ptrace : clone failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 122 | fatal("check_ptrace : expected SIGSTOP, got status = %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | status); |
| 124 | |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 125 | *stack_out = stack; |
Jeff Dike | 9eae9b1 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 126 | return pid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 129 | /* When testing for SYSEMU support, if it is one of the broken versions, we |
| 130 | * must just avoid using sysemu, not panic, but only if SYSEMU features are |
| 131 | * broken. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | * So only for SYSEMU features we test mustpanic, while normal host features |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 133 | * must work anyway! |
| 134 | */ |
| 135 | static int stop_ptraced_child(int pid, void *stack, int exitcode, |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 136 | int mustexit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | { |
| 138 | int status, n, ret = 0; |
| 139 | |
| 140 | if(ptrace(PTRACE_CONT, pid, 0, 0) < 0) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 141 | fatal_perror("stop_ptraced_child : ptrace failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | CATCH_EINTR(n = waitpid(pid, &status, 0)); |
| 143 | if(!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) { |
| 144 | int exit_with = WEXITSTATUS(status); |
| 145 | if (exit_with == 2) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 146 | non_fatal("check_ptrace : child exited with status 2. " |
| 147 | "Serious trouble happening! Try updating " |
| 148 | "your host skas patch!\nDisabling SYSEMU " |
| 149 | "support."); |
| 150 | non_fatal("check_ptrace : child exited with exitcode %d, while " |
| 151 | "expecting %d; status 0x%x\n", exit_with, |
| 152 | exitcode, status); |
| 153 | if (mustexit) |
| 154 | exit(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | ret = -1; |
| 156 | } |
| 157 | |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 158 | if(munmap(stack, PAGE_SIZE) < 0) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 159 | fatal_perror("check_ptrace : munmap failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | return ret; |
| 161 | } |
| 162 | |
Jeff Dike | 7242a40 | 2007-02-10 01:44:19 -0800 | [diff] [blame] | 163 | /* Changed only during early boot */ |
Paolo 'Blaisorblade' Giarrusso | cb66504 | 2005-07-27 11:43:31 -0700 | [diff] [blame] | 164 | int ptrace_faultinfo = 1; |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 165 | int ptrace_ldt = 1; |
Paolo 'Blaisorblade' Giarrusso | cb66504 | 2005-07-27 11:43:31 -0700 | [diff] [blame] | 166 | int proc_mm = 1; |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 167 | int skas_needs_stub = 0; |
Paolo 'Blaisorblade' Giarrusso | cb66504 | 2005-07-27 11:43:31 -0700 | [diff] [blame] | 168 | |
| 169 | static int __init skas0_cmd_param(char *str, int* add) |
| 170 | { |
| 171 | ptrace_faultinfo = proc_mm = 0; |
| 172 | return 0; |
| 173 | } |
| 174 | |
Paolo 'Blaisorblade' Giarrusso | 9e3d862 | 2005-10-09 21:37:18 +0200 | [diff] [blame] | 175 | /* The two __uml_setup would conflict, without this stupid alias. */ |
| 176 | |
| 177 | static int __init mode_skas0_cmd_param(char *str, int* add) |
| 178 | __attribute__((alias("skas0_cmd_param"))); |
| 179 | |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 180 | __uml_setup("skas0", skas0_cmd_param, |
| 181 | "skas0\n" |
| 182 | " Disables SKAS3 usage, so that SKAS0 is used, unless \n" |
| 183 | " you specify mode=tt.\n\n"); |
| 184 | |
Paolo 'Blaisorblade' Giarrusso | 9e3d862 | 2005-10-09 21:37:18 +0200 | [diff] [blame] | 185 | __uml_setup("mode=skas0", mode_skas0_cmd_param, |
| 186 | "mode=skas0\n" |
| 187 | " Disables SKAS3 usage, so that SKAS0 is used, unless you \n" |
| 188 | " specify mode=tt. Note that this was recently added - on \n" |
| 189 | " older kernels you must use simply \"skas0\".\n\n"); |
| 190 | |
Jeff Dike | 7242a40 | 2007-02-10 01:44:19 -0800 | [diff] [blame] | 191 | /* Changed only during early boot */ |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 192 | static int force_sysemu_disabled = 0; |
| 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | static int __init nosysemu_cmd_param(char *str, int* add) |
| 195 | { |
| 196 | force_sysemu_disabled = 1; |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | __uml_setup("nosysemu", nosysemu_cmd_param, |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 201 | "nosysemu\n" |
| 202 | " Turns off syscall emulation patch for ptrace (SYSEMU) on.\n" |
| 203 | " SYSEMU is a performance-patch introduced by Laurent Vivier. It changes\n" |
| 204 | " behaviour of ptrace() and helps reducing host context switch rate.\n" |
| 205 | " To make it working, you need a kernel patch for your host, too.\n" |
| 206 | " See http://perso.wanadoo.fr/laurent.vivier/UML/ for further \n" |
| 207 | " information.\n\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | static void __init check_sysemu(void) |
| 210 | { |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 211 | void *stack; |
Jeff Dike | 9eae9b1 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 212 | int pid, n, status, count=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 214 | non_fatal("Checking syscall emulation patch for ptrace..."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | sysemu_supported = 0; |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 216 | pid = start_ptraced_child(&stack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | if(ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0) |
| 219 | goto fail; |
| 220 | |
| 221 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); |
| 222 | if (n < 0) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 223 | fatal_perror("check_sysemu : wait failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP)) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 225 | fatal("check_sysemu : expected SIGTRAP, got status = %d", |
| 226 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | n = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET, |
| 229 | os_getpid()); |
| 230 | if(n < 0) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 231 | fatal_perror("check_sysemu : failed to modify system call " |
| 232 | "return"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 234 | if (stop_ptraced_child(pid, stack, 0, 0) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | goto fail_stopped; |
| 236 | |
| 237 | sysemu_supported = 1; |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 238 | non_fatal("OK\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | set_using_sysemu(!force_sysemu_disabled); |
| 240 | |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 241 | non_fatal("Checking advanced syscall emulation patch for ptrace..."); |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 242 | pid = start_ptraced_child(&stack); |
Bodo Stroesser | f9dfefe | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 243 | |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 244 | if((ptrace(PTRACE_OLDSETOPTIONS, pid, 0, |
| 245 | (void *) PTRACE_O_TRACESYSGOOD) < 0)) |
| 246 | fatal_perror("check_ptrace: PTRACE_OLDSETOPTIONS failed"); |
Bodo Stroesser | f9dfefe | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | while(1){ |
| 249 | count++; |
| 250 | if(ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, 0) < 0) |
| 251 | goto fail; |
| 252 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); |
| 253 | if(n < 0) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 254 | fatal_perror("check_ptrace : wait failed"); |
| 255 | |
Bodo Stroesser | f9dfefe | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 256 | if(WIFSTOPPED(status) && (WSTOPSIG(status) == (SIGTRAP|0x80))){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | if (!count) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 258 | fatal("check_ptrace : SYSEMU_SINGLESTEP " |
Bodo Stroesser | f9dfefe | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 259 | "doesn't singlestep"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | n = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_RET_OFFSET, |
| 261 | os_getpid()); |
| 262 | if(n < 0) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 263 | fatal_perror("check_sysemu : failed to modify " |
| 264 | "system call return"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | break; |
| 266 | } |
Bodo Stroesser | f9dfefe | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 267 | else if(WIFSTOPPED(status) && (WSTOPSIG(status) == SIGTRAP)) |
| 268 | count++; |
| 269 | else |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 270 | fatal("check_ptrace : expected SIGTRAP or " |
| 271 | "(SIGTRAP | 0x80), got status = %d", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 273 | if (stop_ptraced_child(pid, stack, 0, 0) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | goto fail_stopped; |
| 275 | |
| 276 | sysemu_supported = 2; |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 277 | non_fatal("OK\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | if ( !force_sysemu_disabled ) |
| 280 | set_using_sysemu(sysemu_supported); |
| 281 | return; |
| 282 | |
| 283 | fail: |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 284 | stop_ptraced_child(pid, stack, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | fail_stopped: |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 286 | non_fatal("missing\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 289 | static void __init check_ptrace(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 291 | void *stack; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | int pid, syscall, n, status; |
| 293 | |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 294 | non_fatal("Checking that ptrace can change system call numbers..."); |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 295 | pid = start_ptraced_child(&stack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 297 | if((ptrace(PTRACE_OLDSETOPTIONS, pid, 0, |
| 298 | (void *) PTRACE_O_TRACESYSGOOD) < 0)) |
| 299 | fatal_perror("check_ptrace: PTRACE_OLDSETOPTIONS failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | while(1){ |
| 302 | if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 303 | fatal_perror("check_ptrace : ptrace failed"); |
| 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); |
| 306 | if(n < 0) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 307 | fatal_perror("check_ptrace : wait failed"); |
| 308 | |
| 309 | if(!WIFSTOPPED(status) || |
| 310 | (WSTOPSIG(status) != (SIGTRAP | 0x80))) |
| 311 | fatal("check_ptrace : expected (SIGTRAP|0x80), " |
| 312 | "got status = %d", status); |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | syscall = ptrace(PTRACE_PEEKUSR, pid, PT_SYSCALL_NR_OFFSET, |
| 315 | 0); |
| 316 | if(syscall == __NR_getpid){ |
| 317 | n = ptrace(PTRACE_POKEUSR, pid, PT_SYSCALL_NR_OFFSET, |
| 318 | __NR_getppid); |
| 319 | if(n < 0) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 320 | fatal_perror("check_ptrace : failed to modify " |
| 321 | "system call"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | break; |
| 323 | } |
| 324 | } |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 325 | stop_ptraced_child(pid, stack, 0, 1); |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 326 | non_fatal("OK\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | check_sysemu(); |
| 328 | } |
| 329 | |
Rob Landley | 966a082 | 2006-04-18 22:21:43 -0700 | [diff] [blame] | 330 | extern void check_tmpexec(void); |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 331 | |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 332 | void os_early_checks(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 334 | check_ptrace(); |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 335 | |
| 336 | /* Need to check this early because mmapping happens before the |
| 337 | * kernel is running. |
| 338 | */ |
| 339 | check_tmpexec(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Bodo Stroesser | d9838d8 | 2005-09-03 15:57:51 -0700 | [diff] [blame] | 342 | static int __init noprocmm_cmd_param(char *str, int* add) |
| 343 | { |
| 344 | proc_mm = 0; |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | __uml_setup("noprocmm", noprocmm_cmd_param, |
| 349 | "noprocmm\n" |
| 350 | " Turns off usage of /proc/mm, even if host supports it.\n" |
| 351 | " To support /proc/mm, the host needs to be patched using\n" |
| 352 | " the current skas3 patch.\n\n"); |
| 353 | |
| 354 | static int __init noptracefaultinfo_cmd_param(char *str, int* add) |
| 355 | { |
| 356 | ptrace_faultinfo = 0; |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | __uml_setup("noptracefaultinfo", noptracefaultinfo_cmd_param, |
| 361 | "noptracefaultinfo\n" |
| 362 | " Turns off usage of PTRACE_FAULTINFO, even if host supports\n" |
| 363 | " it. To support PTRACE_FAULTINFO, the host needs to be patched\n" |
| 364 | " using the current skas3 patch.\n\n"); |
| 365 | |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 366 | static int __init noptraceldt_cmd_param(char *str, int* add) |
| 367 | { |
| 368 | ptrace_ldt = 0; |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | __uml_setup("noptraceldt", noptraceldt_cmd_param, |
| 373 | "noptraceldt\n" |
| 374 | " Turns off usage of PTRACE_LDT, even if host supports it.\n" |
| 375 | " To support PTRACE_LDT, the host needs to be patched using\n" |
| 376 | " the current skas3 patch.\n\n"); |
| 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | #ifdef UML_CONFIG_MODE_SKAS |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 379 | static inline void check_skas3_ptrace_faultinfo(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
| 381 | struct ptrace_faultinfo fi; |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 382 | void *stack; |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 383 | int pid, n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 385 | non_fatal(" - PTRACE_FAULTINFO..."); |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 386 | pid = start_ptraced_child(&stack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
| 388 | n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi); |
| 389 | if (n < 0) { |
Paolo 'Blaisorblade' Giarrusso | cb66504 | 2005-07-27 11:43:31 -0700 | [diff] [blame] | 390 | ptrace_faultinfo = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | if(errno == EIO) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 392 | non_fatal("not found\n"); |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 393 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | perror("not found"); |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 395 | } |
| 396 | else { |
Paolo 'Blaisorblade' Giarrusso | cb66504 | 2005-07-27 11:43:31 -0700 | [diff] [blame] | 397 | if (!ptrace_faultinfo) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 398 | non_fatal("found but disabled on command line\n"); |
Paolo 'Blaisorblade' Giarrusso | cb66504 | 2005-07-27 11:43:31 -0700 | [diff] [blame] | 399 | else |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 400 | non_fatal("found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | init_registers(pid); |
Jeff Dike | b85e968 | 2005-07-28 21:16:01 -0700 | [diff] [blame] | 404 | stop_ptraced_child(pid, stack, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 407 | static inline void check_skas3_ptrace_ldt(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | { |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 409 | #ifdef PTRACE_LDT |
| 410 | void *stack; |
| 411 | int pid, n; |
| 412 | unsigned char ldtbuf[40]; |
| 413 | struct ptrace_ldt ldt_op = (struct ptrace_ldt) { |
| 414 | .func = 2, /* read default ldt */ |
| 415 | .ptr = ldtbuf, |
| 416 | .bytecount = sizeof(ldtbuf)}; |
| 417 | |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 418 | non_fatal(" - PTRACE_LDT..."); |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 419 | pid = start_ptraced_child(&stack); |
| 420 | |
| 421 | n = ptrace(PTRACE_LDT, pid, 0, (unsigned long) &ldt_op); |
| 422 | if (n < 0) { |
| 423 | if(errno == EIO) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 424 | non_fatal("not found\n"); |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 425 | else { |
| 426 | perror("not found"); |
| 427 | } |
| 428 | ptrace_ldt = 0; |
| 429 | } |
| 430 | else { |
| 431 | if(ptrace_ldt) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 432 | non_fatal("found\n"); |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 433 | else |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 434 | non_fatal("found, but use is disabled\n"); |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | stop_ptraced_child(pid, stack, 1, 1); |
| 438 | #else |
| 439 | /* PTRACE_LDT might be disabled via cmdline option. |
| 440 | * We want to override this, else we might use the stub |
| 441 | * without real need |
| 442 | */ |
| 443 | ptrace_ldt = 1; |
| 444 | #endif |
| 445 | } |
| 446 | |
| 447 | static inline void check_skas3_proc_mm(void) |
| 448 | { |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 449 | non_fatal(" - /proc/mm..."); |
Jeff Dike | 73c8f44 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 450 | if (access("/proc/mm", W_OK) < 0) { |
Jeff Dike | 9eae9b1 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 451 | proc_mm = 0; |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 452 | perror("not found"); |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 453 | } |
| 454 | else { |
Paolo 'Blaisorblade' Giarrusso | cb66504 | 2005-07-27 11:43:31 -0700 | [diff] [blame] | 455 | if (!proc_mm) |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 456 | non_fatal("found but disabled on command line\n"); |
Paolo 'Blaisorblade' Giarrusso | cb66504 | 2005-07-27 11:43:31 -0700 | [diff] [blame] | 457 | else |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 458 | non_fatal("found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 460 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 462 | int can_do_skas(void) |
| 463 | { |
Jeff Dike | 3a150e1 | 2007-02-10 01:44:28 -0800 | [diff] [blame] | 464 | non_fatal("Checking for the skas3 patch in the host:\n"); |
Bodo Stroesser | 858259c | 2005-11-07 00:58:55 -0800 | [diff] [blame] | 465 | |
| 466 | check_skas3_proc_mm(); |
| 467 | check_skas3_ptrace_faultinfo(); |
| 468 | check_skas3_ptrace_ldt(); |
| 469 | |
| 470 | if(!proc_mm || !ptrace_faultinfo || !ptrace_ldt) |
| 471 | skas_needs_stub = 1; |
| 472 | |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 473 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
| 475 | #else |
| 476 | int can_do_skas(void) |
| 477 | { |
Jeff Dike | 9eae9b1 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 478 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | } |
| 480 | #endif |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 481 | |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 482 | int __init parse_iomem(char *str, int *add) |
| 483 | { |
| 484 | struct iomem_region *new; |
Jeff Dike | 73c8f44 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 485 | struct stat64 buf; |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 486 | char *file, *driver; |
Jeff Dike | 73c8f44 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 487 | int fd, size; |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 488 | |
| 489 | driver = str; |
| 490 | file = strchr(str,','); |
| 491 | if(file == NULL){ |
| 492 | printf("parse_iomem : failed to parse iomem\n"); |
| 493 | goto out; |
| 494 | } |
| 495 | *file = '\0'; |
| 496 | file++; |
Jeff Dike | 73c8f44 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 497 | fd = open(file, O_RDWR, 0); |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 498 | if(fd < 0){ |
| 499 | os_print_error(fd, "parse_iomem - Couldn't open io file"); |
| 500 | goto out; |
| 501 | } |
| 502 | |
Jeff Dike | 73c8f44 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 503 | if(fstat64(fd, &buf) < 0){ |
| 504 | perror("parse_iomem - cannot stat_fd file"); |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 505 | goto out_close; |
| 506 | } |
| 507 | |
| 508 | new = malloc(sizeof(*new)); |
| 509 | if(new == NULL){ |
| 510 | perror("Couldn't allocate iomem_region struct"); |
| 511 | goto out_close; |
| 512 | } |
| 513 | |
Jeff Dike | 73c8f44 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 514 | size = (buf.st_size + UM_KERN_PAGE_SIZE) & ~(UM_KERN_PAGE_SIZE - 1); |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 515 | |
| 516 | *new = ((struct iomem_region) { .next = iomem_regions, |
| 517 | .driver = driver, |
| 518 | .fd = fd, |
| 519 | .size = size, |
| 520 | .phys = 0, |
| 521 | .virt = 0 }); |
| 522 | iomem_regions = new; |
| 523 | iomem_size += new->size + UM_KERN_PAGE_SIZE; |
| 524 | |
Jeff Dike | 9eae9b1 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 525 | return 0; |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 526 | out_close: |
Jeff Dike | 73c8f44 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 527 | close(fd); |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 528 | out: |
Jeff Dike | 9eae9b1 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 529 | return 1; |
Jeff Dike | 0f80bc8 | 2005-09-16 19:27:50 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Jeff Dike | 8e36706 | 2006-03-27 01:14:32 -0800 | [diff] [blame] | 532 | |
| 533 | /* Changed during early boot */ |
| 534 | int pty_output_sigio = 0; |
| 535 | int pty_close_sigio = 0; |
| 536 | |
| 537 | /* Used as a flag during SIGIO testing early in boot */ |
| 538 | static volatile int got_sigio = 0; |
| 539 | |
| 540 | static void __init handler(int sig) |
| 541 | { |
| 542 | got_sigio = 1; |
| 543 | } |
| 544 | |
| 545 | struct openpty_arg { |
| 546 | int master; |
| 547 | int slave; |
| 548 | int err; |
| 549 | }; |
| 550 | |
| 551 | static void openpty_cb(void *arg) |
| 552 | { |
| 553 | struct openpty_arg *info = arg; |
| 554 | |
| 555 | info->err = 0; |
| 556 | if(openpty(&info->master, &info->slave, NULL, NULL, NULL)) |
| 557 | info->err = -errno; |
| 558 | } |
| 559 | |
Jeff Dike | 73c8f44 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 560 | static int async_pty(int master, int slave) |
| 561 | { |
| 562 | int flags; |
| 563 | |
| 564 | flags = fcntl(master, F_GETFL); |
| 565 | if(flags < 0) |
| 566 | return -errno; |
| 567 | |
| 568 | if((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) || |
| 569 | (fcntl(master, F_SETOWN, os_getpid()) < 0)) |
| 570 | return -errno; |
| 571 | |
| 572 | if((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0)) |
| 573 | return -errno; |
| 574 | |
| 575 | return(0); |
| 576 | } |
| 577 | |
Jeff Dike | 8e36706 | 2006-03-27 01:14:32 -0800 | [diff] [blame] | 578 | static void __init check_one_sigio(void (*proc)(int, int)) |
| 579 | { |
| 580 | struct sigaction old, new; |
| 581 | struct openpty_arg pty = { .master = -1, .slave = -1 }; |
| 582 | int master, slave, err; |
| 583 | |
| 584 | initial_thread_cb(openpty_cb, &pty); |
| 585 | if(pty.err){ |
| 586 | printk("openpty failed, errno = %d\n", -pty.err); |
| 587 | return; |
| 588 | } |
| 589 | |
| 590 | master = pty.master; |
| 591 | slave = pty.slave; |
| 592 | |
| 593 | if((master == -1) || (slave == -1)){ |
| 594 | printk("openpty failed to allocate a pty\n"); |
| 595 | return; |
| 596 | } |
| 597 | |
| 598 | /* Not now, but complain so we now where we failed. */ |
| 599 | err = raw(master); |
| 600 | if (err < 0) |
| 601 | panic("check_sigio : __raw failed, errno = %d\n", -err); |
| 602 | |
Jeff Dike | 73c8f44 | 2007-02-10 01:44:20 -0800 | [diff] [blame] | 603 | err = async_pty(master, slave); |
Jeff Dike | 8e36706 | 2006-03-27 01:14:32 -0800 | [diff] [blame] | 604 | if(err < 0) |
| 605 | panic("tty_fds : sigio_async failed, err = %d\n", -err); |
| 606 | |
| 607 | if(sigaction(SIGIO, NULL, &old) < 0) |
| 608 | panic("check_sigio : sigaction 1 failed, errno = %d\n", errno); |
| 609 | new = old; |
| 610 | new.sa_handler = handler; |
| 611 | if(sigaction(SIGIO, &new, NULL) < 0) |
| 612 | panic("check_sigio : sigaction 2 failed, errno = %d\n", errno); |
| 613 | |
| 614 | got_sigio = 0; |
| 615 | (*proc)(master, slave); |
| 616 | |
| 617 | close(master); |
| 618 | close(slave); |
| 619 | |
| 620 | if(sigaction(SIGIO, &old, NULL) < 0) |
| 621 | panic("check_sigio : sigaction 3 failed, errno = %d\n", errno); |
| 622 | } |
| 623 | |
| 624 | static void tty_output(int master, int slave) |
| 625 | { |
| 626 | int n; |
| 627 | char buf[512]; |
| 628 | |
| 629 | printk("Checking that host ptys support output SIGIO..."); |
| 630 | |
| 631 | memset(buf, 0, sizeof(buf)); |
| 632 | |
| 633 | while(os_write_file(master, buf, sizeof(buf)) > 0) ; |
| 634 | if(errno != EAGAIN) |
| 635 | panic("check_sigio : write failed, errno = %d\n", errno); |
| 636 | while(((n = os_read_file(slave, buf, sizeof(buf))) > 0) && !got_sigio) ; |
| 637 | |
| 638 | if(got_sigio){ |
| 639 | printk("Yes\n"); |
| 640 | pty_output_sigio = 1; |
| 641 | } |
| 642 | else if(n == -EAGAIN) printk("No, enabling workaround\n"); |
| 643 | else panic("check_sigio : read failed, err = %d\n", n); |
| 644 | } |
| 645 | |
| 646 | static void tty_close(int master, int slave) |
| 647 | { |
| 648 | printk("Checking that host ptys support SIGIO on close..."); |
| 649 | |
| 650 | close(slave); |
| 651 | if(got_sigio){ |
| 652 | printk("Yes\n"); |
| 653 | pty_close_sigio = 1; |
| 654 | } |
| 655 | else printk("No, enabling workaround\n"); |
| 656 | } |
| 657 | |
| 658 | void __init check_sigio(void) |
| 659 | { |
| 660 | if((os_access("/dev/ptmx", OS_ACC_R_OK) < 0) && |
| 661 | (os_access("/dev/ptyp0", OS_ACC_R_OK) < 0)){ |
| 662 | printk("No pseudo-terminals available - skipping pty SIGIO " |
| 663 | "check\n"); |
| 664 | return; |
| 665 | } |
| 666 | check_one_sigio(tty_output); |
| 667 | check_one_sigio(tty_close); |
| 668 | } |
| 669 | |
| 670 | void os_check_bugs(void) |
| 671 | { |
| 672 | check_ptrace(); |
| 673 | check_sigio(); |
Jeff Dike | 8e36706 | 2006-03-27 01:14:32 -0800 | [diff] [blame] | 674 | } |
| 675 | |