Fix a few 64-bit build issues

This commit is contained in:
Zeex 2019-06-10 11:50:11 +06:00
parent 4c0536989e
commit b6aa92232f
4 changed files with 38 additions and 20 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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