diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2021-09-02 20:25:58 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2021-09-02 20:25:58 +0200 |
| commit | 5d5ef75337cd4db7224d5e0cdb6da2dc96ab8224 (patch) | |
| tree | 6b6f013c09789da472917ff5e00f6bf0d2f7899b /src/tools | |
| parent | c3ef6380a7baa6457974fe2eca1652dff6808cca (diff) | |
| download | box64-5d5ef75337cd4db7224d5e0cdb6da2dc96ab8224.tar.gz box64-5d5ef75337cd4db7224d5e0cdb6da2dc96ab8224.zip | |
Add some support vor VSyscall
Diffstat (limited to 'src/tools')
| -rwxr-xr-x | src/tools/bridge.c | 44 | ||||
| -rwxr-xr-x | src/tools/bridge_private.h | 6 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/tools/bridge.c b/src/tools/bridge.c index 3fdaa2ac..5f6bb5af 100755 --- a/src/tools/bridge.c +++ b/src/tools/bridge.c @@ -203,6 +203,50 @@ void* GetNativeFncOrFnc(uintptr_t fnc) return (void*)b->f; } +// using the brdige mecanism for the VSyscall +uintptr_t AddVSyscall(bridge_t* bridge, int num) +{ + brick_t *b = NULL; + int sz = -1; + #ifdef DYNAREC + int prot = 0; + do { + #endif + pthread_mutex_lock(&my_context->mutex_bridge); + b = bridge->last; + if(b->sz == NBRICK) { + b->next = NewBrick(); + b = b->next; + bridge->last = b; + } + sz = b->sz; + #ifdef DYNAREC + pthread_mutex_unlock(&my_context->mutex_bridge); + if(box64_dynarec) { + prot=(getProtection((uintptr_t)b->b)&PROT_DYNAREC)?1:0; + if(prot) + unprotectDB((uintptr_t)b->b, NBRICK*sizeof(onebridge_t)); + else // only add DB if there is no protection + addDBFromAddressRange((uintptr_t)&b->b[b->sz].CC, sizeof(onebridge_t)); + } + } while(sz!=b->sz); // this while loop if someone took the slot when the bridge mutex was unlocked doing memory protection managment + pthread_mutex_lock(&my_context->mutex_bridge); + #endif + b->sz++; + b->b[sz].B8 = 0xB8; + b->b[sz].num = num; + b->b[sz]._0F = 0x0F; + b->b[sz]._05 = 0x05; + b->b[sz]._C3 = 0xC3; + pthread_mutex_unlock(&my_context->mutex_bridge); + #ifdef DYNAREC + if(box64_dynarec) + protectDB((uintptr_t)b->b, NBRICK*sizeof(onebridge_t)); + #endif + + return (uintptr_t)&b->b[sz].CC; +} + #ifdef HAVE_TRACE KHASH_MAP_INIT_INT64(bridgename, const char*) static kh_bridgename_t *bridgename; diff --git a/src/tools/bridge_private.h b/src/tools/bridge_private.h index 928e1e02..0983cea0 100755 --- a/src/tools/bridge_private.h +++ b/src/tools/bridge_private.h @@ -15,6 +15,12 @@ typedef union onebridge_s { uint8_t C3; // C2 or C3 ret uint16_t N; // N in case of C2 ret }; + struct { + uint8_t B8; // B8 00 11 22 33 mov rax, num + uint32_t num; + uint8_t _0F; uint8_t _05; // 0F 05 syscall + uint8_t _C3; // C3 ret + }; uint64_t dummy[4]; } onebridge_t; #pragma pack(pop) |