Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <stdio.h> |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 7 | #include <unistd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <errno.h> |
| 9 | #include <signal.h> |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 10 | #include <fcntl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <sys/mman.h> |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 12 | #include <sys/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <sys/wait.h> |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 14 | #include <asm/unistd.h> |
Jeff Dike | 36e4546 | 2007-05-06 14:51:11 -0700 | [diff] [blame] | 15 | #include "init.h" |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 16 | #include "kern_constants.h" |
| 17 | #include "longjmp.h" |
| 18 | #include "os.h" |
| 19 | #include "process.h" |
| 20 | #include "skas_ptrace.h" |
| 21 | #include "user.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #define ARBITRARY_ADDR -1 |
| 24 | #define FAILURE_PID -1 |
| 25 | |
| 26 | #define STAT_PATH_LEN sizeof("/proc/#######/stat\0") |
| 27 | #define COMM_SCANF "%*[^)])" |
| 28 | |
| 29 | unsigned long os_process_pc(int pid) |
| 30 | { |
| 31 | char proc_stat[STAT_PATH_LEN], buf[256]; |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 32 | unsigned long pc = ARBITRARY_ADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | int fd, err; |
| 34 | |
| 35 | sprintf(proc_stat, "/proc/%d/stat", pid); |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 36 | fd = open(proc_stat, O_RDONLY, 0); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 37 | if (fd < 0) { |
| 38 | printk(UM_KERN_ERR "os_process_pc - couldn't open '%s', " |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 39 | "errno = %d\n", proc_stat, errno); |
| 40 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | } |
Jeff Dike | a61f334 | 2007-05-06 14:51:35 -0700 | [diff] [blame] | 42 | CATCH_EINTR(err = read(fd, buf, sizeof(buf))); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 43 | if (err < 0) { |
| 44 | printk(UM_KERN_ERR "os_process_pc - couldn't read '%s', " |
| 45 | "err = %d\n", proc_stat, errno); |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 46 | goto out_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
| 48 | os_close_file(fd); |
| 49 | pc = ARBITRARY_ADDR; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 50 | if (sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d " |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 51 | "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d " |
| 52 | "%*d %*d %*d %*d %*d %lu", &pc) != 1) |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 53 | printk(UM_KERN_ERR "os_process_pc - couldn't find pc in '%s'\n", |
| 54 | buf); |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 55 | out_close: |
| 56 | close(fd); |
| 57 | out: |
Jeff Dike | ef0470c | 2007-05-06 14:51:33 -0700 | [diff] [blame] | 58 | return pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | int os_process_parent(int pid) |
| 62 | { |
| 63 | char stat[STAT_PATH_LEN]; |
| 64 | char data[256]; |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 65 | int parent = FAILURE_PID, n, fd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 67 | if (pid == -1) |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 68 | return parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | snprintf(stat, sizeof(stat), "/proc/%d/stat", pid); |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 71 | fd = open(stat, O_RDONLY, 0); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 72 | if (fd < 0) { |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 73 | printk(UM_KERN_ERR "Couldn't open '%s', errno = %d\n", stat, |
| 74 | errno); |
| 75 | return parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Jeff Dike | a61f334 | 2007-05-06 14:51:35 -0700 | [diff] [blame] | 78 | CATCH_EINTR(n = read(fd, data, sizeof(data))); |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 79 | close(fd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 81 | if (n < 0) { |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 82 | printk(UM_KERN_ERR "Couldn't read '%s', errno = %d\n", stat, |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 83 | errno); |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 84 | return parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | parent = FAILURE_PID; |
| 88 | n = sscanf(data, "%*d " COMM_SCANF " %*c %d", &parent); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 89 | if (n != 1) |
| 90 | printk(UM_KERN_ERR "Failed to scan '%s'\n", data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Jeff Dike | ef0470c | 2007-05-06 14:51:33 -0700 | [diff] [blame] | 92 | return parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void os_stop_process(int pid) |
| 96 | { |
| 97 | kill(pid, SIGSTOP); |
| 98 | } |
| 99 | |
| 100 | void os_kill_process(int pid, int reap_child) |
| 101 | { |
| 102 | kill(pid, SIGKILL); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 103 | if (reap_child) |
Stanislaw Gruszka | 4dbed85 | 2007-12-17 16:19:46 -0800 | [diff] [blame] | 104 | CATCH_EINTR(waitpid(pid, NULL, __WALL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Paolo 'Blaisorblade' Giarrusso | 07f4e2c | 2006-02-24 13:03:55 -0800 | [diff] [blame] | 107 | /* This is here uniquely to have access to the userspace errno, i.e. the one |
| 108 | * used by ptrace in case of error. |
| 109 | */ |
| 110 | |
| 111 | long os_ptrace_ldt(long pid, long addr, long data) |
| 112 | { |
| 113 | int ret; |
| 114 | |
| 115 | ret = ptrace(PTRACE_LDT, pid, addr, data); |
| 116 | |
| 117 | if (ret < 0) |
| 118 | return -errno; |
| 119 | return ret; |
| 120 | } |
| 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | /* Kill off a ptraced child by all means available. kill it normally first, |
| 123 | * then PTRACE_KILL it, then PTRACE_CONT it in case it's in a run state from |
| 124 | * which it can't exit directly. |
| 125 | */ |
| 126 | |
| 127 | void os_kill_ptraced_process(int pid, int reap_child) |
| 128 | { |
| 129 | kill(pid, SIGKILL); |
| 130 | ptrace(PTRACE_KILL, pid); |
| 131 | ptrace(PTRACE_CONT, pid); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 132 | if (reap_child) |
Stanislaw Gruszka | 4dbed85 | 2007-12-17 16:19:46 -0800 | [diff] [blame] | 133 | CATCH_EINTR(waitpid(pid, NULL, __WALL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 136 | /* Don't use the glibc version, which caches the result in TLS. It misses some |
| 137 | * syscalls, and also breaks with clone(), which does not unshare the TLS. |
| 138 | */ |
| 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | int os_getpid(void) |
| 141 | { |
Jeff Dike | ef0470c | 2007-05-06 14:51:33 -0700 | [diff] [blame] | 142 | return syscall(__NR_getpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Jeff Dike | cd2ee4a | 2005-05-05 16:15:32 -0700 | [diff] [blame] | 145 | int os_getpgrp(void) |
| 146 | { |
| 147 | return getpgrp(); |
| 148 | } |
| 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | int os_map_memory(void *virt, int fd, unsigned long long off, unsigned long len, |
| 151 | int r, int w, int x) |
| 152 | { |
| 153 | void *loc; |
| 154 | int prot; |
| 155 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 156 | prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | (x ? PROT_EXEC : 0); |
| 158 | |
| 159 | loc = mmap64((void *) virt, len, prot, MAP_SHARED | MAP_FIXED, |
| 160 | fd, off); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 161 | if (loc == MAP_FAILED) |
Jeff Dike | ef0470c | 2007-05-06 14:51:33 -0700 | [diff] [blame] | 162 | return -errno; |
| 163 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | int os_protect_memory(void *addr, unsigned long len, int r, int w, int x) |
| 167 | { |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 168 | int prot = ((r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | (x ? PROT_EXEC : 0)); |
| 170 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 171 | if (mprotect(addr, len, prot) < 0) |
Jeff Dike | ef0470c | 2007-05-06 14:51:33 -0700 | [diff] [blame] | 172 | return -errno; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 173 | |
| 174 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | int os_unmap_memory(void *addr, int len) |
| 178 | { |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 179 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 181 | err = munmap(addr, len); |
| 182 | if (err < 0) |
Jeff Dike | ef0470c | 2007-05-06 14:51:33 -0700 | [diff] [blame] | 183 | return -errno; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 184 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Jeff Dike | 02dea08 | 2006-03-31 02:30:08 -0800 | [diff] [blame] | 187 | #ifndef MADV_REMOVE |
Jeff Dike | b73781c | 2006-04-18 22:20:24 -0700 | [diff] [blame] | 188 | #define MADV_REMOVE KERNEL_MADV_REMOVE |
Jeff Dike | 02dea08 | 2006-03-31 02:30:08 -0800 | [diff] [blame] | 189 | #endif |
| 190 | |
Jeff Dike | 97a1fcb | 2007-07-23 18:43:48 -0700 | [diff] [blame] | 191 | int os_drop_memory(void *addr, int length) |
Jeff Dike | 02dea08 | 2006-03-31 02:30:08 -0800 | [diff] [blame] | 192 | { |
| 193 | int err; |
| 194 | |
| 195 | err = madvise(addr, length, MADV_REMOVE); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 196 | if (err < 0) |
Jeff Dike | 02dea08 | 2006-03-31 02:30:08 -0800 | [diff] [blame] | 197 | err = -errno; |
| 198 | return err; |
| 199 | } |
| 200 | |
Jeff Dike | 36e4546 | 2007-05-06 14:51:11 -0700 | [diff] [blame] | 201 | int __init can_drop_memory(void) |
Jeff Dike | 02dea08 | 2006-03-31 02:30:08 -0800 | [diff] [blame] | 202 | { |
| 203 | void *addr; |
Jeff Dike | e3104f5 | 2006-05-01 12:15:58 -0700 | [diff] [blame] | 204 | int fd, ok = 0; |
Jeff Dike | 02dea08 | 2006-03-31 02:30:08 -0800 | [diff] [blame] | 205 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 206 | printk(UM_KERN_INFO "Checking host MADV_REMOVE support..."); |
Jeff Dike | 02dea08 | 2006-03-31 02:30:08 -0800 | [diff] [blame] | 207 | fd = create_mem_file(UM_KERN_PAGE_SIZE); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 208 | if (fd < 0) { |
| 209 | printk(UM_KERN_ERR "Creating test memory file failed, " |
| 210 | "err = %d\n", -fd); |
Jeff Dike | e3104f5 | 2006-05-01 12:15:58 -0700 | [diff] [blame] | 211 | goto out; |
Jeff Dike | 02dea08 | 2006-03-31 02:30:08 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | addr = mmap64(NULL, UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE, |
Jeff Dike | b73781c | 2006-04-18 22:20:24 -0700 | [diff] [blame] | 215 | MAP_SHARED, fd, 0); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 216 | if (addr == MAP_FAILED) { |
| 217 | printk(UM_KERN_ERR "Mapping test memory file failed, " |
| 218 | "err = %d\n", -errno); |
Jeff Dike | e3104f5 | 2006-05-01 12:15:58 -0700 | [diff] [blame] | 219 | goto out_close; |
Jeff Dike | 02dea08 | 2006-03-31 02:30:08 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 222 | if (madvise(addr, UM_KERN_PAGE_SIZE, MADV_REMOVE) != 0) { |
| 223 | printk(UM_KERN_ERR "MADV_REMOVE failed, err = %d\n", -errno); |
Jeff Dike | e3104f5 | 2006-05-01 12:15:58 -0700 | [diff] [blame] | 224 | goto out_unmap; |
Jeff Dike | 02dea08 | 2006-03-31 02:30:08 -0800 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | printk("OK\n"); |
Jeff Dike | e3104f5 | 2006-05-01 12:15:58 -0700 | [diff] [blame] | 228 | ok = 1; |
| 229 | |
| 230 | out_unmap: |
| 231 | munmap(addr, UM_KERN_PAGE_SIZE); |
| 232 | out_close: |
| 233 | close(fd); |
| 234 | out: |
| 235 | return ok; |
Jeff Dike | 02dea08 | 2006-03-31 02:30:08 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Jeff Dike | e64bd13 | 2006-07-10 04:45:07 -0700 | [diff] [blame] | 238 | void init_new_thread_signals(void) |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 239 | { |
Jeff Dike | e64bd13 | 2006-07-10 04:45:07 -0700 | [diff] [blame] | 240 | set_handler(SIGSEGV, (__sighandler_t) sig_handler, SA_ONSTACK, |
Jeff Dike | 61b63c5 | 2007-10-16 01:27:27 -0700 | [diff] [blame] | 241 | SIGUSR1, SIGIO, SIGWINCH, SIGVTALRM, -1); |
Jeff Dike | e64bd13 | 2006-07-10 04:45:07 -0700 | [diff] [blame] | 242 | set_handler(SIGTRAP, (__sighandler_t) sig_handler, SA_ONSTACK, |
Jeff Dike | 61b63c5 | 2007-10-16 01:27:27 -0700 | [diff] [blame] | 243 | SIGUSR1, SIGIO, SIGWINCH, SIGVTALRM, -1); |
Jeff Dike | e64bd13 | 2006-07-10 04:45:07 -0700 | [diff] [blame] | 244 | set_handler(SIGFPE, (__sighandler_t) sig_handler, SA_ONSTACK, |
Jeff Dike | 61b63c5 | 2007-10-16 01:27:27 -0700 | [diff] [blame] | 245 | SIGUSR1, SIGIO, SIGWINCH, SIGVTALRM, -1); |
Jeff Dike | e64bd13 | 2006-07-10 04:45:07 -0700 | [diff] [blame] | 246 | set_handler(SIGILL, (__sighandler_t) sig_handler, SA_ONSTACK, |
Jeff Dike | 61b63c5 | 2007-10-16 01:27:27 -0700 | [diff] [blame] | 247 | SIGUSR1, SIGIO, SIGWINCH, SIGVTALRM, -1); |
Jeff Dike | e64bd13 | 2006-07-10 04:45:07 -0700 | [diff] [blame] | 248 | set_handler(SIGBUS, (__sighandler_t) sig_handler, SA_ONSTACK, |
Jeff Dike | 61b63c5 | 2007-10-16 01:27:27 -0700 | [diff] [blame] | 249 | SIGUSR1, SIGIO, SIGWINCH, SIGVTALRM, -1); |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 250 | signal(SIGHUP, SIG_IGN); |
| 251 | |
Jeff Dike | 3a24ebf | 2008-02-04 22:31:16 -0800 | [diff] [blame] | 252 | set_handler(SIGIO, (__sighandler_t) sig_handler, |
| 253 | SA_ONSTACK | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, |
| 254 | SIGVTALRM, -1); |
| 255 | signal(SIGWINCH, SIG_IGN); |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Jeff Dike | fab95c5 | 2007-10-16 01:27:05 -0700 | [diff] [blame] | 258 | int run_kernel_thread(int (*fn)(void *), void *arg, jmp_buf **jmp_ptr) |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 259 | { |
Jeff Dike | ad28e02 | 2006-04-18 22:21:41 -0700 | [diff] [blame] | 260 | jmp_buf buf; |
Jeff Dike | a5df0d1 | 2006-07-14 00:24:02 -0700 | [diff] [blame] | 261 | int n; |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 262 | |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 263 | *jmp_ptr = &buf; |
Jeff Dike | a5df0d1 | 2006-07-14 00:24:02 -0700 | [diff] [blame] | 264 | n = UML_SETJMP(&buf); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 265 | if (n != 0) |
Jeff Dike | a5df0d1 | 2006-07-14 00:24:02 -0700 | [diff] [blame] | 266 | return n; |
Jeff Dike | 1d7173b | 2006-01-18 17:42:49 -0800 | [diff] [blame] | 267 | (*fn)(arg); |
Jeff Dike | a5df0d1 | 2006-07-14 00:24:02 -0700 | [diff] [blame] | 268 | return 0; |
Gennady Sharapov | 60d339f | 2005-09-03 15:57:47 -0700 | [diff] [blame] | 269 | } |