This source file includes following definitions.
- svr4_getcontext
- svr4_setcontext
- svr4_getsiginfo
- svr4_sendsig
- svr4_sys_sysarch
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 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/namei.h>
34 #include <sys/proc.h>
35 #include <sys/user.h>
36 #include <sys/filedesc.h>
37 #include <sys/ioctl.h>
38 #include <sys/mount.h>
39 #include <sys/kernel.h>
40 #include <sys/signal.h>
41 #include <sys/signalvar.h>
42 #include <sys/malloc.h>
43
44 #include <sys/syscallargs.h>
45 #include <compat/svr4/svr4_types.h>
46 #include <compat/svr4/svr4_ucontext.h>
47 #include <compat/svr4/svr4_syscallargs.h>
48 #include <compat/svr4/svr4_util.h>
49
50 #include <machine/cpu.h>
51 #include <machine/cpufunc.h>
52 #include <machine/psl.h>
53 #include <machine/reg.h>
54 #include <machine/specialreg.h>
55 #include <machine/sysarch.h>
56 #include <machine/vm86.h>
57 #include <machine/svr4_machdep.h>
58
59 static void svr4_getsiginfo(union svr4_siginfo *, int, u_long, int, caddr_t);
60
61 void
62 svr4_getcontext(struct proc *p, struct svr4_ucontext *uc, int mask,
63 int oonstack)
64 {
65 struct trapframe *tf = p->p_md.md_regs;
66 struct sigacts *psp = p->p_sigacts;
67 svr4_greg_t *r = uc->uc_mcontext.greg;
68 struct svr4_sigaltstack *s = &uc->uc_stack;
69 struct sigaltstack *sf = &psp->ps_sigstk;
70
71 bzero(uc, sizeof(struct svr4_ucontext));
72
73
74
75
76 #ifdef VM86
77 if (tf->tf_eflags & PSL_VM) {
78 r[SVR4_X86_GS] = tf->tf_vm86_gs;
79 r[SVR4_X86_FS] = tf->tf_vm86_fs;
80 r[SVR4_X86_ES] = tf->tf_vm86_es;
81 r[SVR4_X86_DS] = tf->tf_vm86_ds;
82 r[SVR4_X86_EFL] = get_vflags(p);
83 } else
84 #endif
85 {
86 r[SVR4_X86_FS] = tf->tf_fs;
87 r[SVR4_X86_GS] = tf->tf_gs;
88 r[SVR4_X86_ES] = tf->tf_es;
89 r[SVR4_X86_DS] = tf->tf_ds;
90 r[SVR4_X86_EFL] = tf->tf_eflags;
91 }
92 r[SVR4_X86_EDI] = tf->tf_edi;
93 r[SVR4_X86_ESI] = tf->tf_esi;
94 r[SVR4_X86_EBP] = tf->tf_ebp;
95 r[SVR4_X86_ESP] = tf->tf_esp;
96 r[SVR4_X86_EBX] = tf->tf_ebx;
97 r[SVR4_X86_EDX] = tf->tf_edx;
98 r[SVR4_X86_ECX] = tf->tf_ecx;
99 r[SVR4_X86_EAX] = tf->tf_eax;
100 r[SVR4_X86_TRAPNO] = 0;
101 r[SVR4_X86_ERR] = 0;
102 r[SVR4_X86_EIP] = tf->tf_eip;
103 r[SVR4_X86_CS] = tf->tf_cs;
104 r[SVR4_X86_UESP] = 0;
105 r[SVR4_X86_SS] = tf->tf_ss;
106
107
108
109
110 bsd_to_svr4_sigaltstack(sf, s);
111
112
113
114
115 bsd_to_svr4_sigset(&mask, &uc->uc_sigmask);
116
117
118
119
120 uc->uc_flags = SVR4_UC_ALL;
121 }
122
123
124
125
126
127
128
129
130
131
132
133
134 int
135 svr4_setcontext(struct proc *p, struct svr4_ucontext *uc)
136 {
137 struct sigacts *psp = p->p_sigacts;
138 struct trapframe *tf;
139 svr4_greg_t *r = uc->uc_mcontext.greg;
140 struct svr4_sigaltstack *s = &uc->uc_stack;
141 struct sigaltstack *sf = &psp->ps_sigstk;
142 int mask;
143
144
145
146
147
148
149
150
151
152
153 tf = p->p_md.md_regs;
154
155
156
157
158 #ifdef VM86
159 if (r[SVR4_X86_EFL] & PSL_VM) {
160 tf->tf_vm86_gs = r[SVR4_X86_GS];
161 tf->tf_vm86_fs = r[SVR4_X86_FS];
162 tf->tf_vm86_es = r[SVR4_X86_ES];
163 tf->tf_vm86_ds = r[SVR4_X86_DS];
164 set_vflags(p, r[SVR4_X86_EFL]);
165 } else
166 #endif
167 {
168
169
170
171
172
173
174 if (((r[SVR4_X86_EFL] ^ tf->tf_eflags) & PSL_USERSTATIC) != 0 ||
175 !USERMODE(r[SVR4_X86_CS], r[SVR4_X86_EFL]))
176 return (EINVAL);
177
178 tf->tf_fs = r[SVR4_X86_FS];
179 tf->tf_gs = r[SVR4_X86_GS];
180 tf->tf_es = r[SVR4_X86_ES];
181 tf->tf_ds = r[SVR4_X86_DS];
182 tf->tf_eflags = r[SVR4_X86_EFL];
183 }
184 tf->tf_edi = r[SVR4_X86_EDI];
185 tf->tf_esi = r[SVR4_X86_ESI];
186 tf->tf_ebp = r[SVR4_X86_EBP];
187 tf->tf_ebx = r[SVR4_X86_EBX];
188 tf->tf_edx = r[SVR4_X86_EDX];
189 tf->tf_ecx = r[SVR4_X86_ECX];
190 tf->tf_eax = r[SVR4_X86_EAX];
191 tf->tf_eip = r[SVR4_X86_EIP];
192 tf->tf_cs = r[SVR4_X86_CS];
193 tf->tf_ss = r[SVR4_X86_SS];
194 tf->tf_esp = r[SVR4_X86_ESP];
195
196
197
198
199 svr4_to_bsd_sigaltstack(s, sf);
200
201
202
203
204 svr4_to_bsd_sigset(&uc->uc_sigmask, &mask);
205 p->p_sigmask = mask & ~sigcantmask;
206
207 return EJUSTRETURN;
208 }
209
210
211 static void
212 svr4_getsiginfo(union svr4_siginfo *si, int sig, u_long code, int type,
213 caddr_t addr)
214 {
215 si->svr4_si_signo = bsd_to_svr4_sig[sig];
216 si->svr4_si_errno = 0;
217 si->svr4_si_addr = addr;
218
219 si->svr4_si_code = 0;
220 si->svr4_si_trap = 0;
221
222 switch (sig) {
223 case SIGSEGV:
224 switch (type) {
225 case SEGV_ACCERR:
226 si->svr4_si_code = SVR4_SEGV_ACCERR;
227 si->svr4_si_trap = SVR4_T_PROTFLT;
228 break;
229 case SEGV_MAPERR:
230 si->svr4_si_code = SVR4_SEGV_MAPERR;
231 si->svr4_si_trap = SVR4_T_SEGNPFLT;
232 break;
233 }
234 break;
235 case SIGBUS:
236 switch (type) {
237 case BUS_ADRALN:
238 si->svr4_si_code = SVR4_BUS_ADRALN;
239 si->svr4_si_trap = SVR4_T_ALIGNFLT;
240 break;
241 }
242 break;
243 case SIGTRAP:
244 switch (type) {
245 case TRAP_BRKPT:
246 si->svr4_si_code = SVR4_TRAP_BRKPT;
247 si->svr4_si_trap = SVR4_T_BPTFLT;
248 break;
249 case TRAP_TRACE:
250 si->svr4_si_code = SVR4_TRAP_TRACE;
251 si->svr4_si_trap = SVR4_T_TRCTRAP;
252 break;
253 }
254 break;
255 case SIGEMT:
256 switch (type) {
257 }
258 break;
259 case SIGILL:
260 switch (type) {
261 case ILL_PRVOPC:
262 si->svr4_si_code = SVR4_ILL_PRVOPC;
263 si->svr4_si_trap = SVR4_T_PRIVINFLT;
264 break;
265 case ILL_BADSTK:
266 si->svr4_si_code = SVR4_ILL_BADSTK;
267 si->svr4_si_trap = SVR4_T_STKFLT;
268 break;
269 }
270 break;
271 case SIGFPE:
272 switch (type) {
273 case FPE_INTOVF:
274 si->svr4_si_code = SVR4_FPE_INTOVF;
275 si->svr4_si_trap = SVR4_T_DIVIDE;
276 break;
277 case FPE_FLTDIV:
278 si->svr4_si_code = SVR4_FPE_FLTDIV;
279 si->svr4_si_trap = SVR4_T_DIVIDE;
280 break;
281 case FPE_FLTOVF:
282 si->svr4_si_code = SVR4_FPE_FLTOVF;
283 si->svr4_si_trap = SVR4_T_DIVIDE;
284 break;
285 case FPE_FLTSUB:
286 si->svr4_si_code = SVR4_FPE_FLTSUB;
287 si->svr4_si_trap = SVR4_T_BOUND;
288 break;
289 case FPE_FLTINV:
290 si->svr4_si_code = SVR4_FPE_FLTINV;
291 si->svr4_si_trap = SVR4_T_FPOPFLT;
292 break;
293 }
294 break;
295 }
296 }
297
298
299
300
301
302
303
304
305
306
307
308 void
309 svr4_sendsig(sig_t catcher, int sig, int mask, u_long code, int type,
310 union sigval val)
311 {
312 struct proc *p = curproc;
313 struct trapframe *tf;
314 struct svr4_sigframe *fp, frame;
315 struct sigacts *psp = p->p_sigacts;
316 int oonstack;
317
318 tf = p->p_md.md_regs;
319 oonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
320
321
322
323
324 if ((psp->ps_flags & SAS_ALTSTACK) && !oonstack &&
325 (psp->ps_sigonstack & sigmask(sig))) {
326 fp = (struct svr4_sigframe *)((char *)psp->ps_sigstk.ss_sp +
327 psp->ps_sigstk.ss_size - sizeof(struct svr4_sigframe));
328 psp->ps_sigstk.ss_flags |= SS_ONSTACK;
329 } else {
330 fp = (struct svr4_sigframe *)tf->tf_esp - 1;
331 }
332
333
334
335
336
337
338
339
340
341
342
343 svr4_getcontext(p, &frame.sf_uc, mask, oonstack);
344 svr4_getsiginfo(&frame.sf_si, sig, code, type, val.sival_ptr);
345
346 frame.sf_signum = frame.sf_si.svr4_si_signo;
347 frame.sf_sip = &fp->sf_si;
348 frame.sf_ucp = &fp->sf_uc;
349 frame.sf_handler = catcher;
350 #ifdef DEBUG_SVR4
351 printf("sig = %d, sip %p, ucp = %p, handler = %p\n",
352 frame.sf_signum, frame.sf_sip, frame.sf_ucp, frame.sf_handler);
353 #endif
354
355 if (copyout(&frame, fp, sizeof(frame)) != 0) {
356
357
358
359
360 sigexit(p, SIGILL);
361
362 }
363
364
365
366
367 tf->tf_es = GSEL(GUDATA_SEL, SEL_UPL);
368 tf->tf_ds = GSEL(GUDATA_SEL, SEL_UPL);
369 tf->tf_eip = p->p_sigcode;
370 tf->tf_cs = GSEL(GUCODE_SEL, SEL_UPL);
371 tf->tf_eflags &= ~(PSL_T|PSL_VM|PSL_AC);
372 tf->tf_esp = (int)fp;
373 tf->tf_ss = GSEL(GUDATA_SEL, SEL_UPL);
374 }
375
376
377
378
379
380 int
381 svr4_sys_sysarch(struct proc *p, void *v, register_t *retval)
382 {
383 struct svr4_sys_sysarch_args *uap = v;
384 int error;
385 #ifdef USER_LDT
386 caddr_t sg = stackgap_init(p->p_emul);
387 #endif
388 *retval = 0;
389
390 switch (SCARG(uap, op)) {
391 case SVR4_SYSARCH_FPHW:
392 return 0;
393
394 case SVR4_SYSARCH_DSCR:
395 #ifdef USER_LDT
396 if (user_ldt_enable == 0)
397 return (ENOSYS);
398 else {
399 struct i386_set_ldt_args sa, *sap;
400 struct sys_sysarch_args ua;
401
402 struct svr4_ssd ssd;
403 union descriptor bsd;
404
405 if ((error = copyin(SCARG(uap, a1), &ssd,
406 sizeof(ssd))) != 0) {
407 printf("Cannot copy arg1\n");
408 return error;
409 }
410
411 printf("s=%x, b=%x, l=%x, a1=%x a2=%x\n",
412 ssd.selector, ssd.base, ssd.limit,
413 ssd.access1, ssd.access2);
414
415
416 if (!ISLDT(ssd.selector)) {
417 printf("Not an ldt\n");
418 return EPERM;
419 }
420
421
422 if (ssd.access1 == 0)
423 return 0;
424
425 bsd.sd.sd_lobase = ssd.base & 0xffffff;
426 bsd.sd.sd_hibase = (ssd.base >> 24) & 0xff;
427
428 bsd.sd.sd_lolimit = ssd.limit & 0xffff;
429 bsd.sd.sd_hilimit = (ssd.limit >> 16) & 0xf;
430
431 bsd.sd.sd_type = ssd.access1 & 0x1f;
432 bsd.sd.sd_dpl = (ssd.access1 >> 5) & 0x3;
433 bsd.sd.sd_p = (ssd.access1 >> 7) & 0x1;
434
435 bsd.sd.sd_xx = ssd.access2 & 0x3;
436 bsd.sd.sd_def32 = (ssd.access2 >> 2) & 0x1;
437 bsd.sd.sd_gran = (ssd.access2 >> 3)& 0x1;
438
439 sa.start = IDXSEL(ssd.selector);
440 sa.desc = stackgap_alloc(&sg, sizeof(union descriptor));
441 sa.num = 1;
442 sap = stackgap_alloc(&sg,
443 sizeof(struct i386_set_ldt_args));
444
445 if ((error = copyout(&sa, sap, sizeof(sa))) != 0) {
446 printf("Cannot copyout args\n");
447 return error;
448 }
449
450 SCARG(&ua, op) = I386_SET_LDT;
451 SCARG(&ua, parms) = (char *) sap;
452
453 if ((error = copyout(&bsd, sa.desc, sizeof(bsd))) != 0) {
454 printf("Cannot copyout desc\n");
455 return error;
456 }
457
458 return sys_sysarch(p, &ua, retval);
459 }
460 #endif
461 case SVR4_SYSARCH_GOSF:
462 {
463
464 char features[] = {1,1,1,1,1,1,1,1,2,1,1,1};
465
466 if ((error = copyout(features, SCARG(uap, a1),
467 sizeof(features))) != 0) {
468 printf("Cannot copyout vector\n");
469 return error;
470 }
471
472 return 0;
473 }
474
475 default:
476 printf("svr4_sysarch(%d), a1 %p\n", SCARG(uap, op),
477 SCARG(uap, a1));
478 return 0;
479 }
480 }