Skip to content

Commit

Permalink
Add support for x86 and aarch64 (not arm yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadoum committed Mar 25, 2023
1 parent 764f918 commit 110cfa7
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/provision/androidlibrary.d
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public struct AndroidLibrary {
auto alignedMaximumMemory = pageCeil(maximumMemory);

auto allocSize = alignedMaximumMemory - alignedMinimum;
allocation = MmapAllocator.instance.allocate(allocSize)[0..allocSize];
allocation = GC.malloc(allocSize)[0..allocSize];
writefln!("Allocated %1$d bytes (%1$x) of memory, at %2$x")(allocSize, allocation.ptr);

foreach (programHeader; programHeaders) {
Expand Down Expand Up @@ -118,10 +118,10 @@ public struct AndroidLibrary {
static if (__traits(hasMember, relocation, "r_addend")) {
addend = relocation.r_addend;
} else {
if (relocationType == R_GENERIC_NATIVE_ABS) {
if (relocationType == R_386_JUMP_SLOT) {
addend = 0;
} else {
addend = *cast(size_t*) (allocation.ptr + offset);
addend = *cast(size_t*) (cast(size_t) allocation.ptr + offset);
}
}
auto symbol = getSymbolImplementation(getSymbolName(dynamicSymbolTable[symbolIndex]));
Expand All @@ -130,12 +130,14 @@ public struct AndroidLibrary {

switch (relocationType) {
case R_GENERIC!"RELATIVE":
*location = cast(size_t) (allocation.ptr + addend);
*location = cast(size_t) allocation.ptr + addend;
break;
case R_GENERIC!"GLOB_DAT":
case R_GENERIC!"JUMP_SLOT":
*location = cast(size_t) (symbol + addend);
break;
case R_GENERIC!"JUMP_SLOT":
*location = cast(size_t) (symbol);
break;
case R_GENERIC_NATIVE_ABS:
*location = cast(size_t) (symbol + addend);
break;
Expand Down Expand Up @@ -167,22 +169,22 @@ package struct GnuHashTable {
}

GnuHashTableStruct table;
ulong[] bloom;
size_t[] bloom;
uint[] buckets;
uint[] chain;

this(ubyte[] tableData) {
table = *cast(GnuHashTableStruct*) tableData.ptr;
auto bucketsLocation = GnuHashTableStruct.sizeof + table.bloomSize * (ulong.sizeof / ubyte.sizeof);
auto bucketsLocation = GnuHashTableStruct.sizeof + table.bloomSize * (size_t.sizeof / ubyte.sizeof);
auto chainLocation = bucketsLocation + table.nbuckets * (uint.sizeof / ubyte.sizeof);

bloom = cast(ulong[]) tableData[GnuHashTableStruct.sizeof..bucketsLocation];
bloom = cast(size_t[]) tableData[GnuHashTableStruct.sizeof..bucketsLocation];
buckets = cast(uint[]) tableData[bucketsLocation..chainLocation];
chain = cast(uint[]) tableData[chainLocation..$];
}

static uint hash(string name) {
uint32_t h = 5381;
uint h = 5381;

foreach (c; name) {
h = (h << 5) + h + c;
Expand Down Expand Up @@ -255,6 +257,8 @@ version (X86_64) {
private enum R_GENERIC_NATIVE_ABS = R_ARM_ABS32;
}

alias R_386_JUMP_SLOT = R_386_JMP_SLOT;

template R_GENERIC(string relocationType) {
enum R_GENERIC = mixin("R_" ~ relocationArch ~ "_" ~ relocationType);
}
Expand Down

0 comments on commit 110cfa7

Please sign in to comment.