| @@ -127,15 +127,7 @@ static int rt_mem(TCCState *s1, int size) · 126 unmodified lines |
| 127 | 127 | ptr_diff = (char*)prw - (char*)ptr; /* = size; */ |
| 128 | 128 | //printf("map %p %p %p\n", ptr, prw, (void*)ptr_diff); |
| 129 | 129 | #else |
| 130 | | −# if !CONFIG_RUNMEM_ALIGNED |
| 131 | | − ptr = tcc_malloc(size += PAGESIZE); |
| 132 | | −# elif _WIN32 |
| 133 | | − ptr = _aligned_malloc(size, PAGESIZE); |
| 134 | | −# else |
| 135 | | − ptr = memalign(PAGESIZE, size); |
| 136 | | −# endif |
| 137 | | − if (NULL == ptr) |
| 138 | | − return tcc_error_noabort("tccrun: could not allocate memory"); |
| 130 | + ptr = tcc_malloc(size += PAGESIZE); /* one extra page to align malloc memory */ |
| 139 | 131 | #endif |
| 140 | 132 | s1->run_ptr = ptr; |
| 141 | 133 | s1->run_size = size; |
| @@ -200,13 +192,7 @@ ST_FUNC void tcc_run_free(TCCState *s1) · 58 unmodified lines |
| 200 | 192 | # ifdef _WIN64 |
| 201 | 193 | win64_del_function_table(s1->run_function_table); |
| 202 | 194 | # endif |
| 203 | | −# if !CONFIG_RUNMEM_ALIGNED |
| 204 | 195 | tcc_free(ptr); |
| 205 | | −# elif _WIN32 |
| 206 | | − _aligned_free(ptr); |
| 207 | | −# else |
| 208 | | − libc_free(ptr); |
| 209 | | −# endif |
| 210 | 196 | #endif |
| 211 | 197 | } |
| 212 | 198 | |
| @@ -300,7 +286,7 @@ static void cleanup_sections(TCCState *s1) · 87 unmodified lines |
| 300 | 286 | /* 0 = .text rwx other rw */ |
| 301 | 287 | /* 1 = .text rx .rdata r .data/.bss rw */ |
| 302 | 288 | #ifndef CONFIG_RUNMEM_RO |
| 303 | | −# define CONFIG_RUNMEM_RO 1 |
| 289 | +# define CONFIG_RUNMEM_RO 0 |
| 304 | 290 | #endif |
| 305 | 291 | |
| 306 | 292 | /* relocate code. Return -1 on error, required size if ptr is NULL, |
| @@ -377,7 +363,7 @@ redo: · 70 unmodified lines |
| 377 | 363 | align = 64; |
| 378 | 364 | #endif |
| 379 | 365 | /* start new page for different permissions */ |
| 380 | | − if (CONFIG_RUNMEM_RO || k < 2) |
| 366 | + if (CONFIG_RUNMEM_RO || k == 0) |
| 381 | 367 | align = PAGESIZE; |
| 382 | 368 | } |
| 383 | 369 | s->sh_addralign = align; |
| @@ -556,26 +542,8 @@ static void st_unlink(TCCState *s1) · 172 unmodified lines |
| 556 | 542 | rt_post_sem(); |
| 557 | 543 | } |
| 558 | 544 | |
| 559 | | −#ifdef _WIN32 |
| 560 | | −# define GETTID() GetCurrentThreadId() |
| 561 | | −#elif defined __linux__ |
| 562 | | −# define GETTID() gettid() |
| 563 | | −#elif 0 |
| 564 | | −# define GETTID() 1234 // threads not supported |
| 565 | | −#endif |
| 566 | | − |
| 567 | 545 | LIBTCCAPI void *_tcc_setjmp(TCCState *s1, void *p_jmp_buf, void *func, void *p_longjmp) |
| 568 | 546 | { |
| 569 | | −#ifdef GETTID |
| 570 | | − int tid = GETTID(); |
| 571 | | − TCCState *s; |
| 572 | | − rt_wait_sem(); |
| 573 | | − for (s = g_s1; s; s = s->next) |
| 574 | | − if (s->run_tid == tid) |
| 575 | | − s->run_tid = -1; |
| 576 | | − s1->run_tid = (int)tid; |
| 577 | | − rt_post_sem(); |
| 578 | | −#endif |
| 579 | 547 | s1->run_lj = p_longjmp; |
| 580 | 548 | s1->run_jb = p_jmp_buf; |
| 581 | 549 | #ifdef CONFIG_TCC_BACKTRACE |
| @@ -593,14 +561,6 @@ LIBTCCAPI void tcc_set_backtrace_func(TCCState *s1, void *data, TCCBtFunc *func) · 11 unmodified lines |
| 593 | 561 | |
| 594 | 562 | static TCCState *rt_find_state(rt_frame *f) |
| 595 | 563 | { |
| 596 | | −#ifdef GETTID |
| 597 | | − int tid = GETTID(); |
| 598 | | − TCCState *s; |
| 599 | | − for (s = g_s1; s; s = s->next) |
| 600 | | − if (s->run_tid == tid) |
| 601 | | − break; |
| 602 | | − return s; |
| 603 | | −#else |
| 604 | 564 | TCCState *s; |
| 605 | 565 | int level; |
| 606 | 566 | addr_t pc; |
| @@ -620,7 +580,6 @@ static TCCState *rt_find_state(rt_frame *f) · 13 unmodified lines |
| 620 | 580 | } |
| 621 | 581 | } |
| 622 | 582 | return NULL; |
| 623 | | −#endif |
| 624 | 583 | } |
| 625 | 584 | |
| 626 | 585 | static void rt_exit(rt_frame *f, int code) |