| ---
telfcorefreebsd386.c (2119B)
---
1 #include
2 #include
3 #include
4 #include "elf.h"
5 #include "ureg386.h"
6
7 typedef struct Lreg Lreg;
8 typedef struct Status Status;
9 typedef struct Psinfo Psinfo;
10
11 struct Lreg
12 {
13 u32int fs;
14 u32int es;
15 u32int ds;
16 u32int edi;
17 u32int esi;
18 u32int ebp;
19 u32int isp;
20 u32int ebx;
21 u32int edx;
22 u32int ecx;
23 u32int eax;
24 u32int trapno;
25 u32int err;
26 u32int eip;
27 u32int cs;
28 u32int eflags;
29 u32int esp;
30 u32int ss;
31 u32int gs;
32 };
33
34 struct Status
35 {
36 u32int version; /* Version number of struct (1) */
37 u32int statussz; /* sizeof(prstatus_t) (1) */
38 u32int gregsetsz; /* sizeof(gregset_t) (1) */
39 u32int fpregsetsz; /* sizeof(fpregset_t) (1) */
40 u32int osreldate; /* Kernel version (1) */
41 u32int cursig; /* Current signal (1) */
42 u32int pid; /* Process ID (1) */
43 Lreg reg; /* General purpose registers (1) */
44 };
45
46 struct Psinfo
47 {
48 u32int version;
49 u32int size;
50 char name[17];
51 char psargs[81];
52 };
53
54 int
55 coreregsfreebsd386(Elf *elf, ElfNote *note, uchar **up)
56 {
57 Status *s;
58 Lreg *l;
59 Ureg *u;
60
61 if(note->descsz < sizeof(Status)){
62 werrstr("elf status note too small");
63 return -1;
64 }
65 s = (Status*)note->desc;
66 if(s->version != 1){
67 werrstr("unknown status version %ud", (uint)s->version);
68 return -1;
69 }
70 l = &s->reg;
71 u = malloc(sizeof(Ureg));
72 if(u == nil)
73 return -1;
74
75 /* no byte order problems - just copying and rearranging */
76 u->di = l->edi;
77 u->si = l->esi;
78 u->bp = l->ebp;
79 u->nsp = l->esp;
80 u->bx = l->ebx;
81 u->dx = l->edx;
82 u->cx = l->ecx;
83 u->ax = l->eax;
84 u->gs = l->gs;
85 u->fs = l->fs;
86 u->es = l->es;
87 u->ds = l->ds;
88 u->trap = l->trapno;
89 u->ecode = l->err;
90 u->pc = l->eip;
91 u->cs = l->cs;
92 u->flags = l->eflags;
93 u->sp = l->esp;
94 u->ss = l->ss;
95 *up = (uchar*)u;
96 return sizeof(Ureg);
97 }
98
99 int
100 corecmdfreebsd386(Elf *elf, ElfNote *note, char **pp)
101 {
102 char *t;
103 Psinfo *p;
104
105 *pp = nil;
106 if(note->descsz < sizeof(Psinfo)){
107 werrstr("elf psinfo note too small");
108 return -1;
109 }
110 p = (Psinfo*)note->desc;
111 /* print("elf name %s\nelf args %s\n", p->name, p->psargs); */
112 t = malloc(80+1);
113 if(t == nil)
114 return -1;
115 memmove(t, p->psargs, 80);
116 t[80] = 0;
117 *pp = t;
118 return 0;
119 } |