File: remote.h

package info (click to toggle)
libunwind 1.2.1-9
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,040 kB
  • sloc: ansic: 33,510; sh: 11,973; asm: 1,863; makefile: 919; cpp: 118
file content (127 lines) | stat: -rw-r--r-- 2,718 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef REMOTE_H
#define REMOTE_H

/* Helper functions for accessing (remote) memory.  These functions
   assume that all addresses are naturally aligned (e.g., 32-bit
   quantity is stored at a 32-bit-aligned address.  */

#ifdef UNW_LOCAL_ONLY

static inline int
fetch8 (unw_addr_space_t as, unw_accessors_t *a,
        unw_word_t *addr, int8_t *valp, void *arg)
{
  *valp = *(int8_t *) (uintptr_t) *addr;
  *addr += 1;
  return 0;
}

static inline int
fetch16 (unw_addr_space_t as, unw_accessors_t *a,
         unw_word_t *addr, int16_t *valp, void *arg)
{
  *valp = *(int16_t *) (uintptr_t) *addr;
  *addr += 2;
  return 0;
}

static inline int
fetch32 (unw_addr_space_t as, unw_accessors_t *a,
         unw_word_t *addr, int32_t *valp, void *arg)
{
  *valp = *(int32_t *) (uintptr_t) *addr;
  *addr += 4;
  return 0;
}

static inline int
fetchw (unw_addr_space_t as, unw_accessors_t *a,
        unw_word_t *addr, unw_word_t *valp, void *arg)
{
  *valp = *(unw_word_t *) (uintptr_t) *addr;
  *addr += sizeof (unw_word_t);
  return 0;
}

#else /* !UNW_LOCAL_ONLY */

#define WSIZE   (sizeof (unw_word_t))

static inline int
fetch8 (unw_addr_space_t as, unw_accessors_t *a,
        unw_word_t *addr, int8_t *valp, void *arg)
{
  unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
  int ret;

  *addr += 1;

  ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);

#if __BYTE_ORDER == __LITTLE_ENDIAN
  val >>= 8*off;
#else
  val >>= 8*(WSIZE - 1 - off);
#endif
  *valp = val & 0xff;
  return ret;
}

static inline int
fetch16 (unw_addr_space_t as, unw_accessors_t *a,
         unw_word_t *addr, int16_t *valp, void *arg)
{
  unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
  int ret;

  assert ((off & 0x1) == 0);

  *addr += 2;

  ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);

#if __BYTE_ORDER == __LITTLE_ENDIAN
  val >>= 8*off;
#else
  val >>= 8*(WSIZE - 2 - off);
#endif
  *valp = val & 0xffff;
  return ret;
}

static inline int
fetch32 (unw_addr_space_t as, unw_accessors_t *a,
         unw_word_t *addr, int32_t *valp, void *arg)
{
  unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
  int ret;

  assert ((off & 0x3) == 0);

  *addr += 4;

  ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);

#if __BYTE_ORDER == __LITTLE_ENDIAN
  val >>= 8*off;
#else
  val >>= 8*(WSIZE - 4 - off);
#endif
  *valp = val & 0xffffffff;
  return ret;
}

static inline int
fetchw (unw_addr_space_t as, unw_accessors_t *a,
        unw_word_t *addr, unw_word_t *valp, void *arg)
{
  int ret;

  ret = (*a->access_mem) (as, *addr, valp, 0, arg);
  *addr += WSIZE;
  return ret;
}

#endif /* !UNW_LOCAL_ONLY */

#endif /* REMOTE_H */