Skip to content

Commit

Permalink
fix arm64 thunk and test unit (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
fesily committed May 5, 2023
1 parent 105e34b commit 01ee541
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/build/
/extension/package.json
.DS_Store
.idea/
5 changes: 5 additions & 0 deletions compile/test/make.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
local lm = require "luamake"
local platform = require 'bee.platform'

lm.builddir = ("build/test/%s"):format(lm.mode)

if not lm.runtime_platform then
lm.runtime_platform = lm.os..'-'..platform.Arch
end

local arch = lm.arch
if not arch then
arch = lm.runtime_platform:match "[%w]+-([%w]+)"
Expand Down
6 changes: 0 additions & 6 deletions src/luadebug/thunk/thunk_arm64.inl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ struct thunkblock_arg2 {
intptr_t realfn;
};
struct thunkblock_arg3 {
unsigned int mov_x3_x2;
unsigned int mov_x2_x1;
unsigned int mov_x1_x0;
unsigned int ldr_x0_0x0c;
unsigned int ldr_x4_0x10;
unsigned int br_x4;
Expand Down Expand Up @@ -59,9 +56,6 @@ thunk *thunk_create_allocf(intptr_t dbg, intptr_t allocf) {
// return `allocf`(`dbg`, ptr, osize, nsize);
// }
thunkblock_arg3 thunkblock;
thunkblock.mov_x3_x2 = 0xAA0203E3; // mov x3,x2
thunkblock.mov_x2_x1 = 0xAA0103E2; // mov x2,x1
thunkblock.mov_x1_x0 = 0xAA0003E1; // mov x1,x0
thunkblock.ldr_x0_0x0c = 0x58000060; // ldr x0,#0xc
thunkblock.ldr_x4_0x10 = 0x58000084; // ldr x4,#0x10
thunkblock.br_x4 = 0xD61F0080; // br x3
Expand Down
1 change: 1 addition & 0 deletions src/process_inject/macos/injectdll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/sysctl.h>

#include <cstddef> // for ptrdiff_t
#include <cassert>
// for mmap()
#include <dlfcn.h>
#include <pthread_spis.h>
Expand Down
6 changes: 3 additions & 3 deletions test/thunk.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "thunk/thunk.h"
#include "thunk/thunk.cpp"

#include <assert.h>
struct HHI {
Expand All @@ -17,7 +17,7 @@ void* add1(HHI* h, void* a, size_t b, size_t c) {
assert(a == (void*)0x1);
assert(b == 2);
assert(c == 3);
return nullptr;
return (void*)4;
}

int main() {
Expand All @@ -30,7 +30,7 @@ int main() {
auto* thunk1 = thunk_create_allocf((intptr_t)&hhi, (intptr_t)&add1);
auto ret1 = ((void* (*)(void* a, size_t b, size_t c))thunk1->data)((void*)0x1, 2, 3);
assert(hhi.a == 3);
assert(ret1 == nullptr);
assert(ret1 == (void*)4);

return 0;
}

0 comments on commit 01ee541

Please sign in to comment.