mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-13 05:10:07 +08:00
Add extra locking in bound checking code
This commit is contained in:
parent
2c70652e04
commit
a83b285685
20
lib/bcheck.c
20
lib/bcheck.c
@ -257,6 +257,8 @@ void splay_printtree(Tree * t, int d);
|
||||
|
||||
/* external interface */
|
||||
void __bounds_checking (int no_check);
|
||||
void __bound_checking_lock (void);
|
||||
void __bound_checking_unlock (void);
|
||||
void __bound_never_fatal (int no_check);
|
||||
DLL_EXPORT void * __bound_ptr_add(void *p, size_t offset);
|
||||
DLL_EXPORT void * __bound_ptr_indir1(void *p, size_t offset);
|
||||
@ -445,7 +447,11 @@ int tcc_backtrace(const char *fmt, ...);
|
||||
|
||||
/* print a bound error message */
|
||||
#define bound_warning(...) \
|
||||
tcc_backtrace("^bcheck.c^BCHECK: " __VA_ARGS__)
|
||||
do { \
|
||||
WAIT_SEM (); \
|
||||
tcc_backtrace("^bcheck.c^BCHECK: " __VA_ARGS__); \
|
||||
POST_SEM (); \
|
||||
} while (0)
|
||||
|
||||
#define bound_error(...) \
|
||||
do { \
|
||||
@ -498,6 +504,16 @@ void __bounds_checking (int no_check)
|
||||
#endif
|
||||
}
|
||||
|
||||
void __bound_checking_lock(void)
|
||||
{
|
||||
WAIT_SEM ();
|
||||
}
|
||||
|
||||
void __bound_checking_unlock(void)
|
||||
{
|
||||
POST_SEM ();
|
||||
}
|
||||
|
||||
/* enable/disable checking. This can be used in signal handlers. */
|
||||
void __bound_never_fatal (int neverfatal)
|
||||
{
|
||||
@ -1264,6 +1280,7 @@ void __bound_exit_dll(size_t *p)
|
||||
dprintf(stderr, "%s, %s()\n", __FILE__, __FUNCTION__);
|
||||
|
||||
if (p) {
|
||||
WAIT_SEM ();
|
||||
while (p[0] != 0) {
|
||||
tree = splay_delete(p[0], tree);
|
||||
#if BOUND_DEBUG
|
||||
@ -1275,6 +1292,7 @@ void __bound_exit_dll(size_t *p)
|
||||
#endif
|
||||
p += 2;
|
||||
}
|
||||
POST_SEM ();
|
||||
}
|
||||
}
|
||||
|
||||
|
14
lib/bt-exe.c
14
lib/bt-exe.c
@ -7,6 +7,8 @@
|
||||
#include "../tccrun.c"
|
||||
|
||||
int (*__rt_error)(void*, void*, const char *, va_list);
|
||||
__attribute__((weak)) void __bound_checking_lock(void);
|
||||
__attribute__((weak)) void __bound_checking_unlock(void);
|
||||
|
||||
#ifndef _WIN32
|
||||
# define __declspec(n)
|
||||
@ -21,8 +23,10 @@ void __bt_init(rt_context *p, int num_callers)
|
||||
//fprintf(stderr, "__bt_init %d %p %p\n", num_callers, p->stab_sym, p->bounds_start), fflush(stderr);
|
||||
/* call __bound_init here due to redirection of sigaction */
|
||||
/* needed to add global symbols */
|
||||
if (__bound_init && p->bounds_start)
|
||||
if (p->bounds_start) {
|
||||
__bound_init(p->bounds_start, -1);
|
||||
__bound_checking_lock();
|
||||
}
|
||||
if (num_callers) {
|
||||
memcpy(rc, p, offsetof(rt_context, next));
|
||||
rc->num_callers = num_callers - 1;
|
||||
@ -32,6 +36,8 @@ void __bt_init(rt_context *p, int num_callers)
|
||||
} else {
|
||||
p->next = rc->next, rc->next = p;
|
||||
}
|
||||
if (p->bounds_start)
|
||||
__bound_checking_unlock();
|
||||
}
|
||||
|
||||
__declspec(dllexport)
|
||||
@ -40,8 +46,10 @@ void __bt_exit(rt_context *p)
|
||||
__attribute__((weak)) void __bound_exit_dll(void*);
|
||||
struct rt_context *rc = &g_rtctxt;
|
||||
|
||||
if (__bound_exit_dll && p->bounds_start)
|
||||
if (p->bounds_start) {
|
||||
__bound_exit_dll(p->bounds_start);
|
||||
__bound_checking_lock();
|
||||
}
|
||||
while (rc) {
|
||||
if (rc->next == p) {
|
||||
rc->next = rc->next->next;
|
||||
@ -49,6 +57,8 @@ void __bt_exit(rt_context *p)
|
||||
}
|
||||
rc = rc->next;
|
||||
}
|
||||
if (p->bounds_start)
|
||||
__bound_checking_unlock();
|
||||
}
|
||||
|
||||
/* copy a string and truncate it. */
|
||||
|
Loading…
Reference in New Issue
Block a user