1112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 2112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/*--------------------------------------------------------------------*/ 3112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/*--- Create/destroy signal delivery frames. ---*/ 4112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/*--- sigframe-tilegx-linux.c ---*/ 5112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/*--------------------------------------------------------------------*/ 6112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 7112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/* 8112711afefcfcd43680c7c4aa8d38ef180e8811esewardj This file is part of Valgrind, a dynamic binary instrumentation 9112711afefcfcd43680c7c4aa8d38ef180e8811esewardj framework. 10112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 11b3a1e4bffbdbbf38304f216af405009868f43628sewardj Copyright (C) 2010-2015 Tilera Corp. 12112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 13112711afefcfcd43680c7c4aa8d38ef180e8811esewardj This program is free software; you can redistribute it and/or 14112711afefcfcd43680c7c4aa8d38ef180e8811esewardj modify it under the terms of the GNU General Public License as 15112711afefcfcd43680c7c4aa8d38ef180e8811esewardj published by the Free Software Foundation; either version 2 of the 16112711afefcfcd43680c7c4aa8d38ef180e8811esewardj License, or (at your option) any later version. 17112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 18112711afefcfcd43680c7c4aa8d38ef180e8811esewardj This program is distributed in the hope that it will be useful, but 19112711afefcfcd43680c7c4aa8d38ef180e8811esewardj WITHOUT ANY WARRANTY; without even the implied warranty of 20112711afefcfcd43680c7c4aa8d38ef180e8811esewardj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21112711afefcfcd43680c7c4aa8d38ef180e8811esewardj General Public License for more details. 22112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 23112711afefcfcd43680c7c4aa8d38ef180e8811esewardj You should have received a copy of the GNU General Public License 24112711afefcfcd43680c7c4aa8d38ef180e8811esewardj along with this program; if not, write to the Free Software 25112711afefcfcd43680c7c4aa8d38ef180e8811esewardj Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 26112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 02111-1307, USA. 27112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 28112711afefcfcd43680c7c4aa8d38ef180e8811esewardj The GNU General Public License is contained in the file COPYING. 29112711afefcfcd43680c7c4aa8d38ef180e8811esewardj*/ 30112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 31112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/* Contributed by Zhi-Gang Liu <zliu at tilera dot com> */ 32112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 33112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#if defined(VGP_tilegx_linux) 34112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 35112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_basics.h" 36112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_vki.h" 37112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_vkiscnums.h" 38112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_threadstate.h" 39112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_aspacemgr.h" 40112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_libcbase.h" 41112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_libcassert.h" 42112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_libcprint.h" 43112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_machine.h" 44112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_options.h" 45112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_sigframe.h" 46112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_signals.h" 47112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_tooliface.h" 48112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#include "pub_core_trampoline.h" 4901fcf6a890ad645e4ccbf731264f19f850898c5eflorian#include "priv_sigframe.h" 50112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 51112711afefcfcd43680c7c4aa8d38ef180e8811esewardjstruct vg_sig_private 52112711afefcfcd43680c7c4aa8d38ef180e8811esewardj{ 53112711afefcfcd43680c7c4aa8d38ef180e8811esewardj UInt magicPI; 54112711afefcfcd43680c7c4aa8d38ef180e8811esewardj UInt sigNo_private; 55112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VexGuestTILEGXState vex_shadow1; 56112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VexGuestTILEGXState vex_shadow2; 57112711afefcfcd43680c7c4aa8d38ef180e8811esewardj}; 58112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 59112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#ifndef C_ABI_SAVE_AREA_SIZE 60112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#define C_ABI_SAVE_AREA_SIZE 16 61112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#endif 62112711afefcfcd43680c7c4aa8d38ef180e8811esewardjstruct rt_sigframe { 63112711afefcfcd43680c7c4aa8d38ef180e8811esewardj unsigned char save_area[C_ABI_SAVE_AREA_SIZE]; /* caller save area */ 64112711afefcfcd43680c7c4aa8d38ef180e8811esewardj vki_siginfo_t rs_info; 65112711afefcfcd43680c7c4aa8d38ef180e8811esewardj struct vki_ucontext rs_uc; 66112711afefcfcd43680c7c4aa8d38ef180e8811esewardj struct vg_sig_private priv; 67112711afefcfcd43680c7c4aa8d38ef180e8811esewardj}; 68112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 69112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 70112711afefcfcd43680c7c4aa8d38ef180e8811esewardjstatic 71112711afefcfcd43680c7c4aa8d38ef180e8811esewardjvoid setup_sigcontext2 ( ThreadState* tst, struct vki_sigcontext **sc1, 72112711afefcfcd43680c7c4aa8d38ef180e8811esewardj const vki_siginfo_t *si ) 73112711afefcfcd43680c7c4aa8d38ef180e8811esewardj{ 74112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 75112711afefcfcd43680c7c4aa8d38ef180e8811esewardj struct vki_sigcontext *sc = *sc1; 76112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 77112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_TRACK( pre_mem_write, Vg_CoreSignal, tst->tid, "signal frame mcontext", 78112711afefcfcd43680c7c4aa8d38ef180e8811esewardj (Addr)sc, sizeof(unsigned long long)*34 ); 79112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[0] = tst->arch.vex.guest_r0; 80112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[1] = tst->arch.vex.guest_r1; 81112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[2] = tst->arch.vex.guest_r2; 82112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[3] = tst->arch.vex.guest_r3; 83112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[4] = tst->arch.vex.guest_r4; 84112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[5] = tst->arch.vex.guest_r5; 85112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[6] = tst->arch.vex.guest_r6; 86112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[7] = tst->arch.vex.guest_r7; 87112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[8] = tst->arch.vex.guest_r8; 88112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[9] = tst->arch.vex.guest_r9; 89112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[10] = tst->arch.vex.guest_r10; 90112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[11] = tst->arch.vex.guest_r11; 91112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[12] = tst->arch.vex.guest_r12; 92112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[13] = tst->arch.vex.guest_r13; 93112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[14] = tst->arch.vex.guest_r14; 94112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[15] = tst->arch.vex.guest_r15; 95112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[16] = tst->arch.vex.guest_r16; 96112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[17] = tst->arch.vex.guest_r17; 97112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[18] = tst->arch.vex.guest_r18; 98112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[19] = tst->arch.vex.guest_r19; 99112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[20] = tst->arch.vex.guest_r20; 100112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[21] = tst->arch.vex.guest_r21; 101112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[22] = tst->arch.vex.guest_r22; 102112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[23] = tst->arch.vex.guest_r23; 103112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[24] = tst->arch.vex.guest_r24; 104112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[25] = tst->arch.vex.guest_r25; 105112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[26] = tst->arch.vex.guest_r26; 106112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[27] = tst->arch.vex.guest_r27; 107112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[28] = tst->arch.vex.guest_r28; 108112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[29] = tst->arch.vex.guest_r29; 109112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[30] = tst->arch.vex.guest_r30; 110112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[31] = tst->arch.vex.guest_r31; 111112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[32] = tst->arch.vex.guest_r32; 112112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[33] = tst->arch.vex.guest_r33; 113112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[34] = tst->arch.vex.guest_r34; 114112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[35] = tst->arch.vex.guest_r35; 115112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[36] = tst->arch.vex.guest_r36; 116112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[37] = tst->arch.vex.guest_r37; 117112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[38] = tst->arch.vex.guest_r38; 118112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[39] = tst->arch.vex.guest_r39; 119112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[40] = tst->arch.vex.guest_r40; 120112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[41] = tst->arch.vex.guest_r41; 121112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[42] = tst->arch.vex.guest_r42; 122112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[43] = tst->arch.vex.guest_r43; 123112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[44] = tst->arch.vex.guest_r44; 124112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[45] = tst->arch.vex.guest_r45; 125112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[46] = tst->arch.vex.guest_r46; 126112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[47] = tst->arch.vex.guest_r47; 127112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[48] = tst->arch.vex.guest_r48; 128112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[49] = tst->arch.vex.guest_r49; 129112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[50] = tst->arch.vex.guest_r50; 130112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[51] = tst->arch.vex.guest_r51; 131112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->gregs[52] = tst->arch.vex.guest_r52; 132112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->tp = tst->arch.vex.guest_r53; 133112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->sp = tst->arch.vex.guest_r54; 134112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->lr = tst->arch.vex.guest_r55; 135112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sc->pc = tst->arch.vex.guest_pc; 136112711afefcfcd43680c7c4aa8d38ef180e8811esewardj} 137112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 138112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/* EXPORTED */ 139112711afefcfcd43680c7c4aa8d38ef180e8811esewardjvoid VG_(sigframe_create)( ThreadId tid, 140112711afefcfcd43680c7c4aa8d38ef180e8811esewardj Addr sp_top_of_frame, 141112711afefcfcd43680c7c4aa8d38ef180e8811esewardj const vki_siginfo_t *siginfo, 142112711afefcfcd43680c7c4aa8d38ef180e8811esewardj const struct vki_ucontext *siguc, 143112711afefcfcd43680c7c4aa8d38ef180e8811esewardj void *handler, 144112711afefcfcd43680c7c4aa8d38ef180e8811esewardj UInt flags, 145112711afefcfcd43680c7c4aa8d38ef180e8811esewardj const vki_sigset_t *mask, 146112711afefcfcd43680c7c4aa8d38ef180e8811esewardj void *restorer ) 147112711afefcfcd43680c7c4aa8d38ef180e8811esewardj{ 148112711afefcfcd43680c7c4aa8d38ef180e8811esewardj Addr sp; 149112711afefcfcd43680c7c4aa8d38ef180e8811esewardj ThreadState* tst; 150112711afefcfcd43680c7c4aa8d38ef180e8811esewardj Addr faultaddr; 151112711afefcfcd43680c7c4aa8d38ef180e8811esewardj Int sigNo = siginfo->si_signo; 152112711afefcfcd43680c7c4aa8d38ef180e8811esewardj struct vg_sig_private *priv; 153112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 154112711afefcfcd43680c7c4aa8d38ef180e8811esewardj /* Stack must be 8-byte aligned */ 155112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sp_top_of_frame &= ~0x7ULL; 156112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 157112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sp = sp_top_of_frame - sizeof(struct rt_sigframe); 158112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 159112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst = VG_(get_ThreadState)(tid); 1607d4a28b986eaf98814c530a2074e117145b14d1fflorian if (! ML_(sf_maybe_extend_stack)(tst, sp, sizeof(struct rt_sigframe), flags)) 161112711afefcfcd43680c7c4aa8d38ef180e8811esewardj return; 162112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 163112711afefcfcd43680c7c4aa8d38ef180e8811esewardj vg_assert(VG_IS_8_ALIGNED(sp)); 164112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 165112711afefcfcd43680c7c4aa8d38ef180e8811esewardj /* SIGILL defines addr to be the faulting address */ 166112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 167112711afefcfcd43680c7c4aa8d38ef180e8811esewardj faultaddr = (Addr)siginfo->_sifields._sigfault._addr; 168112711afefcfcd43680c7c4aa8d38ef180e8811esewardj if (sigNo == VKI_SIGILL && siginfo->si_code > 0) 169112711afefcfcd43680c7c4aa8d38ef180e8811esewardj faultaddr = tst->arch.vex.guest_pc; 170112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 171112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 172112711afefcfcd43680c7c4aa8d38ef180e8811esewardj struct rt_sigframe *frame = (struct rt_sigframe *) sp; 173112711afefcfcd43680c7c4aa8d38ef180e8811esewardj struct vki_ucontext *ucp = &frame->rs_uc; 174112711afefcfcd43680c7c4aa8d38ef180e8811esewardj if (VG_(clo_trace_signals)) 175112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_(printf)("rt_sigframe\n"); 176112711afefcfcd43680c7c4aa8d38ef180e8811esewardj /* Create siginfo. */ 177112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_TRACK( pre_mem_write, Vg_CoreSignal, tid, "signal frame siginfo", 178112711afefcfcd43680c7c4aa8d38ef180e8811esewardj (Addr)&frame->rs_info, sizeof(frame->rs_info) ); 179112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 180112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_(memcpy)(&frame->rs_info, siginfo, sizeof(*siginfo)); 181112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 182112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_TRACK( post_mem_write, Vg_CoreSignal, tid, 183112711afefcfcd43680c7c4aa8d38ef180e8811esewardj (Addr)&frame->rs_info, sizeof(frame->rs_info) ); 184112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 185112711afefcfcd43680c7c4aa8d38ef180e8811esewardj /* Create the ucontext. */ 186112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_TRACK( pre_mem_write, Vg_CoreSignal, tid, "signal frame ucontext", 187112711afefcfcd43680c7c4aa8d38ef180e8811esewardj (Addr)ucp, offsetof(struct vki_ucontext, uc_mcontext) ); 188112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 189112711afefcfcd43680c7c4aa8d38ef180e8811esewardj ucp->uc_flags = 0; 190112711afefcfcd43680c7c4aa8d38ef180e8811esewardj ucp->uc_link = 0; 191112711afefcfcd43680c7c4aa8d38ef180e8811esewardj ucp->uc_stack = tst->altstack; 192112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 193112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_TRACK( post_mem_write, Vg_CoreSignal, tid, (Addr)ucp, 194112711afefcfcd43680c7c4aa8d38ef180e8811esewardj offsetof(struct vki_ucontext, uc_mcontext) ); 195112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 196112711afefcfcd43680c7c4aa8d38ef180e8811esewardj struct vki_sigcontext *scp = &(frame->rs_uc.uc_mcontext); 197112711afefcfcd43680c7c4aa8d38ef180e8811esewardj setup_sigcontext2(tst, &(scp), siginfo); 198112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 199112711afefcfcd43680c7c4aa8d38ef180e8811esewardj ucp->uc_sigmask = tst->sig_mask; 200112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 201112711afefcfcd43680c7c4aa8d38ef180e8811esewardj priv = &frame->priv; 202112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 203112711afefcfcd43680c7c4aa8d38ef180e8811esewardj /* 204112711afefcfcd43680c7c4aa8d38ef180e8811esewardj * Arguments to signal handler: 205112711afefcfcd43680c7c4aa8d38ef180e8811esewardj * 206112711afefcfcd43680c7c4aa8d38ef180e8811esewardj * r0 = signal number 207112711afefcfcd43680c7c4aa8d38ef180e8811esewardj * r1 = 0 (should be cause) 208112711afefcfcd43680c7c4aa8d38ef180e8811esewardj * r2 = pointer to ucontext 209112711afefcfcd43680c7c4aa8d38ef180e8811esewardj * 210112711afefcfcd43680c7c4aa8d38ef180e8811esewardj * r54 points to the struct rt_sigframe. 211112711afefcfcd43680c7c4aa8d38ef180e8811esewardj */ 212112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 213112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r0 = siginfo->si_signo; 214112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r1 = (Addr) &frame->rs_info; 215112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r2 = (Addr) &frame->rs_uc; 216112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r54 = (Addr) frame; 217112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 218112711afefcfcd43680c7c4aa8d38ef180e8811esewardj if (flags & VKI_SA_RESTORER) 219112711afefcfcd43680c7c4aa8d38ef180e8811esewardj { 220112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r55 = (Addr) restorer; 221112711afefcfcd43680c7c4aa8d38ef180e8811esewardj } 222112711afefcfcd43680c7c4aa8d38ef180e8811esewardj else 223112711afefcfcd43680c7c4aa8d38ef180e8811esewardj { 224112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r55 = (Addr)&VG_(tilegx_linux_SUBST_FOR_rt_sigreturn); 225112711afefcfcd43680c7c4aa8d38ef180e8811esewardj } 226112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 227112711afefcfcd43680c7c4aa8d38ef180e8811esewardj priv->magicPI = 0x31415927; 228112711afefcfcd43680c7c4aa8d38ef180e8811esewardj priv->sigNo_private = sigNo; 229112711afefcfcd43680c7c4aa8d38ef180e8811esewardj priv->vex_shadow1 = tst->arch.vex_shadow1; 230112711afefcfcd43680c7c4aa8d38ef180e8811esewardj priv->vex_shadow2 = tst->arch.vex_shadow2; 231112711afefcfcd43680c7c4aa8d38ef180e8811esewardj /* Set the thread so it will next run the handler. */ 232112711afefcfcd43680c7c4aa8d38ef180e8811esewardj /* tst->m_sp = sp; also notify the tool we've updated SP */ 233112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_TRACK( post_reg_write, Vg_CoreSignal, tid, VG_O_STACK_PTR, sizeof(Addr)); 234112711afefcfcd43680c7c4aa8d38ef180e8811esewardj if (VG_(clo_trace_signals)) 235112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_(printf)("handler = %p\n", handler); 236112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_pc = (Addr) handler; 237112711afefcfcd43680c7c4aa8d38ef180e8811esewardj /* This thread needs to be marked runnable, but we leave that the 238112711afefcfcd43680c7c4aa8d38ef180e8811esewardj caller to do. */ 239112711afefcfcd43680c7c4aa8d38ef180e8811esewardj if (0) 240112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_(printf)("pushed signal frame; sp now = %lx, " 241112711afefcfcd43680c7c4aa8d38ef180e8811esewardj "next %pc = %lx, status=%d\n", 24297f1d337555234c20f3f1d0dd0b22b2a7d571616florian (Addr)frame, tst->arch.vex.guest_pc, (Int)tst->status); 243112711afefcfcd43680c7c4aa8d38ef180e8811esewardj} 244112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 245112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/* EXPORTED */ 246112711afefcfcd43680c7c4aa8d38ef180e8811esewardjvoid VG_(sigframe_destroy)( ThreadId tid, Bool isRT ) 247112711afefcfcd43680c7c4aa8d38ef180e8811esewardj{ 248112711afefcfcd43680c7c4aa8d38ef180e8811esewardj ThreadState *tst; 249112711afefcfcd43680c7c4aa8d38ef180e8811esewardj struct vg_sig_private *priv1; 250112711afefcfcd43680c7c4aa8d38ef180e8811esewardj Addr sp; 251112711afefcfcd43680c7c4aa8d38ef180e8811esewardj UInt frame_size; 252112711afefcfcd43680c7c4aa8d38ef180e8811esewardj struct vki_sigcontext *mc; 253112711afefcfcd43680c7c4aa8d38ef180e8811esewardj Int sigNo; 254112711afefcfcd43680c7c4aa8d38ef180e8811esewardj Bool has_siginfo = isRT; 255112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 256112711afefcfcd43680c7c4aa8d38ef180e8811esewardj vg_assert(VG_(is_valid_tid)(tid)); 257112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst = VG_(get_ThreadState)(tid); 258112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sp = tst->arch.vex.guest_r54 + 8; 259112711afefcfcd43680c7c4aa8d38ef180e8811esewardj if (has_siginfo) 260112711afefcfcd43680c7c4aa8d38ef180e8811esewardj { 261112711afefcfcd43680c7c4aa8d38ef180e8811esewardj struct rt_sigframe *frame = (struct rt_sigframe *)sp; 262112711afefcfcd43680c7c4aa8d38ef180e8811esewardj struct vki_ucontext *ucp = &frame->rs_uc; 263112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 264112711afefcfcd43680c7c4aa8d38ef180e8811esewardj if (0) 265ad4e979f408239dabbaae955d8ffcb84a51a5c85florian VG_(printf)("destroy signal frame; sp = %lx, " 266112711afefcfcd43680c7c4aa8d38ef180e8811esewardj " %pc = %lx, status=%d\n", 26797f1d337555234c20f3f1d0dd0b22b2a7d571616florian (Addr)frame, tst->arch.vex.guest_pc, (Int)tst->status); 268112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 269112711afefcfcd43680c7c4aa8d38ef180e8811esewardj frame_size = sizeof(*frame); 270112711afefcfcd43680c7c4aa8d38ef180e8811esewardj mc = &ucp->uc_mcontext; 271112711afefcfcd43680c7c4aa8d38ef180e8811esewardj priv1 = &frame->priv; 272112711afefcfcd43680c7c4aa8d38ef180e8811esewardj vg_assert(priv1->magicPI == 0x31415927); 273112711afefcfcd43680c7c4aa8d38ef180e8811esewardj sigNo = priv1->sigNo_private; 274112711afefcfcd43680c7c4aa8d38ef180e8811esewardj } 275112711afefcfcd43680c7c4aa8d38ef180e8811esewardj else 276112711afefcfcd43680c7c4aa8d38ef180e8811esewardj { 277112711afefcfcd43680c7c4aa8d38ef180e8811esewardj vg_assert(0); 278112711afefcfcd43680c7c4aa8d38ef180e8811esewardj } 279112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 280112711afefcfcd43680c7c4aa8d38ef180e8811esewardj //restore regs 281112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r0 = mc->gregs[0]; 282112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r1 = mc->gregs[1]; 283112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r2 = mc->gregs[2]; 284112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r3 = mc->gregs[3]; 285112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r4 = mc->gregs[4]; 286112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r5 = mc->gregs[5]; 287112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r6 = mc->gregs[6]; 288112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r7 = mc->gregs[7]; 289112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r8 = mc->gregs[8]; 290112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r9 = mc->gregs[9]; 291112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r10 = mc->gregs[10]; 292112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r11 = mc->gregs[11]; 293112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r12 = mc->gregs[12]; 294112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r13 = mc->gregs[13]; 295112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r14 = mc->gregs[14]; 296112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r15 = mc->gregs[15]; 297112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r16 = mc->gregs[16]; 298112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r17 = mc->gregs[17]; 299112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r18 = mc->gregs[18]; 300112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r19 = mc->gregs[19]; 301112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r20 = mc->gregs[20]; 302112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r21 = mc->gregs[21]; 303112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r22 = mc->gregs[22]; 304112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r23 = mc->gregs[23]; 305112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r24 = mc->gregs[24]; 306112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r25 = mc->gregs[25]; 307112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r26 = mc->gregs[26]; 308112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r27 = mc->gregs[27]; 309112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r28 = mc->gregs[28]; 310112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r29 = mc->gregs[29]; 311112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r30 = mc->gregs[30]; 312112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r31 = mc->gregs[31]; 313112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r32 = mc->gregs[32]; 314112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r33 = mc->gregs[33]; 315112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r34 = mc->gregs[34]; 316112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r35 = mc->gregs[35]; 317112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r36 = mc->gregs[36]; 318112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r37 = mc->gregs[37]; 319112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r38 = mc->gregs[38]; 320112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r39 = mc->gregs[39]; 321112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r40 = mc->gregs[40]; 322112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r41 = mc->gregs[41]; 323112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r42 = mc->gregs[42]; 324112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r43 = mc->gregs[43]; 325112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r44 = mc->gregs[44]; 326112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r45 = mc->gregs[45]; 327112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r46 = mc->gregs[46]; 328112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r47 = mc->gregs[47]; 329112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r48 = mc->gregs[48]; 330112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r49 = mc->gregs[49]; 331112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r50 = mc->gregs[50]; 332112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r51 = mc->gregs[51]; 333112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r52 = mc->gregs[52]; 334112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r53 = mc->tp; 335112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r54 = mc->sp; 336112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_r55 = mc->lr; 337112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tst->arch.vex.guest_pc = mc->pc; 338112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 339112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_TRACK(die_mem_stack_signal, sp, frame_size); 340112711afefcfcd43680c7c4aa8d38ef180e8811esewardj if (VG_(clo_trace_signals)) 341112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_(message)( Vg_DebugMsg, 34297f1d337555234c20f3f1d0dd0b22b2a7d571616florian "VG_(signal_return) (thread %u): isRT=%d valid magic; EIP=%#x\n", 343112711afefcfcd43680c7c4aa8d38ef180e8811esewardj tid, isRT, tst->arch.vex.guest_pc); 344112711afefcfcd43680c7c4aa8d38ef180e8811esewardj /* tell the tools */ 345112711afefcfcd43680c7c4aa8d38ef180e8811esewardj VG_TRACK( post_deliver_signal, tid, sigNo ); 346112711afefcfcd43680c7c4aa8d38ef180e8811esewardj} 347112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 348112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#endif // defined(VGP_tilegx_linux) 349112711afefcfcd43680c7c4aa8d38ef180e8811esewardj 350112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/*--------------------------------------------------------------------*/ 351112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/*--- end sigframe-tilegx-linux.c ---*/ 352112711afefcfcd43680c7c4aa8d38ef180e8811esewardj/*--------------------------------------------------------------------*/ 353