mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-03 18:13:01 +00:00
FreeBSD: enable PERF_FAST_LOADV for x86 and cleanup for clangd
clangd doesn't like asm, prefers __asm__ some hicpp-braces-around-statements fixes
This commit is contained in:
parent
1845f51728
commit
29cfa77b23
@ -175,9 +175,10 @@ static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
|
||||
|
||||
if (VG_(extend_stack)(tid, addr)) {
|
||||
stackseg = VG_(am_find_nsegment)(addr);
|
||||
if (0 && stackseg)
|
||||
if (0 && stackseg) {
|
||||
VG_(printf)("frame=%#lx seg=%#lx-%#lx\n",
|
||||
addr, stackseg->start, stackseg->end);
|
||||
}
|
||||
}
|
||||
|
||||
if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW) {
|
||||
@ -185,10 +186,11 @@ static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
|
||||
Vg_UserMsg,
|
||||
"Can't extend stack to %#lx during signal delivery for thread %u:\n",
|
||||
addr, tid);
|
||||
if (stackseg == NULL)
|
||||
if (stackseg == NULL) {
|
||||
VG_(message)(Vg_UserMsg, " no stack segment\n");
|
||||
else
|
||||
} else {
|
||||
VG_(message)(Vg_UserMsg, " too small or bad protection modes\n");
|
||||
}
|
||||
|
||||
/* set SIGSEGV to default handler */
|
||||
VG_(set_default_handler)(VKI_SIGSEGV);
|
||||
@ -246,8 +248,9 @@ static Addr build_sigframe(ThreadState *tst,
|
||||
rsp = VG_ROUNDDN(rsp, 16) - 8;
|
||||
frame = (struct sigframe *)rsp;
|
||||
|
||||
if (!extend(tst, rsp, sizeof(*frame)))
|
||||
if (!extend(tst, rsp, sizeof(*frame))) {
|
||||
return rsp_top_of_frame;
|
||||
}
|
||||
|
||||
/* retaddr, siginfo, uContext fields are to be written */
|
||||
VG_TRACK( pre_mem_write, Vg_CoreSignal, tst->tid, "signal handler frame",
|
||||
@ -392,8 +395,9 @@ static
|
||||
SizeT restore_sigframe ( ThreadState *tst,
|
||||
struct sigframe *frame, Int *sigNo )
|
||||
{
|
||||
if (restore_vg_sigframe(tst, &frame->vg, sigNo))
|
||||
if (restore_vg_sigframe(tst, &frame->vg, sigNo)) {
|
||||
restore_sigcontext(tst, &frame->uContext.uc_mcontext, &frame->fpstate);
|
||||
}
|
||||
|
||||
return sizeof(*frame);
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ void ML_(call_on_new_stack_0_1) ( Addr stack,
|
||||
// %rsi == retaddr
|
||||
// %rdx == f
|
||||
// %rcx == arg1
|
||||
asm(
|
||||
__asm__(
|
||||
".text\n"
|
||||
".globl vgModuleLocal_call_on_new_stack_0_1\n"
|
||||
"vgModuleLocal_call_on_new_stack_0_1:\n"
|
||||
@ -178,8 +178,6 @@ POST(sys_sysarch)
|
||||
case VKI_AMD64_SET_FSBASE:
|
||||
break;
|
||||
case VKI_AMD64_GET_FSBASE:
|
||||
POST_MEM_WRITE( ARG2, sizeof(void *) );
|
||||
break;
|
||||
case VKI_AMD64_GET_XFPUSTATE:
|
||||
POST_MEM_WRITE( ARG2, sizeof(void *) );
|
||||
break;
|
||||
@ -331,8 +329,9 @@ PRE(sys_preadv)
|
||||
if (!ML_(fd_allowed)(ARG1, "preadv", tid, False)) {
|
||||
SET_STATUS_Failure( VKI_EBADF );
|
||||
} else {
|
||||
if ((Int)ARG3 > 0)
|
||||
if ((Int)ARG3 > 0) {
|
||||
PRE_MEM_READ( "preadv(iov)", ARG2, ARG3 * sizeof(struct vki_iovec) );
|
||||
}
|
||||
|
||||
if (ML_(safe_to_deref)((struct vki_iovec *)ARG2, ARG3 * sizeof(struct vki_iovec))) {
|
||||
vec = (struct vki_iovec *)(Addr)ARG2;
|
||||
@ -355,10 +354,14 @@ POST(sys_preadv)
|
||||
/* RES holds the number of bytes read. */
|
||||
for (i = 0; i < (Int)ARG3; i++) {
|
||||
Int nReadThisBuf = vec[i].iov_len;
|
||||
if (nReadThisBuf > remains) nReadThisBuf = remains;
|
||||
if (nReadThisBuf > remains) {
|
||||
nReadThisBuf = remains;
|
||||
}
|
||||
POST_MEM_WRITE( (Addr)vec[i].iov_base, nReadThisBuf );
|
||||
remains -= nReadThisBuf;
|
||||
if (remains < 0) VG_(core_panic)("preadv: remains < 0");
|
||||
if (remains < 0) {
|
||||
VG_(core_panic)("preadv: remains < 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -381,8 +384,9 @@ PRE(sys_pwritev)
|
||||
if (!ML_(fd_allowed)(ARG1, "pwritev", tid, False)) {
|
||||
SET_STATUS_Failure( VKI_EBADF );
|
||||
} else {
|
||||
if ((Int)ARG3 >= 0)
|
||||
if ((Int)ARG3 >= 0) {
|
||||
PRE_MEM_READ( "pwritev(vector)", ARG2, ARG3 * sizeof(struct vki_iovec) );
|
||||
}
|
||||
if (ML_(safe_to_deref)((struct vki_iovec *)ARG2, ARG3 * sizeof(struct vki_iovec))) {
|
||||
vec = (struct vki_iovec *)(Addr)ARG2;
|
||||
for (i = 0; i < (Int)ARG3; i++) {
|
||||
@ -406,11 +410,13 @@ PRE(sys_sendfile)
|
||||
int, fd, int, s, vki_off_t, offset, size_t, nbytes,
|
||||
void *, hdtr, vki_off_t *, sbytes, int, flags);
|
||||
|
||||
if (ARG5 != 0)
|
||||
if (ARG5 != 0) {
|
||||
PRE_MEM_READ("sendfile(hdtr)", ARG5, sizeof(struct vki_sf_hdtr));
|
||||
}
|
||||
|
||||
if (ARG6 != 0)
|
||||
if (ARG6 != 0) {
|
||||
PRE_MEM_WRITE( "sendfile(sbytes)", ARG6, sizeof(vki_off_t) );
|
||||
}
|
||||
}
|
||||
|
||||
POST(sys_sendfile)
|
||||
@ -567,7 +573,8 @@ PRE(sys_setcontext)
|
||||
// int swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
|
||||
PRE(sys_swapcontext)
|
||||
{
|
||||
struct vki_ucontext *ucp, *oucp;
|
||||
struct vki_ucontext *ucp;
|
||||
struct vki_ucontext *oucp;
|
||||
ThreadState* tst;
|
||||
|
||||
PRINT("sys_swapcontext ( %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", ARG1, ARG2);
|
||||
@ -623,7 +630,8 @@ PRE(sys_thr_new)
|
||||
ThreadState* ptst = VG_(get_ThreadState)(tid);
|
||||
ThreadState* ctst = VG_(get_ThreadState)(ctid);
|
||||
SysRes res;
|
||||
vki_sigset_t blockall, savedmask;
|
||||
vki_sigset_t blockall;
|
||||
vki_sigset_t savedmask;
|
||||
struct vki_thr_param tp;
|
||||
Addr stk;
|
||||
|
||||
@ -689,8 +697,9 @@ PRE(sys_thr_new)
|
||||
label below, to clean up. */
|
||||
VG_TRACK ( pre_thread_ll_create, tid, ctid );
|
||||
|
||||
if (debug)
|
||||
if (debug) {
|
||||
VG_(printf)("clone child has SETTLS: tls at %#lx\n", (Addr)tp.tls_base);
|
||||
}
|
||||
ctst->arch.vex.guest_FS_CONST = (UWord)tp.tls_base;
|
||||
tp.tls_base = 0; /* Don't have the kernel do it too */
|
||||
|
||||
|
||||
@ -235,7 +235,7 @@ static void run_a_thread_NORETURN ( Word tidW )
|
||||
between marking it Empty and exiting. Hence the
|
||||
assembler. */
|
||||
#if defined(VGP_x86_freebsd) /* FreeBSD has args on the stack */
|
||||
asm volatile (
|
||||
__asm__ volatile (
|
||||
"movl %1, %0\n" /* set tst->status = VgTs_Empty */
|
||||
"movl %2, %%eax\n" /* set %eax = __NR_thr_exit */
|
||||
"movl %3, %%ebx\n" /* set %ebx = tst->os_state.exitcode */
|
||||
@ -249,7 +249,7 @@ static void run_a_thread_NORETURN ( Word tidW )
|
||||
: "eax", "ebx"
|
||||
);
|
||||
#elif defined(VGP_amd64_freebsd)
|
||||
asm volatile (
|
||||
__asm__ volatile (
|
||||
"movl %1, %0\n" /* set tst->status = VgTs_Empty */
|
||||
"movq %2, %%rax\n" /* set %rax = __NR_thr_exit */
|
||||
"movq %3, %%rdi\n" /* set %rdi = tst->os_state.exitcode */
|
||||
@ -294,11 +294,13 @@ Addr ML_(allocstack)(ThreadId tid)
|
||||
case a stack hasn't been allocated) or they are both non-zero,
|
||||
in which case it has. */
|
||||
|
||||
if (tst->os_state.valgrind_stack_base == 0)
|
||||
if (tst->os_state.valgrind_stack_base == 0) {
|
||||
vg_assert(tst->os_state.valgrind_stack_init_SP == 0);
|
||||
}
|
||||
|
||||
if (tst->os_state.valgrind_stack_base != 0)
|
||||
if (tst->os_state.valgrind_stack_base != 0) {
|
||||
vg_assert(tst->os_state.valgrind_stack_init_SP != 0);
|
||||
}
|
||||
|
||||
/* If no stack is present, allocate one. */
|
||||
|
||||
@ -5994,8 +5996,9 @@ POST(sys_ppoll)
|
||||
if (SUCCESS && ((Word)RES != -1)) {
|
||||
UInt i;
|
||||
struct vki_pollfd* ufds = (struct vki_pollfd *)(Addr)ARG1;
|
||||
for (i = 0; i < ARG2; i++)
|
||||
for (i = 0; i < ARG2; i++) {
|
||||
POST_MEM_WRITE( (Addr)(&ufds[i].revents), sizeof(ufds[i].revents) );
|
||||
}
|
||||
}
|
||||
ML_(free_safe_mask) ( (Addr)ARG4 );
|
||||
}
|
||||
@ -6184,23 +6187,28 @@ PRE(sys_kevent)
|
||||
int, kq, struct vki_kevent *, changelist, int, nchanges,
|
||||
struct vki_kevent *, 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)*ARG3 );
|
||||
if (ARG4 != 0 && ARG5 != 0)
|
||||
}
|
||||
if (ARG4 != 0 && ARG5 != 0) {
|
||||
PRE_MEM_WRITE( "kevent(eventlist)", ARG4, sizeof(struct vki_kevent)*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_kevent)
|
||||
{
|
||||
vg_assert(SUCCESS);
|
||||
if ((Word)RES != -1) {
|
||||
if (ARG4 != 0)
|
||||
if (ARG4 != 0) {
|
||||
POST_MEM_WRITE( ARG4, sizeof(struct vki_kevent)*RES) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7233,10 +7241,10 @@ const SyscallTableEntry* ML_(get_freebsd_syscall_entry) ( UInt sysno )
|
||||
/* Is it in the contiguous initial section of the table? */
|
||||
if (sysno < syscall_table_size) {
|
||||
const SyscallTableEntry* sys = &ML_(syscall_table)[sysno];
|
||||
if (sys->before == NULL)
|
||||
if (sys->before == NULL) {
|
||||
return NULL; /* no entry */
|
||||
else
|
||||
return sys;
|
||||
}
|
||||
return sys;
|
||||
}
|
||||
|
||||
/* Can't find a wrapper */
|
||||
|
||||
@ -79,7 +79,7 @@ void ML_(call_on_new_stack_0_1) ( Addr stack,
|
||||
// 8(%esp) == retaddr
|
||||
// 12(%esp) == f
|
||||
// 16(%esp) == arg1
|
||||
asm(
|
||||
__asm__(
|
||||
".text\n"
|
||||
".globl vgModuleLocal_call_on_new_stack_0_1\n"
|
||||
"vgModuleLocal_call_on_new_stack_0_1:\n"
|
||||
|
||||
@ -110,8 +110,9 @@ int ptrace_write_memory (pid_t inferior_pid, CORE_ADDR memaddr,
|
||||
|
||||
if (debuglevel >= 1) {
|
||||
DEBUG (1, "Writing ");
|
||||
for (i = 0; i < len; i++)
|
||||
for (i = 0; i < len; i++) {
|
||||
PDEBUG (1, "%02x", ((const unsigned char*)myaddr)[i]);
|
||||
}
|
||||
PDEBUG(1, " to %p\n", (void *) memaddr);
|
||||
}
|
||||
|
||||
@ -139,8 +140,9 @@ int ptrace_write_memory (pid_t inferior_pid, CORE_ADDR memaddr,
|
||||
errno = 0;
|
||||
ptrace (PT_WRITE_I, inferior_pid,
|
||||
(PTRACE_ARG3_TYPE) addr, buffer[i]);
|
||||
if (errno)
|
||||
if (errno) {
|
||||
return errno;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -160,15 +162,18 @@ char *status_image (int status)
|
||||
|
||||
if (WIFSIGNALED(status)) {
|
||||
APPEND ("WIFSIGNALED %d ", WTERMSIG(status));
|
||||
if (WCOREDUMP(status)) APPEND ("WCOREDUMP ");
|
||||
if (WCOREDUMP(status)) {
|
||||
APPEND ("WCOREDUMP ");
|
||||
}
|
||||
}
|
||||
|
||||
if (WIFSTOPPED(status))
|
||||
APPEND ("WIFSTOPPED %d ", WSTOPSIG(status));
|
||||
|
||||
#ifdef WIFCONTINUED
|
||||
if (WIFCONTINUED(status))
|
||||
if (WIFCONTINUED(status)) {
|
||||
APPEND ("WIFCONTINUED ");
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
@ -212,8 +217,9 @@ Bool waitstopped (pid_t pid, int signal_expected, const char *msg)
|
||||
|
||||
assert (WIFSTOPPED(status));
|
||||
signal_received = WSTOPSIG(status);
|
||||
if (signal_received == signal_expected)
|
||||
if (signal_received == signal_expected) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* pid received a signal which is not the signal we are waiting for.
|
||||
If we have not (yet) changed the registers of the inferior
|
||||
|
||||
@ -369,7 +369,7 @@ static void update_SM_counts(SecMap* oldSM, SecMap* newSM)
|
||||
*/
|
||||
#if ENABLE_ASSEMBLY_HELPERS && defined(PERF_FAST_LOADV) \
|
||||
&& (defined(VGP_arm_linux) \
|
||||
|| defined(VGP_x86_linux) || defined(VGP_x86_solaris))
|
||||
|| defined(VGP_x86_linux) || defined(VGP_x86_solaris) || defined(VGP_x86_freebsd))
|
||||
/* mc_main_asm.c needs visibility on a few things declared in this file.
|
||||
MC_MAIN_STATIC allows to define them static if ok, i.e. on
|
||||
platforms that are not using hand-coded asm statements. */
|
||||
@ -5028,7 +5028,7 @@ VG_REGPARM(1) ULong MC_(helperc_LOADV64be) ( Addr a )
|
||||
/* See mc_main_asm.c */
|
||||
|
||||
#elif ENABLE_ASSEMBLY_HELPERS && defined(PERF_FAST_LOADV) \
|
||||
&& (defined(VGP_x86_linux) || defined(VGP_x86_solaris))
|
||||
&& (defined(VGP_x86_linux) || defined(VGP_x86_solaris) || defined(VGP_x86_freebsd))
|
||||
/* See mc_main_asm.c */
|
||||
|
||||
#else
|
||||
|
||||
@ -83,7 +83,7 @@ __asm__( /* Derived from the 32 bit assembly helper */
|
||||
);
|
||||
|
||||
#elif ENABLE_ASSEMBLY_HELPERS && defined(PERF_FAST_LOADV) \
|
||||
&& (defined(VGP_x86_linux) || defined(VGP_x86_solaris))
|
||||
&& (defined(VGP_x86_linux) || defined(VGP_x86_solaris) || defined(VGP_x86_freebsd))
|
||||
__asm__(
|
||||
".text\n"
|
||||
".align 16\n"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user