HPCToolkit
x86-intel-align64.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // --------------------------------------------------------------------------
6 // Part of HPCToolkit (hpctoolkit.org)
7 //
8 // Information about sources of support for research and development of
9 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
10 // --------------------------------------------------------------------------
11 //
12 // Copyright ((c)) 2002-2019, Rice University
13 // All rights reserved.
14 //
15 // Redistribution and use in source and binary forms, with or without
16 // modification, are permitted provided that the following conditions are
17 // met:
18 //
19 // * Redistributions of source code must retain the above copyright
20 // notice, this list of conditions and the following disclaimer.
21 //
22 // * Redistributions in binary form must reproduce the above copyright
23 // notice, this list of conditions and the following disclaimer in the
24 // documentation and/or other materials provided with the distribution.
25 //
26 // * Neither the name of Rice University (RICE) nor the names of its
27 // contributors may be used to endorse or promote products derived from
28 // this software without specific prior written permission.
29 //
30 // This software is provided by RICE and contributors "as is" and any
31 // express or implied warranties, including, but not limited to, the
32 // implied warranties of merchantability and fitness for a particular
33 // purpose are disclaimed. In no event shall RICE or contributors be
34 // liable for any direct, indirect, incidental, special, exemplary, or
35 // consequential damages (including, but not limited to, procurement of
36 // substitute goods or services; loss of use, data, or profits; or
37 // business interruption) however caused and on any theory of liability,
38 // whether in contract, strict liability, or tort (including negligence
39 // or otherwise) arising in any way out of the use of this software, even
40 // if advised of the possibility of such damage.
41 //
42 // ******************************************************* EndRiceCopyright *
43 
44 #include <string.h>
46 #include "x86-unwind-interval.h"
47 
48 static char intel_align64_signature[] = {
49  0x53, // push %rbx
50  0x48, 0x89, 0xe3, // mov %rsp,%rbx
51  0x48, 0x83, 0xe4, 0xc0, // and $0xffffffffffffffc0,%rsp
52  0x55, // push %rbp
53  0x55, // push %rbp
54  0x48, 0x8b, 0x6b, 0x08, // mov 0x8(%rbx),%rbp
55  0x48, 0x89, 0x6c, 0x24, 0x08, // mov %rbp,0x8(%rsp)
56  0x48, 0x89, 0xe5, // mov %rsp,%rbp
57 };
58 
59 
60 int
62 {
63  int siglen = sizeof(intel_align64_signature);
64 
65  if (len > siglen && strncmp((char *)intel_align64_signature, ins, siglen) == 0) {
66  // signature matched
67  unwind_interval *ui = stat->first;
68 
69  // this won't fix all of the intervals, but it will fix the ones
70  // that we care about.
71  //
72  // The method is as follows:
73  // Ignore (do not correct) intervals before 1st std frame
74  // For 1st STD_FRAME, compute the corrections for this interval and subsequent intervals
75  // For this interval and subsequent interval, apply the corrected offsets
76  //
77 
78  for(; UWI_RECIPE(ui)->ra_status != RA_STD_FRAME; ui = UWI_NEXT(ui));
79 
80  // this is only correct for 64-bit code
81  for(; ui; ui = UWI_NEXT(ui)) {
82  x86recipe_t *xr = UWI_RECIPE(ui);
83  if (xr->ra_status == RA_SP_RELATIVE) continue;
84  if ((xr->ra_status == RA_STD_FRAME) || (xr->ra_status == RA_BP_FRAME)) {
85  xr->ra_status = RA_BP_FRAME;
86  xr->reg.bp_ra_pos = 8;
87  xr->reg.bp_bp_pos = 0;
88  }
89  }
90 
91  return 1;
92  }
93  return 0;
94 }
bitree_uwi_t * first
static char intel_align64_signature[]
#define UWI_RECIPE(btuwi)
x86registers_t reg
#define UWI_NEXT(btuwi)
int x86_adjust_intel_align64_intervals(char *ins, int len, btuwi_status_t *stat)
bitree_uwi_t unwind_interval