From 0086b58f39c712f375e26fb1a35ceb8f57bb76c6 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 1 Aug 2005 02:23:42 +0000 Subject: [PATCH] Completed AMD64 compatibility --- amxmodx/natives-amd64.asm | 30 +++++++++++++++++------------- amxmodx/natives.cpp | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/amxmodx/natives-amd64.asm b/amxmodx/natives-amd64.asm index 862ea325..4846ec19 100755 --- a/amxmodx/natives-amd64.asm +++ b/amxmodx/natives-amd64.asm @@ -19,11 +19,7 @@ global amxx_DynaInit, _amxx_DynaInit ;void amxx_DynaInit(void *ptr); amxx_DynaInit: _amxx_DynaInit: - mov rax, rdi ;get pointer, first param is in rdi - lea rdi, [GLOBAL_GATE wrt rip] - mov [rdi], rax ;store - - mov rax, 1 + mov [GLOBAL_GATE wrt rip], rdi ret ;;Assembles the gateway function @@ -34,8 +30,8 @@ _amxx_DynaMake: ;we're not damaging the stack I think so we should be safe with no prologue ;save these two we're about to destroy them - push rsi ;push id - push rdi ;push buffer + push rsi ;push id + push rdi ;push buffer mov rsi, _amxx_DynaFuncStart mov rcx, _amxx_DynaFuncEnd - _amxx_DynaFuncStart @@ -45,10 +41,14 @@ _amxx_DynaMake: pop rdi ;get buffer as destination pop rax ;get id ;align us to mov rsi, 1234... - on x86-64 this is 2 bytes after the differential - add rdi, (_amxx_DynaMoveOffset-_amxx_DynaFuncStart) + 2 + add rdi, (_amxx_DynaFuncStart.move-_amxx_DynaFuncStart) + 2 mov [rdi], qword rax + ;align rdi to the call + add rdi, (_amxx_DynaFuncStart.call-_amxx_DynaFuncStart.move) + mov rax, qword [GLOBAL_GATE wrt rip] + ;copy the real address + mov [rdi], rax - mov rax, 1 ret ;;The gateway function we will re-assemble @@ -59,16 +59,18 @@ global amxx_DynaFunc, _amxx_DynaFunc amxx_DynaFunc: _amxx_DynaFunc: _amxx_DynaFuncStart: - push rbp + push rbp mov rbp, rsp ;we're given an amx and params... we're also hardcoded for this though: mov rdx, rsi ;move 2nd param to 3rd mov rsi, rdi ;move 1st param to 2nd ;this old trick, we'll move in the real pointer in a bit. -_amxx_DynaMoveOffset: - mov rsi, qword 1234567812345678h - call [GLOBAL_GATE wrt rip] ;pass through teh global gateway. +.move: + mov rdi, qword 1234567812345678h +.call: + mov rcx, qword 1234567812345678h + call rcx pop rbp ret @@ -82,6 +84,8 @@ _amxx_DynaCodesize: ; on x86 is this 17 bytes mov rax, _amxx_DynaFuncEnd - _amxx_DynaFuncStart ret + +section .data GLOBAL_GATE DQ 0 diff --git a/amxmodx/natives.cpp b/amxmodx/natives.cpp index 9b8af5dd..99df7dfb 100755 --- a/amxmodx/natives.cpp +++ b/amxmodx/natives.cpp @@ -334,7 +334,7 @@ static cell AMX_NATIVE_CALL register_native(AMX *amx, cell *params) pNative->pfn = new char[size + 10]; VirtualProtect(pNative->pfn, size+10, PAGE_EXECUTE_READWRITE, &temp); #else - pNative->pfn = (char *)memalign(sysconf(_SC_PAGESIZE), amx->code_size); + pNative->pfn = (char *)memalign(sysconf(_SC_PAGESIZE), size+10); mprotect((void *)pNative->pfn, size+10, PROT_READ|PROT_WRITE|PROT_EXEC); #endif