|
14 | 14 | * License for the specific language governing permissions and limitations
|
15 | 15 | * under the License.
|
16 | 16 | *
|
17 |
| - * Version: $Id: amx.c 6966 2023-07-20 18:46:01Z thiadmer $ |
| 17 | + * Version: $Id: amx.c 6973 2023-08-05 20:07:04Z thiadmer $ |
18 | 18 | */
|
19 | 19 |
|
20 | 20 | #define WIN32_LEAN_AND_MEAN
|
|
101 | 101 | #define AMX_CLONE /* amx_Clone() */
|
102 | 102 | #define AMX_EXEC /* amx_Exec() */
|
103 | 103 | #define AMX_FLAGS /* amx_Flags() */
|
104 |
| - #define AMX_INIT /* amx_Init() and amx_InitJIT() */ |
| 104 | + #define AMX_INIT /* amx_Init() */ |
| 105 | + #define AMX_JIT /* amx_InitJIT() and other JIT support */ |
105 | 106 | #define AMX_MEMINFO /* amx_MemInfo() */
|
106 | 107 | #define AMX_NAMELENGTH /* amx_NameLength() */
|
107 | 108 | #define AMX_NATIVEINFO /* amx_NativeInfo() */
|
|
146 | 147 | #define AMX_ALTCORE
|
147 | 148 | #endif
|
148 | 149 | #if !defined AMX_NO_PACKED_OPC && !defined AMX_TOKENTHREADING
|
149 |
| - #define AMX_TOKENTHREADING /* packed opcodes require token threading */ |
| 150 | + #define AMX_TOKENTHREADING /* packed opcodes require token threading (or switch threading) */ |
| 151 | +#endif |
| 152 | +#if defined AMX_DONT_RELOCATE |
| 153 | + #define AMX_TOKENTHREADING /* direct threading cannot be used when opcodes cannot be relocated */ |
150 | 154 | #endif
|
151 | 155 |
|
152 | 156 | #if defined __64BIT__
|
@@ -564,25 +568,27 @@ int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, const cell *params)
|
564 | 568 | * This trick cannot work in the JIT, because the program would need to
|
565 | 569 | * be re-JIT-compiled after patching a P-code instruction.
|
566 | 570 | */
|
567 |
| - assert((amx->flags & AMX_FLAG_JITC)==0 || amx->sysreq_d==0); |
568 |
| - if (amx->sysreq_d!=0) { |
569 |
| - /* at the point of the call, the CIP pseudo-register points directly |
570 |
| - * behind the SYSREQ(.N) instruction and its parameter(s) |
571 |
| - */ |
572 |
| - unsigned char *code=amx->code+(int)amx->cip-sizeof(cell); |
573 |
| - if (amx->flags & AMX_FLAG_SYSREQN) /* SYSREQ.N has 2 parameters */ |
574 |
| - code-=sizeof(cell); |
575 |
| - assert(amx->code!=NULL); |
576 |
| - assert(amx->cip>=4 && amx->cip<(hdr->dat - hdr->cod)); |
577 |
| - assert(sizeof(f)<=sizeof(cell)); /* function pointer must fit in a cell */ |
578 |
| - assert(*(cell*)code==index); |
579 |
| - #if defined AMX_TOKENTHREADING || !(defined __GNUC__ || defined __ICC || defined AMX_ASM || defined AMX_JIT) |
580 |
| - assert(!(amx->flags & AMX_FLAG_SYSREQN) && *(cell*)(code-sizeof(cell))==OP_SYSREQ |
581 |
| - || (amx->flags & AMX_FLAG_SYSREQN) && *(cell*)(code-sizeof(cell))==OP_SYSREQ_N); |
582 |
| - #endif |
583 |
| - *(cell*)(code-sizeof(cell))=amx->sysreq_d; |
584 |
| - *(cell*)code=(cell)(intptr_t)f; |
585 |
| - } /* if */ |
| 571 | + #if !defined AMX_DONT_RELOCATE |
| 572 | + assert((amx->flags & AMX_FLAG_JITC)==0 || amx->sysreq_d==0); |
| 573 | + if (amx->sysreq_d!=0) { |
| 574 | + /* at the point of the call, the CIP pseudo-register points directly |
| 575 | + * behind the SYSREQ(.N) instruction and its parameter(s) |
| 576 | + */ |
| 577 | + unsigned char *code=amx->code+(int)amx->cip-sizeof(cell); |
| 578 | + if (amx->flags & AMX_FLAG_SYSREQN) /* SYSREQ.N has 2 parameters */ |
| 579 | + code-=sizeof(cell); |
| 580 | + assert(amx->code!=NULL); |
| 581 | + assert(amx->cip>=4 && amx->cip<(hdr->dat - hdr->cod)); |
| 582 | + assert(sizeof(f)<=sizeof(cell)); /* function pointer must fit in a cell */ |
| 583 | + assert(*(cell*)code==index); |
| 584 | + #if defined AMX_TOKENTHREADING || !(defined __GNUC__ || defined __ICC || defined AMX_ASM || defined AMX_JIT) |
| 585 | + assert(!(amx->flags & AMX_FLAG_SYSREQN) && *(cell*)(code-sizeof(cell))==OP_SYSREQ |
| 586 | + || (amx->flags & AMX_FLAG_SYSREQN) && *(cell*)(code-sizeof(cell))==OP_SYSREQ_N); |
| 587 | + #endif |
| 588 | + *(cell*)(code-sizeof(cell))=amx->sysreq_d; |
| 589 | + *(cell*)code=(cell)(intptr_t)f; |
| 590 | + } /* if */ |
| 591 | + #endif |
586 | 592 |
|
587 | 593 | /* Note:
|
588 | 594 | * params[0] == number of bytes for the additional parameters passed to the native function
|
@@ -1334,13 +1340,13 @@ int AMXAPI amx_Init(AMX *amx,void *program)
|
1334 | 1340 | char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
|
1335 | 1341 | int ret=proc_pidpath(getpid(), pathbuf, sizeof(pathbuf));
|
1336 | 1342 | if (ret>0) {
|
1337 |
| - char ptr=strrchr(pathbuf,'/'); |
1338 |
| - assert(ptr!=NULL); |
| 1343 | + char ptr=strrchr(pathbuf,'/'); |
| 1344 | + assert(ptr!=NULL); |
1339 | 1345 | *ptr='\0';
|
1340 | 1346 | asprintf(&ptr,"%s/%s",pathbuf,libname);
|
1341 |
| - assert(ptr!=NULL); |
| 1347 | + assert(ptr!=NULL); |
1342 | 1348 | hlib=dlopen(ptr,RTLD_NOW);
|
1343 |
| - free(ptr); |
| 1349 | + free(ptr); |
1344 | 1350 | }
|
1345 | 1351 | if (hlib==NULL) {
|
1346 | 1352 | /* if failed, try to search elsewhere */
|
@@ -1457,16 +1463,6 @@ int AMXAPI amx_InitJIT(AMX *amx, void *reloc_table, void *native_code)
|
1457 | 1463 | return (res == 0) ? AMX_ERR_NONE : AMX_ERR_INIT_JIT;
|
1458 | 1464 | }
|
1459 | 1465 |
|
1460 |
| -#else /* #if defined AMX_JIT */ |
1461 |
| - |
1462 |
| -int AMXAPI amx_InitJIT(AMX *amx,void *compiled_program,void *reloc_table) |
1463 |
| -{ |
1464 |
| - (void)amx; |
1465 |
| - (void)compiled_program; |
1466 |
| - (void)reloc_table; |
1467 |
| - return AMX_ERR_INIT_JIT; |
1468 |
| -} |
1469 |
| - |
1470 | 1466 | #endif /* #if defined AMX_JIT */
|
1471 | 1467 |
|
1472 | 1468 | #endif /* AMX_INIT */
|
|
0 commit comments