History

tccrun: resign from "advanced" system calls (memaligh/gettid)

... let's stay compatible

grischka committed 2 years ago

Commit 4e91d381 parent d2f8cea4 files · +5 −49Browse files

Unified · Split

4 files
  1. libtcc.c +1 −1
  2. libtcc.h +1 −3
  3. tcc.h +0 −1
  4. tccrun.c +3 −44
libtcc.c+1−1
@@ -242,7 +242,7 @@ static void *(*reallocator)(void*, unsigned long) = default_reallocator; · 241 unmodified lines
242 242
243LIBTCCAPI void tcc_set_realloc(TCCReallocFunc *realloc)243LIBTCCAPI void tcc_set_realloc(TCCReallocFunc *realloc)
244{244{
245 reallocator = realloc;245 reallocator = realloc ? realloc : default_reallocator;
246}246}
247 247
248/* in case MEM_DEBUG is #defined */248/* in case MEM_DEBUG is #defined */
libtcc.h+1−3
@@ -10,13 +10,11 @@ extern "C" { · 9 unmodified lines
10#endif10#endif
11 11
12/*****************************/12/*****************************/
13/* set custom allocator for all allocations (optional) */13/* set custom allocator for all allocations (optional), NULL for default. */
14
15typedef void *TCCReallocFunc(void *ptr, unsigned long size);14typedef void *TCCReallocFunc(void *ptr, unsigned long size);
16LIBTCCAPI void tcc_set_realloc(TCCReallocFunc *my_realloc);15LIBTCCAPI void tcc_set_realloc(TCCReallocFunc *my_realloc);
17 16
18/*****************************/17/*****************************/
19
20typedef struct TCCState TCCState;18typedef struct TCCState TCCState;
21 19
22/* create a new TCC compilation context */20/* create a new TCC compilation context */
tcc.h+0−1
@@ -1005,7 +1005,6 @@ struct TCCState { · 1004 unmodified lines
1005 void *run_lj, *run_jb; /* sj/lj for tcc_setjmp()/tcc_run() */1005 void *run_lj, *run_jb; /* sj/lj for tcc_setjmp()/tcc_run() */
1006 TCCBtFunc *bt_func;1006 TCCBtFunc *bt_func;
1007 void *bt_data;1007 void *bt_data;
1008 int run_tid;
1009#endif1008#endif
1010 1009
1011#ifdef CONFIG_TCC_BACKTRACE1010#ifdef CONFIG_TCC_BACKTRACE
tccrun.c+3−44
@@ -127,15 +127,7 @@ static int rt_mem(TCCState *s1, int size) · 126 unmodified lines
127 ptr_diff = (char*)prw - (char*)ptr; /* = size; */127 ptr_diff = (char*)prw - (char*)ptr; /* = size; */
128 //printf("map %p %p %p\n", ptr, prw, (void*)ptr_diff);128 //printf("map %p %p %p\n", ptr, prw, (void*)ptr_diff);
129#else129#else
130# if !CONFIG_RUNMEM_ALIGNED130 ptr = tcc_malloc(size += PAGESIZE); /* one extra page to align malloc memory */
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");
139#endif131#endif
140 s1->run_ptr = ptr;132 s1->run_ptr = ptr;
141 s1->run_size = size;133 s1->run_size = size;
@@ -200,13 +192,7 @@ ST_FUNC void tcc_run_free(TCCState *s1) · 58 unmodified lines
200# ifdef _WIN64192# ifdef _WIN64
201 win64_del_function_table(s1->run_function_table);193 win64_del_function_table(s1->run_function_table);
202# endif194# endif
203# if !CONFIG_RUNMEM_ALIGNED
204 tcc_free(ptr);195 tcc_free(ptr);
205# elif _WIN32
206 _aligned_free(ptr);
207# else
208 libc_free(ptr);
209# endif
210#endif196#endif
211}197}
212 198
@@ -300,7 +286,7 @@ static void cleanup_sections(TCCState *s1) · 87 unmodified lines
300/* 0 = .text rwx other rw */286/* 0 = .text rwx other rw */
301/* 1 = .text rx .rdata r .data/.bss rw */287/* 1 = .text rx .rdata r .data/.bss rw */
302#ifndef CONFIG_RUNMEM_RO288#ifndef CONFIG_RUNMEM_RO
303# define CONFIG_RUNMEM_RO 1289# define CONFIG_RUNMEM_RO 0
304#endif290#endif
305 291
306/* relocate code. Return -1 on error, required size if ptr is NULL,292/* relocate code. Return -1 on error, required size if ptr is NULL,
@@ -377,7 +363,7 @@ redo: · 70 unmodified lines
377 align = 64;363 align = 64;
378#endif364#endif
379 /* start new page for different permissions */365 /* start new page for different permissions */
380 if (CONFIG_RUNMEM_RO || k < 2)366 if (CONFIG_RUNMEM_RO || k == 0)
381 align = PAGESIZE;367 align = PAGESIZE;
382 }368 }
383 s->sh_addralign = align;369 s->sh_addralign = align;
@@ -556,26 +542,8 @@ static void st_unlink(TCCState *s1) · 172 unmodified lines
556 rt_post_sem();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
567LIBTCCAPI void *_tcc_setjmp(TCCState *s1, void *p_jmp_buf, void *func, void *p_longjmp)545LIBTCCAPI 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 s1->run_lj = p_longjmp;547 s1->run_lj = p_longjmp;
580 s1->run_jb = p_jmp_buf;548 s1->run_jb = p_jmp_buf;
581#ifdef CONFIG_TCC_BACKTRACE549#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
594static TCCState *rt_find_state(rt_frame *f)562static 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 TCCState *s;564 TCCState *s;
605 int level;565 int level;
606 addr_t pc;566 addr_t pc;
@@ -620,7 +580,6 @@ static TCCState *rt_find_state(rt_frame *f) · 13 unmodified lines
620 }580 }
621 }581 }
622 return NULL;582 return NULL;
623#endif
624}583}
625 584
626static void rt_exit(rt_frame *f, int code)585static void rt_exit(rt_frame *f, int code)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t