diff --git a/source/amx/amx.c b/source/amx/amx.c index 675576f..3331d30 100644 --- a/source/amx/amx.c +++ b/source/amx/amx.c @@ -484,26 +484,28 @@ int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, const cell *params) if ((amx->flags & AMX_FLAG_JITC)!=0) assert(amx->sysreq_d==0); #endif - if (amx->sysreq_d!=0) { - /* at the point of the call, the CIP pseudo-register points directly - * behind the SYSREQ instruction and its parameter(s) - */ - unsigned char *code=amx->base+(int)hdr->cod+(int)amx->cip-sizeof(cell); - assert(amx->cip >= 4 && amx->cip < (hdr->dat - hdr->cod)); - assert_static(sizeof(f)<=sizeof(cell)); /* function pointer must fit in a cell */ - if (amx->flags & AMX_FLAG_SYSREQN) /* SYSREQ.N has 2 parameters */ - code-=sizeof(cell); -#if defined __GNUC__ || defined __ICC || defined ASM32 - if (*(cell*)code==index) { -#else - if (*(cell*)code!=OP_SYSREQ_PRI) { - assert(*(cell*)(code-sizeof(cell))==OP_SYSREQ_C || *(cell*)(code-sizeof(cell))==OP_SYSREQ_N); - assert(*(cell*)code==index); -#endif - *(cell*)(code-sizeof(cell))=amx->sysreq_d; - *(cell*)code=(cell)f; + #if PAWN_POINTER_SIZE <= PAWN_CELL_SIZE + if (amx->sysreq_d!=0) { + /* at the point of the call, the CIP pseudo-register points directly + * behind the SYSREQ instruction and its parameter(s) + */ + unsigned char *code=amx->base+(int)hdr->cod+(int)amx->cip-sizeof(cell); + assert(amx->cip >= 4 && amx->cip < (hdr->dat - hdr->cod)); + assert_static(sizeof(f)<=sizeof(cell)); /* function pointer must fit in a cell */ + if (amx->flags & AMX_FLAG_SYSREQN) /* SYSREQ.N has 2 parameters */ + code-=sizeof(cell); + #if defined __GNUC__ || defined __ICC || defined ASM32 + if (*(cell*)code==index) { + #else + if (*(cell*)code!=OP_SYSREQ_PRI) { + assert(*(cell*)(code-sizeof(cell))==OP_SYSREQ_C || *(cell*)(code-sizeof(cell))==OP_SYSREQ_N); + assert(*(cell*)code==index); + #endif + *(cell*)(code-sizeof(cell))=amx->sysreq_d; + *(cell*)code=(cell)f; + } /* if */ } /* if */ - } /* if */ + #endif /* Note: * params[0] == number of bytes for the additional parameters passed to the native function diff --git a/source/amx/amx.h b/source/amx/amx.h index 022d751..2cbe3d4 100644 --- a/source/amx/amx.h +++ b/source/amx/amx.h @@ -178,6 +178,16 @@ extern "C" { #error Unsupported cell size (PAWN_CELL_SIZE) #endif +#if !defined PAWN_POINTER_SIZE + #if INTPTR_MAX==INT64_MAX + #define PAWN_POINTER_SIZE 64 + #elif INTPTR_MAX==INT32_MAX + #define PAWN_POINTER_SIZE 32 + #else + #error Unknown pointer size + #endif +#endif + #define UNPACKEDMAX (((cell)1 << (sizeof(cell)-1)*8) - 1) #define UNLIMITED (~1u >> 1) diff --git a/source/compiler/CMakeLists.txt b/source/compiler/CMakeLists.txt index b2aa8a9..f1e6c3b 100644 --- a/source/compiler/CMakeLists.txt +++ b/source/compiler/CMakeLists.txt @@ -44,6 +44,12 @@ if(HAVE_STRLCAT) add_definitions(-DHAVE_STRLCAT) endif() +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + add_definitions(-DPAWN_POINTER_SIZE=32) +elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) + add_definitions(-DPAWN_POINTER_SIZE=64) +endif() + if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE) if(MSVC LESS 1900) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index a418350..9a8cfef 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -52,7 +52,7 @@ #if !defined __x86_64__ && !defined __amd64__ && (__GNUC__>=4 || __GNUC__==3 && __GNUC_MINOR__>=4) #define SC_FASTCALL __attribute__((fastcall)) #else - #define SC_FASTCALL __attribute__((regparam(3))) + #define SC_FASTCALL __attribute__((regparm(3))) #endif #endif #if !defined SC_FASTCALL