1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include "qemu/osdep.h"
20#include "qemu.h"
21#include "signal-common.h"
22#include "linux-user/trace.h"
23
24struct target_sigcontext {
25 struct target_pt_regs regs;
26 uint32_t oldmask;
27};
28
29struct target_stack_t {
30 abi_ulong ss_sp;
31 int ss_flags;
32 unsigned int ss_size;
33};
34
35struct target_ucontext {
36 abi_ulong tuc_flags;
37 abi_ulong tuc_link;
38 struct target_stack_t tuc_stack;
39 struct target_sigcontext tuc_mcontext;
40 uint32_t tuc_extramask[TARGET_NSIG_WORDS - 1];
41};
42
43
44struct target_signal_frame {
45 struct target_ucontext uc;
46 uint32_t extramask[TARGET_NSIG_WORDS - 1];
47 uint32_t tramp[2];
48};
49
50struct rt_signal_frame {
51 siginfo_t info;
52 ucontext_t uc;
53 uint32_t tramp[2];
54};
55
56static void setup_sigcontext(struct target_sigcontext *sc, CPUMBState *env)
57{
58 __put_user(env->regs[0], &sc->regs.r0);
59 __put_user(env->regs[1], &sc->regs.r1);
60 __put_user(env->regs[2], &sc->regs.r2);
61 __put_user(env->regs[3], &sc->regs.r3);
62 __put_user(env->regs[4], &sc->regs.r4);
63 __put_user(env->regs[5], &sc->regs.r5);
64 __put_user(env->regs[6], &sc->regs.r6);
65 __put_user(env->regs[7], &sc->regs.r7);
66 __put_user(env->regs[8], &sc->regs.r8);
67 __put_user(env->regs[9], &sc->regs.r9);
68 __put_user(env->regs[10], &sc->regs.r10);
69 __put_user(env->regs[11], &sc->regs.r11);
70 __put_user(env->regs[12], &sc->regs.r12);
71 __put_user(env->regs[13], &sc->regs.r13);
72 __put_user(env->regs[14], &sc->regs.r14);
73 __put_user(env->regs[15], &sc->regs.r15);
74 __put_user(env->regs[16], &sc->regs.r16);
75 __put_user(env->regs[17], &sc->regs.r17);
76 __put_user(env->regs[18], &sc->regs.r18);
77 __put_user(env->regs[19], &sc->regs.r19);
78 __put_user(env->regs[20], &sc->regs.r20);
79 __put_user(env->regs[21], &sc->regs.r21);
80 __put_user(env->regs[22], &sc->regs.r22);
81 __put_user(env->regs[23], &sc->regs.r23);
82 __put_user(env->regs[24], &sc->regs.r24);
83 __put_user(env->regs[25], &sc->regs.r25);
84 __put_user(env->regs[26], &sc->regs.r26);
85 __put_user(env->regs[27], &sc->regs.r27);
86 __put_user(env->regs[28], &sc->regs.r28);
87 __put_user(env->regs[29], &sc->regs.r29);
88 __put_user(env->regs[30], &sc->regs.r30);
89 __put_user(env->regs[31], &sc->regs.r31);
90 __put_user(env->sregs[SR_PC], &sc->regs.pc);
91}
92
93static void restore_sigcontext(struct target_sigcontext *sc, CPUMBState *env)
94{
95 __get_user(env->regs[0], &sc->regs.r0);
96 __get_user(env->regs[1], &sc->regs.r1);
97 __get_user(env->regs[2], &sc->regs.r2);
98 __get_user(env->regs[3], &sc->regs.r3);
99 __get_user(env->regs[4], &sc->regs.r4);
100 __get_user(env->regs[5], &sc->regs.r5);
101 __get_user(env->regs[6], &sc->regs.r6);
102 __get_user(env->regs[7], &sc->regs.r7);
103 __get_user(env->regs[8], &sc->regs.r8);
104 __get_user(env->regs[9], &sc->regs.r9);
105 __get_user(env->regs[10], &sc->regs.r10);
106 __get_user(env->regs[11], &sc->regs.r11);
107 __get_user(env->regs[12], &sc->regs.r12);
108 __get_user(env->regs[13], &sc->regs.r13);
109 __get_user(env->regs[14], &sc->regs.r14);
110 __get_user(env->regs[15], &sc->regs.r15);
111 __get_user(env->regs[16], &sc->regs.r16);
112 __get_user(env->regs[17], &sc->regs.r17);
113 __get_user(env->regs[18], &sc->regs.r18);
114 __get_user(env->regs[19], &sc->regs.r19);
115 __get_user(env->regs[20], &sc->regs.r20);
116 __get_user(env->regs[21], &sc->regs.r21);
117 __get_user(env->regs[22], &sc->regs.r22);
118 __get_user(env->regs[23], &sc->regs.r23);
119 __get_user(env->regs[24], &sc->regs.r24);
120 __get_user(env->regs[25], &sc->regs.r25);
121 __get_user(env->regs[26], &sc->regs.r26);
122 __get_user(env->regs[27], &sc->regs.r27);
123 __get_user(env->regs[28], &sc->regs.r28);
124 __get_user(env->regs[29], &sc->regs.r29);
125 __get_user(env->regs[30], &sc->regs.r30);
126 __get_user(env->regs[31], &sc->regs.r31);
127 __get_user(env->sregs[SR_PC], &sc->regs.pc);
128}
129
130static abi_ulong get_sigframe(struct target_sigaction *ka,
131 CPUMBState *env, int frame_size)
132{
133 abi_ulong sp = env->regs[1];
134
135 sp = target_sigsp(sp, ka);
136
137 return ((sp - frame_size) & -8UL);
138}
139
140void setup_frame(int sig, struct target_sigaction *ka,
141 target_sigset_t *set, CPUMBState *env)
142{
143 struct target_signal_frame *frame;
144 abi_ulong frame_addr;
145 int i;
146
147 frame_addr = get_sigframe(ka, env, sizeof *frame);
148 trace_user_setup_frame(env, frame_addr);
149 if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0))
150 goto badframe;
151
152
153 __put_user(set->sig[0], &frame->uc.tuc_mcontext.oldmask);
154
155 for(i = 1; i < TARGET_NSIG_WORDS; i++) {
156 __put_user(set->sig[i], &frame->extramask[i - 1]);
157 }
158
159 setup_sigcontext(&frame->uc.tuc_mcontext, env);
160
161
162
163
164 if (ka->sa_flags & TARGET_SA_RESTORER) {
165 env->regs[15] = ((unsigned long)ka->sa_restorer)-8;
166 } else {
167 uint32_t t;
168
169
170 t = 0x31800000UL | TARGET_NR_sigreturn;
171 __put_user(t, frame->tramp + 0);
172
173 t = 0xb9cc0008UL;
174 __put_user(t, frame->tramp + 1);
175
176
177
178 env->regs[15] = frame_addr + offsetof(struct target_signal_frame, tramp)
179 - 8;
180 }
181
182
183 env->regs[1] = frame_addr;
184
185 env->regs[5] = sig;
186 env->regs[6] = 0;
187
188 env->regs[7] = frame_addr += offsetof(typeof(*frame), uc);
189
190
191 env->sregs[SR_PC] = (unsigned long)ka->_sa_handler;
192
193 unlock_user_struct(frame, frame_addr, 1);
194 return;
195badframe:
196 force_sigsegv(sig);
197}
198
199void setup_rt_frame(int sig, struct target_sigaction *ka,
200 target_siginfo_t *info,
201 target_sigset_t *set, CPUMBState *env)
202{
203 qemu_log_mask(LOG_UNIMP, "setup_rt_frame: not implemented\n");
204}
205
206long do_sigreturn(CPUMBState *env)
207{
208 struct target_signal_frame *frame;
209 abi_ulong frame_addr;
210 target_sigset_t target_set;
211 sigset_t set;
212 int i;
213
214 frame_addr = env->regs[R_SP];
215 trace_user_do_sigreturn(env, frame_addr);
216
217 if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 1))
218 goto badframe;
219
220
221 __get_user(target_set.sig[0], &frame->uc.tuc_mcontext.oldmask);
222 for(i = 1; i < TARGET_NSIG_WORDS; i++) {
223 __get_user(target_set.sig[i], &frame->extramask[i - 1]);
224 }
225 target_to_host_sigset_internal(&set, &target_set);
226 set_sigmask(&set);
227
228 restore_sigcontext(&frame->uc.tuc_mcontext, env);
229
230
231 env->regs[14] = env->sregs[SR_PC];
232
233 unlock_user_struct(frame, frame_addr, 0);
234 return -TARGET_QEMU_ESIGRETURN;
235badframe:
236 force_sig(TARGET_SIGSEGV);
237 return -TARGET_QEMU_ESIGRETURN;
238}
239
240long do_rt_sigreturn(CPUMBState *env)
241{
242 trace_user_do_rt_sigreturn(env, 0);
243 qemu_log_mask(LOG_UNIMP, "do_rt_sigreturn: not implemented\n");
244 return -TARGET_ENOSYS;
245}
246