1 2 /*--------------------------------------------------------------------*/ 3 /*--- Linux-specific syscalls, etc. syswrap-linux.c ---*/ 4 /*--------------------------------------------------------------------*/ 5 6 /* 7 This file is part of Valgrind, a dynamic binary instrumentation 8 framework. 9 10 Copyright (C) 2000-2013 Nicholas Nethercote 11 njn (at) valgrind.org 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 31 #if defined(VGO_linux) 32 33 #include "pub_core_basics.h" 34 #include "pub_core_vki.h" 35 #include "pub_core_vkiscnums.h" 36 #include "pub_core_libcsetjmp.h" // to keep _threadstate.h happy 37 #include "pub_core_threadstate.h" 38 #include "pub_core_aspacemgr.h" 39 #include "pub_core_debuginfo.h" // VG_(di_notify_*) 40 #include "pub_core_transtab.h" // VG_(discard_translations) 41 #include "pub_core_xarray.h" 42 #include "pub_core_clientstate.h" 43 #include "pub_core_debuglog.h" 44 #include "pub_core_libcbase.h" 45 #include "pub_core_libcassert.h" 46 #include "pub_core_libcfile.h" 47 #include "pub_core_libcprint.h" 48 #include "pub_core_libcproc.h" 49 #include "pub_core_libcsignal.h" 50 #include "pub_core_machine.h" // VG_(get_SP) 51 #include "pub_core_mallocfree.h" 52 #include "pub_core_tooliface.h" 53 #include "pub_core_options.h" 54 #include "pub_core_scheduler.h" 55 #include "pub_core_signals.h" 56 #include "pub_core_syscall.h" 57 #include "pub_core_syswrap.h" 58 #include "pub_core_inner.h" 59 #if defined(ENABLE_INNER_CLIENT_REQUEST) 60 #include "pub_core_clreq.h" 61 #endif 62 63 #include "priv_types_n_macros.h" 64 #include "priv_syswrap-generic.h" 65 #include "priv_syswrap-linux.h" 66 #include "priv_syswrap-xen.h" 67 68 // Run a thread from beginning to end and return the thread's 69 // scheduler-return-code. 70 static VgSchedReturnCode thread_wrapper(Word /*ThreadId*/ tidW) 71 { 72 VgSchedReturnCode ret; 73 ThreadId tid = (ThreadId)tidW; 74 ThreadState* tst = VG_(get_ThreadState)(tid); 75 76 VG_(debugLog)(1, "syswrap-linux", 77 "thread_wrapper(tid=%lld): entry\n", 78 (ULong)tidW); 79 80 vg_assert(tst->status == VgTs_Init); 81 82 /* make sure we get the CPU lock before doing anything significant */ 83 VG_(acquire_BigLock)(tid, "thread_wrapper(starting new thread)"); 84 85 if (0) 86 VG_(printf)("thread tid %d started: stack = %p\n", 87 tid, &tid); 88 89 /* Make sure error reporting is enabled in the new thread. */ 90 tst->err_disablement_level = 0; 91 92 VG_TRACK(pre_thread_first_insn, tid); 93 94 tst->os_state.lwpid = VG_(gettid)(); 95 /* Set the threadgroup for real. This overwrites the provisional 96 value set in do_clone() syswrap-*-linux.c. See comments in 97 do_clone for background, also #226116. */ 98 tst->os_state.threadgroup = VG_(getpid)(); 99 100 /* Thread created with all signals blocked; scheduler will set the 101 appropriate mask */ 102 103 ret = VG_(scheduler)(tid); 104 105 vg_assert(VG_(is_exiting)(tid)); 106 107 vg_assert(tst->status == VgTs_Runnable); 108 vg_assert(VG_(is_running_thread)(tid)); 109 110 VG_(debugLog)(1, "syswrap-linux", 111 "thread_wrapper(tid=%lld): exit, schedreturncode %s\n", 112 (ULong)tidW, VG_(name_of_VgSchedReturnCode)(ret)); 113 114 /* Return to caller, still holding the lock. */ 115 return ret; 116 } 117 118 119 /* --------------------------------------------------------------------- 120 clone-related stuff 121 ------------------------------------------------------------------ */ 122 123 /* Run a thread all the way to the end, then do appropriate exit actions 124 (this is the last-one-out-turn-off-the-lights bit). */ 125 static void run_a_thread_NORETURN ( Word tidW ) 126 { 127 ThreadId tid = (ThreadId)tidW; 128 VgSchedReturnCode src; 129 Int c; 130 ThreadState* tst; 131 #ifdef ENABLE_INNER_CLIENT_REQUEST 132 Int registered_vgstack_id; 133 #endif 134 135 VG_(debugLog)(1, "syswrap-linux", 136 "run_a_thread_NORETURN(tid=%lld): pre-thread_wrapper\n", 137 (ULong)tidW); 138 139 tst = VG_(get_ThreadState)(tid); 140 vg_assert(tst); 141 142 /* An thread has two stacks: 143 * the simulated stack (used by the synthetic cpu. Guest process 144 is using this stack). 145 * the valgrind stack (used by the real cpu. Valgrind code is running 146 on this stack). 147 When Valgrind runs as an inner, it must signals that its (real) stack 148 is the stack to use by the outer to e.g. do stacktraces. 149 */ 150 INNER_REQUEST 151 (registered_vgstack_id 152 = VALGRIND_STACK_REGISTER (tst->os_state.valgrind_stack_base, 153 tst->os_state.valgrind_stack_init_SP)); 154 155 /* Run the thread all the way through. */ 156 src = thread_wrapper(tid); 157 158 VG_(debugLog)(1, "syswrap-linux", 159 "run_a_thread_NORETURN(tid=%lld): post-thread_wrapper\n", 160 (ULong)tidW); 161 162 c = VG_(count_living_threads)(); 163 vg_assert(c >= 1); /* stay sane */ 164 165 // Tell the tool this thread is exiting 166 VG_TRACK( pre_thread_ll_exit, tid ); 167 168 /* If the thread is exiting with errors disabled, complain loudly; 169 doing so is bad (does the user know this has happened?) Also, 170 in all cases, be paranoid and clear the flag anyway so that the 171 thread slot is safe in this respect if later reallocated. This 172 should be unnecessary since the flag should be cleared when the 173 slot is reallocated, in thread_wrapper(). */ 174 if (tst->err_disablement_level > 0) { 175 VG_(umsg)( 176 "WARNING: exiting thread has error reporting disabled.\n" 177 "WARNING: possibly as a result of some mistake in the use\n" 178 "WARNING: of the VALGRIND_DISABLE_ERROR_REPORTING macros.\n" 179 ); 180 VG_(debugLog)( 181 1, "syswrap-linux", 182 "run_a_thread_NORETURN(tid=%lld): " 183 "WARNING: exiting thread has err_disablement_level = %u\n", 184 (ULong)tidW, tst->err_disablement_level 185 ); 186 } 187 tst->err_disablement_level = 0; 188 189 if (c == 1) { 190 191 VG_(debugLog)(1, "syswrap-linux", 192 "run_a_thread_NORETURN(tid=%lld): " 193 "last one standing\n", 194 (ULong)tidW); 195 196 /* We are the last one standing. Keep hold of the lock and 197 carry on to show final tool results, then exit the entire system. 198 Use the continuation pointer set at startup in m_main. */ 199 ( * VG_(address_of_m_main_shutdown_actions_NORETURN) ) (tid, src); 200 } else { 201 202 VG_(debugLog)(1, "syswrap-linux", 203 "run_a_thread_NORETURN(tid=%lld): " 204 "not last one standing\n", 205 (ULong)tidW); 206 207 /* OK, thread is dead, but others still exist. Just exit. */ 208 209 /* This releases the run lock */ 210 VG_(exit_thread)(tid); 211 vg_assert(tst->status == VgTs_Zombie); 212 vg_assert(sizeof(tst->status) == 4); 213 vg_assert(sizeof(tst->os_state.exitcode) == sizeof(Word)); 214 215 INNER_REQUEST (VALGRIND_STACK_DEREGISTER (registered_vgstack_id)); 216 217 /* We have to use this sequence to terminate the thread to 218 prevent a subtle race. If VG_(exit_thread)() had left the 219 ThreadState as Empty, then it could have been reallocated, 220 reusing the stack while we're doing these last cleanups. 221 Instead, VG_(exit_thread) leaves it as Zombie to prevent 222 reallocation. We need to make sure we don't touch the stack 223 between marking it Empty and exiting. Hence the 224 assembler. */ 225 #if defined(VGP_x86_linux) 226 asm volatile ( 227 "pushl %%ebx\n" 228 "movl %1, %0\n" /* set tst->status = VgTs_Empty */ 229 "movl %2, %%eax\n" /* set %eax = __NR_exit */ 230 "movl %3, %%ebx\n" /* set %ebx = tst->os_state.exitcode */ 231 "int $0x80\n" /* exit(tst->os_state.exitcode) */ 232 "popl %%ebx\n" 233 : "=m" (tst->status) 234 : "n" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode) 235 : "eax" 236 ); 237 #elif defined(VGP_amd64_linux) 238 asm volatile ( 239 "movl %1, %0\n" /* set tst->status = VgTs_Empty */ 240 "movq %2, %%rax\n" /* set %rax = __NR_exit */ 241 "movq %3, %%rdi\n" /* set %rdi = tst->os_state.exitcode */ 242 "syscall\n" /* exit(tst->os_state.exitcode) */ 243 : "=m" (tst->status) 244 : "n" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode) 245 : "rax", "rdi" 246 ); 247 #elif defined(VGP_ppc32_linux) || defined(VGP_ppc64_linux) 248 { UInt vgts_empty = (UInt)VgTs_Empty; 249 asm volatile ( 250 "stw %1,%0\n\t" /* set tst->status = VgTs_Empty */ 251 "li 0,%2\n\t" /* set r0 = __NR_exit */ 252 "lwz 3,%3\n\t" /* set r3 = tst->os_state.exitcode */ 253 "sc\n\t" /* exit(tst->os_state.exitcode) */ 254 : "=m" (tst->status) 255 : "r" (vgts_empty), "n" (__NR_exit), "m" (tst->os_state.exitcode) 256 : "r0", "r3" 257 ); 258 } 259 #elif defined(VGP_arm_linux) 260 asm volatile ( 261 "str %1, %0\n" /* set tst->status = VgTs_Empty */ 262 "mov r7, %2\n" /* set %r7 = __NR_exit */ 263 "ldr r0, %3\n" /* set %r0 = tst->os_state.exitcode */ 264 "svc 0x00000000\n" /* exit(tst->os_state.exitcode) */ 265 : "=m" (tst->status) 266 : "r" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode) 267 : "r0", "r7" 268 ); 269 #elif defined(VGP_arm64_linux) 270 asm volatile ( 271 "str %w1, %0\n" /* set tst->status = VgTs_Empty (32-bit store) */ 272 "mov x8, %2\n" /* set %r7 = __NR_exit */ 273 "ldr x0, %3\n" /* set %r0 = tst->os_state.exitcode */ 274 "svc 0x00000000\n" /* exit(tst->os_state.exitcode) */ 275 : "=m" (tst->status) 276 : "r" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode) 277 : "r0", "r7" 278 ); 279 #elif defined(VGP_s390x_linux) 280 asm volatile ( 281 "st %1, %0\n" /* set tst->status = VgTs_Empty */ 282 "lg 2, %3\n" /* set r2 = tst->os_state.exitcode */ 283 "svc %2\n" /* exit(tst->os_state.exitcode) */ 284 : "=m" (tst->status) 285 : "d" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode) 286 : "2" 287 ); 288 #elif defined(VGP_mips32_linux) || defined(VGP_mips64_linux) 289 asm volatile ( 290 "sw %1, %0\n\t" /* set tst->status = VgTs_Empty */ 291 "li $2, %2\n\t" /* set v0 = __NR_exit */ 292 "lw $4, %3\n\t" /* set a0 = tst->os_state.exitcode */ 293 "syscall\n\t" /* exit(tst->os_state.exitcode) */ 294 "nop" 295 : "=m" (tst->status) 296 : "r" (VgTs_Empty), "n" (__NR_exit), "m" (tst->os_state.exitcode) 297 : "cc", "memory" , "v0", "a0" 298 ); 299 #else 300 # error Unknown platform 301 #endif 302 303 VG_(core_panic)("Thread exit failed?\n"); 304 } 305 306 /*NOTREACHED*/ 307 vg_assert(0); 308 } 309 310 Word ML_(start_thread_NORETURN) ( void* arg ) 311 { 312 ThreadState* tst = (ThreadState*)arg; 313 ThreadId tid = tst->tid; 314 315 run_a_thread_NORETURN ( (Word)tid ); 316 /*NOTREACHED*/ 317 vg_assert(0); 318 } 319 320 /* Allocate a stack for this thread, if it doesn't already have one. 321 They're allocated lazily, and never freed. Returns the initial stack 322 pointer value to use, or 0 if allocation failed. */ 323 Addr ML_(allocstack)(ThreadId tid) 324 { 325 ThreadState* tst = VG_(get_ThreadState)(tid); 326 VgStack* stack; 327 Addr initial_SP; 328 329 /* Either the stack_base and stack_init_SP are both zero (in which 330 case a stack hasn't been allocated) or they are both non-zero, 331 in which case it has. */ 332 333 if (tst->os_state.valgrind_stack_base == 0) 334 vg_assert(tst->os_state.valgrind_stack_init_SP == 0); 335 336 if (tst->os_state.valgrind_stack_base != 0) 337 vg_assert(tst->os_state.valgrind_stack_init_SP != 0); 338 339 /* If no stack is present, allocate one. */ 340 341 if (tst->os_state.valgrind_stack_base == 0) { 342 stack = VG_(am_alloc_VgStack)( &initial_SP ); 343 if (stack) { 344 tst->os_state.valgrind_stack_base = (Addr)stack; 345 tst->os_state.valgrind_stack_init_SP = initial_SP; 346 } 347 } 348 349 if (0) 350 VG_(printf)( "stack for tid %d at %p; init_SP=%p\n", 351 tid, 352 (void*)tst->os_state.valgrind_stack_base, 353 (void*)tst->os_state.valgrind_stack_init_SP ); 354 355 return tst->os_state.valgrind_stack_init_SP; 356 } 357 358 /* Allocate a stack for the main thread, and run it all the way to the 359 end. Although we already have a working VgStack 360 (VG_(interim_stack)) it's better to allocate a new one, so that 361 overflow detection works uniformly for all threads. 362 */ 363 void VG_(main_thread_wrapper_NORETURN)(ThreadId tid) 364 { 365 Addr sp; 366 VG_(debugLog)(1, "syswrap-linux", 367 "entering VG_(main_thread_wrapper_NORETURN)\n"); 368 369 sp = ML_(allocstack)(tid); 370 #if defined(ENABLE_INNER_CLIENT_REQUEST) 371 { 372 // we must register the main thread stack before the call 373 // to ML_(call_on_new_stack_0_1), otherwise the outer valgrind 374 // reports 'write error' on the non registered stack. 375 ThreadState* tst = VG_(get_ThreadState)(tid); 376 INNER_REQUEST 377 ((void) 378 VALGRIND_STACK_REGISTER (tst->os_state.valgrind_stack_base, 379 tst->os_state.valgrind_stack_init_SP)); 380 } 381 #endif 382 383 #if defined(VGP_ppc32_linux) 384 /* make a stack frame */ 385 sp -= 16; 386 sp &= ~0xF; 387 *(UWord *)sp = 0; 388 #elif defined(VGP_ppc64_linux) 389 /* make a stack frame */ 390 sp -= 112; 391 sp &= ~((Addr)0xF); 392 *(UWord *)sp = 0; 393 #elif defined(VGP_s390x_linux) 394 /* make a stack frame */ 395 sp -= 160; 396 sp &= ~((Addr)0xF); 397 *(UWord *)sp = 0; 398 #endif 399 400 /* If we can't even allocate the first thread's stack, we're hosed. 401 Give up. */ 402 vg_assert2(sp != 0, "Cannot allocate main thread's stack."); 403 404 /* shouldn't be any other threads around yet */ 405 vg_assert( VG_(count_living_threads)() == 1 ); 406 407 ML_(call_on_new_stack_0_1)( 408 (Addr)sp, /* stack */ 409 0, /* bogus return address */ 410 run_a_thread_NORETURN, /* fn to call */ 411 (Word)tid /* arg to give it */ 412 ); 413 414 /*NOTREACHED*/ 415 vg_assert(0); 416 } 417 418 419 /* Do a clone which is really a fork() */ 420 SysRes ML_(do_fork_clone) ( ThreadId tid, UInt flags, 421 Int* parent_tidptr, Int* child_tidptr ) 422 { 423 vki_sigset_t fork_saved_mask; 424 vki_sigset_t mask; 425 SysRes res; 426 427 if (flags & (VKI_CLONE_SETTLS | VKI_CLONE_FS | VKI_CLONE_VM 428 | VKI_CLONE_FILES | VKI_CLONE_VFORK)) 429 return VG_(mk_SysRes_Error)( VKI_EINVAL ); 430 431 /* Block all signals during fork, so that we can fix things up in 432 the child without being interrupted. */ 433 VG_(sigfillset)(&mask); 434 VG_(sigprocmask)(VKI_SIG_SETMASK, &mask, &fork_saved_mask); 435 436 VG_(do_atfork_pre)(tid); 437 438 /* Since this is the fork() form of clone, we don't need all that 439 VG_(clone) stuff */ 440 #if defined(VGP_x86_linux) \ 441 || defined(VGP_ppc32_linux) || defined(VGP_ppc64_linux) \ 442 || defined(VGP_arm_linux) || defined(VGP_mips32_linux) \ 443 || defined(VGP_mips64_linux) || defined(VGP_arm64_linux) 444 res = VG_(do_syscall5)( __NR_clone, flags, 445 (UWord)NULL, (UWord)parent_tidptr, 446 (UWord)NULL, (UWord)child_tidptr ); 447 #elif defined(VGP_amd64_linux) 448 /* note that the last two arguments are the opposite way round to x86 and 449 ppc32 as the amd64 kernel expects the arguments in a different order */ 450 res = VG_(do_syscall5)( __NR_clone, flags, 451 (UWord)NULL, (UWord)parent_tidptr, 452 (UWord)child_tidptr, (UWord)NULL ); 453 #elif defined(VGP_s390x_linux) 454 /* Note that s390 has the stack first and then the flags */ 455 res = VG_(do_syscall4)( __NR_clone, (UWord) NULL, flags, 456 (UWord)parent_tidptr, (UWord)child_tidptr); 457 #else 458 # error Unknown platform 459 #endif 460 461 if (!sr_isError(res) && sr_Res(res) == 0) { 462 /* child */ 463 VG_(do_atfork_child)(tid); 464 465 /* restore signal mask */ 466 VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL); 467 468 /* If --child-silent-after-fork=yes was specified, set the 469 output file descriptors to 'impossible' values. This is 470 noticed by send_bytes_to_logging_sink in m_libcprint.c, which 471 duly stops writing any further output. */ 472 if (VG_(clo_child_silent_after_fork)) { 473 if (!VG_(log_output_sink).is_socket) 474 VG_(log_output_sink).fd = -1; 475 if (!VG_(xml_output_sink).is_socket) 476 VG_(xml_output_sink).fd = -1; 477 } 478 } 479 else 480 if (!sr_isError(res) && sr_Res(res) > 0) { 481 /* parent */ 482 VG_(do_atfork_parent)(tid); 483 484 if (VG_(clo_trace_syscalls)) 485 VG_(printf)(" clone(fork): process %d created child %ld\n", 486 VG_(getpid)(), sr_Res(res)); 487 488 /* restore signal mask */ 489 VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL); 490 } 491 492 return res; 493 } 494 495 496 /* --------------------------------------------------------------------- 497 PRE/POST wrappers for arch-generic, Linux-specific syscalls 498 ------------------------------------------------------------------ */ 499 500 // Nb: See the comment above the generic PRE/POST wrappers in 501 // m_syswrap/syswrap-generic.c for notes about how they work. 502 503 #define PRE(name) DEFN_PRE_TEMPLATE(linux, name) 504 #define POST(name) DEFN_POST_TEMPLATE(linux, name) 505 506 // Macros to support 64-bit syscall args split into two 32 bit values 507 #define LOHI64(lo,hi) ( ((ULong)(lo)) | (((ULong)(hi)) << 32) ) 508 #if defined(VG_LITTLEENDIAN) 509 #define MERGE64(lo,hi) ( ((ULong)(lo)) | (((ULong)(hi)) << 32) ) 510 #define MERGE64_FIRST(name) name##_low 511 #define MERGE64_SECOND(name) name##_high 512 #elif defined(VG_BIGENDIAN) 513 #define MERGE64(hi,lo) ( ((ULong)(lo)) | (((ULong)(hi)) << 32) ) 514 #define MERGE64_FIRST(name) name##_high 515 #define MERGE64_SECOND(name) name##_low 516 #else 517 #error Unknown endianness 518 #endif 519 520 /* --------------------------------------------------------------------- 521 *mount wrappers 522 ------------------------------------------------------------------ */ 523 524 PRE(sys_mount) 525 { 526 // Nb: depending on 'flags', the 'type' and 'data' args may be ignored. 527 // We are conservative and check everything, except the memory pointed to 528 // by 'data'. 529 *flags |= SfMayBlock; 530 PRINT("sys_mount( %#lx(%s), %#lx(%s), %#lx(%s), %#lx, %#lx )", 531 ARG1,(HChar*)ARG1, ARG2,(HChar*)ARG2, ARG3,(HChar*)ARG3, ARG4, ARG5); 532 PRE_REG_READ5(long, "mount", 533 char *, source, char *, target, char *, type, 534 unsigned long, flags, void *, data); 535 if (ARG1) 536 PRE_MEM_RASCIIZ( "mount(source)", ARG1); 537 PRE_MEM_RASCIIZ( "mount(target)", ARG2); 538 PRE_MEM_RASCIIZ( "mount(type)", ARG3); 539 } 540 541 PRE(sys_oldumount) 542 { 543 PRINT("sys_oldumount( %#lx )", ARG1); 544 PRE_REG_READ1(long, "umount", char *, path); 545 PRE_MEM_RASCIIZ( "umount(path)", ARG1); 546 } 547 548 PRE(sys_umount) 549 { 550 PRINT("sys_umount( %#lx, %ld )", ARG1, ARG2); 551 PRE_REG_READ2(long, "umount2", char *, path, int, flags); 552 PRE_MEM_RASCIIZ( "umount2(path)", ARG1); 553 } 554 555 /* --------------------------------------------------------------------- 556 16- and 32-bit uid/gid wrappers 557 ------------------------------------------------------------------ */ 558 559 PRE(sys_setfsuid16) 560 { 561 PRINT("sys_setfsuid16 ( %ld )", ARG1); 562 PRE_REG_READ1(long, "setfsuid16", vki_old_uid_t, uid); 563 } 564 565 PRE(sys_setfsuid) 566 { 567 PRINT("sys_setfsuid ( %ld )", ARG1); 568 PRE_REG_READ1(long, "setfsuid", vki_uid_t, uid); 569 } 570 571 PRE(sys_setfsgid16) 572 { 573 PRINT("sys_setfsgid16 ( %ld )", ARG1); 574 PRE_REG_READ1(long, "setfsgid16", vki_old_gid_t, gid); 575 } 576 577 PRE(sys_setfsgid) 578 { 579 PRINT("sys_setfsgid ( %ld )", ARG1); 580 PRE_REG_READ1(long, "setfsgid", vki_gid_t, gid); 581 } 582 583 PRE(sys_setresuid16) 584 { 585 PRINT("sys_setresuid16 ( %ld, %ld, %ld )", ARG1, ARG2, ARG3); 586 PRE_REG_READ3(long, "setresuid16", 587 vki_old_uid_t, ruid, vki_old_uid_t, euid, vki_old_uid_t, suid); 588 } 589 590 PRE(sys_setresuid) 591 { 592 PRINT("sys_setresuid ( %ld, %ld, %ld )", ARG1, ARG2, ARG3); 593 PRE_REG_READ3(long, "setresuid", 594 vki_uid_t, ruid, vki_uid_t, euid, vki_uid_t, suid); 595 } 596 597 PRE(sys_getresuid16) 598 { 599 PRINT("sys_getresuid16 ( %#lx, %#lx, %#lx )", ARG1,ARG2,ARG3); 600 PRE_REG_READ3(long, "getresuid16", 601 vki_old_uid_t *, ruid, vki_old_uid_t *, euid, 602 vki_old_uid_t *, suid); 603 PRE_MEM_WRITE( "getresuid16(ruid)", ARG1, sizeof(vki_old_uid_t) ); 604 PRE_MEM_WRITE( "getresuid16(euid)", ARG2, sizeof(vki_old_uid_t) ); 605 PRE_MEM_WRITE( "getresuid16(suid)", ARG3, sizeof(vki_old_uid_t) ); 606 } 607 POST(sys_getresuid16) 608 { 609 vg_assert(SUCCESS); 610 if (RES == 0) { 611 POST_MEM_WRITE( ARG1, sizeof(vki_old_uid_t) ); 612 POST_MEM_WRITE( ARG2, sizeof(vki_old_uid_t) ); 613 POST_MEM_WRITE( ARG3, sizeof(vki_old_uid_t) ); 614 } 615 } 616 617 PRE(sys_getresuid) 618 { 619 PRINT("sys_getresuid ( %#lx, %#lx, %#lx )", ARG1,ARG2,ARG3); 620 PRE_REG_READ3(long, "getresuid", 621 vki_uid_t *, ruid, vki_uid_t *, euid, vki_uid_t *, suid); 622 PRE_MEM_WRITE( "getresuid(ruid)", ARG1, sizeof(vki_uid_t) ); 623 PRE_MEM_WRITE( "getresuid(euid)", ARG2, sizeof(vki_uid_t) ); 624 PRE_MEM_WRITE( "getresuid(suid)", ARG3, sizeof(vki_uid_t) ); 625 } 626 POST(sys_getresuid) 627 { 628 vg_assert(SUCCESS); 629 if (RES == 0) { 630 POST_MEM_WRITE( ARG1, sizeof(vki_uid_t) ); 631 POST_MEM_WRITE( ARG2, sizeof(vki_uid_t) ); 632 POST_MEM_WRITE( ARG3, sizeof(vki_uid_t) ); 633 } 634 } 635 636 PRE(sys_setresgid16) 637 { 638 PRINT("sys_setresgid16 ( %ld, %ld, %ld )", ARG1, ARG2, ARG3); 639 PRE_REG_READ3(long, "setresgid16", 640 vki_old_gid_t, rgid, 641 vki_old_gid_t, egid, vki_old_gid_t, sgid); 642 } 643 644 PRE(sys_setresgid) 645 { 646 PRINT("sys_setresgid ( %ld, %ld, %ld )", ARG1, ARG2, ARG3); 647 PRE_REG_READ3(long, "setresgid", 648 vki_gid_t, rgid, vki_gid_t, egid, vki_gid_t, sgid); 649 } 650 651 PRE(sys_getresgid16) 652 { 653 PRINT("sys_getresgid16 ( %#lx, %#lx, %#lx )", ARG1,ARG2,ARG3); 654 PRE_REG_READ3(long, "getresgid16", 655 vki_old_gid_t *, rgid, vki_old_gid_t *, egid, 656 vki_old_gid_t *, sgid); 657 PRE_MEM_WRITE( "getresgid16(rgid)", ARG1, sizeof(vki_old_gid_t) ); 658 PRE_MEM_WRITE( "getresgid16(egid)", ARG2, sizeof(vki_old_gid_t) ); 659 PRE_MEM_WRITE( "getresgid16(sgid)", ARG3, sizeof(vki_old_gid_t) ); 660 } 661 POST(sys_getresgid16) 662 { 663 vg_assert(SUCCESS); 664 if (RES == 0) { 665 POST_MEM_WRITE( ARG1, sizeof(vki_old_gid_t) ); 666 POST_MEM_WRITE( ARG2, sizeof(vki_old_gid_t) ); 667 POST_MEM_WRITE( ARG3, sizeof(vki_old_gid_t) ); 668 } 669 } 670 671 PRE(sys_getresgid) 672 { 673 PRINT("sys_getresgid ( %#lx, %#lx, %#lx )", ARG1,ARG2,ARG3); 674 PRE_REG_READ3(long, "getresgid", 675 vki_gid_t *, rgid, vki_gid_t *, egid, vki_gid_t *, sgid); 676 PRE_MEM_WRITE( "getresgid(rgid)", ARG1, sizeof(vki_gid_t) ); 677 PRE_MEM_WRITE( "getresgid(egid)", ARG2, sizeof(vki_gid_t) ); 678 PRE_MEM_WRITE( "getresgid(sgid)", ARG3, sizeof(vki_gid_t) ); 679 } 680 POST(sys_getresgid) 681 { 682 vg_assert(SUCCESS); 683 if (RES == 0) { 684 POST_MEM_WRITE( ARG1, sizeof(vki_gid_t) ); 685 POST_MEM_WRITE( ARG2, sizeof(vki_gid_t) ); 686 POST_MEM_WRITE( ARG3, sizeof(vki_gid_t) ); 687 } 688 } 689 690 /* --------------------------------------------------------------------- 691 miscellaneous wrappers 692 ------------------------------------------------------------------ */ 693 694 PRE(sys_exit_group) 695 { 696 ThreadId t; 697 ThreadState* tst; 698 699 PRINT("exit_group( %ld )", ARG1); 700 PRE_REG_READ1(void, "exit_group", int, status); 701 702 tst = VG_(get_ThreadState)(tid); 703 /* A little complex; find all the threads with the same threadgroup 704 as this one (including this one), and mark them to exit */ 705 /* It is unclear how one can get a threadgroup in this process which 706 is not the threadgroup of the calling thread: 707 The assignments to threadgroups are: 708 = 0; /// scheduler.c os_state_clear 709 = getpid(); /// scheduler.c in child after fork 710 = getpid(); /// this file, in thread_wrapper 711 = ptst->os_state.threadgroup; /// syswrap-*-linux.c, 712 copying the thread group of the thread doing clone 713 So, the only case where the threadgroup might be different to the getpid 714 value is in the child, just after fork. But then the fork syscall is 715 still going on, the forked thread has had no chance yet to make this 716 syscall. */ 717 for (t = 1; t < VG_N_THREADS; t++) { 718 if ( /* not alive */ 719 VG_(threads)[t].status == VgTs_Empty 720 || 721 /* not our group */ 722 VG_(threads)[t].os_state.threadgroup != tst->os_state.threadgroup 723 ) 724 continue; 725 /* Assign the exit code, VG_(nuke_all_threads_except) will assign 726 the exitreason. */ 727 VG_(threads)[t].os_state.exitcode = ARG1; 728 } 729 730 /* Indicate in all other threads that the process is exiting. 731 Then wait using VG_(reap_threads) for these threads to disappear. 732 733 Can this give a deadlock if another thread is calling exit in parallel 734 and would then wait for this thread to disappear ? 735 The answer is no: 736 Other threads are either blocked in a syscall or have yielded the CPU. 737 738 A thread that has yielded the CPU is trying to get the big lock in 739 VG_(scheduler). This thread will get the CPU thanks to the call 740 to VG_(reap_threads). The scheduler will then check for signals, 741 kill the process if this is a fatal signal, and otherwise prepare 742 the thread for handling this signal. After this preparation, if 743 the thread status is VG_(is_exiting), the scheduler exits the thread. 744 So, a thread that has yielded the CPU does not have a chance to 745 call exit => no deadlock for this thread. 746 747 VG_(nuke_all_threads_except) will send the VG_SIGVGKILL signal 748 to all threads blocked in a syscall. 749 The syscall will be interrupted, and the control will go to the 750 scheduler. The scheduler will then return, as the thread is in 751 exiting state. */ 752 753 VG_(nuke_all_threads_except)( tid, VgSrc_ExitProcess ); 754 VG_(reap_threads)(tid); 755 VG_(threads)[tid].exitreason = VgSrc_ExitThread; 756 /* we do assign VgSrc_ExitThread and not VgSrc_ExitProcess, as this thread 757 is the thread calling exit_group and so its registers must be considered 758 as not reachable. See pub_tool_machine.h VG_(apply_to_GP_regs). */ 759 760 /* We have to claim the syscall already succeeded. */ 761 SET_STATUS_Success(0); 762 } 763 764 PRE(sys_llseek) 765 { 766 PRINT("sys_llseek ( %ld, 0x%lx, 0x%lx, %#lx, %ld )", ARG1,ARG2,ARG3,ARG4,ARG5); 767 PRE_REG_READ5(long, "llseek", 768 unsigned int, fd, unsigned long, offset_high, 769 unsigned long, offset_low, vki_loff_t *, result, 770 unsigned int, whence); 771 if (!ML_(fd_allowed)(ARG1, "llseek", tid, False)) 772 SET_STATUS_Failure( VKI_EBADF ); 773 else 774 PRE_MEM_WRITE( "llseek(result)", ARG4, sizeof(vki_loff_t)); 775 } 776 POST(sys_llseek) 777 { 778 vg_assert(SUCCESS); 779 if (RES == 0) 780 POST_MEM_WRITE( ARG4, sizeof(vki_loff_t) ); 781 } 782 783 PRE(sys_adjtimex) 784 { 785 struct vki_timex *tx = (struct vki_timex *)ARG1; 786 PRINT("sys_adjtimex ( %#lx )", ARG1); 787 PRE_REG_READ1(long, "adjtimex", struct timex *, buf); 788 PRE_MEM_READ( "adjtimex(timex->modes)", ARG1, sizeof(tx->modes)); 789 790 #define ADJX(bits,field) \ 791 if (tx->modes & (bits)) \ 792 PRE_MEM_READ( "adjtimex(timex->"#field")", \ 793 (Addr)&tx->field, sizeof(tx->field)) 794 795 if (tx->modes & VKI_ADJ_ADJTIME) { 796 if (!(tx->modes & VKI_ADJ_OFFSET_READONLY)) 797 PRE_MEM_READ( "adjtimex(timex->offset)", (Addr)&tx->offset, sizeof(tx->offset)); 798 } else { 799 ADJX(VKI_ADJ_OFFSET, offset); 800 ADJX(VKI_ADJ_FREQUENCY, freq); 801 ADJX(VKI_ADJ_MAXERROR, maxerror); 802 ADJX(VKI_ADJ_ESTERROR, esterror); 803 ADJX(VKI_ADJ_STATUS, status); 804 ADJX(VKI_ADJ_TIMECONST|VKI_ADJ_TAI, constant); 805 ADJX(VKI_ADJ_TICK, tick); 806 } 807 #undef ADJX 808 809 PRE_MEM_WRITE( "adjtimex(timex)", ARG1, sizeof(struct vki_timex)); 810 } 811 812 POST(sys_adjtimex) 813 { 814 POST_MEM_WRITE( ARG1, sizeof(struct vki_timex) ); 815 } 816 817 PRE(sys_clock_adjtime) 818 { 819 struct vki_timex *tx = (struct vki_timex *)ARG2; 820 PRINT("sys_clock_adjtime ( %ld, %#lx )", ARG1,ARG2); 821 PRE_REG_READ2(long, "clock_adjtime", vki_clockid_t, id, struct timex *, buf); 822 PRE_MEM_READ( "clock_adjtime(timex->modes)", ARG2, sizeof(tx->modes)); 823 824 #define ADJX(bits,field) \ 825 if (tx->modes & (bits)) \ 826 PRE_MEM_READ( "clock_adjtime(timex->"#field")", \ 827 (Addr)&tx->field, sizeof(tx->field)) 828 829 if (tx->modes & VKI_ADJ_ADJTIME) { 830 if (!(tx->modes & VKI_ADJ_OFFSET_READONLY)) 831 PRE_MEM_READ( "clock_adjtime(timex->offset)", (Addr)&tx->offset, sizeof(tx->offset)); 832 } else { 833 ADJX(VKI_ADJ_OFFSET, offset); 834 ADJX(VKI_ADJ_FREQUENCY, freq); 835 ADJX(VKI_ADJ_MAXERROR, maxerror); 836 ADJX(VKI_ADJ_ESTERROR, esterror); 837 ADJX(VKI_ADJ_STATUS, status); 838 ADJX(VKI_ADJ_TIMECONST|VKI_ADJ_TAI, constant); 839 ADJX(VKI_ADJ_TICK, tick); 840 } 841 #undef ADJX 842 843 PRE_MEM_WRITE( "adjtimex(timex)", ARG2, sizeof(struct vki_timex)); 844 } 845 846 POST(sys_clock_adjtime) 847 { 848 POST_MEM_WRITE( ARG2, sizeof(struct vki_timex) ); 849 } 850 851 PRE(sys_ioperm) 852 { 853 PRINT("sys_ioperm ( %ld, %ld, %ld )", ARG1, ARG2, ARG3 ); 854 PRE_REG_READ3(long, "ioperm", 855 unsigned long, from, unsigned long, num, int, turn_on); 856 } 857 858 PRE(sys_syslog) 859 { 860 *flags |= SfMayBlock; 861 PRINT("sys_syslog (%ld, %#lx, %ld)", ARG1,ARG2,ARG3); 862 PRE_REG_READ3(long, "syslog", int, type, char *, bufp, int, len); 863 switch (ARG1) { 864 // The kernel uses magic numbers here, rather than named constants, 865 // therefore so do we. 866 case 2: case 3: case 4: 867 PRE_MEM_WRITE( "syslog(bufp)", ARG2, ARG3); 868 break; 869 default: 870 break; 871 } 872 } 873 POST(sys_syslog) 874 { 875 switch (ARG1) { 876 case 2: case 3: case 4: 877 POST_MEM_WRITE( ARG2, ARG3 ); 878 break; 879 default: 880 break; 881 } 882 } 883 884 PRE(sys_vhangup) 885 { 886 PRINT("sys_vhangup ( )"); 887 PRE_REG_READ0(long, "vhangup"); 888 } 889 890 PRE(sys_sysinfo) 891 { 892 PRINT("sys_sysinfo ( %#lx )",ARG1); 893 PRE_REG_READ1(long, "sysinfo", struct sysinfo *, info); 894 PRE_MEM_WRITE( "sysinfo(info)", ARG1, sizeof(struct vki_sysinfo) ); 895 } 896 POST(sys_sysinfo) 897 { 898 POST_MEM_WRITE( ARG1, sizeof(struct vki_sysinfo) ); 899 } 900 901 PRE(sys_personality) 902 { 903 PRINT("sys_personality ( %llu )", (ULong)ARG1); 904 PRE_REG_READ1(long, "personality", vki_u_long, persona); 905 } 906 907 PRE(sys_sysctl) 908 { 909 struct __vki_sysctl_args *args; 910 PRINT("sys_sysctl ( %#lx )", ARG1 ); 911 args = (struct __vki_sysctl_args *)ARG1; 912 PRE_REG_READ1(long, "sysctl", struct __sysctl_args *, args); 913 PRE_MEM_WRITE( "sysctl(args)", ARG1, sizeof(struct __vki_sysctl_args) ); 914 if (!VG_(am_is_valid_for_client)(ARG1, sizeof(struct __vki_sysctl_args), 915 VKI_PROT_READ)) { 916 SET_STATUS_Failure( VKI_EFAULT ); 917 return; 918 } 919 920 PRE_MEM_READ("sysctl(name)", (Addr)args->name, args->nlen * sizeof(*args->name)); 921 if (args->newval != NULL) 922 PRE_MEM_READ("sysctl(newval)", (Addr)args->newval, args->newlen); 923 if (args->oldlenp != NULL) { 924 PRE_MEM_READ("sysctl(oldlenp)", (Addr)args->oldlenp, sizeof(*args->oldlenp)); 925 PRE_MEM_WRITE("sysctl(oldval)", (Addr)args->oldval, *args->oldlenp); 926 } 927 } 928 POST(sys_sysctl) 929 { 930 struct __vki_sysctl_args *args; 931 args = (struct __vki_sysctl_args *)ARG1; 932 if (args->oldlenp != NULL) { 933 POST_MEM_WRITE((Addr)args->oldlenp, sizeof(*args->oldlenp)); 934 POST_MEM_WRITE((Addr)args->oldval, 1 + *args->oldlenp); 935 } 936 } 937 938 PRE(sys_prctl) 939 { 940 *flags |= SfMayBlock; 941 PRINT( "sys_prctl ( %ld, %ld, %ld, %ld, %ld )", ARG1, ARG2, ARG3, ARG4, ARG5 ); 942 switch (ARG1) { 943 case VKI_PR_SET_PDEATHSIG: 944 PRE_REG_READ2(int, "prctl", int, option, int, signal); 945 break; 946 case VKI_PR_GET_PDEATHSIG: 947 PRE_REG_READ2(int, "prctl", int, option, int *, signal); 948 PRE_MEM_WRITE("prctl(get-death-signal)", ARG2, sizeof(Int)); 949 break; 950 case VKI_PR_GET_DUMPABLE: 951 PRE_REG_READ1(int, "prctl", int, option); 952 break; 953 case VKI_PR_SET_DUMPABLE: 954 PRE_REG_READ2(int, "prctl", int, option, int, dump); 955 break; 956 case VKI_PR_GET_UNALIGN: 957 PRE_REG_READ2(int, "prctl", int, option, int *, value); 958 PRE_MEM_WRITE("prctl(get-unalign)", ARG2, sizeof(Int)); 959 break; 960 case VKI_PR_SET_UNALIGN: 961 PRE_REG_READ2(int, "prctl", int, option, int, value); 962 break; 963 case VKI_PR_GET_KEEPCAPS: 964 PRE_REG_READ1(int, "prctl", int, option); 965 break; 966 case VKI_PR_SET_KEEPCAPS: 967 PRE_REG_READ2(int, "prctl", int, option, int, keepcaps); 968 break; 969 case VKI_PR_GET_FPEMU: 970 PRE_REG_READ2(int, "prctl", int, option, int *, value); 971 PRE_MEM_WRITE("prctl(get-fpemu)", ARG2, sizeof(Int)); 972 break; 973 case VKI_PR_SET_FPEMU: 974 PRE_REG_READ2(int, "prctl", int, option, int, value); 975 break; 976 case VKI_PR_GET_FPEXC: 977 PRE_REG_READ2(int, "prctl", int, option, int *, value); 978 PRE_MEM_WRITE("prctl(get-fpexc)", ARG2, sizeof(Int)); 979 break; 980 case VKI_PR_SET_FPEXC: 981 PRE_REG_READ2(int, "prctl", int, option, int, value); 982 break; 983 case VKI_PR_GET_TIMING: 984 PRE_REG_READ1(int, "prctl", int, option); 985 break; 986 case VKI_PR_SET_TIMING: 987 PRE_REG_READ2(int, "prctl", int, option, int, timing); 988 break; 989 case VKI_PR_SET_NAME: 990 PRE_REG_READ2(int, "prctl", int, option, char *, name); 991 PRE_MEM_RASCIIZ("prctl(set-name)", ARG2); 992 break; 993 case VKI_PR_GET_NAME: 994 PRE_REG_READ2(int, "prctl", int, option, char *, name); 995 PRE_MEM_WRITE("prctl(get-name)", ARG2, VKI_TASK_COMM_LEN); 996 break; 997 case VKI_PR_GET_ENDIAN: 998 PRE_REG_READ2(int, "prctl", int, option, int *, value); 999 PRE_MEM_WRITE("prctl(get-endian)", ARG2, sizeof(Int)); 1000 break; 1001 case VKI_PR_SET_ENDIAN: 1002 PRE_REG_READ2(int, "prctl", int, option, int, value); 1003 break; 1004 default: 1005 PRE_REG_READ5(long, "prctl", 1006 int, option, unsigned long, arg2, unsigned long, arg3, 1007 unsigned long, arg4, unsigned long, arg5); 1008 break; 1009 } 1010 } 1011 POST(sys_prctl) 1012 { 1013 switch (ARG1) { 1014 case VKI_PR_GET_PDEATHSIG: 1015 POST_MEM_WRITE(ARG2, sizeof(Int)); 1016 break; 1017 case VKI_PR_GET_UNALIGN: 1018 POST_MEM_WRITE(ARG2, sizeof(Int)); 1019 break; 1020 case VKI_PR_GET_FPEMU: 1021 POST_MEM_WRITE(ARG2, sizeof(Int)); 1022 break; 1023 case VKI_PR_GET_FPEXC: 1024 POST_MEM_WRITE(ARG2, sizeof(Int)); 1025 break; 1026 case VKI_PR_GET_NAME: 1027 POST_MEM_WRITE(ARG2, VKI_TASK_COMM_LEN); 1028 break; 1029 case VKI_PR_GET_ENDIAN: 1030 POST_MEM_WRITE(ARG2, sizeof(Int)); 1031 break; 1032 case VKI_PR_SET_NAME: 1033 { 1034 const HChar* new_name = (const HChar*) ARG2; 1035 if (new_name) { // Paranoia 1036 ThreadState* tst = VG_(get_ThreadState)(tid); 1037 SizeT new_len = VG_(strlen)(new_name); 1038 1039 /* Don't bother reusing the memory. This is a rare event. */ 1040 tst->thread_name = 1041 VG_(arena_realloc)(VG_AR_CORE, "syswrap.prctl", 1042 tst->thread_name, new_len + 1); 1043 VG_(strcpy)(tst->thread_name, new_name); 1044 } 1045 } 1046 break; 1047 } 1048 } 1049 1050 PRE(sys_sendfile) 1051 { 1052 *flags |= SfMayBlock; 1053 PRINT("sys_sendfile ( %ld, %ld, %#lx, %lu )", ARG1,ARG2,ARG3,ARG4); 1054 PRE_REG_READ4(ssize_t, "sendfile", 1055 int, out_fd, int, in_fd, vki_off_t *, offset, 1056 vki_size_t, count); 1057 if (ARG3 != 0) 1058 PRE_MEM_WRITE( "sendfile(offset)", ARG3, sizeof(vki_off_t) ); 1059 } 1060 POST(sys_sendfile) 1061 { 1062 if (ARG3 != 0 ) { 1063 POST_MEM_WRITE( ARG3, sizeof( vki_off_t ) ); 1064 } 1065 } 1066 1067 PRE(sys_sendfile64) 1068 { 1069 *flags |= SfMayBlock; 1070 PRINT("sendfile64 ( %ld, %ld, %#lx, %lu )",ARG1,ARG2,ARG3,ARG4); 1071 PRE_REG_READ4(ssize_t, "sendfile64", 1072 int, out_fd, int, in_fd, vki_loff_t *, offset, 1073 vki_size_t, count); 1074 if (ARG3 != 0) 1075 PRE_MEM_WRITE( "sendfile64(offset)", ARG3, sizeof(vki_loff_t) ); 1076 } 1077 POST(sys_sendfile64) 1078 { 1079 if (ARG3 != 0 ) { 1080 POST_MEM_WRITE( ARG3, sizeof(vki_loff_t) ); 1081 } 1082 } 1083 1084 PRE(sys_futex) 1085 { 1086 /* 1087 arg param used by ops 1088 1089 ARG1 - u32 *futex all 1090 ARG2 - int op 1091 ARG3 - int val WAIT,WAKE,FD,REQUEUE,CMP_REQUEUE 1092 ARG4 - struct timespec *utime WAIT:time* REQUEUE,CMP_REQUEUE:val2 1093 ARG5 - u32 *uaddr2 REQUEUE,CMP_REQUEUE 1094 ARG6 - int val3 CMP_REQUEUE 1095 */ 1096 PRINT("sys_futex ( %#lx, %ld, %ld, %#lx, %#lx )", ARG1,ARG2,ARG3,ARG4,ARG5); 1097 switch(ARG2 & ~(VKI_FUTEX_PRIVATE_FLAG|VKI_FUTEX_CLOCK_REALTIME)) { 1098 case VKI_FUTEX_CMP_REQUEUE: 1099 case VKI_FUTEX_WAKE_OP: 1100 case VKI_FUTEX_CMP_REQUEUE_PI: 1101 PRE_REG_READ6(long, "futex", 1102 vki_u32 *, futex, int, op, int, val, 1103 struct timespec *, utime, vki_u32 *, uaddr2, int, val3); 1104 break; 1105 case VKI_FUTEX_REQUEUE: 1106 case VKI_FUTEX_WAIT_REQUEUE_PI: 1107 PRE_REG_READ5(long, "futex", 1108 vki_u32 *, futex, int, op, int, val, 1109 struct timespec *, utime, vki_u32 *, uaddr2); 1110 break; 1111 case VKI_FUTEX_WAIT_BITSET: 1112 /* Check that the address at least begins in client-accessible area. */ 1113 if (!VG_(am_is_valid_for_client)( ARG1, 1, VKI_PROT_READ )) { 1114 SET_STATUS_Failure( VKI_EFAULT ); 1115 return; 1116 } 1117 if (*(vki_u32 *)ARG1 != ARG3) { 1118 PRE_REG_READ5(long, "futex", 1119 vki_u32 *, futex, int, op, int, val, 1120 struct timespec *, utime, int, dummy); 1121 } else { 1122 PRE_REG_READ6(long, "futex", 1123 vki_u32 *, futex, int, op, int, val, 1124 struct timespec *, utime, int, dummy, int, val3); 1125 } 1126 break; 1127 case VKI_FUTEX_WAKE_BITSET: 1128 PRE_REG_READ6(long, "futex", 1129 vki_u32 *, futex, int, op, int, val, 1130 int, dummy, int, dummy2, int, val3); 1131 break; 1132 case VKI_FUTEX_WAIT: 1133 case VKI_FUTEX_LOCK_PI: 1134 PRE_REG_READ4(long, "futex", 1135 vki_u32 *, futex, int, op, int, val, 1136 struct timespec *, utime); 1137 break; 1138 case VKI_FUTEX_WAKE: 1139 case VKI_FUTEX_FD: 1140 case VKI_FUTEX_TRYLOCK_PI: 1141 PRE_REG_READ3(long, "futex", 1142 vki_u32 *, futex, int, op, int, val); 1143 break; 1144 case VKI_FUTEX_UNLOCK_PI: 1145 default: 1146 PRE_REG_READ2(long, "futex", vki_u32 *, futex, int, op); 1147 break; 1148 } 1149 1150 *flags |= SfMayBlock; 1151 1152 switch(ARG2 & ~(VKI_FUTEX_PRIVATE_FLAG|VKI_FUTEX_CLOCK_REALTIME)) { 1153 case VKI_FUTEX_WAIT: 1154 case VKI_FUTEX_LOCK_PI: 1155 case VKI_FUTEX_WAIT_BITSET: 1156 case VKI_FUTEX_WAIT_REQUEUE_PI: 1157 PRE_MEM_READ( "futex(futex)", ARG1, sizeof(Int) ); 1158 if (ARG4 != 0) 1159 PRE_MEM_READ( "futex(timeout)", ARG4, sizeof(struct vki_timespec) ); 1160 break; 1161 1162 case VKI_FUTEX_REQUEUE: 1163 case VKI_FUTEX_CMP_REQUEUE: 1164 case VKI_FUTEX_CMP_REQUEUE_PI: 1165 case VKI_FUTEX_WAKE_OP: 1166 PRE_MEM_READ( "futex(futex)", ARG1, sizeof(Int) ); 1167 PRE_MEM_READ( "futex(futex2)", ARG5, sizeof(Int) ); 1168 break; 1169 1170 case VKI_FUTEX_FD: 1171 case VKI_FUTEX_TRYLOCK_PI: 1172 case VKI_FUTEX_UNLOCK_PI: 1173 PRE_MEM_READ( "futex(futex)", ARG1, sizeof(Int) ); 1174 break; 1175 1176 case VKI_FUTEX_WAKE: 1177 case VKI_FUTEX_WAKE_BITSET: 1178 /* no additional pointers */ 1179 break; 1180 1181 default: 1182 SET_STATUS_Failure( VKI_ENOSYS ); // some futex function we don't understand 1183 break; 1184 } 1185 } 1186 POST(sys_futex) 1187 { 1188 vg_assert(SUCCESS); 1189 POST_MEM_WRITE( ARG1, sizeof(int) ); 1190 if (ARG2 == VKI_FUTEX_FD) { 1191 if (!ML_(fd_allowed)(RES, "futex", tid, True)) { 1192 VG_(close)(RES); 1193 SET_STATUS_Failure( VKI_EMFILE ); 1194 } else { 1195 if (VG_(clo_track_fds)) 1196 ML_(record_fd_open_nameless)(tid, RES); 1197 } 1198 } 1199 } 1200 1201 PRE(sys_set_robust_list) 1202 { 1203 PRINT("sys_set_robust_list ( %#lx, %ld )", ARG1,ARG2); 1204 PRE_REG_READ2(long, "set_robust_list", 1205 struct vki_robust_list_head *, head, vki_size_t, len); 1206 1207 /* Just check the robust_list_head structure is readable - don't 1208 try and chase the list as the kernel will only read it when 1209 the thread exits so the current contents is irrelevant. */ 1210 if (ARG1 != 0) 1211 PRE_MEM_READ("set_robust_list(head)", ARG1, ARG2); 1212 } 1213 1214 PRE(sys_get_robust_list) 1215 { 1216 PRINT("sys_get_robust_list ( %ld, %#lx, %ld )", ARG1,ARG2,ARG3); 1217 PRE_REG_READ3(long, "get_robust_list", 1218 int, pid, 1219 struct vki_robust_list_head **, head_ptr, 1220 vki_size_t *, len_ptr); 1221 PRE_MEM_WRITE("get_robust_list(head_ptr)", 1222 ARG2, sizeof(struct vki_robust_list_head *)); 1223 PRE_MEM_WRITE("get_robust_list(len_ptr)", 1224 ARG3, sizeof(struct vki_size_t *)); 1225 } 1226 POST(sys_get_robust_list) 1227 { 1228 POST_MEM_WRITE(ARG2, sizeof(struct vki_robust_list_head *)); 1229 POST_MEM_WRITE(ARG3, sizeof(struct vki_size_t *)); 1230 } 1231 1232 PRE(sys_pselect6) 1233 { 1234 *flags |= SfMayBlock; 1235 PRINT("sys_pselect6 ( %ld, %#lx, %#lx, %#lx, %#lx, %#lx )", ARG1,ARG2,ARG3,ARG4,ARG5,ARG6); 1236 PRE_REG_READ6(long, "pselect6", 1237 int, n, vki_fd_set *, readfds, vki_fd_set *, writefds, 1238 vki_fd_set *, exceptfds, struct vki_timeval *, timeout, 1239 void *, sig); 1240 // XXX: this possibly understates how much memory is read. 1241 if (ARG2 != 0) 1242 PRE_MEM_READ( "pselect6(readfds)", 1243 ARG2, ARG1/8 /* __FD_SETSIZE/8 */ ); 1244 if (ARG3 != 0) 1245 PRE_MEM_READ( "pselect6(writefds)", 1246 ARG3, ARG1/8 /* __FD_SETSIZE/8 */ ); 1247 if (ARG4 != 0) 1248 PRE_MEM_READ( "pselect6(exceptfds)", 1249 ARG4, ARG1/8 /* __FD_SETSIZE/8 */ ); 1250 if (ARG5 != 0) 1251 PRE_MEM_READ( "pselect6(timeout)", ARG5, sizeof(struct vki_timeval) ); 1252 if (ARG6 != 0) 1253 PRE_MEM_READ( "pselect6(sig)", ARG6, sizeof(void *)+sizeof(vki_size_t) ); 1254 } 1255 1256 PRE(sys_ppoll) 1257 { 1258 UInt i; 1259 struct vki_pollfd* ufds = (struct vki_pollfd *)ARG1; 1260 *flags |= SfMayBlock; 1261 PRINT("sys_ppoll ( %#lx, %ld, %#lx, %#lx, %llu )\n", ARG1,ARG2,ARG3,ARG4,(ULong)ARG5); 1262 PRE_REG_READ5(long, "ppoll", 1263 struct vki_pollfd *, ufds, unsigned int, nfds, 1264 struct vki_timespec *, tsp, vki_sigset_t *, sigmask, 1265 vki_size_t, sigsetsize); 1266 1267 for (i = 0; i < ARG2; i++) { 1268 PRE_MEM_READ( "ppoll(ufds.fd)", 1269 (Addr)(&ufds[i].fd), sizeof(ufds[i].fd) ); 1270 PRE_MEM_READ( "ppoll(ufds.events)", 1271 (Addr)(&ufds[i].events), sizeof(ufds[i].events) ); 1272 PRE_MEM_WRITE( "ppoll(ufd.revents)", 1273 (Addr)(&ufds[i].revents), sizeof(ufds[i].revents) ); 1274 } 1275 1276 if (ARG3) 1277 PRE_MEM_READ( "ppoll(tsp)", ARG3, sizeof(struct vki_timespec) ); 1278 if (ARG4) 1279 PRE_MEM_READ( "ppoll(sigmask)", ARG4, sizeof(vki_sigset_t) ); 1280 } 1281 1282 POST(sys_ppoll) 1283 { 1284 if (RES > 0) { 1285 UInt i; 1286 struct vki_pollfd* ufds = (struct vki_pollfd *)ARG1; 1287 for (i = 0; i < ARG2; i++) 1288 POST_MEM_WRITE( (Addr)(&ufds[i].revents), sizeof(ufds[i].revents) ); 1289 } 1290 } 1291 1292 1293 /* --------------------------------------------------------------------- 1294 epoll_* wrappers 1295 ------------------------------------------------------------------ */ 1296 1297 PRE(sys_epoll_create) 1298 { 1299 PRINT("sys_epoll_create ( %ld )", ARG1); 1300 PRE_REG_READ1(long, "epoll_create", int, size); 1301 } 1302 POST(sys_epoll_create) 1303 { 1304 vg_assert(SUCCESS); 1305 if (!ML_(fd_allowed)(RES, "epoll_create", tid, True)) { 1306 VG_(close)(RES); 1307 SET_STATUS_Failure( VKI_EMFILE ); 1308 } else { 1309 if (VG_(clo_track_fds)) 1310 ML_(record_fd_open_nameless) (tid, RES); 1311 } 1312 } 1313 1314 PRE(sys_epoll_create1) 1315 { 1316 PRINT("sys_epoll_create1 ( %ld )", ARG1); 1317 PRE_REG_READ1(long, "epoll_create1", int, flags); 1318 } 1319 POST(sys_epoll_create1) 1320 { 1321 vg_assert(SUCCESS); 1322 if (!ML_(fd_allowed)(RES, "epoll_create1", tid, True)) { 1323 VG_(close)(RES); 1324 SET_STATUS_Failure( VKI_EMFILE ); 1325 } else { 1326 if (VG_(clo_track_fds)) 1327 ML_(record_fd_open_nameless) (tid, RES); 1328 } 1329 } 1330 1331 PRE(sys_epoll_ctl) 1332 { 1333 static const HChar* epoll_ctl_s[3] = { 1334 "EPOLL_CTL_ADD", 1335 "EPOLL_CTL_DEL", 1336 "EPOLL_CTL_MOD" 1337 }; 1338 PRINT("sys_epoll_ctl ( %ld, %s, %ld, %#lx )", 1339 ARG1, ( ARG2<3 ? epoll_ctl_s[ARG2] : "?" ), ARG3, ARG4); 1340 PRE_REG_READ4(long, "epoll_ctl", 1341 int, epfd, int, op, int, fd, struct vki_epoll_event *, event); 1342 if (ARG2 != VKI_EPOLL_CTL_DEL) 1343 PRE_MEM_READ( "epoll_ctl(event)", ARG4, sizeof(struct vki_epoll_event) ); 1344 } 1345 1346 PRE(sys_epoll_wait) 1347 { 1348 *flags |= SfMayBlock; 1349 PRINT("sys_epoll_wait ( %ld, %#lx, %ld, %ld )", ARG1, ARG2, ARG3, ARG4); 1350 PRE_REG_READ4(long, "epoll_wait", 1351 int, epfd, struct vki_epoll_event *, events, 1352 int, maxevents, int, timeout); 1353 PRE_MEM_WRITE( "epoll_wait(events)", ARG2, sizeof(struct vki_epoll_event)*ARG3); 1354 } 1355 POST(sys_epoll_wait) 1356 { 1357 vg_assert(SUCCESS); 1358 if (RES > 0) 1359 POST_MEM_WRITE( ARG2, sizeof(struct vki_epoll_event)*RES ) ; 1360 } 1361 1362 PRE(sys_epoll_pwait) 1363 { 1364 *flags |= SfMayBlock; 1365 PRINT("sys_epoll_pwait ( %ld, %#lx, %ld, %ld, %#lx, %llu )", ARG1,ARG2,ARG3,ARG4,ARG5,(ULong)ARG6); 1366 PRE_REG_READ6(long, "epoll_pwait", 1367 int, epfd, struct vki_epoll_event *, events, 1368 int, maxevents, int, timeout, vki_sigset_t *, sigmask, 1369 vki_size_t, sigsetsize); 1370 PRE_MEM_WRITE( "epoll_pwait(events)", ARG2, sizeof(struct vki_epoll_event)*ARG3); 1371 if (ARG4) 1372 PRE_MEM_READ( "epoll_pwait(sigmask)", ARG5, sizeof(vki_sigset_t) ); 1373 } 1374 POST(sys_epoll_pwait) 1375 { 1376 vg_assert(SUCCESS); 1377 if (RES > 0) 1378 POST_MEM_WRITE( ARG2, sizeof(struct vki_epoll_event)*RES ) ; 1379 } 1380 1381 PRE(sys_eventfd) 1382 { 1383 PRINT("sys_eventfd ( %lu )", ARG1); 1384 PRE_REG_READ1(long, "sys_eventfd", unsigned int, count); 1385 } 1386 POST(sys_eventfd) 1387 { 1388 if (!ML_(fd_allowed)(RES, "eventfd", tid, True)) { 1389 VG_(close)(RES); 1390 SET_STATUS_Failure( VKI_EMFILE ); 1391 } else { 1392 if (VG_(clo_track_fds)) 1393 ML_(record_fd_open_nameless) (tid, RES); 1394 } 1395 } 1396 1397 PRE(sys_eventfd2) 1398 { 1399 PRINT("sys_eventfd2 ( %lu, %ld )", ARG1,ARG2); 1400 PRE_REG_READ2(long, "sys_eventfd2", unsigned int, count, int, flags); 1401 } 1402 POST(sys_eventfd2) 1403 { 1404 if (!ML_(fd_allowed)(RES, "eventfd2", tid, True)) { 1405 VG_(close)(RES); 1406 SET_STATUS_Failure( VKI_EMFILE ); 1407 } else { 1408 if (VG_(clo_track_fds)) 1409 ML_(record_fd_open_nameless) (tid, RES); 1410 } 1411 } 1412 1413 PRE(sys_fallocate) 1414 { 1415 *flags |= SfMayBlock; 1416 #if VG_WORDSIZE == 4 1417 PRINT("sys_fallocate ( %ld, %ld, %lld, %lld )", 1418 ARG1, ARG2, MERGE64(ARG3,ARG4), MERGE64(ARG5,ARG6)); 1419 PRE_REG_READ6(long, "fallocate", 1420 int, fd, int, mode, 1421 unsigned, MERGE64_FIRST(offset), unsigned, MERGE64_SECOND(offset), 1422 unsigned, MERGE64_FIRST(len), unsigned, MERGE64_SECOND(len)); 1423 #elif VG_WORDSIZE == 8 1424 PRINT("sys_fallocate ( %ld, %ld, %lld, %lld )", 1425 ARG1, ARG2, (Long)ARG3, (Long)ARG4); 1426 PRE_REG_READ4(long, "fallocate", 1427 int, fd, int, mode, vki_loff_t, offset, vki_loff_t, len); 1428 #else 1429 # error Unexpected word size 1430 #endif 1431 if (!ML_(fd_allowed)(ARG1, "fallocate", tid, False)) 1432 SET_STATUS_Failure( VKI_EBADF ); 1433 } 1434 1435 PRE(sys_prlimit64) 1436 { 1437 PRINT("sys_prlimit64 ( %ld, %ld, %#lx, %#lx )", ARG1,ARG2,ARG3,ARG4); 1438 PRE_REG_READ4(long, "prlimit64", 1439 vki_pid_t, pid, unsigned int, resource, 1440 const struct rlimit64 *, new_rlim, 1441 struct rlimit64 *, old_rlim); 1442 if (ARG3) 1443 PRE_MEM_READ( "rlimit64(new_rlim)", ARG3, sizeof(struct vki_rlimit64) ); 1444 if (ARG4) 1445 PRE_MEM_WRITE( "rlimit64(old_rlim)", ARG4, sizeof(struct vki_rlimit64) ); 1446 1447 if (ARG3 && 1448 ((struct vki_rlimit64 *)ARG3)->rlim_cur > ((struct vki_rlimit64 *)ARG3)->rlim_max) { 1449 SET_STATUS_Failure( VKI_EINVAL ); 1450 } 1451 else if (ARG1 == 0 || ARG1 == VG_(getpid)()) { 1452 switch (ARG2) { 1453 case VKI_RLIMIT_NOFILE: 1454 SET_STATUS_Success( 0 ); 1455 if (ARG4) { 1456 ((struct vki_rlimit64 *)ARG4)->rlim_cur = VG_(fd_soft_limit); 1457 ((struct vki_rlimit64 *)ARG4)->rlim_max = VG_(fd_hard_limit); 1458 } 1459 if (ARG3) { 1460 if (((struct vki_rlimit64 *)ARG3)->rlim_cur > VG_(fd_hard_limit) || 1461 ((struct vki_rlimit64 *)ARG3)->rlim_max != VG_(fd_hard_limit)) { 1462 SET_STATUS_Failure( VKI_EPERM ); 1463 } 1464 else { 1465 VG_(fd_soft_limit) = ((struct vki_rlimit64 *)ARG3)->rlim_cur; 1466 } 1467 } 1468 break; 1469 1470 case VKI_RLIMIT_DATA: 1471 SET_STATUS_Success( 0 ); 1472 if (ARG4) { 1473 ((struct vki_rlimit64 *)ARG4)->rlim_cur = VG_(client_rlimit_data).rlim_cur; 1474 ((struct vki_rlimit64 *)ARG4)->rlim_max = VG_(client_rlimit_data).rlim_max; 1475 } 1476 if (ARG3) { 1477 if (((struct vki_rlimit64 *)ARG3)->rlim_cur > VG_(client_rlimit_data).rlim_max || 1478 ((struct vki_rlimit64 *)ARG3)->rlim_max > VG_(client_rlimit_data).rlim_max) { 1479 SET_STATUS_Failure( VKI_EPERM ); 1480 } 1481 else { 1482 VG_(client_rlimit_data).rlim_cur = ((struct vki_rlimit64 *)ARG3)->rlim_cur; 1483 VG_(client_rlimit_data).rlim_max = ((struct vki_rlimit64 *)ARG3)->rlim_max; 1484 } 1485 } 1486 break; 1487 1488 case VKI_RLIMIT_STACK: 1489 SET_STATUS_Success( 0 ); 1490 if (ARG4) { 1491 ((struct vki_rlimit64 *)ARG4)->rlim_cur = VG_(client_rlimit_stack).rlim_cur; 1492 ((struct vki_rlimit64 *)ARG4)->rlim_max = VG_(client_rlimit_stack).rlim_max; 1493 } 1494 if (ARG3) { 1495 if (((struct vki_rlimit64 *)ARG3)->rlim_cur > VG_(client_rlimit_stack).rlim_max || 1496 ((struct vki_rlimit64 *)ARG3)->rlim_max > VG_(client_rlimit_stack).rlim_max) { 1497 SET_STATUS_Failure( VKI_EPERM ); 1498 } 1499 else { 1500 VG_(threads)[tid].client_stack_szB = ((struct vki_rlimit64 *)ARG3)->rlim_cur; 1501 VG_(client_rlimit_stack).rlim_cur = ((struct vki_rlimit64 *)ARG3)->rlim_cur; 1502 VG_(client_rlimit_stack).rlim_max = ((struct vki_rlimit64 *)ARG3)->rlim_max; 1503 } 1504 } 1505 break; 1506 } 1507 } 1508 } 1509 1510 POST(sys_prlimit64) 1511 { 1512 if (ARG4) 1513 POST_MEM_WRITE( ARG4, sizeof(struct vki_rlimit64) ); 1514 } 1515 1516 /* --------------------------------------------------------------------- 1517 tid-related wrappers 1518 ------------------------------------------------------------------ */ 1519 1520 PRE(sys_gettid) 1521 { 1522 PRINT("sys_gettid ()"); 1523 PRE_REG_READ0(long, "gettid"); 1524 } 1525 1526 PRE(sys_set_tid_address) 1527 { 1528 PRINT("sys_set_tid_address ( %#lx )", ARG1); 1529 PRE_REG_READ1(long, "set_tid_address", int *, tidptr); 1530 } 1531 1532 PRE(sys_tkill) 1533 { 1534 PRINT("sys_tgkill ( %ld, %ld )", ARG1,ARG2); 1535 PRE_REG_READ2(long, "tkill", int, tid, int, sig); 1536 if (!ML_(client_signal_OK)(ARG2)) { 1537 SET_STATUS_Failure( VKI_EINVAL ); 1538 return; 1539 } 1540 1541 /* Check to see if this kill gave us a pending signal */ 1542 *flags |= SfPollAfter; 1543 1544 if (VG_(clo_trace_signals)) 1545 VG_(message)(Vg_DebugMsg, "tkill: sending signal %ld to pid %ld\n", 1546 ARG2, ARG1); 1547 1548 /* If we're sending SIGKILL, check to see if the target is one of 1549 our threads and handle it specially. */ 1550 if (ARG2 == VKI_SIGKILL && ML_(do_sigkill)(ARG1, -1)) { 1551 SET_STATUS_Success(0); 1552 return; 1553 } 1554 1555 /* Ask to handle this syscall via the slow route, since that's the 1556 only one that sets tst->status to VgTs_WaitSys. If the result 1557 of doing the syscall is an immediate run of 1558 async_signalhandler() in m_signals, then we need the thread to 1559 be properly tidied away. I have the impression the previous 1560 version of this wrapper worked on x86/amd64 only because the 1561 kernel did not immediately deliver the async signal to this 1562 thread (on ppc it did, which broke the assertion re tst->status 1563 at the top of async_signalhandler()). */ 1564 *flags |= SfMayBlock; 1565 } 1566 POST(sys_tkill) 1567 { 1568 if (VG_(clo_trace_signals)) 1569 VG_(message)(Vg_DebugMsg, "tkill: sent signal %ld to pid %ld\n", 1570 ARG2, ARG1); 1571 } 1572 1573 PRE(sys_tgkill) 1574 { 1575 PRINT("sys_tgkill ( %ld, %ld, %ld )", ARG1,ARG2,ARG3); 1576 PRE_REG_READ3(long, "tgkill", int, tgid, int, tid, int, sig); 1577 if (!ML_(client_signal_OK)(ARG3)) { 1578 SET_STATUS_Failure( VKI_EINVAL ); 1579 return; 1580 } 1581 1582 /* Check to see if this kill gave us a pending signal */ 1583 *flags |= SfPollAfter; 1584 1585 if (VG_(clo_trace_signals)) 1586 VG_(message)(Vg_DebugMsg, 1587 "tgkill: sending signal %ld to pid %ld/%ld\n", 1588 ARG3, ARG1, ARG2); 1589 1590 /* If we're sending SIGKILL, check to see if the target is one of 1591 our threads and handle it specially. */ 1592 if (ARG3 == VKI_SIGKILL && ML_(do_sigkill)(ARG2, ARG1)) { 1593 SET_STATUS_Success(0); 1594 return; 1595 } 1596 1597 /* Ask to handle this syscall via the slow route, since that's the 1598 only one that sets tst->status to VgTs_WaitSys. If the result 1599 of doing the syscall is an immediate run of 1600 async_signalhandler() in m_signals, then we need the thread to 1601 be properly tidied away. I have the impression the previous 1602 version of this wrapper worked on x86/amd64 only because the 1603 kernel did not immediately deliver the async signal to this 1604 thread (on ppc it did, which broke the assertion re tst->status 1605 at the top of async_signalhandler()). */ 1606 *flags |= SfMayBlock; 1607 } 1608 POST(sys_tgkill) 1609 { 1610 if (VG_(clo_trace_signals)) 1611 VG_(message)(Vg_DebugMsg, 1612 "tgkill: sent signal %ld to pid %ld/%ld\n", 1613 ARG3, ARG1, ARG2); 1614 } 1615 1616 /* --------------------------------------------------------------------- 1617 fadvise64* wrappers 1618 ------------------------------------------------------------------ */ 1619 1620 PRE(sys_fadvise64) 1621 { 1622 PRINT("sys_fadvise64 ( %ld, %lld, %lu, %ld )", 1623 ARG1, MERGE64(ARG2,ARG3), ARG4, ARG5); 1624 PRE_REG_READ5(long, "fadvise64", 1625 int, fd, vki_u32, MERGE64_FIRST(offset), vki_u32, MERGE64_SECOND(offset), 1626 vki_size_t, len, int, advice); 1627 } 1628 1629 PRE(sys_fadvise64_64) 1630 { 1631 PRINT("sys_fadvise64_64 ( %ld, %lld, %lld, %ld )", 1632 ARG1, MERGE64(ARG2,ARG3), MERGE64(ARG4,ARG5), ARG6); 1633 PRE_REG_READ6(long, "fadvise64_64", 1634 int, fd, vki_u32, MERGE64_FIRST(offset), vki_u32, MERGE64_SECOND(offset), 1635 vki_u32, MERGE64_FIRST(len), vki_u32, MERGE64_SECOND(len), int, advice); 1636 } 1637 1638 /* --------------------------------------------------------------------- 1639 io_* wrappers 1640 ------------------------------------------------------------------ */ 1641 1642 // Nb: this wrapper has to pad/unpad memory around the syscall itself, 1643 // and this allows us to control exactly the code that gets run while 1644 // the padding is in place. 1645 1646 PRE(sys_io_setup) 1647 { 1648 PRINT("sys_io_setup ( %lu, %#lx )", ARG1,ARG2); 1649 PRE_REG_READ2(long, "io_setup", 1650 unsigned, nr_events, vki_aio_context_t *, ctxp); 1651 PRE_MEM_WRITE( "io_setup(ctxp)", ARG2, sizeof(vki_aio_context_t) ); 1652 } 1653 1654 POST(sys_io_setup) 1655 { 1656 SizeT size; 1657 struct vki_aio_ring *r; 1658 1659 size = VG_PGROUNDUP(sizeof(struct vki_aio_ring) + 1660 ARG1*sizeof(struct vki_io_event)); 1661 r = *(struct vki_aio_ring **)ARG2; 1662 vg_assert(ML_(valid_client_addr)((Addr)r, size, tid, "io_setup")); 1663 1664 ML_(notify_core_and_tool_of_mmap)( (Addr)r, size, 1665 VKI_PROT_READ | VKI_PROT_WRITE, 1666 VKI_MAP_ANONYMOUS, -1, 0 ); 1667 1668 POST_MEM_WRITE( ARG2, sizeof(vki_aio_context_t) ); 1669 } 1670 1671 // Nb: This wrapper is "Special" because we need 'size' to do the unmap 1672 // after the syscall. We must get 'size' from the aio_ring structure, 1673 // before the syscall, while the aio_ring structure still exists. (And we 1674 // know that we must look at the aio_ring structure because Tom inspected the 1675 // kernel and glibc sources to see what they do, yuk.) 1676 // 1677 // XXX This segment can be implicitly unmapped when aio 1678 // file-descriptors are closed... 1679 PRE(sys_io_destroy) 1680 { 1681 SizeT size = 0; 1682 1683 PRINT("sys_io_destroy ( %llu )", (ULong)ARG1); 1684 PRE_REG_READ1(long, "io_destroy", vki_aio_context_t, ctx); 1685 1686 // If we are going to seg fault (due to a bogus ARG1) do it as late as 1687 // possible... 1688 if (ML_(safe_to_deref)( (void*)ARG1, sizeof(struct vki_aio_ring))) { 1689 struct vki_aio_ring *r = (struct vki_aio_ring *)ARG1; 1690 size = VG_PGROUNDUP(sizeof(struct vki_aio_ring) + 1691 r->nr*sizeof(struct vki_io_event)); 1692 } 1693 1694 SET_STATUS_from_SysRes( VG_(do_syscall1)(SYSNO, ARG1) ); 1695 1696 if (SUCCESS && RES == 0) { 1697 Bool d = VG_(am_notify_munmap)( ARG1, size ); 1698 VG_TRACK( die_mem_munmap, ARG1, size ); 1699 if (d) 1700 VG_(discard_translations)( (Addr64)ARG1, (ULong)size, 1701 "PRE(sys_io_destroy)" ); 1702 } 1703 } 1704 1705 PRE(sys_io_getevents) 1706 { 1707 *flags |= SfMayBlock; 1708 PRINT("sys_io_getevents ( %llu, %lld, %lld, %#lx, %#lx )", 1709 (ULong)ARG1,(Long)ARG2,(Long)ARG3,ARG4,ARG5); 1710 PRE_REG_READ5(long, "io_getevents", 1711 vki_aio_context_t, ctx_id, long, min_nr, long, nr, 1712 struct io_event *, events, 1713 struct timespec *, timeout); 1714 if (ARG3 > 0) 1715 PRE_MEM_WRITE( "io_getevents(events)", 1716 ARG4, sizeof(struct vki_io_event)*ARG3 ); 1717 if (ARG5 != 0) 1718 PRE_MEM_READ( "io_getevents(timeout)", 1719 ARG5, sizeof(struct vki_timespec)); 1720 } 1721 POST(sys_io_getevents) 1722 { 1723 Int i; 1724 vg_assert(SUCCESS); 1725 if (RES > 0) { 1726 POST_MEM_WRITE( ARG4, sizeof(struct vki_io_event)*RES ); 1727 for (i = 0; i < RES; i++) { 1728 const struct vki_io_event *vev = ((struct vki_io_event *)ARG4) + i; 1729 const struct vki_iocb *cb = (struct vki_iocb *)(Addr)vev->obj; 1730 1731 switch (cb->aio_lio_opcode) { 1732 case VKI_IOCB_CMD_PREAD: 1733 if (vev->result > 0) 1734 POST_MEM_WRITE( cb->aio_buf, vev->result ); 1735 break; 1736 1737 case VKI_IOCB_CMD_PWRITE: 1738 break; 1739 1740 case VKI_IOCB_CMD_FSYNC: 1741 break; 1742 1743 case VKI_IOCB_CMD_FDSYNC: 1744 break; 1745 1746 case VKI_IOCB_CMD_PREADV: 1747 if (vev->result > 0) { 1748 struct vki_iovec * vec = (struct vki_iovec *)(Addr)cb->aio_buf; 1749 Int remains = vev->result; 1750 Int j; 1751 1752 for (j = 0; j < cb->aio_nbytes; j++) { 1753 Int nReadThisBuf = vec[j].iov_len; 1754 if (nReadThisBuf > remains) nReadThisBuf = remains; 1755 POST_MEM_WRITE( (Addr)vec[j].iov_base, nReadThisBuf ); 1756 remains -= nReadThisBuf; 1757 if (remains < 0) VG_(core_panic)("io_getevents(PREADV): remains < 0"); 1758 } 1759 } 1760 break; 1761 1762 case VKI_IOCB_CMD_PWRITEV: 1763 break; 1764 1765 default: 1766 VG_(message)(Vg_DebugMsg, 1767 "Warning: unhandled io_getevents opcode: %u\n", 1768 cb->aio_lio_opcode); 1769 break; 1770 } 1771 } 1772 } 1773 } 1774 1775 PRE(sys_io_submit) 1776 { 1777 Int i, j; 1778 1779 PRINT("sys_io_submit ( %llu, %ld, %#lx )", (ULong)ARG1,ARG2,ARG3); 1780 PRE_REG_READ3(long, "io_submit", 1781 vki_aio_context_t, ctx_id, long, nr, 1782 struct iocb **, iocbpp); 1783 PRE_MEM_READ( "io_submit(iocbpp)", ARG3, ARG2*sizeof(struct vki_iocb *) ); 1784 if (ARG3 != 0) { 1785 for (i = 0; i < ARG2; i++) { 1786 struct vki_iocb *cb = ((struct vki_iocb **)ARG3)[i]; 1787 struct vki_iovec *iov; 1788 1789 PRE_MEM_READ( "io_submit(iocb)", (Addr)cb, sizeof(struct vki_iocb) ); 1790 switch (cb->aio_lio_opcode) { 1791 case VKI_IOCB_CMD_PREAD: 1792 PRE_MEM_WRITE( "io_submit(PREAD)", cb->aio_buf, cb->aio_nbytes ); 1793 break; 1794 1795 case VKI_IOCB_CMD_PWRITE: 1796 PRE_MEM_READ( "io_submit(PWRITE)", cb->aio_buf, cb->aio_nbytes ); 1797 break; 1798 1799 case VKI_IOCB_CMD_FSYNC: 1800 break; 1801 1802 case VKI_IOCB_CMD_FDSYNC: 1803 break; 1804 1805 case VKI_IOCB_CMD_PREADV: 1806 iov = (struct vki_iovec *)(Addr)cb->aio_buf; 1807 PRE_MEM_READ( "io_submit(PREADV)", cb->aio_buf, cb->aio_nbytes * sizeof(struct vki_iovec) ); 1808 for (j = 0; j < cb->aio_nbytes; j++) 1809 PRE_MEM_WRITE( "io_submit(PREADV(iov[i]))", (Addr)iov[j].iov_base, iov[j].iov_len ); 1810 break; 1811 1812 case VKI_IOCB_CMD_PWRITEV: 1813 iov = (struct vki_iovec *)(Addr)cb->aio_buf; 1814 PRE_MEM_READ( "io_submit(PWRITEV)", cb->aio_buf, cb->aio_nbytes * sizeof(struct vki_iovec) ); 1815 for (j = 0; j < cb->aio_nbytes; j++) 1816 PRE_MEM_READ( "io_submit(PWRITEV(iov[i]))", (Addr)iov[j].iov_base, iov[j].iov_len ); 1817 break; 1818 1819 default: 1820 VG_(message)(Vg_DebugMsg,"Warning: unhandled io_submit opcode: %u\n", 1821 cb->aio_lio_opcode); 1822 break; 1823 } 1824 } 1825 } 1826 } 1827 1828 PRE(sys_io_cancel) 1829 { 1830 PRINT("sys_io_cancel ( %llu, %#lx, %#lx )", (ULong)ARG1,ARG2,ARG3); 1831 PRE_REG_READ3(long, "io_cancel", 1832 vki_aio_context_t, ctx_id, struct iocb *, iocb, 1833 struct io_event *, result); 1834 PRE_MEM_READ( "io_cancel(iocb)", ARG2, sizeof(struct vki_iocb) ); 1835 PRE_MEM_WRITE( "io_cancel(result)", ARG3, sizeof(struct vki_io_event) ); 1836 } 1837 POST(sys_io_cancel) 1838 { 1839 POST_MEM_WRITE( ARG3, sizeof(struct vki_io_event) ); 1840 } 1841 1842 /* --------------------------------------------------------------------- 1843 *_mempolicy wrappers 1844 ------------------------------------------------------------------ */ 1845 1846 PRE(sys_mbind) 1847 { 1848 PRINT("sys_mbind ( %#lx, %lu, %ld, %#lx, %lu, %lu )", ARG1,ARG2,ARG3,ARG4,ARG5,ARG6); 1849 PRE_REG_READ6(long, "mbind", 1850 unsigned long, start, unsigned long, len, 1851 unsigned long, policy, unsigned long *, nodemask, 1852 unsigned long, maxnode, unsigned, flags); 1853 if (ARG1 != 0) 1854 PRE_MEM_READ( "mbind(nodemask)", ARG4, 1855 VG_ROUNDUP( ARG5-1, sizeof(UWord) * 8 ) / 8 ); 1856 } 1857 1858 PRE(sys_set_mempolicy) 1859 { 1860 PRINT("sys_set_mempolicy ( %ld, %#lx, %ld )", ARG1,ARG2,ARG3); 1861 PRE_REG_READ3(long, "set_mempolicy", 1862 int, policy, unsigned long *, nodemask, 1863 unsigned long, maxnode); 1864 PRE_MEM_READ( "set_mempolicy(nodemask)", ARG2, 1865 VG_ROUNDUP( ARG3-1, sizeof(UWord) * 8 ) / 8 ); 1866 } 1867 1868 PRE(sys_get_mempolicy) 1869 { 1870 PRINT("sys_get_mempolicy ( %#lx, %#lx, %ld, %#lx, %lx )", ARG1,ARG2,ARG3,ARG4,ARG5); 1871 PRE_REG_READ5(long, "get_mempolicy", 1872 int *, policy, unsigned long *, nodemask, 1873 unsigned long, maxnode, unsigned long, addr, 1874 unsigned long, flags); 1875 if (ARG1 != 0) 1876 PRE_MEM_WRITE( "get_mempolicy(policy)", ARG1, sizeof(Int) ); 1877 if (ARG2 != 0) 1878 PRE_MEM_WRITE( "get_mempolicy(nodemask)", ARG2, 1879 VG_ROUNDUP( ARG3-1, sizeof(UWord) * 8 ) / 8 ); 1880 } 1881 POST(sys_get_mempolicy) 1882 { 1883 if (ARG1 != 0) 1884 POST_MEM_WRITE( ARG1, sizeof(Int) ); 1885 if (ARG2 != 0) 1886 POST_MEM_WRITE( ARG2, VG_ROUNDUP( ARG3-1, sizeof(UWord) * 8 ) / 8 ); 1887 } 1888 1889 /* --------------------------------------------------------------------- 1890 fanotify_* wrappers 1891 ------------------------------------------------------------------ */ 1892 1893 PRE(sys_fanotify_init) 1894 { 1895 PRINT("sys_fanotify_init ( %lu, %lu )", ARG1,ARG2); 1896 PRE_REG_READ2(long, "fanotify_init", 1897 unsigned int, flags, unsigned int, event_f_flags); 1898 } 1899 1900 POST(sys_fanotify_init) 1901 { 1902 vg_assert(SUCCESS); 1903 if (!ML_(fd_allowed)(RES, "fanotify_init", tid, True)) { 1904 VG_(close)(RES); 1905 SET_STATUS_Failure( VKI_EMFILE ); 1906 } else { 1907 if (VG_(clo_track_fds)) 1908 ML_(record_fd_open_nameless) (tid, RES); 1909 } 1910 } 1911 1912 PRE(sys_fanotify_mark) 1913 { 1914 #if VG_WORDSIZE == 4 1915 PRINT( "sys_fanotify_mark ( %ld, %lu, %llu, %ld, %#lx(%s))", 1916 ARG1,ARG2,MERGE64(ARG3,ARG4),ARG5,ARG6,(char *)ARG6); 1917 PRE_REG_READ6(long, "sys_fanotify_mark", 1918 int, fanotify_fd, unsigned int, flags, 1919 __vki_u32, mask0, __vki_u32, mask1, 1920 int, dfd, const char *, pathname); 1921 if (ARG6) 1922 PRE_MEM_RASCIIZ( "fanotify_mark(path)", ARG6); 1923 #elif VG_WORDSIZE == 8 1924 PRINT( "sys_fanotify_mark ( %ld, %lu, %llu, %ld, %#lx(%s))", 1925 ARG1,ARG2,(ULong)ARG3,ARG4,ARG5,(char *)ARG5); 1926 PRE_REG_READ5(long, "sys_fanotify_mark", 1927 int, fanotify_fd, unsigned int, flags, 1928 __vki_u64, mask, 1929 int, dfd, const char *, pathname); 1930 if (ARG5) 1931 PRE_MEM_RASCIIZ( "fanotify_mark(path)", ARG5); 1932 #else 1933 # error Unexpected word size 1934 #endif 1935 } 1936 1937 /* --------------------------------------------------------------------- 1938 inotify_* wrappers 1939 ------------------------------------------------------------------ */ 1940 1941 PRE(sys_inotify_init) 1942 { 1943 PRINT("sys_inotify_init ( )"); 1944 PRE_REG_READ0(long, "inotify_init"); 1945 } 1946 POST(sys_inotify_init) 1947 { 1948 vg_assert(SUCCESS); 1949 if (!ML_(fd_allowed)(RES, "inotify_init", tid, True)) { 1950 VG_(close)(RES); 1951 SET_STATUS_Failure( VKI_EMFILE ); 1952 } else { 1953 if (VG_(clo_track_fds)) 1954 ML_(record_fd_open_nameless) (tid, RES); 1955 } 1956 } 1957 1958 PRE(sys_inotify_init1) 1959 { 1960 PRINT("sys_inotify_init ( %ld )", ARG1); 1961 PRE_REG_READ1(long, "inotify_init", int, flag); 1962 } 1963 1964 POST(sys_inotify_init1) 1965 { 1966 vg_assert(SUCCESS); 1967 if (!ML_(fd_allowed)(RES, "inotify_init", tid, True)) { 1968 VG_(close)(RES); 1969 SET_STATUS_Failure( VKI_EMFILE ); 1970 } else { 1971 if (VG_(clo_track_fds)) 1972 ML_(record_fd_open_nameless) (tid, RES); 1973 } 1974 } 1975 1976 PRE(sys_inotify_add_watch) 1977 { 1978 PRINT( "sys_inotify_add_watch ( %ld, %#lx, %lx )", ARG1,ARG2,ARG3); 1979 PRE_REG_READ3(long, "inotify_add_watch", int, fd, char *, path, int, mask); 1980 PRE_MEM_RASCIIZ( "inotify_add_watch(path)", ARG2 ); 1981 } 1982 1983 PRE(sys_inotify_rm_watch) 1984 { 1985 PRINT( "sys_inotify_rm_watch ( %ld, %lx )", ARG1,ARG2); 1986 PRE_REG_READ2(long, "inotify_rm_watch", int, fd, int, wd); 1987 } 1988 1989 /* --------------------------------------------------------------------- 1990 mq_* wrappers 1991 ------------------------------------------------------------------ */ 1992 1993 PRE(sys_mq_open) 1994 { 1995 PRINT("sys_mq_open( %#lx(%s), %ld, %lld, %#lx )", 1996 ARG1,(char*)ARG1,ARG2,(ULong)ARG3,ARG4); 1997 PRE_REG_READ4(long, "mq_open", 1998 const char *, name, int, oflag, vki_mode_t, mode, 1999 struct mq_attr *, attr); 2000 PRE_MEM_RASCIIZ( "mq_open(name)", ARG1 ); 2001 if ((ARG2 & VKI_O_CREAT) != 0 && ARG4 != 0) { 2002 const struct vki_mq_attr *attr = (struct vki_mq_attr *)ARG4; 2003 PRE_MEM_READ( "mq_open(attr->mq_maxmsg)", 2004 (Addr)&attr->mq_maxmsg, sizeof(attr->mq_maxmsg) ); 2005 PRE_MEM_READ( "mq_open(attr->mq_msgsize)", 2006 (Addr)&attr->mq_msgsize, sizeof(attr->mq_msgsize) ); 2007 } 2008 } 2009 POST(sys_mq_open) 2010 { 2011 vg_assert(SUCCESS); 2012 if (!ML_(fd_allowed)(RES, "mq_open", tid, True)) { 2013 VG_(close)(RES); 2014 SET_STATUS_Failure( VKI_EMFILE ); 2015 } else { 2016 if (VG_(clo_track_fds)) 2017 ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG1); 2018 } 2019 } 2020 2021 PRE(sys_mq_unlink) 2022 { 2023 PRINT("sys_mq_unlink ( %#lx(%s) )", ARG1,(char*)ARG1); 2024 PRE_REG_READ1(long, "mq_unlink", const char *, name); 2025 PRE_MEM_RASCIIZ( "mq_unlink(name)", ARG1 ); 2026 } 2027 2028 PRE(sys_mq_timedsend) 2029 { 2030 *flags |= SfMayBlock; 2031 PRINT("sys_mq_timedsend ( %ld, %#lx, %llu, %ld, %#lx )", 2032 ARG1,ARG2,(ULong)ARG3,ARG4,ARG5); 2033 PRE_REG_READ5(long, "mq_timedsend", 2034 vki_mqd_t, mqdes, const char *, msg_ptr, vki_size_t, msg_len, 2035 unsigned int, msg_prio, const struct timespec *, abs_timeout); 2036 if (!ML_(fd_allowed)(ARG1, "mq_timedsend", tid, False)) { 2037 SET_STATUS_Failure( VKI_EBADF ); 2038 } else { 2039 PRE_MEM_READ( "mq_timedsend(msg_ptr)", ARG2, ARG3 ); 2040 if (ARG5 != 0) 2041 PRE_MEM_READ( "mq_timedsend(abs_timeout)", ARG5, 2042 sizeof(struct vki_timespec) ); 2043 } 2044 } 2045 2046 PRE(sys_mq_timedreceive) 2047 { 2048 *flags |= SfMayBlock; 2049 PRINT("sys_mq_timedreceive( %ld, %#lx, %llu, %#lx, %#lx )", 2050 ARG1,ARG2,(ULong)ARG3,ARG4,ARG5); 2051 PRE_REG_READ5(ssize_t, "mq_timedreceive", 2052 vki_mqd_t, mqdes, char *, msg_ptr, vki_size_t, msg_len, 2053 unsigned int *, msg_prio, 2054 const struct timespec *, abs_timeout); 2055 if (!ML_(fd_allowed)(ARG1, "mq_timedreceive", tid, False)) { 2056 SET_STATUS_Failure( VKI_EBADF ); 2057 } else { 2058 PRE_MEM_WRITE( "mq_timedreceive(msg_ptr)", ARG2, ARG3 ); 2059 if (ARG4 != 0) 2060 PRE_MEM_WRITE( "mq_timedreceive(msg_prio)", 2061 ARG4, sizeof(unsigned int) ); 2062 if (ARG5 != 0) 2063 PRE_MEM_READ( "mq_timedreceive(abs_timeout)", 2064 ARG5, sizeof(struct vki_timespec) ); 2065 } 2066 } 2067 POST(sys_mq_timedreceive) 2068 { 2069 POST_MEM_WRITE( ARG2, RES ); 2070 if (ARG4 != 0) 2071 POST_MEM_WRITE( ARG4, sizeof(unsigned int) ); 2072 } 2073 2074 PRE(sys_mq_notify) 2075 { 2076 PRINT("sys_mq_notify( %ld, %#lx )", ARG1,ARG2 ); 2077 PRE_REG_READ2(long, "mq_notify", 2078 vki_mqd_t, mqdes, const struct sigevent *, notification); 2079 if (!ML_(fd_allowed)(ARG1, "mq_notify", tid, False)) 2080 SET_STATUS_Failure( VKI_EBADF ); 2081 else if (ARG2 != 0) 2082 PRE_MEM_READ( "mq_notify(notification)", 2083 ARG2, sizeof(struct vki_sigevent) ); 2084 } 2085 2086 PRE(sys_mq_getsetattr) 2087 { 2088 PRINT("sys_mq_getsetattr( %ld, %#lx, %#lx )", ARG1,ARG2,ARG3 ); 2089 PRE_REG_READ3(long, "mq_getsetattr", 2090 vki_mqd_t, mqdes, const struct mq_attr *, mqstat, 2091 struct mq_attr *, omqstat); 2092 if (!ML_(fd_allowed)(ARG1, "mq_getsetattr", tid, False)) { 2093 SET_STATUS_Failure( VKI_EBADF ); 2094 } else { 2095 if (ARG2 != 0) { 2096 const struct vki_mq_attr *attr = (struct vki_mq_attr *)ARG2; 2097 PRE_MEM_READ( "mq_getsetattr(mqstat->mq_flags)", 2098 (Addr)&attr->mq_flags, sizeof(attr->mq_flags) ); 2099 } 2100 if (ARG3 != 0) 2101 PRE_MEM_WRITE( "mq_getsetattr(omqstat)", ARG3, 2102 sizeof(struct vki_mq_attr) ); 2103 } 2104 } 2105 POST(sys_mq_getsetattr) 2106 { 2107 if (ARG3 != 0) 2108 POST_MEM_WRITE( ARG3, sizeof(struct vki_mq_attr) ); 2109 } 2110 2111 /* --------------------------------------------------------------------- 2112 clock_* wrappers 2113 ------------------------------------------------------------------ */ 2114 2115 PRE(sys_clock_settime) 2116 { 2117 PRINT("sys_clock_settime( %ld, %#lx )", ARG1,ARG2); 2118 PRE_REG_READ2(long, "clock_settime", 2119 vki_clockid_t, clk_id, const struct timespec *, tp); 2120 PRE_MEM_READ( "clock_settime(tp)", ARG2, sizeof(struct vki_timespec) ); 2121 } 2122 2123 PRE(sys_clock_gettime) 2124 { 2125 PRINT("sys_clock_gettime( %ld, %#lx )" , ARG1,ARG2); 2126 PRE_REG_READ2(long, "clock_gettime", 2127 vki_clockid_t, clk_id, struct timespec *, tp); 2128 PRE_MEM_WRITE( "clock_gettime(tp)", ARG2, sizeof(struct vki_timespec) ); 2129 } 2130 POST(sys_clock_gettime) 2131 { 2132 POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) ); 2133 } 2134 2135 PRE(sys_clock_getres) 2136 { 2137 PRINT("sys_clock_getres( %ld, %#lx )" , ARG1,ARG2); 2138 // Nb: we can't use "RES" as the param name because that's a macro 2139 // defined above! 2140 PRE_REG_READ2(long, "clock_getres", 2141 vki_clockid_t, clk_id, struct timespec *, res); 2142 if (ARG2 != 0) 2143 PRE_MEM_WRITE( "clock_getres(res)", ARG2, sizeof(struct vki_timespec) ); 2144 } 2145 POST(sys_clock_getres) 2146 { 2147 if (ARG2 != 0) 2148 POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) ); 2149 } 2150 2151 PRE(sys_clock_nanosleep) 2152 { 2153 *flags |= SfMayBlock|SfPostOnFail; 2154 PRINT("sys_clock_nanosleep( %ld, %ld, %#lx, %#lx )", ARG1,ARG2,ARG3,ARG4); 2155 PRE_REG_READ4(int32_t, "clock_nanosleep", 2156 vki_clockid_t, clkid, int, flags, 2157 const struct timespec *, rqtp, struct timespec *, rmtp); 2158 PRE_MEM_READ( "clock_nanosleep(rqtp)", ARG3, sizeof(struct vki_timespec) ); 2159 if (ARG4 != 0) 2160 PRE_MEM_WRITE( "clock_nanosleep(rmtp)", ARG4, sizeof(struct vki_timespec) ); 2161 } 2162 POST(sys_clock_nanosleep) 2163 { 2164 if (ARG4 != 0 && FAILURE && ERR == VKI_EINTR) 2165 POST_MEM_WRITE( ARG4, sizeof(struct vki_timespec) ); 2166 } 2167 2168 /* --------------------------------------------------------------------- 2169 timer_* wrappers 2170 ------------------------------------------------------------------ */ 2171 2172 PRE(sys_timer_create) 2173 { 2174 PRINT("sys_timer_create( %ld, %#lx, %#lx )", ARG1,ARG2,ARG3); 2175 PRE_REG_READ3(long, "timer_create", 2176 vki_clockid_t, clockid, struct sigevent *, evp, 2177 vki_timer_t *, timerid); 2178 if (ARG2 != 0) { 2179 struct vki_sigevent *evp = (struct vki_sigevent *) ARG2; 2180 PRE_MEM_READ( "timer_create(evp.sigev_value)", (Addr)&evp->sigev_value, 2181 sizeof(vki_sigval_t) ); 2182 PRE_MEM_READ( "timer_create(evp.sigev_signo)", (Addr)&evp->sigev_signo, 2183 sizeof(int) ); 2184 PRE_MEM_READ( "timer_create(evp.sigev_notify)", (Addr)&evp->sigev_notify, 2185 sizeof(int) ); 2186 if (ML_(safe_to_deref)(&evp->sigev_notify, sizeof(int)) 2187 && (evp->sigev_notify & VKI_SIGEV_THREAD_ID) != 0) 2188 PRE_MEM_READ( "timer_create(evp.sigev_notify_thread_id)", 2189 (Addr)&evp->vki_sigev_notify_thread_id, sizeof(int) ); 2190 } 2191 PRE_MEM_WRITE( "timer_create(timerid)", ARG3, sizeof(vki_timer_t) ); 2192 } 2193 POST(sys_timer_create) 2194 { 2195 POST_MEM_WRITE( ARG3, sizeof(vki_timer_t) ); 2196 } 2197 2198 PRE(sys_timer_settime) 2199 { 2200 PRINT("sys_timer_settime( %lld, %ld, %#lx, %#lx )", (ULong)ARG1,ARG2,ARG3,ARG4); 2201 PRE_REG_READ4(long, "timer_settime", 2202 vki_timer_t, timerid, int, flags, 2203 const struct itimerspec *, value, 2204 struct itimerspec *, ovalue); 2205 PRE_MEM_READ( "timer_settime(value)", ARG3, 2206 sizeof(struct vki_itimerspec) ); 2207 if (ARG4 != 0) 2208 PRE_MEM_WRITE( "timer_settime(ovalue)", ARG4, 2209 sizeof(struct vki_itimerspec) ); 2210 } 2211 POST(sys_timer_settime) 2212 { 2213 if (ARG4 != 0) 2214 POST_MEM_WRITE( ARG4, sizeof(struct vki_itimerspec) ); 2215 } 2216 2217 PRE(sys_timer_gettime) 2218 { 2219 PRINT("sys_timer_gettime( %lld, %#lx )", (ULong)ARG1,ARG2); 2220 PRE_REG_READ2(long, "timer_gettime", 2221 vki_timer_t, timerid, struct itimerspec *, value); 2222 PRE_MEM_WRITE( "timer_gettime(value)", ARG2, 2223 sizeof(struct vki_itimerspec)); 2224 } 2225 POST(sys_timer_gettime) 2226 { 2227 POST_MEM_WRITE( ARG2, sizeof(struct vki_itimerspec) ); 2228 } 2229 2230 PRE(sys_timer_getoverrun) 2231 { 2232 PRINT("sys_timer_getoverrun( %#lx )", ARG1); 2233 PRE_REG_READ1(long, "timer_getoverrun", vki_timer_t, timerid); 2234 } 2235 2236 PRE(sys_timer_delete) 2237 { 2238 PRINT("sys_timer_delete( %#lx )", ARG1); 2239 PRE_REG_READ1(long, "timer_delete", vki_timer_t, timerid); 2240 } 2241 2242 /* --------------------------------------------------------------------- 2243 timerfd* wrappers 2244 See also http://lwn.net/Articles/260172/ for an overview. 2245 See also /usr/src/linux/fs/timerfd.c for the implementation. 2246 ------------------------------------------------------------------ */ 2247 2248 /* Returns True if running on 2.6.22, else False (or False if 2249 cannot be determined). */ 2250 static Bool linux_kernel_2_6_22(void) 2251 { 2252 static Int result = -1; 2253 Int fd, read; 2254 HChar release[64]; 2255 SysRes res; 2256 2257 if (result == -1) { 2258 res = VG_(open)("/proc/sys/kernel/osrelease", 0, 0); 2259 if (sr_isError(res)) 2260 return False; 2261 fd = sr_Res(res); 2262 read = VG_(read)(fd, release, sizeof(release) - 1); 2263 vg_assert(read >= 0); 2264 release[read] = 0; 2265 VG_(close)(fd); 2266 //VG_(printf)("kernel release = %s\n", release); 2267 result = (VG_(strncmp)(release, "2.6.22", 6) == 0 2268 && (release[6] < '0' || release[6] > '9')); 2269 } 2270 vg_assert(result == 0 || result == 1); 2271 return result == 1; 2272 } 2273 2274 PRE(sys_timerfd_create) 2275 { 2276 if (linux_kernel_2_6_22()) { 2277 /* 2.6.22 kernel: timerfd system call. */ 2278 PRINT("sys_timerfd ( %ld, %ld, %#lx )", ARG1, ARG2, ARG3); 2279 PRE_REG_READ3(long, "sys_timerfd", 2280 int, fd, int, clockid, const struct itimerspec *, tmr); 2281 PRE_MEM_READ("timerfd(tmr)", ARG3, 2282 sizeof(struct vki_itimerspec) ); 2283 if ((Word)ARG1 != -1L && !ML_(fd_allowed)(ARG1, "timerfd", tid, False)) 2284 SET_STATUS_Failure( VKI_EBADF ); 2285 } else { 2286 /* 2.6.24 and later kernels: timerfd_create system call. */ 2287 PRINT("sys_timerfd_create (%ld, %ld )", ARG1, ARG2); 2288 PRE_REG_READ2(long, "timerfd_create", int, clockid, int, flags); 2289 } 2290 } 2291 POST(sys_timerfd_create) 2292 { 2293 if (linux_kernel_2_6_22()) 2294 { 2295 /* 2.6.22 kernel: timerfd system call. */ 2296 if (!ML_(fd_allowed)(RES, "timerfd", tid, True)) { 2297 VG_(close)(RES); 2298 SET_STATUS_Failure( VKI_EMFILE ); 2299 } else { 2300 if (VG_(clo_track_fds)) 2301 ML_(record_fd_open_nameless) (tid, RES); 2302 } 2303 } 2304 else 2305 { 2306 /* 2.6.24 and later kernels: timerfd_create system call. */ 2307 if (!ML_(fd_allowed)(RES, "timerfd_create", tid, True)) { 2308 VG_(close)(RES); 2309 SET_STATUS_Failure( VKI_EMFILE ); 2310 } else { 2311 if (VG_(clo_track_fds)) 2312 ML_(record_fd_open_nameless) (tid, RES); 2313 } 2314 } 2315 } 2316 2317 PRE(sys_timerfd_gettime) 2318 { 2319 PRINT("sys_timerfd_gettime ( %ld, %#lx )", ARG1, ARG2); 2320 PRE_REG_READ2(long, "timerfd_gettime", 2321 int, ufd, 2322 struct vki_itimerspec*, otmr); 2323 if (!ML_(fd_allowed)(ARG1, "timerfd_gettime", tid, False)) 2324 SET_STATUS_Failure(VKI_EBADF); 2325 else 2326 PRE_MEM_WRITE("timerfd_gettime(result)", 2327 ARG2, sizeof(struct vki_itimerspec)); 2328 } 2329 POST(sys_timerfd_gettime) 2330 { 2331 if (RES == 0) 2332 POST_MEM_WRITE(ARG2, sizeof(struct vki_itimerspec)); 2333 } 2334 2335 PRE(sys_timerfd_settime) 2336 { 2337 PRINT("sys_timerfd_settime ( %ld, %ld, %#lx, %#lx )", ARG1, ARG2, ARG3, ARG4); 2338 PRE_REG_READ4(long, "timerfd_settime", 2339 int, ufd, 2340 int, flags, 2341 const struct vki_itimerspec*, utmr, 2342 struct vki_itimerspec*, otmr); 2343 if (!ML_(fd_allowed)(ARG1, "timerfd_settime", tid, False)) 2344 SET_STATUS_Failure(VKI_EBADF); 2345 else 2346 { 2347 PRE_MEM_READ("timerfd_settime(result)", 2348 ARG3, sizeof(struct vki_itimerspec)); 2349 if (ARG4) 2350 { 2351 PRE_MEM_WRITE("timerfd_settime(result)", 2352 ARG4, sizeof(struct vki_itimerspec)); 2353 } 2354 } 2355 } 2356 POST(sys_timerfd_settime) 2357 { 2358 if (RES == 0 && ARG4 != 0) 2359 POST_MEM_WRITE(ARG4, sizeof(struct vki_itimerspec)); 2360 } 2361 2362 /* --------------------------------------------------------------------- 2363 capabilities wrappers 2364 ------------------------------------------------------------------ */ 2365 2366 PRE(sys_capget) 2367 { 2368 PRINT("sys_capget ( %#lx, %#lx )", ARG1, ARG2 ); 2369 PRE_REG_READ2(long, "capget", 2370 vki_cap_user_header_t, header, vki_cap_user_data_t, data); 2371 PRE_MEM_READ( "capget(header)", ARG1, 2372 sizeof(struct __vki_user_cap_header_struct) ); 2373 if (ARG2 != (Addr)NULL) 2374 PRE_MEM_WRITE( "capget(data)", ARG2, 2375 sizeof(struct __vki_user_cap_data_struct) ); 2376 } 2377 POST(sys_capget) 2378 { 2379 if (ARG2 != (Addr)NULL) 2380 POST_MEM_WRITE( ARG2, sizeof(struct __vki_user_cap_data_struct) ); 2381 } 2382 2383 PRE(sys_capset) 2384 { 2385 PRINT("sys_capset ( %#lx, %#lx )", ARG1, ARG2 ); 2386 PRE_REG_READ2(long, "capset", 2387 vki_cap_user_header_t, header, 2388 const vki_cap_user_data_t, data); 2389 PRE_MEM_READ( "capset(header)", 2390 ARG1, sizeof(struct __vki_user_cap_header_struct) ); 2391 PRE_MEM_READ( "capset(data)", 2392 ARG2, sizeof(struct __vki_user_cap_data_struct) ); 2393 } 2394 2395 /* --------------------------------------------------------------------- 2396 16-bit uid/gid/groups wrappers 2397 ------------------------------------------------------------------ */ 2398 2399 PRE(sys_getuid16) 2400 { 2401 PRINT("sys_getuid16 ( )"); 2402 PRE_REG_READ0(long, "getuid16"); 2403 } 2404 2405 PRE(sys_setuid16) 2406 { 2407 PRINT("sys_setuid16 ( %ld )", ARG1); 2408 PRE_REG_READ1(long, "setuid16", vki_old_uid_t, uid); 2409 } 2410 2411 PRE(sys_getgid16) 2412 { 2413 PRINT("sys_getgid16 ( )"); 2414 PRE_REG_READ0(long, "getgid16"); 2415 } 2416 2417 PRE(sys_setgid16) 2418 { 2419 PRINT("sys_setgid16 ( %ld )", ARG1); 2420 PRE_REG_READ1(long, "setgid16", vki_old_gid_t, gid); 2421 } 2422 2423 PRE(sys_geteuid16) 2424 { 2425 PRINT("sys_geteuid16 ( )"); 2426 PRE_REG_READ0(long, "geteuid16"); 2427 } 2428 2429 PRE(sys_getegid16) 2430 { 2431 PRINT("sys_getegid16 ( )"); 2432 PRE_REG_READ0(long, "getegid16"); 2433 } 2434 2435 PRE(sys_setreuid16) 2436 { 2437 PRINT("setreuid16 ( 0x%lx, 0x%lx )", ARG1, ARG2); 2438 PRE_REG_READ2(long, "setreuid16", vki_old_uid_t, ruid, vki_old_uid_t, euid); 2439 } 2440 2441 PRE(sys_setregid16) 2442 { 2443 PRINT("sys_setregid16 ( %ld, %ld )", ARG1, ARG2); 2444 PRE_REG_READ2(long, "setregid16", vki_old_gid_t, rgid, vki_old_gid_t, egid); 2445 } 2446 2447 PRE(sys_getgroups16) 2448 { 2449 PRINT("sys_getgroups16 ( %ld, %#lx )", ARG1, ARG2); 2450 PRE_REG_READ2(long, "getgroups16", int, size, vki_old_gid_t *, list); 2451 if (ARG1 > 0) 2452 PRE_MEM_WRITE( "getgroups16(list)", ARG2, ARG1 * sizeof(vki_old_gid_t) ); 2453 } 2454 POST(sys_getgroups16) 2455 { 2456 vg_assert(SUCCESS); 2457 if (ARG1 > 0 && RES > 0) 2458 POST_MEM_WRITE( ARG2, RES * sizeof(vki_old_gid_t) ); 2459 } 2460 2461 PRE(sys_setgroups16) 2462 { 2463 PRINT("sys_setgroups16 ( %llu, %#lx )", (ULong)ARG1, ARG2); 2464 PRE_REG_READ2(long, "setgroups16", int, size, vki_old_gid_t *, list); 2465 if (ARG1 > 0) 2466 PRE_MEM_READ( "setgroups16(list)", ARG2, ARG1 * sizeof(vki_old_gid_t) ); 2467 } 2468 2469 /* --------------------------------------------------------------------- 2470 *chown16 wrappers 2471 ------------------------------------------------------------------ */ 2472 2473 PRE(sys_chown16) 2474 { 2475 PRINT("sys_chown16 ( %#lx, 0x%lx, 0x%lx )", ARG1,ARG2,ARG3); 2476 PRE_REG_READ3(long, "chown16", 2477 const char *, path, 2478 vki_old_uid_t, owner, vki_old_gid_t, group); 2479 PRE_MEM_RASCIIZ( "chown16(path)", ARG1 ); 2480 } 2481 2482 PRE(sys_fchown16) 2483 { 2484 PRINT("sys_fchown16 ( %ld, %ld, %ld )", ARG1,ARG2,ARG3); 2485 PRE_REG_READ3(long, "fchown16", 2486 unsigned int, fd, vki_old_uid_t, owner, vki_old_gid_t, group); 2487 } 2488 2489 /* --------------------------------------------------------------------- 2490 *xattr wrappers 2491 ------------------------------------------------------------------ */ 2492 2493 PRE(sys_setxattr) 2494 { 2495 *flags |= SfMayBlock; 2496 PRINT("sys_setxattr ( %#lx, %#lx, %#lx, %llu, %ld )", 2497 ARG1, ARG2, ARG3, (ULong)ARG4, ARG5); 2498 PRE_REG_READ5(long, "setxattr", 2499 char *, path, char *, name, 2500 void *, value, vki_size_t, size, int, flags); 2501 PRE_MEM_RASCIIZ( "setxattr(path)", ARG1 ); 2502 PRE_MEM_RASCIIZ( "setxattr(name)", ARG2 ); 2503 PRE_MEM_READ( "setxattr(value)", ARG3, ARG4 ); 2504 } 2505 2506 PRE(sys_lsetxattr) 2507 { 2508 *flags |= SfMayBlock; 2509 PRINT("sys_lsetxattr ( %#lx, %#lx, %#lx, %llu, %ld )", 2510 ARG1, ARG2, ARG3, (ULong)ARG4, ARG5); 2511 PRE_REG_READ5(long, "lsetxattr", 2512 char *, path, char *, name, 2513 void *, value, vki_size_t, size, int, flags); 2514 PRE_MEM_RASCIIZ( "lsetxattr(path)", ARG1 ); 2515 PRE_MEM_RASCIIZ( "lsetxattr(name)", ARG2 ); 2516 PRE_MEM_READ( "lsetxattr(value)", ARG3, ARG4 ); 2517 } 2518 2519 PRE(sys_fsetxattr) 2520 { 2521 *flags |= SfMayBlock; 2522 PRINT("sys_fsetxattr ( %ld, %#lx, %#lx, %llu, %ld )", 2523 ARG1, ARG2, ARG3, (ULong)ARG4, ARG5); 2524 PRE_REG_READ5(long, "fsetxattr", 2525 int, fd, char *, name, void *, value, 2526 vki_size_t, size, int, flags); 2527 PRE_MEM_RASCIIZ( "fsetxattr(name)", ARG2 ); 2528 PRE_MEM_READ( "fsetxattr(value)", ARG3, ARG4 ); 2529 } 2530 2531 PRE(sys_getxattr) 2532 { 2533 *flags |= SfMayBlock; 2534 PRINT("sys_getxattr ( %#lx, %#lx, %#lx, %llu )", ARG1,ARG2,ARG3, (ULong)ARG4); 2535 PRE_REG_READ4(ssize_t, "getxattr", 2536 char *, path, char *, name, void *, value, vki_size_t, size); 2537 PRE_MEM_RASCIIZ( "getxattr(path)", ARG1 ); 2538 PRE_MEM_RASCIIZ( "getxattr(name)", ARG2 ); 2539 PRE_MEM_WRITE( "getxattr(value)", ARG3, ARG4 ); 2540 } 2541 POST(sys_getxattr) 2542 { 2543 vg_assert(SUCCESS); 2544 if (RES > 0 && ARG3 != (Addr)NULL) { 2545 POST_MEM_WRITE( ARG3, RES ); 2546 } 2547 } 2548 2549 PRE(sys_lgetxattr) 2550 { 2551 *flags |= SfMayBlock; 2552 PRINT("sys_lgetxattr ( %#lx, %#lx, %#lx, %llu )", ARG1,ARG2,ARG3, (ULong)ARG4); 2553 PRE_REG_READ4(ssize_t, "lgetxattr", 2554 char *, path, char *, name, void *, value, vki_size_t, size); 2555 PRE_MEM_RASCIIZ( "lgetxattr(path)", ARG1 ); 2556 PRE_MEM_RASCIIZ( "lgetxattr(name)", ARG2 ); 2557 PRE_MEM_WRITE( "lgetxattr(value)", ARG3, ARG4 ); 2558 } 2559 POST(sys_lgetxattr) 2560 { 2561 vg_assert(SUCCESS); 2562 if (RES > 0 && ARG3 != (Addr)NULL) { 2563 POST_MEM_WRITE( ARG3, RES ); 2564 } 2565 } 2566 2567 PRE(sys_fgetxattr) 2568 { 2569 *flags |= SfMayBlock; 2570 PRINT("sys_fgetxattr ( %ld, %#lx, %#lx, %llu )", ARG1, ARG2, ARG3, (ULong)ARG4); 2571 PRE_REG_READ4(ssize_t, "fgetxattr", 2572 int, fd, char *, name, void *, value, vki_size_t, size); 2573 PRE_MEM_RASCIIZ( "fgetxattr(name)", ARG2 ); 2574 PRE_MEM_WRITE( "fgetxattr(value)", ARG3, ARG4 ); 2575 } 2576 POST(sys_fgetxattr) 2577 { 2578 if (RES > 0 && ARG3 != (Addr)NULL) 2579 POST_MEM_WRITE( ARG3, RES ); 2580 } 2581 2582 PRE(sys_listxattr) 2583 { 2584 *flags |= SfMayBlock; 2585 PRINT("sys_listxattr ( %#lx, %#lx, %llu )", ARG1, ARG2, (ULong)ARG3); 2586 PRE_REG_READ3(ssize_t, "listxattr", 2587 char *, path, char *, list, vki_size_t, size); 2588 PRE_MEM_RASCIIZ( "listxattr(path)", ARG1 ); 2589 PRE_MEM_WRITE( "listxattr(list)", ARG2, ARG3 ); 2590 } 2591 POST(sys_listxattr) 2592 { 2593 if (RES > 0 && ARG2 != (Addr)NULL) 2594 POST_MEM_WRITE( ARG2, RES ); 2595 } 2596 2597 PRE(sys_llistxattr) 2598 { 2599 *flags |= SfMayBlock; 2600 PRINT("sys_llistxattr ( %#lx, %#lx, %llu )", ARG1, ARG2, (ULong)ARG3); 2601 PRE_REG_READ3(ssize_t, "llistxattr", 2602 char *, path, char *, list, vki_size_t, size); 2603 PRE_MEM_RASCIIZ( "llistxattr(path)", ARG1 ); 2604 PRE_MEM_WRITE( "llistxattr(list)", ARG2, ARG3 ); 2605 } 2606 POST(sys_llistxattr) 2607 { 2608 if (RES > 0 && ARG2 != (Addr)NULL) 2609 POST_MEM_WRITE( ARG2, RES ); 2610 } 2611 2612 PRE(sys_flistxattr) 2613 { 2614 *flags |= SfMayBlock; 2615 PRINT("sys_flistxattr ( %ld, %#lx, %llu )", ARG1, ARG2, (ULong)ARG3); 2616 PRE_REG_READ3(ssize_t, "flistxattr", 2617 int, fd, char *, list, vki_size_t, size); 2618 PRE_MEM_WRITE( "flistxattr(list)", ARG2, ARG3 ); 2619 } 2620 POST(sys_flistxattr) 2621 { 2622 if (RES > 0 && ARG2 != (Addr)NULL) 2623 POST_MEM_WRITE( ARG2, RES ); 2624 } 2625 2626 PRE(sys_removexattr) 2627 { 2628 *flags |= SfMayBlock; 2629 PRINT("sys_removexattr ( %#lx, %#lx )", ARG1, ARG2); 2630 PRE_REG_READ2(long, "removexattr", char *, path, char *, name); 2631 PRE_MEM_RASCIIZ( "removexattr(path)", ARG1 ); 2632 PRE_MEM_RASCIIZ( "removexattr(name)", ARG2 ); 2633 } 2634 2635 PRE(sys_lremovexattr) 2636 { 2637 *flags |= SfMayBlock; 2638 PRINT("sys_lremovexattr ( %#lx, %#lx )", ARG1, ARG2); 2639 PRE_REG_READ2(long, "lremovexattr", char *, path, char *, name); 2640 PRE_MEM_RASCIIZ( "lremovexattr(path)", ARG1 ); 2641 PRE_MEM_RASCIIZ( "lremovexattr(name)", ARG2 ); 2642 } 2643 2644 PRE(sys_fremovexattr) 2645 { 2646 *flags |= SfMayBlock; 2647 PRINT("sys_fremovexattr ( %ld, %#lx )", ARG1, ARG2); 2648 PRE_REG_READ2(long, "fremovexattr", int, fd, char *, name); 2649 PRE_MEM_RASCIIZ( "fremovexattr(name)", ARG2 ); 2650 } 2651 2652 /* --------------------------------------------------------------------- 2653 sched_* wrappers 2654 ------------------------------------------------------------------ */ 2655 2656 PRE(sys_sched_setparam) 2657 { 2658 PRINT("sched_setparam ( %ld, %#lx )", ARG1, ARG2 ); 2659 PRE_REG_READ2(long, "sched_setparam", 2660 vki_pid_t, pid, struct sched_param *, p); 2661 PRE_MEM_READ( "sched_setparam(p)", ARG2, sizeof(struct vki_sched_param) ); 2662 } 2663 POST(sys_sched_setparam) 2664 { 2665 POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) ); 2666 } 2667 2668 PRE(sys_sched_getparam) 2669 { 2670 PRINT("sched_getparam ( %ld, %#lx )", ARG1, ARG2 ); 2671 PRE_REG_READ2(long, "sched_getparam", 2672 vki_pid_t, pid, struct sched_param *, p); 2673 PRE_MEM_WRITE( "sched_getparam(p)", ARG2, sizeof(struct vki_sched_param) ); 2674 } 2675 POST(sys_sched_getparam) 2676 { 2677 POST_MEM_WRITE( ARG2, sizeof(struct vki_sched_param) ); 2678 } 2679 2680 PRE(sys_sched_getscheduler) 2681 { 2682 PRINT("sys_sched_getscheduler ( %ld )", ARG1); 2683 PRE_REG_READ1(long, "sched_getscheduler", vki_pid_t, pid); 2684 } 2685 2686 PRE(sys_sched_setscheduler) 2687 { 2688 PRINT("sys_sched_setscheduler ( %ld, %ld, %#lx )", ARG1,ARG2,ARG3); 2689 PRE_REG_READ3(long, "sched_setscheduler", 2690 vki_pid_t, pid, int, policy, struct sched_param *, p); 2691 if (ARG3 != 0) 2692 PRE_MEM_READ( "sched_setscheduler(p)", 2693 ARG3, sizeof(struct vki_sched_param)); 2694 } 2695 2696 PRE(sys_sched_yield) 2697 { 2698 *flags |= SfMayBlock; 2699 PRINT("sched_yield()"); 2700 PRE_REG_READ0(long, "sys_sched_yield"); 2701 } 2702 2703 PRE(sys_sched_get_priority_max) 2704 { 2705 PRINT("sched_get_priority_max ( %ld )", ARG1); 2706 PRE_REG_READ1(long, "sched_get_priority_max", int, policy); 2707 } 2708 2709 PRE(sys_sched_get_priority_min) 2710 { 2711 PRINT("sched_get_priority_min ( %ld )", ARG1); 2712 PRE_REG_READ1(long, "sched_get_priority_min", int, policy); 2713 } 2714 2715 PRE(sys_sched_rr_get_interval) 2716 { 2717 PRINT("sys_sched_rr_get_interval ( %ld, %#lx )", ARG1, ARG2); 2718 PRE_REG_READ2(int, "sched_rr_get_interval", 2719 vki_pid_t, pid, 2720 struct vki_timespec *, tp); 2721 PRE_MEM_WRITE("sched_rr_get_interval(timespec)", 2722 ARG2, sizeof(struct vki_timespec)); 2723 } 2724 2725 POST(sys_sched_rr_get_interval) 2726 { 2727 POST_MEM_WRITE(ARG2, sizeof(struct vki_timespec)); 2728 } 2729 2730 PRE(sys_sched_setaffinity) 2731 { 2732 PRINT("sched_setaffinity ( %ld, %ld, %#lx )", ARG1, ARG2, ARG3); 2733 PRE_REG_READ3(long, "sched_setaffinity", 2734 vki_pid_t, pid, unsigned int, len, unsigned long *, mask); 2735 PRE_MEM_READ( "sched_setaffinity(mask)", ARG3, ARG2); 2736 } 2737 2738 PRE(sys_sched_getaffinity) 2739 { 2740 PRINT("sched_getaffinity ( %ld, %ld, %#lx )", ARG1, ARG2, ARG3); 2741 PRE_REG_READ3(long, "sched_getaffinity", 2742 vki_pid_t, pid, unsigned int, len, unsigned long *, mask); 2743 PRE_MEM_WRITE( "sched_getaffinity(mask)", ARG3, ARG2); 2744 } 2745 POST(sys_sched_getaffinity) 2746 { 2747 POST_MEM_WRITE(ARG3, ARG2); 2748 } 2749 2750 /* --------------------------------------------------------------------- 2751 miscellaneous wrappers 2752 ------------------------------------------------------------------ */ 2753 2754 PRE(sys_munlockall) 2755 { 2756 *flags |= SfMayBlock; 2757 PRINT("sys_munlockall ( )"); 2758 PRE_REG_READ0(long, "munlockall"); 2759 } 2760 2761 // This has different signatures for different platforms. 2762 // 2763 // x86: int sys_pipe(unsigned long __user *fildes); 2764 // AMD64: long sys_pipe(int *fildes); 2765 // ppc32: int sys_pipe(int __user *fildes); 2766 // ppc64: int sys_pipe(int __user *fildes); 2767 // 2768 // The type of the argument is most important, and it is an array of 32 bit 2769 // values in all cases. (The return type differs across platforms, but it 2770 // is not used.) So we use 'int' as its type. This fixed bug #113230 which 2771 // was caused by using an array of 'unsigned long's, which didn't work on 2772 // AMD64. 2773 PRE(sys_pipe) 2774 { 2775 PRINT("sys_pipe ( %#lx )", ARG1); 2776 PRE_REG_READ1(int, "pipe", int *, filedes); 2777 PRE_MEM_WRITE( "pipe(filedes)", ARG1, 2*sizeof(int) ); 2778 } 2779 POST(sys_pipe) 2780 { 2781 Int *p = (Int *)ARG1; 2782 if (!ML_(fd_allowed)(p[0], "pipe", tid, True) || 2783 !ML_(fd_allowed)(p[1], "pipe", tid, True)) { 2784 VG_(close)(p[0]); 2785 VG_(close)(p[1]); 2786 SET_STATUS_Failure( VKI_EMFILE ); 2787 } else { 2788 POST_MEM_WRITE( ARG1, 2*sizeof(int) ); 2789 if (VG_(clo_track_fds)) { 2790 ML_(record_fd_open_nameless)(tid, p[0]); 2791 ML_(record_fd_open_nameless)(tid, p[1]); 2792 } 2793 } 2794 } 2795 2796 /* pipe2 (a kernel 2.6.twentysomething invention) is like pipe, except 2797 there's a second arg containing flags to be applied to the new file 2798 descriptors. It hardly seems worth the effort to factor out the 2799 duplicated code, hence: */ 2800 PRE(sys_pipe2) 2801 { 2802 PRINT("sys_pipe2 ( %#lx, %#lx )", ARG1, ARG2); 2803 PRE_REG_READ2(int, "pipe", int *, filedes, long, flags); 2804 PRE_MEM_WRITE( "pipe2(filedes)", ARG1, 2*sizeof(int) ); 2805 } 2806 POST(sys_pipe2) 2807 { 2808 Int *p = (Int *)ARG1; 2809 if (!ML_(fd_allowed)(p[0], "pipe2", tid, True) || 2810 !ML_(fd_allowed)(p[1], "pipe2", tid, True)) { 2811 VG_(close)(p[0]); 2812 VG_(close)(p[1]); 2813 SET_STATUS_Failure( VKI_EMFILE ); 2814 } else { 2815 POST_MEM_WRITE( ARG1, 2*sizeof(int) ); 2816 if (VG_(clo_track_fds)) { 2817 ML_(record_fd_open_nameless)(tid, p[0]); 2818 ML_(record_fd_open_nameless)(tid, p[1]); 2819 } 2820 } 2821 } 2822 2823 PRE(sys_dup3) 2824 { 2825 PRINT("sys_dup3 ( %ld, %ld, %ld )", ARG1,ARG2,ARG3); 2826 PRE_REG_READ3(long, "dup3", unsigned int, oldfd, unsigned int, newfd, int, flags); 2827 if (!ML_(fd_allowed)(ARG2, "dup3", tid, True)) 2828 SET_STATUS_Failure( VKI_EBADF ); 2829 } 2830 2831 POST(sys_dup3) 2832 { 2833 vg_assert(SUCCESS); 2834 if (VG_(clo_track_fds)) 2835 ML_(record_fd_open_named)(tid, RES); 2836 } 2837 2838 PRE(sys_quotactl) 2839 { 2840 PRINT("sys_quotactl (0x%lx, %#lx, 0x%lx, 0x%lx )", ARG1,ARG2,ARG3, ARG4); 2841 PRE_REG_READ4(long, "quotactl", 2842 unsigned int, cmd, const char *, special, vki_qid_t, id, 2843 void *, addr); 2844 PRE_MEM_RASCIIZ( "quotactl(special)", ARG2 ); 2845 } 2846 2847 PRE(sys_waitid) 2848 { 2849 *flags |= SfMayBlock; 2850 PRINT("sys_waitid( %ld, %ld, %#lx, %ld, %#lx )", ARG1,ARG2,ARG3,ARG4,ARG5); 2851 PRE_REG_READ5(int32_t, "sys_waitid", 2852 int, which, vki_pid_t, pid, struct vki_siginfo *, infop, 2853 int, options, struct vki_rusage *, ru); 2854 PRE_MEM_WRITE( "waitid(infop)", ARG3, sizeof(struct vki_siginfo) ); 2855 if (ARG5 != 0) 2856 PRE_MEM_WRITE( "waitid(ru)", ARG5, sizeof(struct vki_rusage) ); 2857 } 2858 POST(sys_waitid) 2859 { 2860 POST_MEM_WRITE( ARG3, sizeof(struct vki_siginfo) ); 2861 if (ARG5 != 0) 2862 POST_MEM_WRITE( ARG5, sizeof(struct vki_rusage) ); 2863 } 2864 2865 PRE(sys_sync_file_range) 2866 { 2867 *flags |= SfMayBlock; 2868 #if VG_WORDSIZE == 4 2869 PRINT("sys_sync_file_range ( %ld, %lld, %lld, %ld )", 2870 ARG1,MERGE64(ARG2,ARG3),MERGE64(ARG4,ARG5),ARG6); 2871 PRE_REG_READ6(long, "sync_file_range", 2872 int, fd, 2873 unsigned, MERGE64_FIRST(offset), unsigned, MERGE64_SECOND(offset), 2874 unsigned, MERGE64_FIRST(nbytes), unsigned, MERGE64_SECOND(nbytes), 2875 unsigned int, flags); 2876 #elif VG_WORDSIZE == 8 2877 PRINT("sys_sync_file_range ( %ld, %lld, %lld, %ld )", 2878 ARG1,(Long)ARG2,(Long)ARG3,ARG4); 2879 PRE_REG_READ4(long, "sync_file_range", 2880 int, fd, vki_loff_t, offset, vki_loff_t, nbytes, 2881 unsigned int, flags); 2882 #else 2883 # error Unexpected word size 2884 #endif 2885 if (!ML_(fd_allowed)(ARG1, "sync_file_range", tid, False)) 2886 SET_STATUS_Failure( VKI_EBADF ); 2887 } 2888 2889 PRE(sys_sync_file_range2) 2890 { 2891 *flags |= SfMayBlock; 2892 #if VG_WORDSIZE == 4 2893 PRINT("sys_sync_file_range2 ( %ld, %ld, %lld, %lld )", 2894 ARG1,ARG2,MERGE64(ARG3,ARG4),MERGE64(ARG5,ARG6)); 2895 PRE_REG_READ6(long, "sync_file_range2", 2896 int, fd, unsigned int, flags, 2897 unsigned, MERGE64_FIRST(offset), unsigned, MERGE64_SECOND(offset), 2898 unsigned, MERGE64_FIRST(nbytes), unsigned, MERGE64_SECOND(nbytes)); 2899 #elif VG_WORDSIZE == 8 2900 PRINT("sys_sync_file_range2 ( %ld, %ld, %lld, %lld )", 2901 ARG1,ARG2,(Long)ARG3,(Long)ARG4); 2902 PRE_REG_READ4(long, "sync_file_range2", 2903 int, fd, unsigned int, flags, 2904 vki_loff_t, offset, vki_loff_t, nbytes); 2905 #else 2906 # error Unexpected word size 2907 #endif 2908 if (!ML_(fd_allowed)(ARG1, "sync_file_range2", tid, False)) 2909 SET_STATUS_Failure( VKI_EBADF ); 2910 } 2911 2912 PRE(sys_stime) 2913 { 2914 PRINT("sys_stime ( %#lx )", ARG1); 2915 PRE_REG_READ1(int, "stime", vki_time_t*, t); 2916 PRE_MEM_READ( "stime(t)", ARG1, sizeof(vki_time_t) ); 2917 } 2918 2919 PRE(sys_perf_event_open) 2920 { 2921 struct vki_perf_event_attr *attr; 2922 PRINT("sys_perf_event_open ( %#lx, %ld, %ld, %ld, %ld )", 2923 ARG1,ARG2,ARG3,ARG4,ARG5); 2924 PRE_REG_READ5(long, "perf_event_open", 2925 struct vki_perf_event_attr *, attr, 2926 vki_pid_t, pid, int, cpu, int, group_fd, 2927 unsigned long, flags); 2928 attr = (struct vki_perf_event_attr *)ARG1; 2929 PRE_MEM_READ( "perf_event_open(attr->size)", 2930 (Addr)&attr->size, sizeof(attr->size) ); 2931 PRE_MEM_READ( "perf_event_open(attr)", 2932 (Addr)attr, attr->size ); 2933 } 2934 2935 POST(sys_perf_event_open) 2936 { 2937 vg_assert(SUCCESS); 2938 if (!ML_(fd_allowed)(RES, "perf_event_open", tid, True)) { 2939 VG_(close)(RES); 2940 SET_STATUS_Failure( VKI_EMFILE ); 2941 } else { 2942 if (VG_(clo_track_fds)) 2943 ML_(record_fd_open_nameless)(tid, RES); 2944 } 2945 } 2946 2947 PRE(sys_getcpu) 2948 { 2949 PRINT("sys_getcpu ( %#lx, %#lx, %#lx )" , ARG1,ARG2,ARG3); 2950 PRE_REG_READ3(int, "getcpu", 2951 unsigned *, cpu, unsigned *, node, struct vki_getcpu_cache *, tcache); 2952 if (ARG1 != 0) 2953 PRE_MEM_WRITE( "getcpu(cpu)", ARG1, sizeof(unsigned) ); 2954 if (ARG2 != 0) 2955 PRE_MEM_WRITE( "getcpu(node)", ARG2, sizeof(unsigned) ); 2956 if (ARG3 != 0) 2957 PRE_MEM_WRITE( "getcpu(tcache)", ARG3, sizeof(struct vki_getcpu_cache) ); 2958 } 2959 2960 POST(sys_getcpu) 2961 { 2962 if (ARG1 != 0) 2963 POST_MEM_WRITE( ARG1, sizeof(unsigned) ); 2964 if (ARG2 != 0) 2965 POST_MEM_WRITE( ARG2, sizeof(unsigned) ); 2966 if (ARG3 != 0) 2967 POST_MEM_WRITE( ARG3, sizeof(struct vki_getcpu_cache) ); 2968 } 2969 2970 PRE(sys_move_pages) 2971 { 2972 PRINT("sys_move_pages ( %ld, %ld, %#lx, %#lx, %#lx, %lx )", 2973 ARG1,ARG2,ARG3,ARG4,ARG5,ARG6); 2974 PRE_REG_READ6(int, "move_pages", 2975 vki_pid_t, pid, unsigned long, nr_pages, const void **, pages, 2976 const int *, nodes, int *, status, int, flags); 2977 PRE_MEM_READ("move_pages(pages)", ARG3, ARG2 * sizeof(void *)); 2978 if (ARG4) 2979 PRE_MEM_READ("move_pages(nodes)", ARG4, ARG2 * sizeof(int)); 2980 PRE_MEM_WRITE("move_pages(status)", ARG5, ARG2 * sizeof(int)); 2981 } 2982 2983 POST(sys_move_pages) 2984 { 2985 POST_MEM_WRITE(ARG5, ARG2 * sizeof(int)); 2986 } 2987 2988 /* --------------------------------------------------------------------- 2989 utime wrapper 2990 ------------------------------------------------------------------ */ 2991 2992 PRE(sys_utime) 2993 { 2994 *flags |= SfMayBlock; 2995 PRINT("sys_utime ( %#lx, %#lx )", ARG1,ARG2); 2996 PRE_REG_READ2(long, "utime", char *, filename, struct utimbuf *, buf); 2997 PRE_MEM_RASCIIZ( "utime(filename)", ARG1 ); 2998 if (ARG2 != 0) 2999 PRE_MEM_READ( "utime(buf)", ARG2, sizeof(struct vki_utimbuf) ); 3000 } 3001 3002 /* --------------------------------------------------------------------- 3003 lseek wrapper 3004 ------------------------------------------------------------------ */ 3005 3006 PRE(sys_lseek) 3007 { 3008 PRINT("sys_lseek ( %ld, %ld, %ld )", ARG1,ARG2,ARG3); 3009 PRE_REG_READ3(vki_off_t, "lseek", 3010 unsigned int, fd, vki_off_t, offset, unsigned int, whence); 3011 } 3012 3013 /* --------------------------------------------------------------------- 3014 readahead wrapper 3015 ------------------------------------------------------------------ */ 3016 3017 PRE(sys_readahead) 3018 { 3019 *flags |= SfMayBlock; 3020 #if VG_WORDSIZE == 4 3021 PRINT("sys_readahead ( %ld, %lld, %ld )", ARG1, MERGE64(ARG2,ARG3), ARG4); 3022 PRE_REG_READ4(vki_off_t, "readahead", 3023 int, fd, unsigned, MERGE64_FIRST(offset), 3024 unsigned, MERGE64_SECOND(offset), vki_size_t, count); 3025 #elif VG_WORDSIZE == 8 3026 PRINT("sys_readahead ( %ld, %lld, %ld )", ARG1, (Long)ARG2, ARG3); 3027 PRE_REG_READ3(vki_off_t, "readahead", 3028 int, fd, vki_loff_t, offset, vki_size_t, count); 3029 #else 3030 # error Unexpected word size 3031 #endif 3032 if (!ML_(fd_allowed)(ARG1, "readahead", tid, False)) 3033 SET_STATUS_Failure( VKI_EBADF ); 3034 } 3035 3036 /* --------------------------------------------------------------------- 3037 sig* wrappers 3038 ------------------------------------------------------------------ */ 3039 3040 PRE(sys_sigpending) 3041 { 3042 PRINT( "sys_sigpending ( %#lx )", ARG1 ); 3043 PRE_REG_READ1(long, "sigpending", vki_old_sigset_t *, set); 3044 PRE_MEM_WRITE( "sigpending(set)", ARG1, sizeof(vki_old_sigset_t)); 3045 } 3046 POST(sys_sigpending) 3047 { 3048 POST_MEM_WRITE( ARG1, sizeof(vki_old_sigset_t) ) ; 3049 } 3050 3051 // This syscall is not used on amd64/Linux -- it only provides 3052 // sys_rt_sigprocmask, which uses sigset_t rather than old_sigset_t. 3053 // This wrapper is only suitable for 32-bit architectures. 3054 // (XXX: so how is it that PRE(sys_sigpending) above doesn't need 3055 // conditional compilation like this?) 3056 #if defined(VGP_x86_linux) || defined(VGP_ppc32_linux) \ 3057 || defined(VGP_arm_linux) || defined(VGP_mips32_linux) 3058 PRE(sys_sigprocmask) 3059 { 3060 vki_old_sigset_t* set; 3061 vki_old_sigset_t* oldset; 3062 vki_sigset_t bigger_set; 3063 vki_sigset_t bigger_oldset; 3064 3065 PRINT("sys_sigprocmask ( %ld, %#lx, %#lx )",ARG1,ARG2,ARG3); 3066 PRE_REG_READ3(long, "sigprocmask", 3067 int, how, vki_old_sigset_t *, set, vki_old_sigset_t *, oldset); 3068 if (ARG2 != 0) 3069 PRE_MEM_READ( "sigprocmask(set)", ARG2, sizeof(vki_old_sigset_t)); 3070 if (ARG3 != 0) 3071 PRE_MEM_WRITE( "sigprocmask(oldset)", ARG3, sizeof(vki_old_sigset_t)); 3072 3073 // Nb: We must convert the smaller vki_old_sigset_t params into bigger 3074 // vki_sigset_t params. 3075 set = (vki_old_sigset_t*)ARG2; 3076 oldset = (vki_old_sigset_t*)ARG3; 3077 3078 VG_(memset)(&bigger_set, 0, sizeof(vki_sigset_t)); 3079 VG_(memset)(&bigger_oldset, 0, sizeof(vki_sigset_t)); 3080 if (set) 3081 bigger_set.sig[0] = *(vki_old_sigset_t*)set; 3082 3083 SET_STATUS_from_SysRes( 3084 VG_(do_sys_sigprocmask) ( tid, ARG1 /*how*/, 3085 set ? &bigger_set : NULL, 3086 oldset ? &bigger_oldset : NULL) 3087 ); 3088 3089 if (oldset) 3090 *oldset = bigger_oldset.sig[0]; 3091 3092 if (SUCCESS) 3093 *flags |= SfPollAfter; 3094 } 3095 POST(sys_sigprocmask) 3096 { 3097 vg_assert(SUCCESS); 3098 if (RES == 0 && ARG3 != 0) 3099 POST_MEM_WRITE( ARG3, sizeof(vki_old_sigset_t)); 3100 } 3101 3102 /* Convert from non-RT to RT sigset_t's */ 3103 static 3104 void convert_sigset_to_rt(const vki_old_sigset_t *oldset, vki_sigset_t *set) 3105 { 3106 VG_(sigemptyset)(set); 3107 set->sig[0] = *oldset; 3108 } 3109 PRE(sys_sigaction) 3110 { 3111 vki_sigaction_toK_t new, *newp; 3112 vki_sigaction_fromK_t old, *oldp; 3113 3114 PRINT("sys_sigaction ( %ld, %#lx, %#lx )", ARG1,ARG2,ARG3); 3115 PRE_REG_READ3(int, "sigaction", 3116 int, signum, const struct old_sigaction *, act, 3117 struct old_sigaction *, oldact); 3118 3119 newp = oldp = NULL; 3120 3121 if (ARG2 != 0) { 3122 struct vki_old_sigaction *sa = (struct vki_old_sigaction *)ARG2; 3123 PRE_MEM_READ( "sigaction(act->sa_handler)", (Addr)&sa->ksa_handler, sizeof(sa->ksa_handler)); 3124 PRE_MEM_READ( "sigaction(act->sa_mask)", (Addr)&sa->sa_mask, sizeof(sa->sa_mask)); 3125 PRE_MEM_READ( "sigaction(act->sa_flags)", (Addr)&sa->sa_flags, sizeof(sa->sa_flags)); 3126 if (ML_(safe_to_deref)(sa,sizeof(sa)) 3127 && (sa->sa_flags & VKI_SA_RESTORER)) 3128 PRE_MEM_READ( "sigaction(act->sa_restorer)", (Addr)&sa->sa_restorer, sizeof(sa->sa_restorer)); 3129 } 3130 3131 if (ARG3 != 0) { 3132 PRE_MEM_WRITE( "sigaction(oldact)", ARG3, sizeof(struct vki_old_sigaction)); 3133 oldp = &old; 3134 } 3135 3136 if (ARG2 != 0) { 3137 struct vki_old_sigaction *oldnew = (struct vki_old_sigaction *)ARG2; 3138 3139 new.ksa_handler = oldnew->ksa_handler; 3140 new.sa_flags = oldnew->sa_flags; 3141 new.sa_restorer = oldnew->sa_restorer; 3142 convert_sigset_to_rt(&oldnew->sa_mask, &new.sa_mask); 3143 newp = &new; 3144 } 3145 3146 SET_STATUS_from_SysRes( VG_(do_sys_sigaction)(ARG1, newp, oldp) ); 3147 3148 if (ARG3 != 0 && SUCCESS && RES == 0) { 3149 struct vki_old_sigaction *oldold = (struct vki_old_sigaction *)ARG3; 3150 3151 oldold->ksa_handler = oldp->ksa_handler; 3152 oldold->sa_flags = oldp->sa_flags; 3153 oldold->sa_restorer = oldp->sa_restorer; 3154 oldold->sa_mask = oldp->sa_mask.sig[0]; 3155 } 3156 } 3157 POST(sys_sigaction) 3158 { 3159 vg_assert(SUCCESS); 3160 if (RES == 0 && ARG3 != 0) 3161 POST_MEM_WRITE( ARG3, sizeof(struct vki_old_sigaction)); 3162 } 3163 #endif 3164 3165 PRE(sys_signalfd) 3166 { 3167 PRINT("sys_signalfd ( %d, %#lx, %llu )", (Int)ARG1,ARG2,(ULong)ARG3); 3168 PRE_REG_READ3(long, "sys_signalfd", 3169 int, fd, vki_sigset_t *, sigmask, vki_size_t, sigsetsize); 3170 PRE_MEM_READ( "signalfd(sigmask)", ARG2, sizeof(vki_sigset_t) ); 3171 if ((int)ARG1 != -1 && !ML_(fd_allowed)(ARG1, "signalfd", tid, False)) 3172 SET_STATUS_Failure( VKI_EBADF ); 3173 } 3174 POST(sys_signalfd) 3175 { 3176 if (!ML_(fd_allowed)(RES, "signalfd", tid, True)) { 3177 VG_(close)(RES); 3178 SET_STATUS_Failure( VKI_EMFILE ); 3179 } else { 3180 if (VG_(clo_track_fds)) 3181 ML_(record_fd_open_nameless) (tid, RES); 3182 } 3183 } 3184 3185 PRE(sys_signalfd4) 3186 { 3187 PRINT("sys_signalfd4 ( %d, %#lx, %llu, %ld )", (Int)ARG1,ARG2,(ULong)ARG3,ARG4); 3188 PRE_REG_READ4(long, "sys_signalfd4", 3189 int, fd, vki_sigset_t *, sigmask, vki_size_t, sigsetsize, int, flags); 3190 PRE_MEM_READ( "signalfd(sigmask)", ARG2, sizeof(vki_sigset_t) ); 3191 if ((int)ARG1 != -1 && !ML_(fd_allowed)(ARG1, "signalfd", tid, False)) 3192 SET_STATUS_Failure( VKI_EBADF ); 3193 } 3194 POST(sys_signalfd4) 3195 { 3196 if (!ML_(fd_allowed)(RES, "signalfd4", tid, True)) { 3197 VG_(close)(RES); 3198 SET_STATUS_Failure( VKI_EMFILE ); 3199 } else { 3200 if (VG_(clo_track_fds)) 3201 ML_(record_fd_open_nameless) (tid, RES); 3202 } 3203 } 3204 3205 3206 /* --------------------------------------------------------------------- 3207 rt_sig* wrappers 3208 ------------------------------------------------------------------ */ 3209 3210 PRE(sys_rt_sigaction) 3211 { 3212 PRINT("sys_rt_sigaction ( %ld, %#lx, %#lx, %ld )", ARG1,ARG2,ARG3,ARG4); 3213 PRE_REG_READ4(long, "rt_sigaction", 3214 int, signum, const struct sigaction *, act, 3215 struct sigaction *, oldact, vki_size_t, sigsetsize); 3216 3217 if (ARG2 != 0) { 3218 vki_sigaction_toK_t *sa = (vki_sigaction_toK_t *)ARG2; 3219 PRE_MEM_READ( "rt_sigaction(act->sa_handler)", (Addr)&sa->ksa_handler, sizeof(sa->ksa_handler)); 3220 PRE_MEM_READ( "rt_sigaction(act->sa_mask)", (Addr)&sa->sa_mask, sizeof(sa->sa_mask)); 3221 PRE_MEM_READ( "rt_sigaction(act->sa_flags)", (Addr)&sa->sa_flags, sizeof(sa->sa_flags)); 3222 if (sa->sa_flags & VKI_SA_RESTORER) 3223 PRE_MEM_READ( "rt_sigaction(act->sa_restorer)", (Addr)&sa->sa_restorer, sizeof(sa->sa_restorer)); 3224 } 3225 if (ARG3 != 0) 3226 PRE_MEM_WRITE( "rt_sigaction(oldact)", ARG3, sizeof(vki_sigaction_fromK_t)); 3227 3228 // XXX: doesn't seem right to be calling do_sys_sigaction for 3229 // sys_rt_sigaction... perhaps this function should be renamed 3230 // VG_(do_sys_rt_sigaction)() --njn 3231 3232 SET_STATUS_from_SysRes( 3233 VG_(do_sys_sigaction)(ARG1, (const vki_sigaction_toK_t *)ARG2, 3234 (vki_sigaction_fromK_t *)ARG3) 3235 ); 3236 } 3237 POST(sys_rt_sigaction) 3238 { 3239 vg_assert(SUCCESS); 3240 if (RES == 0 && ARG3 != 0) 3241 POST_MEM_WRITE( ARG3, sizeof(vki_sigaction_fromK_t)); 3242 } 3243 3244 PRE(sys_rt_sigprocmask) 3245 { 3246 PRINT("sys_rt_sigprocmask ( %ld, %#lx, %#lx, %llu )",ARG1,ARG2,ARG3,(ULong)ARG4); 3247 PRE_REG_READ4(long, "rt_sigprocmask", 3248 int, how, vki_sigset_t *, set, vki_sigset_t *, oldset, 3249 vki_size_t, sigsetsize); 3250 if (ARG2 != 0) 3251 PRE_MEM_READ( "rt_sigprocmask(set)", ARG2, sizeof(vki_sigset_t)); 3252 if (ARG3 != 0) 3253 PRE_MEM_WRITE( "rt_sigprocmask(oldset)", ARG3, sizeof(vki_sigset_t)); 3254 3255 // Like the kernel, we fail if the sigsetsize is not exactly what we expect. 3256 if (sizeof(vki_sigset_t) != ARG4) 3257 SET_STATUS_Failure( VKI_EMFILE ); 3258 else { 3259 SET_STATUS_from_SysRes( 3260 VG_(do_sys_sigprocmask) ( tid, ARG1 /*how*/, 3261 (vki_sigset_t*) ARG2, 3262 (vki_sigset_t*) ARG3 ) 3263 ); 3264 } 3265 3266 if (SUCCESS) 3267 *flags |= SfPollAfter; 3268 } 3269 POST(sys_rt_sigprocmask) 3270 { 3271 vg_assert(SUCCESS); 3272 if (RES == 0 && ARG3 != 0) 3273 POST_MEM_WRITE( ARG3, sizeof(vki_sigset_t)); 3274 } 3275 3276 PRE(sys_rt_sigpending) 3277 { 3278 PRINT( "sys_rt_sigpending ( %#lx )", ARG1 ); 3279 PRE_REG_READ2(long, "rt_sigpending", 3280 vki_sigset_t *, set, vki_size_t, sigsetsize); 3281 PRE_MEM_WRITE( "rt_sigpending(set)", ARG1, sizeof(vki_sigset_t)); 3282 } 3283 POST(sys_rt_sigpending) 3284 { 3285 POST_MEM_WRITE( ARG1, sizeof(vki_sigset_t) ) ; 3286 } 3287 3288 PRE(sys_rt_sigtimedwait) 3289 { 3290 *flags |= SfMayBlock; 3291 PRINT("sys_rt_sigtimedwait ( %#lx, %#lx, %#lx, %lld )", 3292 ARG1,ARG2,ARG3,(ULong)ARG4); 3293 PRE_REG_READ4(long, "rt_sigtimedwait", 3294 const vki_sigset_t *, set, vki_siginfo_t *, info, 3295 const struct timespec *, timeout, vki_size_t, sigsetsize); 3296 if (ARG1 != 0) 3297 PRE_MEM_READ( "rt_sigtimedwait(set)", ARG1, sizeof(vki_sigset_t)); 3298 if (ARG2 != 0) 3299 PRE_MEM_WRITE( "rt_sigtimedwait(info)", ARG2, sizeof(vki_siginfo_t) ); 3300 if (ARG3 != 0) 3301 PRE_MEM_READ( "rt_sigtimedwait(timeout)", 3302 ARG3, sizeof(struct vki_timespec) ); 3303 } 3304 POST(sys_rt_sigtimedwait) 3305 { 3306 if (ARG2 != 0) 3307 POST_MEM_WRITE( ARG2, sizeof(vki_siginfo_t) ); 3308 } 3309 3310 PRE(sys_rt_sigqueueinfo) 3311 { 3312 PRINT("sys_rt_sigqueueinfo(%ld, %ld, %#lx)", ARG1, ARG2, ARG3); 3313 PRE_REG_READ3(long, "rt_sigqueueinfo", 3314 int, pid, int, sig, vki_siginfo_t *, uinfo); 3315 if (ARG2 != 0) 3316 PRE_MEM_READ( "rt_sigqueueinfo(uinfo)", ARG3, VKI_SI_MAX_SIZE ); 3317 } 3318 POST(sys_rt_sigqueueinfo) 3319 { 3320 if (!ML_(client_signal_OK)(ARG2)) 3321 SET_STATUS_Failure( VKI_EINVAL ); 3322 } 3323 3324 PRE(sys_rt_tgsigqueueinfo) 3325 { 3326 PRINT("sys_rt_tgsigqueueinfo(%ld, %ld, %ld, %#lx)", ARG1, ARG2, ARG3, ARG4); 3327 PRE_REG_READ4(long, "rt_tgsigqueueinfo", 3328 int, tgid, int, pid, int, sig, vki_siginfo_t *, uinfo); 3329 if (ARG3 != 0) 3330 PRE_MEM_READ( "rt_tgsigqueueinfo(uinfo)", ARG4, VKI_SI_MAX_SIZE ); 3331 } 3332 3333 POST(sys_rt_tgsigqueueinfo) 3334 { 3335 if (!ML_(client_signal_OK)(ARG3)) 3336 SET_STATUS_Failure( VKI_EINVAL ); 3337 } 3338 3339 // XXX: x86-specific? The kernel prototypes for the different archs are 3340 // hard to decipher. 3341 PRE(sys_rt_sigsuspend) 3342 { 3343 /* The C library interface to sigsuspend just takes a pointer to 3344 a signal mask but this system call has two arguments - a pointer 3345 to the mask and the number of bytes used by it. The kernel insists 3346 on the size being equal to sizeof(sigset_t) however and will just 3347 return EINVAL if it isn't. 3348 */ 3349 *flags |= SfMayBlock; 3350 PRINT("sys_rt_sigsuspend ( %#lx, %ld )", ARG1,ARG2 ); 3351 PRE_REG_READ2(int, "rt_sigsuspend", vki_sigset_t *, mask, vki_size_t, size) 3352 if (ARG1 != (Addr)NULL) { 3353 PRE_MEM_READ( "rt_sigsuspend(mask)", ARG1, sizeof(vki_sigset_t) ); 3354 } 3355 } 3356 3357 /* --------------------------------------------------------------------- 3358 linux msg* wrapper helpers 3359 ------------------------------------------------------------------ */ 3360 3361 void 3362 ML_(linux_PRE_sys_msgsnd) ( ThreadId tid, 3363 UWord arg0, UWord arg1, UWord arg2, UWord arg3 ) 3364 { 3365 /* int msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg); */ 3366 struct vki_msgbuf *msgp = (struct vki_msgbuf *)arg1; 3367 PRE_MEM_READ( "msgsnd(msgp->mtype)", (Addr)&msgp->mtype, sizeof(msgp->mtype) ); 3368 PRE_MEM_READ( "msgsnd(msgp->mtext)", (Addr)&msgp->mtext, arg2 ); 3369 } 3370 3371 void 3372 ML_(linux_PRE_sys_msgrcv) ( ThreadId tid, 3373 UWord arg0, UWord arg1, UWord arg2, 3374 UWord arg3, UWord arg4 ) 3375 { 3376 /* ssize_t msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz, 3377 long msgtyp, int msgflg); */ 3378 struct vki_msgbuf *msgp = (struct vki_msgbuf *)arg1; 3379 PRE_MEM_WRITE( "msgrcv(msgp->mtype)", (Addr)&msgp->mtype, sizeof(msgp->mtype) ); 3380 PRE_MEM_WRITE( "msgrcv(msgp->mtext)", (Addr)&msgp->mtext, arg2 ); 3381 } 3382 void 3383 ML_(linux_POST_sys_msgrcv) ( ThreadId tid, 3384 UWord res, 3385 UWord arg0, UWord arg1, UWord arg2, 3386 UWord arg3, UWord arg4 ) 3387 { 3388 struct vki_msgbuf *msgp = (struct vki_msgbuf *)arg1; 3389 POST_MEM_WRITE( (Addr)&msgp->mtype, sizeof(msgp->mtype) ); 3390 POST_MEM_WRITE( (Addr)&msgp->mtext, res ); 3391 } 3392 3393 void 3394 ML_(linux_PRE_sys_msgctl) ( ThreadId tid, 3395 UWord arg0, UWord arg1, UWord arg2 ) 3396 { 3397 /* int msgctl(int msqid, int cmd, struct msqid_ds *buf); */ 3398 switch (arg1 /* cmd */) { 3399 case VKI_IPC_INFO: 3400 case VKI_MSG_INFO: 3401 case VKI_IPC_INFO|VKI_IPC_64: 3402 case VKI_MSG_INFO|VKI_IPC_64: 3403 PRE_MEM_WRITE( "msgctl(IPC_INFO, buf)", 3404 arg2, sizeof(struct vki_msginfo) ); 3405 break; 3406 case VKI_IPC_STAT: 3407 case VKI_MSG_STAT: 3408 PRE_MEM_WRITE( "msgctl(IPC_STAT, buf)", 3409 arg2, sizeof(struct vki_msqid_ds) ); 3410 break; 3411 case VKI_IPC_STAT|VKI_IPC_64: 3412 case VKI_MSG_STAT|VKI_IPC_64: 3413 PRE_MEM_WRITE( "msgctl(IPC_STAT, arg.buf)", 3414 arg2, sizeof(struct vki_msqid64_ds) ); 3415 break; 3416 case VKI_IPC_SET: 3417 PRE_MEM_READ( "msgctl(IPC_SET, arg.buf)", 3418 arg2, sizeof(struct vki_msqid_ds) ); 3419 break; 3420 case VKI_IPC_SET|VKI_IPC_64: 3421 PRE_MEM_READ( "msgctl(IPC_SET, arg.buf)", 3422 arg2, sizeof(struct vki_msqid64_ds) ); 3423 break; 3424 } 3425 } 3426 void 3427 ML_(linux_POST_sys_msgctl) ( ThreadId tid, 3428 UWord res, 3429 UWord arg0, UWord arg1, UWord arg2 ) 3430 { 3431 switch (arg1 /* cmd */) { 3432 case VKI_IPC_INFO: 3433 case VKI_MSG_INFO: 3434 case VKI_IPC_INFO|VKI_IPC_64: 3435 case VKI_MSG_INFO|VKI_IPC_64: 3436 POST_MEM_WRITE( arg2, sizeof(struct vki_msginfo) ); 3437 break; 3438 case VKI_IPC_STAT: 3439 case VKI_MSG_STAT: 3440 POST_MEM_WRITE( arg2, sizeof(struct vki_msqid_ds) ); 3441 break; 3442 case VKI_IPC_STAT|VKI_IPC_64: 3443 case VKI_MSG_STAT|VKI_IPC_64: 3444 POST_MEM_WRITE( arg2, sizeof(struct vki_msqid64_ds) ); 3445 break; 3446 } 3447 } 3448 3449 /* --------------------------------------------------------------------- 3450 Generic handler for sys_ipc 3451 Depending on the platform, some syscalls (e.g. semctl, semop, ...) 3452 are either direct system calls, or are all implemented via sys_ipc. 3453 ------------------------------------------------------------------ */ 3454 #ifdef __NR_ipc 3455 static Addr deref_Addr ( ThreadId tid, Addr a, const HChar* s ) 3456 { 3457 Addr* a_p = (Addr*)a; 3458 PRE_MEM_READ( s, (Addr)a_p, sizeof(Addr) ); 3459 return *a_p; 3460 } 3461 3462 static Bool semctl_cmd_has_4args (UWord cmd) 3463 { 3464 switch (cmd & ~VKI_IPC_64) 3465 { 3466 case VKI_IPC_INFO: 3467 case VKI_SEM_INFO: 3468 case VKI_IPC_STAT: 3469 case VKI_SEM_STAT: 3470 case VKI_IPC_SET: 3471 case VKI_GETALL: 3472 case VKI_SETALL: 3473 return True; 3474 default: 3475 return False; 3476 } 3477 } 3478 3479 PRE(sys_ipc) 3480 { 3481 PRINT("sys_ipc ( %ld, %ld, %ld, %ld, %#lx, %ld )", 3482 ARG1,ARG2,ARG3,ARG4,ARG5,ARG6); 3483 3484 switch (ARG1 /* call */) { 3485 case VKI_SEMOP: 3486 PRE_REG_READ5(int, "ipc", 3487 vki_uint, call, int, first, int, second, int, third, 3488 void *, ptr); 3489 ML_(generic_PRE_sys_semop)( tid, ARG2, ARG5, ARG3 ); 3490 *flags |= SfMayBlock; 3491 break; 3492 case VKI_SEMGET: 3493 PRE_REG_READ4(int, "ipc", 3494 vki_uint, call, int, first, int, second, int, third); 3495 break; 3496 case VKI_SEMCTL: 3497 { 3498 PRE_REG_READ5(int, "ipc", 3499 vki_uint, call, int, first, int, second, int, third, 3500 void *, ptr); 3501 UWord arg; 3502 if (semctl_cmd_has_4args(ARG4)) 3503 arg = deref_Addr( tid, ARG5, "semctl(arg)" ); 3504 else 3505 arg = 0; 3506 ML_(generic_PRE_sys_semctl)( tid, ARG2, ARG3, ARG4, arg ); 3507 break; 3508 } 3509 case VKI_SEMTIMEDOP: 3510 PRE_REG_READ6(int, "ipc", 3511 vki_uint, call, int, first, int, second, int, third, 3512 void *, ptr, long, fifth); 3513 ML_(generic_PRE_sys_semtimedop)( tid, ARG2, ARG5, ARG3, ARG6 ); 3514 *flags |= SfMayBlock; 3515 break; 3516 case VKI_MSGSND: 3517 PRE_REG_READ5(int, "ipc", 3518 vki_uint, call, int, first, int, second, int, third, 3519 void *, ptr); 3520 ML_(linux_PRE_sys_msgsnd)( tid, ARG2, ARG5, ARG3, ARG4 ); 3521 if ((ARG4 & VKI_IPC_NOWAIT) == 0) 3522 *flags |= SfMayBlock; 3523 break; 3524 case VKI_MSGRCV: 3525 { 3526 PRE_REG_READ5(int, "ipc", 3527 vki_uint, call, int, first, int, second, int, third, 3528 void *, ptr); 3529 Addr msgp; 3530 Word msgtyp; 3531 3532 msgp = deref_Addr( tid, (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgp), 3533 "msgrcv(msgp)" ); 3534 msgtyp = deref_Addr( tid, 3535 (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgtyp), 3536 "msgrcv(msgp)" ); 3537 3538 ML_(linux_PRE_sys_msgrcv)( tid, ARG2, msgp, ARG3, msgtyp, ARG4 ); 3539 3540 if ((ARG4 & VKI_IPC_NOWAIT) == 0) 3541 *flags |= SfMayBlock; 3542 break; 3543 } 3544 case VKI_MSGGET: 3545 PRE_REG_READ3(int, "ipc", vki_uint, call, int, first, int, second); 3546 break; 3547 case VKI_MSGCTL: 3548 PRE_REG_READ5(int, "ipc", 3549 vki_uint, call, int, first, int, second, int, third, 3550 void *, ptr); 3551 ML_(linux_PRE_sys_msgctl)( tid, ARG2, ARG3, ARG5 ); 3552 break; 3553 case VKI_SHMAT: 3554 { 3555 PRE_REG_READ5(int, "ipc", 3556 vki_uint, call, int, first, int, second, int, third, 3557 void *, ptr); 3558 UWord w; 3559 PRE_MEM_WRITE( "shmat(raddr)", ARG4, sizeof(Addr) ); 3560 w = ML_(generic_PRE_sys_shmat)( tid, ARG2, ARG5, ARG3 ); 3561 if (w == 0) 3562 SET_STATUS_Failure( VKI_EINVAL ); 3563 else 3564 ARG5 = w; 3565 break; 3566 } 3567 case VKI_SHMDT: 3568 PRE_REG_READ5(int, "ipc", 3569 vki_uint, call, int, first, int, second, int, third, 3570 void *, ptr); 3571 if (!ML_(generic_PRE_sys_shmdt)(tid, ARG5)) 3572 SET_STATUS_Failure( VKI_EINVAL ); 3573 break; 3574 case VKI_SHMGET: 3575 PRE_REG_READ4(int, "ipc", 3576 vki_uint, call, int, first, int, second, int, third); 3577 break; 3578 case VKI_SHMCTL: /* IPCOP_shmctl */ 3579 PRE_REG_READ5(int, "ipc", 3580 vki_uint, call, int, first, int, second, int, third, 3581 void *, ptr); 3582 ML_(generic_PRE_sys_shmctl)( tid, ARG2, ARG3, ARG5 ); 3583 break; 3584 default: 3585 VG_(message)(Vg_DebugMsg, "FATAL: unhandled syscall(ipc) %ld\n", ARG1 ); 3586 VG_(core_panic)("... bye!\n"); 3587 break; /*NOTREACHED*/ 3588 } 3589 } 3590 3591 POST(sys_ipc) 3592 { 3593 vg_assert(SUCCESS); 3594 switch (ARG1 /* call */) { 3595 case VKI_SEMOP: 3596 case VKI_SEMGET: 3597 break; 3598 case VKI_SEMCTL: 3599 { 3600 UWord arg; 3601 if (semctl_cmd_has_4args(ARG4)) 3602 arg = deref_Addr( tid, ARG5, "semctl(arg)" ); 3603 else 3604 arg = 0; 3605 ML_(generic_POST_sys_semctl)( tid, RES, ARG2, ARG3, ARG4, arg ); 3606 break; 3607 } 3608 case VKI_SEMTIMEDOP: 3609 case VKI_MSGSND: 3610 break; 3611 case VKI_MSGRCV: 3612 { 3613 Addr msgp; 3614 Word msgtyp; 3615 3616 msgp = deref_Addr( tid, 3617 (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgp), 3618 "msgrcv(msgp)" ); 3619 msgtyp = deref_Addr( tid, 3620 (Addr) (&((struct vki_ipc_kludge *)ARG5)->msgtyp), 3621 "msgrcv(msgp)" ); 3622 3623 ML_(linux_POST_sys_msgrcv)( tid, RES, ARG2, msgp, ARG3, msgtyp, ARG4 ); 3624 break; 3625 } 3626 case VKI_MSGGET: 3627 break; 3628 case VKI_MSGCTL: 3629 ML_(linux_POST_sys_msgctl)( tid, RES, ARG2, ARG3, ARG5 ); 3630 break; 3631 case VKI_SHMAT: 3632 { 3633 Addr addr; 3634 3635 /* force readability. before the syscall it is 3636 * indeed uninitialized, as can be seen in 3637 * glibc/sysdeps/unix/sysv/linux/shmat.c */ 3638 POST_MEM_WRITE( ARG4, sizeof( Addr ) ); 3639 3640 addr = deref_Addr ( tid, ARG4, "shmat(addr)" ); 3641 ML_(generic_POST_sys_shmat)( tid, addr, ARG2, ARG5, ARG3 ); 3642 break; 3643 } 3644 case VKI_SHMDT: 3645 ML_(generic_POST_sys_shmdt)( tid, RES, ARG5 ); 3646 break; 3647 case VKI_SHMGET: 3648 break; 3649 case VKI_SHMCTL: 3650 ML_(generic_POST_sys_shmctl)( tid, RES, ARG2, ARG3, ARG5 ); 3651 break; 3652 default: 3653 VG_(message)(Vg_DebugMsg, 3654 "FATAL: unhandled syscall(ipc) %ld\n", 3655 ARG1 ); 3656 VG_(core_panic)("... bye!\n"); 3657 break; /*NOTREACHED*/ 3658 } 3659 } 3660 #endif 3661 3662 PRE(sys_semget) 3663 { 3664 PRINT("sys_semget ( %ld, %ld, %ld )",ARG1,ARG2,ARG3); 3665 PRE_REG_READ3(long, "semget", vki_key_t, key, int, nsems, int, semflg); 3666 } 3667 3668 PRE(sys_semop) 3669 { 3670 *flags |= SfMayBlock; 3671 PRINT("sys_semop ( %ld, %#lx, %lu )",ARG1,ARG2,ARG3); 3672 PRE_REG_READ3(long, "semop", 3673 int, semid, struct sembuf *, sops, unsigned, nsoops); 3674 ML_(generic_PRE_sys_semop)(tid, ARG1,ARG2,ARG3); 3675 } 3676 3677 PRE(sys_semctl) 3678 { 3679 switch (ARG3 & ~VKI_IPC_64) { 3680 case VKI_IPC_INFO: 3681 case VKI_SEM_INFO: 3682 PRINT("sys_semctl ( %ld, %ld, %ld, %#lx )",ARG1,ARG2,ARG3,ARG4); 3683 PRE_REG_READ4(long, "semctl", 3684 int, semid, int, semnum, int, cmd, struct seminfo *, arg); 3685 break; 3686 case VKI_IPC_STAT: 3687 case VKI_SEM_STAT: 3688 case VKI_IPC_SET: 3689 PRINT("sys_semctl ( %ld, %ld, %ld, %#lx )",ARG1,ARG2,ARG3,ARG4); 3690 PRE_REG_READ4(long, "semctl", 3691 int, semid, int, semnum, int, cmd, struct semid_ds *, arg); 3692 break; 3693 case VKI_GETALL: 3694 case VKI_SETALL: 3695 PRINT("sys_semctl ( %ld, %ld, %ld, %#lx )",ARG1,ARG2,ARG3,ARG4); 3696 PRE_REG_READ4(long, "semctl", 3697 int, semid, int, semnum, int, cmd, unsigned short *, arg); 3698 break; 3699 default: 3700 PRINT("sys_semctl ( %ld, %ld, %ld )",ARG1,ARG2,ARG3); 3701 PRE_REG_READ3(long, "semctl", 3702 int, semid, int, semnum, int, cmd); 3703 break; 3704 } 3705 #ifdef VGP_amd64_linux 3706 ML_(generic_PRE_sys_semctl)(tid, ARG1,ARG2,ARG3|VKI_IPC_64,ARG4); 3707 #else 3708 ML_(generic_PRE_sys_semctl)(tid, ARG1,ARG2,ARG3,ARG4); 3709 #endif 3710 } 3711 3712 POST(sys_semctl) 3713 { 3714 #ifdef VGP_amd64_linux 3715 ML_(generic_POST_sys_semctl)(tid, RES,ARG1,ARG2,ARG3|VKI_IPC_64,ARG4); 3716 #else 3717 ML_(generic_POST_sys_semctl)(tid, RES,ARG1,ARG2,ARG3,ARG4); 3718 #endif 3719 } 3720 3721 PRE(sys_semtimedop) 3722 { 3723 *flags |= SfMayBlock; 3724 PRINT("sys_semtimedop ( %ld, %#lx, %lu, %#lx )",ARG1,ARG2,ARG3,ARG4); 3725 PRE_REG_READ4(long, "semtimedop", 3726 int, semid, struct sembuf *, sops, unsigned, nsoops, 3727 struct timespec *, timeout); 3728 ML_(generic_PRE_sys_semtimedop)(tid, ARG1,ARG2,ARG3,ARG4); 3729 } 3730 3731 PRE(sys_msgget) 3732 { 3733 PRINT("sys_msgget ( %ld, %ld )",ARG1,ARG2); 3734 PRE_REG_READ2(long, "msgget", vki_key_t, key, int, msgflg); 3735 } 3736 3737 PRE(sys_msgsnd) 3738 { 3739 PRINT("sys_msgsnd ( %ld, %#lx, %ld, %ld )",ARG1,ARG2,ARG3,ARG4); 3740 PRE_REG_READ4(long, "msgsnd", 3741 int, msqid, struct msgbuf *, msgp, vki_size_t, msgsz, int, msgflg); 3742 ML_(linux_PRE_sys_msgsnd)(tid, ARG1,ARG2,ARG3,ARG4); 3743 if ((ARG4 & VKI_IPC_NOWAIT) == 0) 3744 *flags |= SfMayBlock; 3745 } 3746 3747 PRE(sys_msgrcv) 3748 { 3749 PRINT("sys_msgrcv ( %ld, %#lx, %ld, %ld, %ld )",ARG1,ARG2,ARG3,ARG4,ARG5); 3750 PRE_REG_READ5(long, "msgrcv", 3751 int, msqid, struct msgbuf *, msgp, vki_size_t, msgsz, 3752 long, msgytp, int, msgflg); 3753 ML_(linux_PRE_sys_msgrcv)(tid, ARG1,ARG2,ARG3,ARG4,ARG5); 3754 if ((ARG5 & VKI_IPC_NOWAIT) == 0) 3755 *flags |= SfMayBlock; 3756 } 3757 POST(sys_msgrcv) 3758 { 3759 ML_(linux_POST_sys_msgrcv)(tid, RES,ARG1,ARG2,ARG3,ARG4,ARG5); 3760 } 3761 3762 PRE(sys_msgctl) 3763 { 3764 PRINT("sys_msgctl ( %ld, %ld, %#lx )",ARG1,ARG2,ARG3); 3765 PRE_REG_READ3(long, "msgctl", 3766 int, msqid, int, cmd, struct msqid_ds *, buf); 3767 ML_(linux_PRE_sys_msgctl)(tid, ARG1,ARG2,ARG3); 3768 } 3769 3770 POST(sys_msgctl) 3771 { 3772 ML_(linux_POST_sys_msgctl)(tid, RES,ARG1,ARG2,ARG3); 3773 } 3774 3775 PRE(sys_shmget) 3776 { 3777 PRINT("sys_shmget ( %ld, %ld, %ld )",ARG1,ARG2,ARG3); 3778 PRE_REG_READ3(long, "shmget", vki_key_t, key, vki_size_t, size, int, shmflg); 3779 } 3780 3781 PRE(wrap_sys_shmat) 3782 { 3783 UWord arg2tmp; 3784 PRINT("wrap_sys_shmat ( %ld, %#lx, %ld )",ARG1,ARG2,ARG3); 3785 PRE_REG_READ3(long, "shmat", 3786 int, shmid, const void *, shmaddr, int, shmflg); 3787 #if defined(VGP_arm_linux) 3788 /* Round the attach address down to an VKI_SHMLBA boundary if the 3789 client requested rounding. See #222545. This is necessary only 3790 on arm-linux because VKI_SHMLBA is 4 * VKI_PAGE size; on all 3791 other linux targets it is the same as the page size. */ 3792 if (ARG3 & VKI_SHM_RND) 3793 ARG2 = VG_ROUNDDN(ARG2, VKI_SHMLBA); 3794 #endif 3795 arg2tmp = ML_(generic_PRE_sys_shmat)(tid, ARG1,ARG2,ARG3); 3796 if (arg2tmp == 0) 3797 SET_STATUS_Failure( VKI_EINVAL ); 3798 else 3799 ARG2 = arg2tmp; // used in POST 3800 } 3801 3802 POST(wrap_sys_shmat) 3803 { 3804 ML_(generic_POST_sys_shmat)(tid, RES,ARG1,ARG2,ARG3); 3805 } 3806 3807 PRE(sys_shmdt) 3808 { 3809 PRINT("sys_shmdt ( %#lx )",ARG1); 3810 PRE_REG_READ1(long, "shmdt", const void *, shmaddr); 3811 if (!ML_(generic_PRE_sys_shmdt)(tid, ARG1)) 3812 SET_STATUS_Failure( VKI_EINVAL ); 3813 } 3814 3815 POST(sys_shmdt) 3816 { 3817 ML_(generic_POST_sys_shmdt)(tid, RES,ARG1); 3818 } 3819 3820 PRE(sys_shmctl) 3821 { 3822 PRINT("sys_shmctl ( %ld, %ld, %#lx )",ARG1,ARG2,ARG3); 3823 PRE_REG_READ3(long, "shmctl", 3824 int, shmid, int, cmd, struct shmid_ds *, buf); 3825 #ifdef VGP_amd64_linux 3826 ML_(generic_PRE_sys_shmctl)(tid, ARG1,ARG2|VKI_IPC_64,ARG3); 3827 #else 3828 ML_(generic_PRE_sys_shmctl)(tid, ARG1,ARG2,ARG3); 3829 #endif 3830 } 3831 3832 POST(sys_shmctl) 3833 { 3834 #ifdef VGP_amd64_linux 3835 ML_(generic_POST_sys_shmctl)(tid, RES,ARG1,ARG2|VKI_IPC_64,ARG3); 3836 #else 3837 ML_(generic_POST_sys_shmctl)(tid, RES,ARG1,ARG2,ARG3); 3838 #endif 3839 } 3840 3841 3842 /* --------------------------------------------------------------------- 3843 Generic handler for sys_socketcall 3844 Depending on the platform, some socket related syscalls (e.g. socketpair, 3845 socket, bind, ...) 3846 are either direct system calls, or are all implemented via sys_socketcall. 3847 ------------------------------------------------------------------ */ 3848 #ifdef __NR_socketcall 3849 PRE(sys_socketcall) 3850 { 3851 # define ARG2_0 (((UWord*)ARG2)[0]) 3852 # define ARG2_1 (((UWord*)ARG2)[1]) 3853 # define ARG2_2 (((UWord*)ARG2)[2]) 3854 # define ARG2_3 (((UWord*)ARG2)[3]) 3855 # define ARG2_4 (((UWord*)ARG2)[4]) 3856 # define ARG2_5 (((UWord*)ARG2)[5]) 3857 3858 // call PRE_MEM_READ and check for EFAULT result. 3859 #define PRE_MEM_READ_ef(msg, arg, size) \ 3860 { \ 3861 PRE_MEM_READ( msg, arg, size); \ 3862 if (!ML_(valid_client_addr)(arg, size, tid, NULL)) { \ 3863 SET_STATUS_Failure( VKI_EFAULT ); \ 3864 break; \ 3865 } \ 3866 } 3867 3868 *flags |= SfMayBlock; 3869 PRINT("sys_socketcall ( %ld, %#lx )",ARG1,ARG2); 3870 PRE_REG_READ2(long, "socketcall", int, call, unsigned long *, args); 3871 3872 switch (ARG1 /* request */) { 3873 3874 case VKI_SYS_SOCKETPAIR: 3875 /* int socketpair(int d, int type, int protocol, int sv[2]); */ 3876 PRE_MEM_READ_ef( "socketcall.socketpair(args)", ARG2, 4*sizeof(Addr) ); 3877 ML_(generic_PRE_sys_socketpair)( tid, ARG2_0, ARG2_1, ARG2_2, ARG2_3 ); 3878 break; 3879 3880 case VKI_SYS_SOCKET: 3881 /* int socket(int domain, int type, int protocol); */ 3882 PRE_MEM_READ_ef( "socketcall.socket(args)", ARG2, 3*sizeof(Addr) ); 3883 break; 3884 3885 case VKI_SYS_BIND: 3886 /* int bind(int sockfd, struct sockaddr *my_addr, 3887 int addrlen); */ 3888 PRE_MEM_READ_ef( "socketcall.bind(args)", ARG2, 3*sizeof(Addr) ); 3889 ML_(generic_PRE_sys_bind)( tid, ARG2_0, ARG2_1, ARG2_2 ); 3890 break; 3891 3892 case VKI_SYS_LISTEN: 3893 /* int listen(int s, int backlog); */ 3894 PRE_MEM_READ_ef( "socketcall.listen(args)", ARG2, 2*sizeof(Addr) ); 3895 break; 3896 3897 case VKI_SYS_ACCEPT: 3898 /* int accept(int s, struct sockaddr *addr, int *addrlen); */ 3899 PRE_MEM_READ_ef( "socketcall.accept(args)", ARG2, 3*sizeof(Addr) ); 3900 ML_(generic_PRE_sys_accept)( tid, ARG2_0, ARG2_1, ARG2_2 ); 3901 break; 3902 3903 case VKI_SYS_ACCEPT4: 3904 /* int accept4(int s, struct sockaddr *addr, int *addrlen, int flags); */ 3905 PRE_MEM_READ_ef( "socketcall.accept4(args)", ARG2, 4*sizeof(Addr) ); 3906 ML_(generic_PRE_sys_accept)( tid, ARG2_0, ARG2_1, ARG2_2 ); 3907 break; 3908 3909 case VKI_SYS_SENDTO: 3910 /* int sendto(int s, const void *msg, int len, 3911 unsigned int flags, 3912 const struct sockaddr *to, int tolen); */ 3913 PRE_MEM_READ_ef( "socketcall.sendto(args)", ARG2, 6*sizeof(Addr) ); 3914 ML_(generic_PRE_sys_sendto)( tid, ARG2_0, ARG2_1, ARG2_2, 3915 ARG2_3, ARG2_4, ARG2_5 ); 3916 break; 3917 3918 case VKI_SYS_SEND: 3919 /* int send(int s, const void *msg, size_t len, int flags); */ 3920 PRE_MEM_READ_ef( "socketcall.send(args)", ARG2, 4*sizeof(Addr) ); 3921 ML_(generic_PRE_sys_send)( tid, ARG2_0, ARG2_1, ARG2_2 ); 3922 break; 3923 3924 case VKI_SYS_RECVFROM: 3925 /* int recvfrom(int s, void *buf, int len, unsigned int flags, 3926 struct sockaddr *from, int *fromlen); */ 3927 PRE_MEM_READ_ef( "socketcall.recvfrom(args)", ARG2, 6*sizeof(Addr) ); 3928 ML_(generic_PRE_sys_recvfrom)( tid, ARG2_0, ARG2_1, ARG2_2, 3929 ARG2_3, ARG2_4, ARG2_5 ); 3930 break; 3931 3932 case VKI_SYS_RECV: 3933 /* int recv(int s, void *buf, int len, unsigned int flags); */ 3934 /* man 2 recv says: 3935 The recv call is normally used only on a connected socket 3936 (see connect(2)) and is identical to recvfrom with a NULL 3937 from parameter. 3938 */ 3939 PRE_MEM_READ_ef( "socketcall.recv(args)", ARG2, 4*sizeof(Addr) ); 3940 ML_(generic_PRE_sys_recv)( tid, ARG2_0, ARG2_1, ARG2_2 ); 3941 break; 3942 3943 case VKI_SYS_CONNECT: 3944 /* int connect(int sockfd, 3945 struct sockaddr *serv_addr, int addrlen ); */ 3946 PRE_MEM_READ_ef( "socketcall.connect(args)", ARG2, 3*sizeof(Addr) ); 3947 ML_(generic_PRE_sys_connect)( tid, ARG2_0, ARG2_1, ARG2_2 ); 3948 break; 3949 3950 case VKI_SYS_SETSOCKOPT: 3951 /* int setsockopt(int s, int level, int optname, 3952 const void *optval, int optlen); */ 3953 PRE_MEM_READ_ef( "socketcall.setsockopt(args)", ARG2, 5*sizeof(Addr) ); 3954 ML_(linux_PRE_sys_setsockopt)( tid, ARG2_0, ARG2_1, ARG2_2, 3955 ARG2_3, ARG2_4 ); 3956 break; 3957 3958 case VKI_SYS_GETSOCKOPT: 3959 /* int getsockopt(int s, int level, int optname, 3960 void *optval, socklen_t *optlen); */ 3961 PRE_MEM_READ_ef( "socketcall.getsockopt(args)", ARG2, 5*sizeof(Addr) ); 3962 ML_(linux_PRE_sys_getsockopt)( tid, ARG2_0, ARG2_1, ARG2_2, 3963 ARG2_3, ARG2_4 ); 3964 break; 3965 3966 case VKI_SYS_GETSOCKNAME: 3967 /* int getsockname(int s, struct sockaddr* name, int* namelen) */ 3968 PRE_MEM_READ_ef( "socketcall.getsockname(args)", ARG2, 3*sizeof(Addr) ); 3969 ML_(generic_PRE_sys_getsockname)( tid, ARG2_0, ARG2_1, ARG2_2 ); 3970 break; 3971 3972 case VKI_SYS_GETPEERNAME: 3973 /* int getpeername(int s, struct sockaddr* name, int* namelen) */ 3974 PRE_MEM_READ_ef( "socketcall.getpeername(args)", ARG2, 3*sizeof(Addr) ); 3975 ML_(generic_PRE_sys_getpeername)( tid, ARG2_0, ARG2_1, ARG2_2 ); 3976 break; 3977 3978 case VKI_SYS_SHUTDOWN: 3979 /* int shutdown(int s, int how); */ 3980 PRE_MEM_READ_ef( "socketcall.shutdown(args)", ARG2, 2*sizeof(Addr) ); 3981 break; 3982 3983 case VKI_SYS_SENDMSG: 3984 /* int sendmsg(int s, const struct msghdr *msg, int flags); */ 3985 PRE_MEM_READ_ef( "socketcall.sendmsg(args)", ARG2, 3*sizeof(Addr) ); 3986 ML_(generic_PRE_sys_sendmsg)( tid, "msg", (struct vki_msghdr *)ARG2_1 ); 3987 break; 3988 3989 case VKI_SYS_RECVMSG: 3990 /* int recvmsg(int s, struct msghdr *msg, int flags); */ 3991 PRE_MEM_READ_ef("socketcall.recvmsg(args)", ARG2, 3*sizeof(Addr) ); 3992 ML_(generic_PRE_sys_recvmsg)( tid, "msg", (struct vki_msghdr *)ARG2_1 ); 3993 break; 3994 3995 default: 3996 VG_(message)(Vg_DebugMsg,"Warning: unhandled socketcall 0x%lx\n",ARG1); 3997 SET_STATUS_Failure( VKI_EINVAL ); 3998 break; 3999 } 4000 # undef ARG2_0 4001 # undef ARG2_1 4002 # undef ARG2_2 4003 # undef ARG2_3 4004 # undef ARG2_4 4005 # undef ARG2_5 4006 } 4007 4008 POST(sys_socketcall) 4009 { 4010 # define ARG2_0 (((UWord*)ARG2)[0]) 4011 # define ARG2_1 (((UWord*)ARG2)[1]) 4012 # define ARG2_2 (((UWord*)ARG2)[2]) 4013 # define ARG2_3 (((UWord*)ARG2)[3]) 4014 # define ARG2_4 (((UWord*)ARG2)[4]) 4015 # define ARG2_5 (((UWord*)ARG2)[5]) 4016 4017 SysRes r; 4018 vg_assert(SUCCESS); 4019 switch (ARG1 /* request */) { 4020 4021 case VKI_SYS_SOCKETPAIR: 4022 r = ML_(generic_POST_sys_socketpair)( 4023 tid, VG_(mk_SysRes_Success)(RES), 4024 ARG2_0, ARG2_1, ARG2_2, ARG2_3 4025 ); 4026 SET_STATUS_from_SysRes(r); 4027 break; 4028 4029 case VKI_SYS_SOCKET: 4030 r = ML_(generic_POST_sys_socket)( tid, VG_(mk_SysRes_Success)(RES) ); 4031 SET_STATUS_from_SysRes(r); 4032 break; 4033 4034 case VKI_SYS_BIND: 4035 /* int bind(int sockfd, struct sockaddr *my_addr, 4036 int addrlen); */ 4037 break; 4038 4039 case VKI_SYS_LISTEN: 4040 /* int listen(int s, int backlog); */ 4041 break; 4042 4043 case VKI_SYS_ACCEPT: 4044 case VKI_SYS_ACCEPT4: 4045 /* int accept(int s, struct sockaddr *addr, int *addrlen); */ 4046 /* int accept4(int s, struct sockaddr *addr, int *addrlen, int flags); */ 4047 r = ML_(generic_POST_sys_accept)( tid, VG_(mk_SysRes_Success)(RES), 4048 ARG2_0, ARG2_1, ARG2_2 ); 4049 SET_STATUS_from_SysRes(r); 4050 break; 4051 4052 case VKI_SYS_SENDTO: 4053 break; 4054 4055 case VKI_SYS_SEND: 4056 break; 4057 4058 case VKI_SYS_RECVFROM: 4059 ML_(generic_POST_sys_recvfrom)( tid, VG_(mk_SysRes_Success)(RES), 4060 ARG2_0, ARG2_1, ARG2_2, 4061 ARG2_3, ARG2_4, ARG2_5 ); 4062 break; 4063 4064 case VKI_SYS_RECV: 4065 ML_(generic_POST_sys_recv)( tid, RES, ARG2_0, ARG2_1, ARG2_2 ); 4066 break; 4067 4068 case VKI_SYS_CONNECT: 4069 break; 4070 4071 case VKI_SYS_SETSOCKOPT: 4072 break; 4073 4074 case VKI_SYS_GETSOCKOPT: 4075 ML_(linux_POST_sys_getsockopt)( tid, VG_(mk_SysRes_Success)(RES), 4076 ARG2_0, ARG2_1, 4077 ARG2_2, ARG2_3, ARG2_4 ); 4078 break; 4079 4080 case VKI_SYS_GETSOCKNAME: 4081 ML_(generic_POST_sys_getsockname)( tid, VG_(mk_SysRes_Success)(RES), 4082 ARG2_0, ARG2_1, ARG2_2 ); 4083 break; 4084 4085 case VKI_SYS_GETPEERNAME: 4086 ML_(generic_POST_sys_getpeername)( tid, VG_(mk_SysRes_Success)(RES), 4087 ARG2_0, ARG2_1, ARG2_2 ); 4088 break; 4089 4090 case VKI_SYS_SHUTDOWN: 4091 break; 4092 4093 case VKI_SYS_SENDMSG: 4094 break; 4095 4096 case VKI_SYS_RECVMSG: 4097 ML_(generic_POST_sys_recvmsg)( tid, "msg", (struct vki_msghdr *)ARG2_1, RES ); 4098 break; 4099 4100 # if defined(ANDROID_HARDWARE_nexus_10) 4101 /* undocumented ioctl ids noted on the device */ 4102 case 0x4d07: 4103 case 0x6101: 4104 case 0xfa01: /* used by NFC */ 4105 case 0xfa05: /* used by NFC */ 4106 return; 4107 # elif defined(ANDROID_HARDWARE_nexus_7) 4108 /* undocumented ioctl ids noted on the device */ 4109 case 0x4e04: 4110 case 0x7231: 4111 case 0x4004e901: /* used by NFC */ 4112 return; 4113 # elif defined(ANDROID_HARDWARE_nexus_4) 4114 4115 # endif 4116 4117 default: 4118 VG_(message)(Vg_DebugMsg,"FATAL: unhandled socketcall 0x%lx\n",ARG1); 4119 VG_(core_panic)("... bye!\n"); 4120 break; /*NOTREACHED*/ 4121 } 4122 # undef ARG2_0 4123 # undef ARG2_1 4124 # undef ARG2_2 4125 # undef ARG2_3 4126 # undef ARG2_4 4127 # undef ARG2_5 4128 } 4129 #endif 4130 4131 PRE(sys_socket) 4132 { 4133 PRINT("sys_socket ( %ld, %ld, %ld )",ARG1,ARG2,ARG3); 4134 PRE_REG_READ3(long, "socket", int, domain, int, type, int, protocol); 4135 } 4136 POST(sys_socket) 4137 { 4138 SysRes r; 4139 vg_assert(SUCCESS); 4140 r = ML_(generic_POST_sys_socket)(tid, VG_(mk_SysRes_Success)(RES)); 4141 SET_STATUS_from_SysRes(r); 4142 } 4143 4144 PRE(sys_setsockopt) 4145 { 4146 PRINT("sys_setsockopt ( %ld, %ld, %ld, %#lx, %ld )",ARG1,ARG2,ARG3,ARG4,ARG5); 4147 PRE_REG_READ5(long, "setsockopt", 4148 int, s, int, level, int, optname, 4149 const void *, optval, int, optlen); 4150 ML_(linux_PRE_sys_setsockopt)(tid, ARG1,ARG2,ARG3,ARG4,ARG5); 4151 } 4152 4153 PRE(sys_getsockopt) 4154 { 4155 PRINT("sys_getsockopt ( %ld, %ld, %ld, %#lx, %#lx )",ARG1,ARG2,ARG3,ARG4,ARG5); 4156 PRE_REG_READ5(long, "getsockopt", 4157 int, s, int, level, int, optname, 4158 void *, optval, int, *optlen); 4159 ML_(linux_PRE_sys_getsockopt)(tid, ARG1,ARG2,ARG3,ARG4,ARG5); 4160 } 4161 POST(sys_getsockopt) 4162 { 4163 vg_assert(SUCCESS); 4164 ML_(linux_POST_sys_getsockopt)(tid, VG_(mk_SysRes_Success)(RES), 4165 ARG1,ARG2,ARG3,ARG4,ARG5); 4166 } 4167 4168 PRE(sys_connect) 4169 { 4170 *flags |= SfMayBlock; 4171 PRINT("sys_connect ( %ld, %#lx, %ld )",ARG1,ARG2,ARG3); 4172 PRE_REG_READ3(long, "connect", 4173 int, sockfd, struct sockaddr *, serv_addr, int, addrlen); 4174 ML_(generic_PRE_sys_connect)(tid, ARG1,ARG2,ARG3); 4175 } 4176 4177 PRE(sys_accept) 4178 { 4179 *flags |= SfMayBlock; 4180 PRINT("sys_accept ( %ld, %#lx, %ld )",ARG1,ARG2,ARG3); 4181 PRE_REG_READ3(long, "accept", 4182 int, s, struct sockaddr *, addr, int, *addrlen); 4183 ML_(generic_PRE_sys_accept)(tid, ARG1,ARG2,ARG3); 4184 } 4185 POST(sys_accept) 4186 { 4187 SysRes r; 4188 vg_assert(SUCCESS); 4189 r = ML_(generic_POST_sys_accept)(tid, VG_(mk_SysRes_Success)(RES), 4190 ARG1,ARG2,ARG3); 4191 SET_STATUS_from_SysRes(r); 4192 } 4193 4194 PRE(sys_accept4) 4195 { 4196 *flags |= SfMayBlock; 4197 PRINT("sys_accept4 ( %ld, %#lx, %ld, %ld )",ARG1,ARG2,ARG3,ARG4); 4198 PRE_REG_READ4(long, "accept4", 4199 int, s, struct sockaddr *, addr, int, *addrlen, int, flags); 4200 ML_(generic_PRE_sys_accept)(tid, ARG1,ARG2,ARG3); 4201 } 4202 POST(sys_accept4) 4203 { 4204 SysRes r; 4205 vg_assert(SUCCESS); 4206 r = ML_(generic_POST_sys_accept)(tid, VG_(mk_SysRes_Success)(RES), 4207 ARG1,ARG2,ARG3); 4208 SET_STATUS_from_SysRes(r); 4209 } 4210 4211 PRE(sys_send) 4212 { 4213 *flags |= SfMayBlock; 4214 PRINT("sys_send ( %ld, %#lx, %ld, %lu )",ARG1,ARG2,ARG3,ARG4); 4215 PRE_REG_READ4(long, "send", 4216 int, s, const void *, msg, int, len, 4217 unsigned int, flags); 4218 4219 ML_(generic_PRE_sys_send)( tid, ARG1, ARG2, ARG3 ); 4220 } 4221 4222 PRE(sys_sendto) 4223 { 4224 *flags |= SfMayBlock; 4225 PRINT("sys_sendto ( %ld, %#lx, %ld, %lu, %#lx, %ld )",ARG1,ARG2,ARG3,ARG4,ARG5,ARG6); 4226 PRE_REG_READ6(long, "sendto", 4227 int, s, const void *, msg, int, len, 4228 unsigned int, flags, 4229 const struct sockaddr *, to, int, tolen); 4230 ML_(generic_PRE_sys_sendto)(tid, ARG1,ARG2,ARG3,ARG4,ARG5,ARG6); 4231 } 4232 4233 PRE (sys_recv) 4234 { 4235 *flags |= SfMayBlock; 4236 PRINT ("sys_recv ( %ld, %#lx, %ld, %lu )", ARG1, ARG2, ARG3, ARG4); 4237 PRE_REG_READ4 (long, "recv", int, s, void *, buf, int, len, 4238 unsigned int, flags); 4239 ML_ (generic_PRE_sys_recv) (tid, ARG1, ARG2, ARG3); 4240 } 4241 4242 POST (sys_recv) 4243 { 4244 ML_ (generic_POST_sys_recv) (tid, RES, ARG1, ARG2, ARG3); 4245 } 4246 4247 PRE(sys_recvfrom) 4248 { 4249 *flags |= SfMayBlock; 4250 PRINT("sys_recvfrom ( %ld, %#lx, %ld, %lu, %#lx, %#lx )",ARG1,ARG2,ARG3,ARG4,ARG5,ARG6); 4251 PRE_REG_READ6(long, "recvfrom", 4252 int, s, void *, buf, int, len, unsigned int, flags, 4253 struct sockaddr *, from, int *, fromlen); 4254 ML_(generic_PRE_sys_recvfrom)(tid, ARG1,ARG2,ARG3,ARG4,ARG5,ARG6); 4255 } 4256 POST(sys_recvfrom) 4257 { 4258 vg_assert(SUCCESS); 4259 ML_(generic_POST_sys_recvfrom)(tid, VG_(mk_SysRes_Success)(RES), 4260 ARG1,ARG2,ARG3,ARG4,ARG5,ARG6); 4261 } 4262 4263 PRE(sys_sendmsg) 4264 { 4265 *flags |= SfMayBlock; 4266 PRINT("sys_sendmsg ( %ld, %#lx, %ld )",ARG1,ARG2,ARG3); 4267 PRE_REG_READ3(long, "sendmsg", 4268 int, s, const struct msghdr *, msg, int, flags); 4269 ML_(generic_PRE_sys_sendmsg)(tid, "msg", (struct vki_msghdr *)ARG2); 4270 } 4271 4272 PRE(sys_recvmsg) 4273 { 4274 *flags |= SfMayBlock; 4275 PRINT("sys_recvmsg ( %ld, %#lx, %ld )",ARG1,ARG2,ARG3); 4276 PRE_REG_READ3(long, "recvmsg", int, s, struct msghdr *, msg, int, flags); 4277 ML_(generic_PRE_sys_recvmsg)(tid, "msg", (struct vki_msghdr *)ARG2); 4278 } 4279 POST(sys_recvmsg) 4280 { 4281 ML_(generic_POST_sys_recvmsg)(tid, "msg", (struct vki_msghdr *)ARG2, RES); 4282 } 4283 4284 PRE(sys_shutdown) 4285 { 4286 *flags |= SfMayBlock; 4287 PRINT("sys_shutdown ( %ld, %ld )",ARG1,ARG2); 4288 PRE_REG_READ2(int, "shutdown", int, s, int, how); 4289 } 4290 4291 PRE(sys_bind) 4292 { 4293 PRINT("sys_bind ( %ld, %#lx, %ld )",ARG1,ARG2,ARG3); 4294 PRE_REG_READ3(long, "bind", 4295 int, sockfd, struct sockaddr *, my_addr, int, addrlen); 4296 ML_(generic_PRE_sys_bind)(tid, ARG1,ARG2,ARG3); 4297 } 4298 4299 PRE(sys_listen) 4300 { 4301 PRINT("sys_listen ( %ld, %ld )",ARG1,ARG2); 4302 PRE_REG_READ2(long, "listen", int, s, int, backlog); 4303 } 4304 4305 PRE(sys_getsockname) 4306 { 4307 PRINT("sys_getsockname ( %ld, %#lx, %#lx )",ARG1,ARG2,ARG3); 4308 PRE_REG_READ3(long, "getsockname", 4309 int, s, struct sockaddr *, name, int *, namelen); 4310 ML_(generic_PRE_sys_getsockname)(tid, ARG1,ARG2,ARG3); 4311 } 4312 POST(sys_getsockname) 4313 { 4314 vg_assert(SUCCESS); 4315 ML_(generic_POST_sys_getsockname)(tid, VG_(mk_SysRes_Success)(RES), 4316 ARG1,ARG2,ARG3); 4317 } 4318 4319 PRE(sys_getpeername) 4320 { 4321 PRINT("sys_getpeername ( %ld, %#lx, %#lx )",ARG1,ARG2,ARG3); 4322 PRE_REG_READ3(long, "getpeername", 4323 int, s, struct sockaddr *, name, int *, namelen); 4324 ML_(generic_PRE_sys_getpeername)(tid, ARG1,ARG2,ARG3); 4325 } 4326 POST(sys_getpeername) 4327 { 4328 vg_assert(SUCCESS); 4329 ML_(generic_POST_sys_getpeername)(tid, VG_(mk_SysRes_Success)(RES), 4330 ARG1,ARG2,ARG3); 4331 } 4332 4333 PRE(sys_socketpair) 4334 { 4335 PRINT("sys_socketpair ( %ld, %ld, %ld, %#lx )",ARG1,ARG2,ARG3,ARG4); 4336 PRE_REG_READ4(long, "socketpair", 4337 int, d, int, type, int, protocol, int*, sv); 4338 ML_(generic_PRE_sys_socketpair)(tid, ARG1,ARG2,ARG3,ARG4); 4339 } 4340 POST(sys_socketpair) 4341 { 4342 vg_assert(SUCCESS); 4343 ML_(generic_POST_sys_socketpair)(tid, VG_(mk_SysRes_Success)(RES), 4344 ARG1,ARG2,ARG3,ARG4); 4345 } 4346 4347 4348 /* --------------------------------------------------------------------- 4349 *at wrappers 4350 ------------------------------------------------------------------ */ 4351 4352 PRE(sys_openat) 4353 { 4354 HChar name[30]; 4355 SysRes sres; 4356 4357 if (ARG3 & VKI_O_CREAT) { 4358 // 4-arg version 4359 PRINT("sys_openat ( %ld, %#lx(%s), %ld, %ld )",ARG1,ARG2,(char*)ARG2,ARG3,ARG4); 4360 PRE_REG_READ4(long, "openat", 4361 int, dfd, const char *, filename, int, flags, int, mode); 4362 } else { 4363 // 3-arg version 4364 PRINT("sys_openat ( %ld, %#lx(%s), %ld )",ARG1,ARG2,(char*)ARG2,ARG3); 4365 PRE_REG_READ3(long, "openat", 4366 int, dfd, const char *, filename, int, flags); 4367 } 4368 4369 PRE_MEM_RASCIIZ( "openat(filename)", ARG2 ); 4370 4371 /* For absolute filenames, dfd is ignored. If dfd is AT_FDCWD, 4372 filename is relative to cwd. */ 4373 if (ML_(safe_to_deref)( (void*)ARG2, 1 ) 4374 && *(Char *)ARG2 != '/' 4375 && ((Int)ARG1) != VKI_AT_FDCWD 4376 && !ML_(fd_allowed)(ARG1, "openat", tid, False)) 4377 SET_STATUS_Failure( VKI_EBADF ); 4378 4379 /* Handle the case where the open is of /proc/self/cmdline or 4380 /proc/<pid>/cmdline, and just give it a copy of the fd for the 4381 fake file we cooked up at startup (in m_main). Also, seek the 4382 cloned fd back to the start. */ 4383 4384 VG_(sprintf)(name, "/proc/%d/cmdline", VG_(getpid)()); 4385 if (ML_(safe_to_deref)( (void*)ARG2, 1 ) 4386 && (VG_(strcmp)((HChar *)ARG2, name) == 0 4387 || VG_(strcmp)((HChar *)ARG2, "/proc/self/cmdline") == 0)) { 4388 sres = VG_(dup)( VG_(cl_cmdline_fd) ); 4389 SET_STATUS_from_SysRes( sres ); 4390 if (!sr_isError(sres)) { 4391 OffT off = VG_(lseek)( sr_Res(sres), 0, VKI_SEEK_SET ); 4392 if (off < 0) 4393 SET_STATUS_Failure( VKI_EMFILE ); 4394 } 4395 return; 4396 } 4397 4398 /* Do the same for /proc/self/auxv or /proc/<pid>/auxv case. */ 4399 4400 VG_(sprintf)(name, "/proc/%d/auxv", VG_(getpid)()); 4401 if (ML_(safe_to_deref)( (void*)ARG2, 1 ) 4402 && (VG_(strcmp)((HChar *)ARG2, name) == 0 4403 || VG_(strcmp)((HChar *)ARG2, "/proc/self/auxv") == 0)) { 4404 sres = VG_(dup)( VG_(cl_auxv_fd) ); 4405 SET_STATUS_from_SysRes( sres ); 4406 if (!sr_isError(sres)) { 4407 OffT off = VG_(lseek)( sr_Res(sres), 0, VKI_SEEK_SET ); 4408 if (off < 0) 4409 SET_STATUS_Failure( VKI_EMFILE ); 4410 } 4411 return; 4412 } 4413 4414 /* Otherwise handle normally */ 4415 *flags |= SfMayBlock; 4416 } 4417 4418 POST(sys_openat) 4419 { 4420 vg_assert(SUCCESS); 4421 if (!ML_(fd_allowed)(RES, "openat", tid, True)) { 4422 VG_(close)(RES); 4423 SET_STATUS_Failure( VKI_EMFILE ); 4424 } else { 4425 if (VG_(clo_track_fds)) 4426 ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG2); 4427 } 4428 } 4429 4430 PRE(sys_mkdirat) 4431 { 4432 *flags |= SfMayBlock; 4433 PRINT("sys_mkdirat ( %ld, %#lx(%s), %ld )", ARG1,ARG2,(char*)ARG2,ARG3); 4434 PRE_REG_READ3(long, "mkdirat", 4435 int, dfd, const char *, pathname, int, mode); 4436 PRE_MEM_RASCIIZ( "mkdirat(pathname)", ARG2 ); 4437 } 4438 4439 PRE(sys_mknodat) 4440 { 4441 PRINT("sys_mknodat ( %ld, %#lx(%s), 0x%lx, 0x%lx )", ARG1,ARG2,(char*)ARG2,ARG3,ARG4 ); 4442 PRE_REG_READ4(long, "mknodat", 4443 int, dfd, const char *, pathname, int, mode, unsigned, dev); 4444 PRE_MEM_RASCIIZ( "mknodat(pathname)", ARG2 ); 4445 } 4446 4447 PRE(sys_fchownat) 4448 { 4449 PRINT("sys_fchownat ( %ld, %#lx(%s), 0x%lx, 0x%lx )", ARG1,ARG2,(char*)ARG2,ARG3,ARG4); 4450 PRE_REG_READ4(long, "fchownat", 4451 int, dfd, const char *, path, 4452 vki_uid_t, owner, vki_gid_t, group); 4453 PRE_MEM_RASCIIZ( "fchownat(path)", ARG2 ); 4454 } 4455 4456 PRE(sys_futimesat) 4457 { 4458 PRINT("sys_futimesat ( %ld, %#lx(%s), %#lx )", ARG1,ARG2,(char*)ARG2,ARG3); 4459 PRE_REG_READ3(long, "futimesat", 4460 int, dfd, char *, filename, struct timeval *, tvp); 4461 if (ARG2 != 0) 4462 PRE_MEM_RASCIIZ( "futimesat(filename)", ARG2 ); 4463 if (ARG3 != 0) 4464 PRE_MEM_READ( "futimesat(tvp)", ARG3, 2 * sizeof(struct vki_timeval) ); 4465 } 4466 4467 PRE(sys_utimensat) 4468 { 4469 PRINT("sys_utimensat ( %ld, %#lx(%s), %#lx, 0x%lx )", ARG1,ARG2,(char*)ARG2,ARG3,ARG4); 4470 PRE_REG_READ4(long, "utimensat", 4471 int, dfd, char *, filename, struct timespec *, utimes, int, flags); 4472 if (ARG2 != 0) 4473 PRE_MEM_RASCIIZ( "utimensat(filename)", ARG2 ); 4474 if (ARG3 != 0) 4475 PRE_MEM_READ( "utimensat(tvp)", ARG3, 2 * sizeof(struct vki_timespec) ); 4476 } 4477 4478 PRE(sys_newfstatat) 4479 { 4480 FUSE_COMPATIBLE_MAY_BLOCK(); 4481 PRINT("sys_newfstatat ( %ld, %#lx(%s), %#lx )", ARG1,ARG2,(char*)ARG2,ARG3); 4482 PRE_REG_READ3(long, "fstatat", 4483 int, dfd, char *, file_name, struct stat *, buf); 4484 PRE_MEM_RASCIIZ( "fstatat(file_name)", ARG2 ); 4485 PRE_MEM_WRITE( "fstatat(buf)", ARG3, sizeof(struct vki_stat) ); 4486 } 4487 4488 POST(sys_newfstatat) 4489 { 4490 POST_MEM_WRITE( ARG3, sizeof(struct vki_stat) ); 4491 } 4492 4493 PRE(sys_unlinkat) 4494 { 4495 *flags |= SfMayBlock; 4496 PRINT("sys_unlinkat ( %ld, %#lx(%s) )", ARG1,ARG2,(char*)ARG2); 4497 PRE_REG_READ2(long, "unlinkat", int, dfd, const char *, pathname); 4498 PRE_MEM_RASCIIZ( "unlinkat(pathname)", ARG2 ); 4499 } 4500 4501 PRE(sys_renameat) 4502 { 4503 PRINT("sys_renameat ( %ld, %#lx(%s), %ld, %#lx(%s) )", ARG1,ARG2,(char*)ARG2,ARG3,ARG4,(char*)ARG4); 4504 PRE_REG_READ4(long, "renameat", 4505 int, olddfd, const char *, oldpath, 4506 int, newdfd, const char *, newpath); 4507 PRE_MEM_RASCIIZ( "renameat(oldpath)", ARG2 ); 4508 PRE_MEM_RASCIIZ( "renameat(newpath)", ARG4 ); 4509 } 4510 4511 PRE(sys_linkat) 4512 { 4513 *flags |= SfMayBlock; 4514 PRINT("sys_linkat ( %ld, %#lx(%s), %ld, %#lx(%s), %ld )",ARG1,ARG2,(char*)ARG2,ARG3,ARG4,(char*)ARG4,ARG5); 4515 PRE_REG_READ5(long, "linkat", 4516 int, olddfd, const char *, oldpath, 4517 int, newdfd, const char *, newpath, 4518 int, flags); 4519 PRE_MEM_RASCIIZ( "linkat(oldpath)", ARG2); 4520 PRE_MEM_RASCIIZ( "linkat(newpath)", ARG4); 4521 } 4522 4523 PRE(sys_symlinkat) 4524 { 4525 *flags |= SfMayBlock; 4526 PRINT("sys_symlinkat ( %#lx(%s), %ld, %#lx(%s) )",ARG1,(char*)ARG1,ARG2,ARG3,(char*)ARG3); 4527 PRE_REG_READ3(long, "symlinkat", 4528 const char *, oldpath, int, newdfd, const char *, newpath); 4529 PRE_MEM_RASCIIZ( "symlinkat(oldpath)", ARG1 ); 4530 PRE_MEM_RASCIIZ( "symlinkat(newpath)", ARG3 ); 4531 } 4532 4533 PRE(sys_readlinkat) 4534 { 4535 HChar name[25]; 4536 Word saved = SYSNO; 4537 4538 PRINT("sys_readlinkat ( %ld, %#lx(%s), %#lx, %llu )", ARG1,ARG2,(char*)ARG2,ARG3,(ULong)ARG4); 4539 PRE_REG_READ4(long, "readlinkat", 4540 int, dfd, const char *, path, char *, buf, int, bufsiz); 4541 PRE_MEM_RASCIIZ( "readlinkat(path)", ARG2 ); 4542 PRE_MEM_WRITE( "readlinkat(buf)", ARG3,ARG4 ); 4543 4544 /* 4545 * Handle the case where readlinkat is looking at /proc/self/exe or 4546 * /proc/<pid>/exe. 4547 */ 4548 VG_(sprintf)(name, "/proc/%d/exe", VG_(getpid)()); 4549 if (ML_(safe_to_deref)((void*)ARG2, 1) 4550 && (VG_(strcmp)((HChar *)ARG2, name) == 0 4551 || VG_(strcmp)((HChar *)ARG2, "/proc/self/exe") == 0)) { 4552 VG_(sprintf)(name, "/proc/self/fd/%d", VG_(cl_exec_fd)); 4553 SET_STATUS_from_SysRes( VG_(do_syscall4)(saved, ARG1, (UWord)name, 4554 ARG3, ARG4)); 4555 } else { 4556 /* Normal case */ 4557 SET_STATUS_from_SysRes( VG_(do_syscall4)(saved, ARG1, ARG2, ARG3, ARG4)); 4558 } 4559 4560 if (SUCCESS && RES > 0) 4561 POST_MEM_WRITE( ARG3, RES ); 4562 } 4563 4564 PRE(sys_fchmodat) 4565 { 4566 PRINT("sys_fchmodat ( %ld, %#lx(%s), %ld )", ARG1,ARG2,(char*)ARG2,ARG3); 4567 PRE_REG_READ3(long, "fchmodat", 4568 int, dfd, const char *, path, vki_mode_t, mode); 4569 PRE_MEM_RASCIIZ( "fchmodat(path)", ARG2 ); 4570 } 4571 4572 PRE(sys_faccessat) 4573 { 4574 PRINT("sys_faccessat ( %ld, %#lx(%s), %ld )", ARG1,ARG2,(char*)ARG2,ARG3); 4575 PRE_REG_READ3(long, "faccessat", 4576 int, dfd, const char *, pathname, int, mode); 4577 PRE_MEM_RASCIIZ( "faccessat(pathname)", ARG2 ); 4578 } 4579 4580 PRE(sys_name_to_handle_at) 4581 { 4582 PRINT("sys_name_to_handle_at ( %ld, %#lx(%s), %#lx, %#lx, %ld )", ARG1, ARG2, (char*)ARG2, ARG3, ARG4, ARG5); 4583 PRE_REG_READ5(int, "name_to_handle_at", 4584 int, dfd, const char *, name, 4585 struct vki_file_handle *, handle, 4586 int *, mnt_id, int, flag); 4587 PRE_MEM_RASCIIZ( "name_to_handle_at(name)", ARG2 ); 4588 if (ML_(safe_to_deref)( (void*)ARG3, sizeof(struct vki_file_handle))) { 4589 struct vki_file_handle *fh = (struct vki_file_handle *)ARG3; 4590 PRE_MEM_READ( "name_to_handle_at(handle)", (Addr)&fh->handle_bytes, sizeof(fh->handle_bytes) ); 4591 PRE_MEM_WRITE( "name_to_handle_at(handle)", (Addr)fh, sizeof(struct vki_file_handle) + fh->handle_bytes ); 4592 } 4593 PRE_MEM_WRITE( "name_to_handle_at(mnt_id)", ARG4, sizeof(int) ); 4594 } 4595 4596 POST(sys_name_to_handle_at) 4597 { 4598 struct vki_file_handle *fh = (struct vki_file_handle *)ARG3; 4599 POST_MEM_WRITE( ARG3, sizeof(struct vki_file_handle) + fh->handle_bytes ); 4600 POST_MEM_WRITE( ARG4, sizeof(int) ); 4601 } 4602 4603 PRE(sys_open_by_handle_at) 4604 { 4605 *flags |= SfMayBlock; 4606 PRINT("sys_open_by_handle_at ( %ld, %#lx, %ld )", ARG1, ARG2, ARG3); 4607 PRE_REG_READ3(int, "open_by_handle_at", 4608 int, mountdirfd, 4609 struct vki_file_handle *, handle, 4610 int, flags); 4611 PRE_MEM_READ( "open_by_handle_at(handle)", ARG2, sizeof(struct vki_file_handle) + ((struct vki_file_handle*)ARG2)->handle_bytes ); 4612 } 4613 4614 POST(sys_open_by_handle_at) 4615 { 4616 vg_assert(SUCCESS); 4617 if (!ML_(fd_allowed)(RES, "open_by_handle_at", tid, True)) { 4618 VG_(close)(RES); 4619 SET_STATUS_Failure( VKI_EMFILE ); 4620 } else { 4621 if (VG_(clo_track_fds)) 4622 ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG2); 4623 } 4624 } 4625 4626 /* --------------------------------------------------------------------- 4627 p{read,write}v wrappers 4628 ------------------------------------------------------------------ */ 4629 4630 PRE(sys_preadv) 4631 { 4632 Int i; 4633 struct vki_iovec * vec; 4634 *flags |= SfMayBlock; 4635 #if VG_WORDSIZE == 4 4636 /* Note that the offset argument here is in lo+hi order on both 4637 big and little endian platforms... */ 4638 PRINT("sys_preadv ( %ld, %#lx, %llu, %lld )",ARG1,ARG2,(ULong)ARG3,LOHI64(ARG4,ARG5)); 4639 PRE_REG_READ5(ssize_t, "preadv", 4640 unsigned long, fd, const struct iovec *, vector, 4641 unsigned long, count, vki_u32, offset_low, 4642 vki_u32, offset_high); 4643 #elif VG_WORDSIZE == 8 4644 PRINT("sys_preadv ( %ld, %#lx, %llu, %lld )",ARG1,ARG2,(ULong)ARG3,(Long)ARG4); 4645 PRE_REG_READ4(ssize_t, "preadv", 4646 unsigned long, fd, const struct iovec *, vector, 4647 unsigned long, count, Word, offset); 4648 #else 4649 # error Unexpected word size 4650 #endif 4651 if (!ML_(fd_allowed)(ARG1, "preadv", tid, False)) { 4652 SET_STATUS_Failure( VKI_EBADF ); 4653 } else { 4654 PRE_MEM_READ( "preadv(vector)", ARG2, ARG3 * sizeof(struct vki_iovec) ); 4655 4656 if (ARG2 != 0) { 4657 /* ToDo: don't do any of the following if the vector is invalid */ 4658 vec = (struct vki_iovec *)ARG2; 4659 for (i = 0; i < (Int)ARG3; i++) 4660 PRE_MEM_WRITE( "preadv(vector[...])", 4661 (Addr)vec[i].iov_base, vec[i].iov_len ); 4662 } 4663 } 4664 } 4665 4666 POST(sys_preadv) 4667 { 4668 vg_assert(SUCCESS); 4669 if (RES > 0) { 4670 Int i; 4671 struct vki_iovec * vec = (struct vki_iovec *)ARG2; 4672 Int remains = RES; 4673 4674 /* RES holds the number of bytes read. */ 4675 for (i = 0; i < (Int)ARG3; i++) { 4676 Int nReadThisBuf = vec[i].iov_len; 4677 if (nReadThisBuf > remains) nReadThisBuf = remains; 4678 POST_MEM_WRITE( (Addr)vec[i].iov_base, nReadThisBuf ); 4679 remains -= nReadThisBuf; 4680 if (remains < 0) VG_(core_panic)("preadv: remains < 0"); 4681 } 4682 } 4683 } 4684 4685 PRE(sys_pwritev) 4686 { 4687 Int i; 4688 struct vki_iovec * vec; 4689 *flags |= SfMayBlock; 4690 #if VG_WORDSIZE == 4 4691 /* Note that the offset argument here is in lo+hi order on both 4692 big and little endian platforms... */ 4693 PRINT("sys_pwritev ( %ld, %#lx, %llu, %lld )",ARG1,ARG2,(ULong)ARG3,LOHI64(ARG4,ARG5)); 4694 PRE_REG_READ5(ssize_t, "pwritev", 4695 unsigned long, fd, const struct iovec *, vector, 4696 unsigned long, count, vki_u32, offset_low, 4697 vki_u32, offset_high); 4698 #elif VG_WORDSIZE == 8 4699 PRINT("sys_pwritev ( %ld, %#lx, %llu, %lld )",ARG1,ARG2,(ULong)ARG3,(Long)ARG4); 4700 PRE_REG_READ4(ssize_t, "pwritev", 4701 unsigned long, fd, const struct iovec *, vector, 4702 unsigned long, count, Word, offset); 4703 #else 4704 # error Unexpected word size 4705 #endif 4706 if (!ML_(fd_allowed)(ARG1, "pwritev", tid, False)) { 4707 SET_STATUS_Failure( VKI_EBADF ); 4708 } else { 4709 PRE_MEM_READ( "pwritev(vector)", 4710 ARG2, ARG3 * sizeof(struct vki_iovec) ); 4711 if (ARG2 != 0) { 4712 /* ToDo: don't do any of the following if the vector is invalid */ 4713 vec = (struct vki_iovec *)ARG2; 4714 for (i = 0; i < (Int)ARG3; i++) 4715 PRE_MEM_READ( "pwritev(vector[...])", 4716 (Addr)vec[i].iov_base, vec[i].iov_len ); 4717 } 4718 } 4719 } 4720 4721 /* --------------------------------------------------------------------- 4722 process_vm_{read,write}v wrappers 4723 ------------------------------------------------------------------ */ 4724 4725 PRE(sys_process_vm_readv) 4726 { 4727 PRINT("sys_process_vm_readv ( %lu, %#lx, %lu, %#lx, %lu, %lu )", 4728 ARG1, ARG2, ARG3, ARG4, ARG5, ARG6); 4729 PRE_REG_READ6(ssize_t, "process_vm_readv", 4730 vki_pid_t, pid, 4731 const struct iovec *, lvec, 4732 unsigned long, liovcnt, 4733 const struct iovec *, rvec, 4734 unsigned long, riovcnt, 4735 unsigned long, flags); 4736 PRE_MEM_READ( "process_vm_readv(lvec)", 4737 ARG2, ARG3 * sizeof(struct vki_iovec) ); 4738 PRE_MEM_READ( "process_vm_readv(rvec)", 4739 ARG4, ARG5 * sizeof(struct vki_iovec) ); 4740 if (ARG2 != 0) { 4741 /* TODO: Don't do any of the following if lvec is invalid */ 4742 const struct vki_iovec *vec = (const struct vki_iovec *)ARG2; 4743 UInt i; 4744 for (i = 0; i < ARG3; i++) 4745 PRE_MEM_WRITE( "process_vm_readv(lvec[...])", 4746 (Addr)vec[i].iov_base, vec[i].iov_len ); 4747 } 4748 } 4749 4750 POST(sys_process_vm_readv) 4751 { 4752 const struct vki_iovec *vec = (const struct vki_iovec *)ARG2; 4753 UInt remains = RES; 4754 UInt i; 4755 for (i = 0; i < ARG3; i++) { 4756 UInt nReadThisBuf = vec[i].iov_len <= remains ? 4757 vec[i].iov_len : remains; 4758 POST_MEM_WRITE( (Addr)vec[i].iov_base, nReadThisBuf ); 4759 remains -= nReadThisBuf; 4760 } 4761 } 4762 4763 PRE(sys_process_vm_writev) 4764 { 4765 PRINT("sys_process_vm_writev ( %lu, %#lx, %lu, %#lx, %lu, %lu )", 4766 ARG1, ARG2, ARG3, ARG4, ARG5, ARG6); 4767 PRE_REG_READ6(ssize_t, "process_vm_writev", 4768 vki_pid_t, pid, 4769 const struct iovec *, lvec, 4770 unsigned long, liovcnt, 4771 const struct iovec *, rvec, 4772 unsigned long, riovcnt, 4773 unsigned long, flags); 4774 PRE_MEM_READ( "process_vm_writev(lvec)", 4775 ARG2, ARG3 * sizeof(struct vki_iovec) ); 4776 PRE_MEM_READ( "process_vm_writev(rvec)", 4777 ARG4, ARG5 * sizeof(struct vki_iovec) ); 4778 if (ARG2 != 0) { 4779 /* TODO: Don't do any of the following if lvec is invalid */ 4780 const struct vki_iovec *vec = (const struct vki_iovec *)ARG2; 4781 UInt i; 4782 for (i = 0; i < ARG3; i++) 4783 PRE_MEM_READ( "process_vm_writev(lvec[...])", 4784 (Addr)vec[i].iov_base, vec[i].iov_len ); 4785 } 4786 } 4787 4788 /* --------------------------------------------------------------------- 4789 {send,recv}mmsg wrappers 4790 ------------------------------------------------------------------ */ 4791 4792 PRE(sys_sendmmsg) 4793 { 4794 struct vki_mmsghdr *mmsg = (struct vki_mmsghdr *)ARG2; 4795 HChar name[32]; 4796 UInt i; 4797 *flags |= SfMayBlock; 4798 PRINT("sys_sendmmsg ( %ld, %#lx, %ld, %ld )",ARG1,ARG2,ARG3,ARG4); 4799 PRE_REG_READ4(long, "sendmmsg", 4800 int, s, const struct mmsghdr *, mmsg, int, vlen, int, flags); 4801 for (i = 0; i < ARG3; i++) { 4802 VG_(sprintf)(name, "mmsg[%u].msg_hdr", i); 4803 ML_(generic_PRE_sys_sendmsg)(tid, name, &mmsg[i].msg_hdr); 4804 VG_(sprintf)(name, "sendmmsg(mmsg[%u].msg_len)", i); 4805 PRE_MEM_WRITE( name, (Addr)&mmsg[i].msg_len, sizeof(mmsg[i].msg_len) ); 4806 } 4807 } 4808 4809 POST(sys_sendmmsg) 4810 { 4811 if (RES > 0) { 4812 struct vki_mmsghdr *mmsg = (struct vki_mmsghdr *)ARG2; 4813 UInt i; 4814 for (i = 0; i < RES; i++) { 4815 POST_MEM_WRITE( (Addr)&mmsg[i].msg_len, sizeof(mmsg[i].msg_len) ); 4816 } 4817 } 4818 } 4819 4820 PRE(sys_recvmmsg) 4821 { 4822 struct vki_mmsghdr *mmsg = (struct vki_mmsghdr *)ARG2; 4823 HChar name[32]; 4824 UInt i; 4825 *flags |= SfMayBlock; 4826 PRINT("sys_recvmmsg ( %ld, %#lx, %ld, %ld, %#lx )",ARG1,ARG2,ARG3,ARG4,ARG5); 4827 PRE_REG_READ5(long, "recvmmsg", 4828 int, s, struct mmsghdr *, mmsg, int, vlen, 4829 int, flags, struct timespec *, timeout); 4830 for (i = 0; i < ARG3; i++) { 4831 VG_(sprintf)(name, "mmsg[%u].msg_hdr", i); 4832 ML_(generic_PRE_sys_recvmsg)(tid, name, &mmsg[i].msg_hdr); 4833 VG_(sprintf)(name, "recvmmsg(mmsg[%u].msg_len)", i); 4834 PRE_MEM_WRITE( name, (Addr)&mmsg[i].msg_len, sizeof(mmsg[i].msg_len) ); 4835 } 4836 if (ARG5) 4837 PRE_MEM_READ( "recvmmsg(timeout)", ARG5, sizeof(struct vki_timespec) ); 4838 } 4839 4840 POST(sys_recvmmsg) 4841 { 4842 if (RES > 0) { 4843 struct vki_mmsghdr *mmsg = (struct vki_mmsghdr *)ARG2; 4844 HChar name[32]; 4845 UInt i; 4846 for (i = 0; i < RES; i++) { 4847 VG_(sprintf)(name, "mmsg[%u].msg_hdr", i); 4848 ML_(generic_POST_sys_recvmsg)(tid, name, &mmsg[i].msg_hdr, mmsg[i].msg_len); 4849 POST_MEM_WRITE( (Addr)&mmsg[i].msg_len, sizeof(mmsg[i].msg_len) ); 4850 } 4851 } 4852 } 4853 4854 /* --------------------------------------------------------------------- 4855 key retention service wrappers 4856 ------------------------------------------------------------------ */ 4857 4858 PRE(sys_request_key) 4859 { 4860 PRINT("sys_request_key ( %#lx(%s), %#lx(%s), %#lx(%s), %ld )", 4861 ARG1,(char*)ARG1,ARG2,(char*)ARG2,ARG3,(char*)ARG3,ARG4); 4862 PRE_REG_READ4(long, "request_key", 4863 const char *, type, const char *, description, 4864 const char *, callout_info, vki_key_serial_t, keyring); 4865 PRE_MEM_RASCIIZ( "request_key(type)", ARG1); 4866 PRE_MEM_RASCIIZ( "request_key(description)", ARG2); 4867 if (ARG3 != (UWord)NULL) 4868 PRE_MEM_RASCIIZ( "request_key(callout_info)", ARG3); 4869 } 4870 4871 PRE(sys_add_key) 4872 { 4873 PRINT("sys_add_key ( %#lx(%s), %#lx(%s), %#lx, %ld, %ld )", 4874 ARG1,(char*)ARG1,ARG2,(char*)ARG2,ARG3,ARG4,ARG5); 4875 PRE_REG_READ5(long, "add_key", 4876 const char *, type, const char *, description, 4877 const void *, payload, vki_size_t, plen, 4878 vki_key_serial_t, keyring); 4879 PRE_MEM_RASCIIZ( "add_key(type)", ARG1); 4880 PRE_MEM_RASCIIZ( "add_key(description)", ARG2); 4881 if (ARG3 != (UWord)NULL) 4882 PRE_MEM_READ( "request_key(payload)", ARG3, ARG4); 4883 } 4884 4885 PRE(sys_keyctl) 4886 { 4887 switch (ARG1 /* option */) { 4888 case VKI_KEYCTL_GET_KEYRING_ID: 4889 PRINT("sys_keyctl ( KEYCTL_GET_KEYRING_ID, %ld, %ld )", ARG2,ARG3); 4890 PRE_REG_READ3(long, "keyctl(KEYCTL_GET_KEYRING_ID)", 4891 int, option, vki_key_serial_t, id, int, create); 4892 break; 4893 case VKI_KEYCTL_JOIN_SESSION_KEYRING: 4894 PRINT("sys_keyctl ( KEYCTL_JOIN_SESSION_KEYRING, %#lx(%s) )", ARG2,(char*)ARG2); 4895 PRE_REG_READ2(long, "keyctl(KEYCTL_JOIN_SESSION_KEYRING)", 4896 int, option, const char *, name); 4897 if (ARG2 != (UWord)NULL) 4898 PRE_MEM_RASCIIZ("keyctl(KEYCTL_JOIN_SESSION_KEYRING, name)", ARG2); 4899 break; 4900 case VKI_KEYCTL_UPDATE: 4901 PRINT("sys_keyctl ( KEYCTL_UPDATE, %ld, %#lx, %ld )", ARG2,ARG3,ARG4); 4902 PRE_REG_READ4(long, "keyctl(KEYCTL_UPDATE)", 4903 int, option, vki_key_serial_t, key, 4904 const void *, payload, vki_size_t, plen); 4905 if (ARG3 != (UWord)NULL) 4906 PRE_MEM_READ("keyctl(KEYCTL_UPDATE, payload)", ARG3, ARG4); 4907 break; 4908 case VKI_KEYCTL_REVOKE: 4909 PRINT("sys_keyctl ( KEYCTL_REVOKE, %ld )", ARG2); 4910 PRE_REG_READ2(long, "keyctl(KEYCTL_REVOKE)", 4911 int, option, vki_key_serial_t, id); 4912 break; 4913 case VKI_KEYCTL_CHOWN: 4914 PRINT("sys_keyctl ( KEYCTL_CHOWN, %ld, %ld, %ld )", ARG2,ARG3,ARG4); 4915 PRE_REG_READ4(long, "keyctl(KEYCTL_CHOWN)", 4916 int, option, vki_key_serial_t, id, 4917 vki_uid_t, uid, vki_gid_t, gid); 4918 break; 4919 case VKI_KEYCTL_SETPERM: 4920 PRINT("sys_keyctl ( KEYCTL_SETPERM, %ld, %ld )", ARG2,ARG3); 4921 PRE_REG_READ3(long, "keyctl(KEYCTL_SETPERM)", 4922 int, option, vki_key_serial_t, id, vki_key_perm_t, perm); 4923 break; 4924 case VKI_KEYCTL_DESCRIBE: 4925 PRINT("sys_keyctl ( KEYCTL_DESCRIBE, %ld, %#lx, %ld )", ARG2,ARG3,ARG4); 4926 PRE_REG_READ4(long, "keyctl(KEYCTL_DESCRIBE)", 4927 int, option, vki_key_serial_t, id, 4928 char *, buffer, vki_size_t, buflen); 4929 if (ARG3 != (UWord)NULL) 4930 PRE_MEM_WRITE("keyctl(KEYCTL_DESCRIBE, buffer)", ARG3, ARG4); 4931 break; 4932 case VKI_KEYCTL_CLEAR: 4933 PRINT("sys_keyctl ( KEYCTL_CLEAR, %ld )", ARG2); 4934 PRE_REG_READ2(long, "keyctl(KEYCTL_CLEAR)", 4935 int, option, vki_key_serial_t, keyring); 4936 break; 4937 case VKI_KEYCTL_LINK: 4938 PRINT("sys_keyctl ( KEYCTL_LINK, %ld, %ld )", ARG2,ARG3); 4939 PRE_REG_READ3(long, "keyctl(KEYCTL_LINK)", int, option, 4940 vki_key_serial_t, keyring, vki_key_serial_t, key); 4941 break; 4942 case VKI_KEYCTL_UNLINK: 4943 PRINT("sys_keyctl ( KEYCTL_UNLINK, %ld, %ld )", ARG2,ARG3); 4944 PRE_REG_READ3(long, "keyctl(KEYCTL_UNLINK)", int, option, 4945 vki_key_serial_t, keyring, vki_key_serial_t, key); 4946 break; 4947 case VKI_KEYCTL_SEARCH: 4948 PRINT("sys_keyctl ( KEYCTL_SEARCH, %ld, %#lx(%s), %#lx(%s), %ld )", 4949 ARG2,ARG3,(char*)ARG3,ARG4,(char*)ARG4,ARG5); 4950 PRE_REG_READ5(long, "keyctl(KEYCTL_SEARCH)", 4951 int, option, vki_key_serial_t, keyring, 4952 const char *, type, const char *, description, 4953 vki_key_serial_t, destring); 4954 PRE_MEM_RASCIIZ("sys_keyctl(KEYCTL_SEARCH, type)", ARG3); 4955 PRE_MEM_RASCIIZ("sys_keyctl(KEYCTL_SEARCH, description)", ARG4); 4956 break; 4957 case VKI_KEYCTL_READ: 4958 PRINT("sys_keyctl ( KEYCTL_READ, %ld, %#lx, %ld )", ARG2,ARG3,ARG4); 4959 PRE_REG_READ4(long, "keyctl(KEYCTL_READ)", 4960 int, option, vki_key_serial_t, keyring, 4961 char *, buffer, vki_size_t, buflen); 4962 if (ARG3 != (UWord)NULL) 4963 PRE_MEM_WRITE("keyctl(KEYCTL_READ, buffer)", ARG3, ARG4); 4964 break; 4965 case VKI_KEYCTL_INSTANTIATE: 4966 PRINT("sys_keyctl ( KEYCTL_INSTANTIATE, %ld, %#lx, %ld, %ld )", 4967 ARG2,ARG3,ARG4,ARG5); 4968 PRE_REG_READ5(long, "keyctl(KEYCTL_INSTANTIATE)", 4969 int, option, vki_key_serial_t, key, 4970 char *, payload, vki_size_t, plen, 4971 vki_key_serial_t, keyring); 4972 if (ARG3 != (UWord)NULL) 4973 PRE_MEM_READ("keyctl(KEYCTL_INSTANTIATE, payload)", ARG3, ARG4); 4974 break; 4975 case VKI_KEYCTL_NEGATE: 4976 PRINT("sys_keyctl ( KEYCTL_NEGATE, %ld, %lu, %ld )", ARG2,ARG3,ARG4); 4977 PRE_REG_READ4(long, "keyctl(KEYCTL_NEGATE)", 4978 int, option, vki_key_serial_t, key, 4979 unsigned, timeout, vki_key_serial_t, keyring); 4980 break; 4981 case VKI_KEYCTL_SET_REQKEY_KEYRING: 4982 PRINT("sys_keyctl ( KEYCTL_SET_REQKEY_KEYRING, %ld )", ARG2); 4983 PRE_REG_READ2(long, "keyctl(KEYCTL_SET_REQKEY_KEYRING)", 4984 int, option, int, reqkey_defl); 4985 break; 4986 case VKI_KEYCTL_SET_TIMEOUT: 4987 PRINT("sys_keyctl ( KEYCTL_SET_TIMEOUT, %ld, %ld )", ARG2,ARG3); 4988 PRE_REG_READ3(long, "keyctl(KEYCTL_SET_TIMEOUT)", 4989 int, option, vki_key_serial_t, key, unsigned, timeout); 4990 break; 4991 case VKI_KEYCTL_ASSUME_AUTHORITY: 4992 PRINT("sys_keyctl ( KEYCTL_ASSUME_AUTHORITY, %ld )", ARG2); 4993 PRE_REG_READ2(long, "keyctl(KEYCTL_ASSUME_AUTHORITY)", 4994 int, option, vki_key_serial_t, key); 4995 break; 4996 default: 4997 PRINT("sys_keyctl ( %ld ) ", ARG1); 4998 PRE_REG_READ1(long, "keyctl", int, option); 4999 break; 5000 } 5001 } 5002 5003 POST(sys_keyctl) 5004 { 5005 vg_assert(SUCCESS); 5006 switch (ARG1 /* option */) { 5007 case VKI_KEYCTL_DESCRIBE: 5008 case VKI_KEYCTL_READ: 5009 if (RES > ARG4) 5010 POST_MEM_WRITE(ARG3, ARG4); 5011 else 5012 POST_MEM_WRITE(ARG3, RES); 5013 break; 5014 default: 5015 break; 5016 } 5017 } 5018 5019 /* --------------------------------------------------------------------- 5020 ioprio_ wrappers 5021 ------------------------------------------------------------------ */ 5022 5023 PRE(sys_ioprio_set) 5024 { 5025 PRINT("sys_ioprio_set ( %ld, %ld, %ld )", ARG1,ARG2,ARG3); 5026 PRE_REG_READ3(int, "ioprio_set", int, which, int, who, int, ioprio); 5027 } 5028 5029 PRE(sys_ioprio_get) 5030 { 5031 PRINT("sys_ioprio_get ( %ld, %ld )", ARG1,ARG2); 5032 PRE_REG_READ2(int, "ioprio_get", int, which, int, who); 5033 } 5034 5035 /* --------------------------------------------------------------------- 5036 _module wrappers 5037 ------------------------------------------------------------------ */ 5038 5039 PRE(sys_init_module) 5040 { 5041 *flags |= SfMayBlock; 5042 PRINT("sys_init_module ( %#lx, %llu, %#lx(\"%s\") )", 5043 ARG1, (ULong)ARG2, ARG3, (char*)ARG3); 5044 PRE_REG_READ3(long, "init_module", 5045 void *, umod, unsigned long, len, const char *, uargs); 5046 PRE_MEM_READ( "init_module(umod)", ARG1, ARG2 ); 5047 PRE_MEM_RASCIIZ( "init_module(uargs)", ARG3 ); 5048 } 5049 5050 PRE(sys_delete_module) 5051 { 5052 *flags |= SfMayBlock; 5053 PRINT("sys_delete_module ( %#lx(\"%s\"), 0x%lx )", ARG1,(char*)ARG1, ARG2); 5054 PRE_REG_READ2(long, "delete_module", 5055 const char *, name_user, unsigned int, flags); 5056 PRE_MEM_RASCIIZ("delete_module(name_user)", ARG1); 5057 } 5058 5059 /* --------------------------------------------------------------------- 5060 splice wrappers 5061 ------------------------------------------------------------------ */ 5062 5063 PRE(sys_splice) 5064 { 5065 *flags |= SfMayBlock; 5066 PRINT("sys_splice ( %ld, %#lx, %ld, %#lx, %ld, %ld )", 5067 ARG1,ARG2,ARG3,ARG4,ARG5,ARG6); 5068 PRE_REG_READ6(vki_ssize_t, "splice", 5069 int, fd_in, vki_loff_t *, off_in, 5070 int, fd_out, vki_loff_t *, off_out, 5071 vki_size_t, len, unsigned int, flags); 5072 if (!ML_(fd_allowed)(ARG1, "splice(fd_in)", tid, False) || 5073 !ML_(fd_allowed)(ARG3, "splice(fd_out)", tid, False)) { 5074 SET_STATUS_Failure( VKI_EBADF ); 5075 } else { 5076 if (ARG2 != 0) 5077 PRE_MEM_READ( "splice(off_in)", ARG2, sizeof(vki_loff_t)); 5078 if (ARG4 != 0) 5079 PRE_MEM_READ( "splice(off_out)", ARG4, sizeof(vki_loff_t)); 5080 } 5081 } 5082 5083 PRE(sys_tee) 5084 { 5085 *flags |= SfMayBlock; 5086 PRINT("sys_tree ( %ld, %ld, %ld, %ld )", ARG1,ARG2,ARG3,ARG4); 5087 PRE_REG_READ4(vki_ssize_t, "tee", 5088 int, fd_in, int, fd_out, 5089 vki_size_t, len, unsigned int, flags); 5090 if (!ML_(fd_allowed)(ARG1, "tee(fd_in)", tid, False) || 5091 !ML_(fd_allowed)(ARG2, "tee(fd_out)", tid, False)) { 5092 SET_STATUS_Failure( VKI_EBADF ); 5093 } 5094 } 5095 5096 PRE(sys_vmsplice) 5097 { 5098 Int fdfl; 5099 *flags |= SfMayBlock; 5100 PRINT("sys_vmsplice ( %ld, %#lx, %ld, %ld )", 5101 ARG1,ARG2,ARG3,ARG4); 5102 PRE_REG_READ4(vki_ssize_t, "splice", 5103 int, fd, struct vki_iovec *, iov, 5104 unsigned long, nr_segs, unsigned int, flags); 5105 if (!ML_(fd_allowed)(ARG1, "vmsplice(fd)", tid, False)) { 5106 SET_STATUS_Failure( VKI_EBADF ); 5107 } else if ((fdfl = VG_(fcntl)(ARG1, VKI_F_GETFL, 0)) < 0) { 5108 SET_STATUS_Failure( VKI_EBADF ); 5109 } else { 5110 const struct vki_iovec *iov; 5111 PRE_MEM_READ( "vmsplice(iov)", ARG2, sizeof(struct vki_iovec) * ARG3 ); 5112 for (iov = (struct vki_iovec *)ARG2; 5113 iov < (struct vki_iovec *)ARG2 + ARG3; iov++) 5114 { 5115 if ((fdfl & VKI_O_ACCMODE) == VKI_O_RDONLY) 5116 PRE_MEM_WRITE( "vmsplice(iov[...])", (Addr)iov->iov_base, iov->iov_len ); 5117 else 5118 PRE_MEM_READ( "vmsplice(iov[...])", (Addr)iov->iov_base, iov->iov_len ); 5119 } 5120 } 5121 } 5122 5123 POST(sys_vmsplice) 5124 { 5125 vg_assert(SUCCESS); 5126 if (RES > 0) { 5127 Int fdfl = VG_(fcntl)(ARG1, VKI_F_GETFL, 0); 5128 vg_assert(fdfl >= 0); 5129 if ((fdfl & VKI_O_ACCMODE) == VKI_O_RDONLY) 5130 { 5131 const struct vki_iovec *iov; 5132 for (iov = (struct vki_iovec *)ARG2; 5133 iov < (struct vki_iovec *)ARG2 + ARG3; iov++) 5134 { 5135 POST_MEM_WRITE( (Addr)iov->iov_base, iov->iov_len ); 5136 } 5137 } 5138 } 5139 } 5140 5141 /* --------------------------------------------------------------------- 5142 oprofile-related wrappers 5143 ------------------------------------------------------------------ */ 5144 5145 #if defined(VGP_x86_linux) 5146 PRE(sys_lookup_dcookie) 5147 { 5148 PRINT("sys_lookup_dcookie (0x%llx, %#lx, %ld)", 5149 MERGE64(ARG1,ARG2), ARG3, ARG4); 5150 PRE_REG_READ4(long, "lookup_dcookie", 5151 vki_u32, MERGE64_FIRST(cookie), vki_u32, MERGE64_SECOND(cookie), 5152 char *, buf, vki_size_t, len); 5153 PRE_MEM_WRITE( "lookup_dcookie(buf)", ARG3, ARG4); 5154 } 5155 POST(sys_lookup_dcookie) 5156 { 5157 vg_assert(SUCCESS); 5158 if (ARG3 != (Addr)NULL) 5159 POST_MEM_WRITE( ARG3, RES); 5160 } 5161 #endif 5162 5163 #if defined(VGP_amd64_linux) || defined(VGP_s390x_linux) 5164 PRE(sys_lookup_dcookie) 5165 { 5166 *flags |= SfMayBlock; 5167 PRINT("sys_lookup_dcookie ( %llu, %#lx, %llu )", 5168 (ULong)ARG1, ARG2, (ULong)ARG3); 5169 PRE_REG_READ3(int, "lookup_dcookie", 5170 unsigned long long, cookie, char *, buf, vki_size_t, len); 5171 5172 PRE_MEM_WRITE( "sys_lookup_dcookie(buf)", ARG2, ARG3 ); 5173 } 5174 5175 POST(sys_lookup_dcookie) 5176 { 5177 vg_assert(SUCCESS); 5178 if (ARG2 != (Addr)NULL) 5179 POST_MEM_WRITE( ARG2, RES ); 5180 } 5181 #endif 5182 5183 /* --------------------------------------------------------------------- 5184 fcntl wrappers 5185 ------------------------------------------------------------------ */ 5186 5187 PRE(sys_fcntl) 5188 { 5189 switch (ARG2) { 5190 // These ones ignore ARG3. 5191 case VKI_F_GETFD: 5192 case VKI_F_GETFL: 5193 case VKI_F_GETOWN: 5194 case VKI_F_GETSIG: 5195 case VKI_F_GETLEASE: 5196 case VKI_F_GETPIPE_SZ: 5197 PRINT("sys_fcntl ( %ld, %ld )", ARG1,ARG2); 5198 PRE_REG_READ2(long, "fcntl", unsigned int, fd, unsigned int, cmd); 5199 break; 5200 5201 // These ones use ARG3 as "arg". 5202 case VKI_F_DUPFD: 5203 case VKI_F_DUPFD_CLOEXEC: 5204 case VKI_F_SETFD: 5205 case VKI_F_SETFL: 5206 case VKI_F_SETLEASE: 5207 case VKI_F_NOTIFY: 5208 case VKI_F_SETOWN: 5209 case VKI_F_SETSIG: 5210 case VKI_F_SETPIPE_SZ: 5211 PRINT("sys_fcntl[ARG3=='arg'] ( %ld, %ld, %ld )", ARG1,ARG2,ARG3); 5212 PRE_REG_READ3(long, "fcntl", 5213 unsigned int, fd, unsigned int, cmd, unsigned long, arg); 5214 break; 5215 5216 // These ones use ARG3 as "lock". 5217 case VKI_F_GETLK: 5218 case VKI_F_SETLK: 5219 case VKI_F_SETLKW: 5220 # if defined(VGP_x86_linux) || defined(VGP_mips64_linux) 5221 case VKI_F_GETLK64: 5222 case VKI_F_SETLK64: 5223 case VKI_F_SETLKW64: 5224 # endif 5225 PRINT("sys_fcntl[ARG3=='lock'] ( %ld, %ld, %#lx )", ARG1,ARG2,ARG3); 5226 PRE_REG_READ3(long, "fcntl", 5227 unsigned int, fd, unsigned int, cmd, 5228 struct flock64 *, lock); 5229 break; 5230 5231 case VKI_F_SETOWN_EX: 5232 PRINT("sys_fcntl[F_SETOWN_EX] ( %ld, %ld, %ld )", ARG1,ARG2,ARG3); 5233 PRE_REG_READ3(long, "fcntl", 5234 unsigned int, fd, unsigned int, cmd, 5235 struct vki_f_owner_ex *, arg); 5236 PRE_MEM_READ("fcntl(F_SETOWN_EX)", ARG3, sizeof(struct vki_f_owner_ex)); 5237 break; 5238 5239 case VKI_F_GETOWN_EX: 5240 PRINT("sys_fcntl[F_GETOWN_EX] ( %ld, %ld, %ld )", ARG1,ARG2,ARG3); 5241 PRE_REG_READ3(long, "fcntl", 5242 unsigned int, fd, unsigned int, cmd, 5243 struct vki_f_owner_ex *, arg); 5244 PRE_MEM_WRITE("fcntl(F_GETOWN_EX)", ARG3, sizeof(struct vki_f_owner_ex)); 5245 break; 5246 5247 case VKI_DRM_IOCTL_VERSION: 5248 if (ARG3) { 5249 struct vki_drm_version *data = (struct vki_drm_version *)ARG3; 5250 PRE_MEM_WRITE("ioctl(DRM_VERSION).version_major", (Addr)&data->version_major, sizeof(data->version_major)); 5251 PRE_MEM_WRITE("ioctl(DRM_VERSION).version_minor", (Addr)&data->version_minor, sizeof(data->version_minor)); 5252 PRE_MEM_WRITE("ioctl(DRM_VERSION).version_patchlevel", (Addr)&data->version_patchlevel, sizeof(data->version_patchlevel)); 5253 PRE_MEM_READ("ioctl(DRM_VERSION).name_len", (Addr)&data->name_len, sizeof(data->name_len)); 5254 PRE_MEM_READ("ioctl(DRM_VERSION).name", (Addr)&data->name, sizeof(data->name)); 5255 PRE_MEM_WRITE("ioctl(DRM_VERSION).name", (Addr)data->name, data->name_len); 5256 PRE_MEM_READ("ioctl(DRM_VERSION).date_len", (Addr)&data->date_len, sizeof(data->date_len)); 5257 PRE_MEM_READ("ioctl(DRM_VERSION).date", (Addr)&data->date, sizeof(data->date)); 5258 PRE_MEM_WRITE("ioctl(DRM_VERSION).date", (Addr)data->date, data->date_len); 5259 PRE_MEM_READ("ioctl(DRM_VERSION).desc_len", (Addr)&data->desc_len, sizeof(data->desc_len)); 5260 PRE_MEM_READ("ioctl(DRM_VERSION).desc", (Addr)&data->desc, sizeof(data->desc)); 5261 PRE_MEM_WRITE("ioctl(DRM_VERSION).desc", (Addr)data->desc, data->desc_len); 5262 } 5263 break; 5264 case VKI_DRM_IOCTL_GET_UNIQUE: 5265 if (ARG3) { 5266 struct vki_drm_unique *data = (struct vki_drm_unique *)ARG3; 5267 PRE_MEM_READ("ioctl(DRM_GET_UNIQUE).unique_len", (Addr)&data->unique_len, sizeof(data->unique_len)); 5268 PRE_MEM_READ("ioctl(DRM_GET_UNIQUE).unique", (Addr)&data->unique, sizeof(data->unique)); 5269 PRE_MEM_WRITE("ioctl(DRM_GET_UNIQUE).unique", (Addr)data->unique, data->unique_len); 5270 } 5271 break; 5272 case VKI_DRM_IOCTL_GET_MAGIC: 5273 if (ARG3) { 5274 struct vki_drm_auth *data = (struct vki_drm_auth *)ARG3; 5275 PRE_MEM_WRITE("ioctl(DRM_GET_MAGIC).magic", (Addr)&data->magic, sizeof(data->magic)); 5276 } 5277 break; 5278 case VKI_DRM_IOCTL_WAIT_VBLANK: 5279 if (ARG3) { 5280 union vki_drm_wait_vblank *data = (union vki_drm_wait_vblank *)ARG3; 5281 PRE_MEM_READ("ioctl(DRM_WAIT_VBLANK).request.type", (Addr)&data->request.type, sizeof(data->request.type)); 5282 PRE_MEM_READ("ioctl(DRM_WAIT_VBLANK).request.sequence", (Addr)&data->request.sequence, sizeof(data->request.sequence)); 5283 /* XXX: It seems request.signal isn't used */ 5284 PRE_MEM_WRITE("ioctl(DRM_WAIT_VBLANK).reply", (Addr)&data->reply, sizeof(data->reply)); 5285 } 5286 break; 5287 case VKI_DRM_IOCTL_GEM_CLOSE: 5288 if (ARG3) { 5289 struct vki_drm_gem_close *data = (struct vki_drm_gem_close *)ARG3; 5290 PRE_MEM_READ("ioctl(DRM_GEM_CLOSE).handle", (Addr)&data->handle, sizeof(data->handle)); 5291 } 5292 break; 5293 case VKI_DRM_IOCTL_GEM_FLINK: 5294 if (ARG3) { 5295 struct vki_drm_gem_flink *data = (struct vki_drm_gem_flink *)ARG3; 5296 PRE_MEM_READ("ioctl(DRM_GEM_FLINK).handle", (Addr)&data->handle, sizeof(data->handle)); 5297 PRE_MEM_WRITE("ioctl(DRM_GEM_FLINK).name", (Addr)&data->name, sizeof(data->name)); 5298 } 5299 break; 5300 case VKI_DRM_IOCTL_GEM_OPEN: 5301 if (ARG3) { 5302 struct vki_drm_gem_open *data = (struct vki_drm_gem_open *)ARG3; 5303 PRE_MEM_READ("ioctl(DRM_GEM_OPEN).name", (Addr)&data->name, sizeof(data->name)); 5304 PRE_MEM_WRITE("ioctl(DRM_GEM_OPEN).handle", (Addr)&data->handle, sizeof(data->handle)); 5305 PRE_MEM_WRITE("ioctl(DRM_GEM_OPEN).size", (Addr)&data->size, sizeof(data->size)); 5306 } 5307 break; 5308 case VKI_DRM_IOCTL_I915_GETPARAM: 5309 if (ARG3) { 5310 vki_drm_i915_getparam_t *data = (vki_drm_i915_getparam_t *)ARG3; 5311 PRE_MEM_READ("ioctl(DRM_I915_GETPARAM).param", (Addr)&data->param, sizeof(data->param)); 5312 PRE_MEM_WRITE("ioctl(DRM_I915_GETPARAM).value", (Addr)data->value, sizeof(int)); 5313 } 5314 break; 5315 case VKI_DRM_IOCTL_I915_GEM_BUSY: 5316 if (ARG3) { 5317 struct vki_drm_i915_gem_busy *data = (struct vki_drm_i915_gem_busy *)ARG3; 5318 PRE_MEM_READ("ioctl(DRM_I915_GEM_BUSY).handle", (Addr)&data->handle, sizeof(data->handle)); 5319 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_BUSY).busy", (Addr)&data->busy, sizeof(data->busy)); 5320 } 5321 break; 5322 case VKI_DRM_IOCTL_I915_GEM_CREATE: 5323 if (ARG3) { 5324 struct vki_drm_i915_gem_create *data = (struct vki_drm_i915_gem_create *)ARG3; 5325 PRE_MEM_READ("ioctl(DRM_I915_GEM_CREATE).size", (Addr)&data->size, sizeof(data->size)); 5326 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_CREATE).handle", (Addr)&data->handle, sizeof(data->handle)); 5327 } 5328 break; 5329 case VKI_DRM_IOCTL_I915_GEM_PREAD: 5330 if (ARG3) { 5331 struct vki_drm_i915_gem_pread *data = (struct vki_drm_i915_gem_pread *)ARG3; 5332 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).handle", (Addr)&data->handle, sizeof(data->handle)); 5333 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).offset", (Addr)&data->offset, sizeof(data->offset)); 5334 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).size", (Addr)&data->size, sizeof(data->size)); 5335 PRE_MEM_READ("ioctl(DRM_I915_GEM_PREAD).data_ptr", (Addr)&data->data_ptr, sizeof(data->data_ptr)); 5336 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_PREAD).data_ptr", (Addr)data->data_ptr, data->size); 5337 } 5338 break; 5339 case VKI_DRM_IOCTL_I915_GEM_PWRITE: 5340 if (ARG3) { 5341 struct vki_drm_i915_gem_pwrite *data = (struct vki_drm_i915_gem_pwrite *)ARG3; 5342 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).handle", (Addr)&data->handle, sizeof(data->handle)); 5343 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).offset", (Addr)&data->offset, sizeof(data->offset)); 5344 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).size", (Addr)&data->size, sizeof(data->size)); 5345 PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).data_ptr", (Addr)&data->data_ptr, sizeof(data->data_ptr)); 5346 /* PRE_MEM_READ("ioctl(DRM_I915_GEM_PWRITE).data_ptr", (Addr)data->data_ptr, data->size); 5347 * NB: the buffer is allowed to contain any amount of uninitialized data (e.g. 5348 * interleaved vertex attributes may have a wide stride with uninitialized data between 5349 * consecutive vertices) */ 5350 } 5351 break; 5352 case VKI_DRM_IOCTL_I915_GEM_MMAP_GTT: 5353 if (ARG3) { 5354 struct vki_drm_i915_gem_mmap_gtt *data = (struct vki_drm_i915_gem_mmap_gtt *)ARG3; 5355 PRE_MEM_READ("ioctl(DRM_I915_GEM_MMAP_GTT).handle", (Addr)&data->handle, sizeof(data->handle)); 5356 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_MMAP_GTT).offset", (Addr)&data->offset, sizeof(data->offset)); 5357 } 5358 break; 5359 case VKI_DRM_IOCTL_I915_GEM_SET_DOMAIN: 5360 if (ARG3) { 5361 struct vki_drm_i915_gem_set_domain *data = (struct vki_drm_i915_gem_set_domain *)ARG3; 5362 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_DOMAIN).handle", (Addr)&data->handle, sizeof(data->handle)); 5363 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_DOMAIN).read_domains", (Addr)&data->read_domains, sizeof(data->read_domains)); 5364 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_DOMAIN).write_domain", (Addr)&data->write_domain, sizeof(data->write_domain)); 5365 } 5366 break; 5367 case VKI_DRM_IOCTL_I915_GEM_SET_TILING: 5368 if (ARG3) { 5369 struct vki_drm_i915_gem_set_tiling *data = (struct vki_drm_i915_gem_set_tiling *)ARG3; 5370 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_TILING).handle", (Addr)&data->handle, sizeof(data->handle)); 5371 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_TILING).tiling_mode", (Addr)&data->tiling_mode, sizeof(data->tiling_mode)); 5372 PRE_MEM_READ("ioctl(DRM_I915_GEM_SET_TILING).stride", (Addr)&data->stride, sizeof(data->stride)); 5373 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_SET_TILING).swizzle_mode", (Addr)&data->swizzle_mode, sizeof(data->swizzle_mode)); 5374 } 5375 break; 5376 case VKI_DRM_IOCTL_I915_GEM_GET_TILING: 5377 if (ARG3) { 5378 struct vki_drm_i915_gem_get_tiling *data = (struct vki_drm_i915_gem_get_tiling *)ARG3; 5379 PRE_MEM_READ("ioctl(DRM_I915_GEM_GET_TILING).handle", (Addr)&data->handle, sizeof(data->handle)); 5380 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_TILING).tiling_mode", (Addr)&data->tiling_mode, sizeof(data->tiling_mode)); 5381 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_TILING).swizzle_mode", (Addr)&data->swizzle_mode, sizeof(data->swizzle_mode)); 5382 } 5383 break; 5384 case VKI_DRM_IOCTL_I915_GEM_GET_APERTURE: 5385 if (ARG3) { 5386 struct vki_drm_i915_gem_get_aperture *data = (struct vki_drm_i915_gem_get_aperture *)ARG3; 5387 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_APERTURE).aper_size", (Addr)&data->aper_size, sizeof(data->aper_size)); 5388 PRE_MEM_WRITE("ioctl(DRM_I915_GEM_GET_APERTURE).aper_available_size", (Addr)&data->aper_available_size, sizeof(data->aper_available_size)); 5389 } 5390 break; 5391 5392 default: 5393 PRINT("sys_fcntl[UNKNOWN] ( %ld, %ld, %ld )", ARG1,ARG2,ARG3); 5394 I_die_here; 5395 break; 5396 } 5397 5398 # if defined(VGP_x86_linux) 5399 if (ARG2 == VKI_F_SETLKW || ARG2 == VKI_F_SETLKW64) 5400 # else 5401 if (ARG2 == VKI_F_SETLKW) 5402 # endif 5403 *flags |= SfMayBlock; 5404 } 5405 5406 POST(sys_fcntl) 5407 { 5408 vg_assert(SUCCESS); 5409 if (ARG2 == VKI_F_DUPFD) { 5410 if (!ML_(fd_allowed)(RES, "fcntl(DUPFD)", tid, True)) { 5411 VG_(close)(RES); 5412 SET_STATUS_Failure( VKI_EMFILE ); 5413 } else { 5414 if (VG_(clo_track_fds)) 5415 ML_(record_fd_open_named)(tid, RES); 5416 } 5417 } 5418 else if (ARG2 == VKI_F_DUPFD_CLOEXEC) { 5419 if (!ML_(fd_allowed)(RES, "fcntl(DUPFD_CLOEXEC)", tid, True)) { 5420 VG_(close)(RES); 5421 SET_STATUS_Failure( VKI_EMFILE ); 5422 } else { 5423 if (VG_(clo_track_fds)) 5424 ML_(record_fd_open_named)(tid, RES); 5425 } 5426 } else if (ARG2 == VKI_F_GETOWN_EX) { 5427 POST_MEM_WRITE(ARG3, sizeof(struct vki_f_owner_ex)); 5428 } 5429 } 5430 5431 // XXX: wrapper only suitable for 32-bit systems 5432 PRE(sys_fcntl64) 5433 { 5434 switch (ARG2) { 5435 // These ones ignore ARG3. 5436 case VKI_F_GETFD: 5437 case VKI_F_GETFL: 5438 case VKI_F_GETOWN: 5439 case VKI_F_SETOWN: 5440 case VKI_F_GETSIG: 5441 case VKI_F_SETSIG: 5442 case VKI_F_GETLEASE: 5443 PRINT("sys_fcntl64 ( %ld, %ld )", ARG1,ARG2); 5444 PRE_REG_READ2(long, "fcntl64", unsigned int, fd, unsigned int, cmd); 5445 break; 5446 5447 // These ones use ARG3 as "arg". 5448 case VKI_F_DUPFD: 5449 case VKI_F_DUPFD_CLOEXEC: 5450 case VKI_F_SETFD: 5451 case VKI_F_SETFL: 5452 case VKI_F_SETLEASE: 5453 case VKI_F_NOTIFY: 5454 PRINT("sys_fcntl64[ARG3=='arg'] ( %ld, %ld, %ld )", ARG1,ARG2,ARG3); 5455 PRE_REG_READ3(long, "fcntl64", 5456 unsigned int, fd, unsigned int, cmd, unsigned long, arg); 5457 break; 5458 5459 // These ones use ARG3 as "lock". 5460 case VKI_F_GETLK: 5461 case VKI_F_SETLK: 5462 case VKI_F_SETLKW: 5463 # if defined(VGP_x86_linux) 5464 case VKI_F_GETLK64: 5465 case VKI_F_SETLK64: 5466 case VKI_F_SETLKW64: 5467 # endif 5468 PRINT("sys_fcntl64[ARG3=='lock'] ( %ld, %ld, %#lx )", ARG1,ARG2,ARG3); 5469 PRE_REG_READ3(long, "fcntl64", 5470 unsigned int, fd, unsigned int, cmd, 5471 struct flock64 *, lock); 5472 break; 5473 5474 case VKI_F_SETOWN_EX: 5475 PRINT("sys_fcntl[F_SETOWN_EX] ( %ld, %ld, %ld )", ARG1,ARG2,ARG3); 5476 PRE_REG_READ3(long, "fcntl", 5477 unsigned int, fd, unsigned int, cmd, 5478 struct vki_f_owner_ex *, arg); 5479 PRE_MEM_READ("fcntl(F_SETOWN_EX)", ARG3, sizeof(struct vki_f_owner_ex)); 5480 break; 5481 5482 case VKI_F_GETOWN_EX: 5483 PRINT("sys_fcntl[F_GETOWN_EX] ( %ld, %ld, %ld )", ARG1,ARG2,ARG3); 5484 PRE_REG_READ3(long, "fcntl", 5485 unsigned int, fd, unsigned int, cmd, 5486 struct vki_f_owner_ex *, arg); 5487 PRE_MEM_WRITE("fcntl(F_GETOWN_EX)", ARG3, sizeof(struct vki_f_owner_ex)); 5488 break; 5489 } 5490 5491 # if defined(VGP_x86_linux) 5492 if (ARG2 == VKI_F_SETLKW || ARG2 == VKI_F_SETLKW64) 5493 # else 5494 if (ARG2 == VKI_F_SETLKW) 5495 # endif 5496 *flags |= SfMayBlock; 5497 } 5498 5499 POST(sys_fcntl64) 5500 { 5501 vg_assert(SUCCESS); 5502 if (ARG2 == VKI_F_DUPFD) { 5503 if (!ML_(fd_allowed)(RES, "fcntl64(DUPFD)", tid, True)) { 5504 VG_(close)(RES); 5505 SET_STATUS_Failure( VKI_EMFILE ); 5506 } else { 5507 if (VG_(clo_track_fds)) 5508 ML_(record_fd_open_named)(tid, RES); 5509 } 5510 } 5511 else if (ARG2 == VKI_F_DUPFD_CLOEXEC) { 5512 if (!ML_(fd_allowed)(RES, "fcntl64(DUPFD_CLOEXEC)", tid, True)) { 5513 VG_(close)(RES); 5514 SET_STATUS_Failure( VKI_EMFILE ); 5515 } else { 5516 if (VG_(clo_track_fds)) 5517 ML_(record_fd_open_named)(tid, RES); 5518 } 5519 } else if (ARG2 == VKI_F_GETOWN_EX) { 5520 POST_MEM_WRITE(ARG3, sizeof(struct vki_f_owner_ex)); 5521 } 5522 } 5523 5524 /* --------------------------------------------------------------------- 5525 ioctl wrappers 5526 ------------------------------------------------------------------ */ 5527 5528 PRE(sys_ioctl) 5529 { 5530 *flags |= SfMayBlock; 5531 5532 // We first handle the ones that don't use ARG3 (even as a 5533 // scalar/non-pointer argument). 5534 switch (ARG2 /* request */) { 5535 5536 /* asm-generic/ioctls.h */ 5537 case VKI_FIOCLEX: 5538 case VKI_FIONCLEX: 5539 5540 /* linux/soundcard interface (ALSA) */ 5541 case VKI_SNDRV_PCM_IOCTL_HW_FREE: 5542 case VKI_SNDRV_PCM_IOCTL_HWSYNC: 5543 case VKI_SNDRV_PCM_IOCTL_PREPARE: 5544 case VKI_SNDRV_PCM_IOCTL_RESET: 5545 case VKI_SNDRV_PCM_IOCTL_START: 5546 case VKI_SNDRV_PCM_IOCTL_DROP: 5547 case VKI_SNDRV_PCM_IOCTL_DRAIN: 5548 case VKI_SNDRV_PCM_IOCTL_RESUME: 5549 case VKI_SNDRV_PCM_IOCTL_XRUN: 5550 case VKI_SNDRV_PCM_IOCTL_UNLINK: 5551 case VKI_SNDRV_TIMER_IOCTL_START: 5552 case VKI_SNDRV_TIMER_IOCTL_STOP: 5553 case VKI_SNDRV_TIMER_IOCTL_CONTINUE: 5554 case VKI_SNDRV_TIMER_IOCTL_PAUSE: 5555 5556 /* SCSI no operand */ 5557 case VKI_SCSI_IOCTL_DOORLOCK: 5558 case VKI_SCSI_IOCTL_DOORUNLOCK: 5559 5560 /* KVM ioctls that dont check for a numeric value as parameter */ 5561 case VKI_KVM_S390_ENABLE_SIE: 5562 case VKI_KVM_CREATE_IRQCHIP: 5563 case VKI_KVM_S390_INITIAL_RESET: 5564 5565 /* vhost without parameter */ 5566 case VKI_VHOST_SET_OWNER: 5567 case VKI_VHOST_RESET_OWNER: 5568 5569 /* User input device creation */ 5570 case VKI_UI_DEV_CREATE: 5571 case VKI_UI_DEV_DESTROY: 5572 5573 /* InfiniBand */ 5574 case VKI_IB_USER_MAD_ENABLE_PKEY: 5575 PRINT("sys_ioctl ( %ld, 0x%lx )",ARG1,ARG2); 5576 PRE_REG_READ2(long, "ioctl", 5577 unsigned int, fd, unsigned int, request); 5578 return; 5579 5580 case VKI_DRM_IOCTL_VERSION: 5581 if (ARG3) { 5582 struct vki_drm_version *data = (struct vki_drm_version *)ARG3; 5583 POST_MEM_WRITE((Addr)&data->version_major, sizeof(data->version_major)); 5584 POST_MEM_WRITE((Addr)&data->version_minor, sizeof(data->version_minor)); 5585 POST_MEM_WRITE((Addr)&data->version_patchlevel, sizeof(data->version_patchlevel)); 5586 POST_MEM_WRITE((Addr)&data->name_len, sizeof(data->name_len)); 5587 POST_MEM_WRITE((Addr)data->name, data->name_len); 5588 POST_MEM_WRITE((Addr)&data->date_len, sizeof(data->date_len)); 5589 POST_MEM_WRITE((Addr)data->date, data->date_len); 5590 POST_MEM_WRITE((Addr)&data->desc_len, sizeof(data->desc_len)); 5591 POST_MEM_WRITE((Addr)data->desc, data->desc_len); 5592 } 5593 break; 5594 case VKI_DRM_IOCTL_GET_UNIQUE: 5595 if (ARG3) { 5596 struct vki_drm_unique *data = (struct vki_drm_unique *)ARG3; 5597 POST_MEM_WRITE((Addr)data->unique, sizeof(data->unique_len)); 5598 } 5599 break; 5600 case VKI_DRM_IOCTL_GET_MAGIC: 5601 if (ARG3) { 5602 struct vki_drm_auth *data = (struct vki_drm_auth *)ARG3; 5603 POST_MEM_WRITE((Addr)&data->magic, sizeof(data->magic)); 5604 } 5605 break; 5606 case VKI_DRM_IOCTL_WAIT_VBLANK: 5607 if (ARG3) { 5608 union vki_drm_wait_vblank *data = (union vki_drm_wait_vblank *)ARG3; 5609 POST_MEM_WRITE((Addr)&data->reply, sizeof(data->reply)); 5610 } 5611 break; 5612 case VKI_DRM_IOCTL_GEM_FLINK: 5613 if (ARG3) { 5614 struct vki_drm_gem_flink *data = (struct vki_drm_gem_flink *)ARG3; 5615 POST_MEM_WRITE((Addr)&data->name, sizeof(data->name)); 5616 } 5617 break; 5618 case VKI_DRM_IOCTL_GEM_OPEN: 5619 if (ARG3) { 5620 struct vki_drm_gem_open *data = (struct vki_drm_gem_open *)ARG3; 5621 POST_MEM_WRITE((Addr)&data->handle, sizeof(data->handle)); 5622 POST_MEM_WRITE((Addr)&data->size, sizeof(data->size)); 5623 } 5624 break; 5625 case VKI_DRM_IOCTL_I915_GETPARAM: 5626 if (ARG3) { 5627 vki_drm_i915_getparam_t *data = (vki_drm_i915_getparam_t *)ARG3; 5628 POST_MEM_WRITE((Addr)data->value, sizeof(int)); 5629 } 5630 break; 5631 case VKI_DRM_IOCTL_I915_GEM_BUSY: 5632 if (ARG3) { 5633 struct vki_drm_i915_gem_busy *data = (struct vki_drm_i915_gem_busy *)ARG3; 5634 POST_MEM_WRITE((Addr)&data->busy, sizeof(data->busy)); 5635 } 5636 break; 5637 case VKI_DRM_IOCTL_I915_GEM_CREATE: 5638 if (ARG3) { 5639 struct vki_drm_i915_gem_create *data = (struct vki_drm_i915_gem_create *)ARG3; 5640 POST_MEM_WRITE((Addr)&data->handle, sizeof(data->handle)); 5641 } 5642 break; 5643 case VKI_DRM_IOCTL_I915_GEM_PREAD: 5644 if (ARG3) { 5645 struct vki_drm_i915_gem_pread *data = (struct vki_drm_i915_gem_pread *)ARG3; 5646 POST_MEM_WRITE((Addr)data->data_ptr, data->size); 5647 } 5648 break; 5649 case VKI_DRM_IOCTL_I915_GEM_MMAP_GTT: 5650 if (ARG3) { 5651 struct vki_drm_i915_gem_mmap_gtt *data = (struct vki_drm_i915_gem_mmap_gtt *)ARG3; 5652 POST_MEM_WRITE((Addr)&data->offset, sizeof(data->offset)); 5653 } 5654 break; 5655 case VKI_DRM_IOCTL_I915_GEM_SET_TILING: 5656 if (ARG3) { 5657 struct vki_drm_i915_gem_set_tiling *data = (struct vki_drm_i915_gem_set_tiling *)ARG3; 5658 POST_MEM_WRITE((Addr)&data->tiling_mode, sizeof(data->tiling_mode)); 5659 POST_MEM_WRITE((Addr)&data->stride, sizeof(data->stride)); 5660 POST_MEM_WRITE((Addr)&data->swizzle_mode, sizeof(data->swizzle_mode)); 5661 } 5662 break; 5663 case VKI_DRM_IOCTL_I915_GEM_GET_TILING: 5664 if (ARG3) { 5665 struct vki_drm_i915_gem_get_tiling *data = (struct vki_drm_i915_gem_get_tiling *)ARG3; 5666 POST_MEM_WRITE((Addr)&data->tiling_mode, sizeof(data->tiling_mode)); 5667 POST_MEM_WRITE((Addr)&data->swizzle_mode, sizeof(data->swizzle_mode)); 5668 } 5669 break; 5670 case VKI_DRM_IOCTL_I915_GEM_GET_APERTURE: 5671 if (ARG3) { 5672 struct vki_drm_i915_gem_get_aperture *data = (struct vki_drm_i915_gem_get_aperture *)ARG3; 5673 POST_MEM_WRITE((Addr)&data->aper_size, sizeof(data->aper_size)); 5674 POST_MEM_WRITE((Addr)&data->aper_available_size, sizeof(data->aper_available_size)); 5675 } 5676 break; 5677 5678 default: 5679 PRINT("sys_ioctl ( %ld, 0x%lx, 0x%lx )",ARG1,ARG2,ARG3); 5680 PRE_REG_READ3(long, "ioctl", 5681 unsigned int, fd, unsigned int, request, unsigned long, arg); 5682 break; 5683 } 5684 5685 5686 # if defined(ANDROID_HARDWARE_nexus_10) 5687 5688 /* undocumented ioctl ids noted on the device */ 5689 if (ARG2 >= 0xc0108000 && ARG2 <= 0xc1e8820b && ARG3 != 0) { 5690 int size = (ARG2 >> 16) & 0x3fff; 5691 PRE_MEM_WRITE("ioctl(GL_UNDOCUMENTED)", (Addr)ARG3, size); 5692 return; 5693 } 5694 5695 # endif 5696 5697 5698 # if defined(ANDROID_HARDWARE_nexus_10) 5699 5700 /* undocumented ioctl ids noted on the device */ 5701 if (ARG2 >= 0xc0108000 && ARG2 <= 0xc1e8820b && ARG3 != 0) { 5702 int size = (ARG2 >> 16) & 0x3fff; 5703 PRE_MEM_WRITE("ioctl(GL_UNDOCUMENTED)", (Addr)ARG3, size); 5704 return; 5705 } 5706 5707 # endif 5708 5709 // We now handle those that do look at ARG3 (and unknown ones fall into 5710 // this category). Nb: some of these may well belong in the 5711 // doesn't-use-ARG3 switch above. 5712 switch (ARG2 /* request */) { 5713 case VKI_TCSETS: 5714 case VKI_TCSETSW: 5715 case VKI_TCSETSF: 5716 PRE_MEM_READ( "ioctl(TCSET{S,SW,SF})", ARG3, sizeof(struct vki_termios) ); 5717 break; 5718 case VKI_TCGETS: 5719 PRE_MEM_WRITE( "ioctl(TCGETS)", ARG3, sizeof(struct vki_termios) ); 5720 break; 5721 case VKI_TCSETA: 5722 case VKI_TCSETAW: 5723 case VKI_TCSETAF: 5724 PRE_MEM_READ( "ioctl(TCSET{A,AW,AF})", ARG3, sizeof(struct vki_termio) ); 5725 break; 5726 case VKI_TCGETA: 5727 PRE_MEM_WRITE( "ioctl(TCGETA)", ARG3, sizeof(struct vki_termio) ); 5728 break; 5729 case VKI_TCSBRK: 5730 case VKI_TCXONC: 5731 case VKI_TCSBRKP: 5732 case VKI_TCFLSH: 5733 /* These just take an int by value */ 5734 break; 5735 case VKI_TIOCGWINSZ: 5736 PRE_MEM_WRITE( "ioctl(TIOCGWINSZ)", ARG3, sizeof(struct vki_winsize) ); 5737 break; 5738 case VKI_TIOCSWINSZ: 5739 PRE_MEM_READ( "ioctl(TIOCSWINSZ)", ARG3, sizeof(struct vki_winsize) ); 5740 break; 5741 case VKI_TIOCMBIS: 5742 PRE_MEM_READ( "ioctl(TIOCMBIS)", ARG3, sizeof(unsigned int) ); 5743 break; 5744 case VKI_TIOCMBIC: 5745 PRE_MEM_READ( "ioctl(TIOCMBIC)", ARG3, sizeof(unsigned int) ); 5746 break; 5747 case VKI_TIOCMSET: 5748 PRE_MEM_READ( "ioctl(TIOCMSET)", ARG3, sizeof(unsigned int) ); 5749 break; 5750 case VKI_TIOCMGET: 5751 PRE_MEM_WRITE( "ioctl(TIOCMGET)", ARG3, sizeof(unsigned int) ); 5752 break; 5753 case VKI_TIOCLINUX: 5754 PRE_MEM_READ( "ioctl(TIOCLINUX)", ARG3, sizeof(char *) ); 5755 if (*(char *)ARG3 == 11) { 5756 PRE_MEM_READ( "ioctl(TIOCLINUX, 11)", ARG3, 2 * sizeof(char *) ); 5757 } 5758 break; 5759 case VKI_TIOCGPGRP: 5760 /* Get process group ID for foreground processing group. */ 5761 PRE_MEM_WRITE( "ioctl(TIOCGPGRP)", ARG3, sizeof(vki_pid_t) ); 5762 break; 5763 case VKI_TIOCSPGRP: 5764 /* Set a process group ID? */ 5765 PRE_MEM_WRITE( "ioctl(TIOCGPGRP)", ARG3, sizeof(vki_pid_t) ); 5766 break; 5767 case VKI_TIOCGPTN: /* Get Pty Number (of pty-mux device) */ 5768 PRE_MEM_WRITE( "ioctl(TIOCGPTN)", ARG3, sizeof(int) ); 5769 break; 5770 case VKI_TIOCSCTTY: 5771 /* Just takes an int value. */ 5772 break; 5773 case VKI_TIOCSPTLCK: /* Lock/unlock Pty */ 5774 PRE_MEM_READ( "ioctl(TIOCSPTLCK)", ARG3, sizeof(int) ); 5775 break; 5776 case VKI_FIONBIO: 5777 PRE_MEM_READ( "ioctl(FIONBIO)", ARG3, sizeof(int) ); 5778 break; 5779 case VKI_FIOASYNC: 5780 PRE_MEM_READ( "ioctl(FIOASYNC)", ARG3, sizeof(int) ); 5781 break; 5782 case VKI_FIONREAD: /* identical to SIOCINQ */ 5783 PRE_MEM_WRITE( "ioctl(FIONREAD)", ARG3, sizeof(int) ); 5784 break; 5785 case VKI_FIOQSIZE: 5786 PRE_MEM_WRITE( "ioctl(FIOQSIZE)", ARG3, sizeof(vki_loff_t) ); 5787 break; 5788 5789 case VKI_TIOCSERGETLSR: 5790 PRE_MEM_WRITE( "ioctl(TIOCSERGETLSR)", ARG3, sizeof(int) ); 5791 break; 5792 case VKI_TIOCGICOUNT: 5793 PRE_MEM_WRITE( "ioctl(TIOCGICOUNT)", ARG3, 5794 sizeof(struct vki_serial_icounter_struct) ); 5795 break; 5796 5797 case VKI_SG_SET_COMMAND_Q: 5798 PRE_MEM_READ( "ioctl(SG_SET_COMMAND_Q)", ARG3, sizeof(int) ); 5799 break; 5800 case VKI_SG_IO: 5801 PRE_MEM_WRITE( "ioctl(SG_IO)", ARG3, sizeof(vki_sg_io_hdr_t) ); 5802 break; 5803 case VKI_SG_GET_SCSI_ID: 5804 PRE_MEM_WRITE( "ioctl(SG_GET_SCSI_ID)", ARG3, sizeof(vki_sg_scsi_id_t) ); 5805 break; 5806 case VKI_SG_SET_RESERVED_SIZE: 5807 PRE_MEM_READ( "ioctl(SG_SET_RESERVED_SIZE)", ARG3, sizeof(int) ); 5808 break; 5809 case VKI_SG_SET_TIMEOUT: 5810 PRE_MEM_READ( "ioctl(SG_SET_TIMEOUT)", ARG3, sizeof(int) ); 5811 break; 5812 case VKI_SG_GET_RESERVED_SIZE: 5813 PRE_MEM_WRITE( "ioctl(SG_GET_RESERVED_SIZE)", ARG3, sizeof(int) ); 5814 break; 5815 case VKI_SG_GET_TIMEOUT: 5816 break; 5817 case VKI_SG_GET_VERSION_NUM: 5818 PRE_MEM_WRITE( "ioctl(SG_GET_VERSION_NUM)", ARG3, sizeof(int) ); 5819 break; 5820 case VKI_SG_EMULATED_HOST: /* 0x2203 */ 5821 PRE_MEM_WRITE( "ioctl(SG_EMULATED_HOST)", ARG3, sizeof(int) ); 5822 break; 5823 case VKI_SG_GET_SG_TABLESIZE: /* 0x227f */ 5824 PRE_MEM_WRITE( "ioctl(SG_GET_SG_TABLESIZE)", ARG3, sizeof(int) ); 5825 break; 5826 5827 case VKI_IIOCGETCPS: 5828 PRE_MEM_WRITE( "ioctl(IIOCGETCPS)", ARG3, 5829 VKI_ISDN_MAX_CHANNELS * 2 * sizeof(unsigned long) ); 5830 break; 5831 case VKI_IIOCNETGPN: 5832 PRE_MEM_READ( "ioctl(IIOCNETGPN)", 5833 (Addr)&((vki_isdn_net_ioctl_phone *)ARG3)->name, 5834 sizeof(((vki_isdn_net_ioctl_phone *)ARG3)->name) ); 5835 PRE_MEM_WRITE( "ioctl(IIOCNETGPN)", ARG3, 5836 sizeof(vki_isdn_net_ioctl_phone) ); 5837 break; 5838 5839 /* These all use struct ifreq AFAIK */ 5840 case VKI_SIOCGIFINDEX: /* get iface index */ 5841 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFINDEX)", 5842 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5843 PRE_MEM_WRITE( "ioctl(SIOCGIFINDEX)", ARG3, sizeof(struct vki_ifreq)); 5844 break; 5845 case VKI_SIOCGIFFLAGS: /* get flags */ 5846 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFFLAGS)", 5847 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5848 PRE_MEM_WRITE( "ioctl(SIOCGIFFLAGS)", ARG3, sizeof(struct vki_ifreq)); 5849 break; 5850 case VKI_SIOCGIFHWADDR: /* Get hardware address */ 5851 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFHWADDR)", 5852 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5853 PRE_MEM_WRITE( "ioctl(SIOCGIFHWADDR)", ARG3, sizeof(struct vki_ifreq)); 5854 break; 5855 case VKI_SIOCGIFMTU: /* get MTU size */ 5856 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMTU)", 5857 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5858 PRE_MEM_WRITE( "ioctl(SIOCGIFMTU)", ARG3, sizeof(struct vki_ifreq)); 5859 break; 5860 case VKI_SIOCGIFADDR: /* get PA address */ 5861 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFADDR)", 5862 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5863 PRE_MEM_WRITE( "ioctl(SIOCGIFADDR)", ARG3, sizeof(struct vki_ifreq)); 5864 break; 5865 case VKI_SIOCGIFNETMASK: /* get network PA mask */ 5866 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFNETMASK)", 5867 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5868 PRE_MEM_WRITE( "ioctl(SIOCGIFNETMASK)", ARG3, sizeof(struct vki_ifreq)); 5869 break; 5870 case VKI_SIOCGIFMETRIC: /* get metric */ 5871 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMETRIC)", 5872 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5873 PRE_MEM_WRITE( "ioctl(SIOCGIFMETRIC)", ARG3, sizeof(struct vki_ifreq)); 5874 break; 5875 case VKI_SIOCGIFMAP: /* Get device parameters */ 5876 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMAP)", 5877 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5878 PRE_MEM_WRITE( "ioctl(SIOCGIFMAP)", ARG3, sizeof(struct vki_ifreq)); 5879 break; 5880 case VKI_SIOCGIFTXQLEN: /* Get the tx queue length */ 5881 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFTXQLEN)", 5882 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5883 PRE_MEM_WRITE( "ioctl(SIOCGIFTXQLEN)", ARG3, sizeof(struct vki_ifreq)); 5884 break; 5885 case VKI_SIOCGIFDSTADDR: /* get remote PA address */ 5886 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFDSTADDR)", 5887 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5888 PRE_MEM_WRITE( "ioctl(SIOCGIFDSTADDR)", ARG3, sizeof(struct vki_ifreq)); 5889 break; 5890 case VKI_SIOCGIFBRDADDR: /* get broadcast PA address */ 5891 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFBRDADDR)", 5892 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5893 PRE_MEM_WRITE( "ioctl(SIOCGIFBRDADDR)", ARG3, sizeof(struct vki_ifreq)); 5894 break; 5895 case VKI_SIOCGIFNAME: /* get iface name */ 5896 PRE_MEM_READ( "ioctl(SIOCGIFNAME)", 5897 (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_ifindex, 5898 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_ifindex) ); 5899 PRE_MEM_WRITE( "ioctl(SIOCGIFNAME)", ARG3, sizeof(struct vki_ifreq)); 5900 break; 5901 case VKI_SIOCGMIIPHY: /* get hardware entry */ 5902 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMIIPHY)", 5903 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5904 PRE_MEM_WRITE( "ioctl(SIOCGIFMIIPHY)", ARG3, sizeof(struct vki_ifreq)); 5905 break; 5906 case VKI_SIOCGMIIREG: /* get hardware entry registers */ 5907 PRE_MEM_RASCIIZ( "ioctl(SIOCGIFMIIREG)", 5908 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5909 PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)", 5910 (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id, 5911 sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id) ); 5912 PRE_MEM_READ( "ioctl(SIOCGIFMIIREG)", 5913 (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num, 5914 sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num) ); 5915 PRE_MEM_WRITE( "ioctl(SIOCGIFMIIREG)", ARG3, 5916 sizeof(struct vki_ifreq)); 5917 break; 5918 case VKI_SIOCGIFCONF: /* get iface list */ 5919 /* WAS: 5920 PRE_MEM_WRITE( "ioctl(SIOCGIFCONF)", ARG3, sizeof(struct ifconf)); 5921 KERNEL_DO_SYSCALL(tid,RES); 5922 if (!VG_(is_kerror)(RES) && RES == 0) 5923 POST_MEM_WRITE(ARG3, sizeof(struct ifconf)); 5924 */ 5925 PRE_MEM_READ( "ioctl(SIOCGIFCONF)", 5926 (Addr)&((struct vki_ifconf *)ARG3)->ifc_len, 5927 sizeof(((struct vki_ifconf *)ARG3)->ifc_len)); 5928 PRE_MEM_READ( "ioctl(SIOCGIFCONF)", 5929 (Addr)&((struct vki_ifconf *)ARG3)->vki_ifc_buf, 5930 sizeof(((struct vki_ifconf *)ARG3)->vki_ifc_buf)); 5931 if ( ARG3 ) { 5932 // TODO len must be readable and writable 5933 // buf pointer only needs to be readable 5934 struct vki_ifconf *ifc = (struct vki_ifconf *) ARG3; 5935 PRE_MEM_WRITE( "ioctl(SIOCGIFCONF).ifc_buf", 5936 (Addr)(ifc->vki_ifc_buf), ifc->ifc_len ); 5937 } 5938 break; 5939 case VKI_SIOCGSTAMP: 5940 PRE_MEM_WRITE( "ioctl(SIOCGSTAMP)", ARG3, sizeof(struct vki_timeval)); 5941 break; 5942 case VKI_SIOCGSTAMPNS: 5943 PRE_MEM_WRITE( "ioctl(SIOCGSTAMPNS)", ARG3, sizeof(struct vki_timespec)); 5944 break; 5945 /* SIOCOUTQ is an ioctl that, when called on a socket, returns 5946 the number of bytes currently in that socket's send buffer. 5947 It writes this value as an int to the memory location 5948 indicated by the third argument of ioctl(2). */ 5949 case VKI_SIOCOUTQ: 5950 PRE_MEM_WRITE( "ioctl(SIOCOUTQ)", ARG3, sizeof(int)); 5951 break; 5952 case VKI_SIOCGRARP: /* get RARP table entry */ 5953 case VKI_SIOCGARP: /* get ARP table entry */ 5954 PRE_MEM_WRITE( "ioctl(SIOCGARP)", ARG3, sizeof(struct vki_arpreq)); 5955 break; 5956 5957 case VKI_SIOCSIFFLAGS: /* set flags */ 5958 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFFLAGS)", 5959 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5960 PRE_MEM_READ( "ioctl(SIOCSIFFLAGS)", 5961 (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_flags, 5962 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_flags) ); 5963 break; 5964 case VKI_SIOCSIFMAP: /* Set device parameters */ 5965 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMAP)", 5966 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5967 PRE_MEM_READ( "ioctl(SIOCSIFMAP)", 5968 (Addr)&((struct vki_ifreq *)ARG3)->ifr_map, 5969 sizeof(((struct vki_ifreq *)ARG3)->ifr_map) ); 5970 break; 5971 case VKI_SIOCSHWTSTAMP: /* Set hardware time stamping */ 5972 PRE_MEM_RASCIIZ( "ioctl(SIOCSHWTSTAMP)", 5973 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5974 PRE_MEM_READ( "ioctl(SIOCSHWTSTAMP)", 5975 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_data, 5976 sizeof(struct vki_hwtstamp_config) ); 5977 break; 5978 case VKI_SIOCSIFTXQLEN: /* Set the tx queue length */ 5979 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFTXQLEN)", 5980 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5981 PRE_MEM_READ( "ioctl(SIOCSIFTXQLEN)", 5982 (Addr)&((struct vki_ifreq *)ARG3)->ifr_qlen, 5983 sizeof(((struct vki_ifreq *)ARG3)->ifr_qlen) ); 5984 break; 5985 case VKI_SIOCSIFADDR: /* set PA address */ 5986 case VKI_SIOCSIFDSTADDR: /* set remote PA address */ 5987 case VKI_SIOCSIFBRDADDR: /* set broadcast PA address */ 5988 case VKI_SIOCSIFNETMASK: /* set network PA mask */ 5989 PRE_MEM_RASCIIZ( "ioctl(SIOCSIF*ADDR)", 5990 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5991 PRE_MEM_READ( "ioctl(SIOCSIF*ADDR)", 5992 (Addr)&((struct vki_ifreq *)ARG3)->ifr_addr, 5993 sizeof(((struct vki_ifreq *)ARG3)->ifr_addr) ); 5994 break; 5995 case VKI_SIOCSIFMETRIC: /* set metric */ 5996 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMETRIC)", 5997 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 5998 PRE_MEM_READ( "ioctl(SIOCSIFMETRIC)", 5999 (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_metric, 6000 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_metric) ); 6001 break; 6002 case VKI_SIOCSIFMTU: /* set MTU size */ 6003 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFMTU)", 6004 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 6005 PRE_MEM_READ( "ioctl(SIOCSIFMTU)", 6006 (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_mtu, 6007 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_mtu) ); 6008 break; 6009 case VKI_SIOCSIFHWADDR: /* set hardware address */ 6010 PRE_MEM_RASCIIZ( "ioctl(SIOCSIFHWADDR)", 6011 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 6012 PRE_MEM_READ( "ioctl(SIOCSIFHWADDR)", 6013 (Addr)&((struct vki_ifreq *)ARG3)->ifr_hwaddr, 6014 sizeof(((struct vki_ifreq *)ARG3)->ifr_hwaddr) ); 6015 break; 6016 case VKI_SIOCSMIIREG: /* set hardware entry registers */ 6017 PRE_MEM_RASCIIZ( "ioctl(SIOCSMIIREG)", 6018 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 6019 PRE_MEM_READ( "ioctl(SIOCSMIIREG)", 6020 (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id, 6021 sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id) ); 6022 PRE_MEM_READ( "ioctl(SIOCSMIIREG)", 6023 (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num, 6024 sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->reg_num) ); 6025 PRE_MEM_READ( "ioctl(SIOCSMIIREG)", 6026 (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->val_in, 6027 sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->val_in) ); 6028 break; 6029 /* Routing table calls. */ 6030 case VKI_SIOCADDRT: /* add routing table entry */ 6031 case VKI_SIOCDELRT: /* delete routing table entry */ 6032 PRE_MEM_READ( "ioctl(SIOCADDRT/DELRT)", ARG3, 6033 sizeof(struct vki_rtentry)); 6034 break; 6035 6036 /* tun/tap related ioctls */ 6037 case VKI_TUNSETIFF: 6038 PRE_MEM_RASCIIZ( "ioctl(TUNSETIFF)", 6039 (Addr)((struct vki_ifreq *)ARG3)->vki_ifr_name ); 6040 PRE_MEM_READ( "ioctl(TUNSETIFF)", 6041 (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_flags, 6042 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_flags) ); 6043 PRE_MEM_WRITE( "ioctl(TUNSETIFF)", ARG3, 6044 sizeof(struct vki_ifreq)); 6045 break; 6046 case VKI_TUNSETOFFLOAD: 6047 break; 6048 case VKI_TUNGETIFF: 6049 PRE_MEM_WRITE( "ioctl(TUNGETIFF)", ARG3, 6050 sizeof(struct vki_ifreq)); 6051 break; 6052 6053 /* RARP cache control calls. */ 6054 case VKI_SIOCDRARP: /* delete RARP table entry */ 6055 case VKI_SIOCSRARP: /* set RARP table entry */ 6056 /* ARP cache control calls. */ 6057 case VKI_SIOCSARP: /* set ARP table entry */ 6058 case VKI_SIOCDARP: /* delete ARP table entry */ 6059 PRE_MEM_READ( "ioctl(SIOCSIFFLAGS)", ARG3, sizeof(struct vki_ifreq)); 6060 break; 6061 6062 case VKI_SIOCGPGRP: 6063 PRE_MEM_WRITE( "ioctl(SIOCGPGRP)", ARG3, sizeof(int) ); 6064 break; 6065 case VKI_SIOCSPGRP: 6066 PRE_MEM_READ( "ioctl(SIOCSPGRP)", ARG3, sizeof(int) ); 6067 //tst->sys_flags &= ~SfMayBlock; 6068 break; 6069 6070 /* linux/soundcard interface (OSS) */ 6071 case VKI_SNDCTL_SEQ_GETOUTCOUNT: 6072 case VKI_SNDCTL_SEQ_GETINCOUNT: 6073 case VKI_SNDCTL_SEQ_PERCMODE: 6074 case VKI_SNDCTL_SEQ_TESTMIDI: 6075 case VKI_SNDCTL_SEQ_RESETSAMPLES: 6076 case VKI_SNDCTL_SEQ_NRSYNTHS: 6077 case VKI_SNDCTL_SEQ_NRMIDIS: 6078 case VKI_SNDCTL_SEQ_GETTIME: 6079 case VKI_SNDCTL_DSP_GETBLKSIZE: 6080 case VKI_SNDCTL_DSP_GETFMTS: 6081 case VKI_SNDCTL_DSP_GETTRIGGER: 6082 case VKI_SNDCTL_DSP_GETODELAY: 6083 case VKI_SNDCTL_DSP_GETSPDIF: 6084 case VKI_SNDCTL_DSP_GETCAPS: 6085 case VKI_SOUND_PCM_READ_RATE: 6086 case VKI_SOUND_PCM_READ_CHANNELS: 6087 case VKI_SOUND_PCM_READ_BITS: 6088 case VKI_SOUND_PCM_READ_FILTER: 6089 PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOR, int))", 6090 ARG3, sizeof(int)); 6091 break; 6092 case VKI_SNDCTL_SEQ_CTRLRATE: 6093 case VKI_SNDCTL_DSP_SPEED: 6094 case VKI_SNDCTL_DSP_STEREO: 6095 case VKI_SNDCTL_DSP_CHANNELS: 6096 case VKI_SOUND_PCM_WRITE_FILTER: 6097 case VKI_SNDCTL_DSP_SUBDIVIDE: 6098 case VKI_SNDCTL_DSP_SETFRAGMENT: 6099 case VKI_SNDCTL_DSP_SETFMT: 6100 case VKI_SNDCTL_DSP_GETCHANNELMASK: 6101 case VKI_SNDCTL_DSP_BIND_CHANNEL: 6102 case VKI_SNDCTL_TMR_TIMEBASE: 6103 case VKI_SNDCTL_TMR_TEMPO: 6104 case VKI_SNDCTL_TMR_SOURCE: 6105 case VKI_SNDCTL_MIDI_PRETIME: 6106 case VKI_SNDCTL_MIDI_MPUMODE: 6107 PRE_MEM_READ( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOWR, int))", 6108 ARG3, sizeof(int)); 6109 PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOWR, int))", 6110 ARG3, sizeof(int)); 6111 break; 6112 case VKI_SNDCTL_DSP_GETOSPACE: 6113 case VKI_SNDCTL_DSP_GETISPACE: 6114 PRE_MEM_WRITE( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOR, audio_buf_info))", 6115 ARG3, sizeof(vki_audio_buf_info)); 6116 break; 6117 case VKI_SNDCTL_DSP_NONBLOCK: 6118 break; 6119 case VKI_SNDCTL_DSP_SETTRIGGER: 6120 PRE_MEM_READ( "ioctl(SNDCTL_XXX|SOUND_XXX (SIOW, int))", 6121 ARG3, sizeof(int)); 6122 break; 6123 6124 case VKI_SNDCTL_DSP_POST: 6125 case VKI_SNDCTL_DSP_RESET: 6126 case VKI_SNDCTL_DSP_SYNC: 6127 case VKI_SNDCTL_DSP_SETSYNCRO: 6128 case VKI_SNDCTL_DSP_SETDUPLEX: 6129 break; 6130 6131 /* linux/soundcard interface (ALSA) */ 6132 case VKI_SNDRV_PCM_IOCTL_PAUSE: 6133 case VKI_SNDRV_PCM_IOCTL_LINK: 6134 /* these just take an int by value */ 6135 break; 6136 6137 /* Real Time Clock (/dev/rtc) ioctls */ 6138 case VKI_RTC_UIE_ON: 6139 case VKI_RTC_UIE_OFF: 6140 case VKI_RTC_AIE_ON: 6141 case VKI_RTC_AIE_OFF: 6142 case VKI_RTC_PIE_ON: 6143 case VKI_RTC_PIE_OFF: 6144 case VKI_RTC_IRQP_SET: 6145 break; 6146 case VKI_RTC_RD_TIME: 6147 case VKI_RTC_ALM_READ: 6148 PRE_MEM_WRITE( "ioctl(RTC_RD_TIME/ALM_READ)", 6149 ARG3, sizeof(struct vki_rtc_time)); 6150 break; 6151 case VKI_RTC_ALM_SET: 6152 PRE_MEM_READ( "ioctl(RTC_ALM_SET)", ARG3, sizeof(struct vki_rtc_time)); 6153 break; 6154 case VKI_RTC_IRQP_READ: 6155 PRE_MEM_WRITE( "ioctl(RTC_IRQP_READ)", ARG3, sizeof(unsigned long)); 6156 break; 6157 6158 /* Block devices */ 6159 case VKI_BLKROSET: 6160 PRE_MEM_READ( "ioctl(BLKROSET)", ARG3, sizeof(int)); 6161 break; 6162 case VKI_BLKROGET: 6163 PRE_MEM_WRITE( "ioctl(BLKROGET)", ARG3, sizeof(int)); 6164 break; 6165 case VKI_BLKGETSIZE: 6166 PRE_MEM_WRITE( "ioctl(BLKGETSIZE)", ARG3, sizeof(unsigned long)); 6167 break; 6168 case VKI_BLKRASET: 6169 break; 6170 case VKI_BLKRAGET: 6171 PRE_MEM_WRITE( "ioctl(BLKRAGET)", ARG3, sizeof(long)); 6172 break; 6173 case VKI_BLKFRASET: 6174 break; 6175 case VKI_BLKFRAGET: 6176 PRE_MEM_WRITE( "ioctl(BLKFRAGET)", ARG3, sizeof(long)); 6177 break; 6178 case VKI_BLKSECTGET: 6179 PRE_MEM_WRITE( "ioctl(BLKSECTGET)", ARG3, sizeof(unsigned short)); 6180 break; 6181 case VKI_BLKSSZGET: 6182 PRE_MEM_WRITE( "ioctl(BLKSSZGET)", ARG3, sizeof(int)); 6183 break; 6184 case VKI_BLKBSZGET: 6185 PRE_MEM_WRITE( "ioctl(BLKBSZGET)", ARG3, sizeof(int)); 6186 break; 6187 case VKI_BLKBSZSET: 6188 PRE_MEM_READ( "ioctl(BLKBSZSET)", ARG3, sizeof(int)); 6189 break; 6190 case VKI_BLKGETSIZE64: 6191 PRE_MEM_WRITE( "ioctl(BLKGETSIZE64)", ARG3, sizeof(unsigned long long)); 6192 break; 6193 case VKI_BLKPBSZGET: 6194 PRE_MEM_WRITE( "ioctl(BLKPBSZGET)", ARG3, sizeof(int)); 6195 break; 6196 6197 /* Hard disks */ 6198 case VKI_HDIO_GETGEO: /* 0x0301 */ 6199 PRE_MEM_WRITE( "ioctl(HDIO_GETGEO)", ARG3, sizeof(struct vki_hd_geometry)); 6200 break; 6201 case VKI_HDIO_GET_DMA: /* 0x030b */ 6202 PRE_MEM_WRITE( "ioctl(HDIO_GET_DMA)", ARG3, sizeof(long)); 6203 break; 6204 case VKI_HDIO_GET_IDENTITY: /* 0x030d */ 6205 PRE_MEM_WRITE( "ioctl(HDIO_GET_IDENTITY)", ARG3, 6206 VKI_SIZEOF_STRUCT_HD_DRIVEID ); 6207 break; 6208 6209 /* SCSI */ 6210 case VKI_SCSI_IOCTL_GET_IDLUN: /* 0x5382 */ 6211 PRE_MEM_WRITE( "ioctl(SCSI_IOCTL_GET_IDLUN)", ARG3, sizeof(struct vki_scsi_idlun)); 6212 break; 6213 case VKI_SCSI_IOCTL_GET_BUS_NUMBER: /* 0x5386 */ 6214 PRE_MEM_WRITE( "ioctl(SCSI_IOCTL_GET_BUS_NUMBER)", ARG3, sizeof(int)); 6215 break; 6216 6217 /* CD ROM stuff (??) */ 6218 case VKI_CDROM_GET_MCN: 6219 PRE_MEM_READ( "ioctl(CDROM_GET_MCN)", ARG3, 6220 sizeof(struct vki_cdrom_mcn) ); 6221 break; 6222 case VKI_CDROM_SEND_PACKET: 6223 PRE_MEM_READ( "ioctl(CDROM_SEND_PACKET)", ARG3, 6224 sizeof(struct vki_cdrom_generic_command)); 6225 break; 6226 case VKI_CDROMSUBCHNL: 6227 PRE_MEM_READ( "ioctl(CDROMSUBCHNL (cdsc_format, char))", 6228 (Addr) &(((struct vki_cdrom_subchnl*) ARG3)->cdsc_format), 6229 sizeof(((struct vki_cdrom_subchnl*) ARG3)->cdsc_format)); 6230 PRE_MEM_WRITE( "ioctl(CDROMSUBCHNL)", ARG3, 6231 sizeof(struct vki_cdrom_subchnl)); 6232 break; 6233 case VKI_CDROMREADMODE2: 6234 PRE_MEM_READ( "ioctl(CDROMREADMODE2)", ARG3, VKI_CD_FRAMESIZE_RAW0 ); 6235 break; 6236 case VKI_CDROMREADTOCHDR: 6237 PRE_MEM_WRITE( "ioctl(CDROMREADTOCHDR)", ARG3, 6238 sizeof(struct vki_cdrom_tochdr)); 6239 break; 6240 case VKI_CDROMREADTOCENTRY: 6241 PRE_MEM_READ( "ioctl(CDROMREADTOCENTRY (cdte_format, char))", 6242 (Addr) &(((struct vki_cdrom_tocentry*) ARG3)->cdte_format), 6243 sizeof(((struct vki_cdrom_tocentry*) ARG3)->cdte_format)); 6244 PRE_MEM_READ( "ioctl(CDROMREADTOCENTRY (cdte_track, char))", 6245 (Addr) &(((struct vki_cdrom_tocentry*) ARG3)->cdte_track), 6246 sizeof(((struct vki_cdrom_tocentry*) ARG3)->cdte_track)); 6247 PRE_MEM_WRITE( "ioctl(CDROMREADTOCENTRY)", ARG3, 6248 sizeof(struct vki_cdrom_tocentry)); 6249 break; 6250 case VKI_CDROMMULTISESSION: /* 0x5310 */ 6251 PRE_MEM_WRITE( "ioctl(CDROMMULTISESSION)", ARG3, 6252 sizeof(struct vki_cdrom_multisession)); 6253 break; 6254 case VKI_CDROMVOLREAD: /* 0x5313 */ 6255 PRE_MEM_WRITE( "ioctl(CDROMVOLREAD)", ARG3, 6256 sizeof(struct vki_cdrom_volctrl)); 6257 break; 6258 case VKI_CDROMREADRAW: /* 0x5314 */ 6259 PRE_MEM_READ( "ioctl(CDROMREADRAW)", ARG3, sizeof(struct vki_cdrom_msf)); 6260 PRE_MEM_WRITE( "ioctl(CDROMREADRAW)", ARG3, VKI_CD_FRAMESIZE_RAW); 6261 break; 6262 case VKI_CDROMREADAUDIO: /* 0x530e */ 6263 PRE_MEM_READ( "ioctl(CDROMREADAUDIO)", ARG3, 6264 sizeof (struct vki_cdrom_read_audio)); 6265 if ( ARG3 ) { 6266 /* ToDo: don't do any of the following if the structure is invalid */ 6267 struct vki_cdrom_read_audio *cra = (struct vki_cdrom_read_audio *) ARG3; 6268 PRE_MEM_WRITE( "ioctl(CDROMREADAUDIO).buf", 6269 (Addr)(cra->buf), cra->nframes * VKI_CD_FRAMESIZE_RAW); 6270 } 6271 break; 6272 case VKI_CDROMPLAYMSF: 6273 PRE_MEM_READ( "ioctl(CDROMPLAYMSF)", ARG3, sizeof(struct vki_cdrom_msf)); 6274 break; 6275 /* The following two are probably bogus (should check args 6276 for readability). JRS 20021117 */ 6277 case VKI_CDROM_DRIVE_STATUS: /* 0x5326 */ 6278 case VKI_CDROM_CLEAR_OPTIONS: /* 0x5321 */ 6279 break; 6280 case VKI_CDROM_GET_CAPABILITY: /* 0x5331 */ 6281 break; 6282 6283 case VKI_FIGETBSZ: 6284 PRE_MEM_WRITE( "ioctl(FIGETBSZ)", ARG3, sizeof(unsigned long)); 6285 break; 6286 case VKI_FIBMAP: 6287 PRE_MEM_READ( "ioctl(FIBMAP)", ARG3, sizeof(int)); 6288 break; 6289 6290 case VKI_FBIOGET_VSCREENINFO: /* 0x4600 */ 6291 PRE_MEM_WRITE( "ioctl(FBIOGET_VSCREENINFO)", ARG3, 6292 sizeof(struct vki_fb_var_screeninfo)); 6293 break; 6294 case VKI_FBIOPUT_VSCREENINFO: 6295 PRE_MEM_READ( "ioctl(FBIOPUT_VSCREENINFO)", ARG3, 6296 sizeof(struct vki_fb_var_screeninfo)); 6297 break; 6298 case VKI_FBIOGET_FSCREENINFO: /* 0x4602 */ 6299 PRE_MEM_WRITE( "ioctl(FBIOGET_FSCREENINFO)", ARG3, 6300 sizeof(struct vki_fb_fix_screeninfo)); 6301 break; 6302 case VKI_FBIOPAN_DISPLAY: 6303 PRE_MEM_READ( "ioctl(FBIOPAN_DISPLAY)", ARG3, 6304 sizeof(struct vki_fb_var_screeninfo)); 6305 6306 break; 6307 case VKI_PPCLAIM: 6308 case VKI_PPEXCL: 6309 case VKI_PPYIELD: 6310 case VKI_PPRELEASE: 6311 break; 6312 case VKI_PPSETMODE: 6313 PRE_MEM_READ( "ioctl(PPSETMODE)", ARG3, sizeof(int) ); 6314 break; 6315 case VKI_PPGETMODE: 6316 PRE_MEM_WRITE( "ioctl(PPGETMODE)", ARG3, sizeof(int) ); 6317 break; 6318 case VKI_PPSETPHASE: 6319 PRE_MEM_READ( "ioctl(PPSETPHASE)", ARG3, sizeof(int) ); 6320 break; 6321 case VKI_PPGETPHASE: 6322 PRE_MEM_WRITE( "ioctl(PPGETPHASE)", ARG3, sizeof(int) ); 6323 break; 6324 case VKI_PPGETMODES: 6325 PRE_MEM_WRITE( "ioctl(PPGETMODES)", ARG3, sizeof(unsigned int) ); 6326 break; 6327 case VKI_PPSETFLAGS: 6328 PRE_MEM_READ( "ioctl(PPSETFLAGS)", ARG3, sizeof(int) ); 6329 break; 6330 case VKI_PPGETFLAGS: 6331 PRE_MEM_WRITE( "ioctl(PPGETFLAGS)", ARG3, sizeof(int) ); 6332 break; 6333 case VKI_PPRSTATUS: 6334 PRE_MEM_WRITE( "ioctl(PPRSTATUS)", ARG3, sizeof(unsigned char) ); 6335 break; 6336 case VKI_PPRDATA: 6337 PRE_MEM_WRITE( "ioctl(PPRDATA)", ARG3, sizeof(unsigned char) ); 6338 break; 6339 case VKI_PPRCONTROL: 6340 PRE_MEM_WRITE( "ioctl(PPRCONTROL)", ARG3, sizeof(unsigned char) ); 6341 break; 6342 case VKI_PPWDATA: 6343 PRE_MEM_READ( "ioctl(PPWDATA)", ARG3, sizeof(unsigned char) ); 6344 break; 6345 case VKI_PPWCONTROL: 6346 PRE_MEM_READ( "ioctl(PPWCONTROL)", ARG3, sizeof(unsigned char) ); 6347 break; 6348 case VKI_PPFCONTROL: 6349 PRE_MEM_READ( "ioctl(PPFCONTROL)", ARG3, 2 * sizeof(unsigned char) ); 6350 break; 6351 case VKI_PPDATADIR: 6352 PRE_MEM_READ( "ioctl(PPDATADIR)", ARG3, sizeof(int) ); 6353 break; 6354 case VKI_PPNEGOT: 6355 PRE_MEM_READ( "ioctl(PPNEGOT)", ARG3, sizeof(int) ); 6356 break; 6357 case VKI_PPWCTLONIRQ: 6358 PRE_MEM_READ( "ioctl(PPWCTLONIRQ)",ARG3, sizeof(unsigned char) ); 6359 break; 6360 case VKI_PPCLRIRQ: 6361 PRE_MEM_WRITE( "ioctl(PPCLRIRQ)", ARG3, sizeof(int) ); 6362 break; 6363 case VKI_PPSETTIME: 6364 PRE_MEM_READ( "ioctl(PPSETTIME)", ARG3, sizeof(struct vki_timeval) ); 6365 break; 6366 case VKI_PPGETTIME: 6367 PRE_MEM_WRITE( "ioctl(PPGETTIME)", ARG3, sizeof(struct vki_timeval) ); 6368 break; 6369 6370 case VKI_GIO_FONT: 6371 PRE_MEM_WRITE( "ioctl(GIO_FONT)", ARG3, 32 * 256 ); 6372 break; 6373 case VKI_PIO_FONT: 6374 PRE_MEM_READ( "ioctl(PIO_FONT)", ARG3, 32 * 256 ); 6375 break; 6376 6377 case VKI_GIO_FONTX: 6378 PRE_MEM_READ( "ioctl(GIO_FONTX)", ARG3, sizeof(struct vki_consolefontdesc) ); 6379 if ( ARG3 ) { 6380 /* ToDo: don't do any of the following if the structure is invalid */ 6381 struct vki_consolefontdesc *cfd = (struct vki_consolefontdesc *)ARG3; 6382 PRE_MEM_WRITE( "ioctl(GIO_FONTX).chardata", (Addr)cfd->chardata, 6383 32 * cfd->charcount ); 6384 } 6385 break; 6386 case VKI_PIO_FONTX: 6387 PRE_MEM_READ( "ioctl(PIO_FONTX)", ARG3, sizeof(struct vki_consolefontdesc) ); 6388 if ( ARG3 ) { 6389 /* ToDo: don't do any of the following if the structure is invalid */ 6390 struct vki_consolefontdesc *cfd = (struct vki_consolefontdesc *)ARG3; 6391 PRE_MEM_READ( "ioctl(PIO_FONTX).chardata", (Addr)cfd->chardata, 6392 32 * cfd->charcount ); 6393 } 6394 break; 6395 6396 case VKI_PIO_FONTRESET: 6397 break; 6398 6399 case VKI_GIO_CMAP: 6400 PRE_MEM_WRITE( "ioctl(GIO_CMAP)", ARG3, 16 * 3 ); 6401 break; 6402 case VKI_PIO_CMAP: 6403 PRE_MEM_READ( "ioctl(PIO_CMAP)", ARG3, 16 * 3 ); 6404 break; 6405 6406 case VKI_KIOCSOUND: 6407 case VKI_KDMKTONE: 6408 break; 6409 6410 case VKI_KDGETLED: 6411 PRE_MEM_WRITE( "ioctl(KDGETLED)", ARG3, sizeof(char) ); 6412 break; 6413 case VKI_KDSETLED: 6414 break; 6415 6416 case VKI_KDGKBTYPE: 6417 PRE_MEM_WRITE( "ioctl(KDGKBTYPE)", ARG3, sizeof(char) ); 6418 break; 6419 6420 case VKI_KDADDIO: 6421 case VKI_KDDELIO: 6422 case VKI_KDENABIO: 6423 case VKI_KDDISABIO: 6424 break; 6425 6426 case VKI_KDSETMODE: 6427 break; 6428 case VKI_KDGETMODE: 6429 PRE_MEM_WRITE( "ioctl(KDGETMODE)", ARG3, sizeof(int) ); 6430 break; 6431 6432 case VKI_KDMAPDISP: 6433 case VKI_KDUNMAPDISP: 6434 break; 6435 6436 case VKI_GIO_SCRNMAP: 6437 PRE_MEM_WRITE( "ioctl(GIO_SCRNMAP)", ARG3, VKI_E_TABSZ ); 6438 break; 6439 case VKI_PIO_SCRNMAP: 6440 PRE_MEM_READ( "ioctl(PIO_SCRNMAP)", ARG3, VKI_E_TABSZ ); 6441 break; 6442 case VKI_GIO_UNISCRNMAP: 6443 PRE_MEM_WRITE( "ioctl(GIO_UNISCRNMAP)", ARG3, 6444 VKI_E_TABSZ * sizeof(unsigned short) ); 6445 break; 6446 case VKI_PIO_UNISCRNMAP: 6447 PRE_MEM_READ( "ioctl(PIO_UNISCRNMAP)", ARG3, 6448 VKI_E_TABSZ * sizeof(unsigned short) ); 6449 break; 6450 6451 case VKI_GIO_UNIMAP: 6452 if ( ARG3 ) { 6453 struct vki_unimapdesc *desc = (struct vki_unimapdesc *) ARG3; 6454 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr)&desc->entry_ct, 6455 sizeof(unsigned short)); 6456 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr)&desc->entries, 6457 sizeof(struct vki_unipair *)); 6458 PRE_MEM_WRITE( "ioctl(GIO_UNIMAP).entries", (Addr)desc->entries, 6459 desc->entry_ct * sizeof(struct vki_unipair)); 6460 } 6461 break; 6462 case VKI_PIO_UNIMAP: 6463 if ( ARG3 ) { 6464 struct vki_unimapdesc *desc = (struct vki_unimapdesc *) ARG3; 6465 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr)&desc->entry_ct, 6466 sizeof(unsigned short) ); 6467 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", (Addr)&desc->entries, 6468 sizeof(struct vki_unipair *) ); 6469 PRE_MEM_READ( "ioctl(PIO_UNIMAP).entries", (Addr)desc->entries, 6470 desc->entry_ct * sizeof(struct vki_unipair) ); 6471 } 6472 break; 6473 case VKI_PIO_UNIMAPCLR: 6474 PRE_MEM_READ( "ioctl(GIO_UNIMAP)", ARG3, sizeof(struct vki_unimapinit)); 6475 break; 6476 6477 case VKI_KDGKBMODE: 6478 PRE_MEM_WRITE( "ioctl(KDGKBMODE)", ARG3, sizeof(int) ); 6479 break; 6480 case VKI_KDSKBMODE: 6481 break; 6482 6483 case VKI_KDGKBMETA: 6484 PRE_MEM_WRITE( "ioctl(KDGKBMETA)", ARG3, sizeof(int) ); 6485 break; 6486 case VKI_KDSKBMETA: 6487 break; 6488 6489 case VKI_KDGKBLED: 6490 PRE_MEM_WRITE( "ioctl(KDGKBLED)", ARG3, sizeof(char) ); 6491 break; 6492 case VKI_KDSKBLED: 6493 break; 6494 6495 case VKI_KDGKBENT: 6496 PRE_MEM_READ( "ioctl(KDGKBENT).kb_table", 6497 (Addr)&((struct vki_kbentry *)ARG3)->kb_table, 6498 sizeof(((struct vki_kbentry *)ARG3)->kb_table) ); 6499 PRE_MEM_READ( "ioctl(KDGKBENT).kb_index", 6500 (Addr)&((struct vki_kbentry *)ARG3)->kb_index, 6501 sizeof(((struct vki_kbentry *)ARG3)->kb_index) ); 6502 PRE_MEM_WRITE( "ioctl(KDGKBENT).kb_value", 6503 (Addr)&((struct vki_kbentry *)ARG3)->kb_value, 6504 sizeof(((struct vki_kbentry *)ARG3)->kb_value) ); 6505 break; 6506 case VKI_KDSKBENT: 6507 PRE_MEM_READ( "ioctl(KDSKBENT).kb_table", 6508 (Addr)&((struct vki_kbentry *)ARG3)->kb_table, 6509 sizeof(((struct vki_kbentry *)ARG3)->kb_table) ); 6510 PRE_MEM_READ( "ioctl(KDSKBENT).kb_index", 6511 (Addr)&((struct vki_kbentry *)ARG3)->kb_index, 6512 sizeof(((struct vki_kbentry *)ARG3)->kb_index) ); 6513 PRE_MEM_READ( "ioctl(KDSKBENT).kb_value", 6514 (Addr)&((struct vki_kbentry *)ARG3)->kb_value, 6515 sizeof(((struct vki_kbentry *)ARG3)->kb_value) ); 6516 break; 6517 6518 case VKI_KDGKBSENT: 6519 PRE_MEM_READ( "ioctl(KDGKBSENT).kb_func", 6520 (Addr)&((struct vki_kbsentry *)ARG3)->kb_func, 6521 sizeof(((struct vki_kbsentry *)ARG3)->kb_func) ); 6522 PRE_MEM_WRITE( "ioctl(KDGKSENT).kb_string", 6523 (Addr)((struct vki_kbsentry *)ARG3)->kb_string, 6524 sizeof(((struct vki_kbsentry *)ARG3)->kb_string) ); 6525 break; 6526 case VKI_KDSKBSENT: 6527 PRE_MEM_READ( "ioctl(KDSKBSENT).kb_func", 6528 (Addr)&((struct vki_kbsentry *)ARG3)->kb_func, 6529 sizeof(((struct vki_kbsentry *)ARG3)->kb_func) ); 6530 PRE_MEM_RASCIIZ( "ioctl(KDSKBSENT).kb_string", 6531 (Addr)((struct vki_kbsentry *)ARG3)->kb_string ); 6532 break; 6533 6534 case VKI_KDGKBDIACR: 6535 PRE_MEM_WRITE( "ioctl(KDGKBDIACR)", ARG3, sizeof(struct vki_kbdiacrs) ); 6536 break; 6537 case VKI_KDSKBDIACR: 6538 PRE_MEM_READ( "ioctl(KDSKBDIACR)", ARG3, sizeof(struct vki_kbdiacrs) ); 6539 break; 6540 6541 case VKI_KDGETKEYCODE: 6542 PRE_MEM_READ( "ioctl(KDGETKEYCODE).scancode", 6543 (Addr)&((struct vki_kbkeycode *)ARG3)->scancode, 6544 sizeof(((struct vki_kbkeycode *)ARG3)->scancode) ); 6545 PRE_MEM_WRITE( "ioctl(KDGETKEYCODE).keycode", 6546 (Addr)((struct vki_kbkeycode *)ARG3)->keycode, 6547 sizeof(((struct vki_kbkeycode *)ARG3)->keycode) ); 6548 break; 6549 case VKI_KDSETKEYCODE: 6550 PRE_MEM_READ( "ioctl(KDSETKEYCODE).scancode", 6551 (Addr)&((struct vki_kbkeycode *)ARG3)->scancode, 6552 sizeof(((struct vki_kbkeycode *)ARG3)->scancode) ); 6553 PRE_MEM_READ( "ioctl(KDSETKEYCODE).keycode", 6554 (Addr)((struct vki_kbkeycode *)ARG3)->keycode, 6555 sizeof(((struct vki_kbkeycode *)ARG3)->keycode) ); 6556 break; 6557 6558 case VKI_KDSIGACCEPT: 6559 break; 6560 6561 case VKI_KDKBDREP: 6562 PRE_MEM_READ( "ioctl(KBKBDREP)", ARG3, sizeof(struct vki_kbd_repeat) ); 6563 break; 6564 6565 case VKI_KDFONTOP: 6566 if ( ARG3 ) { 6567 struct vki_console_font_op *op = (struct vki_console_font_op *) ARG3; 6568 PRE_MEM_READ( "ioctl(KDFONTOP)", (Addr)op, 6569 sizeof(struct vki_console_font_op) ); 6570 switch ( op->op ) { 6571 case VKI_KD_FONT_OP_SET: 6572 PRE_MEM_READ( "ioctl(KDFONTOP,KD_FONT_OP_SET).data", 6573 (Addr)op->data, 6574 (op->width + 7) / 8 * 32 * op->charcount ); 6575 break; 6576 case VKI_KD_FONT_OP_GET: 6577 if ( op->data ) 6578 PRE_MEM_WRITE( "ioctl(KDFONTOP,KD_FONT_OP_GET).data", 6579 (Addr)op->data, 6580 (op->width + 7) / 8 * 32 * op->charcount ); 6581 break; 6582 case VKI_KD_FONT_OP_SET_DEFAULT: 6583 if ( op->data ) 6584 PRE_MEM_RASCIIZ( "ioctl(KDFONTOP,KD_FONT_OP_SET_DEFAULT).data", 6585 (Addr)op->data ); 6586 break; 6587 case VKI_KD_FONT_OP_COPY: 6588 break; 6589 } 6590 } 6591 break; 6592 6593 case VKI_VT_OPENQRY: 6594 PRE_MEM_WRITE( "ioctl(VT_OPENQRY)", ARG3, sizeof(int) ); 6595 break; 6596 case VKI_VT_GETMODE: 6597 PRE_MEM_WRITE( "ioctl(VT_GETMODE)", ARG3, sizeof(struct vki_vt_mode) ); 6598 break; 6599 case VKI_VT_SETMODE: 6600 PRE_MEM_READ( "ioctl(VT_SETMODE)", ARG3, sizeof(struct vki_vt_mode) ); 6601 break; 6602 case VKI_VT_GETSTATE: 6603 PRE_MEM_WRITE( "ioctl(VT_GETSTATE).v_active", 6604 (Addr) &(((struct vki_vt_stat*) ARG3)->v_active), 6605 sizeof(((struct vki_vt_stat*) ARG3)->v_active)); 6606 PRE_MEM_WRITE( "ioctl(VT_GETSTATE).v_state", 6607 (Addr) &(((struct vki_vt_stat*) ARG3)->v_state), 6608 sizeof(((struct vki_vt_stat*) ARG3)->v_state)); 6609 break; 6610 case VKI_VT_RELDISP: 6611 case VKI_VT_ACTIVATE: 6612 case VKI_VT_WAITACTIVE: 6613 case VKI_VT_DISALLOCATE: 6614 break; 6615 case VKI_VT_RESIZE: 6616 PRE_MEM_READ( "ioctl(VT_RESIZE)", ARG3, sizeof(struct vki_vt_sizes) ); 6617 break; 6618 case VKI_VT_RESIZEX: 6619 PRE_MEM_READ( "ioctl(VT_RESIZEX)", ARG3, sizeof(struct vki_vt_consize) ); 6620 break; 6621 case VKI_VT_LOCKSWITCH: 6622 case VKI_VT_UNLOCKSWITCH: 6623 break; 6624 6625 case VKI_USBDEVFS_CONTROL: 6626 if ( ARG3 ) { 6627 struct vki_usbdevfs_ctrltransfer *vkuc = (struct vki_usbdevfs_ctrltransfer *)ARG3; 6628 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).bRequestType", (Addr)&vkuc->bRequestType, sizeof(vkuc->bRequestType)); 6629 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).bRequest", (Addr)&vkuc->bRequest, sizeof(vkuc->bRequest)); 6630 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).wValue", (Addr)&vkuc->wValue, sizeof(vkuc->wValue)); 6631 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).wIndex", (Addr)&vkuc->wIndex, sizeof(vkuc->wIndex)); 6632 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).wLength", (Addr)&vkuc->wLength, sizeof(vkuc->wLength)); 6633 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).timeout", (Addr)&vkuc->timeout, sizeof(vkuc->timeout)); 6634 if (vkuc->bRequestType & 0x80) 6635 PRE_MEM_WRITE( "ioctl(USBDEVFS_CONTROL).data", (Addr)vkuc->data, vkuc->wLength); 6636 else 6637 PRE_MEM_READ( "ioctl(USBDEVFS_CONTROL).data", (Addr)vkuc->data, vkuc->wLength); 6638 } 6639 break; 6640 case VKI_USBDEVFS_BULK: 6641 if ( ARG3 ) { 6642 struct vki_usbdevfs_bulktransfer *vkub = (struct vki_usbdevfs_bulktransfer *)ARG3; 6643 PRE_MEM_READ( "ioctl(USBDEVFS_BULK)", ARG3, sizeof(struct vki_usbdevfs_bulktransfer)); 6644 if (vkub->ep & 0x80) 6645 PRE_MEM_WRITE( "ioctl(USBDEVFS_BULK).data", (Addr)vkub->data, vkub->len); 6646 else 6647 PRE_MEM_READ( "ioctl(USBDEVFS_BULK).data", (Addr)vkub->data, vkub->len); 6648 } 6649 break; 6650 case VKI_USBDEVFS_GETDRIVER: 6651 if ( ARG3 ) { 6652 struct vki_usbdevfs_getdriver *vkugd = (struct vki_usbdevfs_getdriver *) ARG3; 6653 PRE_MEM_WRITE( "ioctl(USBDEVFS_GETDRIVER)", (Addr)&vkugd->driver, sizeof(vkugd->driver)); 6654 } 6655 break; 6656 case VKI_USBDEVFS_SUBMITURB: 6657 if ( ARG3 ) { 6658 struct vki_usbdevfs_urb *vkuu = (struct vki_usbdevfs_urb *)ARG3; 6659 6660 /* Not the whole struct needs to be initialized */ 6661 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).endpoint", (Addr)&vkuu->endpoint, sizeof(vkuu->endpoint)); 6662 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).type", (Addr)&vkuu->type, sizeof(vkuu->type)); 6663 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).flags", (Addr)&vkuu->flags, sizeof(vkuu->flags)); 6664 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)&vkuu->buffer, sizeof(vkuu->buffer)); 6665 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).signr", (Addr)&vkuu->signr, sizeof(vkuu->signr)); 6666 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).status", (Addr)&vkuu->status, sizeof(vkuu->status)); 6667 if (vkuu->type == VKI_USBDEVFS_URB_TYPE_CONTROL) { 6668 struct vki_usbdevfs_setuppacket *vkusp = (struct vki_usbdevfs_setuppacket *)vkuu->buffer; 6669 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer_length", (Addr)&vkuu->buffer_length, sizeof(vkuu->buffer_length)); 6670 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer.setup_packet", (Addr)vkusp, sizeof(*vkusp)); 6671 if (vkusp->bRequestType & 0x80) 6672 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer.data", (Addr)(vkusp+1), vkuu->buffer_length - sizeof(*vkusp)); 6673 else 6674 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer.data", (Addr)(vkusp+1), vkuu->buffer_length - sizeof(*vkusp)); 6675 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).actual_length", (Addr)&vkuu->actual_length, sizeof(vkuu->actual_length)); 6676 } else if (vkuu->type == VKI_USBDEVFS_URB_TYPE_ISO) { 6677 int total_length = 0; 6678 int i; 6679 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).number_of_packets", (Addr)&vkuu->number_of_packets, sizeof(vkuu->number_of_packets)); 6680 for(i=0; i<vkuu->number_of_packets; i++) { 6681 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].length", (Addr)&vkuu->iso_frame_desc[i].length, sizeof(vkuu->iso_frame_desc[i].length)); 6682 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].actual_length", (Addr)&vkuu->iso_frame_desc[i].actual_length, sizeof(vkuu->iso_frame_desc[i].actual_length)); 6683 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).iso_frame_desc[].status", (Addr)&vkuu->iso_frame_desc[i].status, sizeof(vkuu->iso_frame_desc[i].status)); 6684 total_length += vkuu->iso_frame_desc[i].length; 6685 } 6686 if (vkuu->endpoint & 0x80) 6687 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)vkuu->buffer, total_length); 6688 else 6689 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)vkuu->buffer, total_length); 6690 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).error_count", (Addr)&vkuu->error_count, sizeof(vkuu->error_count)); 6691 } else { 6692 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer_length", (Addr)&vkuu->buffer_length, sizeof(vkuu->buffer_length)); 6693 if (vkuu->endpoint & 0x80) 6694 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)vkuu->buffer, vkuu->buffer_length); 6695 else 6696 PRE_MEM_READ( "ioctl(USBDEVFS_SUBMITURB).buffer", (Addr)vkuu->buffer, vkuu->buffer_length); 6697 PRE_MEM_WRITE( "ioctl(USBDEVFS_SUBMITURB).actual_length", (Addr)&vkuu->actual_length, sizeof(vkuu->actual_length)); 6698 } 6699 } 6700 break; 6701 case VKI_USBDEVFS_DISCARDURB: 6702 break; 6703 case VKI_USBDEVFS_REAPURB: 6704 if ( ARG3 ) { 6705 PRE_MEM_WRITE( "ioctl(USBDEVFS_REAPURB)", ARG3, sizeof(struct vki_usbdevfs_urb **)); 6706 } 6707 break; 6708 case VKI_USBDEVFS_REAPURBNDELAY: 6709 if ( ARG3 ) { 6710 PRE_MEM_WRITE( "ioctl(USBDEVFS_REAPURBNDELAY)", ARG3, sizeof(struct vki_usbdevfs_urb **)); 6711 } 6712 break; 6713 case VKI_USBDEVFS_CONNECTINFO: 6714 PRE_MEM_WRITE( "ioctl(USBDEVFS_CONNECTINFO)", ARG3, sizeof(struct vki_usbdevfs_connectinfo)); 6715 break; 6716 case VKI_USBDEVFS_IOCTL: 6717 if ( ARG3 ) { 6718 struct vki_usbdevfs_ioctl *vkui = (struct vki_usbdevfs_ioctl *)ARG3; 6719 UInt dir2, size2; 6720 PRE_MEM_READ("ioctl(USBDEVFS_IOCTL)", (Addr)vkui, sizeof(struct vki_usbdevfs_ioctl)); 6721 dir2 = _VKI_IOC_DIR(vkui->ioctl_code); 6722 size2 = _VKI_IOC_SIZE(vkui->ioctl_code); 6723 if (size2 > 0) { 6724 if (dir2 & _VKI_IOC_WRITE) 6725 PRE_MEM_READ("ioctl(USBDEVFS_IOCTL).dataWrite", (Addr)vkui->data, size2); 6726 else if (dir2 & _VKI_IOC_READ) 6727 PRE_MEM_WRITE("ioctl(USBDEVFS_IOCTL).dataRead", (Addr)vkui->data, size2); 6728 } 6729 } 6730 break; 6731 case VKI_USBDEVFS_RESET: 6732 break; 6733 6734 /* I2C (/dev/i2c-*) ioctls */ 6735 case VKI_I2C_SLAVE: 6736 case VKI_I2C_SLAVE_FORCE: 6737 case VKI_I2C_TENBIT: 6738 case VKI_I2C_PEC: 6739 break; 6740 case VKI_I2C_FUNCS: 6741 PRE_MEM_WRITE( "ioctl(I2C_FUNCS)", ARG3, sizeof(unsigned long) ); 6742 break; 6743 case VKI_I2C_RDWR: 6744 if ( ARG3 ) { 6745 struct vki_i2c_rdwr_ioctl_data *vkui = (struct vki_i2c_rdwr_ioctl_data *)ARG3; 6746 UInt i; 6747 PRE_MEM_READ("ioctl(I2C_RDWR)", (Addr)vkui, sizeof(struct vki_i2c_rdwr_ioctl_data)); 6748 for (i=0; i < vkui->nmsgs; i++) { 6749 struct vki_i2c_msg *msg = vkui->msgs + i; 6750 PRE_MEM_READ("ioctl(I2C_RDWR).msgs", (Addr)msg, sizeof(struct vki_i2c_msg)); 6751 if (msg->flags & VKI_I2C_M_RD) 6752 PRE_MEM_WRITE("ioctl(I2C_RDWR).msgs.buf", (Addr)msg->buf, msg->len); 6753 else 6754 PRE_MEM_READ("ioctl(I2C_RDWR).msgs.buf", (Addr)msg->buf, msg->len); 6755 } 6756 } 6757 break; 6758 6759 /* Wireless extensions ioctls */ 6760 case VKI_SIOCSIWCOMMIT: 6761 case VKI_SIOCSIWNWID: 6762 case VKI_SIOCSIWFREQ: 6763 case VKI_SIOCSIWMODE: 6764 case VKI_SIOCSIWSENS: 6765 case VKI_SIOCSIWRANGE: 6766 case VKI_SIOCSIWPRIV: 6767 case VKI_SIOCSIWSTATS: 6768 case VKI_SIOCSIWSPY: 6769 case VKI_SIOCSIWTHRSPY: 6770 case VKI_SIOCSIWAP: 6771 case VKI_SIOCSIWSCAN: 6772 case VKI_SIOCSIWESSID: 6773 case VKI_SIOCSIWRATE: 6774 case VKI_SIOCSIWNICKN: 6775 case VKI_SIOCSIWRTS: 6776 case VKI_SIOCSIWFRAG: 6777 case VKI_SIOCSIWTXPOW: 6778 case VKI_SIOCSIWRETRY: 6779 case VKI_SIOCSIWENCODE: 6780 case VKI_SIOCSIWPOWER: 6781 case VKI_SIOCSIWGENIE: 6782 case VKI_SIOCSIWMLME: 6783 case VKI_SIOCSIWAUTH: 6784 case VKI_SIOCSIWENCODEEXT: 6785 case VKI_SIOCSIWPMKSA: 6786 break; 6787 case VKI_SIOCGIWNAME: 6788 if (ARG3) { 6789 PRE_MEM_WRITE("ioctl(SIOCGIWNAME)", 6790 (Addr)((struct vki_iwreq *)ARG3)->u.name, 6791 sizeof(((struct vki_iwreq *)ARG3)->u.name)); 6792 } 6793 break; 6794 case VKI_SIOCGIWNWID: 6795 case VKI_SIOCGIWSENS: 6796 case VKI_SIOCGIWRATE: 6797 case VKI_SIOCGIWRTS: 6798 case VKI_SIOCGIWFRAG: 6799 case VKI_SIOCGIWTXPOW: 6800 case VKI_SIOCGIWRETRY: 6801 case VKI_SIOCGIWPOWER: 6802 case VKI_SIOCGIWAUTH: 6803 if (ARG3) { 6804 PRE_MEM_WRITE("ioctl(SIOCGIW[NWID|SENS|RATE|RTS|FRAG|TXPOW|" 6805 "RETRY|PARAM|AUTH])", 6806 (Addr)&((struct vki_iwreq *)ARG3)->u.nwid, 6807 sizeof(struct vki_iw_param)); 6808 } 6809 break; 6810 case VKI_SIOCGIWFREQ: 6811 if (ARG3) { 6812 PRE_MEM_WRITE("ioctl(SIOCGIWFREQ", 6813 (Addr)&((struct vki_iwreq *)ARG3)->u.freq, 6814 sizeof(struct vki_iw_freq)); 6815 } 6816 break; 6817 case VKI_SIOCGIWMODE: 6818 if (ARG3) { 6819 PRE_MEM_WRITE("ioctl(SIOCGIWMODE", 6820 (Addr)&((struct vki_iwreq *)ARG3)->u.mode, 6821 sizeof(__vki_u32)); 6822 } 6823 break; 6824 case VKI_SIOCGIWRANGE: 6825 case VKI_SIOCGIWPRIV: 6826 case VKI_SIOCGIWSTATS: 6827 case VKI_SIOCGIWSPY: 6828 case VKI_SIOCGIWTHRSPY: 6829 case VKI_SIOCGIWAPLIST: 6830 case VKI_SIOCGIWSCAN: 6831 case VKI_SIOCGIWESSID: 6832 case VKI_SIOCGIWNICKN: 6833 case VKI_SIOCGIWENCODE: 6834 case VKI_SIOCGIWGENIE: 6835 case VKI_SIOCGIWENCODEEXT: 6836 if (ARG3) { 6837 struct vki_iw_point* point; 6838 point = &((struct vki_iwreq *)ARG3)->u.data; 6839 PRE_MEM_WRITE("ioctl(SIOCGIW[RANGE|PRIV|STATS|SPY|THRSPY|" 6840 "APLIST|SCAN|ESSID|NICKN|ENCODE|GENIE|ENCODEEXT])", 6841 (Addr)point->pointer, point->length); 6842 } 6843 break; 6844 case VKI_SIOCGIWAP: 6845 if (ARG3) { 6846 PRE_MEM_WRITE("ioctl(SIOCGIWAP)", 6847 (Addr)&((struct vki_iwreq *)ARG3)->u.ap_addr, 6848 sizeof(struct vki_sockaddr)); 6849 } 6850 break; 6851 6852 /* User input device creation */ 6853 case VKI_UI_SET_EVBIT: 6854 case VKI_UI_SET_KEYBIT: 6855 case VKI_UI_SET_RELBIT: 6856 case VKI_UI_SET_ABSBIT: 6857 case VKI_UI_SET_MSCBIT: 6858 case VKI_UI_SET_LEDBIT: 6859 case VKI_UI_SET_SNDBIT: 6860 case VKI_UI_SET_FFBIT: 6861 case VKI_UI_SET_SWBIT: 6862 case VKI_UI_SET_PROPBIT: 6863 /* These just take an int by value */ 6864 break; 6865 6866 # if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \ 6867 || defined(VGPV_mips32_linux_android) 6868 /* ashmem */ 6869 case VKI_ASHMEM_GET_SIZE: 6870 case VKI_ASHMEM_SET_SIZE: 6871 case VKI_ASHMEM_GET_PROT_MASK: 6872 case VKI_ASHMEM_SET_PROT_MASK: 6873 case VKI_ASHMEM_GET_PIN_STATUS: 6874 case VKI_ASHMEM_PURGE_ALL_CACHES: 6875 break; 6876 case VKI_ASHMEM_GET_NAME: 6877 PRE_MEM_WRITE( "ioctl(ASHMEM_SET_NAME)", ARG3, VKI_ASHMEM_NAME_LEN ); 6878 break; 6879 case VKI_ASHMEM_SET_NAME: 6880 PRE_MEM_RASCIIZ( "ioctl(ASHMEM_SET_NAME)", ARG3); 6881 break; 6882 case VKI_ASHMEM_PIN: 6883 case VKI_ASHMEM_UNPIN: 6884 PRE_MEM_READ( "ioctl(ASHMEM_PIN|ASHMEM_UNPIN)", 6885 ARG3, sizeof(struct vki_ashmem_pin) ); 6886 break; 6887 6888 /* binder */ 6889 case VKI_BINDER_WRITE_READ: 6890 if (ARG3) { 6891 struct vki_binder_write_read* bwr 6892 = (struct vki_binder_write_read*)ARG3; 6893 6894 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).write_buffer", 6895 bwr->write_buffer); 6896 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).write_size", 6897 bwr->write_size); 6898 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).write_consumed", 6899 bwr->write_consumed); 6900 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).read_buffer", 6901 bwr->read_buffer); 6902 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).read_size", 6903 bwr->read_size); 6904 PRE_FIELD_READ("ioctl(BINDER_WRITE_READ).read_consumed", 6905 bwr->read_consumed); 6906 6907 PRE_FIELD_WRITE("ioctl(BINDER_WRITE_READ).write_consumed", 6908 bwr->write_consumed); 6909 PRE_FIELD_WRITE("ioctl(BINDER_WRITE_READ).read_consumed", 6910 bwr->read_consumed); 6911 6912 if (bwr->read_size) 6913 PRE_MEM_WRITE("ioctl(BINDER_WRITE_READ).read_buffer[]", 6914 (Addr)bwr->read_buffer, bwr->read_size); 6915 if (bwr->write_size) 6916 PRE_MEM_READ("ioctl(BINDER_WRITE_READ).write_buffer[]", 6917 (Addr)bwr->write_buffer, bwr->write_size); 6918 } 6919 break; 6920 6921 case VKI_BINDER_SET_IDLE_TIMEOUT: 6922 case VKI_BINDER_SET_MAX_THREADS: 6923 case VKI_BINDER_SET_IDLE_PRIORITY: 6924 case VKI_BINDER_SET_CONTEXT_MGR: 6925 case VKI_BINDER_THREAD_EXIT: 6926 break; 6927 case VKI_BINDER_VERSION: 6928 if (ARG3) { 6929 struct vki_binder_version* bv = (struct vki_binder_version*)ARG3; 6930 PRE_FIELD_WRITE("ioctl(BINDER_VERSION)", bv->protocol_version); 6931 } 6932 break; 6933 # endif /* defined(VGPV_*_linux_android) */ 6934 6935 case VKI_HCIINQUIRY: 6936 if (ARG3) { 6937 struct vki_hci_inquiry_req* ir = (struct vki_hci_inquiry_req*)ARG3; 6938 PRE_MEM_READ("ioctl(HCIINQUIRY)", 6939 (Addr)ARG3, sizeof(struct vki_hci_inquiry_req)); 6940 PRE_MEM_WRITE("ioctl(HCIINQUIRY)", 6941 (Addr)ARG3 + sizeof(struct vki_hci_inquiry_req), 6942 ir->num_rsp * sizeof(struct vki_inquiry_info)); 6943 } 6944 break; 6945 6946 /* KVM ioctls that check for a numeric value as parameter */ 6947 case VKI_KVM_GET_API_VERSION: 6948 case VKI_KVM_CREATE_VM: 6949 case VKI_KVM_GET_VCPU_MMAP_SIZE: 6950 case VKI_KVM_CHECK_EXTENSION: 6951 case VKI_KVM_CREATE_VCPU: 6952 case VKI_KVM_RUN: 6953 break; 6954 6955 #ifdef ENABLE_XEN 6956 case VKI_XEN_IOCTL_PRIVCMD_HYPERCALL: { 6957 SyscallArgs harrghs; 6958 struct vki_xen_privcmd_hypercall *args = 6959 (struct vki_xen_privcmd_hypercall *)(ARG3); 6960 6961 if (!args) 6962 break; 6963 6964 VG_(memset)(&harrghs, 0, sizeof(harrghs)); 6965 harrghs.sysno = args->op; 6966 harrghs.arg1 = args->arg[0]; 6967 harrghs.arg2 = args->arg[1]; 6968 harrghs.arg3 = args->arg[2]; 6969 harrghs.arg4 = args->arg[3]; 6970 harrghs.arg5 = args->arg[4]; 6971 harrghs.arg6 = harrghs.arg7 = harrghs.arg8 = 0; 6972 6973 WRAPPER_PRE_NAME(xen, hypercall) (tid, layout, &harrghs, status, flags); 6974 6975 /* HACK. arg8 is used to return the number of hypercall 6976 * arguments actually consumed! */ 6977 PRE_MEM_READ("hypercall", ARG3, sizeof(args->op) + 6978 ( sizeof(args->arg[0]) * harrghs.arg8 ) ); 6979 6980 break; 6981 } 6982 6983 case VKI_XEN_IOCTL_PRIVCMD_MMAP: { 6984 struct vki_xen_privcmd_mmap *args = 6985 (struct vki_xen_privcmd_mmap *)(ARG3); 6986 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAP(num)", 6987 (Addr)&args->num, sizeof(args->num)); 6988 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAP(dom)", 6989 (Addr)&args->dom, sizeof(args->dom)); 6990 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAP(entry)", 6991 (Addr)args->entry, sizeof(*(args->entry)) * args->num); 6992 break; 6993 } 6994 case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH: { 6995 struct vki_xen_privcmd_mmapbatch *args = 6996 (struct vki_xen_privcmd_mmapbatch *)(ARG3); 6997 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(num)", 6998 (Addr)&args->num, sizeof(args->num)); 6999 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(dom)", 7000 (Addr)&args->dom, sizeof(args->dom)); 7001 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(addr)", 7002 (Addr)&args->addr, sizeof(args->addr)); 7003 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH(arr)", 7004 (Addr)args->arr, sizeof(*(args->arr)) * args->num); 7005 break; 7006 } 7007 case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2: { 7008 struct vki_xen_privcmd_mmapbatch_v2 *args = 7009 (struct vki_xen_privcmd_mmapbatch_v2 *)(ARG3); 7010 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(num)", 7011 (Addr)&args->num, sizeof(args->num)); 7012 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(dom)", 7013 (Addr)&args->dom, sizeof(args->dom)); 7014 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(addr)", 7015 (Addr)&args->addr, sizeof(args->addr)); 7016 PRE_MEM_READ("VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2(arr)", 7017 (Addr)args->arr, sizeof(*(args->arr)) * args->num); 7018 break; 7019 } 7020 #endif 7021 7022 case VKI_EVIOCSSUSPENDBLOCK: 7023 break; 7024 7025 case VKI_MEDIA_IOC_DEVICE_INFO: 7026 if (ARG3) { 7027 PRE_MEM_WRITE("ioctl(MEDIA_IOC_DEVICE_INFO)", ARG3, 7028 sizeof(struct vki_media_device_info)); 7029 } 7030 break; 7031 7032 default: 7033 /* EVIOC* are variable length and return size written on success */ 7034 switch (ARG2 & ~(_VKI_IOC_SIZEMASK << _VKI_IOC_SIZESHIFT)) { 7035 case VKI_EVIOCGNAME(0): 7036 case VKI_EVIOCGPHYS(0): 7037 case VKI_EVIOCGUNIQ(0): 7038 case VKI_EVIOCGKEY(0): 7039 case VKI_EVIOCGLED(0): 7040 case VKI_EVIOCGSND(0): 7041 case VKI_EVIOCGSW(0): 7042 case VKI_EVIOCGBIT(VKI_EV_SYN,0): 7043 case VKI_EVIOCGBIT(VKI_EV_KEY,0): 7044 case VKI_EVIOCGBIT(VKI_EV_REL,0): 7045 case VKI_EVIOCGBIT(VKI_EV_ABS,0): 7046 case VKI_EVIOCGBIT(VKI_EV_MSC,0): 7047 case VKI_EVIOCGBIT(VKI_EV_SW,0): 7048 case VKI_EVIOCGBIT(VKI_EV_LED,0): 7049 case VKI_EVIOCGBIT(VKI_EV_SND,0): 7050 case VKI_EVIOCGBIT(VKI_EV_REP,0): 7051 case VKI_EVIOCGBIT(VKI_EV_FF,0): 7052 case VKI_EVIOCGBIT(VKI_EV_PWR,0): 7053 case VKI_EVIOCGBIT(VKI_EV_FF_STATUS,0): 7054 PRE_MEM_WRITE("ioctl(EVIO*)", ARG3, _VKI_IOC_SIZE(ARG2)); 7055 break; 7056 default: 7057 ML_(PRE_unknown_ioctl)(tid, ARG2, ARG3); 7058 break; 7059 } 7060 break; 7061 } 7062 } 7063 7064 POST(sys_ioctl) 7065 { 7066 vg_assert(SUCCESS); 7067 7068 /* --- BEGIN special IOCTL handlers for specific Android hardware --- */ 7069 7070 # if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \ 7071 || defined(VGPV_mips32_linux_android) 7072 7073 # if defined(ANDROID_HARDWARE_nexus_s) 7074 7075 /* BEGIN undocumented ioctls for the graphics hardware (??) 7076 (libpvr) on Nexus S */ 7077 if (ARG2 >= 0xC01C6700 && ARG2 <= 0xC01C67FF && ARG3 >= 0x1000) { 7078 /* What's going on here: there appear to be a bunch of ioctls of 7079 the form 0xC01C67xx which are undocumented, and if unhandled 7080 give rise to a vast number of false positives in Memcheck. 7081 7082 The "normal" intrepretation of an ioctl of this form would be 7083 that the 3rd arg is a pointer to an area of size 0x1C (28 7084 bytes) which is filled in by the kernel. Hence you might 7085 think that "POST_MEM_WRITE(ARG3, 28)" would fix it. But it 7086 doesn't. 7087 7088 It requires POST_MEM_WRITE(ARG3, 256) to silence them. One 7089 interpretation of this is that ARG3 really does point to a 28 7090 byte struct, but inside that are pointers to other areas also 7091 filled in by the kernel. If these happen to be allocated 7092 just back up the stack then the 256 byte paint might cover 7093 them too, somewhat indiscriminately. 7094 7095 By printing out ARG3 and also the 28 bytes that it points at, 7096 it's possible to guess that the 7 word structure has this form 7097 7098 0 1 2 3 4 5 6 7099 ioctl-number 0x1C ptr1 ptr1size ptr2 ptr2size aBitMask 7100 7101 Unfortunately that doesn't seem to work for some reason, so 7102 stay with the blunt-instrument approach for the time being. 7103 */ 7104 if (1) { 7105 /* blunt-instrument approach */ 7106 if (0) VG_(printf)("QQQQQQQQQQ c01c quick hack actioned" 7107 " (%08lx, %08lx)\n", ARG2, ARG3); 7108 POST_MEM_WRITE(ARG3, 256); 7109 } else { 7110 /* be a bit more sophisticated */ 7111 if (0) VG_(printf)("QQQQQQQQQQ c01c quick hack actioned" 7112 " (%08lx, %08lx) (fancy)\n", ARG2, ARG3); 7113 POST_MEM_WRITE(ARG3, 28); 7114 UInt* word = (UInt*)ARG3; 7115 if (word && word[2] && word[3] < 0x200/*stay sane*/) 7116 POST_MEM_WRITE(word[2], word[3]); // "ptr1" 7117 if (word && word[4] && word[5] < 0x200/*stay sane*/) 7118 POST_MEM_WRITE(word[4], word[5]); // "ptr2" 7119 } 7120 if (0) { 7121 Int i; 7122 VG_(printf)("QQQQQQQQQQ "); 7123 for (i = 0; i < (0x1C/4); i++) { 7124 VG_(printf)("%08x ", ((UInt*)(ARG3))[i]); 7125 } 7126 VG_(printf)("\n"); 7127 } 7128 return; 7129 } 7130 /* END Nexus S specific ioctls */ 7131 7132 7133 # elif defined(ANDROID_HARDWARE_generic) || defined(ANDROID_HARDWARE_emulator) 7134 7135 /* BEGIN generic/emulator specific ioctls */ 7136 /* currently none are known */ 7137 /* END generic/emulator specific ioctls */ 7138 7139 7140 # elif defined(ANDROID_HARDWARE_nexus_10) 7141 7142 /* undocumented ioctl ids noted on the device */ 7143 if (ARG2 >= 0xc0108000 && ARG2 <= 0xc1e8820b && ARG3 != 0) { 7144 int size = (ARG2 >> 16) & 0x3fff; 7145 POST_MEM_WRITE(ARG3, size); 7146 } 7147 7148 # elif defined(ANDROID_HARDWARE_nexus_7) 7149 7150 # elif defined(ANDROID_HARDWARE_nexus_4) 7151 7152 # else /* no ANDROID_HARDWARE_anything defined */ 7153 7154 # warning "" 7155 # warning "You need to define one the CPP symbols ANDROID_HARDWARE_blah" 7156 # warning "at configure time, to tell Valgrind what hardware you are" 7157 # warning "building for. Currently known values are" 7158 # warning "" 7159 # warning " ANDROID_HARDWARE_nexus_s Samsung Nexus S" 7160 # warning " ANDROID_HARDWARE_nexus_10 Samsung Nexus 10" 7161 # warning " ANDROID_HARDWARE_nexus_7 ASUS Nexus 7" 7162 # warning " ANDROID_HARDWARE_nexus_4 LG Nexus 4" 7163 # warning " ANDROID_HARDWARE_generic Generic device (eg, Pandaboard)" 7164 # warning " ANDROID_HARDWARE_emulator x86 or arm emulator" 7165 # warning "" 7166 # warning "Make sure you exactly follow the steps in README.android." 7167 # warning "" 7168 # error "No CPP symbol ANDROID_HARDWARE_blah defined. Giving up." 7169 7170 # endif /* cases for ANDROID_HARDWARE_blah */ 7171 7172 # endif /* defined(VGPV_*_linux_android) */ 7173 7174 /* --- END special IOCTL handlers for specific Android hardware --- */ 7175 7176 /* --- normal handling --- */ 7177 switch (ARG2 /* request */) { 7178 case VKI_TCSETS: 7179 case VKI_TCSETSW: 7180 case VKI_TCSETSF: 7181 case VKI_IB_USER_MAD_ENABLE_PKEY: 7182 break; 7183 case VKI_TCGETS: 7184 POST_MEM_WRITE( ARG3, sizeof(struct vki_termios) ); 7185 break; 7186 case VKI_TCSETA: 7187 case VKI_TCSETAW: 7188 case VKI_TCSETAF: 7189 break; 7190 case VKI_TCGETA: 7191 POST_MEM_WRITE( ARG3, sizeof(struct vki_termio) ); 7192 break; 7193 case VKI_TCSBRK: 7194 case VKI_TCXONC: 7195 case VKI_TCSBRKP: 7196 case VKI_TCFLSH: 7197 break; 7198 case VKI_TIOCGWINSZ: 7199 POST_MEM_WRITE( ARG3, sizeof(struct vki_winsize) ); 7200 break; 7201 case VKI_TIOCSWINSZ: 7202 case VKI_TIOCMBIS: 7203 case VKI_TIOCMBIC: 7204 case VKI_TIOCMSET: 7205 break; 7206 case VKI_TIOCMGET: 7207 POST_MEM_WRITE( ARG3, sizeof(unsigned int) ); 7208 break; 7209 case VKI_TIOCLINUX: 7210 POST_MEM_WRITE( ARG3, sizeof(char *) ); 7211 break; 7212 case VKI_TIOCGPGRP: 7213 /* Get process group ID for foreground processing group. */ 7214 POST_MEM_WRITE( ARG3, sizeof(vki_pid_t) ); 7215 break; 7216 case VKI_TIOCSPGRP: 7217 /* Set a process group ID? */ 7218 POST_MEM_WRITE( ARG3, sizeof(vki_pid_t) ); 7219 break; 7220 case VKI_TIOCGPTN: /* Get Pty Number (of pty-mux device) */ 7221 POST_MEM_WRITE( ARG3, sizeof(int)); 7222 break; 7223 case VKI_TIOCSCTTY: 7224 break; 7225 case VKI_TIOCSPTLCK: /* Lock/unlock Pty */ 7226 break; 7227 case VKI_FIONBIO: 7228 break; 7229 case VKI_FIONCLEX: 7230 break; 7231 case VKI_FIOCLEX: 7232 break; 7233 case VKI_FIOASYNC: 7234 break; 7235 case VKI_FIONREAD: /* identical to SIOCINQ */ 7236 POST_MEM_WRITE( ARG3, sizeof(int) ); 7237 break; 7238 case VKI_FIOQSIZE: 7239 POST_MEM_WRITE( ARG3, sizeof(vki_loff_t) ); 7240 break; 7241 7242 case VKI_TIOCSERGETLSR: 7243 POST_MEM_WRITE( ARG3, sizeof(int) ); 7244 break; 7245 case VKI_TIOCGICOUNT: 7246 POST_MEM_WRITE( ARG3, sizeof(struct vki_serial_icounter_struct) ); 7247 break; 7248 7249 case VKI_SG_SET_COMMAND_Q: 7250 break; 7251 case VKI_SG_IO: 7252 POST_MEM_WRITE(ARG3, sizeof(vki_sg_io_hdr_t)); 7253 break; 7254 case VKI_SG_GET_SCSI_ID: 7255 POST_MEM_WRITE(ARG3, sizeof(vki_sg_scsi_id_t)); 7256 break; 7257 case VKI_SG_SET_RESERVED_SIZE: 7258 break; 7259 case VKI_SG_SET_TIMEOUT: 7260 break; 7261 case VKI_SG_GET_RESERVED_SIZE: 7262 POST_MEM_WRITE(ARG3, sizeof(int)); 7263 break; 7264 case VKI_SG_GET_TIMEOUT: 7265 break; 7266 case VKI_SG_GET_VERSION_NUM: 7267 POST_MEM_WRITE(ARG3, sizeof(int)); 7268 break; 7269 case VKI_SG_EMULATED_HOST: 7270 POST_MEM_WRITE(ARG3, sizeof(int)); 7271 break; 7272 case VKI_SG_GET_SG_TABLESIZE: 7273 POST_MEM_WRITE(ARG3, sizeof(int)); 7274 break; 7275 7276 case VKI_IIOCGETCPS: 7277 POST_MEM_WRITE( ARG3, VKI_ISDN_MAX_CHANNELS * 2 * sizeof(unsigned long) ); 7278 break; 7279 case VKI_IIOCNETGPN: 7280 POST_MEM_WRITE( ARG3, sizeof(vki_isdn_net_ioctl_phone) ); 7281 break; 7282 7283 /* These all use struct ifreq AFAIK */ 7284 case VKI_SIOCGIFINDEX: /* get iface index */ 7285 POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_ifindex, 7286 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_ifindex) ); 7287 break; 7288 case VKI_SIOCGIFFLAGS: /* get flags */ 7289 POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_flags, 7290 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_flags) ); 7291 break; 7292 case VKI_SIOCGIFHWADDR: /* Get hardware address */ 7293 POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->ifr_hwaddr, 7294 sizeof(((struct vki_ifreq *)ARG3)->ifr_hwaddr) ); 7295 break; 7296 case VKI_SIOCGIFMTU: /* get MTU size */ 7297 POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_mtu, 7298 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_mtu) ); 7299 break; 7300 case VKI_SIOCGIFADDR: /* get PA address */ 7301 case VKI_SIOCGIFDSTADDR: /* get remote PA address */ 7302 case VKI_SIOCGIFBRDADDR: /* get broadcast PA address */ 7303 case VKI_SIOCGIFNETMASK: /* get network PA mask */ 7304 POST_MEM_WRITE( 7305 (Addr)&((struct vki_ifreq *)ARG3)->ifr_addr, 7306 sizeof(((struct vki_ifreq *)ARG3)->ifr_addr) ); 7307 break; 7308 case VKI_SIOCGIFMETRIC: /* get metric */ 7309 POST_MEM_WRITE( 7310 (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_metric, 7311 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_metric) ); 7312 break; 7313 case VKI_SIOCGIFMAP: /* Get device parameters */ 7314 POST_MEM_WRITE( 7315 (Addr)&((struct vki_ifreq *)ARG3)->ifr_map, 7316 sizeof(((struct vki_ifreq *)ARG3)->ifr_map) ); 7317 break; 7318 break; 7319 case VKI_SIOCGIFTXQLEN: /* Get the tx queue length */ 7320 POST_MEM_WRITE( 7321 (Addr)&((struct vki_ifreq *)ARG3)->ifr_qlen, 7322 sizeof(((struct vki_ifreq *)ARG3)->ifr_qlen) ); 7323 break; 7324 case VKI_SIOCGIFNAME: /* get iface name */ 7325 POST_MEM_WRITE( 7326 (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_name, 7327 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_name) ); 7328 break; 7329 case VKI_SIOCGMIIPHY: /* get hardware entry */ 7330 POST_MEM_WRITE( 7331 (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id, 7332 sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->phy_id) ); 7333 break; 7334 case VKI_SIOCGMIIREG: /* get hardware entry registers */ 7335 POST_MEM_WRITE( 7336 (Addr)&((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->val_out, 7337 sizeof(((struct vki_mii_ioctl_data *)&((struct vki_ifreq *)ARG3)->vki_ifr_data)->val_out) ); 7338 break; 7339 7340 /* tun/tap related ioctls */ 7341 case VKI_TUNSETIFF: 7342 POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_name, 7343 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_name) ); 7344 break; 7345 case VKI_TUNGETIFF: 7346 POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_name, 7347 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_name) ); 7348 POST_MEM_WRITE( (Addr)&((struct vki_ifreq *)ARG3)->vki_ifr_flags, 7349 sizeof(((struct vki_ifreq *)ARG3)->vki_ifr_flags) ); 7350 break; 7351 7352 case VKI_SIOCGIFCONF: /* get iface list */ 7353 /* WAS: 7354 PRE_MEM_WRITE("ioctl(SIOCGIFCONF)", ARG3, sizeof(struct ifconf)); 7355 KERNEL_DO_SYSCALL(tid,RES); 7356 if (!VG_(is_kerror)(RES) && RES == 0) 7357 POST_MEM_WRITE(ARG3, sizeof(struct ifconf)); 7358 */ 7359 if (RES == 0 && ARG3 ) { 7360 struct vki_ifconf *ifc = (struct vki_ifconf *) ARG3; 7361 if (ifc->vki_ifc_buf != NULL) 7362 POST_MEM_WRITE( (Addr)(ifc->vki_ifc_buf), ifc->ifc_len ); 7363 } 7364 break; 7365 case VKI_SIOCGSTAMP: 7366 POST_MEM_WRITE( ARG3, sizeof(struct vki_timeval) ); 7367 break; 7368 case VKI_SIOCGSTAMPNS: 7369 POST_MEM_WRITE( ARG3, sizeof(struct vki_timespec) ); 7370 break; 7371 /* SIOCOUTQ is an ioctl that, when called on a socket, returns 7372 the number of bytes currently in that socket's send buffer. 7373 It writes this value as an int to the memory location 7374 indicated by the third argument of ioctl(2). */ 7375 case VKI_SIOCOUTQ: 7376 POST_MEM_WRITE(ARG3, sizeof(int)); 7377 break; 7378 case VKI_SIOCGRARP: /* get RARP table entry */ 7379 case VKI_SIOCGARP: /* get ARP table entry */ 7380 POST_MEM_WRITE(ARG3, sizeof(struct vki_arpreq)); 7381 break; 7382 7383 case VKI_SIOCSIFFLAGS: /* set flags */ 7384 case VKI_SIOCSIFMAP: /* Set device parameters */ 7385 case VKI_SIOCSHWTSTAMP: /* Set hardware time stamping */ 7386 case VKI_SIOCSIFTXQLEN: /* Set the tx queue length */ 7387 case VKI_SIOCSIFDSTADDR: /* set remote PA address */ 7388 case VKI_SIOCSIFBRDADDR: /* set broadcast PA address */ 7389 case VKI_SIOCSIFNETMASK: /* set network PA mask */ 7390 case VKI_SIOCSIFMETRIC: /* set metric */ 7391 case VKI_SIOCSIFADDR: /* set PA address */ 7392 case VKI_SIOCSIFMTU: /* set MTU size */ 7393 case VKI_SIOCSIFHWADDR: /* set hardware address */ 7394 case VKI_SIOCSMIIREG: /* set hardware entry registers */ 7395 break; 7396 /* Routing table calls. */ 7397 case VKI_SIOCADDRT: /* add routing table entry */ 7398 case VKI_SIOCDELRT: /* delete routing table entry */ 7399 break; 7400 7401 /* RARP cache control calls. */ 7402 case VKI_SIOCDRARP: /* delete RARP table entry */ 7403 case VKI_SIOCSRARP: /* set RARP table entry */ 7404 /* ARP cache control calls. */ 7405 case VKI_SIOCSARP: /* set ARP table entry */ 7406 case VKI_SIOCDARP: /* delete ARP table entry */ 7407 break; 7408 7409 case VKI_SIOCGPGRP: 7410 POST_MEM_WRITE(ARG3, sizeof(int)); 7411 break; 7412 case VKI_SIOCSPGRP: 7413 break; 7414 7415 /* linux/soundcard interface (OSS) */ 7416 case VKI_SNDCTL_SEQ_GETOUTCOUNT: 7417 case VKI_SNDCTL_SEQ_GETINCOUNT: 7418 case VKI_SNDCTL_SEQ_PERCMODE: 7419 case VKI_SNDCTL_SEQ_TESTMIDI: 7420 case VKI_SNDCTL_SEQ_RESETSAMPLES: 7421 case VKI_SNDCTL_SEQ_NRSYNTHS: 7422 case VKI_SNDCTL_SEQ_NRMIDIS: 7423 case VKI_SNDCTL_SEQ_GETTIME: 7424 case VKI_SNDCTL_DSP_GETBLKSIZE: 7425 case VKI_SNDCTL_DSP_GETFMTS: 7426 case VKI_SNDCTL_DSP_SETFMT: 7427 case VKI_SNDCTL_DSP_GETTRIGGER: 7428 case VKI_SNDCTL_DSP_GETODELAY: 7429 case VKI_SNDCTL_DSP_GETSPDIF: 7430 case VKI_SNDCTL_DSP_GETCAPS: 7431 case VKI_SOUND_PCM_READ_RATE: 7432 case VKI_SOUND_PCM_READ_CHANNELS: 7433 case VKI_SOUND_PCM_READ_BITS: 7434 case VKI_SOUND_PCM_READ_FILTER: 7435 POST_MEM_WRITE(ARG3, sizeof(int)); 7436 break; 7437 case VKI_SNDCTL_SEQ_CTRLRATE: 7438 case VKI_SNDCTL_DSP_SPEED: 7439 case VKI_SNDCTL_DSP_STEREO: 7440 case VKI_SNDCTL_DSP_CHANNELS: 7441 case VKI_SOUND_PCM_WRITE_FILTER: 7442 case VKI_SNDCTL_DSP_SUBDIVIDE: 7443 case VKI_SNDCTL_DSP_SETFRAGMENT: 7444 case VKI_SNDCTL_DSP_GETCHANNELMASK: 7445 case VKI_SNDCTL_DSP_BIND_CHANNEL: 7446 case VKI_SNDCTL_TMR_TIMEBASE: 7447 case VKI_SNDCTL_TMR_TEMPO: 7448 case VKI_SNDCTL_TMR_SOURCE: 7449 case VKI_SNDCTL_MIDI_PRETIME: 7450 case VKI_SNDCTL_MIDI_MPUMODE: 7451 break; 7452 case VKI_SNDCTL_DSP_GETOSPACE: 7453 case VKI_SNDCTL_DSP_GETISPACE: 7454 POST_MEM_WRITE(ARG3, sizeof(vki_audio_buf_info)); 7455 break; 7456 case VKI_SNDCTL_DSP_NONBLOCK: 7457 break; 7458 case VKI_SNDCTL_DSP_SETTRIGGER: 7459 break; 7460 7461 case VKI_SNDCTL_DSP_POST: 7462 case VKI_SNDCTL_DSP_RESET: 7463 case VKI_SNDCTL_DSP_SYNC: 7464 case VKI_SNDCTL_DSP_SETSYNCRO: 7465 case VKI_SNDCTL_DSP_SETDUPLEX: 7466 break; 7467 7468 /* linux/soundcard interface (ALSA) */ 7469 case VKI_SNDRV_PCM_IOCTL_HW_FREE: 7470 case VKI_SNDRV_PCM_IOCTL_HWSYNC: 7471 case VKI_SNDRV_PCM_IOCTL_PREPARE: 7472 case VKI_SNDRV_PCM_IOCTL_RESET: 7473 case VKI_SNDRV_PCM_IOCTL_START: 7474 case VKI_SNDRV_PCM_IOCTL_DROP: 7475 case VKI_SNDRV_PCM_IOCTL_DRAIN: 7476 case VKI_SNDRV_PCM_IOCTL_RESUME: 7477 case VKI_SNDRV_PCM_IOCTL_XRUN: 7478 case VKI_SNDRV_PCM_IOCTL_UNLINK: 7479 case VKI_SNDRV_TIMER_IOCTL_START: 7480 case VKI_SNDRV_TIMER_IOCTL_STOP: 7481 case VKI_SNDRV_TIMER_IOCTL_CONTINUE: 7482 case VKI_SNDRV_TIMER_IOCTL_PAUSE: 7483 7484 /* SCSI no operand */ 7485 case VKI_SCSI_IOCTL_DOORLOCK: 7486 case VKI_SCSI_IOCTL_DOORUNLOCK: 7487 break; 7488 7489 /* Real Time Clock (/dev/rtc) ioctls */ 7490 case VKI_RTC_UIE_ON: 7491 case VKI_RTC_UIE_OFF: 7492 case VKI_RTC_AIE_ON: 7493 case VKI_RTC_AIE_OFF: 7494 case VKI_RTC_PIE_ON: 7495 case VKI_RTC_PIE_OFF: 7496 case VKI_RTC_IRQP_SET: 7497 break; 7498 case VKI_RTC_RD_TIME: 7499 case VKI_RTC_ALM_READ: 7500 POST_MEM_WRITE(ARG3, sizeof(struct vki_rtc_time)); 7501 break; 7502 case VKI_RTC_ALM_SET: 7503 break; 7504 case VKI_RTC_IRQP_READ: 7505 POST_MEM_WRITE(ARG3, sizeof(unsigned long)); 7506 break; 7507 7508 /* Block devices */ 7509 case VKI_BLKROSET: 7510 break; 7511 case VKI_BLKROGET: 7512 POST_MEM_WRITE(ARG3, sizeof(int)); 7513 break; 7514 case VKI_BLKGETSIZE: 7515 POST_MEM_WRITE(ARG3, sizeof(unsigned long)); 7516 break; 7517 case VKI_BLKRASET: 7518 break; 7519 case VKI_BLKRAGET: 7520 POST_MEM_WRITE(ARG3, sizeof(long)); 7521 break; 7522 case VKI_BLKFRASET: 7523 break; 7524 case VKI_BLKFRAGET: 7525 POST_MEM_WRITE(ARG3, sizeof(long)); 7526 break; 7527 case VKI_BLKSECTGET: 7528 POST_MEM_WRITE(ARG3, sizeof(unsigned short)); 7529 break; 7530 case VKI_BLKSSZGET: 7531 POST_MEM_WRITE(ARG3, sizeof(int)); 7532 break; 7533 case VKI_BLKBSZGET: 7534 POST_MEM_WRITE(ARG3, sizeof(int)); 7535 break; 7536 case VKI_BLKBSZSET: 7537 break; 7538 case VKI_BLKGETSIZE64: 7539 POST_MEM_WRITE(ARG3, sizeof(unsigned long long)); 7540 break; 7541 case VKI_BLKPBSZGET: 7542 POST_MEM_WRITE(ARG3, sizeof(int)); 7543 break; 7544 7545 /* Hard disks */ 7546 case VKI_HDIO_GETGEO: /* 0x0301 */ 7547 POST_MEM_WRITE(ARG3, sizeof(struct vki_hd_geometry)); 7548 break; 7549 case VKI_HDIO_GET_DMA: /* 0x030b */ 7550 POST_MEM_WRITE(ARG3, sizeof(long)); 7551 break; 7552 case VKI_HDIO_GET_IDENTITY: /* 0x030d */ 7553 POST_MEM_WRITE(ARG3, VKI_SIZEOF_STRUCT_HD_DRIVEID ); 7554 break; 7555 7556 /* SCSI */ 7557 case VKI_SCSI_IOCTL_GET_IDLUN: /* 0x5382 */ 7558 POST_MEM_WRITE(ARG3, sizeof(struct vki_scsi_idlun)); 7559 break; 7560 case VKI_SCSI_IOCTL_GET_BUS_NUMBER: /* 0x5386 */ 7561 POST_MEM_WRITE(ARG3, sizeof(int)); 7562 break; 7563 7564 /* CD ROM stuff (??) */ 7565 case VKI_CDROMSUBCHNL: 7566 POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_subchnl)); 7567 break; 7568 case VKI_CDROMREADTOCHDR: 7569 POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_tochdr)); 7570 break; 7571 case VKI_CDROMREADTOCENTRY: 7572 POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_tocentry)); 7573 break; 7574 case VKI_CDROMMULTISESSION: 7575 POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_multisession)); 7576 break; 7577 case VKI_CDROMVOLREAD: 7578 POST_MEM_WRITE(ARG3, sizeof(struct vki_cdrom_volctrl)); 7579 break; 7580 case VKI_CDROMREADRAW: 7581 POST_MEM_WRITE(ARG3, VKI_CD_FRAMESIZE_RAW); 7582 break; 7583 case VKI_CDROMREADAUDIO: 7584 { 7585 struct vki_cdrom_read_audio *cra = (struct vki_cdrom_read_audio *) ARG3; 7586 POST_MEM_WRITE( (Addr)(cra->buf), cra->nframes * VKI_CD_FRAMESIZE_RAW); 7587 break; 7588 } 7589 7590 case VKI_CDROMPLAYMSF: 7591 break; 7592 /* The following two are probably bogus (should check args 7593 for readability). JRS 20021117 */ 7594 case VKI_CDROM_DRIVE_STATUS: /* 0x5326 */ 7595 case VKI_CDROM_CLEAR_OPTIONS: /* 0x5321 */ 7596 break; 7597 case VKI_CDROM_GET_CAPABILITY: /* 0x5331 */ 7598 break; 7599 7600 case VKI_FIGETBSZ: 7601 POST_MEM_WRITE(ARG3, sizeof(unsigned long)); 7602 break; 7603 case VKI_FIBMAP: 7604 POST_MEM_WRITE(ARG3, sizeof(int)); 7605 break; 7606 7607 case VKI_FBIOGET_VSCREENINFO: //0x4600 7608 POST_MEM_WRITE(ARG3, sizeof(struct vki_fb_var_screeninfo)); 7609 break; 7610 case VKI_FBIOGET_FSCREENINFO: //0x4602 7611 POST_MEM_WRITE(ARG3, sizeof(struct vki_fb_fix_screeninfo)); 7612 break; 7613 7614 case VKI_PPCLAIM: 7615 case VKI_PPEXCL: 7616 case VKI_PPYIELD: 7617 case VKI_PPRELEASE: 7618 case VKI_PPSETMODE: 7619 case VKI_PPSETPHASE: 7620 case VKI_PPSETFLAGS: 7621 case VKI_PPWDATA: 7622 case VKI_PPWCONTROL: 7623 case VKI_PPFCONTROL: 7624 case VKI_PPDATADIR: 7625 case VKI_PPNEGOT: 7626 case VKI_PPWCTLONIRQ: 7627 case VKI_PPSETTIME: 7628 break; 7629 case VKI_PPGETMODE: 7630 POST_MEM_WRITE( ARG3, sizeof(int) ); 7631 break; 7632 case VKI_PPGETPHASE: 7633 POST_MEM_WRITE( ARG3, sizeof(int) ); 7634 break; 7635 case VKI_PPGETMODES: 7636 POST_MEM_WRITE( ARG3, sizeof(unsigned int) ); 7637 break; 7638 case VKI_PPGETFLAGS: 7639 POST_MEM_WRITE( ARG3, sizeof(int) ); 7640 break; 7641 case VKI_PPRSTATUS: 7642 POST_MEM_WRITE( ARG3, sizeof(unsigned char) ); 7643 break; 7644 case VKI_PPRDATA: 7645 POST_MEM_WRITE( ARG3, sizeof(unsigned char) ); 7646 break; 7647 case VKI_PPRCONTROL: 7648 POST_MEM_WRITE( ARG3, sizeof(unsigned char) ); 7649 break; 7650 case VKI_PPCLRIRQ: 7651 POST_MEM_WRITE( ARG3, sizeof(int) ); 7652 break; 7653 case VKI_PPGETTIME: 7654 POST_MEM_WRITE( ARG3, sizeof(struct vki_timeval) ); 7655 break; 7656 7657 case VKI_GIO_FONT: 7658 POST_MEM_WRITE( ARG3, 32 * 256 ); 7659 break; 7660 case VKI_PIO_FONT: 7661 break; 7662 7663 case VKI_GIO_FONTX: 7664 POST_MEM_WRITE( (Addr)((struct vki_consolefontdesc *)ARG3)->chardata, 7665 32 * ((struct vki_consolefontdesc *)ARG3)->charcount ); 7666 break; 7667 case VKI_PIO_FONTX: 7668 break; 7669 7670 case VKI_PIO_FONTRESET: 7671 break; 7672 7673 case VKI_GIO_CMAP: 7674 POST_MEM_WRITE( ARG3, 16 * 3 ); 7675 break; 7676 case VKI_PIO_CMAP: 7677 break; 7678 7679 case VKI_KIOCSOUND: 7680 case VKI_KDMKTONE: 7681 break; 7682 7683 case VKI_KDGETLED: 7684 POST_MEM_WRITE( ARG3, sizeof(char) ); 7685 break; 7686 case VKI_KDSETLED: 7687 break; 7688 7689 case VKI_KDGKBTYPE: 7690 POST_MEM_WRITE( ARG3, sizeof(char) ); 7691 break; 7692 7693 case VKI_KDADDIO: 7694 case VKI_KDDELIO: 7695 case VKI_KDENABIO: 7696 case VKI_KDDISABIO: 7697 break; 7698 7699 case VKI_KDSETMODE: 7700 break; 7701 case VKI_KDGETMODE: 7702 POST_MEM_WRITE( ARG3, sizeof(int) ); 7703 break; 7704 7705 case VKI_KDMAPDISP: 7706 case VKI_KDUNMAPDISP: 7707 break; 7708 7709 case VKI_GIO_SCRNMAP: 7710 POST_MEM_WRITE( ARG3, VKI_E_TABSZ ); 7711 break; 7712 case VKI_PIO_SCRNMAP: 7713 break; 7714 case VKI_GIO_UNISCRNMAP: 7715 POST_MEM_WRITE( ARG3, VKI_E_TABSZ * sizeof(unsigned short) ); 7716 break; 7717 case VKI_PIO_UNISCRNMAP: 7718 break; 7719 7720 case VKI_GIO_UNIMAP: 7721 if ( ARG3 ) { 7722 struct vki_unimapdesc *desc = (struct vki_unimapdesc *) ARG3; 7723 POST_MEM_WRITE( (Addr)&desc->entry_ct, sizeof(desc->entry_ct)); 7724 POST_MEM_WRITE( (Addr)desc->entries, 7725 desc->entry_ct * sizeof(struct vki_unipair) ); 7726 } 7727 break; 7728 case VKI_PIO_UNIMAP: 7729 break; 7730 case VKI_PIO_UNIMAPCLR: 7731 break; 7732 7733 case VKI_KDGKBMODE: 7734 POST_MEM_WRITE( ARG3, sizeof(int) ); 7735 break; 7736 case VKI_KDSKBMODE: 7737 break; 7738 7739 case VKI_KDGKBMETA: 7740 POST_MEM_WRITE( ARG3, sizeof(int) ); 7741 break; 7742 case VKI_KDSKBMETA: 7743 break; 7744 7745 case VKI_KDGKBLED: 7746 POST_MEM_WRITE( ARG3, sizeof(char) ); 7747 break; 7748 case VKI_KDSKBLED: 7749 break; 7750 7751 case VKI_KDGKBENT: 7752 POST_MEM_WRITE( (Addr)&((struct vki_kbentry *)ARG3)->kb_value, 7753 sizeof(((struct vki_kbentry *)ARG3)->kb_value) ); 7754 break; 7755 case VKI_KDSKBENT: 7756 break; 7757 7758 case VKI_KDGKBSENT: 7759 POST_MEM_WRITE( (Addr)((struct vki_kbsentry *)ARG3)->kb_string, 7760 sizeof(((struct vki_kbsentry *)ARG3)->kb_string) ); 7761 break; 7762 case VKI_KDSKBSENT: 7763 break; 7764 7765 case VKI_KDGKBDIACR: 7766 POST_MEM_WRITE( ARG3, sizeof(struct vki_kbdiacrs) ); 7767 break; 7768 case VKI_KDSKBDIACR: 7769 break; 7770 7771 case VKI_KDGETKEYCODE: 7772 POST_MEM_WRITE( (Addr)((struct vki_kbkeycode *)ARG3)->keycode, 7773 sizeof(((struct vki_kbkeycode *)ARG3)->keycode) ); 7774 break; 7775 case VKI_KDSETKEYCODE: 7776 break; 7777 7778 case VKI_KDSIGACCEPT: 7779 break; 7780 7781 case VKI_KDKBDREP: 7782 break; 7783 7784 case VKI_KDFONTOP: 7785 if ( ARG3 ) { 7786 struct vki_console_font_op *op = (struct vki_console_font_op *) ARG3; 7787 switch ( op->op ) { 7788 case VKI_KD_FONT_OP_SET: 7789 break; 7790 case VKI_KD_FONT_OP_GET: 7791 if ( op->data ) 7792 POST_MEM_WRITE( (Addr) op->data, 7793 (op->width + 7) / 8 * 32 * op->charcount ); 7794 break; 7795 case VKI_KD_FONT_OP_SET_DEFAULT: 7796 break; 7797 case VKI_KD_FONT_OP_COPY: 7798 break; 7799 } 7800 POST_MEM_WRITE( (Addr) op, sizeof(*op)); 7801 } 7802 break; 7803 7804 case VKI_VT_OPENQRY: 7805 POST_MEM_WRITE( ARG3, sizeof(int) ); 7806 break; 7807 case VKI_VT_GETMODE: 7808 POST_MEM_WRITE( ARG3, sizeof(struct vki_vt_mode) ); 7809 break; 7810 case VKI_VT_SETMODE: 7811 break; 7812 case VKI_VT_GETSTATE: 7813 POST_MEM_WRITE( (Addr) &(((struct vki_vt_stat*) ARG3)->v_active), 7814 sizeof(((struct vki_vt_stat*) ARG3)->v_active) ); 7815 POST_MEM_WRITE( (Addr) &(((struct vki_vt_stat*) ARG3)->v_state), 7816 sizeof(((struct vki_vt_stat*) ARG3)->v_state) ); 7817 break; 7818 case VKI_VT_RELDISP: 7819 case VKI_VT_ACTIVATE: 7820 case VKI_VT_WAITACTIVE: 7821 case VKI_VT_DISALLOCATE: 7822 break; 7823 case VKI_VT_RESIZE: 7824 break; 7825 case VKI_VT_RESIZEX: 7826 break; 7827 case VKI_VT_LOCKSWITCH: 7828 case VKI_VT_UNLOCKSWITCH: 7829 break; 7830 7831 case VKI_USBDEVFS_CONTROL: 7832 if ( ARG3 ) { 7833 struct vki_usbdevfs_ctrltransfer *vkuc = (struct vki_usbdevfs_ctrltransfer *)ARG3; 7834 if (vkuc->bRequestType & 0x80) 7835 POST_MEM_WRITE((Addr)vkuc->data, RES); 7836 } 7837 break; 7838 case VKI_USBDEVFS_BULK: 7839 if ( ARG3 ) { 7840 struct vki_usbdevfs_bulktransfer *vkub = (struct vki_usbdevfs_bulktransfer *)ARG3; 7841 if (vkub->ep & 0x80) 7842 POST_MEM_WRITE((Addr)vkub->data, RES); 7843 } 7844 break; 7845 case VKI_USBDEVFS_GETDRIVER: 7846 if ( ARG3 ) { 7847 struct vki_usbdevfs_getdriver *vkugd = (struct vki_usbdevfs_getdriver *)ARG3; 7848 POST_MEM_WRITE((Addr)&vkugd->driver, sizeof(vkugd->driver)); 7849 } 7850 break; 7851 case VKI_USBDEVFS_REAPURB: 7852 case VKI_USBDEVFS_REAPURBNDELAY: 7853 if ( ARG3 ) { 7854 struct vki_usbdevfs_urb **vkuu = (struct vki_usbdevfs_urb**)ARG3; 7855 POST_MEM_WRITE((Addr)vkuu, sizeof(*vkuu)); 7856 if (!*vkuu) 7857 break; 7858 POST_MEM_WRITE((Addr) &((*vkuu)->status),sizeof((*vkuu)->status)); 7859 if ((*vkuu)->type == VKI_USBDEVFS_URB_TYPE_CONTROL) { 7860 struct vki_usbdevfs_setuppacket *vkusp = (struct vki_usbdevfs_setuppacket *)(*vkuu)->buffer; 7861 if (vkusp->bRequestType & 0x80) 7862 POST_MEM_WRITE((Addr)(vkusp+1), (*vkuu)->buffer_length - sizeof(*vkusp)); 7863 POST_MEM_WRITE((Addr)&(*vkuu)->actual_length, sizeof((*vkuu)->actual_length)); 7864 } else if ((*vkuu)->type == VKI_USBDEVFS_URB_TYPE_ISO) { 7865 char *bp = (*vkuu)->buffer; 7866 int i; 7867 for(i=0; i<(*vkuu)->number_of_packets; i++) { 7868 POST_MEM_WRITE((Addr)&(*vkuu)->iso_frame_desc[i].actual_length, sizeof((*vkuu)->iso_frame_desc[i].actual_length)); 7869 POST_MEM_WRITE((Addr)&(*vkuu)->iso_frame_desc[i].status, sizeof((*vkuu)->iso_frame_desc[i].status)); 7870 if ((*vkuu)->endpoint & 0x80) 7871 POST_MEM_WRITE((Addr)bp, (*vkuu)->iso_frame_desc[i].actual_length); 7872 bp += (*vkuu)->iso_frame_desc[i].length; // FIXME: or actual_length?? 7873 } 7874 POST_MEM_WRITE((Addr)&(*vkuu)->error_count, sizeof((*vkuu)->error_count)); 7875 } else { 7876 if ((*vkuu)->endpoint & 0x80) 7877 POST_MEM_WRITE((Addr)(*vkuu)->buffer, (*vkuu)->actual_length); 7878 POST_MEM_WRITE((Addr)&(*vkuu)->actual_length, sizeof((*vkuu)->actual_length)); 7879 } 7880 } 7881 break; 7882 case VKI_USBDEVFS_CONNECTINFO: 7883 POST_MEM_WRITE(ARG3, sizeof(struct vki_usbdevfs_connectinfo)); 7884 break; 7885 case VKI_USBDEVFS_IOCTL: 7886 if ( ARG3 ) { 7887 struct vki_usbdevfs_ioctl *vkui = (struct vki_usbdevfs_ioctl *)ARG3; 7888 UInt dir2, size2; 7889 dir2 = _VKI_IOC_DIR(vkui->ioctl_code); 7890 size2 = _VKI_IOC_SIZE(vkui->ioctl_code); 7891 if (size2 > 0) { 7892 if (dir2 & _VKI_IOC_READ) 7893 POST_MEM_WRITE((Addr)vkui->data, size2); 7894 } 7895 } 7896 break; 7897 7898 /* I2C (/dev/i2c-*) ioctls */ 7899 case VKI_I2C_SLAVE: 7900 case VKI_I2C_SLAVE_FORCE: 7901 case VKI_I2C_TENBIT: 7902 case VKI_I2C_PEC: 7903 break; 7904 case VKI_I2C_FUNCS: 7905 POST_MEM_WRITE( ARG3, sizeof(unsigned long) ); 7906 break; 7907 case VKI_I2C_RDWR: 7908 if ( ARG3 ) { 7909 struct vki_i2c_rdwr_ioctl_data *vkui = (struct vki_i2c_rdwr_ioctl_data *)ARG3; 7910 UInt i; 7911 for (i=0; i < vkui->nmsgs; i++) { 7912 struct vki_i2c_msg *msg = vkui->msgs + i; 7913 if (msg->flags & VKI_I2C_M_RD) 7914 POST_MEM_WRITE((Addr)msg->buf, msg->len); 7915 } 7916 } 7917 break; 7918 7919 /* Wireless extensions ioctls */ 7920 case VKI_SIOCSIWCOMMIT: 7921 case VKI_SIOCSIWNWID: 7922 case VKI_SIOCSIWFREQ: 7923 case VKI_SIOCSIWMODE: 7924 case VKI_SIOCSIWSENS: 7925 case VKI_SIOCSIWRANGE: 7926 case VKI_SIOCSIWPRIV: 7927 case VKI_SIOCSIWSTATS: 7928 case VKI_SIOCSIWSPY: 7929 case VKI_SIOCSIWTHRSPY: 7930 case VKI_SIOCSIWAP: 7931 case VKI_SIOCSIWSCAN: 7932 case VKI_SIOCSIWESSID: 7933 case VKI_SIOCSIWRATE: 7934 case VKI_SIOCSIWNICKN: 7935 case VKI_SIOCSIWRTS: 7936 case VKI_SIOCSIWFRAG: 7937 case VKI_SIOCSIWTXPOW: 7938 case VKI_SIOCSIWRETRY: 7939 case VKI_SIOCSIWENCODE: 7940 case VKI_SIOCSIWPOWER: 7941 case VKI_SIOCSIWGENIE: 7942 case VKI_SIOCSIWMLME: 7943 case VKI_SIOCSIWAUTH: 7944 case VKI_SIOCSIWENCODEEXT: 7945 case VKI_SIOCSIWPMKSA: 7946 break; 7947 case VKI_SIOCGIWNAME: 7948 if (ARG3) { 7949 POST_MEM_WRITE((Addr)((struct vki_iwreq *)ARG3)->u.name, 7950 sizeof(((struct vki_iwreq *)ARG3)->u.name)); 7951 } 7952 break; 7953 case VKI_SIOCGIWNWID: 7954 case VKI_SIOCGIWSENS: 7955 case VKI_SIOCGIWRATE: 7956 case VKI_SIOCGIWRTS: 7957 case VKI_SIOCGIWFRAG: 7958 case VKI_SIOCGIWTXPOW: 7959 case VKI_SIOCGIWRETRY: 7960 case VKI_SIOCGIWPOWER: 7961 case VKI_SIOCGIWAUTH: 7962 if (ARG3) { 7963 POST_MEM_WRITE((Addr)&((struct vki_iwreq *)ARG3)->u.param, 7964 sizeof(struct vki_iw_param)); 7965 } 7966 break; 7967 case VKI_SIOCGIWFREQ: 7968 if (ARG3) { 7969 POST_MEM_WRITE((Addr)&((struct vki_iwreq *)ARG3)->u.freq, 7970 sizeof(struct vki_iw_freq)); 7971 } 7972 break; 7973 case VKI_SIOCGIWMODE: 7974 if (ARG3) { 7975 POST_MEM_WRITE((Addr)&((struct vki_iwreq *)ARG3)->u.mode, 7976 sizeof(__vki_u32)); 7977 } 7978 break; 7979 case VKI_SIOCGIWRANGE: 7980 case VKI_SIOCGIWPRIV: 7981 case VKI_SIOCGIWSTATS: 7982 case VKI_SIOCGIWSPY: 7983 case VKI_SIOCGIWTHRSPY: 7984 case VKI_SIOCGIWAPLIST: 7985 case VKI_SIOCGIWSCAN: 7986 case VKI_SIOCGIWESSID: 7987 case VKI_SIOCGIWNICKN: 7988 case VKI_SIOCGIWENCODE: 7989 case VKI_SIOCGIWGENIE: 7990 case VKI_SIOCGIWENCODEEXT: 7991 if (ARG3) { 7992 struct vki_iw_point* point; 7993 point = &((struct vki_iwreq *)ARG3)->u.data; 7994 POST_MEM_WRITE((Addr)point->pointer, point->length); 7995 } 7996 break; 7997 case VKI_SIOCGIWAP: 7998 if (ARG3) { 7999 POST_MEM_WRITE((Addr)&((struct vki_iwreq *)ARG3)->u.ap_addr, 8000 sizeof(struct vki_sockaddr)); 8001 } 8002 break; 8003 8004 # if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \ 8005 || defined(VGPV_mips32_linux_android) 8006 /* ashmem */ 8007 case VKI_ASHMEM_GET_SIZE: 8008 case VKI_ASHMEM_SET_SIZE: 8009 case VKI_ASHMEM_GET_PROT_MASK: 8010 case VKI_ASHMEM_SET_PROT_MASK: 8011 case VKI_ASHMEM_GET_PIN_STATUS: 8012 case VKI_ASHMEM_PURGE_ALL_CACHES: 8013 case VKI_ASHMEM_SET_NAME: 8014 case VKI_ASHMEM_PIN: 8015 case VKI_ASHMEM_UNPIN: 8016 break; 8017 case VKI_ASHMEM_GET_NAME: 8018 POST_MEM_WRITE( ARG3, VKI_ASHMEM_NAME_LEN ); 8019 break; 8020 8021 /* binder */ 8022 case VKI_BINDER_WRITE_READ: 8023 if (ARG3) { 8024 struct vki_binder_write_read* bwr 8025 = (struct vki_binder_write_read*)ARG3; 8026 POST_FIELD_WRITE(bwr->write_consumed); 8027 POST_FIELD_WRITE(bwr->read_consumed); 8028 8029 if (bwr->read_size) 8030 POST_MEM_WRITE((Addr)bwr->read_buffer, bwr->read_consumed); 8031 } 8032 break; 8033 8034 case VKI_BINDER_SET_IDLE_TIMEOUT: 8035 case VKI_BINDER_SET_MAX_THREADS: 8036 case VKI_BINDER_SET_IDLE_PRIORITY: 8037 case VKI_BINDER_SET_CONTEXT_MGR: 8038 case VKI_BINDER_THREAD_EXIT: 8039 break; 8040 case VKI_BINDER_VERSION: 8041 if (ARG3) { 8042 struct vki_binder_version* bv = (struct vki_binder_version*)ARG3; 8043 POST_FIELD_WRITE(bv->protocol_version); 8044 } 8045 break; 8046 # endif /* defined(VGPV_*_linux_android) */ 8047 8048 case VKI_HCIINQUIRY: 8049 if (ARG3) { 8050 struct vki_hci_inquiry_req* ir = (struct vki_hci_inquiry_req*)ARG3; 8051 POST_MEM_WRITE((Addr)ARG3 + sizeof(struct vki_hci_inquiry_req), 8052 ir->num_rsp * sizeof(struct vki_inquiry_info)); 8053 } 8054 break; 8055 8056 /* KVM ioctls that only write the system call return value */ 8057 case VKI_KVM_GET_API_VERSION: 8058 case VKI_KVM_CREATE_VM: 8059 case VKI_KVM_CHECK_EXTENSION: 8060 case VKI_KVM_GET_VCPU_MMAP_SIZE: 8061 case VKI_KVM_S390_ENABLE_SIE: 8062 case VKI_KVM_CREATE_VCPU: 8063 case VKI_KVM_CREATE_IRQCHIP: 8064 case VKI_KVM_RUN: 8065 case VKI_KVM_S390_INITIAL_RESET: 8066 break; 8067 8068 #ifdef ENABLE_XEN 8069 case VKI_XEN_IOCTL_PRIVCMD_HYPERCALL: { 8070 SyscallArgs harrghs; 8071 struct vki_xen_privcmd_hypercall *args = 8072 (struct vki_xen_privcmd_hypercall *)(ARG3); 8073 8074 if (!args) 8075 break; 8076 8077 VG_(memset)(&harrghs, 0, sizeof(harrghs)); 8078 harrghs.sysno = args->op; 8079 harrghs.arg1 = args->arg[0]; 8080 harrghs.arg2 = args->arg[1]; 8081 harrghs.arg3 = args->arg[2]; 8082 harrghs.arg4 = args->arg[3]; 8083 harrghs.arg5 = args->arg[4]; 8084 harrghs.arg6 = harrghs.arg7 = harrghs.arg8 = 0; 8085 8086 WRAPPER_POST_NAME(xen, hypercall) (tid, &harrghs, status); 8087 break; 8088 }; 8089 8090 case VKI_XEN_IOCTL_PRIVCMD_MMAP: 8091 break; 8092 case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH: { 8093 struct vki_xen_privcmd_mmapbatch *args = 8094 (struct vki_xen_privcmd_mmapbatch *)(ARG3); 8095 POST_MEM_WRITE((Addr)args->arr, sizeof(*(args->arr)) * args->num); 8096 } 8097 break; 8098 case VKI_XEN_IOCTL_PRIVCMD_MMAPBATCH_V2: { 8099 struct vki_xen_privcmd_mmapbatch_v2 *args = 8100 (struct vki_xen_privcmd_mmapbatch_v2 *)(ARG3); 8101 POST_MEM_WRITE((Addr)args->err, sizeof(*(args->err)) * args->num); 8102 } 8103 break; 8104 #endif 8105 8106 case VKI_EVIOCSSUSPENDBLOCK: 8107 POST_MEM_WRITE( ARG3, sizeof(int) ); 8108 break; 8109 8110 case VKI_MEDIA_IOC_DEVICE_INFO: 8111 if (ARG3) { 8112 POST_MEM_WRITE(ARG3, sizeof(struct vki_media_device_info)); 8113 } 8114 break; 8115 8116 default: 8117 /* EVIOC* are variable length and return size written on success */ 8118 switch (ARG2 & ~(_VKI_IOC_SIZEMASK << _VKI_IOC_SIZESHIFT)) { 8119 case VKI_EVIOCGNAME(0): 8120 case VKI_EVIOCGPHYS(0): 8121 case VKI_EVIOCGUNIQ(0): 8122 case VKI_EVIOCGKEY(0): 8123 case VKI_EVIOCGLED(0): 8124 case VKI_EVIOCGSND(0): 8125 case VKI_EVIOCGSW(0): 8126 case VKI_EVIOCGBIT(VKI_EV_SYN,0): 8127 case VKI_EVIOCGBIT(VKI_EV_KEY,0): 8128 case VKI_EVIOCGBIT(VKI_EV_REL,0): 8129 case VKI_EVIOCGBIT(VKI_EV_ABS,0): 8130 case VKI_EVIOCGBIT(VKI_EV_MSC,0): 8131 case VKI_EVIOCGBIT(VKI_EV_SW,0): 8132 case VKI_EVIOCGBIT(VKI_EV_LED,0): 8133 case VKI_EVIOCGBIT(VKI_EV_SND,0): 8134 case VKI_EVIOCGBIT(VKI_EV_REP,0): 8135 case VKI_EVIOCGBIT(VKI_EV_FF,0): 8136 case VKI_EVIOCGBIT(VKI_EV_PWR,0): 8137 case VKI_EVIOCGBIT(VKI_EV_FF_STATUS,0): 8138 if (RES > 0) 8139 POST_MEM_WRITE(ARG3, RES); 8140 break; 8141 default: 8142 ML_(POST_unknown_ioctl)(tid, RES, ARG2, ARG3); 8143 break; 8144 } 8145 break; 8146 } 8147 } 8148 8149 /* --------------------------------------------------------------------- 8150 socketcall wrapper helpers 8151 ------------------------------------------------------------------ */ 8152 8153 void 8154 ML_(linux_PRE_sys_getsockopt) ( ThreadId tid, 8155 UWord arg0, UWord arg1, UWord arg2, 8156 UWord arg3, UWord arg4 ) 8157 { 8158 /* int getsockopt(int s, int level, int optname, 8159 void *optval, socklen_t *optlen); */ 8160 Addr optval_p = arg3; 8161 Addr optlen_p = arg4; 8162 /* vg_assert(sizeof(socklen_t) == sizeof(UInt)); */ 8163 if (optval_p != (Addr)NULL) { 8164 ML_(buf_and_len_pre_check) ( tid, optval_p, optlen_p, 8165 "socketcall.getsockopt(optval)", 8166 "socketcall.getsockopt(optlen)" ); 8167 if (arg1 == VKI_SOL_SCTP && 8168 (arg2 == VKI_SCTP_GET_PEER_ADDRS || 8169 arg2 == VKI_SCTP_GET_LOCAL_ADDRS)) 8170 { 8171 struct vki_sctp_getaddrs *ga = (struct vki_sctp_getaddrs*)arg3; 8172 int address_bytes = sizeof(struct vki_sockaddr_in6) * ga->addr_num; 8173 PRE_MEM_WRITE( "socketcall.getsockopt(optval.addrs)", 8174 (Addr)ga->addrs, address_bytes ); 8175 } 8176 } 8177 } 8178 8179 void 8180 ML_(linux_POST_sys_getsockopt) ( ThreadId tid, 8181 SysRes res, 8182 UWord arg0, UWord arg1, UWord arg2, 8183 UWord arg3, UWord arg4 ) 8184 { 8185 Addr optval_p = arg3; 8186 Addr optlen_p = arg4; 8187 vg_assert(!sr_isError(res)); /* guaranteed by caller */ 8188 if (optval_p != (Addr)NULL) { 8189 ML_(buf_and_len_post_check) ( tid, res, optval_p, optlen_p, 8190 "socketcall.getsockopt(optlen_out)" ); 8191 if (arg1 == VKI_SOL_SCTP && 8192 (arg2 == VKI_SCTP_GET_PEER_ADDRS || 8193 arg2 == VKI_SCTP_GET_LOCAL_ADDRS)) 8194 { 8195 struct vki_sctp_getaddrs *ga = (struct vki_sctp_getaddrs*)arg3; 8196 struct vki_sockaddr *a = ga->addrs; 8197 int i; 8198 for (i = 0; i < ga->addr_num; i++) { 8199 int sl = 0; 8200 if (a->sa_family == VKI_AF_INET) 8201 sl = sizeof(struct vki_sockaddr_in); 8202 else if (a->sa_family == VKI_AF_INET6) 8203 sl = sizeof(struct vki_sockaddr_in6); 8204 else { 8205 VG_(message)(Vg_UserMsg, "Warning: getsockopt: unhandled " 8206 "address type %d\n", a->sa_family); 8207 } 8208 a = (struct vki_sockaddr*)((char*)a + sl); 8209 } 8210 POST_MEM_WRITE( (Addr)ga->addrs, (char*)a - (char*)ga->addrs ); 8211 } 8212 } 8213 } 8214 8215 void 8216 ML_(linux_PRE_sys_setsockopt) ( ThreadId tid, 8217 UWord arg0, UWord arg1, UWord arg2, 8218 UWord arg3, UWord arg4 ) 8219 { 8220 /* int setsockopt(int s, int level, int optname, 8221 const void *optval, socklen_t optlen); */ 8222 Addr optval_p = arg3; 8223 if (optval_p != (Addr)NULL) { 8224 /* 8225 * OK, let's handle at least some setsockopt levels and options 8226 * ourselves, so we don't get false claims of references to 8227 * uninitialized memory (such as padding in structures) and *do* 8228 * check what pointers in the argument point to. 8229 */ 8230 if (arg1 == VKI_SOL_SOCKET && arg2 == VKI_SO_ATTACH_FILTER) 8231 { 8232 struct vki_sock_fprog *fp = (struct vki_sock_fprog *)optval_p; 8233 8234 /* 8235 * struct sock_fprog has a 16-bit count of instructions, 8236 * followed by a pointer to an array of those instructions. 8237 * There's padding between those two elements. 8238 * 8239 * So that we don't bogusly complain about the padding bytes, 8240 * we just report that we read len and and filter. 8241 * 8242 * We then make sure that what filter points to is valid. 8243 */ 8244 PRE_MEM_READ( "setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, &optval.len)", 8245 (Addr)&fp->len, sizeof(fp->len) ); 8246 PRE_MEM_READ( "setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, &optval.filter)", 8247 (Addr)&fp->filter, sizeof(fp->filter) ); 8248 8249 /* len * sizeof (*filter) */ 8250 if (fp->filter != NULL) 8251 { 8252 PRE_MEM_READ( "setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, optval.filter)", 8253 (Addr)(fp->filter), 8254 fp->len * sizeof(*fp->filter) ); 8255 } 8256 } 8257 else 8258 { 8259 PRE_MEM_READ( "socketcall.setsockopt(optval)", 8260 arg3, /* optval */ 8261 arg4 /* optlen */ ); 8262 } 8263 } 8264 } 8265 8266 /* --------------------------------------------------------------------- 8267 ptrace wrapper helpers 8268 ------------------------------------------------------------------ */ 8269 8270 void 8271 ML_(linux_PRE_getregset) ( ThreadId tid, long arg3, long arg4 ) 8272 { 8273 struct vki_iovec *iov = (struct vki_iovec *) arg4; 8274 8275 PRE_MEM_READ("ptrace(getregset iovec->iov_base)", 8276 (unsigned long) &iov->iov_base, sizeof(iov->iov_base)); 8277 PRE_MEM_READ("ptrace(getregset iovec->iov_len)", 8278 (unsigned long) &iov->iov_len, sizeof(iov->iov_len)); 8279 PRE_MEM_WRITE("ptrace(getregset *(iovec->iov_base))", 8280 (unsigned long) iov->iov_base, iov->iov_len); 8281 } 8282 8283 void 8284 ML_(linux_PRE_setregset) ( ThreadId tid, long arg3, long arg4 ) 8285 { 8286 struct vki_iovec *iov = (struct vki_iovec *) arg4; 8287 8288 PRE_MEM_READ("ptrace(setregset iovec->iov_base)", 8289 (unsigned long) &iov->iov_base, sizeof(iov->iov_base)); 8290 PRE_MEM_READ("ptrace(setregset iovec->iov_len)", 8291 (unsigned long) &iov->iov_len, sizeof(iov->iov_len)); 8292 PRE_MEM_READ("ptrace(setregset *(iovec->iov_base))", 8293 (unsigned long) iov->iov_base, iov->iov_len); 8294 } 8295 8296 void 8297 ML_(linux_POST_getregset) ( ThreadId tid, long arg3, long arg4 ) 8298 { 8299 struct vki_iovec *iov = (struct vki_iovec *) arg4; 8300 8301 /* XXX: The actual amount of data written by the kernel might be 8302 less than iov_len, depending on the regset (arg3). */ 8303 POST_MEM_WRITE((unsigned long) iov->iov_base, iov->iov_len); 8304 } 8305 8306 #undef PRE 8307 #undef POST 8308 8309 #endif // defined(VGO_linux) 8310 8311 /*--------------------------------------------------------------------*/ 8312 /*--- end ---*/ 8313 /*--------------------------------------------------------------------*/ 8314