-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsegment.d
56 lines (51 loc) · 1.02 KB
/
segment.d
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
import std.exception;
import std.stdio;
import section;
enum SegmentType
{
Import,
Export,
Text,
TLS,
Data,
Const,
BSS,
Reloc,
Debug,
}
final class Segment
{
SegmentType type;
uint base;
uint length;
uint fileOffset;
CombinedSection[] members;
ubyte[] data;
size_t segid;
this(SegmentType type, uint base, uint fileOffset)
{
this.type = type;
this.base = base;
this.fileOffset = fileOffset;
}
void append(CombinedSection sec)
{
members ~= sec;
sec.seg = this;
sec.setBase(base + length);
length += sec.length;
}
void allocate(uint segAlign)
{
data.length = (length + segAlign - 1) & ~(segAlign - 1);
foreach(sec; members)
{
auto rbase = sec.base-base;
sec.allocate(data[rbase..rbase+sec.length]);
}
}
void dump()
{
writefln("Segment: (%s) 0x%.8X -> 0x%.8X (0x%.8X)", type, base, base + length, length);
}
}