OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [i386/] [kernel/] [ptrace.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1623 jcastillo
/* ptrace.c */
2
/* By Ross Biro 1/23/92 */
3
/* edited by Linus Torvalds */
4
 
5
#include <linux/config.h> /* CONFIG_MATH_EMULATION */
6
#include <linux/head.h>
7
#include <linux/kernel.h>
8
#include <linux/sched.h>
9
#include <linux/mm.h>
10
#include <linux/errno.h>
11
#include <linux/ptrace.h>
12
#include <linux/user.h>
13
#include <linux/debugreg.h>
14
 
15
#include <asm/segment.h>
16
#include <asm/pgtable.h>
17
#include <asm/system.h>
18
 
19
/*
20
 * does not yet catch signals sent when the child dies.
21
 * in exit.c or in signal.c.
22
 */
23
 
24
/* determines which flags the user has access to. */
25
/* 1 = access 0 = no access */
26
#define FLAG_MASK 0x00044dd5
27
 
28
/* set's the trap flag. */
29
#define TRAP_FLAG 0x100
30
 
31
/*
32
 * this is the number to subtract from the top of the stack. To find
33
 * the local frame.
34
 */
35
#define MAGICNUMBER 68
36
 
37
/* change a pid into a task struct. */
38
static inline struct task_struct * get_task(int pid)
39
{
40
        int i;
41
 
42
        for (i = 1; i < NR_TASKS; i++) {
43
                if (task[i] != NULL && (task[i]->pid == pid))
44
                        return task[i];
45
        }
46
        return NULL;
47
}
48
 
49
/*
50
 * this routine will get a word off of the processes privileged stack.
51
 * the offset is how far from the base addr as stored in the TSS.
52
 * this routine assumes that all the privileged stacks are in our
53
 * data space.
54
 */
55
static inline int get_stack_long(struct task_struct *task, int offset)
56
{
57
        unsigned char *stack;
58
 
59
        stack = (unsigned char *)task->tss.esp0;
60
        stack += offset;
61
        return (*((int *)stack));
62
}
63
 
64
/*
65
 * this routine will put a word on the processes privileged stack.
66
 * the offset is how far from the base addr as stored in the TSS.
67
 * this routine assumes that all the privileged stacks are in our
68
 * data space.
69
 */
70
static inline int put_stack_long(struct task_struct *task, int offset,
71
        unsigned long data)
72
{
73
        unsigned char * stack;
74
 
75
        stack = (unsigned char *) task->tss.esp0;
76
        stack += offset;
77
        *(unsigned long *) stack = data;
78
        return 0;
79
}
80
 
81
/*
82
 * This routine gets a long from any process space by following the page
83
 * tables. NOTE! You should check that the long isn't on a page boundary,
84
 * and that it is in the task area before calling this: this routine does
85
 * no checking.
86
 */
87
static unsigned long get_long(struct task_struct * tsk,
88
        struct vm_area_struct * vma, unsigned long addr)
89
{
90
        pgd_t * pgdir;
91
        pmd_t * pgmiddle;
92
        pte_t * pgtable;
93
        unsigned long page;
94
 
95
repeat:
96
        pgdir = pgd_offset(vma->vm_mm, addr);
97
        if (pgd_none(*pgdir)) {
98
                do_no_page(tsk, vma, addr, 0);
99
                goto repeat;
100
        }
101
        if (pgd_bad(*pgdir)) {
102
                printk("ptrace: bad page directory %08lx\n", pgd_val(*pgdir));
103
                pgd_clear(pgdir);
104
                return 0;
105
        }
106
        pgmiddle = pmd_offset(pgdir, addr);
107
        if (pmd_none(*pgmiddle)) {
108
                do_no_page(tsk, vma, addr, 0);
109
                goto repeat;
110
        }
111
        if (pmd_bad(*pgmiddle)) {
112
                printk("ptrace: bad page middle %08lx\n", pmd_val(*pgmiddle));
113
                pmd_clear(pgmiddle);
114
                return 0;
115
        }
116
        pgtable = pte_offset(pgmiddle, addr);
117
        if (!pte_present(*pgtable)) {
118
                do_no_page(tsk, vma, addr, 0);
119
                goto repeat;
120
        }
121
        page = pte_page(*pgtable);
122
/* this is a hack for non-kernel-mapped video buffers and similar */
123
        if (page >= high_memory)
124
                return 0;
125
        page += addr & ~PAGE_MASK;
126
        return *(unsigned long *) page;
127
}
128
 
129
/*
130
 * This routine puts a long into any process space by following the page
131
 * tables. NOTE! You should check that the long isn't on a page boundary,
132
 * and that it is in the task area before calling this: this routine does
133
 * no checking.
134
 *
135
 * Now keeps R/W state of page so that a text page stays readonly
136
 * even if a debugger scribbles breakpoints into it.  -M.U-
137
 */
138
static void put_long(struct task_struct * tsk, struct vm_area_struct * vma, unsigned long addr,
139
        unsigned long data)
140
{
141
        pgd_t *pgdir;
142
        pmd_t *pgmiddle;
143
        pte_t *pgtable;
144
        unsigned long page;
145
 
146
repeat:
147
        pgdir = pgd_offset(vma->vm_mm, addr);
148
        if (!pgd_present(*pgdir)) {
149
                do_no_page(tsk, vma, addr, 1);
150
                goto repeat;
151
        }
152
        if (pgd_bad(*pgdir)) {
153
                printk("ptrace: bad page directory %08lx\n", pgd_val(*pgdir));
154
                pgd_clear(pgdir);
155
                return;
156
        }
157
        pgmiddle = pmd_offset(pgdir, addr);
158
        if (pmd_none(*pgmiddle)) {
159
                do_no_page(tsk, vma, addr, 1);
160
                goto repeat;
161
        }
162
        if (pmd_bad(*pgmiddle)) {
163
                printk("ptrace: bad page middle %08lx\n", pmd_val(*pgmiddle));
164
                pmd_clear(pgmiddle);
165
                return;
166
        }
167
        pgtable = pte_offset(pgmiddle, addr);
168
        if (!pte_present(*pgtable)) {
169
                do_no_page(tsk, vma, addr, 1);
170
                goto repeat;
171
        }
172
        page = pte_page(*pgtable);
173
        if (!pte_write(*pgtable)) {
174
                do_wp_page(tsk, vma, addr, 1);
175
                goto repeat;
176
        }
177
/* this is a hack for non-kernel-mapped video buffers and similar */
178
        if (page < high_memory)
179
                *(unsigned long *) (page + (addr & ~PAGE_MASK)) = data;
180
/* we're bypassing pagetables, so we have to set the dirty bit ourselves */
181
/* this should also re-instate whatever read-only mode there was before */
182
        set_pte(pgtable, pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
183
        flush_tlb();
184
}
185
 
186
static struct vm_area_struct * find_extend_vma(struct task_struct * tsk, unsigned long addr)
187
{
188
        struct vm_area_struct * vma;
189
 
190
        addr &= PAGE_MASK;
191
        vma = find_vma(tsk->mm,addr);
192
        if (!vma)
193
                return NULL;
194
        if (vma->vm_start <= addr)
195
                return vma;
196
        if (!(vma->vm_flags & VM_GROWSDOWN))
197
                return NULL;
198
        if (vma->vm_end - addr > tsk->rlim[RLIMIT_STACK].rlim_cur)
199
                return NULL;
200
        vma->vm_offset -= vma->vm_start - addr;
201
        vma->vm_start = addr;
202
        return vma;
203
}
204
 
205
/*
206
 * This routine checks the page boundaries, and that the offset is
207
 * within the task area. It then calls get_long() to read a long.
208
 */
209
static int read_long(struct task_struct * tsk, unsigned long addr,
210
        unsigned long * result)
211
{
212
        struct vm_area_struct * vma = find_extend_vma(tsk, addr);
213
 
214
        if (!vma)
215
                return -EIO;
216
        if ((addr & ~PAGE_MASK) > PAGE_SIZE-sizeof(long)) {
217
                unsigned long low,high;
218
                struct vm_area_struct * vma_high = vma;
219
 
220
                if (addr + sizeof(long) >= vma->vm_end) {
221
                        vma_high = vma->vm_next;
222
                        if (!vma_high || vma_high->vm_start != vma->vm_end)
223
                                return -EIO;
224
                }
225
                low = get_long(tsk, vma, addr & ~(sizeof(long)-1));
226
                high = get_long(tsk, vma_high, (addr+sizeof(long)) & ~(sizeof(long)-1));
227
                switch (addr & (sizeof(long)-1)) {
228
                        case 1:
229
                                low >>= 8;
230
                                low |= high << 24;
231
                                break;
232
                        case 2:
233
                                low >>= 16;
234
                                low |= high << 16;
235
                                break;
236
                        case 3:
237
                                low >>= 24;
238
                                low |= high << 8;
239
                                break;
240
                }
241
                *result = low;
242
        } else
243
                *result = get_long(tsk, vma, addr);
244
        return 0;
245
}
246
 
247
/*
248
 * This routine checks the page boundaries, and that the offset is
249
 * within the task area. It then calls put_long() to write a long.
250
 */
251
static int write_long(struct task_struct * tsk, unsigned long addr,
252
        unsigned long data)
253
{
254
        struct vm_area_struct * vma = find_extend_vma(tsk, addr);
255
 
256
        if (!vma)
257
                return -EIO;
258
        if ((addr & ~PAGE_MASK) > PAGE_SIZE-sizeof(long)) {
259
                unsigned long low,high;
260
                struct vm_area_struct * vma_high = vma;
261
 
262
                if (addr + sizeof(long) >= vma->vm_end) {
263
                        vma_high = vma->vm_next;
264
                        if (!vma_high || vma_high->vm_start != vma->vm_end)
265
                                return -EIO;
266
                }
267
                low = get_long(tsk, vma, addr & ~(sizeof(long)-1));
268
                high = get_long(tsk, vma_high, (addr+sizeof(long)) & ~(sizeof(long)-1));
269
                switch (addr & (sizeof(long)-1)) {
270
                        case 0: /* shouldn't happen, but safety first */
271
                                low = data;
272
                                break;
273
                        case 1:
274
                                low &= 0x000000ff;
275
                                low |= data << 8;
276
                                high &= ~0xff;
277
                                high |= data >> 24;
278
                                break;
279
                        case 2:
280
                                low &= 0x0000ffff;
281
                                low |= data << 16;
282
                                high &= ~0xffff;
283
                                high |= data >> 16;
284
                                break;
285
                        case 3:
286
                                low &= 0x00ffffff;
287
                                low |= data << 24;
288
                                high &= ~0xffffff;
289
                                high |= data >> 8;
290
                                break;
291
                }
292
                put_long(tsk, vma, addr & ~(sizeof(long)-1),low);
293
                put_long(tsk, vma_high, (addr+sizeof(long)) & ~(sizeof(long)-1),high);
294
        } else
295
                put_long(tsk, vma, addr, data);
296
        return 0;
297
}
298
#ifdef CONFIG_MATH_EMULATION
299
static void write_emulator_word(struct task_struct *child,
300
                                unsigned long register_offset,
301
                                long data)
302
{
303
        int i, j;
304
        struct i387_soft_struct *soft_fpu;
305
        struct fpu_reg *this_fpreg, *next_fpreg;
306
        char hard_reg[2][10];
307
        int control_word;
308
        unsigned long top;
309
        i = register_offset / 10;
310
        j = register_offset % 10;
311
        soft_fpu = &child->tss.i387.soft;
312
        top = i + (unsigned long) soft_fpu->top;
313
        control_word = soft_fpu->cwd;
314
        this_fpreg = &soft_fpu->regs[(top + i) % 8];
315
        next_fpreg = &soft_fpu->regs[(top + i + 1) % 8];
316
        softreg_to_hardreg(this_fpreg, hard_reg[0], control_word);
317
        if (j > 6)
318
                softreg_to_hardreg(next_fpreg, hard_reg[1], control_word);
319
        *(long *) &hard_reg[0][j] = data;
320
        hardreg_to_softreg(hard_reg[0], this_fpreg);
321
        if (j > 6)
322
                hardreg_to_softreg(hard_reg[1], next_fpreg);
323
}
324
#endif /* defined(CONFIG_MATH_EMULATION) */
325
 
326
/*
327
 * Floating point support added to ptrace by Ramon Garcia,
328
 * ramon@juguete.quim.ucm.es
329
 */
330
 
331
#ifdef CONFIG_MATH_EMULATION
332
 
333
static unsigned long get_emulator_word(struct task_struct *child,
334
                                       unsigned long register_offset)
335
{
336
        char hard_reg[2][10];
337
        int i, j;
338
        struct fpu_reg *this_fpreg, *next_fpreg;
339
        struct i387_soft_struct *soft_fpu;
340
        long int control_word;
341
        unsigned long top;
342
        unsigned long tmp;
343
        i = register_offset / 10;
344
        j = register_offset % 10;
345
        soft_fpu = &child->tss.i387.soft;
346
        top = (unsigned long) soft_fpu->top;
347
        this_fpreg = &soft_fpu->regs[(top + i) % 8];
348
        next_fpreg = &soft_fpu->regs[(top + i + 1) % 8];
349
        control_word = soft_fpu->cwd;
350
        softreg_to_hardreg(this_fpreg, hard_reg[0], control_word);
351
        if (j > 6)
352
                softreg_to_hardreg(next_fpreg, hard_reg[1], control_word);
353
        tmp = *(long *)
354
                &hard_reg[0][j];
355
        return tmp;
356
}
357
 
358
#endif /* defined(CONFIG_MATH_EMULATION) */
359
 
360
static int putreg(struct task_struct *child,
361
        unsigned long regno, unsigned long value)
362
{
363
        switch (regno >> 2) {
364
                case ORIG_EAX:
365
                        return -EIO;
366
                case FS:
367
                case GS:
368
                case DS:
369
                case ES:
370
                        if (value && (value & 3) != 3)
371
                                return -EIO;
372
                        value &= 0xffff;
373
                        break;
374
                case SS:
375
                case CS:
376
                        if ((value & 3) != 3)
377
                                return -EIO;
378
                        value &= 0xffff;
379
                        break;
380
                case EFL:
381
                        value &= FLAG_MASK;
382
                        value |= get_stack_long(child, sizeof(long)*EFL-MAGICNUMBER) & ~FLAG_MASK;
383
        }
384
        put_stack_long(child, regno - sizeof(struct pt_regs), value);
385
        return 0;
386
}
387
 
388
static unsigned long getreg(struct task_struct *child,
389
        unsigned long regno)
390
{
391
        unsigned long retval = ~0UL;
392
 
393
        switch (regno >> 2) {
394
                case FS:
395
                case GS:
396
                case DS:
397
                case ES:
398
                case SS:
399
                case CS:
400
                        retval = 0xffff;
401
                        /* fall through */
402
                default:
403
                        regno = regno - sizeof(struct pt_regs);
404
                        retval &= get_stack_long(child, regno);
405
        }
406
        return retval;
407
}
408
 
409
asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
410
{
411
        struct task_struct *child;
412
        struct user * dummy;
413
        int i;
414
 
415
        dummy = NULL;
416
 
417
        if (request == PTRACE_TRACEME) {
418
                /* are we already being traced? */
419
                if (current->flags & PF_PTRACED)
420
                        return -EPERM;
421
                /* set the ptrace bit in the process flags. */
422
                current->flags |= PF_PTRACED;
423
                return 0;
424
        }
425
        if (pid == 1)           /* you may not mess with init */
426
                return -EPERM;
427
        if (!(child = get_task(pid)))
428
                return -ESRCH;
429
        if (request == PTRACE_ATTACH) {
430
                if (child == current)
431
                        return -EPERM;
432
                if ((!child->dumpable ||
433
                    (current->uid != child->euid) ||
434
                    (current->uid != child->suid) ||
435
                    (current->uid != child->uid) ||
436
                    (current->gid != child->egid) ||
437
                    (current->gid != child->sgid) ||
438
                    (current->gid != child->gid)) && !suser())
439
                        return -EPERM;
440
                /* the same process cannot be attached many times */
441
                if (child->flags & PF_PTRACED)
442
                        return -EPERM;
443
                child->flags |= PF_PTRACED;
444
                if (child->p_pptr != current) {
445
                        REMOVE_LINKS(child);
446
                        child->p_pptr = current;
447
                        SET_LINKS(child);
448
                }
449
                send_sig(SIGSTOP, child, 1);
450
                return 0;
451
        }
452
        if (!(child->flags & PF_PTRACED))
453
                return -ESRCH;
454
        if (child->state != TASK_STOPPED) {
455
                if (request != PTRACE_KILL)
456
                        return -ESRCH;
457
        }
458
        if (child->p_pptr != current)
459
                return -ESRCH;
460
 
461
        switch (request) {
462
        /* when I and D space are separate, these will need to be fixed. */
463
                case PTRACE_PEEKTEXT: /* read word at location addr. */
464
                case PTRACE_PEEKDATA: {
465
                        unsigned long tmp;
466
                        int res;
467
 
468
                        res = read_long(child, addr, &tmp);
469
                        if (res < 0)
470
                                return res;
471
                        res = verify_area(VERIFY_WRITE, (void *) data, sizeof(long));
472
                        if (!res)
473
                                put_fs_long(tmp,(unsigned long *) data);
474
                        return res;
475
                }
476
 
477
        /* read the word at location addr in the USER area. */
478
                case PTRACE_PEEKUSR: {
479
                        unsigned long tmp;
480
                        int res;
481
 
482
                        if ((addr & 3) || addr < 0
483
                            || addr > sizeof(struct user) - 3)
484
                                return -EIO;
485
 
486
                        res = verify_area(VERIFY_WRITE, (void *) data, sizeof(long));
487
                        if (res)
488
                                return res;
489
                        tmp = 0;  /* Default return condition */
490
                        if(addr < 17*sizeof(long))
491
                                tmp = getreg(child, addr);
492
                        else if(addr >= (long) &dummy->u_debugreg[0]
493
                                && addr <= (long) &dummy->u_debugreg[7])
494
                        {
495
                                addr -= (long) &dummy->u_debugreg[0];
496
                                addr = addr >> 2;
497
                                tmp = child->debugreg[addr];
498
                        }
499
                        put_fs_long(tmp,(unsigned long *) data);
500
                        return 0;
501
                }
502
 
503
      /* when I and D space are separate, this will have to be fixed. */
504
                case PTRACE_POKETEXT: /* write the word at location addr. */
505
                case PTRACE_POKEDATA:
506
                        return write_long(child,addr,data);
507
 
508
                case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
509
                        if ((addr & 3) || addr < 0
510
                            || addr > sizeof(struct user) - 3)
511
                                return -EIO;
512
 
513
                        if(addr < 17*sizeof(long))
514
                                return putreg(child, addr, data);
515
 
516
                  /* We need to be very careful here.  We implicitly
517
                     want to modify a portion of the task_struct, and we
518
                     have to be selective about what portions we allow someone
519
                     to modify. */
520
 
521
                  if(addr >= (long) &dummy->u_debugreg[0] &&
522
                     addr <= (long) &dummy->u_debugreg[7]){
523
 
524
                          if(addr == (long) &dummy->u_debugreg[4]) return -EIO;
525
                          if(addr == (long) &dummy->u_debugreg[5]) return -EIO;
526
                          if(addr < (long) &dummy->u_debugreg[4] &&
527
                             ((unsigned long) data) >= 0xbffffffd) return -EIO;
528
 
529
                          if(addr == (long) &dummy->u_debugreg[7]) {
530
                                  data &= ~DR_CONTROL_RESERVED;
531
                                  for(i=0; i<4; i++)
532
                                          if ((0x5f54 >> ((data >> (16 + 4*i)) & 0xf)) & 1)
533
                                                  return -EIO;
534
                          };
535
 
536
                          addr -= (long) &dummy->u_debugreg;
537
                          addr = addr >> 2;
538
                          child->debugreg[addr] = data;
539
                          return 0;
540
                  };
541
                  return -EIO;
542
 
543
                case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
544
                case PTRACE_CONT: { /* restart after signal. */
545
                        long tmp;
546
 
547
                        if ((unsigned long) data > NSIG)
548
                                return -EIO;
549
                        if (request == PTRACE_SYSCALL)
550
                                child->flags |= PF_TRACESYS;
551
                        else
552
                                child->flags &= ~PF_TRACESYS;
553
                        child->exit_code = data;
554
                        wake_up_process(child);
555
        /* make sure the single step bit is not set. */
556
                        tmp = get_stack_long(child, sizeof(long)*EFL-MAGICNUMBER) & ~TRAP_FLAG;
557
                        put_stack_long(child, sizeof(long)*EFL-MAGICNUMBER,tmp);
558
                        return 0;
559
                }
560
 
561
/*
562
 * make the child exit.  Best I can do is send it a sigkill.
563
 * perhaps it should be put in the status that it wants to
564
 * exit.
565
 */
566
                case PTRACE_KILL: {
567
                        long tmp;
568
 
569
                        if (child->state == TASK_ZOMBIE)        /* already dead */
570
                                return 0;
571
                        wake_up_process(child);
572
                        child->exit_code = SIGKILL;
573
        /* make sure the single step bit is not set. */
574
                        tmp = get_stack_long(child, sizeof(long)*EFL-MAGICNUMBER) & ~TRAP_FLAG;
575
                        put_stack_long(child, sizeof(long)*EFL-MAGICNUMBER,tmp);
576
                        return 0;
577
                }
578
 
579
                case PTRACE_SINGLESTEP: {  /* set the trap flag. */
580
                        long tmp;
581
 
582
                        if ((unsigned long) data > NSIG)
583
                                return -EIO;
584
                        child->flags &= ~PF_TRACESYS;
585
                        tmp = get_stack_long(child, sizeof(long)*EFL-MAGICNUMBER) | TRAP_FLAG;
586
                        put_stack_long(child, sizeof(long)*EFL-MAGICNUMBER,tmp);
587
                        wake_up_process(child);
588
                        child->exit_code = data;
589
        /* give it a chance to run. */
590
                        return 0;
591
                }
592
 
593
                case PTRACE_DETACH: { /* detach a process that was attached. */
594
                        long tmp;
595
 
596
                        if ((unsigned long) data > NSIG)
597
                                return -EIO;
598
                        child->flags &= ~(PF_PTRACED|PF_TRACESYS);
599
                        wake_up_process(child);
600
                        child->exit_code = data;
601
                        REMOVE_LINKS(child);
602
                        child->p_pptr = child->p_opptr;
603
                        SET_LINKS(child);
604
                        /* make sure the single step bit is not set. */
605
                        tmp = get_stack_long(child, sizeof(long)*EFL-MAGICNUMBER) & ~TRAP_FLAG;
606
                        put_stack_long(child, sizeof(long)*EFL-MAGICNUMBER,tmp);
607
                        return 0;
608
                }
609
 
610
                case PTRACE_GETREGS: { /* Get all gp regs from the child. */
611
#ifdef CONFIG_MATH_EMULATION
612
                        if (!hard_math)
613
                                /* Not supported. */
614
                                return -EIO;
615
#endif
616
 
617
                        if (verify_area(VERIFY_WRITE, (void *) data,
618
                                        17*sizeof(long)))
619
                          return -EIO;
620
                        for (i = 0; i < 17*sizeof(long);
621
                             i += sizeof(long), data += sizeof(long))
622
                          put_fs_long (getreg(child, i), (unsigned long *) data);
623
                        return 0;
624
                  };
625
 
626
                case PTRACE_SETREGS: { /* Set all gp regs in the child. */
627
                        unsigned long tmp;
628
 
629
#ifdef CONFIG_MATH_EMULATION
630
                        if (!hard_math)
631
                                /* Not supported. */
632
                                return -EIO;
633
#endif
634
 
635
                        if (verify_area(VERIFY_READ, (void *) data,
636
                                        17*sizeof(long)))
637
                          return -EIO;
638
                        for (i = 0; i < 17*sizeof(long);
639
                             i += sizeof(long), data += sizeof(long))
640
                          {
641
                            tmp = get_fs_long ((unsigned long *) data);
642
                            putreg(child, i, tmp);
643
                          }
644
                        return 0;
645
                  };
646
 
647
                case PTRACE_GETFPREGS: { /* Get the child FPU state. */
648
                        unsigned long *tmp;
649
 
650
#ifdef CONFIG_MATH_EMULATION
651
                        if (!hard_math)
652
                                /* Not supported. */
653
                                return -EIO;
654
#endif
655
 
656
                        if (verify_area(VERIFY_WRITE, (void *) data,
657
                                        sizeof(struct user_i387_struct)))
658
                          return -EIO;
659
                        if ( !child->used_math ) {
660
                          /* Simulate an empty FPU. */
661
                          child->tss.i387.hard.cwd = 0xffff037f;
662
                          child->tss.i387.hard.swd = 0xffff0000;
663
                          child->tss.i387.hard.twd = 0xffffffff;
664
                        }
665
                        if (last_task_used_math == child)
666
                          {
667
                            clts();
668
                            __asm__("fnsave %0; fwait":"=m" (child->tss.i387.hard));
669
                            last_task_used_math = NULL;
670
                            stts();
671
                          }
672
                        tmp = (unsigned long *) &child->tss.i387.hard;
673
                        for ( i = 0; i < sizeof(struct user_i387_struct); i += sizeof(long) )
674
                          {
675
                            put_fs_long (*tmp, (unsigned long *) data);
676
                            data += sizeof(long);
677
                            tmp++;
678
                          }
679
 
680
                        return 0;
681
                  };
682
 
683
                case PTRACE_SETFPREGS: { /* Set the child FPU state. */
684
                        unsigned long *tmp;
685
 
686
#ifdef CONFIG_MATH_EMULATION
687
                        if (!hard_math)
688
                                /* Not supported. */
689
                                return -EIO;
690
#endif
691
 
692
                        if (verify_area(VERIFY_READ, (void *) data,
693
                                        sizeof(struct user_i387_struct)))
694
                          return -EIO;
695
                        child->used_math = 1;
696
                        if (last_task_used_math == child)
697
                          {
698
                            /* Discard the state of the FPU */
699
                            last_task_used_math = NULL;
700
                          }
701
                        tmp = (unsigned long *) &child->tss.i387.hard;
702
                        for ( i = 0; i < sizeof(struct user_i387_struct); i += sizeof(long) )
703
                          {
704
                            *tmp = get_fs_long ((unsigned long *) data);
705
                            data += sizeof(long);
706
                            tmp++;
707
                          }
708
                        child->flags &= ~PF_USEDFPU;
709
                        return 0;
710
                  };
711
 
712
                default:
713
                        return -EIO;
714
        }
715
}
716
 
717
asmlinkage void syscall_trace(void)
718
{
719
        if ((current->flags & (PF_PTRACED|PF_TRACESYS))
720
                        != (PF_PTRACED|PF_TRACESYS))
721
                return;
722
        current->exit_code = SIGTRAP;
723
        current->state = TASK_STOPPED;
724
        notify_parent(current, SIGCHLD);
725
        schedule();
726
        /*
727
         * this isn't the same as continuing with a signal, but it will do
728
         * for normal use.  strace only continues with a signal if the
729
         * stopping signal is not SIGTRAP.  -brl
730
         */
731
        if (current->exit_code)
732
                current->signal |= (1 << (current->exit_code - 1));
733
        current->exit_code = 0;
734
}
735
 
736
void get_pt_regs_for_task(struct pt_regs *regs, struct task_struct *task)
737
{
738
        *regs = *(struct pt_regs *) (((unsigned char *) task->tss.esp0) - MAGICNUMBER);
739
}
740
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.