1
2
3
4
5
6
7
8
9
10
11#ifndef AARCH64_HOST_SIGNAL_H
12#define AARCH64_HOST_SIGNAL_H
13
14
15typedef ucontext_t host_sigcontext;
16
17
18#ifndef ESR_MAGIC
19#define ESR_MAGIC 0x45535201
20struct esr_context {
21 struct _aarch64_ctx head;
22 uint64_t esr;
23};
24#endif
25
26static inline struct _aarch64_ctx *first_ctx(host_sigcontext *uc)
27{
28 return (struct _aarch64_ctx *)&uc->uc_mcontext.__reserved;
29}
30
31static inline struct _aarch64_ctx *next_ctx(struct _aarch64_ctx *hdr)
32{
33 return (struct _aarch64_ctx *)((char *)hdr + hdr->size);
34}
35
36static inline uintptr_t host_signal_pc(host_sigcontext *uc)
37{
38 return uc->uc_mcontext.pc;
39}
40
41static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
42{
43 uc->uc_mcontext.pc = pc;
44}
45
46static inline void *host_signal_mask(host_sigcontext *uc)
47{
48 return &uc->uc_sigmask;
49}
50
51static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
52{
53 struct _aarch64_ctx *hdr;
54 uint32_t insn;
55
56
57 for (hdr = first_ctx(uc); hdr->magic; hdr = next_ctx(hdr)) {
58 if (hdr->magic == ESR_MAGIC) {
59 struct esr_context const *ec = (struct esr_context const *)hdr;
60 uint64_t esr = ec->esr;
61
62
63 return extract32(esr, 27, 5) == 0x12 && extract32(esr, 6, 1) == 1;
64 }
65 }
66
67
68
69
70
71 insn = *(uint32_t *)host_signal_pc(uc);
72
73 return (insn & 0xbfff0000) == 0x0c000000
74 || (insn & 0xbfe00000) == 0x0c800000
75 || (insn & 0xbfdf0000) == 0x0d000000
76 || (insn & 0xbfc00000) == 0x0d800000
77 || (insn & 0x3f400000) == 0x08000000
78 || (insn & 0x3bc00000) == 0x39000000
79 || (insn & 0x3fc00000) == 0x3d800000
80
81 || (insn & 0x3bc00000) == 0x38000000
82 || (insn & 0x3fe00000) == 0x3c800000
83
84 || (insn & 0x3a400000) == 0x28000000;
85}
86
87#endif
88