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

Showing the changes to tccrun.c (1 of 4 files). Show all

Unified · Split

tccrun.c+3−44
@@ -127,15 +127,7 @@ static int rt_mem(TCCState *s1, int size) · 126 unmodified lines
127127 ptr_diff = (char*)prw - (char*)ptr; /* = size; */
128128 //printf("map %p %p %p\n", ptr, prw, (void*)ptr_diff);
129129 #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 */
139131 #endif
140132 s1->run_ptr = ptr;
141133 s1->run_size = size;
@@ -200,13 +192,7 @@ ST_FUNC void tcc_run_free(TCCState *s1) · 58 unmodified lines
200192 # ifdef _WIN64
201193 win64_del_function_table(s1->run_function_table);
202194 # endif
203−# if !CONFIG_RUNMEM_ALIGNED
204195 tcc_free(ptr);
205−# elif _WIN32
206− _aligned_free(ptr);
207−# else
208− libc_free(ptr);
209−# endif
210196 #endif
211197 }
212198
@@ -300,7 +286,7 @@ static void cleanup_sections(TCCState *s1) · 87 unmodified lines
300286 /* 0 = .text rwx other rw */
301287 /* 1 = .text rx .rdata r .data/.bss rw */
302288 #ifndef CONFIG_RUNMEM_RO
303−# define CONFIG_RUNMEM_RO 1
289+# define CONFIG_RUNMEM_RO 0
304290 #endif
305291
306292 /* relocate code. Return -1 on error, required size if ptr is NULL,
@@ -377,7 +363,7 @@ redo: · 70 unmodified lines
377363 align = 64;
378364 #endif
379365 /* start new page for different permissions */
380− if (CONFIG_RUNMEM_RO || k < 2)
366+ if (CONFIG_RUNMEM_RO || k == 0)
381367 align = PAGESIZE;
382368 }
383369 s->sh_addralign = align;
@@ -556,26 +542,8 @@ static void st_unlink(TCCState *s1) · 172 unmodified lines
556542 rt_post_sem();
557543 }
558544
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−
567545 LIBTCCAPI void *_tcc_setjmp(TCCState *s1, void *p_jmp_buf, void *func, void *p_longjmp)
568546 {
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
579547 s1->run_lj = p_longjmp;
580548 s1->run_jb = p_jmp_buf;
581549 #ifdef CONFIG_TCC_BACKTRACE
@@ -593,14 +561,6 @@ LIBTCCAPI void tcc_set_backtrace_func(TCCState *s1, void *data, TCCBtFunc *func) · 11 unmodified lines
593561
594562 static TCCState *rt_find_state(rt_frame *f)
595563 {
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
604564 TCCState *s;
605565 int level;
606566 addr_t pc;
@@ -620,7 +580,6 @@ static TCCState *rt_find_state(rt_frame *f) · 13 unmodified lines
620580 }
621581 }
622582 return NULL;
623−#endif
624583 }
625584
626585 static 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