HPCToolkit
x86-linux-dlresolver.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 #include <string.h>
49 #include "x86-unwind-interval.h"
50 
51 // code snippets from ld-2.17.so
52 
54  0x48, 0x83, 0xec, 0x78, // sub $0x78,%rsp
55  0x48, 0x89, 0x44, 0x24, 0x40, // mov %rax,0x40(%rsp)
56  0x48, 0x89, 0x4c, 0x24, 0x48, // mov %rcx,0x48(%rsp)
57  0x48, 0x89, 0x54, 0x24, 0x50, // mov %rdx,0x50(%rsp)
58  0x48, 0x89, 0x74, 0x24, 0x58, // mov %rsi,0x58(%rsp)
59  0x48, 0x89, 0x7c, 0x24, 0x60, // mov %rdi,0x60(%rsp)
60  0x4c, 0x89, 0x44, 0x24, 0x68, // mov %r8,0x68(%rsp)
61  0x4c, 0x89, 0x4c, 0x24, 0x70, // mov %r9,0x70(%rsp)
62  0x66, 0x0f, 0x1b, 0x04, 0x24, // bndmov %bnd0,(%rsp)
63  0x66, 0x0f, 0x1b, 0x4c, 0x24, 0x10, // bndmov %bnd1,0x10(%rsp)
64  0x66, 0x0f, 0x1b, 0x54, 0x24, 0x20, // bndmov %bnd2,0x20(%rsp)
65  0x66, 0x0f, 0x1b, 0x5c, 0x24, 0x30, // bndmov %bnd3,0x30(%rsp)
66  0x48, 0x8b, 0xb4, 0x24, 0x80, 0x00, 0x00 // mov 0x80(%rsp),%rsi
67 };
68 
69 
71  0x48, 0x83, 0xec, 0x38, // sub $0x38,%rsp
72  0x48, 0x89, 0x04, 0x24, // mov %rax,(%rsp)
73  0x48, 0x89, 0x4c, 0x24, 0x08, // mov %rcx,0x8(%rsp)
74  0x48, 0x89, 0x54, 0x24, 0x10, // mov %rdx,0x10(%rsp)
75  0x48, 0x89, 0x74, 0x24, 0x18, // mov %rsi,0x18(%rsp)
76  0x48, 0x89, 0x7c, 0x24, 0x20, // mov %rdi,0x20(%rsp)
77  0x4c, 0x89, 0x44, 0x24, 0x28, // mov %r8,0x28(%rsp)
78  0x4c, 0x89, 0x4c, 0x24, 0x30, // mov %r9,0x30(%rsp)
79  0x48, 0x8b, 0x74, 0x24, 0x40 // mov 0x40(%rsp),%rsi
80 };
81 
82 
83 static int matches(char *ins, int len, const char *sig)
84 {
85  int siglen = sizeof(sig);
86  return (len > siglen && strncmp((char *)sig, ins, siglen) == 0);
87 }
88 
89 
90 int
92 {
93 
94  if (matches(ins, len, dl_runtime_resolve_signature_1) ||
96  // one of the signatures matched
97  unwind_interval *ui = stat->first;
98  while(ui) {
99  UWI_RECIPE(ui)->reg.sp_ra_pos += 16;
100  ui = UWI_NEXT(ui);
101  }
102  return 1;
103  }
104  return 0;
105 }
bitree_uwi_t * first
static char dl_runtime_resolve_signature_1[]
#define UWI_RECIPE(btuwi)
static int matches(char *ins, int len, const char *sig)
static char dl_runtime_resolve_signature_2[]
#define UWI_NEXT(btuwi)
int x86_adjust_dl_runtime_resolve_unwind_intervals(char *ins, int len, btuwi_status_t *stat)
bitree_uwi_t unwind_interval