1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * Dwarf address ranges parsing code.
3*c2c66affSColin Finck */
4*c2c66affSColin Finck
5*c2c66affSColin Finck #include <ntddk.h>
6*c2c66affSColin Finck #include <reactos/rossym.h>
7*c2c66affSColin Finck #include "rossympriv.h"
8*c2c66affSColin Finck #include <ntimage.h>
9*c2c66affSColin Finck
10*c2c66affSColin Finck #define NDEBUG
11*c2c66affSColin Finck #include <debug.h>
12*c2c66affSColin Finck
13*c2c66affSColin Finck #include "dwarf.h"
14*c2c66affSColin Finck
15*c2c66affSColin Finck int
dwarfaddrtounit(Dwarf * d,ulong addr,ulong * unit)16*c2c66affSColin Finck dwarfaddrtounit(Dwarf *d, ulong addr, ulong *unit)
17*c2c66affSColin Finck {
18*c2c66affSColin Finck DwarfBuf b;
19*c2c66affSColin Finck int segsize, i;
20*c2c66affSColin Finck ulong len, id, off, base, size;
21*c2c66affSColin Finck uchar *start, *end;
22*c2c66affSColin Finck
23*c2c66affSColin Finck memset(&b, 0, sizeof b);
24*c2c66affSColin Finck b.d = d;
25*c2c66affSColin Finck b.p = d->aranges.data;
26*c2c66affSColin Finck b.ep = b.p + d->aranges.len;
27*c2c66affSColin Finck
28*c2c66affSColin Finck while(b.p < b.ep){
29*c2c66affSColin Finck start = b.p;
30*c2c66affSColin Finck len = dwarfget4(&b);
31*c2c66affSColin Finck if (!len) { b.ep = b.p - 4; return -1; }
32*c2c66affSColin Finck if((id = dwarfget2(&b)) != 2){
33*c2c66affSColin Finck if(b.p == nil){
34*c2c66affSColin Finck underflow:
35*c2c66affSColin Finck werrstr("buffer underflow reading address ranges header");
36*c2c66affSColin Finck }else
37*c2c66affSColin Finck werrstr("bad dwarf version 0x%x in address ranges header", id);
38*c2c66affSColin Finck return -1;
39*c2c66affSColin Finck }
40*c2c66affSColin Finck off = dwarfget4(&b);
41*c2c66affSColin Finck b.addrsize = dwarfget1(&b);
42*c2c66affSColin Finck if(d->addrsize == 0)
43*c2c66affSColin Finck d->addrsize = b.addrsize;
44*c2c66affSColin Finck segsize = dwarfget1(&b);
45*c2c66affSColin Finck USED(segsize); /* what am i supposed to do with this? */
46*c2c66affSColin Finck if(b.p == nil)
47*c2c66affSColin Finck goto underflow;
48*c2c66affSColin Finck if((i = (b.p-start) % (2*b.addrsize)) != 0)
49*c2c66affSColin Finck b.p += 2*b.addrsize - i;
50*c2c66affSColin Finck end = start+4+len;
51*c2c66affSColin Finck while(b.p!=nil && b.p<end){
52*c2c66affSColin Finck base = dwarfgetaddr(&b);
53*c2c66affSColin Finck size = dwarfgetaddr(&b);
54*c2c66affSColin Finck if (!size) continue;
55*c2c66affSColin Finck if(b.p == nil)
56*c2c66affSColin Finck goto underflow;
57*c2c66affSColin Finck if(base <= addr && addr < base+size){
58*c2c66affSColin Finck *unit = off;
59*c2c66affSColin Finck return 0;
60*c2c66affSColin Finck }
61*c2c66affSColin Finck }
62*c2c66affSColin Finck if(b.p == nil)
63*c2c66affSColin Finck goto underflow;
64*c2c66affSColin Finck b.p = end;
65*c2c66affSColin Finck }
66*c2c66affSColin Finck werrstr("address 0x%lux is not listed in dwarf debugging symbols", addr);
67*c2c66affSColin Finck return -1;
68*c2c66affSColin Finck }
69*c2c66affSColin Finck
70*c2c66affSColin Finck
71