1
2
3
4
5
6
7
8
9
10
11#ifndef LOONGARCH64_HOST_SIGNAL_H
12#define LOONGARCH64_HOST_SIGNAL_H
13
14
15typedef ucontext_t host_sigcontext;
16
17static inline uintptr_t host_signal_pc(host_sigcontext *uc)
18{
19 return uc->uc_mcontext.__pc;
20}
21
22static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
23{
24 uc->uc_mcontext.__pc = pc;
25}
26
27static inline void *host_signal_mask(host_sigcontext *uc)
28{
29 return &uc->uc_sigmask;
30}
31
32static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
33{
34 const uint32_t *pinsn = (const uint32_t *)host_signal_pc(uc);
35 uint32_t insn = pinsn[0];
36
37
38 switch ((insn >> 26) & 0b111111) {
39 case 0b001000:
40 switch ((insn >> 24) & 0b11) {
41 case 0b01:
42 case 0b11:
43 return true;
44 }
45 break;
46 case 0b001001:
47 switch ((insn >> 24) & 0b11) {
48 case 0b01:
49 case 0b11:
50 return true;
51 }
52 break;
53 case 0b001010:
54 switch ((insn >> 22) & 0b1111) {
55 case 0b0100:
56 case 0b0101:
57 case 0b0110:
58 case 0b0111:
59 case 0b1101:
60 case 0b1111:
61 return true;
62 }
63 break;
64 case 0b001110:
65 switch ((insn >> 15) & 0b11111111111) {
66 case 0b00000100000:
67 case 0b00000101000:
68 case 0b00000110000:
69 case 0b00000111000:
70 case 0b00001110000:
71 case 0b00001111000:
72 case 0b00011101100:
73 case 0b00011101101:
74 case 0b00011101110:
75 case 0b00011101111:
76 case 0b00011111000:
77 case 0b00011111001:
78 case 0b00011111010:
79 case 0b00011111011:
80 case 0b00011111100:
81 case 0b00011111101:
82 case 0b00011111110:
83 case 0b00011111111:
84 case 0b00011000000 ... 0b00011100011:
85 return true;
86 }
87 break;
88 }
89
90 return false;
91}
92
93#endif
94