nethercote | 41c75da | 2004-10-18 15:34:14 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 3 | /*--- Platform-specific syscalls stuff. syswrap-x86-linux.c ---*/ |
nethercote | 41c75da | 2004-10-18 15:34:14 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
nethercote | 41c75da | 2004-10-18 15:34:14 +0000 | [diff] [blame] | 9 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2005 Nicholas Nethercote |
njn | 2bc1012 | 2005-05-08 02:10:27 +0000 | [diff] [blame] | 11 | njn@valgrind.org |
nethercote | 41c75da | 2004-10-18 15:34:14 +0000 | [diff] [blame] | 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 31 | /* TODO/FIXME jrs 20050207: assignments to the syscall return result |
| 32 | in interrupted_syscall() need to be reviewed. They don't seem |
| 33 | to assign the shadow state. |
| 34 | */ |
| 35 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 36 | #include "pub_core_basics.h" |
| 37 | #include "pub_core_threadstate.h" |
njn | 899ce73 | 2005-06-21 00:28:11 +0000 | [diff] [blame] | 38 | #include "pub_core_debuginfo.h" // Needed for pub_core_aspacemgr :( |
sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 39 | #include "pub_core_aspacemgr.h" |
njn | 899ce73 | 2005-06-21 00:28:11 +0000 | [diff] [blame] | 40 | #include "pub_core_debuglog.h" |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 41 | #include "pub_core_libcbase.h" |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 42 | #include "pub_core_libcassert.h" |
njn | e9befc6 | 2005-06-11 15:51:30 +0000 | [diff] [blame] | 43 | #include "pub_core_libcmman.h" |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 44 | #include "pub_core_libcprint.h" |
njn | f39e9a3 | 2005-06-12 02:43:17 +0000 | [diff] [blame] | 45 | #include "pub_core_libcproc.h" |
njn | de62cbf | 2005-06-10 22:08:14 +0000 | [diff] [blame] | 46 | #include "pub_core_libcsignal.h" |
njn | f4c5016 | 2005-06-20 14:18:12 +0000 | [diff] [blame] | 47 | #include "pub_core_main.h" // For VG_(shutdown_actions_NORETURN)() |
njn | af1d7df | 2005-06-11 01:31:52 +0000 | [diff] [blame] | 48 | #include "pub_core_mallocfree.h" |
njn | f4c5016 | 2005-06-20 14:18:12 +0000 | [diff] [blame] | 49 | #include "pub_core_options.h" |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 50 | #include "pub_core_scheduler.h" |
njn | f4c5016 | 2005-06-20 14:18:12 +0000 | [diff] [blame] | 51 | #include "pub_core_sigframe.h" // For VG_(sigframe_destroy)() |
njn | de62cbf | 2005-06-10 22:08:14 +0000 | [diff] [blame] | 52 | #include "pub_core_signals.h" |
njn | 9abd608 | 2005-06-17 21:31:45 +0000 | [diff] [blame] | 53 | #include "pub_core_syscall.h" |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 54 | #include "pub_core_syswrap.h" |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 55 | #include "pub_core_tooliface.h" |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 56 | |
| 57 | #include "priv_types_n_macros.h" |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 58 | #include "priv_syswrap-generic.h" /* for decls of generic wrappers */ |
| 59 | #include "priv_syswrap-linux.h" /* for decls of linux-ish wrappers */ |
| 60 | #include "priv_syswrap-main.h" |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 61 | |
| 62 | #include "vki_unistd.h" /* for the __NR_* constants */ |
sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 63 | |
sewardj | 4d89e30 | 2005-03-16 22:04:40 +0000 | [diff] [blame] | 64 | |
| 65 | /* --------------------------------------------------------------------- |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 66 | Stacks, thread wrappers |
sewardj | 4d89e30 | 2005-03-16 22:04:40 +0000 | [diff] [blame] | 67 | Note. Why is this stuff here? |
| 68 | ------------------------------------------------------------------ */ |
| 69 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 70 | /* |
| 71 | Allocate a stack for this thread. |
| 72 | |
| 73 | They're allocated lazily, but never freed. |
| 74 | */ |
| 75 | #define FILL 0xdeadbeef |
| 76 | |
njn | 45ed2c6 | 2005-05-16 21:39:23 +0000 | [diff] [blame] | 77 | // Valgrind's stack size, in words. |
| 78 | #define STACK_SIZE_W 16384 |
| 79 | |
njn | 990e90c | 2005-04-05 02:49:09 +0000 | [diff] [blame] | 80 | static UWord* allocstack(ThreadId tid) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 81 | { |
| 82 | ThreadState *tst = VG_(get_ThreadState)(tid); |
njn | 990e90c | 2005-04-05 02:49:09 +0000 | [diff] [blame] | 83 | UWord *esp; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 84 | |
njn | 990e90c | 2005-04-05 02:49:09 +0000 | [diff] [blame] | 85 | if (tst->os_state.valgrind_stack_base == 0) { |
njn | 45ed2c6 | 2005-05-16 21:39:23 +0000 | [diff] [blame] | 86 | void *stk = VG_(mmap)(0, STACK_SIZE_W * sizeof(UWord) + VKI_PAGE_SIZE, |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 87 | VKI_PROT_READ|VKI_PROT_WRITE, |
| 88 | VKI_MAP_PRIVATE|VKI_MAP_ANONYMOUS, |
| 89 | SF_VALGRIND, |
| 90 | -1, 0); |
| 91 | |
| 92 | if (stk != (void *)-1) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 93 | VG_(mprotect)(stk, VKI_PAGE_SIZE, VKI_PROT_NONE); /* guard page */ |
| 94 | tst->os_state.valgrind_stack_base = ((Addr)stk) + VKI_PAGE_SIZE; |
| 95 | tst->os_state.valgrind_stack_szB = STACK_SIZE_W * sizeof(UWord); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 96 | } else |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 97 | return (UWord*)-1; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 98 | } |
| 99 | |
njn | 990e90c | 2005-04-05 02:49:09 +0000 | [diff] [blame] | 100 | for (esp = (UWord*) tst->os_state.valgrind_stack_base; |
| 101 | esp < (UWord*)(tst->os_state.valgrind_stack_base + |
| 102 | tst->os_state.valgrind_stack_szB); |
| 103 | esp++) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 104 | *esp = FILL; |
| 105 | /* esp is left at top of stack */ |
| 106 | |
| 107 | if (0) |
| 108 | VG_(printf)("stack for tid %d at %p (%x); esp=%p\n", |
njn | 990e90c | 2005-04-05 02:49:09 +0000 | [diff] [blame] | 109 | tid, tst->os_state.valgrind_stack_base, |
| 110 | *(UWord*)(tst->os_state.valgrind_stack_base), esp); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 111 | |
| 112 | return esp; |
| 113 | } |
| 114 | |
sewardj | 4d89e30 | 2005-03-16 22:04:40 +0000 | [diff] [blame] | 115 | /* NB: this is identical the the amd64 version. */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 116 | /* Return how many bytes of this stack have not been used */ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 117 | SSizeT VG_(stack_unused)(ThreadId tid) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 118 | { |
| 119 | ThreadState *tst = VG_(get_ThreadState)(tid); |
njn | 990e90c | 2005-04-05 02:49:09 +0000 | [diff] [blame] | 120 | UWord* p; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 121 | |
njn | 990e90c | 2005-04-05 02:49:09 +0000 | [diff] [blame] | 122 | for (p = (UWord*)tst->os_state.valgrind_stack_base; |
| 123 | p && (p < (UWord*)(tst->os_state.valgrind_stack_base + |
| 124 | tst->os_state.valgrind_stack_szB)); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 125 | p++) |
| 126 | if (*p != FILL) |
| 127 | break; |
| 128 | |
| 129 | if (0) |
njn | 990e90c | 2005-04-05 02:49:09 +0000 | [diff] [blame] | 130 | VG_(printf)("p=%p %x tst->os_state.valgrind_stack_base=%p\n", |
| 131 | p, *p, tst->os_state.valgrind_stack_base); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 132 | |
njn | 990e90c | 2005-04-05 02:49:09 +0000 | [diff] [blame] | 133 | return ((Addr)p) - tst->os_state.valgrind_stack_base; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 134 | } |
| 135 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 136 | |
| 137 | /* Run a thread all the way to the end, then do appropriate exit actions |
| 138 | (this is the last-one-out-turn-off-the-lights bit). |
| 139 | */ |
| 140 | static void run_a_thread_NORETURN ( Word tidW ) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 141 | { |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 142 | ThreadId tid = (ThreadId)tidW; |
| 143 | |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 144 | VG_(debugLog)(1, "syswrap-x86-linux", |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 145 | "run_a_thread_NORETURN(tid=%lld): " |
cerion | 7b2c38c | 2005-06-23 07:52:54 +0000 | [diff] [blame] | 146 | "ML_(thread_wrapper) called\n", |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 147 | (ULong)tidW); |
| 148 | |
| 149 | /* Run the thread all the way through. */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 150 | VgSchedReturnCode src = ML_(thread_wrapper)(tid); |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 151 | |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 152 | VG_(debugLog)(1, "syswrap-x86-linux", |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 153 | "run_a_thread_NORETURN(tid=%lld): " |
cerion | 7b2c38c | 2005-06-23 07:52:54 +0000 | [diff] [blame] | 154 | "ML_(thread_wrapper) done\n", |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 155 | (ULong)tidW); |
| 156 | |
| 157 | Int c = VG_(count_living_threads)(); |
| 158 | vg_assert(c >= 1); /* stay sane */ |
| 159 | |
| 160 | if (c == 1) { |
| 161 | |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 162 | VG_(debugLog)(1, "syswrap-x86-linux", |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 163 | "run_a_thread_NORETURN(tid=%lld): " |
| 164 | "last one standing\n", |
| 165 | (ULong)tidW); |
| 166 | |
| 167 | /* We are the last one standing. Keep hold of the lock and |
| 168 | carry on to show final tool results, then exit the entire system. */ |
| 169 | VG_(shutdown_actions_NORETURN)(tid, src); |
| 170 | |
| 171 | } else { |
| 172 | |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 173 | VG_(debugLog)(1, "syswrap-x86-linux", |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 174 | "run_a_thread_NORETURN(tid=%lld): " |
| 175 | "not last one standing\n", |
| 176 | (ULong)tidW); |
| 177 | |
| 178 | /* OK, thread is dead, but others still exist. Just exit. */ |
| 179 | ThreadState *tst = VG_(get_ThreadState)(tid); |
| 180 | |
| 181 | /* This releases the run lock */ |
| 182 | VG_(exit_thread)(tid); |
| 183 | vg_assert(tst->status == VgTs_Zombie); |
| 184 | |
| 185 | /* We have to use this sequence to terminate the thread to |
| 186 | prevent a subtle race. If VG_(exit_thread)() had left the |
| 187 | ThreadState as Empty, then it could have been reallocated, |
| 188 | reusing the stack while we're doing these last cleanups. |
| 189 | Instead, VG_(exit_thread) leaves it as Zombie to prevent |
| 190 | reallocation. We need to make sure we don't touch the stack |
| 191 | between marking it Empty and exiting. Hence the |
| 192 | assembler. */ |
| 193 | asm volatile ( |
| 194 | "movl %1, %0\n" /* set tst->status = VgTs_Empty */ |
| 195 | "movl %2, %%eax\n" /* set %eax = __NR_exit */ |
| 196 | "movl %3, %%ebx\n" /* set %ebx = tst->os_state.exitcode */ |
| 197 | "int $0x80\n" /* exit(tst->os_state.exitcode) */ |
| 198 | : "=m" (tst->status) |
| 199 | : "n" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode)); |
| 200 | |
| 201 | VG_(core_panic)("Thread exit failed?\n"); |
| 202 | } |
| 203 | |
| 204 | /*NOTREACHED*/ |
| 205 | vg_assert(0); |
| 206 | } |
| 207 | |
| 208 | |
njn | fcb7c3e | 2005-06-18 15:54:25 +0000 | [diff] [blame] | 209 | /* Call f(arg1), but first switch stacks, using 'stack' as the new |
| 210 | stack, and use 'retaddr' as f's return-to address. Also, clear all |
| 211 | the integer registers before entering f.*/ |
| 212 | __attribute__((noreturn)) |
| 213 | void call_on_new_stack_0_1 ( Addr stack, |
| 214 | Addr retaddr, |
| 215 | void (*f)(Word), |
| 216 | Word arg1 ); |
| 217 | // 4(%esp) == stack |
| 218 | // 8(%esp) == retaddr |
| 219 | // 12(%esp) == f |
| 220 | // 16(%esp) == arg1 |
| 221 | asm( |
| 222 | "call_on_new_stack_0_1:\n" |
| 223 | " movl %esp, %esi\n" // remember old stack pointer |
| 224 | " movl 4(%esi), %esp\n" // set stack |
| 225 | " pushl 16(%esi)\n" // arg1 to stack |
| 226 | " pushl 8(%esi)\n" // retaddr to stack |
| 227 | " pushl 12(%esi)\n" // f to stack |
| 228 | " movl $0, %eax\n" // zero all GP regs |
| 229 | " movl $0, %ebx\n" |
| 230 | " movl $0, %ecx\n" |
| 231 | " movl $0, %edx\n" |
| 232 | " movl $0, %esi\n" |
| 233 | " movl $0, %edi\n" |
| 234 | " movl $0, %ebp\n" |
| 235 | " ret\n" // jump to f |
| 236 | " ud2\n" // should never get here |
| 237 | ); |
| 238 | |
| 239 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 240 | /* |
| 241 | Allocate a stack for the main thread, and run it all the way to the |
| 242 | end. |
| 243 | */ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 244 | void VG_(main_thread_wrapper_NORETURN)(ThreadId tid) |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 245 | { |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 246 | VG_(debugLog)(1, "syswrap-x86-linux", |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 247 | "entering VG_(main_thread_wrapper_NORETURN)\n"); |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 248 | |
njn | 990e90c | 2005-04-05 02:49:09 +0000 | [diff] [blame] | 249 | UWord* esp = allocstack(tid); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 250 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 251 | /* shouldn't be any other threads around yet */ |
| 252 | vg_assert( VG_(count_living_threads)() == 1 ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 253 | |
sewardj | 7f082a6 | 2005-03-22 01:55:35 +0000 | [diff] [blame] | 254 | call_on_new_stack_0_1( |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 255 | (Addr)esp, /* stack */ |
| 256 | 0, /*bogus return address*/ |
| 257 | run_a_thread_NORETURN, /* fn to call */ |
| 258 | (Word)tid /* arg to give it */ |
sewardj | 7f082a6 | 2005-03-22 01:55:35 +0000 | [diff] [blame] | 259 | ); |
| 260 | |
| 261 | /*NOTREACHED*/ |
| 262 | vg_assert(0); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 263 | } |
| 264 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 265 | |
| 266 | static Int start_thread_NORETURN ( void* arg ) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 267 | { |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 268 | ThreadState* tst = (ThreadState*)arg; |
| 269 | ThreadId tid = tst->tid; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 270 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 271 | run_a_thread_NORETURN ( (Word)tid ); |
| 272 | /*NOTREACHED*/ |
| 273 | vg_assert(0); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 274 | } |
| 275 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 276 | |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 277 | /* --------------------------------------------------------------------- |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 278 | clone() handling |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 279 | ------------------------------------------------------------------ */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 280 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 281 | /* |
| 282 | Perform a clone system call. clone is strange because it has |
| 283 | fork()-like return-twice semantics, so it needs special |
| 284 | handling here. |
| 285 | |
| 286 | Upon entry, we have: |
| 287 | |
| 288 | int (fn)(void*) in 0+FSZ(%esp) |
| 289 | void* child_stack in 4+FSZ(%esp) |
| 290 | int flags in 8+FSZ(%esp) |
| 291 | void* arg in 12+FSZ(%esp) |
| 292 | pid_t* child_tid in 16+FSZ(%esp) |
| 293 | pid_t* parent_tid in 20+FSZ(%esp) |
| 294 | void* tls_ptr in 24+FSZ(%esp) |
| 295 | |
| 296 | System call requires: |
| 297 | |
| 298 | int $__NR_clone in %eax |
| 299 | int flags in %ebx |
| 300 | void* child_stack in %ecx |
| 301 | pid_t* parent_tid in %edx |
| 302 | pid_t* child_tid in %edi |
| 303 | void* tls_ptr in %esi |
| 304 | |
| 305 | Returns an Int encoded in the linux-x86 way, not a SysRes. |
| 306 | */ |
| 307 | #define STRINGIFZ(__str) #__str |
| 308 | #define STRINGIFY(__str) STRINGIFZ(__str) |
| 309 | #define FSZ "4+4+4" /* frame size = retaddr+ebx+edi */ |
| 310 | #define __NR_CLONE STRINGIFY(__NR_clone) |
| 311 | #define __NR_EXIT STRINGIFY(__NR_exit) |
| 312 | |
| 313 | extern |
| 314 | Int do_syscall_clone_x86_linux ( Int (*fn)(void *), |
| 315 | void* stack, |
| 316 | Int flags, |
| 317 | void* arg, |
| 318 | Int* child_tid, |
| 319 | Int* parent_tid, |
| 320 | vki_modify_ldt_t * ); |
| 321 | asm( |
| 322 | "\n" |
| 323 | "do_syscall_clone_x86_linux:\n" |
| 324 | " push %ebx\n" |
| 325 | " push %edi\n" |
| 326 | |
| 327 | /* set up child stack with function and arg */ |
| 328 | " movl 4+"FSZ"(%esp), %ecx\n" /* syscall arg2: child stack */ |
| 329 | " movl 12+"FSZ"(%esp), %ebx\n" /* fn arg */ |
| 330 | " movl 0+"FSZ"(%esp), %eax\n" /* fn */ |
| 331 | " lea -8(%ecx), %ecx\n" /* make space on stack */ |
| 332 | " movl %ebx, 4(%ecx)\n" /* fn arg */ |
| 333 | " movl %eax, 0(%ecx)\n" /* fn */ |
| 334 | |
| 335 | /* get other args to clone */ |
| 336 | " movl 8+"FSZ"(%esp), %ebx\n" /* syscall arg1: flags */ |
| 337 | " movl 20+"FSZ"(%esp), %edx\n" /* syscall arg3: parent tid * */ |
| 338 | " movl 16+"FSZ"(%esp), %edi\n" /* syscall arg4: child tid * */ |
| 339 | " movl 24+"FSZ"(%esp), %esi\n" /* syscall arg5: tls_ptr * */ |
| 340 | " movl $"__NR_CLONE", %eax\n" |
| 341 | " int $0x80\n" /* clone() */ |
| 342 | " testl %eax, %eax\n" /* child if retval == 0 */ |
| 343 | " jnz 1f\n" |
| 344 | |
| 345 | /* CHILD - call thread function */ |
| 346 | " popl %eax\n" |
| 347 | " call *%eax\n" /* call fn */ |
| 348 | |
| 349 | /* exit with result */ |
| 350 | " movl %eax, %ebx\n" /* arg1: return value from fn */ |
| 351 | " movl $"__NR_EXIT", %eax\n" |
| 352 | " int $0x80\n" |
| 353 | |
| 354 | /* Hm, exit returned */ |
| 355 | " ud2\n" |
| 356 | |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 357 | "1:\n" /* PARENT or ERROR */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 358 | " pop %edi\n" |
| 359 | " pop %ebx\n" |
| 360 | " ret\n" |
| 361 | ); |
| 362 | |
| 363 | #undef FSZ |
| 364 | #undef __NR_CLONE |
| 365 | #undef __NR_EXIT |
| 366 | #undef STRINGIFY |
| 367 | #undef STRINGIFZ |
| 368 | |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 369 | |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 370 | // forward declarations |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 371 | static void setup_child ( ThreadArchState*, ThreadArchState*, Bool ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 372 | static SysRes sys_set_thread_area ( ThreadId, vki_modify_ldt_t* ); |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 373 | |
| 374 | /* |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 375 | When a client clones, we need to keep track of the new thread. This means: |
| 376 | 1. allocate a ThreadId+ThreadState+stack for the the thread |
| 377 | |
| 378 | 2. initialize the thread's new VCPU state |
| 379 | |
| 380 | 3. create the thread using the same args as the client requested, |
| 381 | but using the scheduler entrypoint for EIP, and a separate stack |
| 382 | for ESP. |
| 383 | */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 384 | static SysRes do_clone ( ThreadId ptid, |
| 385 | UInt flags, Addr esp, |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 386 | Int* parent_tidptr, |
| 387 | Int* child_tidptr, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 388 | vki_modify_ldt_t *tlsinfo) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 389 | { |
| 390 | static const Bool debug = False; |
| 391 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 392 | ThreadId ctid = VG_(alloc_ThreadState)(); |
| 393 | ThreadState* ptst = VG_(get_ThreadState)(ptid); |
| 394 | ThreadState* ctst = VG_(get_ThreadState)(ctid); |
| 395 | UWord* stack; |
| 396 | Segment* seg; |
| 397 | SysRes res; |
| 398 | Int eax; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 399 | vki_sigset_t blockall, savedmask; |
| 400 | |
| 401 | VG_(sigfillset)(&blockall); |
| 402 | |
| 403 | vg_assert(VG_(is_running_thread)(ptid)); |
| 404 | vg_assert(VG_(is_valid_tid)(ctid)); |
| 405 | |
| 406 | stack = allocstack(ctid); |
| 407 | |
| 408 | /* Copy register state |
| 409 | |
| 410 | Both parent and child return to the same place, and the code |
| 411 | following the clone syscall works out which is which, so we |
| 412 | don't need to worry about it. |
| 413 | |
| 414 | The parent gets the child's new tid returned from clone, but the |
| 415 | child gets 0. |
| 416 | |
| 417 | If the clone call specifies a NULL esp for the new thread, then |
| 418 | it actually gets a copy of the parent's esp. |
| 419 | */ |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 420 | /* HACK: The clone call done by the Quadrics Elan3 driver specifies |
| 421 | clone flags of 0xF00, and it seems to rely on the assumption |
| 422 | that the child inherits a copy of the parent's GDT. Hence that |
| 423 | is passed as an arg to setup_child. */ |
sewardj | 934d2d5 | 2005-05-31 13:08:03 +0000 | [diff] [blame] | 424 | setup_child( &ctst->arch, &ptst->arch, True /*VG_(clo_support_elan3)*/ ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 425 | |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 426 | /* Make sys_clone appear to have returned Success(0) in the |
| 427 | child. */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 428 | ctst->arch.vex.guest_EAX = 0; |
| 429 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 430 | if (esp != 0) |
| 431 | ctst->arch.vex.guest_ESP = esp; |
| 432 | |
| 433 | ctst->os_state.parent = ptid; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 434 | |
| 435 | /* inherit signal mask */ |
njn | affd878 | 2005-05-18 22:56:00 +0000 | [diff] [blame] | 436 | ctst->sig_mask = ptst->sig_mask; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 437 | ctst->tmp_sig_mask = ptst->sig_mask; |
| 438 | |
| 439 | /* We don't really know where the client stack is, because its |
| 440 | allocated by the client. The best we can do is look at the |
| 441 | memory mappings and try to derive some useful information. We |
| 442 | assume that esp starts near its highest possible value, and can |
| 443 | only go down to the start of the mmaped segment. */ |
| 444 | seg = VG_(find_segment)((Addr)esp); |
| 445 | if (seg) { |
njn | 13bfd85 | 2005-06-02 03:52:53 +0000 | [diff] [blame] | 446 | ctst->client_stack_highest_word = (Addr)VG_PGROUNDUP(esp); |
njn | 50ba34e | 2005-04-04 02:41:42 +0000 | [diff] [blame] | 447 | ctst->client_stack_szB = ctst->client_stack_highest_word - seg->addr; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 448 | |
| 449 | if (debug) |
| 450 | VG_(printf)("tid %d: guessed client stack range %p-%p\n", |
njn | 13bfd85 | 2005-06-02 03:52:53 +0000 | [diff] [blame] | 451 | ctid, seg->addr, VG_PGROUNDUP(esp)); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 452 | } else { |
| 453 | VG_(message)(Vg_UserMsg, "!? New thread %d starts with ESP(%p) unmapped\n", |
| 454 | ctid, esp); |
njn | 50ba34e | 2005-04-04 02:41:42 +0000 | [diff] [blame] | 455 | ctst->client_stack_szB = 0; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | if (flags & VKI_CLONE_SETTLS) { |
| 459 | if (debug) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 460 | VG_(printf)("clone child has SETTLS: tls info at %p: idx=%d " |
| 461 | "base=%p limit=%x; esp=%p fs=%x gs=%x\n", |
| 462 | tlsinfo, tlsinfo->entry_number, |
| 463 | tlsinfo->base_addr, tlsinfo->limit, |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 464 | ptst->arch.vex.guest_ESP, |
| 465 | ctst->arch.vex.guest_FS, ctst->arch.vex.guest_GS); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 466 | res = sys_set_thread_area(ctid, tlsinfo); |
| 467 | if (res.isError) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 468 | goto out; |
| 469 | } |
| 470 | |
| 471 | flags &= ~VKI_CLONE_SETTLS; |
| 472 | |
| 473 | /* start the thread with everything blocked */ |
| 474 | VG_(sigprocmask)(VKI_SIG_SETMASK, &blockall, &savedmask); |
| 475 | |
| 476 | /* Create the new thread */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 477 | eax = do_syscall_clone_x86_linux( |
| 478 | start_thread_NORETURN, stack, flags, &VG_(threads)[ctid], |
| 479 | child_tidptr, parent_tidptr, NULL |
| 480 | ); |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame] | 481 | res = VG_(mk_SysRes_x86_linux)( eax ); |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 482 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 483 | VG_(sigprocmask)(VKI_SIG_SETMASK, &savedmask, NULL); |
| 484 | |
| 485 | out: |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 486 | if (res.isError) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 487 | /* clone failed */ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 488 | VG_(cleanup_thread)(&ctst->arch); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 489 | ctst->status = VgTs_Empty; |
| 490 | } |
| 491 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 492 | return res; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 493 | } |
| 494 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 495 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 496 | /* Do a clone which is really a fork() */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 497 | static SysRes do_fork_clone ( ThreadId tid, |
| 498 | UInt flags, Addr esp, |
| 499 | Int* parent_tidptr, |
| 500 | Int* child_tidptr ) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 501 | { |
| 502 | vki_sigset_t fork_saved_mask; |
| 503 | vki_sigset_t mask; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 504 | SysRes res; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 505 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 506 | if (flags & (VKI_CLONE_SETTLS | VKI_CLONE_FS | VKI_CLONE_VM |
| 507 | | VKI_CLONE_FILES | VKI_CLONE_VFORK)) |
| 508 | return VG_(mk_SysRes_Error)( VKI_EINVAL ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 509 | |
| 510 | /* Block all signals during fork, so that we can fix things up in |
| 511 | the child without being interrupted. */ |
| 512 | VG_(sigfillset)(&mask); |
| 513 | VG_(sigprocmask)(VKI_SIG_SETMASK, &mask, &fork_saved_mask); |
| 514 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 515 | /* Since this is the fork() form of clone, we don't need all that |
| 516 | VG_(clone) stuff */ |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 517 | res = VG_(do_syscall5)( __NR_clone, flags, |
| 518 | (UWord)NULL, (UWord)parent_tidptr, |
| 519 | (UWord)NULL, (UWord)child_tidptr ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 520 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 521 | if (!res.isError && res.val == 0) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 522 | /* child */ |
| 523 | VG_(do_atfork_child)(tid); |
| 524 | |
| 525 | /* restore signal mask */ |
| 526 | VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 527 | } |
| 528 | else |
| 529 | if (!res.isError && res.val > 0) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 530 | /* parent */ |
| 531 | if (VG_(clo_trace_syscalls)) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 532 | VG_(printf)(" clone(fork): process %d created child %d\n", |
| 533 | VG_(getpid)(), res.val); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 534 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 535 | /* restore signal mask */ |
| 536 | VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL); |
| 537 | } |
| 538 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 539 | return res; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 540 | } |
| 541 | |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 542 | /* --------------------------------------------------------------------- |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 543 | LDT/GDT simulation |
| 544 | ------------------------------------------------------------------ */ |
| 545 | |
| 546 | /* Details of the LDT simulation |
| 547 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 548 | |
| 549 | When a program runs natively, the linux kernel allows each *thread* |
| 550 | in it to have its own LDT. Almost all programs never do this -- |
| 551 | it's wildly unportable, after all -- and so the kernel never |
| 552 | allocates the structure, which is just as well as an LDT occupies |
| 553 | 64k of memory (8192 entries of size 8 bytes). |
| 554 | |
| 555 | A thread may choose to modify its LDT entries, by doing the |
| 556 | __NR_modify_ldt syscall. In such a situation the kernel will then |
| 557 | allocate an LDT structure for it. Each LDT entry is basically a |
| 558 | (base, limit) pair. A virtual address in a specific segment is |
| 559 | translated to a linear address by adding the segment's base value. |
| 560 | In addition, the virtual address must not exceed the limit value. |
| 561 | |
| 562 | To use an LDT entry, a thread loads one of the segment registers |
| 563 | (%cs, %ss, %ds, %es, %fs, %gs) with the index of the LDT entry (0 |
| 564 | .. 8191) it wants to use. In fact, the required value is (index << |
| 565 | 3) + 7, but that's not important right now. Any normal instruction |
| 566 | which includes an addressing mode can then be made relative to that |
| 567 | LDT entry by prefixing the insn with a so-called segment-override |
| 568 | prefix, a byte which indicates which of the 6 segment registers |
| 569 | holds the LDT index. |
| 570 | |
| 571 | Now, a key constraint is that valgrind's address checks operate in |
| 572 | terms of linear addresses. So we have to explicitly translate |
| 573 | virtual addrs into linear addrs, and that means doing a complete |
| 574 | LDT simulation. |
| 575 | |
| 576 | Calls to modify_ldt are intercepted. For each thread, we maintain |
| 577 | an LDT (with the same normally-never-allocated optimisation that |
| 578 | the kernel does). This is updated as expected via calls to |
| 579 | modify_ldt. |
| 580 | |
| 581 | When a thread does an amode calculation involving a segment |
| 582 | override prefix, the relevant LDT entry for the thread is |
| 583 | consulted. It all works. |
| 584 | |
| 585 | There is a conceptual problem, which appears when switching back to |
| 586 | native execution, either temporarily to pass syscalls to the |
| 587 | kernel, or permanently, when debugging V. Problem at such points |
| 588 | is that it's pretty pointless to copy the simulated machine's |
| 589 | segment registers to the real machine, because we'd also need to |
| 590 | copy the simulated LDT into the real one, and that's prohibitively |
| 591 | expensive. |
| 592 | |
| 593 | Fortunately it looks like no syscalls rely on the segment regs or |
| 594 | LDT being correct, so we can get away with it. Apart from that the |
| 595 | simulation is pretty straightforward. All 6 segment registers are |
| 596 | tracked, although only %ds, %es, %fs and %gs are allowed as |
| 597 | prefixes. Perhaps it could be restricted even more than that -- I |
| 598 | am not sure what is and isn't allowed in user-mode. |
| 599 | */ |
| 600 | |
| 601 | /* Translate a struct modify_ldt_ldt_s to a VexGuestX86SegDescr, using |
| 602 | the Linux kernel's logic (cut-n-paste of code in |
| 603 | linux/kernel/ldt.c). */ |
| 604 | |
| 605 | static |
| 606 | void translate_to_hw_format ( /* IN */ vki_modify_ldt_t* inn, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 607 | /* OUT */ VexGuestX86SegDescr* out, |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 608 | Int oldmode ) |
| 609 | { |
| 610 | UInt entry_1, entry_2; |
| 611 | vg_assert(8 == sizeof(VexGuestX86SegDescr)); |
| 612 | |
| 613 | if (0) |
| 614 | VG_(printf)("translate_to_hw_format: base %p, limit %d\n", |
| 615 | inn->base_addr, inn->limit ); |
| 616 | |
| 617 | /* Allow LDTs to be cleared by the user. */ |
| 618 | if (inn->base_addr == 0 && inn->limit == 0) { |
| 619 | if (oldmode || |
| 620 | (inn->contents == 0 && |
| 621 | inn->read_exec_only == 1 && |
| 622 | inn->seg_32bit == 0 && |
| 623 | inn->limit_in_pages == 0 && |
| 624 | inn->seg_not_present == 1 && |
| 625 | inn->useable == 0 )) { |
| 626 | entry_1 = 0; |
| 627 | entry_2 = 0; |
| 628 | goto install; |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | entry_1 = ((inn->base_addr & 0x0000ffff) << 16) | |
| 633 | (inn->limit & 0x0ffff); |
| 634 | entry_2 = (inn->base_addr & 0xff000000) | |
| 635 | ((inn->base_addr & 0x00ff0000) >> 16) | |
| 636 | (inn->limit & 0xf0000) | |
| 637 | ((inn->read_exec_only ^ 1) << 9) | |
| 638 | (inn->contents << 10) | |
| 639 | ((inn->seg_not_present ^ 1) << 15) | |
| 640 | (inn->seg_32bit << 22) | |
| 641 | (inn->limit_in_pages << 23) | |
| 642 | 0x7000; |
| 643 | if (!oldmode) |
| 644 | entry_2 |= (inn->useable << 20); |
| 645 | |
| 646 | /* Install the new entry ... */ |
| 647 | install: |
| 648 | out->LdtEnt.Words.word1 = entry_1; |
| 649 | out->LdtEnt.Words.word2 = entry_2; |
| 650 | } |
| 651 | |
| 652 | /* Create a zeroed-out GDT. */ |
| 653 | static VexGuestX86SegDescr* alloc_zeroed_x86_GDT ( void ) |
| 654 | { |
| 655 | Int nbytes = VEX_GUEST_X86_GDT_NENT * sizeof(VexGuestX86SegDescr); |
| 656 | return VG_(arena_calloc)(VG_AR_CORE, nbytes, 1); |
| 657 | } |
| 658 | |
| 659 | /* Create a zeroed-out LDT. */ |
| 660 | static VexGuestX86SegDescr* alloc_zeroed_x86_LDT ( void ) |
| 661 | { |
| 662 | Int nbytes = VEX_GUEST_X86_LDT_NENT * sizeof(VexGuestX86SegDescr); |
| 663 | return VG_(arena_calloc)(VG_AR_CORE, nbytes, 1); |
| 664 | } |
| 665 | |
| 666 | /* Free up an LDT or GDT allocated by the above fns. */ |
| 667 | static void free_LDT_or_GDT ( VexGuestX86SegDescr* dt ) |
| 668 | { |
| 669 | vg_assert(dt); |
| 670 | VG_(arena_free)(VG_AR_CORE, (void*)dt); |
| 671 | } |
| 672 | |
| 673 | /* Copy contents between two existing LDTs. */ |
| 674 | static void copy_LDT_from_to ( VexGuestX86SegDescr* src, |
| 675 | VexGuestX86SegDescr* dst ) |
| 676 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 677 | Int i; |
| 678 | vg_assert(src); |
| 679 | vg_assert(dst); |
| 680 | for (i = 0; i < VEX_GUEST_X86_LDT_NENT; i++) |
| 681 | dst[i] = src[i]; |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 682 | } |
| 683 | |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 684 | /* Copy contents between two existing GDTs. */ |
| 685 | static void copy_GDT_from_to ( VexGuestX86SegDescr* src, |
| 686 | VexGuestX86SegDescr* dst ) |
| 687 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 688 | Int i; |
| 689 | vg_assert(src); |
| 690 | vg_assert(dst); |
| 691 | for (i = 0; i < VEX_GUEST_X86_GDT_NENT; i++) |
| 692 | dst[i] = src[i]; |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 693 | } |
| 694 | |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 695 | /* Free this thread's DTs, if it has any. */ |
| 696 | static void deallocate_LGDTs_for_thread ( VexGuestX86State* vex ) |
| 697 | { |
| 698 | vg_assert(sizeof(HWord) == sizeof(void*)); |
| 699 | |
| 700 | if (0) |
| 701 | VG_(printf)("deallocate_LGDTs_for_thread: " |
| 702 | "ldt = 0x%x, gdt = 0x%x\n", |
| 703 | vex->guest_LDT, vex->guest_GDT ); |
| 704 | |
| 705 | if (vex->guest_LDT != (HWord)NULL) { |
| 706 | free_LDT_or_GDT( (VexGuestX86SegDescr*)vex->guest_LDT ); |
| 707 | vex->guest_LDT = (HWord)NULL; |
| 708 | } |
| 709 | |
| 710 | if (vex->guest_GDT != (HWord)NULL) { |
| 711 | free_LDT_or_GDT( (VexGuestX86SegDescr*)vex->guest_GDT ); |
| 712 | vex->guest_GDT = (HWord)NULL; |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | |
| 717 | /* |
| 718 | * linux/kernel/ldt.c |
| 719 | * |
| 720 | * Copyright (C) 1992 Krishna Balasubramanian and Linus Torvalds |
| 721 | * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com> |
| 722 | */ |
| 723 | |
| 724 | /* |
| 725 | * read_ldt() is not really atomic - this is not a problem since |
| 726 | * synchronization of reads and writes done to the LDT has to be |
| 727 | * assured by user-space anyway. Writes are atomic, to protect |
| 728 | * the security checks done on new descriptors. |
| 729 | */ |
| 730 | static |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 731 | SysRes read_ldt ( ThreadId tid, UChar* ptr, UInt bytecount ) |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 732 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 733 | SysRes res; |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 734 | UInt i, size; |
| 735 | UChar* ldt; |
| 736 | |
| 737 | if (0) |
| 738 | VG_(printf)("read_ldt: tid = %d, ptr = %p, bytecount = %d\n", |
| 739 | tid, ptr, bytecount ); |
| 740 | |
| 741 | vg_assert(sizeof(HWord) == sizeof(VexGuestX86SegDescr*)); |
| 742 | vg_assert(8 == sizeof(VexGuestX86SegDescr)); |
| 743 | |
| 744 | ldt = (Char*)(VG_(threads)[tid].arch.vex.guest_LDT); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 745 | res = VG_(mk_SysRes_Success)( 0 ); |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 746 | if (ldt == NULL) |
| 747 | /* LDT not allocated, meaning all entries are null */ |
| 748 | goto out; |
| 749 | |
| 750 | size = VEX_GUEST_X86_LDT_NENT * sizeof(VexGuestX86SegDescr); |
| 751 | if (size > bytecount) |
| 752 | size = bytecount; |
| 753 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 754 | res = VG_(mk_SysRes_Success)( size ); |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 755 | for (i = 0; i < size; i++) |
| 756 | ptr[i] = ldt[i]; |
| 757 | |
| 758 | out: |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 759 | return res; |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | |
| 763 | static |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 764 | SysRes write_ldt ( ThreadId tid, void* ptr, UInt bytecount, Int oldmode ) |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 765 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 766 | SysRes res; |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 767 | VexGuestX86SegDescr* ldt; |
| 768 | vki_modify_ldt_t* ldt_info; |
| 769 | |
| 770 | if (0) |
| 771 | VG_(printf)("write_ldt: tid = %d, ptr = %p, " |
| 772 | "bytecount = %d, oldmode = %d\n", |
| 773 | tid, ptr, bytecount, oldmode ); |
| 774 | |
| 775 | vg_assert(8 == sizeof(VexGuestX86SegDescr)); |
| 776 | vg_assert(sizeof(HWord) == sizeof(VexGuestX86SegDescr*)); |
| 777 | |
| 778 | ldt = (VexGuestX86SegDescr*)VG_(threads)[tid].arch.vex.guest_LDT; |
| 779 | ldt_info = (vki_modify_ldt_t*)ptr; |
| 780 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 781 | res = VG_(mk_SysRes_Error)( VKI_EINVAL ); |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 782 | if (bytecount != sizeof(vki_modify_ldt_t)) |
| 783 | goto out; |
| 784 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 785 | res = VG_(mk_SysRes_Error)( VKI_EINVAL ); |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 786 | if (ldt_info->entry_number >= VEX_GUEST_X86_LDT_NENT) |
| 787 | goto out; |
| 788 | if (ldt_info->contents == 3) { |
| 789 | if (oldmode) |
| 790 | goto out; |
| 791 | if (ldt_info->seg_not_present == 0) |
| 792 | goto out; |
| 793 | } |
| 794 | |
| 795 | /* If this thread doesn't have an LDT, we'd better allocate it |
| 796 | now. */ |
| 797 | if (ldt == (HWord)NULL) { |
| 798 | ldt = alloc_zeroed_x86_LDT(); |
| 799 | VG_(threads)[tid].arch.vex.guest_LDT = (HWord)ldt; |
| 800 | } |
| 801 | |
| 802 | /* Install the new entry ... */ |
| 803 | translate_to_hw_format ( ldt_info, &ldt[ldt_info->entry_number], oldmode ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 804 | res = VG_(mk_SysRes_Success)( 0 ); |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 805 | |
| 806 | out: |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 807 | return res; |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 811 | static SysRes sys_modify_ldt ( ThreadId tid, |
| 812 | Int func, void* ptr, UInt bytecount ) |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 813 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 814 | SysRes ret = VG_(mk_SysRes_Error)( VKI_ENOSYS ); |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 815 | |
| 816 | switch (func) { |
| 817 | case 0: |
| 818 | ret = read_ldt(tid, ptr, bytecount); |
| 819 | break; |
| 820 | case 1: |
| 821 | ret = write_ldt(tid, ptr, bytecount, 1); |
| 822 | break; |
| 823 | case 2: |
| 824 | VG_(unimplemented)("sys_modify_ldt: func == 2"); |
| 825 | /* god knows what this is about */ |
| 826 | /* ret = read_default_ldt(ptr, bytecount); */ |
| 827 | /*UNREACHED*/ |
| 828 | break; |
| 829 | case 0x11: |
| 830 | ret = write_ldt(tid, ptr, bytecount, 0); |
| 831 | break; |
| 832 | } |
| 833 | return ret; |
| 834 | } |
| 835 | |
| 836 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 837 | static SysRes sys_set_thread_area ( ThreadId tid, vki_modify_ldt_t* info ) |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 838 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 839 | Int idx; |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 840 | VexGuestX86SegDescr* gdt; |
| 841 | |
| 842 | vg_assert(8 == sizeof(VexGuestX86SegDescr)); |
| 843 | vg_assert(sizeof(HWord) == sizeof(VexGuestX86SegDescr*)); |
| 844 | |
| 845 | if (info == NULL) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 846 | return VG_(mk_SysRes_Error)( VKI_EFAULT ); |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 847 | |
| 848 | gdt = (VexGuestX86SegDescr*)VG_(threads)[tid].arch.vex.guest_GDT; |
| 849 | |
| 850 | /* If the thread doesn't have a GDT, allocate it now. */ |
| 851 | if (!gdt) { |
| 852 | gdt = alloc_zeroed_x86_GDT(); |
| 853 | VG_(threads)[tid].arch.vex.guest_GDT = (HWord)gdt; |
| 854 | } |
| 855 | |
| 856 | idx = info->entry_number; |
| 857 | |
| 858 | if (idx == -1) { |
| 859 | /* Find and use the first free entry. */ |
| 860 | for (idx = 0; idx < VEX_GUEST_X86_GDT_NENT; idx++) { |
| 861 | if (gdt[idx].LdtEnt.Words.word1 == 0 |
| 862 | && gdt[idx].LdtEnt.Words.word2 == 0) |
| 863 | break; |
| 864 | } |
| 865 | |
| 866 | if (idx == VEX_GUEST_X86_GDT_NENT) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 867 | return VG_(mk_SysRes_Error)( VKI_ESRCH ); |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 868 | } else if (idx < 0 || idx >= VEX_GUEST_X86_GDT_NENT) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 869 | return VG_(mk_SysRes_Error)( VKI_EINVAL ); |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | translate_to_hw_format(info, &gdt[idx], 0); |
| 873 | |
| 874 | VG_TRACK( pre_mem_write, Vg_CoreSysCall, tid, |
| 875 | "set_thread_area(info->entry)", |
| 876 | (Addr) & info->entry_number, sizeof(unsigned int) ); |
| 877 | info->entry_number = idx; |
| 878 | VG_TRACK( post_mem_write, Vg_CoreSysCall, tid, |
| 879 | (Addr) & info->entry_number, sizeof(unsigned int) ); |
| 880 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 881 | return VG_(mk_SysRes_Success)( 0 ); |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 885 | static SysRes sys_get_thread_area ( ThreadId tid, vki_modify_ldt_t* info ) |
| 886 | { |
| 887 | Int idx; |
| 888 | VexGuestX86SegDescr* gdt; |
| 889 | |
| 890 | vg_assert(sizeof(HWord) == sizeof(VexGuestX86SegDescr*)); |
| 891 | vg_assert(8 == sizeof(VexGuestX86SegDescr)); |
| 892 | |
| 893 | if (info == NULL) |
| 894 | return VG_(mk_SysRes_Error)( VKI_EFAULT ); |
| 895 | |
| 896 | idx = info->entry_number; |
| 897 | |
| 898 | if (idx < 0 || idx >= VEX_GUEST_X86_GDT_NENT) |
| 899 | return VG_(mk_SysRes_Error)( VKI_EINVAL ); |
| 900 | |
| 901 | gdt = (VexGuestX86SegDescr*)VG_(threads)[tid].arch.vex.guest_GDT; |
| 902 | |
| 903 | /* If the thread doesn't have a GDT, allocate it now. */ |
| 904 | if (!gdt) { |
| 905 | gdt = alloc_zeroed_x86_GDT(); |
| 906 | VG_(threads)[tid].arch.vex.guest_GDT = (HWord)gdt; |
| 907 | } |
| 908 | |
| 909 | info->base_addr = ( gdt[idx].LdtEnt.Bits.BaseHi << 24 ) | |
| 910 | ( gdt[idx].LdtEnt.Bits.BaseMid << 16 ) | |
| 911 | gdt[idx].LdtEnt.Bits.BaseLow; |
| 912 | info->limit = ( gdt[idx].LdtEnt.Bits.LimitHi << 16 ) | |
| 913 | gdt[idx].LdtEnt.Bits.LimitLow; |
| 914 | info->seg_32bit = gdt[idx].LdtEnt.Bits.Default_Big; |
| 915 | info->contents = ( gdt[idx].LdtEnt.Bits.Type >> 2 ) & 0x3; |
| 916 | info->read_exec_only = ( gdt[idx].LdtEnt.Bits.Type & 0x1 ) ^ 0x1; |
| 917 | info->limit_in_pages = gdt[idx].LdtEnt.Bits.Granularity; |
| 918 | info->seg_not_present = gdt[idx].LdtEnt.Bits.Pres ^ 0x1; |
| 919 | info->useable = gdt[idx].LdtEnt.Bits.Sys; |
| 920 | info->reserved = 0; |
| 921 | |
| 922 | return VG_(mk_SysRes_Error)( 0 ); |
| 923 | } |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 924 | |
| 925 | /* --------------------------------------------------------------------- |
| 926 | More thread stuff |
| 927 | ------------------------------------------------------------------ */ |
| 928 | |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 929 | void VG_(cleanup_thread) ( ThreadArchState* arch ) |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 930 | { |
| 931 | /* Release arch-specific resources held by this thread. */ |
| 932 | /* On x86, we have to dump the LDT and GDT. */ |
| 933 | deallocate_LGDTs_for_thread( &arch->vex ); |
| 934 | } |
| 935 | |
| 936 | |
| 937 | static void setup_child ( /*OUT*/ ThreadArchState *child, |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 938 | /*IN*/ ThreadArchState *parent, |
| 939 | Bool inherit_parents_GDT ) |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 940 | { |
| 941 | /* We inherit our parent's guest state. */ |
| 942 | child->vex = parent->vex; |
| 943 | child->vex_shadow = parent->vex_shadow; |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 944 | |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 945 | /* We inherit our parent's LDT. */ |
| 946 | if (parent->vex.guest_LDT == (HWord)NULL) { |
| 947 | /* We hope this is the common case. */ |
| 948 | child->vex.guest_LDT = (HWord)NULL; |
| 949 | } else { |
| 950 | /* No luck .. we have to take a copy of the parent's. */ |
| 951 | child->vex.guest_LDT = (HWord)alloc_zeroed_x86_LDT(); |
| 952 | copy_LDT_from_to( (VexGuestX86SegDescr*)parent->vex.guest_LDT, |
| 953 | (VexGuestX86SegDescr*)child->vex.guest_LDT ); |
| 954 | } |
| 955 | |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 956 | /* Either we start with an empty GDT (the usual case) or inherit a |
| 957 | copy of our parents' one (Quadrics Elan3 driver -style clone |
| 958 | only). */ |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 959 | child->vex.guest_GDT = (HWord)NULL; |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 960 | |
| 961 | if (inherit_parents_GDT && parent->vex.guest_GDT != (HWord)NULL) { |
| 962 | child->vex.guest_GDT = (HWord)alloc_zeroed_x86_GDT(); |
| 963 | copy_GDT_from_to( (VexGuestX86SegDescr*)parent->vex.guest_GDT, |
| 964 | (VexGuestX86SegDescr*)child->vex.guest_GDT ); |
| 965 | } |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 966 | } |
| 967 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 968 | |
njn | 2335d11 | 2005-05-15 20:52:04 +0000 | [diff] [blame] | 969 | /* --------------------------------------------------------------------- |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 970 | PRE/POST wrappers for x86/Linux-specific syscalls |
| 971 | ------------------------------------------------------------------ */ |
| 972 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 973 | #define PRE(name) DEFN_PRE_TEMPLATE(x86_linux, name) |
| 974 | #define POST(name) DEFN_POST_TEMPLATE(x86_linux, name) |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 975 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 976 | /* Add prototypes for the wrappers declared here, so that gcc doesn't |
| 977 | harass us for not having prototypes. Really this is a kludge -- |
| 978 | the right thing to do is to make these wrappers 'static' since they |
| 979 | aren't visible outside this file, but that requires even more macro |
| 980 | magic. */ |
| 981 | DECL_TEMPLATE(x86_linux, sys_socketcall); |
| 982 | DECL_TEMPLATE(x86_linux, sys_stat64); |
| 983 | DECL_TEMPLATE(x86_linux, sys_fstat64); |
| 984 | DECL_TEMPLATE(x86_linux, sys_lstat64); |
| 985 | DECL_TEMPLATE(x86_linux, sys_clone); |
| 986 | DECL_TEMPLATE(x86_linux, old_mmap); |
| 987 | DECL_TEMPLATE(x86_linux, sys_sigreturn); |
| 988 | DECL_TEMPLATE(x86_linux, sys_ipc); |
| 989 | DECL_TEMPLATE(x86_linux, sys_rt_sigreturn); |
| 990 | DECL_TEMPLATE(x86_linux, sys_modify_ldt); |
sewardj | bc22cf7 | 2005-06-08 00:02:49 +0000 | [diff] [blame] | 991 | DECL_TEMPLATE(x86_linux, sys_set_thread_area); |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 992 | DECL_TEMPLATE(x86_linux, sys_get_thread_area); |
sewardj | 8c25732 | 2005-06-08 01:01:48 +0000 | [diff] [blame] | 993 | DECL_TEMPLATE(x86_linux, sys_ptrace); |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 994 | DECL_TEMPLATE(x86_linux, sys_sigaction); |
| 995 | DECL_TEMPLATE(x86_linux, old_select); |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 996 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 997 | PRE(old_select) |
| 998 | { |
| 999 | /* struct sel_arg_struct { |
| 1000 | unsigned long n; |
| 1001 | fd_set *inp, *outp, *exp; |
| 1002 | struct timeval *tvp; |
| 1003 | }; |
| 1004 | */ |
| 1005 | PRE_REG_READ1(long, "old_select", struct sel_arg_struct *, args); |
| 1006 | PRE_MEM_READ( "old_select(args)", ARG1, 5*sizeof(UWord) ); |
| 1007 | *flags |= SfMayBlock; |
| 1008 | { |
| 1009 | UInt* arg_struct = (UInt*)ARG1; |
| 1010 | UInt a1, a2, a3, a4, a5; |
| 1011 | |
| 1012 | a1 = arg_struct[0]; |
| 1013 | a2 = arg_struct[1]; |
| 1014 | a3 = arg_struct[2]; |
| 1015 | a4 = arg_struct[3]; |
| 1016 | a5 = arg_struct[4]; |
| 1017 | |
| 1018 | PRINT("old_select ( %d, %p, %p, %p, %p )", a1,a2,a3,a4,a5); |
| 1019 | if (a2 != (Addr)NULL) |
| 1020 | PRE_MEM_READ( "old_select(readfds)", a2, a1/8 /* __FD_SETSIZE/8 */ ); |
| 1021 | if (a3 != (Addr)NULL) |
| 1022 | PRE_MEM_READ( "old_select(writefds)", a3, a1/8 /* __FD_SETSIZE/8 */ ); |
| 1023 | if (a4 != (Addr)NULL) |
| 1024 | PRE_MEM_READ( "old_select(exceptfds)", a4, a1/8 /* __FD_SETSIZE/8 */ ); |
| 1025 | if (a5 != (Addr)NULL) |
| 1026 | PRE_MEM_READ( "old_select(timeout)", a5, sizeof(struct vki_timeval) ); |
| 1027 | } |
| 1028 | } |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1029 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1030 | PRE(sys_clone) |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1031 | { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1032 | UInt cloneflags; |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1033 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1034 | PRINT("sys_clone ( %x, %p, %p, %p, %p )",ARG1,ARG2,ARG3,ARG4,ARG5); |
| 1035 | PRE_REG_READ5(int, "clone", |
| 1036 | unsigned long, flags, |
| 1037 | void *, child_stack, |
| 1038 | int *, parent_tidptr, |
| 1039 | vki_modify_ldt_t *, tlsinfo, |
| 1040 | int *, child_tidptr); |
| 1041 | |
| 1042 | if (ARG1 & VKI_CLONE_PARENT_SETTID) { |
| 1043 | PRE_MEM_WRITE("clone(parent_tidptr)", ARG3, sizeof(Int)); |
| 1044 | if (!VG_(is_addressable)(ARG3, sizeof(Int), VKI_PROT_WRITE)) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1045 | SET_STATUS_Failure( VKI_EFAULT ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1046 | return; |
| 1047 | } |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1048 | } |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1049 | if (ARG1 & (VKI_CLONE_CHILD_SETTID | VKI_CLONE_CHILD_CLEARTID)) { |
| 1050 | PRE_MEM_WRITE("clone(child_tidptr)", ARG5, sizeof(Int)); |
| 1051 | if (!VG_(is_addressable)(ARG5, sizeof(Int), VKI_PROT_WRITE)) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1052 | SET_STATUS_Failure( VKI_EFAULT ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1053 | return; |
| 1054 | } |
| 1055 | } |
| 1056 | if (ARG1 & VKI_CLONE_SETTLS) { |
| 1057 | PRE_MEM_READ("clone(tls_user_desc)", ARG4, sizeof(vki_modify_ldt_t)); |
| 1058 | if (!VG_(is_addressable)(ARG4, sizeof(vki_modify_ldt_t), VKI_PROT_READ)) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1059 | SET_STATUS_Failure( VKI_EFAULT ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1060 | return; |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | cloneflags = ARG1; |
| 1065 | |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1066 | if (!ML_(client_signal_OK)(ARG1 & VKI_CSIGNAL)) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1067 | SET_STATUS_Failure( VKI_EINVAL ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1068 | return; |
| 1069 | } |
| 1070 | |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 1071 | /* Be ultra-paranoid and filter out any clone-variants we don't understand: |
| 1072 | - ??? specifies clone flags of 0x100011 |
| 1073 | - ??? specifies clone flags of 0x1200011. |
| 1074 | - NPTL specifies clone flags of 0x7D0F00. |
| 1075 | - The Quadrics Elan3 driver specifies clone flags of 0xF00. |
| 1076 | Everything else is rejected. |
| 1077 | */ |
sewardj | 934d2d5 | 2005-05-31 13:08:03 +0000 | [diff] [blame] | 1078 | if ( |
| 1079 | (cloneflags == 0x100011 || cloneflags == 0x1200011 |
| 1080 | || cloneflags == 0x7D0F00 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1081 | || cloneflags == 0x790F00 |
sewardj | d15ce0c | 2005-05-31 21:07:01 +0000 | [diff] [blame] | 1082 | || cloneflags == 0x3D0F00 |
sewardj | 934d2d5 | 2005-05-31 13:08:03 +0000 | [diff] [blame] | 1083 | || cloneflags == 0xF00 |
| 1084 | || cloneflags == 0xF21)) { |
| 1085 | /* OK */ |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 1086 | } |
| 1087 | else { |
| 1088 | /* Nah. We don't like it. Go away. */ |
| 1089 | goto reject; |
| 1090 | } |
| 1091 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1092 | /* Only look at the flags we really care about */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1093 | switch (cloneflags & (VKI_CLONE_VM | VKI_CLONE_FS |
| 1094 | | VKI_CLONE_FILES | VKI_CLONE_VFORK)) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1095 | case VKI_CLONE_VM | VKI_CLONE_FS | VKI_CLONE_FILES: |
| 1096 | /* thread creation */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1097 | SET_STATUS_from_SysRes( |
| 1098 | do_clone(tid, |
| 1099 | ARG1, /* flags */ |
| 1100 | (Addr)ARG2, /* child ESP */ |
| 1101 | (Int *)ARG3, /* parent_tidptr */ |
| 1102 | (Int *)ARG5, /* child_tidptr */ |
| 1103 | (vki_modify_ldt_t *)ARG4)); /* set_tls */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1104 | break; |
| 1105 | |
| 1106 | case VKI_CLONE_VFORK | VKI_CLONE_VM: /* vfork */ |
| 1107 | /* FALLTHROUGH - assume vfork == fork */ |
| 1108 | cloneflags &= ~(VKI_CLONE_VFORK | VKI_CLONE_VM); |
| 1109 | |
| 1110 | case 0: /* plain fork */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1111 | SET_STATUS_from_SysRes( |
| 1112 | do_fork_clone(tid, |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 1113 | cloneflags, /* flags */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1114 | (Addr)ARG2, /* child ESP */ |
| 1115 | (Int *)ARG3, /* parent_tidptr */ |
| 1116 | (Int *)ARG5)); /* child_tidptr */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1117 | break; |
| 1118 | |
| 1119 | default: |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 1120 | reject: |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1121 | /* should we just ENOSYS? */ |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 1122 | VG_(message)(Vg_UserMsg, ""); |
| 1123 | VG_(message)(Vg_UserMsg, "Unsupported clone() flags: 0x%x", ARG1); |
| 1124 | VG_(message)(Vg_UserMsg, ""); |
| 1125 | VG_(message)(Vg_UserMsg, "NOTE: if this happened when attempting " |
| 1126 | "to run code using"); |
| 1127 | VG_(message)(Vg_UserMsg, " Quadrics Elan3 user-space drivers," |
| 1128 | " you should re-run "); |
| 1129 | VG_(message)(Vg_UserMsg, " with --support-elan3=yes."); |
| 1130 | VG_(message)(Vg_UserMsg, ""); |
| 1131 | VG_(message)(Vg_UserMsg, "The only supported clone() uses are:"); |
| 1132 | VG_(message)(Vg_UserMsg, " - via a threads library (LinuxThreads or NPTL)"); |
| 1133 | VG_(message)(Vg_UserMsg, " - via the implementation of fork or vfork"); |
| 1134 | VG_(message)(Vg_UserMsg, " - for the Quadrics Elan3 user-space driver"); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1135 | VG_(unimplemented) |
sewardj | 468dc79 | 2005-05-31 10:12:06 +0000 | [diff] [blame] | 1136 | ("Valgrind does not support general clone()."); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1139 | if (SUCCESS) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1140 | if (ARG1 & VKI_CLONE_PARENT_SETTID) |
| 1141 | POST_MEM_WRITE(ARG3, sizeof(Int)); |
| 1142 | if (ARG1 & (VKI_CLONE_CHILD_SETTID | VKI_CLONE_CHILD_CLEARTID)) |
| 1143 | POST_MEM_WRITE(ARG5, sizeof(Int)); |
| 1144 | |
| 1145 | /* Thread creation was successful; let the child have the chance |
| 1146 | to run */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1147 | *flags |= SfYieldAfter; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1151 | PRE(sys_sigreturn) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1152 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1153 | ThreadState* tst; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1154 | PRINT("sigreturn ( )"); |
| 1155 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1156 | vg_assert(VG_(is_valid_tid)(tid)); |
| 1157 | vg_assert(tid >= 1 && tid < VG_N_THREADS); |
| 1158 | vg_assert(VG_(is_running_thread)(tid)); |
| 1159 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1160 | /* Adjust esp to point to start of frame; skip back up over |
| 1161 | sigreturn sequence's "popl %eax" and handler ret addr */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1162 | tst = VG_(get_ThreadState)(tid); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1163 | tst->arch.vex.guest_ESP -= sizeof(Addr)+sizeof(Word); |
| 1164 | |
| 1165 | /* This is only so that the EIP is (might be) useful to report if |
| 1166 | something goes wrong in the sigreturn */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1167 | ML_(fixup_guest_state_to_restart_syscall)(&tst->arch); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1168 | |
sewardj | 985fabb | 2005-04-24 14:18:14 +0000 | [diff] [blame] | 1169 | VG_(sigframe_destroy)(tid, False); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1170 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1171 | /* For unclear reasons, it appears we need the syscall to return |
| 1172 | without changing %EAX. Since %EAX is the return value, and can |
| 1173 | denote either success or failure, we must set up so that the |
| 1174 | driver logic copies it back unchanged. Also, note %EAX is of |
| 1175 | the guest registers written by VG_(sigframe_destroy). */ |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame] | 1176 | SET_STATUS_from_SysRes( VG_(mk_SysRes_x86_linux)( tst->arch.vex.guest_EAX ) ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1177 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1178 | /* Check to see if some any signals arose as a result of this. */ |
| 1179 | *flags |= SfPollAfter; |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1182 | PRE(sys_rt_sigreturn) |
sewardj | d571aff | 2005-03-15 14:47:30 +0000 | [diff] [blame] | 1183 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1184 | ThreadState* tst; |
sewardj | d571aff | 2005-03-15 14:47:30 +0000 | [diff] [blame] | 1185 | PRINT("rt_sigreturn ( )"); |
| 1186 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1187 | vg_assert(VG_(is_valid_tid)(tid)); |
| 1188 | vg_assert(tid >= 1 && tid < VG_N_THREADS); |
| 1189 | vg_assert(VG_(is_running_thread)(tid)); |
| 1190 | |
sewardj | d571aff | 2005-03-15 14:47:30 +0000 | [diff] [blame] | 1191 | /* Adjust esp to point to start of frame; skip back up over handler |
| 1192 | ret addr */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1193 | tst = VG_(get_ThreadState)(tid); |
sewardj | d571aff | 2005-03-15 14:47:30 +0000 | [diff] [blame] | 1194 | tst->arch.vex.guest_ESP -= sizeof(Addr); |
| 1195 | |
| 1196 | /* This is only so that the EIP is (might be) useful to report if |
| 1197 | something goes wrong in the sigreturn */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1198 | ML_(fixup_guest_state_to_restart_syscall)(&tst->arch); |
sewardj | d571aff | 2005-03-15 14:47:30 +0000 | [diff] [blame] | 1199 | |
sewardj | 5bcde92 | 2005-05-03 22:31:22 +0000 | [diff] [blame] | 1200 | VG_(sigframe_destroy)(tid, True); |
sewardj | d571aff | 2005-03-15 14:47:30 +0000 | [diff] [blame] | 1201 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1202 | /* For unclear reasons, it appears we need the syscall to return |
| 1203 | without changing %EAX. Since %EAX is the return value, and can |
| 1204 | denote either success or failure, we must set up so that the |
| 1205 | driver logic copies it back unchanged. Also, note %EAX is of |
| 1206 | the guest registers written by VG_(sigframe_destroy). */ |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame] | 1207 | SET_STATUS_from_SysRes( VG_(mk_SysRes_x86_linux)( tst->arch.vex.guest_EAX ) ); |
sewardj | d571aff | 2005-03-15 14:47:30 +0000 | [diff] [blame] | 1208 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1209 | /* Check to see if some any signals arose as a result of this. */ |
| 1210 | *flags |= SfPollAfter; |
sewardj | d571aff | 2005-03-15 14:47:30 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1213 | PRE(sys_modify_ldt) |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1214 | { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 1215 | PRINT("sys_modify_ldt ( %d, %p, %d )", ARG1,ARG2,ARG3); |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1216 | PRE_REG_READ3(int, "modify_ldt", int, func, void *, ptr, |
| 1217 | unsigned long, bytecount); |
| 1218 | |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 1219 | if (ARG1 == 0) { |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1220 | /* read the LDT into ptr */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 1221 | PRE_MEM_WRITE( "modify_ldt(ptr)", ARG2, ARG3 ); |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1222 | } |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 1223 | if (ARG1 == 1 || ARG1 == 0x11) { |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1224 | /* write the LDT with the entry pointed at by ptr */ |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 1225 | PRE_MEM_READ( "modify_ldt(ptr)", ARG2, sizeof(vki_modify_ldt_t) ); |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1226 | } |
| 1227 | /* "do" the syscall ourselves; the kernel never sees it */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1228 | SET_STATUS_from_SysRes( sys_modify_ldt( tid, ARG1, (void*)ARG2, ARG3 ) ); |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1229 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1230 | if (ARG1 == 0 && SUCCESS && RES > 0) { |
njn | 22cfccb | 2004-11-27 16:10:23 +0000 | [diff] [blame] | 1231 | POST_MEM_WRITE( ARG2, RES ); |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | |
sewardj | bc22cf7 | 2005-06-08 00:02:49 +0000 | [diff] [blame] | 1235 | PRE(sys_set_thread_area) |
| 1236 | { |
| 1237 | PRINT("sys_set_thread_area ( %p )", ARG1); |
| 1238 | PRE_REG_READ1(int, "set_thread_area", struct user_desc *, u_info) |
| 1239 | PRE_MEM_READ( "set_thread_area(u_info)", ARG1, sizeof(vki_modify_ldt_t) ); |
| 1240 | |
| 1241 | /* "do" the syscall ourselves; the kernel never sees it */ |
| 1242 | SET_STATUS_from_SysRes( sys_set_thread_area( tid, (void *)ARG1 ) ); |
| 1243 | } |
| 1244 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 1245 | PRE(sys_get_thread_area) |
| 1246 | { |
| 1247 | PRINT("sys_get_thread_area ( %p )", ARG1); |
| 1248 | PRE_REG_READ1(int, "get_thread_area", struct user_desc *, u_info) |
| 1249 | PRE_MEM_WRITE( "get_thread_area(u_info)", ARG1, sizeof(vki_modify_ldt_t) ); |
| 1250 | |
| 1251 | /* "do" the syscall ourselves; the kernel never sees it */ |
| 1252 | SET_STATUS_from_SysRes( sys_get_thread_area( tid, (void *)ARG1 ) ); |
| 1253 | |
| 1254 | if (SUCCESS) { |
| 1255 | POST_MEM_WRITE( ARG1, sizeof(vki_modify_ldt_t) ); |
| 1256 | } |
| 1257 | } |
sewardj | 8c25732 | 2005-06-08 01:01:48 +0000 | [diff] [blame] | 1258 | |
| 1259 | // Parts of this are x86-specific, but the *PEEK* cases are generic. |
| 1260 | // XXX: Why is the memory pointed to by ARG3 never checked? |
| 1261 | PRE(sys_ptrace) |
| 1262 | { |
| 1263 | PRINT("sys_ptrace ( %d, %d, %p, %p )", ARG1,ARG2,ARG3,ARG4); |
| 1264 | PRE_REG_READ4(int, "ptrace", |
| 1265 | long, request, long, pid, long, addr, long, data); |
| 1266 | switch (ARG1) { |
| 1267 | case VKI_PTRACE_PEEKTEXT: |
| 1268 | case VKI_PTRACE_PEEKDATA: |
| 1269 | case VKI_PTRACE_PEEKUSR: |
| 1270 | PRE_MEM_WRITE( "ptrace(peek)", ARG4, |
| 1271 | sizeof (long)); |
| 1272 | break; |
| 1273 | case VKI_PTRACE_GETREGS: |
| 1274 | PRE_MEM_WRITE( "ptrace(getregs)", ARG4, |
| 1275 | sizeof (struct vki_user_regs_struct)); |
| 1276 | break; |
| 1277 | case VKI_PTRACE_GETFPREGS: |
| 1278 | PRE_MEM_WRITE( "ptrace(getfpregs)", ARG4, |
| 1279 | sizeof (struct vki_user_i387_struct)); |
| 1280 | break; |
| 1281 | case VKI_PTRACE_GETFPXREGS: |
| 1282 | PRE_MEM_WRITE( "ptrace(getfpxregs)", ARG4, |
| 1283 | sizeof(struct vki_user_fxsr_struct) ); |
| 1284 | break; |
| 1285 | case VKI_PTRACE_SETREGS: |
| 1286 | PRE_MEM_READ( "ptrace(setregs)", ARG4, |
| 1287 | sizeof (struct vki_user_regs_struct)); |
| 1288 | break; |
| 1289 | case VKI_PTRACE_SETFPREGS: |
| 1290 | PRE_MEM_READ( "ptrace(setfpregs)", ARG4, |
| 1291 | sizeof (struct vki_user_i387_struct)); |
| 1292 | break; |
| 1293 | case VKI_PTRACE_SETFPXREGS: |
| 1294 | PRE_MEM_READ( "ptrace(setfpxregs)", ARG4, |
| 1295 | sizeof(struct vki_user_fxsr_struct) ); |
| 1296 | break; |
| 1297 | default: |
| 1298 | break; |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | POST(sys_ptrace) |
| 1303 | { |
| 1304 | switch (ARG1) { |
| 1305 | case VKI_PTRACE_PEEKTEXT: |
| 1306 | case VKI_PTRACE_PEEKDATA: |
| 1307 | case VKI_PTRACE_PEEKUSR: |
| 1308 | POST_MEM_WRITE( ARG4, sizeof (long)); |
| 1309 | break; |
| 1310 | case VKI_PTRACE_GETREGS: |
| 1311 | POST_MEM_WRITE( ARG4, sizeof (struct vki_user_regs_struct)); |
| 1312 | break; |
| 1313 | case VKI_PTRACE_GETFPREGS: |
| 1314 | POST_MEM_WRITE( ARG4, sizeof (struct vki_user_i387_struct)); |
| 1315 | break; |
| 1316 | case VKI_PTRACE_GETFPXREGS: |
| 1317 | POST_MEM_WRITE( ARG4, sizeof(struct vki_user_fxsr_struct) ); |
| 1318 | break; |
| 1319 | default: |
| 1320 | break; |
| 1321 | } |
| 1322 | } |
njn | ca0518d | 2004-11-26 19:34:36 +0000 | [diff] [blame] | 1323 | |
njn | b249fd7 | 2004-11-29 14:24:57 +0000 | [diff] [blame] | 1324 | static Addr deref_Addr ( ThreadId tid, Addr a, Char* s ) |
| 1325 | { |
| 1326 | Addr* a_p = (Addr*)a; |
| 1327 | PRE_MEM_READ( s, (Addr)a_p, sizeof(Addr) ); |
| 1328 | return *a_p; |
| 1329 | } |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1330 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1331 | PRE(sys_ipc) |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1332 | { |
| 1333 | PRINT("sys_ipc ( %d, %d, %d, %d, %p, %d )", ARG1,ARG2,ARG3,ARG4,ARG5,ARG6); |
| 1334 | // XXX: this is simplistic -- some args are not used in all circumstances. |
| 1335 | PRE_REG_READ6(int, "ipc", |
| 1336 | vki_uint, call, int, first, int, second, int, third, |
| 1337 | void *, ptr, long, fifth) |
| 1338 | |
| 1339 | switch (ARG1 /* call */) { |
| 1340 | case VKI_SEMOP: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1341 | ML_(generic_PRE_sys_semop)( tid, ARG2, ARG5, ARG3 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1342 | *flags |= SfMayBlock; |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1343 | break; |
| 1344 | case VKI_SEMGET: |
| 1345 | break; |
| 1346 | case VKI_SEMCTL: |
| 1347 | { |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1348 | UWord arg = deref_Addr( tid, ARG5, "semctl(arg)" ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1349 | ML_(generic_PRE_sys_semctl)( tid, ARG2, ARG3, ARG4, arg ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1350 | break; |
| 1351 | } |
| 1352 | case VKI_SEMTIMEDOP: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1353 | ML_(generic_PRE_sys_semtimedop)( tid, ARG2, ARG5, ARG3, ARG6 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1354 | *flags |= SfMayBlock; |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1355 | break; |
| 1356 | case VKI_MSGSND: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1357 | ML_(generic_PRE_sys_msgsnd)( tid, ARG2, ARG5, ARG3, ARG4 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1358 | if ((ARG4 & VKI_IPC_NOWAIT) == 0) |
| 1359 | *flags |= SfMayBlock; |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1360 | break; |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1361 | case VKI_MSGRCV: |
| 1362 | { |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1363 | Addr msgp; |
| 1364 | Word msgtyp; |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1365 | |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1366 | msgp = deref_Addr( tid, |
| 1367 | (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgp), |
| 1368 | "msgrcv(msgp)" ); |
| 1369 | msgtyp = deref_Addr( tid, |
| 1370 | (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgtyp), |
| 1371 | "msgrcv(msgp)" ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1372 | |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1373 | ML_(generic_PRE_sys_msgrcv)( tid, ARG2, msgp, ARG3, msgtyp, ARG4 ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1374 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1375 | if ((ARG4 & VKI_IPC_NOWAIT) == 0) |
| 1376 | *flags |= SfMayBlock; |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1377 | break; |
| 1378 | } |
| 1379 | case VKI_MSGGET: |
| 1380 | break; |
| 1381 | case VKI_MSGCTL: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1382 | ML_(generic_PRE_sys_msgctl)( tid, ARG2, ARG3, ARG5 ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1383 | break; |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1384 | case VKI_SHMAT: |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1385 | { |
| 1386 | UWord w; |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1387 | PRE_MEM_WRITE( "shmat(raddr)", ARG4, sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1388 | w = ML_(generic_PRE_sys_shmat)( tid, ARG2, ARG5, ARG3 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1389 | if (w == 0) |
| 1390 | SET_STATUS_Failure( VKI_EINVAL ); |
| 1391 | else |
| 1392 | ARG5 = w; |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1393 | break; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1394 | } |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1395 | case VKI_SHMDT: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1396 | if (!ML_(generic_PRE_sys_shmdt)(tid, ARG5)) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1397 | SET_STATUS_Failure( VKI_EINVAL ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1398 | break; |
| 1399 | case VKI_SHMGET: |
| 1400 | break; |
| 1401 | case VKI_SHMCTL: /* IPCOP_shmctl */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1402 | ML_(generic_PRE_sys_shmctl)( tid, ARG2, ARG3, ARG5 ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1403 | break; |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1404 | default: |
| 1405 | VG_(message)(Vg_DebugMsg, "FATAL: unhandled syscall(ipc) %d", ARG1 ); |
| 1406 | VG_(core_panic)("... bye!\n"); |
| 1407 | break; /*NOTREACHED*/ |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | POST(sys_ipc) |
| 1412 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1413 | vg_assert(SUCCESS); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1414 | switch (ARG1 /* call */) { |
| 1415 | case VKI_SEMOP: |
| 1416 | case VKI_SEMGET: |
| 1417 | break; |
| 1418 | case VKI_SEMCTL: |
| 1419 | { |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1420 | UWord arg = deref_Addr( tid, ARG5, "semctl(arg)" ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1421 | ML_(generic_PRE_sys_semctl)( tid, ARG2, ARG3, ARG4, arg ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1422 | break; |
| 1423 | } |
| 1424 | case VKI_SEMTIMEDOP: |
| 1425 | case VKI_MSGSND: |
| 1426 | break; |
| 1427 | case VKI_MSGRCV: |
| 1428 | { |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1429 | Addr msgp; |
| 1430 | Word msgtyp; |
| 1431 | |
| 1432 | msgp = deref_Addr( tid, |
| 1433 | (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgp), |
| 1434 | "msgrcv(msgp)" ); |
| 1435 | msgtyp = deref_Addr( tid, |
| 1436 | (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgtyp), |
| 1437 | "msgrcv(msgp)" ); |
| 1438 | |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1439 | ML_(generic_POST_sys_msgrcv)( tid, RES, ARG2, msgp, ARG3, msgtyp, ARG4 ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1440 | break; |
| 1441 | } |
| 1442 | case VKI_MSGGET: |
| 1443 | break; |
| 1444 | case VKI_MSGCTL: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1445 | ML_(generic_POST_sys_msgctl)( tid, RES, ARG2, ARG3, ARG5 ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1446 | break; |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1447 | case VKI_SHMAT: |
| 1448 | { |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1449 | Addr addr; |
| 1450 | |
| 1451 | /* force readability. before the syscall it is |
| 1452 | * indeed uninitialized, as can be seen in |
| 1453 | * glibc/sysdeps/unix/sysv/linux/shmat.c */ |
sewardj | b369c5e | 2005-03-24 17:52:02 +0000 | [diff] [blame] | 1454 | POST_MEM_WRITE( ARG4, sizeof( Addr ) ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1455 | |
| 1456 | addr = deref_Addr ( tid, ARG4, "shmat(addr)" ); |
| 1457 | if ( addr > 0 ) { |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1458 | ML_(generic_POST_sys_shmat)( tid, addr, ARG2, ARG5, ARG3 ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1459 | } |
| 1460 | break; |
| 1461 | } |
| 1462 | case VKI_SHMDT: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1463 | ML_(generic_POST_sys_shmdt)( tid, RES, ARG5 ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1464 | break; |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1465 | case VKI_SHMGET: |
| 1466 | break; |
| 1467 | case VKI_SHMCTL: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1468 | ML_(generic_POST_sys_shmctl)( tid, RES, ARG2, ARG3, ARG5 ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1469 | break; |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1470 | default: |
| 1471 | VG_(message)(Vg_DebugMsg, |
| 1472 | "FATAL: unhandled syscall(ipc) %d", |
| 1473 | ARG1 ); |
| 1474 | VG_(core_panic)("... bye!\n"); |
| 1475 | break; /*NOTREACHED*/ |
| 1476 | } |
| 1477 | } |
| 1478 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1479 | PRE(old_mmap) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1480 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1481 | /* struct mmap_arg_struct { |
| 1482 | unsigned long addr; |
| 1483 | unsigned long len; |
| 1484 | unsigned long prot; |
| 1485 | unsigned long flags; |
| 1486 | unsigned long fd; |
| 1487 | unsigned long offset; |
| 1488 | }; */ |
| 1489 | UWord a1, a2, a3, a4, a5, a6; |
| 1490 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 1491 | UWord* args = (UWord*)ARG1; |
| 1492 | PRE_REG_READ1(long, "old_mmap", struct mmap_arg_struct *, args); |
| 1493 | PRE_MEM_READ( "old_mmap(args)", (Addr)args, 6*sizeof(UWord) ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1494 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 1495 | a1 = args[0]; |
| 1496 | a2 = args[1]; |
| 1497 | a3 = args[2]; |
| 1498 | a4 = args[3]; |
| 1499 | a5 = args[4]; |
| 1500 | a6 = args[5]; |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1501 | |
| 1502 | PRINT("old_mmap ( %p, %llu, %d, %d, %d, %d )", |
| 1503 | a1, (ULong)a2, a3, a4, a5, a6 ); |
| 1504 | |
| 1505 | if (a2 == 0) { |
| 1506 | /* SuSV3 says: If len is zero, mmap() shall fail and no mapping |
| 1507 | shall be established. */ |
| 1508 | SET_STATUS_Failure( VKI_EINVAL ); |
| 1509 | return; |
| 1510 | } |
| 1511 | |
| 1512 | if (/*(a4 & VKI_MAP_FIXED) &&*/ (0 != (a1 & (VKI_PAGE_SIZE-1)))) { |
| 1513 | /* zap any misaligned addresses. */ |
| 1514 | SET_STATUS_Failure( VKI_EINVAL ); |
| 1515 | return; |
| 1516 | } |
| 1517 | |
| 1518 | if (a4 & VKI_MAP_FIXED) { |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1519 | if (!ML_(valid_client_addr)(a1, a2, tid, "old_mmap")) { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1520 | PRINT("old_mmap failing: %p-%p\n", a1, a1+a2); |
| 1521 | SET_STATUS_Failure( VKI_ENOMEM ); |
| 1522 | } |
| 1523 | } else { |
| 1524 | Addr a = VG_(find_map_space)(a1, a2, True); |
| 1525 | if (0) VG_(printf)("find_map_space(%p, %d) -> %p\n",a1,a2,a); |
| 1526 | if (a == 0 && a1 != 0) { |
| 1527 | a1 = VG_(find_map_space)(0, a2, True); |
| 1528 | } |
| 1529 | else |
| 1530 | a1 = a; |
| 1531 | if (a1 == 0) |
| 1532 | SET_STATUS_Failure( VKI_ENOMEM ); |
| 1533 | else |
| 1534 | a4 |= VKI_MAP_FIXED; |
| 1535 | } |
| 1536 | |
| 1537 | if (! FAILURE) { |
| 1538 | SysRes res = VG_(mmap_native)((void*)a1, a2, a3, a4, a5, a6); |
| 1539 | SET_STATUS_from_SysRes(res); |
| 1540 | if (!res.isError) { |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1541 | vg_assert(ML_(valid_client_addr)(res.val, a2, tid, "old_mmap")); |
| 1542 | ML_(mmap_segment)( (Addr)res.val, a2, a3, a4, a5, a6 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1543 | } |
| 1544 | } |
| 1545 | |
| 1546 | if (0) |
| 1547 | VG_(printf)("old_mmap( %p, fixed %d ) -> %s(%p)\n", |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 1548 | args[0], |
| 1549 | args[3]&VKI_MAP_FIXED, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1550 | FAILURE ? "Fail" : "Success", RES_unchecked); |
| 1551 | |
| 1552 | /* Stay sane */ |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 1553 | if (SUCCESS && (args[3] & VKI_MAP_FIXED)) |
| 1554 | vg_assert(RES == args[0]); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1555 | } |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1556 | |
| 1557 | // XXX: lstat64/fstat64/stat64 are generic, but not necessarily |
| 1558 | // applicable to every architecture -- I think only to 32-bit archs. |
| 1559 | // We're going to need something like linux/core_os32.h for such |
| 1560 | // things, eventually, I think. --njn |
| 1561 | PRE(sys_lstat64) |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1562 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1563 | PRINT("sys_lstat64 ( %p(%s), %p )",ARG1,ARG1,ARG2); |
| 1564 | PRE_REG_READ2(long, "lstat64", char *, file_name, struct stat64 *, buf); |
| 1565 | PRE_MEM_RASCIIZ( "lstat64(file_name)", ARG1 ); |
| 1566 | PRE_MEM_WRITE( "lstat64(buf)", ARG2, sizeof(struct vki_stat64) ); |
| 1567 | } |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1568 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1569 | POST(sys_lstat64) |
| 1570 | { |
| 1571 | vg_assert(SUCCESS); |
| 1572 | if (RES == 0) { |
| 1573 | POST_MEM_WRITE( ARG2, sizeof(struct vki_stat64) ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1574 | } |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1575 | } |
| 1576 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1577 | PRE(sys_stat64) |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1578 | { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1579 | PRINT("sys_stat64 ( %p, %p )",ARG1,ARG2); |
| 1580 | PRE_REG_READ2(long, "stat64", char *, file_name, struct stat64 *, buf); |
| 1581 | PRE_MEM_RASCIIZ( "stat64(file_name)", ARG1 ); |
| 1582 | PRE_MEM_WRITE( "stat64(buf)", ARG2, sizeof(struct vki_stat64) ); |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1585 | POST(sys_stat64) |
| 1586 | { |
| 1587 | POST_MEM_WRITE( ARG2, sizeof(struct vki_stat64) ); |
| 1588 | } |
| 1589 | |
| 1590 | PRE(sys_fstat64) |
| 1591 | { |
| 1592 | PRINT("sys_fstat64 ( %d, %p )",ARG1,ARG2); |
| 1593 | PRE_REG_READ2(long, "fstat64", unsigned long, fd, struct stat64 *, buf); |
| 1594 | PRE_MEM_WRITE( "fstat64(buf)", ARG2, sizeof(struct vki_stat64) ); |
| 1595 | } |
| 1596 | |
| 1597 | POST(sys_fstat64) |
| 1598 | { |
| 1599 | POST_MEM_WRITE( ARG2, sizeof(struct vki_stat64) ); |
| 1600 | } |
| 1601 | |
| 1602 | PRE(sys_socketcall) |
| 1603 | { |
| 1604 | # define ARG2_0 (((UWord*)ARG2)[0]) |
| 1605 | # define ARG2_1 (((UWord*)ARG2)[1]) |
| 1606 | # define ARG2_2 (((UWord*)ARG2)[2]) |
| 1607 | # define ARG2_3 (((UWord*)ARG2)[3]) |
| 1608 | # define ARG2_4 (((UWord*)ARG2)[4]) |
| 1609 | # define ARG2_5 (((UWord*)ARG2)[5]) |
| 1610 | |
| 1611 | *flags |= SfMayBlock; |
| 1612 | PRINT("sys_socketcall ( %d, %p )",ARG1,ARG2); |
| 1613 | PRE_REG_READ2(long, "socketcall", int, call, unsigned long *, args); |
| 1614 | |
| 1615 | switch (ARG1 /* request */) { |
| 1616 | |
| 1617 | case VKI_SYS_SOCKETPAIR: |
| 1618 | /* int socketpair(int d, int type, int protocol, int sv[2]); */ |
| 1619 | PRE_MEM_READ( "socketcall.socketpair(args)", ARG2, 4*sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1620 | ML_(generic_PRE_sys_socketpair)( tid, ARG2_0, ARG2_1, ARG2_2, ARG2_3 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1621 | break; |
| 1622 | |
| 1623 | case VKI_SYS_SOCKET: |
| 1624 | /* int socket(int domain, int type, int protocol); */ |
| 1625 | PRE_MEM_READ( "socketcall.socket(args)", ARG2, 3*sizeof(Addr) ); |
| 1626 | break; |
| 1627 | |
| 1628 | case VKI_SYS_BIND: |
| 1629 | /* int bind(int sockfd, struct sockaddr *my_addr, |
| 1630 | int addrlen); */ |
| 1631 | PRE_MEM_READ( "socketcall.bind(args)", ARG2, 3*sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1632 | ML_(generic_PRE_sys_bind)( tid, ARG2_0, ARG2_1, ARG2_2 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1633 | break; |
| 1634 | |
| 1635 | case VKI_SYS_LISTEN: |
| 1636 | /* int listen(int s, int backlog); */ |
| 1637 | PRE_MEM_READ( "socketcall.listen(args)", ARG2, 2*sizeof(Addr) ); |
| 1638 | break; |
| 1639 | |
| 1640 | case VKI_SYS_ACCEPT: { |
| 1641 | /* int accept(int s, struct sockaddr *addr, int *addrlen); */ |
| 1642 | PRE_MEM_READ( "socketcall.accept(args)", ARG2, 3*sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1643 | ML_(generic_PRE_sys_accept)( tid, ARG2_0, ARG2_1, ARG2_2 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1644 | break; |
| 1645 | } |
| 1646 | |
| 1647 | case VKI_SYS_SENDTO: |
| 1648 | /* int sendto(int s, const void *msg, int len, |
| 1649 | unsigned int flags, |
| 1650 | const struct sockaddr *to, int tolen); */ |
| 1651 | PRE_MEM_READ( "socketcall.sendto(args)", ARG2, 6*sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1652 | ML_(generic_PRE_sys_sendto)( tid, ARG2_0, ARG2_1, ARG2_2, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1653 | ARG2_3, ARG2_4, ARG2_5 ); |
| 1654 | break; |
| 1655 | |
| 1656 | case VKI_SYS_SEND: |
| 1657 | /* int send(int s, const void *msg, size_t len, int flags); */ |
| 1658 | PRE_MEM_READ( "socketcall.send(args)", ARG2, 4*sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1659 | ML_(generic_PRE_sys_send)( tid, ARG2_0, ARG2_1, ARG2_2 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1660 | break; |
| 1661 | |
| 1662 | case VKI_SYS_RECVFROM: |
| 1663 | /* int recvfrom(int s, void *buf, int len, unsigned int flags, |
| 1664 | struct sockaddr *from, int *fromlen); */ |
| 1665 | PRE_MEM_READ( "socketcall.recvfrom(args)", ARG2, 6*sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1666 | ML_(generic_PRE_sys_recvfrom)( tid, ARG2_0, ARG2_1, ARG2_2, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1667 | ARG2_3, ARG2_4, ARG2_5 ); |
| 1668 | break; |
| 1669 | |
| 1670 | case VKI_SYS_RECV: |
| 1671 | /* int recv(int s, void *buf, int len, unsigned int flags); */ |
| 1672 | /* man 2 recv says: |
| 1673 | The recv call is normally used only on a connected socket |
| 1674 | (see connect(2)) and is identical to recvfrom with a NULL |
| 1675 | from parameter. |
| 1676 | */ |
| 1677 | PRE_MEM_READ( "socketcall.recv(args)", ARG2, 4*sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1678 | ML_(generic_PRE_sys_recv)( tid, ARG2_0, ARG2_1, ARG2_2 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1679 | break; |
| 1680 | |
| 1681 | case VKI_SYS_CONNECT: |
| 1682 | /* int connect(int sockfd, |
| 1683 | struct sockaddr *serv_addr, int addrlen ); */ |
| 1684 | PRE_MEM_READ( "socketcall.connect(args)", ARG2, 3*sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1685 | ML_(generic_PRE_sys_connect)( tid, ARG2_0, ARG2_1, ARG2_2 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1686 | break; |
| 1687 | |
| 1688 | case VKI_SYS_SETSOCKOPT: |
| 1689 | /* int setsockopt(int s, int level, int optname, |
| 1690 | const void *optval, int optlen); */ |
| 1691 | PRE_MEM_READ( "socketcall.setsockopt(args)", ARG2, 5*sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1692 | ML_(generic_PRE_sys_setsockopt)( tid, ARG2_0, ARG2_1, ARG2_2, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1693 | ARG2_3, ARG2_4 ); |
| 1694 | break; |
| 1695 | |
| 1696 | case VKI_SYS_GETSOCKOPT: |
| 1697 | /* int getsockopt(int s, int level, int optname, |
| 1698 | void *optval, socklen_t *optlen); */ |
| 1699 | PRE_MEM_READ( "socketcall.getsockopt(args)", ARG2, 5*sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1700 | ML_(generic_PRE_sys_getsockopt)( tid, ARG2_0, ARG2_1, ARG2_2, |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1701 | ARG2_3, ARG2_4 ); |
| 1702 | break; |
| 1703 | |
| 1704 | case VKI_SYS_GETSOCKNAME: |
| 1705 | /* int getsockname(int s, struct sockaddr* name, int* namelen) */ |
| 1706 | PRE_MEM_READ( "socketcall.getsockname(args)", ARG2, 3*sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1707 | ML_(generic_PRE_sys_getsockname)( tid, ARG2_0, ARG2_1, ARG2_2 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1708 | break; |
| 1709 | |
| 1710 | case VKI_SYS_GETPEERNAME: |
| 1711 | /* int getpeername(int s, struct sockaddr* name, int* namelen) */ |
| 1712 | PRE_MEM_READ( "socketcall.getpeername(args)", ARG2, 3*sizeof(Addr) ); |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1713 | ML_(generic_PRE_sys_getpeername)( tid, ARG2_0, ARG2_1, ARG2_2 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1714 | break; |
| 1715 | |
| 1716 | case VKI_SYS_SHUTDOWN: |
| 1717 | /* int shutdown(int s, int how); */ |
| 1718 | PRE_MEM_READ( "socketcall.shutdown(args)", ARG2, 2*sizeof(Addr) ); |
| 1719 | break; |
| 1720 | |
| 1721 | case VKI_SYS_SENDMSG: { |
| 1722 | /* int sendmsg(int s, const struct msghdr *msg, int flags); */ |
| 1723 | |
| 1724 | /* this causes warnings, and I don't get why. glibc bug? |
| 1725 | * (after all it's glibc providing the arguments array) |
| 1726 | PRE_MEM_READ( "socketcall.sendmsg(args)", ARG2, 3*sizeof(Addr) ); |
| 1727 | */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1728 | ML_(generic_PRE_sys_sendmsg)( tid, ARG2_0, ARG2_1 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1729 | break; |
| 1730 | } |
| 1731 | |
| 1732 | case VKI_SYS_RECVMSG: { |
| 1733 | /* int recvmsg(int s, struct msghdr *msg, int flags); */ |
| 1734 | |
| 1735 | /* this causes warnings, and I don't get why. glibc bug? |
| 1736 | * (after all it's glibc providing the arguments array) |
| 1737 | PRE_MEM_READ("socketcall.recvmsg(args)", ARG2, 3*sizeof(Addr) ); |
| 1738 | */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1739 | ML_(generic_PRE_sys_recvmsg)( tid, ARG2_0, ARG2_1 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1740 | break; |
| 1741 | } |
| 1742 | |
| 1743 | default: |
| 1744 | VG_(message)(Vg_DebugMsg,"Warning: unhandled socketcall 0x%x",ARG1); |
| 1745 | SET_STATUS_Failure( VKI_EINVAL ); |
| 1746 | break; |
| 1747 | } |
| 1748 | # undef ARG2_0 |
| 1749 | # undef ARG2_1 |
| 1750 | # undef ARG2_2 |
| 1751 | # undef ARG2_3 |
| 1752 | # undef ARG2_4 |
| 1753 | # undef ARG2_5 |
| 1754 | } |
| 1755 | |
| 1756 | POST(sys_socketcall) |
| 1757 | { |
| 1758 | # define ARG2_0 (((UWord*)ARG2)[0]) |
| 1759 | # define ARG2_1 (((UWord*)ARG2)[1]) |
| 1760 | # define ARG2_2 (((UWord*)ARG2)[2]) |
| 1761 | # define ARG2_3 (((UWord*)ARG2)[3]) |
| 1762 | # define ARG2_4 (((UWord*)ARG2)[4]) |
| 1763 | # define ARG2_5 (((UWord*)ARG2)[5]) |
| 1764 | |
| 1765 | SysRes r; |
| 1766 | vg_assert(SUCCESS); |
| 1767 | switch (ARG1 /* request */) { |
| 1768 | |
| 1769 | case VKI_SYS_SOCKETPAIR: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1770 | r = ML_(generic_POST_sys_socketpair)( |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1771 | tid, VG_(mk_SysRes_Success)(RES), |
| 1772 | ARG2_0, ARG2_1, ARG2_2, ARG2_3 |
| 1773 | ); |
| 1774 | SET_STATUS_from_SysRes(r); |
| 1775 | break; |
| 1776 | |
| 1777 | case VKI_SYS_SOCKET: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1778 | r = ML_(generic_POST_sys_socket)( tid, VG_(mk_SysRes_Success)(RES) ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1779 | SET_STATUS_from_SysRes(r); |
| 1780 | break; |
| 1781 | |
| 1782 | case VKI_SYS_BIND: |
| 1783 | /* int bind(int sockfd, struct sockaddr *my_addr, |
| 1784 | int addrlen); */ |
| 1785 | break; |
| 1786 | |
| 1787 | case VKI_SYS_LISTEN: |
| 1788 | /* int listen(int s, int backlog); */ |
| 1789 | break; |
| 1790 | |
| 1791 | case VKI_SYS_ACCEPT: |
| 1792 | /* int accept(int s, struct sockaddr *addr, int *addrlen); */ |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1793 | r = ML_(generic_POST_sys_accept)( tid, VG_(mk_SysRes_Success)(RES), |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1794 | ARG2_0, ARG2_1, ARG2_2 ); |
| 1795 | SET_STATUS_from_SysRes(r); |
| 1796 | break; |
| 1797 | |
| 1798 | case VKI_SYS_SENDTO: |
| 1799 | break; |
| 1800 | |
| 1801 | case VKI_SYS_SEND: |
| 1802 | break; |
| 1803 | |
| 1804 | case VKI_SYS_RECVFROM: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1805 | ML_(generic_POST_sys_recvfrom)( tid, VG_(mk_SysRes_Success)(RES), |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1806 | ARG2_0, ARG2_1, ARG2_2, |
| 1807 | ARG2_3, ARG2_4, ARG2_5 ); |
| 1808 | break; |
| 1809 | |
| 1810 | case VKI_SYS_RECV: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1811 | ML_(generic_POST_sys_recv)( tid, RES, ARG2_0, ARG2_1, ARG2_2 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1812 | break; |
| 1813 | |
| 1814 | case VKI_SYS_CONNECT: |
| 1815 | break; |
| 1816 | |
| 1817 | case VKI_SYS_SETSOCKOPT: |
| 1818 | break; |
| 1819 | |
| 1820 | case VKI_SYS_GETSOCKOPT: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1821 | ML_(generic_POST_sys_getsockopt)( tid, VG_(mk_SysRes_Success)(RES), |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1822 | ARG2_0, ARG2_1, |
| 1823 | ARG2_2, ARG2_3, ARG2_4 ); |
| 1824 | break; |
| 1825 | |
| 1826 | case VKI_SYS_GETSOCKNAME: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1827 | ML_(generic_POST_sys_getsockname)( tid, VG_(mk_SysRes_Success)(RES), |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1828 | ARG2_0, ARG2_1, ARG2_2 ); |
| 1829 | break; |
| 1830 | |
| 1831 | case VKI_SYS_GETPEERNAME: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1832 | ML_(generic_POST_sys_getpeername)( tid, VG_(mk_SysRes_Success)(RES), |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1833 | ARG2_0, ARG2_1, ARG2_2 ); |
| 1834 | break; |
| 1835 | |
| 1836 | case VKI_SYS_SHUTDOWN: |
| 1837 | break; |
| 1838 | |
| 1839 | case VKI_SYS_SENDMSG: |
| 1840 | break; |
| 1841 | |
| 1842 | case VKI_SYS_RECVMSG: |
sewardj | 7eb7c58 | 2005-06-23 01:02:53 +0000 | [diff] [blame] | 1843 | ML_(generic_POST_sys_recvmsg)( tid, ARG2_0, ARG2_1 ); |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1844 | break; |
| 1845 | |
| 1846 | default: |
| 1847 | VG_(message)(Vg_DebugMsg,"FATAL: unhandled socketcall 0x%x",ARG1); |
| 1848 | VG_(core_panic)("... bye!\n"); |
| 1849 | break; /*NOTREACHED*/ |
| 1850 | } |
| 1851 | # undef ARG2_0 |
| 1852 | # undef ARG2_1 |
| 1853 | # undef ARG2_2 |
| 1854 | # undef ARG2_3 |
| 1855 | # undef ARG2_4 |
| 1856 | # undef ARG2_5 |
| 1857 | } |
| 1858 | |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 1859 | /* Convert from non-RT to RT sigset_t's */ |
| 1860 | static |
| 1861 | void convert_sigset_to_rt(const vki_old_sigset_t *oldset, vki_sigset_t *set) |
| 1862 | { |
| 1863 | VG_(sigemptyset)(set); |
| 1864 | set->sig[0] = *oldset; |
| 1865 | } |
| 1866 | PRE(sys_sigaction) |
| 1867 | { |
| 1868 | struct vki_sigaction new, old; |
| 1869 | struct vki_sigaction *newp, *oldp; |
| 1870 | |
| 1871 | PRINT("sys_sigaction ( %d, %p, %p )", ARG1,ARG2,ARG3); |
| 1872 | PRE_REG_READ3(int, "sigaction", |
| 1873 | int, signum, const struct old_sigaction *, act, |
| 1874 | struct old_sigaction *, oldact); |
| 1875 | |
| 1876 | newp = oldp = NULL; |
| 1877 | |
| 1878 | if (ARG2 != 0) |
| 1879 | PRE_MEM_READ( "sigaction(act)", ARG2, sizeof(struct vki_old_sigaction)); |
| 1880 | |
| 1881 | if (ARG3 != 0) { |
| 1882 | PRE_MEM_WRITE( "sigaction(oldact)", ARG3, sizeof(struct vki_old_sigaction)); |
| 1883 | oldp = &old; |
| 1884 | } |
| 1885 | |
| 1886 | //jrs 20050207: what?! how can this make any sense? |
| 1887 | //if (VG_(is_kerror)(SYSRES)) |
| 1888 | // return; |
| 1889 | |
| 1890 | if (ARG2 != 0) { |
| 1891 | struct vki_old_sigaction *oldnew = (struct vki_old_sigaction *)ARG2; |
| 1892 | |
| 1893 | new.ksa_handler = oldnew->ksa_handler; |
| 1894 | new.sa_flags = oldnew->sa_flags; |
| 1895 | new.sa_restorer = oldnew->sa_restorer; |
| 1896 | convert_sigset_to_rt(&oldnew->sa_mask, &new.sa_mask); |
| 1897 | newp = &new; |
| 1898 | } |
| 1899 | |
| 1900 | SET_STATUS_from_SysRes( VG_(do_sys_sigaction)(ARG1, newp, oldp) ); |
| 1901 | |
| 1902 | if (ARG3 != 0 && SUCCESS && RES == 0) { |
| 1903 | struct vki_old_sigaction *oldold = (struct vki_old_sigaction *)ARG3; |
| 1904 | |
| 1905 | oldold->ksa_handler = oldp->ksa_handler; |
| 1906 | oldold->sa_flags = oldp->sa_flags; |
| 1907 | oldold->sa_restorer = oldp->sa_restorer; |
| 1908 | oldold->sa_mask = oldp->sa_mask.sig[0]; |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | POST(sys_sigaction) |
| 1913 | { |
| 1914 | vg_assert(SUCCESS); |
| 1915 | if (RES == 0 && ARG3 != 0) |
| 1916 | POST_MEM_WRITE( ARG3, sizeof(struct vki_old_sigaction)); |
| 1917 | } |
| 1918 | |
| 1919 | #undef PRE |
| 1920 | #undef POST |
| 1921 | |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1922 | |
| 1923 | /* --------------------------------------------------------------------- |
| 1924 | The x86/Linux syscall table |
| 1925 | ------------------------------------------------------------------ */ |
| 1926 | |
sewardj | e7aa4ae | 2005-06-09 12:43:42 +0000 | [diff] [blame] | 1927 | /* Add an x86-linux specific wrapper to a syscall table. */ |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1928 | #define PLAX_(sysno, name) WRAPPER_ENTRY_X_(x86_linux, sysno, name) |
| 1929 | #define PLAXY(sysno, name) WRAPPER_ENTRY_XY(x86_linux, sysno, name) |
| 1930 | |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1931 | |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1932 | // This table maps from __NR_xxx syscall numbers (from |
| 1933 | // linux/include/asm-i386/unistd.h) to the appropriate PRE/POST sys_foo() |
| 1934 | // wrappers on x86 (as per sys_call_table in linux/arch/i386/kernel/entry.S). |
| 1935 | // |
| 1936 | // For those syscalls not handled by Valgrind, the annotation indicate its |
| 1937 | // arch/OS combination, eg. */* (generic), */Linux (Linux only), ?/? |
| 1938 | // (unknown). |
| 1939 | |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 1940 | const SyscallTableEntry ML_(syscall_table)[] = { |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1941 | //zz // (restart_syscall) // 0 |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1942 | GENX_(__NR_exit, sys_exit), // 1 |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1943 | GENX_(__NR_fork, sys_fork), // 2 |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1944 | GENXY(__NR_read, sys_read), // 3 |
| 1945 | GENX_(__NR_write, sys_write), // 4 |
| 1946 | |
| 1947 | GENXY(__NR_open, sys_open), // 5 |
| 1948 | GENXY(__NR_close, sys_close), // 6 |
| 1949 | GENXY(__NR_waitpid, sys_waitpid), // 7 |
| 1950 | GENXY(__NR_creat, sys_creat), // 8 |
| 1951 | GENX_(__NR_link, sys_link), // 9 |
| 1952 | |
| 1953 | GENX_(__NR_unlink, sys_unlink), // 10 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1954 | GENX_(__NR_execve, sys_execve), // 11 |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1955 | GENX_(__NR_chdir, sys_chdir), // 12 |
| 1956 | GENXY(__NR_time, sys_time), // 13 |
| 1957 | GENX_(__NR_mknod, sys_mknod), // 14 |
| 1958 | |
| 1959 | GENX_(__NR_chmod, sys_chmod), // 15 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1960 | //zz // (__NR_lchown, sys_lchown16), // 16 ## P |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1961 | GENX_(__NR_break, sys_ni_syscall), // 17 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1962 | //zz // (__NR_oldstat, sys_stat), // 18 (obsolete) |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1963 | GENX_(__NR_lseek, sys_lseek), // 19 |
| 1964 | |
| 1965 | GENX_(__NR_getpid, sys_getpid), // 20 |
| 1966 | LINX_(__NR_mount, sys_mount), // 21 |
| 1967 | LINX_(__NR_umount, sys_oldumount), // 22 |
| 1968 | GENX_(__NR_setuid, sys_setuid16), // 23 ## P |
| 1969 | GENX_(__NR_getuid, sys_getuid16), // 24 ## P |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1970 | //zz |
| 1971 | //zz // (__NR_stime, sys_stime), // 25 * (SVr4,SVID,X/OPEN) |
sewardj | 8c25732 | 2005-06-08 01:01:48 +0000 | [diff] [blame] | 1972 | PLAXY(__NR_ptrace, sys_ptrace), // 26 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1973 | GENX_(__NR_alarm, sys_alarm), // 27 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1974 | //zz // (__NR_oldfstat, sys_fstat), // 28 * L -- obsolete |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1975 | GENX_(__NR_pause, sys_pause), // 29 |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 1976 | |
| 1977 | GENX_(__NR_utime, sys_utime), // 30 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1978 | GENX_(__NR_stty, sys_ni_syscall), // 31 |
| 1979 | GENX_(__NR_gtty, sys_ni_syscall), // 32 |
| 1980 | GENX_(__NR_access, sys_access), // 33 |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 1981 | GENX_(__NR_nice, sys_nice), // 34 |
| 1982 | |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1983 | GENX_(__NR_ftime, sys_ni_syscall), // 35 |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 1984 | GENX_(__NR_sync, sys_sync), // 36 |
njn | 03f1e58 | 2005-03-26 20:08:06 +0000 | [diff] [blame] | 1985 | GENX_(__NR_kill, sys_kill), // 37 |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1986 | GENX_(__NR_rename, sys_rename), // 38 |
| 1987 | GENX_(__NR_mkdir, sys_mkdir), // 39 |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 1988 | |
| 1989 | GENX_(__NR_rmdir, sys_rmdir), // 40 |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 1990 | GENXY(__NR_dup, sys_dup), // 41 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1991 | GENXY(__NR_pipe, sys_pipe), // 42 |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 1992 | GENXY(__NR_times, sys_times), // 43 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1993 | GENX_(__NR_prof, sys_ni_syscall), // 44 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1994 | //zz |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1995 | GENX_(__NR_brk, sys_brk), // 45 |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 1996 | GENX_(__NR_setgid, sys_setgid16), // 46 |
| 1997 | GENX_(__NR_getgid, sys_getgid16), // 47 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 1998 | //zz // (__NR_signal, sys_signal), // 48 */* (ANSI C) |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 1999 | GENX_(__NR_geteuid, sys_geteuid16), // 49 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2000 | |
| 2001 | GENX_(__NR_getegid, sys_getegid16), // 50 |
| 2002 | GENX_(__NR_acct, sys_acct), // 51 |
| 2003 | LINX_(__NR_umount2, sys_umount), // 52 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2004 | GENX_(__NR_lock, sys_ni_syscall), // 53 |
| 2005 | GENXY(__NR_ioctl, sys_ioctl), // 54 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2006 | |
| 2007 | GENXY(__NR_fcntl, sys_fcntl), // 55 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2008 | GENX_(__NR_mpx, sys_ni_syscall), // 56 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2009 | GENX_(__NR_setpgid, sys_setpgid), // 57 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2010 | GENX_(__NR_ulimit, sys_ni_syscall), // 58 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2011 | //zz // (__NR_oldolduname, sys_olduname), // 59 Linux -- obsolete |
| 2012 | //zz |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2013 | GENX_(__NR_umask, sys_umask), // 60 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2014 | GENX_(__NR_chroot, sys_chroot), // 61 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2015 | //zz // (__NR_ustat, sys_ustat) // 62 SVr4 -- deprecated |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2016 | GENXY(__NR_dup2, sys_dup2), // 63 |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 2017 | GENX_(__NR_getppid, sys_getppid), // 64 |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2018 | |
| 2019 | GENX_(__NR_getpgrp, sys_getpgrp), // 65 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2020 | GENX_(__NR_setsid, sys_setsid), // 66 |
| 2021 | PLAXY(__NR_sigaction, sys_sigaction), // 67 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2022 | //zz // (__NR_sgetmask, sys_sgetmask), // 68 */* (ANSI C) |
| 2023 | //zz // (__NR_ssetmask, sys_ssetmask), // 69 */* (ANSI C) |
| 2024 | //zz |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2025 | GENX_(__NR_setreuid, sys_setreuid16), // 70 |
| 2026 | GENX_(__NR_setregid, sys_setregid16), // 71 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2027 | //zz GENX_(__NR_sigsuspend, sys_sigsuspend), // 72 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2028 | GENXY(__NR_sigpending, sys_sigpending), // 73 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2029 | //zz // (__NR_sethostname, sys_sethostname), // 74 */* |
| 2030 | //zz |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2031 | GENX_(__NR_setrlimit, sys_setrlimit), // 75 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2032 | GENXY(__NR_getrlimit, sys_old_getrlimit), // 76 |
| 2033 | GENXY(__NR_getrusage, sys_getrusage), // 77 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2034 | GENXY(__NR_gettimeofday, sys_gettimeofday), // 78 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2035 | GENX_(__NR_settimeofday, sys_settimeofday), // 79 |
| 2036 | |
| 2037 | GENXY(__NR_getgroups, sys_getgroups16), // 80 |
| 2038 | GENX_(__NR_setgroups, sys_setgroups16), // 81 |
| 2039 | PLAX_(__NR_select, old_select), // 82 |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2040 | GENX_(__NR_symlink, sys_symlink), // 83 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2041 | //zz // (__NR_oldlstat, sys_lstat), // 84 -- obsolete |
| 2042 | //zz |
rjwalsh | 17d8530 | 2004-11-18 22:56:09 +0000 | [diff] [blame] | 2043 | GENX_(__NR_readlink, sys_readlink), // 85 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2044 | //zz // (__NR_uselib, sys_uselib), // 86 */Linux |
| 2045 | //zz // (__NR_swapon, sys_swapon), // 87 */Linux |
| 2046 | //zz // (__NR_reboot, sys_reboot), // 88 */Linux |
| 2047 | //zz // (__NR_readdir, old_readdir), // 89 -- superseded |
| 2048 | //zz |
| 2049 | PLAX_(__NR_mmap, old_mmap), // 90 |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2050 | GENXY(__NR_munmap, sys_munmap), // 91 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2051 | GENX_(__NR_truncate, sys_truncate), // 92 |
sewardj | 8c25732 | 2005-06-08 01:01:48 +0000 | [diff] [blame] | 2052 | GENX_(__NR_ftruncate, sys_ftruncate), // 93 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2053 | GENX_(__NR_fchmod, sys_fchmod), // 94 |
| 2054 | |
| 2055 | GENX_(__NR_fchown, sys_fchown16), // 95 |
| 2056 | GENX_(__NR_getpriority, sys_getpriority), // 96 |
| 2057 | GENX_(__NR_setpriority, sys_setpriority), // 97 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2058 | GENX_(__NR_profil, sys_ni_syscall), // 98 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2059 | GENXY(__NR_statfs, sys_statfs), // 99 |
| 2060 | |
| 2061 | GENXY(__NR_fstatfs, sys_fstatfs), // 100 |
| 2062 | LINX_(__NR_ioperm, sys_ioperm), // 101 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2063 | PLAXY(__NR_socketcall, sys_socketcall), // 102 x86/Linux-only |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2064 | LINXY(__NR_syslog, sys_syslog), // 103 |
| 2065 | GENXY(__NR_setitimer, sys_setitimer), // 104 |
| 2066 | |
| 2067 | GENXY(__NR_getitimer, sys_getitimer), // 105 |
| 2068 | GENXY(__NR_stat, sys_newstat), // 106 |
| 2069 | GENXY(__NR_lstat, sys_newlstat), // 107 |
| 2070 | GENXY(__NR_fstat, sys_newfstat), // 108 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2071 | //zz // (__NR_olduname, sys_uname), // 109 -- obsolete |
| 2072 | //zz |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2073 | GENX_(__NR_iopl, sys_iopl), // 110 |
| 2074 | LINX_(__NR_vhangup, sys_vhangup), // 111 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2075 | GENX_(__NR_idle, sys_ni_syscall), // 112 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2076 | //zz // (__NR_vm86old, sys_vm86old), // 113 x86/Linux-only |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2077 | GENXY(__NR_wait4, sys_wait4), // 114 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2078 | //zz |
| 2079 | //zz // (__NR_swapoff, sys_swapoff), // 115 */Linux |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2080 | LINXY(__NR_sysinfo, sys_sysinfo), // 116 |
njn | c616819 | 2004-11-29 13:54:10 +0000 | [diff] [blame] | 2081 | PLAXY(__NR_ipc, sys_ipc), // 117 |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2082 | GENX_(__NR_fsync, sys_fsync), // 118 |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2083 | PLAX_(__NR_sigreturn, sys_sigreturn), // 119 ?/Linux |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2084 | |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2085 | PLAX_(__NR_clone, sys_clone), // 120 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2086 | //zz // (__NR_setdomainname, sys_setdomainname), // 121 */*(?) |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2087 | GENXY(__NR_uname, sys_newuname), // 122 |
| 2088 | PLAX_(__NR_modify_ldt, sys_modify_ldt), // 123 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2089 | //zz LINXY(__NR_adjtimex, sys_adjtimex), // 124 |
| 2090 | //zz |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2091 | GENXY(__NR_mprotect, sys_mprotect), // 125 |
| 2092 | GENXY(__NR_sigprocmask, sys_sigprocmask), // 126 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2093 | //zz // Nb: create_module() was removed 2.4-->2.6 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2094 | GENX_(__NR_create_module, sys_ni_syscall), // 127 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2095 | GENX_(__NR_init_module, sys_init_module), // 128 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2096 | //zz // (__NR_delete_module, sys_delete_module), // 129 (*/Linux)? |
| 2097 | //zz |
| 2098 | //zz // Nb: get_kernel_syms() was removed 2.4-->2.6 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2099 | GENX_(__NR_get_kernel_syms, sys_ni_syscall), // 130 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2100 | GENX_(__NR_quotactl, sys_quotactl), // 131 |
| 2101 | GENX_(__NR_getpgid, sys_getpgid), // 132 |
| 2102 | GENX_(__NR_fchdir, sys_fchdir), // 133 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2103 | //zz // (__NR_bdflush, sys_bdflush), // 134 */Linux |
| 2104 | //zz |
| 2105 | //zz // (__NR_sysfs, sys_sysfs), // 135 SVr4 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2106 | LINX_(__NR_personality, sys_personality), // 136 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2107 | GENX_(__NR_afs_syscall, sys_ni_syscall), // 137 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2108 | LINX_(__NR_setfsuid, sys_setfsuid16), // 138 |
| 2109 | LINX_(__NR_setfsgid, sys_setfsgid16), // 139 |
| 2110 | |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2111 | LINXY(__NR__llseek, sys_llseek), // 140 |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2112 | GENXY(__NR_getdents, sys_getdents), // 141 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2113 | GENX_(__NR__newselect, sys_select), // 142 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2114 | GENX_(__NR_flock, sys_flock), // 143 |
| 2115 | GENX_(__NR_msync, sys_msync), // 144 |
| 2116 | |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2117 | GENXY(__NR_readv, sys_readv), // 145 |
| 2118 | GENX_(__NR_writev, sys_writev), // 146 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2119 | GENX_(__NR_getsid, sys_getsid), // 147 |
| 2120 | GENX_(__NR_fdatasync, sys_fdatasync), // 148 |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2121 | LINXY(__NR__sysctl, sys_sysctl), // 149 |
sewardj | 696c551 | 2005-06-08 23:38:32 +0000 | [diff] [blame] | 2122 | |
| 2123 | GENX_(__NR_mlock, sys_mlock), // 150 |
| 2124 | GENX_(__NR_munlock, sys_munlock), // 151 |
| 2125 | GENX_(__NR_mlockall, sys_mlockall), // 152 |
| 2126 | GENX_(__NR_munlockall, sys_munlockall), // 153 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2127 | GENXY(__NR_sched_setparam, sys_sched_setparam), // 154 |
| 2128 | |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2129 | GENXY(__NR_sched_getparam, sys_sched_getparam), // 155 |
| 2130 | GENX_(__NR_sched_setscheduler, sys_sched_setscheduler), // 156 |
| 2131 | GENX_(__NR_sched_getscheduler, sys_sched_getscheduler), // 157 |
| 2132 | GENX_(__NR_sched_yield, sys_sched_yield), // 158 |
| 2133 | GENX_(__NR_sched_get_priority_max, sys_sched_get_priority_max),// 159 |
| 2134 | |
| 2135 | GENX_(__NR_sched_get_priority_min, sys_sched_get_priority_min),// 160 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2136 | //zz // (__NR_sched_rr_get_interval, sys_sched_rr_get_interval), // 161 */* |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2137 | GENXY(__NR_nanosleep, sys_nanosleep), // 162 |
| 2138 | GENX_(__NR_mremap, sys_mremap), // 163 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2139 | LINX_(__NR_setresuid, sys_setresuid16), // 164 |
| 2140 | |
| 2141 | LINXY(__NR_getresuid, sys_getresuid16), // 165 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2142 | //zz // (__NR_vm86, sys_vm86), // 166 x86/Linux-only |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2143 | GENX_(__NR_query_module, sys_ni_syscall), // 167 |
| 2144 | GENXY(__NR_poll, sys_poll), // 168 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2145 | //zz // (__NR_nfsservctl, sys_nfsservctl), // 169 */Linux |
| 2146 | //zz |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2147 | LINX_(__NR_setresgid, sys_setresgid16), // 170 |
| 2148 | LINXY(__NR_getresgid, sys_getresgid16), // 171 |
| 2149 | LINX_(__NR_prctl, sys_prctl), // 172 |
sewardj | d571aff | 2005-03-15 14:47:30 +0000 | [diff] [blame] | 2150 | PLAX_(__NR_rt_sigreturn, sys_rt_sigreturn), // 173 x86/Linux only? |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2151 | GENXY(__NR_rt_sigaction, sys_rt_sigaction), // 174 |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2152 | |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2153 | GENXY(__NR_rt_sigprocmask, sys_rt_sigprocmask), // 175 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2154 | GENXY(__NR_rt_sigpending, sys_rt_sigpending), // 176 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2155 | GENXY(__NR_rt_sigtimedwait, sys_rt_sigtimedwait),// 177 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2156 | GENXY(__NR_rt_sigqueueinfo, sys_rt_sigqueueinfo),// 178 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2157 | GENX_(__NR_rt_sigsuspend, sys_rt_sigsuspend), // 179 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2158 | |
| 2159 | GENXY(__NR_pread64, sys_pread64), // 180 |
| 2160 | GENX_(__NR_pwrite64, sys_pwrite64), // 181 |
| 2161 | GENX_(__NR_chown, sys_chown16), // 182 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2162 | GENXY(__NR_getcwd, sys_getcwd), // 183 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2163 | GENXY(__NR_capget, sys_capget), // 184 |
| 2164 | |
| 2165 | GENX_(__NR_capset, sys_capset), // 185 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2166 | GENXY(__NR_sigaltstack, sys_sigaltstack), // 186 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2167 | LINXY(__NR_sendfile, sys_sendfile), // 187 |
| 2168 | GENXY(__NR_getpmsg, sys_getpmsg), // 188 |
| 2169 | GENX_(__NR_putpmsg, sys_putpmsg), // 189 |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2170 | |
sewardj | c93d7b6 | 2005-03-12 20:45:56 +0000 | [diff] [blame] | 2171 | // Nb: we treat vfork as fork |
| 2172 | GENX_(__NR_vfork, sys_fork), // 190 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2173 | GENXY(__NR_ugetrlimit, sys_getrlimit), // 191 |
| 2174 | GENXY(__NR_mmap2, sys_mmap2), // 192 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2175 | GENX_(__NR_truncate64, sys_truncate64), // 193 |
| 2176 | GENX_(__NR_ftruncate64, sys_ftruncate64), // 194 |
| 2177 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2178 | PLAXY(__NR_stat64, sys_stat64), // 195 |
| 2179 | PLAXY(__NR_lstat64, sys_lstat64), // 196 |
| 2180 | PLAXY(__NR_fstat64, sys_fstat64), // 197 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2181 | GENX_(__NR_lchown32, sys_lchown), // 198 |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2182 | GENX_(__NR_getuid32, sys_getuid), // 199 |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2183 | |
| 2184 | GENX_(__NR_getgid32, sys_getgid), // 200 |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2185 | GENX_(__NR_geteuid32, sys_geteuid), // 201 |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2186 | GENX_(__NR_getegid32, sys_getegid), // 202 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2187 | GENX_(__NR_setreuid32, sys_setreuid), // 203 |
| 2188 | GENX_(__NR_setregid32, sys_setregid), // 204 |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2189 | |
| 2190 | GENXY(__NR_getgroups32, sys_getgroups), // 205 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2191 | GENX_(__NR_setgroups32, sys_setgroups), // 206 |
| 2192 | GENX_(__NR_fchown32, sys_fchown), // 207 |
| 2193 | LINX_(__NR_setresuid32, sys_setresuid), // 208 |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2194 | LINXY(__NR_getresuid32, sys_getresuid), // 209 |
| 2195 | |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2196 | LINX_(__NR_setresgid32, sys_setresgid), // 210 |
sewardj | 78b50e4 | 2005-06-08 01:47:28 +0000 | [diff] [blame] | 2197 | LINXY(__NR_getresgid32, sys_getresgid), // 211 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2198 | GENX_(__NR_chown32, sys_chown), // 212 |
| 2199 | GENX_(__NR_setuid32, sys_setuid), // 213 |
| 2200 | GENX_(__NR_setgid32, sys_setgid), // 214 |
| 2201 | |
| 2202 | LINX_(__NR_setfsuid32, sys_setfsuid), // 215 |
| 2203 | LINX_(__NR_setfsgid32, sys_setfsgid), // 216 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2204 | //zz // (__NR_pivot_root, sys_pivot_root), // 217 */Linux |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2205 | GENXY(__NR_mincore, sys_mincore), // 218 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2206 | GENX_(__NR_madvise, sys_madvise), // 219 |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2207 | |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2208 | GENXY(__NR_getdents64, sys_getdents64), // 220 |
| 2209 | GENXY(__NR_fcntl64, sys_fcntl64), // 221 |
| 2210 | GENX_(222, sys_ni_syscall), // 222 |
| 2211 | GENX_(223, sys_ni_syscall), // 223 |
sewardj | 8c25732 | 2005-06-08 01:01:48 +0000 | [diff] [blame] | 2212 | LINX_(__NR_gettid, sys_gettid), // 224 |
| 2213 | |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2214 | //zz // (__NR_readahead, sys_readahead), // 225 */(Linux?) |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2215 | GENX_(__NR_setxattr, sys_setxattr), // 226 |
| 2216 | GENX_(__NR_lsetxattr, sys_lsetxattr), // 227 |
| 2217 | GENX_(__NR_fsetxattr, sys_fsetxattr), // 228 |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2218 | GENXY(__NR_getxattr, sys_getxattr), // 229 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2219 | |
| 2220 | GENXY(__NR_lgetxattr, sys_lgetxattr), // 230 |
| 2221 | GENXY(__NR_fgetxattr, sys_fgetxattr), // 231 |
| 2222 | GENXY(__NR_listxattr, sys_listxattr), // 232 |
| 2223 | GENXY(__NR_llistxattr, sys_llistxattr), // 233 |
| 2224 | GENXY(__NR_flistxattr, sys_flistxattr), // 234 |
| 2225 | |
| 2226 | GENX_(__NR_removexattr, sys_removexattr), // 235 |
| 2227 | GENX_(__NR_lremovexattr, sys_lremovexattr), // 236 |
| 2228 | GENX_(__NR_fremovexattr, sys_fremovexattr), // 237 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2229 | //zz LINX_(__NR_tkill, sys_tkill), // 238 */Linux |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2230 | LINXY(__NR_sendfile64, sys_sendfile64), // 239 |
| 2231 | |
sewardj | bc22cf7 | 2005-06-08 00:02:49 +0000 | [diff] [blame] | 2232 | LINXY(__NR_futex, sys_futex), // 240 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2233 | GENX_(__NR_sched_setaffinity, sys_sched_setaffinity), // 241 |
| 2234 | GENXY(__NR_sched_getaffinity, sys_sched_getaffinity), // 242 |
sewardj | bc22cf7 | 2005-06-08 00:02:49 +0000 | [diff] [blame] | 2235 | PLAX_(__NR_set_thread_area, sys_set_thread_area), // 243 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2236 | PLAX_(__NR_get_thread_area, sys_get_thread_area), // 244 |
| 2237 | |
| 2238 | LINX_(__NR_io_setup, sys_io_setup), // 245 |
| 2239 | LINX_(__NR_io_destroy, sys_io_destroy), // 246 |
| 2240 | LINXY(__NR_io_getevents, sys_io_getevents), // 247 |
| 2241 | LINX_(__NR_io_submit, sys_io_submit), // 248 |
| 2242 | LINXY(__NR_io_cancel, sys_io_cancel), // 249 |
| 2243 | |
tom | 7244083 | 2005-06-15 10:31:10 +0000 | [diff] [blame] | 2244 | LINX_(__NR_fadvise64, sys_fadvise64), // 250 */(Linux?) |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2245 | GENX_(251, sys_ni_syscall), // 251 |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2246 | LINX_(__NR_exit_group, sys_exit_group), // 252 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2247 | GENXY(__NR_lookup_dcookie, sys_lookup_dcookie), // 253 |
| 2248 | LINXY(__NR_epoll_create, sys_epoll_create), // 254 |
| 2249 | |
| 2250 | LINX_(__NR_epoll_ctl, sys_epoll_ctl), // 255 |
| 2251 | LINXY(__NR_epoll_wait, sys_epoll_wait), // 256 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2252 | //zz // (__NR_remap_file_pages, sys_remap_file_pages), // 257 */Linux |
sewardj | bc22cf7 | 2005-06-08 00:02:49 +0000 | [diff] [blame] | 2253 | LINX_(__NR_set_tid_address, sys_set_tid_address), // 258 |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2254 | GENXY(__NR_timer_create, sys_timer_create), // 259 |
| 2255 | |
| 2256 | GENXY(__NR_timer_settime, sys_timer_settime), // (timer_create+1) |
| 2257 | GENXY(__NR_timer_gettime, sys_timer_gettime), // (timer_create+2) |
| 2258 | GENX_(__NR_timer_getoverrun, sys_timer_getoverrun),//(timer_create+3) |
| 2259 | GENX_(__NR_timer_delete, sys_timer_delete), // (timer_create+4) |
| 2260 | GENX_(__NR_clock_settime, sys_clock_settime), // (timer_create+5) |
| 2261 | |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2262 | GENXY(__NR_clock_gettime, sys_clock_gettime), // (timer_create+6) |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2263 | GENXY(__NR_clock_getres, sys_clock_getres), // (timer_create+7) |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2264 | //zz // (__NR_clock_nanosleep, sys_clock_nanosleep),// (timer_create+8) */* |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2265 | GENXY(__NR_statfs64, sys_statfs64), // 268 |
| 2266 | GENXY(__NR_fstatfs64, sys_fstatfs64), // 269 |
| 2267 | |
sewardj | bc22cf7 | 2005-06-08 00:02:49 +0000 | [diff] [blame] | 2268 | LINX_(__NR_tgkill, sys_tgkill), // 270 */Linux |
sewardj | e6d5e72 | 2005-06-10 10:27:55 +0000 | [diff] [blame] | 2269 | GENX_(__NR_utimes, sys_utimes), // 271 |
tom | 7244083 | 2005-06-15 10:31:10 +0000 | [diff] [blame] | 2270 | LINX_(__NR_fadvise64_64, sys_fadvise64_64), // 272 */(Linux?) |
nethercote | 3d5e910 | 2004-11-17 18:22:38 +0000 | [diff] [blame] | 2271 | GENX_(__NR_vserver, sys_ni_syscall), // 273 |
sewardj | a8d8e23 | 2005-06-07 20:04:56 +0000 | [diff] [blame] | 2272 | //zz // (__NR_mbind, sys_mbind), // 274 ?/? |
| 2273 | //zz |
| 2274 | //zz // (__NR_get_mempolicy, sys_get_mempolicy), // 275 ?/? |
| 2275 | //zz // (__NR_set_mempolicy, sys_set_mempolicy), // 276 ?/? |
sewardj | 8c25732 | 2005-06-08 01:01:48 +0000 | [diff] [blame] | 2276 | GENXY(__NR_mq_open, sys_mq_open), // 277 |
| 2277 | GENX_(__NR_mq_unlink, sys_mq_unlink), // (mq_open+1) |
sewardj | 8c9ea4e | 2005-06-08 10:46:56 +0000 | [diff] [blame] | 2278 | GENX_(__NR_mq_timedsend, sys_mq_timedsend), // (mq_open+2) |
| 2279 | |
| 2280 | GENXY(__NR_mq_timedreceive, sys_mq_timedreceive),// (mq_open+3) |
| 2281 | GENX_(__NR_mq_notify, sys_mq_notify), // (mq_open+4) |
| 2282 | GENXY(__NR_mq_getsetattr, sys_mq_getsetattr), // (mq_open+5) |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2283 | GENX_(__NR_sys_kexec_load, sys_ni_syscall), // 283 |
| 2284 | }; |
| 2285 | |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 2286 | const UInt ML_(syscall_table_size) = |
| 2287 | sizeof(ML_(syscall_table)) / sizeof(ML_(syscall_table)[0]); |
nethercote | 8ff888f | 2004-11-17 17:11:45 +0000 | [diff] [blame] | 2288 | |
nethercote | 41c75da | 2004-10-18 15:34:14 +0000 | [diff] [blame] | 2289 | /*--------------------------------------------------------------------*/ |
| 2290 | /*--- end ---*/ |
| 2291 | /*--------------------------------------------------------------------*/ |