From: Paul Floyd Date: Sun, 25 Dec 2022 17:36:20 +0000 (+0100) Subject: Cleanup for clangd, mostly FreeBSD X-Git-Tag: VALGRIND_3_21_0~260 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=227fa1d53bccaa236af3a72764d5efe763bcf036;p=thirdparty%2Fvalgrind.git Cleanup for clangd, mostly FreeBSD Consistently use braces. Make some bitwise expressions use unsigned. Use some named variables for magic numbers. --- diff --git a/coregrind/m_debuginfo/readpdb.c b/coregrind/m_debuginfo/readpdb.c index f3a3817d89..7c5467d379 100644 --- a/coregrind/m_debuginfo/readpdb.c +++ b/coregrind/m_debuginfo/readpdb.c @@ -1545,8 +1545,9 @@ static ULong DEBUG_SnarfLinetab( Bool debug = di->trace_symtab; ULong n_lines_read = 0; - if (debug) + if (debug) { VG_(umsg)("BEGIN SnarfLineTab linetab=%p size=%d\n", linetab, size); + } /* * Now get the important bits. diff --git a/coregrind/m_initimg/initimg-freebsd.c b/coregrind/m_initimg/initimg-freebsd.c index ece565e66d..f0e2bcfd07 100644 --- a/coregrind/m_initimg/initimg-freebsd.c +++ b/coregrind/m_initimg/initimg-freebsd.c @@ -86,8 +86,9 @@ static void load_client ( /*OUT*/ExeInfo* info, /* Get hold of a file descriptor which refers to the client executable. This is needed for attaching to GDB. */ res = VG_(open)(exe_name, VKI_O_RDONLY, VKI_S_IRUSR); - if (!sr_isError(res)) + if (!sr_isError(res)) { VG_(cl_exec_fd) = sr_Res(res); + } /* Copy necessary bits of 'info' that were filled in */ *client_ip = info->init_ip; @@ -137,7 +138,8 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) HChar** cpp; HChar** ret; HChar* preload_tool_path; - Int envc, i; + Int envc; + Int i; /* Alloc space for the vgpreload_core.so path and vgpreload_.so paths. We might not need the space for vgpreload_.so, but it @@ -168,11 +170,15 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) VG_(debugLog)(2, "initimg", " \"%s\"\n", preload_string); /* Count the original size of the env */ - if (debug) VG_(printf)("\n\n"); + if (debug) { + VG_(printf)("\n\n"); + } envc = 0; for (cpp = origenv; cpp && *cpp; cpp++) { envc++; - if (debug) VG_(printf)("XXXXXXXXX: BEFORE %s\n", *cpp); + if (debug) { + VG_(printf)("XXXXXXXXX: BEFORE %s\n", *cpp); + } } /* Allocate a new space */ @@ -181,7 +187,9 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) /* copy it over */ for (cpp = ret; *origenv; ) { - if (debug) VG_(printf)("XXXXXXXXX: COPY %s\n", *origenv); + if (debug) { + VG_(printf)("XXXXXXXXX: COPY %s\n", *origenv); + } *cpp++ = *origenv++; } *cpp = NULL; @@ -202,7 +210,9 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) ld_preload_done = True; } - if (debug) VG_(printf)("XXXXXXXXX: MASH %s\n", *cpp); + if (debug) { + VG_(printf)("XXXXXXXXX: MASH %s\n", *cpp); + } } /* Add the missing bits */ @@ -213,7 +223,9 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) VG_(snprintf)(cp, len, "%s%s", ld_preload, preload_string); ret[envc++] = cp; - if (debug) VG_(printf)("XXXXXXXXX: ADD %s\n", cp); + if (debug) { + VG_(printf)("XXXXXXXXX: ADD %s\n", cp); + } } #if defined(VGP_x86_freebsd) @@ -249,13 +261,16 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) /* ret[0 .. envc-1] is live now. */ /* Find and remove a binding for VALGRIND_LAUNCHER. */ - for (i = 0; i < envc; i++) - if (0 == VG_(memcmp)(ret[i], v_launcher, v_launcher_len)) + for (i = 0; i < envc; i++) { + if (0 == VG_(memcmp)(ret[i], v_launcher, v_launcher_len)) { break; + } + } if (i < envc) { - for (; i < envc-1; i++) + for (; i < envc-1; i++) { ret[i] = ret[i+1]; + } envc--; } @@ -263,7 +278,9 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname) ret[envc] = NULL; for (i = 0; i < envc; i++) { - if (debug) VG_(printf)("XXXXXXXXX: FINAL %s\n", ret[i]); + if (debug) { + VG_(printf)("XXXXXXXXX: FINAL %s\n", ret[i]); + } } return ret; @@ -280,12 +297,14 @@ static HChar *copy_str(HChar **tab, const HChar *str) HChar *cp = *tab; HChar *orig = cp; - while(*str) + while(*str) { *cp++ = *str++; + } *cp++ = '\0'; - if (0) + if (0) { VG_(printf)("copied %p \"%s\" len %lld\n", (void*)orig, orig, (Long)(cp-orig)); + } *tab = cp; @@ -348,12 +367,14 @@ struct auxv *find_auxv(UWord* sp) { sp++; // skip argc (Nb: is word-sized, not int-sized!) - while (*sp != 0) // skip argv + while (*sp != 0) { // skip argv sp++; + } sp++; - while (*sp != 0) // skip env + while (*sp != 0) { // skip env sp++; + } sp++; return (struct auxv *)sp; @@ -411,8 +432,9 @@ Addr setup_client_stack( void* init_sp, } /* now scan the args we're given... */ - if (have_exename) + if (have_exename) { stringsize += VG_(strlen)( VG_(args_the_exename) ) + 1; + } for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) { argc++; @@ -480,7 +502,9 @@ Addr setup_client_stack( void* init_sp, auxsize + /* auxv */ VG_ROUNDUP(stringsize, sizeof(Word)); /* strings (aligned) */ - if (0) VG_(printf)("stacksize = %u\n", stacksize); + if (0) { + VG_(printf)("stacksize = %u\n", stacksize); + } /* client_SP is the client's stack pointer */ client_SP = clstack_end - stacksize; @@ -495,12 +519,13 @@ Addr setup_client_stack( void* init_sp, /* The max stack size */ clstack_max_size = VG_PGROUNDUP(clstack_max_size); - if (0) + if (0) { VG_(printf)("stringsize=%u auxsize=%u stacksize=%u maxsize=0x%lx\n" "clstack_start %p\n" "clstack_end %p\n", stringsize, auxsize, stacksize, clstack_max_size, (void*)clstack_start, (void*)clstack_end); + } /* ==================== allocate space ==================== */ @@ -540,9 +565,10 @@ Addr setup_client_stack( void* init_sp, inner_HACK = 1024*1024; // create 1M non-fault-extending stack # endif - if (0) + if (0) { VG_(printf)("%#lx 0x%lx %#lx 0x%lx\n", resvn_start, resvn_size, anon_start, anon_size); + } /* Create a shrinkable reservation followed by an anonymous segment. Together these constitute a growdown stack. */ @@ -589,13 +615,16 @@ Addr setup_client_stack( void* init_sp, /* --- client argv --- */ client_argv = (Word)ptr; - if (info->interp_name) + if (info->interp_name) { *ptr++ = (Addr)copy_str(&strtab, info->interp_name); - if (info->interp_args) + } + if (info->interp_args) { *ptr++ = (Addr)copy_str(&strtab, info->interp_args); + } - if (have_exename) + if (have_exename) { *ptr++ = (Addr)copy_str(&strtab, VG_(args_the_exename)); + } for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) { *ptr++ = (Addr)copy_str( @@ -607,8 +636,9 @@ Addr setup_client_stack( void* init_sp, /* --- envp --- */ VG_(client_envp) = (HChar **)ptr; - for (cpp = orig_envp; cpp && *cpp; ptr++, cpp++) + for (cpp = orig_envp; cpp && *cpp; ptr++, cpp++) { *ptr = (Addr)copy_str(&strtab, *cpp); + } *ptr++ = 0; /* --- auxv --- */ @@ -658,16 +688,18 @@ Addr setup_client_stack( void* init_sp, auxv->u.a_ptr = copy_str(&strtab, orig_auxv->u.a_ptr); break; case VKI_AT_CANARY: - if (canarylen >= 1) + if (canarylen >= 1) { auxv->u.a_ptr = copy_bytes(&strtab, orig_auxv->u.a_ptr, canarylen); - else + } else { auxv->a_type = VKI_AT_IGNORE; + } break; case VKI_AT_PAGESIZES: - if (pagesizeslen >= 1) + if (pagesizeslen >= 1) { auxv->u.a_ptr = copy_bytes(&strtab, orig_auxv->u.a_ptr, pagesizeslen); - else + } else { auxv->a_type = VKI_AT_IGNORE; + } break; #if 0 /* @@ -717,17 +749,19 @@ Addr setup_client_stack( void* init_sp, #endif case VKI_AT_PHDR: - if (info->phdr == 0) + if (info->phdr == 0) { auxv->a_type = VKI_AT_IGNORE; - else + } else { auxv->u.a_val = info->phdr; + } break; case VKI_AT_PHNUM: - if (info->phdr == 0) + if (info->phdr == 0) { auxv->a_type = VKI_AT_IGNORE; - else + } else { auxv->u.a_val = info->phnum; + } break; case VKI_AT_BASE: @@ -754,7 +788,9 @@ Addr setup_client_stack( void* init_sp, /* client_SP is pointing at client's argc/argv */ - if (0) VG_(printf)("startup SP = %#lx\n", client_SP); + if (0) { + VG_(printf)("startup SP = %#lx\n", client_SP); + } return client_SP; } @@ -803,8 +839,9 @@ static void setup_client_dataseg ( SizeT max_size ) SmLower, anon_size ); - if (ok) + if (ok) { VG_(brk_base) = VG_(brk_limit) = anon_start; + } } /* that too might have failed, but if it has, we're hosed: there is no Plan C. */ @@ -848,8 +885,9 @@ IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo iicii, //-------------------------------------------------------------- VG_(debugLog)(1, "initimg", "Loading client\n"); - if (VG_(args_the_exename) == NULL) + if (VG_(args_the_exename) == NULL) { VG_(err_missing_prog)(); + } VG_(memset)(&info, 0, sizeof(info)); @@ -883,10 +921,18 @@ IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo iicii, SizeT m1 = 1024 * 1024; SizeT m16 = 16 * m1; SizeT szB = (SizeT)VG_(client_rlimit_stack).rlim_cur; - if (szB < m1) szB = m1; - if (szB > m16) szB = m16; - if (VG_(clo_main_stacksize) > 0) szB = VG_(clo_main_stacksize); - if (szB < m1) szB = m1; + if (szB < m1) { + szB = m1; + } + if (szB > m16) { + szB = m16; + } + if (VG_(clo_main_stacksize) > 0) { + szB = VG_(clo_main_stacksize); + } + if (szB < m1) { + szB = m1; + } szB = VG_PGROUNDUP(szB); VG_(debugLog)(1, "initimg", "Setup client stack: size will be %lu\n", szB); @@ -923,8 +969,12 @@ IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo iicii, SizeT m8 = 8 * m1; SizeT dseg_max_size = (SizeT)VG_(client_rlimit_data).rlim_cur; VG_(debugLog)(1, "initimg", "Setup client data (brk) segment\n"); - if (dseg_max_size < m1) dseg_max_size = m1; - if (dseg_max_size > m8) dseg_max_size = m8; + if (dseg_max_size < m1) { + dseg_max_size = m1; + } + if (dseg_max_size > m8) { + dseg_max_size = m8; + } dseg_max_size = VG_PGROUNDUP(dseg_max_size); setup_client_dataseg( dseg_max_size ); @@ -988,7 +1038,7 @@ void VG_(ii_finalise_image)( IIFinaliseImageInfo iifii ) VG_(memset)(&arch->vex_shadow2, 0, sizeof(VexGuestAMD64State)); /* Put essential stuff into the new state. */ - arch->vex.guest_RSP = ((iifii.initial_client_SP - 8) & ~0xFul) + 8; + arch->vex.guest_RSP = ((iifii.initial_client_SP - 8) & ~0xFUL) + 8; arch->vex.guest_RDI = iifii.initial_client_SP; arch->vex.guest_RIP = iifii.initial_client_IP; diff --git a/coregrind/m_sigframe/sigframe-amd64-freebsd.c b/coregrind/m_sigframe/sigframe-amd64-freebsd.c index 31e6e784ae..7ae0ec291d 100644 --- a/coregrind/m_sigframe/sigframe-amd64-freebsd.c +++ b/coregrind/m_sigframe/sigframe-amd64-freebsd.c @@ -49,6 +49,8 @@ on amd64-freebsd. */ +const UInt MAGIC_PI = 0x31415927U; +const UInt MAGIC_E = 0x27182818U; /*------------------------------------------------------------*/ /*--- Signal frame layouts ---*/ @@ -153,12 +155,12 @@ void synth_ucontext(ThreadId tid, const vki_siginfo_t *si, XXX */ SC2(rip,RIP); - sc->addr = (UWord)si->si_addr; - sc->err = err; + sc->addr = (vki_register_t)si->si_addr; + sc->err = (vki_register_t)err; sc->fpformat = VKI_FPFMT_NODEV; sc->ownedfp = VKI_FPOWNED_NONE; sc->len = sizeof(*sc); - sc->rflags = LibVEX_GuestAMD64_get_rflags(&tst->arch.vex); + sc->rflags = (vki_register_t)LibVEX_GuestAMD64_get_rflags(&tst->arch.vex); sc->trapno = trapno; # undef SC2 } @@ -219,7 +221,7 @@ static void build_vg_sigframe(struct vg_sigframe *frame, Int sigNo) { frame->sigNo_private = sigNo; - frame->magicPI = 0x31415927; + frame->magicPI = MAGIC_PI; frame->vex_shadow1 = tst->arch.vex_shadow1; frame->vex_shadow2 = tst->arch.vex_shadow2; /* HACK ALERT */ @@ -227,7 +229,7 @@ static void build_vg_sigframe(struct vg_sigframe *frame, /* end HACK ALERT */ frame->mask = tst->sig_mask; frame->handlerflags = flags; - frame->magicE = 0x27182818; + frame->magicE = MAGIC_E; } static Addr build_sigframe(ThreadState *tst, @@ -268,8 +270,9 @@ static Addr build_sigframe(ThreadState *tst, VG_(memcpy)(&frame->sigInfo, siginfo, sizeof(vki_siginfo_t)); - if (sigNo == VKI_SIGILL && siginfo->si_code > 0) + if (sigNo == VKI_SIGILL && siginfo->si_code > 0) { frame->sigInfo.si_addr = (void*)tst->arch.vex.guest_RIP; + } synth_ucontext(tst->tid, siginfo, trapno, err, mask, &frame->uContext, &frame->fpstate); @@ -336,8 +339,8 @@ static Bool restore_vg_sigframe ( ThreadState *tst, struct vg_sigframe *frame, Int *sigNo ) { - if (frame->magicPI != 0x31415927 || - frame->magicE != 0x27182818) { + if (frame->magicPI != MAGIC_PI || + frame->magicE != MAGIC_E) { VG_(message)(Vg_UserMsg, "Thread %u return signal frame " "corrupted. Killing process.\n", tst->tid); @@ -419,11 +422,12 @@ void VG_(sigframe_destroy)( ThreadId tid ) VG_TRACK( die_mem_stack_signal, rsp - VG_STACK_REDZONE_SZB, size + VG_STACK_REDZONE_SZB ); - if (VG_(clo_trace_signals)) + if (VG_(clo_trace_signals)) { VG_(message)( Vg_DebugMsg, "VG_(signal_return) (thread %u): valid magic; RIP=%#llx\n", tid, tst->arch.vex.guest_RIP); + } /* tell the tools */ VG_TRACK( post_deliver_signal, tid, sigNo ); diff --git a/coregrind/m_syswrap/priv_types_n_macros.h b/coregrind/m_syswrap/priv_types_n_macros.h index 461019ad7b..dd241839a6 100644 --- a/coregrind/m_syswrap/priv_types_n_macros.h +++ b/coregrind/m_syswrap/priv_types_n_macros.h @@ -180,12 +180,12 @@ typedef SyscallArgLayout; /* Flags describing syscall wrappers */ -#define SfMayBlock (1 << 1) /* may block */ -#define SfPostOnFail (1 << 2) /* call POST() function on failure */ -#define SfPollAfter (1 << 3) /* poll for signals on completion */ -#define SfYieldAfter (1 << 4) /* yield on completion */ -#define SfNoWriteResult (1 << 5) /* don't write result to guest state */ -#define SfKernelRestart (1 << 6) /* needs a manual restart */ +#define SfMayBlock (1U << 1U) /* may block */ +#define SfPostOnFail (1U << 2U) /* call POST() function on failure */ +#define SfPollAfter (1U << 3U) /* poll for signals on completion */ +#define SfYieldAfter (1U << 4U) /* yield on completion */ +#define SfNoWriteResult (1U << 5U) /* don't write result to guest state */ +#define SfKernelRestart (1U << 6U) /* needs a manual restart */ /* --------------------------------------------------------------------- diff --git a/coregrind/m_syswrap/syswrap-amd64-freebsd.c b/coregrind/m_syswrap/syswrap-amd64-freebsd.c index aa58140e2c..52eeb808cc 100644 --- a/coregrind/m_syswrap/syswrap-amd64-freebsd.c +++ b/coregrind/m_syswrap/syswrap-amd64-freebsd.c @@ -761,10 +761,11 @@ PRE(sys_pread) unsigned int, fd, char *, buf, vki_size_t, count, unsigned long, off); - if (!ML_(fd_allowed)(ARG1, "read", tid, False)) + if (!ML_(fd_allowed)(ARG1, "read", tid, False)) { SET_STATUS_Failure( VKI_EBADF ); - else + } else { PRE_MEM_WRITE( "pread(buf)", ARG2, ARG3 ); + } } POST(sys_pread) @@ -789,10 +790,11 @@ PRE(sys_pwrite) if (!ok && ARG1 == 2/*stderr*/ && SimHintiS(SimHint_enable_outer, VG_(clo_sim_hints))) ok = True; - if (!ok) + if (!ok) { SET_STATUS_Failure( VKI_EBADF ); - else + } else { PRE_MEM_READ( "pwrite(buf)", ARG2, ARG3 ); + } } // SYS_mmap 477 diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index 71443e399b..8bf4fcddee 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -90,9 +90,10 @@ static VgSchedReturnCode thread_wrapper(Word /*ThreadId*/ tidW) /* make sure we get the CPU lock before doing anything significant */ VG_(acquire_BigLock)(tid, "thread_wrapper(starting new thread)"); - if (0) + if (0) { VG_(printf)("thread tid %u started: stack = %p\n", tid, (void*)&tid); + } /* Make sure error reporting is enabled in the new thread. */ tst->err_disablement_level = 0; @@ -171,8 +172,9 @@ static void run_a_thread_NORETURN ( Word tidW ) vg_assert(c >= 1); /* stay sane */ /* Deregister thread's stack. */ - if (tst->os_state.stk_id != NULL_STK_ID) + if (tst->os_state.stk_id != NULL_STK_ID) { VG_(deregister_stack)(tst->os_state.stk_id); + } // Tell the tool this thread is exiting VG_TRACK( pre_thread_ll_exit, tid ); @@ -312,11 +314,12 @@ Addr ML_(allocstack)(ThreadId tid) } } - if (0) + if (0) { VG_(printf)( "stack for tid %u at %p; init_SP=%p\n", tid, (void*)tst->os_state.valgrind_stack_base, (void*)tst->os_state.valgrind_stack_init_SP ); + } return tst->os_state.valgrind_stack_init_SP; } @@ -394,9 +397,10 @@ SysRes ML_(do_fork) ( ThreadId tid ) /* parent */ VG_(do_atfork_parent)(tid); - if (VG_(clo_trace_syscalls)) + if (VG_(clo_trace_syscalls)) { VG_(printf)(" clone(fork): process %d created child %lu\n", VG_(getpid)(), sr_Res(res)); + } /* restore signal mask */ VG_(sigprocmask)(VKI_SIG_SETMASK, &fork_saved_mask, NULL); @@ -454,8 +458,9 @@ PRE(sys_exit) /* Mark all threads (including this one) to exit. */ for (t = 1; t < VG_N_THREADS; t++) { - if ( /* not alive */ VG_(threads)[t].status == VgTs_Empty ) + if ( /* not alive */ VG_(threads)[t].status == VgTs_Empty ) { continue; + } //VG_(threads)[t].exitreason = VgSrc_ExitThread; VG_(threads)[t].os_state.exitcode = ARG1; @@ -573,11 +578,8 @@ PRE(sys_ptrace) switch (ARG1) { case VKI_PTRACE_TRACEME: - break; case VKI_PTRACE_READ_I: case VKI_PTRACE_READ_D: - break; - case VKI_PTRACE_WRITE_I: case VKI_PTRACE_WRITE_D: break; @@ -598,46 +600,38 @@ PRE(sys_ptrace) break; case VKI_PTRACE_CONTINUE: - break; - case VKI_PTRACE_STEP: - break; - case VKI_PTRACE_KILL: - break; - case VKI_PTRACE_ATTACH: - break; - case VKI_PTRACE_DETACH: break; case VKI_PTRACE_GETREGS: - PRE_MEM_WRITE( "ptrace", ARG3, sizeof(struct vki_user_regs_struct)); + PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_user_regs_struct)); break; case VKI_PTRACE_SETREGS: - PRE_MEM_READ( "ptrace", ARG3, sizeof(struct vki_user_regs_struct)); + PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_user_regs_struct)); break; case VKI_PTRACE_GETFPREGS: - PRE_MEM_WRITE( "ptrace", ARG3, sizeof(struct vki_fpreg)); + PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_fpreg)); break; case VKI_PTRACE_SETFPREGS: - PRE_MEM_READ( "ptrace", ARG3, sizeof(struct vki_fpreg)); + PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_fpreg)); break; case VKI_PTRACE_GETDBREGS: - PRE_MEM_WRITE( "ptrace", ARG3, sizeof(struct vki_dbreg)); + PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_dbreg)); break; case VKI_PTRACE_SETDBREGS: - PRE_MEM_READ( "ptrace", ARG3, sizeof(struct vki_dbreg)); + PRE_MEM_READ("ptrace", ARG3, sizeof(struct vki_dbreg)); break; case VKI_PTRACE_LWPINFO: - PRE_MEM_WRITE( "ptrace", ARG3, sizeof(struct vki_ptrace_lwpinfo)); + PRE_MEM_WRITE("ptrace", ARG3, sizeof(struct vki_ptrace_lwpinfo)); break; case VKI_PTRACE_GETNUMLWPS: @@ -648,29 +642,14 @@ PRE(sys_ptrace) break; case VKI_PTRACE_SETSTEP: - break; - case VKI_PTRACE_CLEARSTEP: - break; - case VKI_PTRACE_SUSPEND: - break; - case VKI_PTRACE_RESUME: - break; - case VKI_PTRACE_TO_SCE: - break; - case VKI_PTRACE_TO_SCX: - break; - case VKI_PTRACE_SYSCALL: - break; - case VKI_PTRACE_VM_TIMESTAMP: break; - case VKI_PTRACE_VM_ENTRY: PRE_MEM_WRITE( "ptrace", ARG3, sizeof(struct vki_ptrace_vm_entry)); break; @@ -683,11 +662,8 @@ POST(sys_ptrace) switch (ARG1) { case VKI_PTRACE_TRACEME: - break; case VKI_PTRACE_READ_I: case VKI_PTRACE_READ_D: - break; - case VKI_PTRACE_WRITE_I: case VKI_PTRACE_WRITE_D: break; @@ -697,8 +673,9 @@ POST(sys_ptrace) switch (io_desc->piod_op) { case VKI_PIOD_READ_D: case VKI_PIOD_READ_I: - if ((Word)RES != -1) + if ((Word)RES != -1) { POST_MEM_WRITE((UWord)io_desc->piod_addr, io_desc->piod_len); + } break; case VKI_PIOD_WRITE_D: case VKI_PIOD_WRITE_I: @@ -707,84 +684,68 @@ POST(sys_ptrace) break; case VKI_PTRACE_CONTINUE: - break; - case VKI_PTRACE_STEP: - break; - case VKI_PTRACE_KILL: - break; - case VKI_PTRACE_ATTACH: - break; - case VKI_PTRACE_DETACH: break; case VKI_PTRACE_GETREGS: - if ((Word)RES != -1) + if ((Word)RES != -1) { POST_MEM_WRITE(ARG3, sizeof(struct vki_user_regs_struct)); + } break; case VKI_PTRACE_SETREGS: break; case VKI_PTRACE_GETFPREGS: - if ((Word)RES != -1) + if ((Word)RES != -1) { POST_MEM_WRITE(ARG3, sizeof(struct vki_fpreg)); + } break; case VKI_PTRACE_SETFPREGS: break; case VKI_PTRACE_GETDBREGS: - if ((Word)RES != -1) + if ((Word)RES != -1) { POST_MEM_WRITE(ARG3, sizeof(struct vki_dbreg)); + } break; case VKI_PTRACE_SETDBREGS: break; case VKI_PTRACE_LWPINFO: - if ((Word)RES != -1) + if ((Word)RES != -1) { POST_MEM_WRITE(ARG3, sizeof(struct vki_ptrace_lwpinfo)); + } break; case VKI_PTRACE_GETNUMLWPS: break; case VKI_PTRACE_GETLWPLIST: - if ((Word)RES != -1) + if ((Word)RES != -1) { POST_MEM_WRITE(ARG3, sizeof(vki_lwpid_t) * RES); + } break; case VKI_PTRACE_SETSTEP: - break; - case VKI_PTRACE_CLEARSTEP: - break; - case VKI_PTRACE_SUSPEND: - break; - case VKI_PTRACE_RESUME: - break; - case VKI_PTRACE_TO_SCE: - break; - case VKI_PTRACE_TO_SCX: - break; - case VKI_PTRACE_SYSCALL: - break; - case VKI_PTRACE_VM_TIMESTAMP: break; case VKI_PTRACE_VM_ENTRY: - if ((Word)RES != -1) + if ((Word)RES != -1) { POST_MEM_WRITE(ARG3, sizeof(struct vki_ptrace_vm_entry)); + } break; } } @@ -1022,8 +983,9 @@ PRE(sys_ioctl) /* Check if have not already moaned for this request. */ UInt i; for (i = 0; i < sizeof(unknown_ioctl)/sizeof(unknown_ioctl[0]); i++) { - if (unknown_ioctl[i] == ARG2) + if (unknown_ioctl[i] == ARG2) { break; + } if (unknown_ioctl[i] == 0) { unknown_ioctl[i] = ARG2; moans--; @@ -1037,10 +999,12 @@ PRE(sys_ioctl) } } } else { - if ((dir & _VKI_IOC_WRITE) && size > 0) + if ((dir & _VKI_IOC_WRITE) && size > 0) { PRE_MEM_READ( "ioctl(generic)", ARG3, size); - if ((dir & _VKI_IOC_READ) && size > 0) + } + if ((dir & _VKI_IOC_READ) && size > 0) { PRE_MEM_WRITE( "ioctl(generic)", ARG3, size); + } } // The block below is from Ryan Stone @@ -1111,8 +1075,9 @@ POST(sys_ioctl) UInt size = _VKI_IOC_SIZE(ARG2); vg_assert(SUCCESS); if (size > 0 && (dir & _VKI_IOC_READ) - && RES == 0 && ARG3 != (Addr)NULL) + && RES == 0 && ARG3 != (Addr)NULL) { POST_MEM_WRITE(ARG3, size); + } #if 0 /* Handle specific ioctls which pass structures which may have pointers to other @@ -1353,16 +1318,18 @@ POST(sys_fcntl) VG_(close)(RES); SET_STATUS_Failure( VKI_EMFILE ); } else { - if (VG_(clo_track_fds)) + if (VG_(clo_track_fds)) { ML_(record_fd_open_named)(tid, RES); + } } } else if (ARG2 == VKI_F_DUPFD_CLOEXEC) { if (!ML_(fd_allowed)(RES, "fcntl(DUPFD_CLOEXEC)", tid, True)) { VG_(close)(RES); SET_STATUS_Failure( VKI_EMFILE ); } else { - if (VG_(clo_track_fds)) + if (VG_(clo_track_fds)) { ML_(record_fd_open_named)(tid, RES); + } } } } @@ -1718,8 +1685,9 @@ PRE(sys_rtprio) POST(sys_rtprio) { - if (ARG1 == VKI_RTP_LOOKUP && RES == 0) + if (ARG1 == VKI_RTP_LOOKUP && RES == 0) { POST_MEM_WRITE( ARG3, sizeof(struct vki_rtprio)); + } } // freebsd6_pread 173 FREEBSD_VERS <= 10 @@ -1891,8 +1859,9 @@ PRE(sys_freebsd11_getdirentries) int, nbytes, long *, basep); PRE_MEM_WRITE( "getdirentries(buf)", ARG2, ARG3 ); - if (ARG4) + if (ARG4) { PRE_MEM_WRITE( "getdirentries(basep)", ARG4, sizeof(long) ); + } } POST(sys_freebsd11_getdirentries) @@ -1900,8 +1869,9 @@ POST(sys_freebsd11_getdirentries) vg_assert(SUCCESS); if (RES > 0) { POST_MEM_WRITE( ARG2, RES ); - if ( ARG4 != 0 ) + if ( ARG4 != 0 ) { POST_MEM_WRITE( ARG4, sizeof (long)); + } } } #else @@ -2059,8 +2029,9 @@ PRE(sys___sysctl) PRE_MEM_READ("sysctl(name)", (Addr)ARG1, ARG2 * sizeof(int)); // if 'newp' is not NULL can read namelen bytes from that address - if (ARG5 != (UWord)NULL) + if (ARG5 != (UWord)NULL) { PRE_MEM_READ("sysctl(newp)", (Addr)ARG5, ARG6); + } // there are two scenarios for oldlenp/oldp // 1. oldval is NULL and oldlenp is non-NULL @@ -2094,8 +2065,9 @@ POST(sys___sysctl) if (ARG3 != (UWord)NULL) { //POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t)); POST_MEM_WRITE((Addr)ARG3, *(vki_size_t *)ARG4); - } else + } else { POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t)); + } } } @@ -2121,8 +2093,9 @@ PRE(sys_futimes) { PRINT("sys_lutimes ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2); PRE_REG_READ2(long, "futimes", int, fd, struct timeval *, times); - if (ARG2 != 0) + if (ARG2 != 0) { PRE_MEM_READ( "futimes(times)", ARG2, sizeof(struct vki_timeval) ); + } } // SYS_getpgid 207 @@ -2265,10 +2238,11 @@ PRE(sys_shmat) PRE_REG_READ3(void *, "shmat", int, shmid, const void *, addr, int, flag); arg2tmp = ML_(generic_PRE_sys_shmat)(tid, ARG1,ARG2,ARG3); - if (arg2tmp == 0) + if (arg2tmp == 0) { SET_STATUS_Failure( VKI_EINVAL ); - else + } else { ARG2 = arg2tmp; + } } POST(sys_shmat) @@ -2308,8 +2282,9 @@ PRE(sys_shmdt) { PRINT("sys_shmdt ( %#" FMT_REGWORD "x )",ARG1); PRE_REG_READ1(int, "shmdt", const void *, addr); - if (!ML_(generic_PRE_sys_shmdt)(tid, ARG1)) + if (!ML_(generic_PRE_sys_shmdt)(tid, ARG1)) { SET_STATUS_Failure( VKI_EINVAL ); + } } POST(sys_shmdt) @@ -2360,14 +2335,16 @@ PRE(sys_clock_getres) // defined above! PRE_REG_READ2(int, "clock_getres", vki_clockid_t, clock_id, struct timespec *, tp); - if (ARG2 != 0) + if (ARG2 != 0) { PRE_MEM_WRITE( "clock_getres(tp)", ARG2, sizeof(struct vki_timespec) ); + } } POST(sys_clock_getres) { - if (ARG2 != 0) + if (ARG2 != 0) { POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) ); + } } // SYS_ktimer_create 235 @@ -2379,8 +2356,9 @@ PRE(sys_timer_create) PRE_REG_READ3(int, "timer_create", vki_clockid_t, clockid, struct sigevent *, evp, vki_timer_t *, timerid); - if (ARG2 != 0) + if (ARG2 != 0) { PRE_MEM_READ( "timer_create(evp)", ARG2, sizeof(struct vki_sigevent) ); + } PRE_MEM_WRITE( "timer_create(timerid)", ARG3, sizeof(vki_timer_t) ); } @@ -2410,15 +2388,17 @@ PRE(sys_timer_settime) struct itimerspec *, ovalue); PRE_MEM_READ( "timer_settime(value)", ARG3, sizeof(struct vki_itimerspec) ); - if (ARG4 != 0) + if (ARG4 != 0) { PRE_MEM_WRITE( "timer_settime(ovalue)", ARG4, sizeof(struct vki_itimerspec) ); + } } POST(sys_timer_settime) { - if (ARG4 != 0) + if (ARG4 != 0) { POST_MEM_WRITE( ARG4, sizeof(struct vki_itimerspec) ); + } } // SYS_ktimer_gettime 238 @@ -2471,15 +2451,16 @@ PRE(sys_clock_nanosleep) PRE_REG_READ4(int, "clock_nanosleep", clockid_t, clock_id, int, flags, const struct timespec *, rqtp, struct timespec *, rmtp); PRE_MEM_READ("clock_nanosleep(rqtp)", ARG1, sizeof(struct vki_timespec)); - if (ARG2 != 0) + if (ARG2 != 0) { PRE_MEM_WRITE( "clock_nanosleep(rmtp)", ARG2, sizeof(struct vki_timespec) ); - + } } POST(sys_clock_nanosleep) { - if (ARG2 != 0) + if (ARG2 != 0) { POST_MEM_WRITE( ARG2, sizeof(struct vki_timespec) ); + } } // SYS_clock_getcpuclockid2 247 @@ -2502,14 +2483,16 @@ PRE(sys_minherit) PRINT("sys_minherit( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %" FMT_REGWORD "u )", ARG1,ARG2,ARG3); PRE_REG_READ3(int, "minherit", void *, addr, vki_size_t, len, int, inherit); - if (ARG2 != 0) + if (ARG2 != 0) { PRE_MEM_WRITE( "minherit(addr)", ARG1,ARG2 ); + } } POST(sys_minherit) { - if (ARG2 != 0) + if (ARG2 != 0) { POST_MEM_WRITE( ARG1, ARG2 ); + } } // SYS_rfork 251 @@ -2622,8 +2605,9 @@ PRE(sys_lutimes) PRINT("sys_lutimes ( %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,(char *)ARG1,ARG2); PRE_REG_READ2(int, "lutimes", char *, path, struct timeval *, times); PRE_MEM_RASCIIZ( "lutimes(path)", ARG1 ); - if (ARG2 != 0) + if (ARG2 != 0) { PRE_MEM_READ( "lutimes(times)", ARG2, sizeof(struct vki_timeval) ); + } } // SYS_freebsd11_nstat 278 @@ -2661,8 +2645,9 @@ POST(sys_fhopen) VG_(close)(RES); SET_STATUS_Failure( VKI_EMFILE ); } else { - if (VG_(clo_track_fds)) + if (VG_(clo_track_fds)) { ML_(record_fd_open_nameless)(tid, RES); + } } } @@ -2932,9 +2917,10 @@ PRE(sys_sched_setscheduler) PRINT("sys_sched_setscheduler ( %" FMT_REGWORD "d, %" FMT_REGWORD "d, %#" FMT_REGWORD "x )", SARG1,SARG2,ARG3); PRE_REG_READ3(int, "sched_setscheduler", vki_pid_t, pid, int, policy, struct sched_param *, param); - if (ARG3 != 0) + if (ARG3 != 0) { PRE_MEM_READ("sched_setscheduler(param)", ARG3, sizeof(struct vki_sched_param)); + } } // SYS_sched_getscheduler 330 @@ -3033,10 +3019,12 @@ PRE(sys_sigprocmask) PRINT("sys_sigprocmask ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3); PRE_REG_READ3(int, "sigprocmask", int, how, vki_sigset_t *, set, vki_sigset_t *, oset); - if (ARG2 != 0) + if (ARG2 != 0) { PRE_MEM_READ( "sigprocmask(set)", ARG2, sizeof(vki_sigset_t)); - if (ARG3 != 0) + } + if (ARG3 != 0) { PRE_MEM_WRITE( "sigprocmask(oset)", ARG3, sizeof(vki_sigset_t)); + } if (ARG2 != 0 && !ML_(safe_to_deref)((void *)(Addr)ARG2, sizeof(vki_sigset_t))) { @@ -3054,15 +3042,17 @@ PRE(sys_sigprocmask) (vki_sigset_t*)(Addr)ARG3)); } - if (SUCCESS) + if (SUCCESS) { *flags |= SfPollAfter; + } } POST(sys_sigprocmask) { vg_assert(SUCCESS); - if (RES == 0 && ARG3 != 0) + if (RES == 0 && ARG3 != 0) { POST_MEM_WRITE( ARG3, sizeof(vki_sigset_t)); + } } // SYS_sigsuspend 341 @@ -3109,19 +3099,23 @@ PRE(sys_sigtimedwait) PRE_REG_READ3(int, "sigtimedwait", const vki_sigset_t *, set, vki_siginfo_t *, info, const struct timespec *, timeout); - if (ARG1 != 0) + if (ARG1 != 0) { PRE_MEM_READ( "sigtimedwait(set)", ARG1, sizeof(vki_sigset_t)); - if (ARG2 != 0) + } + if (ARG2 != 0) { PRE_MEM_WRITE( "sigtimedwait(info)", ARG2, sizeof(vki_siginfo_t) ); - if (ARG3 != 0) + } + if (ARG3 != 0) { PRE_MEM_READ( "sigtimedwait(timeout)", ARG3, sizeof(struct vki_timespec) ); + } } POST(sys_sigtimedwait) { - if (ARG2 != 0) + if (ARG2 != 0) { POST_MEM_WRITE( ARG2, sizeof(vki_siginfo_t) ); + } } // SYS_sigwaitinfo 346 @@ -3133,16 +3127,19 @@ PRE(sys_sigwaitinfo) ARG1,ARG2); PRE_REG_READ2(int, "sigwaitinfo", const vki_sigset_t *, set, vki_siginfo_t *, info); - if (ARG1 != 0) + if (ARG1 != 0) { PRE_MEM_READ( "sigwaitinfo(set)", ARG1, sizeof(vki_sigset_t)); - if (ARG2 != 0) + } + if (ARG2 != 0) { PRE_MEM_WRITE( "sigwaitinfo(info)", ARG2, sizeof(vki_siginfo_t) ); + } } POST(sys_sigwaitinfo) { - if (ARG2 != 0) + if (ARG2 != 0) { POST_MEM_WRITE( ARG2, sizeof(vki_siginfo_t) ); + } } // SYS___acl_get_file 347 @@ -3396,23 +3393,28 @@ PRE(sys_freebsd11_kevent) int, fd, const struct vki_kevent_freebsd11 *, changelist, int, nchanges, struct vki_kevent_freebsd11 *, eventlist, int, nevents, struct timespec *, timeout); - if (ARG2 != 0 && ARG3 != 0) + if (ARG2 != 0 && ARG3 != 0) { PRE_MEM_READ( "kevent(changelist)", ARG2, sizeof(struct vki_kevent_freebsd11)*ARG3 ); - if (ARG4 != 0 && ARG5 != 0) + } + if (ARG4 != 0 && ARG5 != 0) { PRE_MEM_WRITE( "kevent(eventlist)", ARG4, sizeof(struct vki_kevent_freebsd11)*ARG5); - if (ARG5 != 0) + } + if (ARG5 != 0) { *flags |= SfMayBlock; - if (ARG6 != 0) + } + if (ARG6 != 0) { PRE_MEM_READ( "kevent(timeout)", ARG6, sizeof(struct vki_timespec)); + } } POST(sys_freebsd11_kevent) { vg_assert(SUCCESS); if ((Word)RES != -1) { - if (ARG4 != 0) + if (ARG4 != 0) { POST_MEM_WRITE( ARG4, sizeof(struct vki_kevent_freebsd11)*RES) ; + } } } #else @@ -3555,8 +3557,9 @@ POST(sys_kenv) POST_MEM_WRITE(ARG3, ARG4); break; case VKI_KENV_DUMP: - if (ARG3 != (Addr)NULL) + if (ARG3 != (Addr)NULL) { POST_MEM_WRITE(ARG3, ARG4); + } break; } } @@ -3584,8 +3587,9 @@ PRE(sys_uuidgen) POST(sys_uuidgen) { - if (SUCCESS) + if (SUCCESS) { POST_MEM_WRITE( ARG1, ARG2 * sizeof(struct vki_uuid) ); + } } // SYS_sendfile 393 @@ -3812,8 +3816,10 @@ PRE(sys_extattr_delete_link) // struct sigaction * restrict oact); PRE(sys_sigaction) { - vki_sigaction_toK_t new, *newp; - vki_sigaction_fromK_t old, *oldp; + vki_sigaction_toK_t new; + vki_sigaction_toK_t *newp; + vki_sigaction_fromK_t old; + vki_sigaction_fromK_t *oldp; PRINT("sys_sigaction ( %" FMT_REGWORD "d, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", SARG1,ARG2,ARG3); @@ -3874,8 +3880,9 @@ PRE(sys_sigaction) POST(sys_sigaction) { vg_assert(SUCCESS); - if (RES == 0 && ARG3 != 0) + if (RES == 0 && ARG3 != 0) { POST_MEM_WRITE( ARG3, sizeof(struct vki_sigaction)); + } } // SYS_sigreturn 417 @@ -3893,8 +3900,9 @@ POST(sys_getcontext) POST(sys_swapcontext) { - if (SUCCESS) + if (SUCCESS) { POST_MEM_WRITE( ARG1, sizeof(struct vki_ucontext) ); + } } #if (FREEBSD_VERS >= FREEBSD_13_1) @@ -3976,16 +3984,19 @@ PRE(sys_sigwait) ARG1,ARG2); PRE_REG_READ2(int, "sigwait", const vki_sigset_t *, set, int *, sig); - if (ARG1 != 0) + if (ARG1 != 0) { PRE_MEM_READ( "sigwait(set)", ARG1, sizeof(vki_sigset_t)); - if (ARG2 != 0) + } + if (ARG2 != 0) { PRE_MEM_WRITE( "sigwait(sig)", ARG2, sizeof(int)); + } } POST(sys_sigwait) { - if (ARG2 != 0) + if (ARG2 != 0) { POST_MEM_WRITE( ARG2, sizeof(int)); + } } // SYS_thr_create 430 @@ -4049,9 +4060,10 @@ PRE(sys_thr_kill) /* Check to see if this kill gave us a pending signal */ *flags |= SfPollAfter; - if (VG_(clo_trace_signals)) + if (VG_(clo_trace_signals)) { VG_(message)(Vg_DebugMsg, "thr_kill: sending signal %lu to tid %lu\n", ARG2, ARG1); + } /* If we're sending SIGKILL, check to see if the target is one of our threads and handle it specially. */ @@ -4074,9 +4086,10 @@ PRE(sys_thr_kill) POST(sys_thr_kill) { - if (VG_(clo_trace_signals)) + if (VG_(clo_trace_signals)) { VG_(message)(Vg_DebugMsg, "thr_kill: sent signal %lu to tid %lu\n", ARG2, ARG1); + } } #if (FREEBSD_VERS <= FREEBSD_10) @@ -4091,8 +4104,9 @@ PRE(sys__umtx_lock) POST(sys__umtx_lock) { - if (SUCCESS) + if (SUCCESS) { POST_MEM_WRITE(ARG1, sizeof(struct vki_umtx)); + } } // SYS__umtx_unlock 434 @@ -4106,8 +4120,9 @@ PRE(sys__umtx_unlock) POST(sys__umtx_unlock) { - if (SUCCESS) + if (SUCCESS) { POST_MEM_WRITE(ARG1, sizeof(struct vki_umtx)); + } } #endif @@ -4504,12 +4519,10 @@ POST(sys__umtx_op) { switch(ARG2) { case VKI_UMTX_OP_LOCK: - if (SUCCESS) - POST_MEM_WRITE( ARG1, sizeof(struct vki_umtx) ); - break; case VKI_UMTX_OP_UNLOCK: - if (SUCCESS) + if (SUCCESS) { POST_MEM_WRITE( ARG1, sizeof(struct vki_umtx) ); + } break; case VKI_UMTX_OP_WAIT: case VKI_UMTX_OP_WAKE: @@ -4522,14 +4535,16 @@ POST(sys__umtx_op) case VKI_UMTX_OP_MUTEX_UNLOCK: case VKI_UMTX_OP_MUTEX_WAIT: /* Sets/clears contested bits */ case VKI_UMTX_OP_MUTEX_WAKE: /* Sets/clears contested bits */ - if (SUCCESS) + if (SUCCESS) { POST_MEM_WRITE( ARG1, sizeof(struct vki_umutex) ); + } break; case VKI_UMTX_OP_SET_CEILING: if (SUCCESS) { POST_MEM_WRITE( ARG1, sizeof(struct vki_umutex) ); - if (ARG4) + if (ARG4) { POST_MEM_WRITE( ARG4, sizeof(vki_uint32_t) ); + } } break; case VKI_UMTX_OP_CV_WAIT: @@ -4539,10 +4554,6 @@ POST(sys__umtx_op) } break; case VKI_UMTX_OP_CV_SIGNAL: - if (SUCCESS) { - POST_MEM_WRITE( ARG1, sizeof(struct vki_ucond) ); - } - break; case VKI_UMTX_OP_CV_BROADCAST: if (SUCCESS) { POST_MEM_WRITE( ARG1, sizeof(struct vki_ucond) ); @@ -4617,8 +4628,9 @@ POST(sys_kmq_open) VG_(close)(RES); SET_STATUS_Failure( VKI_EMFILE ); } else { - if (VG_(clo_track_fds)) + if (VG_(clo_track_fds)) { ML_(record_fd_open_with_given_name)(tid, RES, (const HChar*)ARG1); + } } } @@ -4660,20 +4672,23 @@ PRE(sys_kmq_timedreceive) SET_STATUS_Failure( VKI_EBADF ); } else { PRE_MEM_WRITE( "mq_timedreceive(msg_ptr)", ARG2, ARG3 ); - if (ARG4 != 0) + if (ARG4 != 0) { PRE_MEM_WRITE( "mq_timedreceive(msg_prio)", ARG4, sizeof(unsigned int) ); - if (ARG5 != 0) + } + if (ARG5 != 0) { PRE_MEM_READ( "mq_timedreceive(abs_timeout)", ARG5, sizeof(struct vki_timespec) ); + } } } POST(sys_kmq_timedreceive) { POST_MEM_WRITE( ARG2, ARG3 ); - if (ARG4 != 0) + if (ARG4 != 0) { POST_MEM_WRITE( ARG4, sizeof(unsigned int) ); + } } // SYS_kmq_timedsend 460 @@ -4691,9 +4706,10 @@ PRE(sys_kmq_timedsend) SET_STATUS_Failure( VKI_EBADF ); } else { PRE_MEM_READ( "mq_timedsend(msg_ptr)", ARG2, ARG3 ); - if (ARG5 != 0) + if (ARG5 != 0) { PRE_MEM_READ( "mq_timedsend(abs_timeout)", ARG5, sizeof(struct vki_timespec) ); + } } } @@ -4704,11 +4720,13 @@ PRE(sys_kmq_notify) PRINT("sys_kmq_notify( %" FMT_REGWORD "u, %#" FMT_REGWORD "x )", ARG1,ARG2 ); PRE_REG_READ2(int, "mq_notify", vki_mqd_t, mqdes, const struct sigevent *, notification); - if (!ML_(fd_allowed)(ARG1, "mq_notify", tid, False)) + if (!ML_(fd_allowed)(ARG1, "mq_notify", tid, False)) { SET_STATUS_Failure( VKI_EBADF ); - else if (ARG2 != 0) + } + else if (ARG2 != 0) { PRE_MEM_READ( "mq_notify(notification)", ARG2, sizeof(struct vki_sigevent) ); + } } // SYS_kmq_unlink 462 @@ -4776,8 +4794,9 @@ PRE(sys_rtprio_thread) POST(sys_rtprio_thread) { - if (ARG1 == VKI_RTP_LOOKUP && RES == 0) + if (ARG1 == VKI_RTP_LOOKUP && RES == 0) { POST_MEM_WRITE( ARG3, sizeof(struct vki_rtprio)); + } } // SYS_sctp_peeloff 471 @@ -4803,8 +4822,9 @@ PRE(sys_sctp_generic_sendmsg) ML_(pre_mem_read_sockaddr) (tid, "sctp_generic_sendmsg(to)", (struct vki_sockaddr *)ARG4, ARG5); - if (ARG6 != (Addr)NULL) + if (ARG6 != (Addr)NULL) { PRE_MEM_READ( "sctp_generic_sendmsg(sinfo)", ARG6, sizeof(struct vki_sctp_sndrcvinfo)); + } } // SYS_sctp_generic_sendmsg_iov 473 @@ -4836,16 +4856,19 @@ PRE(sys_sctp_generic_recvmsg) PRE_MEM_WRITE("sctp_generic_recvmsg(iov.iov_base)", (Addr)iovec->iov_base, iovec->iov_len); } - if (ARG4 != (Addr)NULL) + if (ARG4 != (Addr)NULL) { ML_(buf_and_len_pre_check) (tid, ARG4, ARG5, "sctp_generic_recvmsg(from)", "sctp_generic_recvmsg(fromlen_in)"); + } - if (ARG6 != (Addr)NULL) + if (ARG6 != (Addr)NULL) { PRE_MEM_WRITE("sctp_generic_recvmsg(sinfo)", ARG6, sizeof(struct vki_sctp_sndrcvinfo)); + } - if (ARG7 != (Addr)NULL) + if (ARG7 != (Addr)NULL) { PRE_MEM_WRITE("sctp_generic_recvmsg(msgflags)", ARG7, sizeof(int)); + } } POST(sys_sctp_generic_recvmsg) @@ -4856,15 +4879,18 @@ POST(sys_sctp_generic_recvmsg) POST_MEM_WRITE( ARG2, ARG3*sizeof(struct vki_iovec) ); - if (ARG4 != (Addr)NULL) + if (ARG4 != (Addr)NULL) { ML_(buf_and_len_post_check) (tid, VG_(mk_SysRes_Success)(RES), ARG4, ARG5, "sctp_generic_recvmsg(fromlen_out)"); + } - if (ARG6 != (Addr)NULL) + if (ARG6 != (Addr)NULL) { POST_MEM_WRITE(ARG6, sizeof(struct vki_sctp_sndrcvinfo)); + } - if (ARG7 != (Addr)NULL) + if (ARG7 != (Addr)NULL) { POST_MEM_WRITE(ARG7, sizeof(int)); + } } // SYS_pread 475 @@ -4899,9 +4925,10 @@ PRE(sys_thr_kill2) /* Check to see if this kill gave us a pending signal */ *flags |= SfPollAfter; - if (VG_(clo_trace_signals)) + if (VG_(clo_trace_signals)) { VG_(message)(Vg_DebugMsg, "thr_kill2: sending signal %lu to pid %lu/%lu\n", ARG3, ARG1, ARG2); + } /* If we're sending SIGKILL, check to see if the target is one of our threads and handle it specially. */ @@ -4924,9 +4951,10 @@ PRE(sys_thr_kill2) POST(sys_thr_kill2) { - if (VG_(clo_trace_signals)) + if (VG_(clo_trace_signals)) { VG_(message)(Vg_DebugMsg, "thr_kill2: sent signal %lu to pid %lu/%lu\n", ARG3, ARG1, ARG2); + } } // SYS_shm_open 482 @@ -4951,8 +4979,9 @@ POST(sys_shm_open) VG_(close)(RES); SET_STATUS_Failure( VKI_EMFILE ); } else { - if (VG_(clo_track_fds)) + if (VG_(clo_track_fds)) { ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG1); + } } } @@ -5077,14 +5106,13 @@ PRE(sys_fexecve) if (sr_isError(res)) { SET_STATUS_Failure(VKI_ENOENT); return; - } else { - char buf[2]; - VG_(read)((Int)sr_Res(res), buf, 2); - VG_(close)((Int)sr_Res(res)); - if (buf[0] == '#' && buf[1] == '!') - { - isScript = True; - } + } + + char buf[2]; + VG_(read)((Int)sr_Res(res), buf, 2); + VG_(close)((Int)sr_Res(res)); + if (buf[0] == '#' && buf[1] == '!') { + isScript = True; } if (isScript) { @@ -5145,10 +5173,12 @@ PRE(sys_futimesat) PRINT("sys_futimesat ( %" FMT_REGWORD "u, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )", ARG1,ARG2,(char*)ARG2,ARG3); PRE_REG_READ3(int, "futimesat", int, fd, const char *, path, struct timeval *, times); - if (ARG2 != 0) + if (ARG2 != 0) { PRE_MEM_RASCIIZ( "futimesat(path)", ARG2 ); - if (ARG3 != 0) + } + if (ARG3 != 0) { PRE_MEM_READ( "futimesat(times)", ARG3, 2 * sizeof(struct vki_timeval) ); + } } // SYS_linkat 495 @@ -5224,10 +5254,11 @@ PRE(sys_openat) int, fd, const char *, path, int, flags); } - if (ARG1 != (unsigned)VKI_AT_FDCWD && !ML_(fd_allowed)(ARG1, "openat", tid, False)) + if (ARG1 != (unsigned)VKI_AT_FDCWD && !ML_(fd_allowed)(ARG1, "openat", tid, False)) { SET_STATUS_Failure( VKI_EBADF ); - else + } else { PRE_MEM_RASCIIZ( "openat(path)", ARG2 ); + } /* Otherwise handle normally */ *flags |= SfMayBlock; @@ -5240,8 +5271,9 @@ POST(sys_openat) VG_(close)(RES); SET_STATUS_Failure( VKI_EMFILE ); } else { - if (VG_(clo_track_fds)) + if (VG_(clo_track_fds)) { ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG2); + } } } @@ -5549,11 +5581,13 @@ PRE(sys_pdfork) SET_STATUS_from_SysRes( VG_(do_syscall2)(__NR_pdfork, ARG1, ARG2) ); - if (!SUCCESS) return; + if (!SUCCESS) { + return; + } // RES is 0 for child, non-0 (the child's PID) for parent. is_child = ( RES == 0 ? True : False ); - child_pid = ( is_child ? -1 : RES ); + child_pid = ( is_child ? -1 : (Int)RES ); if (is_child) { VG_(do_atfork_child)(tid); @@ -5618,9 +5652,10 @@ PRE(sys_pdkill) SET_STATUS_from_SysRes(VG_(do_syscall2)(SYSNO, ARG1, ARG2)); - if (VG_(clo_trace_signals)) + if (VG_(clo_trace_signals)) { VG_(message)(Vg_DebugMsg, "pdkill: sent signal %ld to fd %ld\n", SARG2, SARG1); + } /* This kill might have given us a pending signal. Ask for a check once the syscall is done. */ @@ -5660,17 +5695,21 @@ PRE(sys_pselect) vki_fd_set *, exceptfds, struct vki_timespec *, timeout, const sigset_t *, newsigmask); // XXX: this possibly understates how much memory is read. - if (ARG2 != 0) + if (ARG2 != 0) { PRE_MEM_READ( "pselect(readfds)", ARG2, ARG1/8 /* __FD_SETSIZE/8 */ ); - if (ARG3 != 0) + } + if (ARG3 != 0) { PRE_MEM_READ( "pselect(writefds)", ARG3, ARG1/8 /* __FD_SETSIZE/8 */ ); - if (ARG4 != 0) + } + if (ARG4 != 0) { PRE_MEM_READ( "pselect(exceptfds)", ARG4, ARG1/8 /* __FD_SETSIZE/8 */ ); - if (ARG5 != 0) + } + if (ARG5 != 0) { PRE_MEM_READ( "pselect(timeout)", ARG5, sizeof(struct vki_timeval) ); + } if (ARG6 != 0) { PRE_MEM_READ( "pselect(sig)", ARG6, sizeof(vki_sigset_t) ); @@ -5935,8 +5974,9 @@ POST(sys_pipe2) { int *fildes; - if (RES != 0) + if (RES != 0) { return; + } POST_MEM_WRITE(ARG1, 2 * sizeof(int)); fildes = (int *)ARG1; @@ -6101,8 +6141,9 @@ PRE(sys_getdirentries) size_t, nbytes, off_t *, basep); PRE_MEM_WRITE( "getdirentries(buf)", ARG2, ARG3 ); - if (ARG4) + if (ARG4) { PRE_MEM_WRITE("getdirentries(basep)", ARG4, sizeof (vki_off_t)); + } } POST(sys_getdirentries) @@ -6110,8 +6151,9 @@ POST(sys_getdirentries) vg_assert(SUCCESS); if (RES > 0) { POST_MEM_WRITE( ARG2, RES ); - if ( ARG4 != 0 ) + if ( ARG4 != 0 ) { POST_MEM_WRITE( ARG4, sizeof (vki_off_t)); + } } } @@ -6318,31 +6360,33 @@ PRE(sys_funlinkat) // size_t len, unsigned int flags); PRE(sys_copy_file_range) { - PRINT("sys_copy_file_range (%" FMT_REGWORD"d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "d, %" FMT_REGWORD "d)", - SARG1, ARG2, SARG3, ARG4, (char*)ARG4, SARG5, SARG6); - - PRE_REG_READ6(vki_ssize_t, "copy_file_range", - int, "infd", - vki_off_t *, "inoffp", - int, "outfd", - vki_off_t *, "outoffp", - vki_size_t, "len", - unsigned int, "flags"); - - /* File descriptors are "specially" tracked by valgrind. - valgrind itself uses some, so make sure someone didn't - put in one of our own... */ - if (!ML_(fd_allowed)(ARG1, "copy_file_range(infd)", tid, False) || - !ML_(fd_allowed)(ARG3, "copy_file_range(infd)", tid, False)) { - SET_STATUS_Failure( VKI_EBADF ); - } else { - /* Now see if the offsets are defined. PRE_MEM_READ will - double check it can dereference them. */ - if (ARG2 != 0) - PRE_MEM_READ( "copy_file_range(inoffp)", ARG2, sizeof(vki_off_t)); - if (ARG4 != 0) - PRE_MEM_READ( "copy_file_range(outoffp)", ARG4, sizeof(vki_off_t)); - } + PRINT("sys_copy_file_range (%" FMT_REGWORD"d, %#" FMT_REGWORD "x, %" FMT_REGWORD "d, %#" FMT_REGWORD "x(%s), %" FMT_REGWORD "d, %" FMT_REGWORD "d)", + SARG1, ARG2, SARG3, ARG4, (char*)ARG4, SARG5, SARG6); + + PRE_REG_READ6(vki_ssize_t, "copy_file_range", + int, "infd", + vki_off_t *, "inoffp", + int, "outfd", + vki_off_t *, "outoffp", + vki_size_t, "len", + unsigned int, "flags"); + + /* File descriptors are "specially" tracked by valgrind. + valgrind itself uses some, so make sure someone didn't + put in one of our own... */ + if (!ML_(fd_allowed)(ARG1, "copy_file_range(infd)", tid, False) || + !ML_(fd_allowed)(ARG3, "copy_file_range(infd)", tid, False)) { + SET_STATUS_Failure( VKI_EBADF ); + } else { + /* Now see if the offsets are defined. PRE_MEM_READ will + double check it can dereference them. */ + if (ARG2 != 0) { + PRE_MEM_READ( "copy_file_range(inoffp)", ARG2, sizeof(vki_off_t)); + } + if (ARG4 != 0) { + PRE_MEM_READ( "copy_file_range(outoffp)", ARG4, sizeof(vki_off_t)); + } + } } @@ -6383,8 +6427,9 @@ PRE(sys___sysctlbyname) PRE_MEM_READ("__sysctlbyname(name)", (Addr)ARG1, ARG2 * sizeof(int)); // if 'newp' is not NULL can read namelen bytes from that addess - if (ARG5 != (UWord)NULL) + if (ARG5 != (UWord)NULL) { PRE_MEM_READ("__sysctlbyname(newp)", (Addr)ARG5, ARG6); + } // there are two scenarios for oldlenp/oldp // 1. oldval is NULL and oldlenp is non-NULL @@ -6418,8 +6463,9 @@ POST(sys___sysctlbyname) if (ARG3 != (UWord)NULL) { //POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t)); POST_MEM_WRITE((Addr)ARG3, *(vki_size_t *)ARG4); - } else + } else { POST_MEM_WRITE((Addr)ARG4, sizeof(vki_size_t)); + } } } @@ -6460,8 +6506,9 @@ POST(sys_shm_open2) VG_(close)(RES); SET_STATUS_Failure( VKI_EMFILE ); } else { - if (VG_(clo_track_fds)) + if (VG_(clo_track_fds)) { ML_(record_fd_open_with_given_name)(tid, RES, (HChar*)ARG1); + } } } diff --git a/include/vki/vki-amd64-freebsd.h b/include/vki/vki-amd64-freebsd.h index 213c805cdf..44f4ce8c95 100644 --- a/include/vki/vki-amd64-freebsd.h +++ b/include/vki/vki-amd64-freebsd.h @@ -27,7 +27,7 @@ #define VKI_AMD64_FREEBSD_H /* PAGE_SHIFT determines the page size. */ -#define VKI_PAGE_SHIFT 12 +#define VKI_PAGE_SHIFT 12UL #define VKI_PAGE_SIZE (1UL << VKI_PAGE_SHIFT) #define VKI_MAX_PAGE_SHIFT VKI_PAGE_SHIFT #define VKI_MAX_PAGE_SIZE VKI_PAGE_SIZE diff --git a/include/vki/vki-freebsd.h b/include/vki/vki-freebsd.h index 936abc8e3a..929eb74adb 100644 --- a/include/vki/vki-freebsd.h +++ b/include/vki/vki-freebsd.h @@ -959,12 +959,12 @@ struct vki_termios { * We actually have a 16 bit "base" ioctl, which may or may not be decoded * into number/group */ -#define _VKI_IOC_BASEBITS 16 -#define _VKI_IOC_NRBITS 8 /* "num" on freebsd */ -#define _VKI_IOC_TYPEBITS 8 /* "group" on freebsd */ +#define _VKI_IOC_BASEBITS 16U +#define _VKI_IOC_NRBITS 8U /* "num" on freebsd */ +#define _VKI_IOC_TYPEBITS 8U /* "group" on freebsd */ -#define _VKI_IOC_SIZEBITS 13 -#define _VKI_IOC_DIRBITS 3 +#define _VKI_IOC_SIZEBITS 13U +#define _VKI_IOC_DIRBITS 3U #define _VKI_IOC_BASEMASK ((1ul << _VKI_IOC_BASEBITS)-1) #define _VKI_IOC_NRMASK ((1ul << _VKI_IOC_NRBITS)-1) @@ -972,8 +972,8 @@ struct vki_termios { #define _VKI_IOC_SIZEMASK ((1ul << _VKI_IOC_SIZEBITS)-1) #define _VKI_IOC_DIRMASK ((1ul << _VKI_IOC_DIRBITS)-1) -#define _VKI_IOC_BASESHIFT 0 -#define _VKI_IOC_NRSHIFT 0 +#define _VKI_IOC_BASESHIFT 0U +#define _VKI_IOC_NRSHIFT 0U #define _VKI_IOC_TYPESHIFT (_VKI_IOC_NRSHIFT+_VKI_IOC_NRBITS) #define _VKI_IOC_SIZESHIFT (_VKI_IOC_TYPESHIFT+_VKI_IOC_TYPEBITS) #define _VKI_IOC_DIRSHIFT (_VKI_IOC_SIZESHIFT+_VKI_IOC_SIZEBITS) @@ -1013,7 +1013,7 @@ extern unsigned int __vki_invalid_size_argument_for_IOC; // From sys/random.h //---------------------------------------------------------------------- -#define VKI_GRND_NONBLOCK 0x1 +#define VKI_GRND_NONBLOCK 0x1U //---------------------------------------------------------------------- // From sys/termios.h