aboutsummaryrefslogtreecommitdiff
path: root/src/libmach/elfcorefreebsd386.c
blob: 2ff746dee42843fa39c6604fb527172662975961 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <u.h>
#include <libc.h>
#include <mach.h>
#include "elf.h"
#include "ureg386.h"

typedef struct Lreg Lreg;
typedef struct Status Status;

struct Lreg
{
	u32int	fs;
	u32int	es;
	u32int	ds;
	u32int	edi;
	u32int	esi;
	u32int	ebp;
	u32int	isp;
	u32int	ebx;
	u32int	edx;
	u32int	ecx;
	u32int	eax;
	u32int	trapno;
	u32int	err;
	u32int	eip;
	u32int	cs;
	u32int	eflags;
	u32int	esp;
	u32int	ss;
	u32int	gs;
};

struct Status
{
    u32int		version;	/* Version number of struct (1) */
    u32int		statussz;	/* sizeof(prstatus_t) (1) */
    u32int		gregsetsz;	/* sizeof(gregset_t) (1) */
    u32int		fpregsetsz;	/* sizeof(fpregset_t) (1) */
    u32int		osreldate;	/* Kernel version (1) */
    u32int		cursig;	/* Current signal (1) */
    u32int		pid;		/* Process ID (1) */
    Lreg		reg;		/* General purpose registers (1) */
};

int
coreregsfreebsd386(Elf *elf, ElfNote *note, uchar **up)
{
	Status *s;
	Lreg *l;
	Ureg *u;

	if(note->descsz < sizeof(Status)){
		werrstr("elf status note too small");
		return -1;
	}
	s = (Status*)note->desc;
	if(s->version != 1){
		werrstr("unknown status version %ud", (uint)s->version);
		return -1;
	}
	l = &s->reg;
	u = malloc(sizeof(Ureg));
	if(u == nil)
		return -1;

	/* no byte order problems - just copying and rearranging */
	u->di = l->edi;
	u->si = l->esi;
	u->bp = l->ebp;
	u->nsp = l->esp;
	u->bx = l->ebx;
	u->dx = l->edx;
	u->cx = l->ecx;
	u->ax = l->eax;
	u->gs = l->gs;
	u->fs = l->fs;
	u->es = l->es;
	u->ds = l->ds;
	u->trap = l->trapno;
	u->ecode = l->err;
	u->pc = l->eip;
	u->cs = l->cs;
	u->flags = l->eflags;
	u->sp = l->esp;
	u->ss = l->ss;
	*up = (uchar*)u;
	return sizeof(Ureg);
}