win32: enable bounds checker & exception handler

exception handler borrowed from k1w1. Thanks.
This commit is contained in:
grischka
2009-12-19 22:22:43 +01:00
parent 8bbde91f62
commit 7fa712e00c
11 changed files with 471 additions and 381 deletions

View File

@ -2911,8 +2911,10 @@ static void indir(void)
&& (vtop->type.t & VT_BTYPE) != VT_FUNC) {
vtop->r |= lvalue_type(vtop->type.t);
/* if bound checking, the referenced pointer must be checked */
#ifdef CONFIG_TCC_BCHECK
if (tcc_state->do_bounds_check)
vtop->r |= VT_MUSTBOUND;
#endif
}
}
@ -3328,9 +3330,11 @@ static void unary(void)
/* an array is never an lvalue */
if (!(vtop->type.t & VT_ARRAY)) {
vtop->r |= lvalue_type(vtop->type.t);
#ifdef CONFIG_TCC_BCHECK
/* if bound checking, the referenced pointer must be checked */
if (tcc_state->do_bounds_check)
vtop->r |= VT_MUSTBOUND;
#endif
}
next();
} else if (tok == '[') {
@ -4702,10 +4706,13 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
}
if ((r & VT_VALMASK) == VT_LOCAL) {
sec = NULL;
#ifdef CONFIG_TCC_BCHECK
if (tcc_state->do_bounds_check && (type->t & VT_ARRAY))
loc--;
#endif
loc = (loc - size) & -align;
addr = loc;
#ifdef CONFIG_TCC_BCHECK
/* handles bounds */
/* XXX: currently, since we do only one pass, we cannot track
'&' operators, so we add only arrays */
@ -4718,6 +4725,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
bounds_ptr[0] = addr;
bounds_ptr[1] = size;
}
#endif
if (v) {
/* local variable */
sym_push(v, type, r, addr);
@ -4774,9 +4782,11 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
/* very important to increment global pointer at this time
because initializers themselves can create new initializers */
data_offset += size;
#ifdef CONFIG_TCC_BCHECK
/* add padding if bound check */
if (tcc_state->do_bounds_check)
data_offset++;
#endif
sec->data_offset = data_offset;
/* allocate section space to put the data */
if (sec->sh_type != SHT_NOBITS &&
@ -4813,7 +4823,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
vsetc(type, VT_CONST | VT_SYM, &cval);
vtop->sym = sym;
}
#ifdef CONFIG_TCC_BCHECK
/* handles bounds now because the symbol must be defined
before for the relocation */
if (tcc_state->do_bounds_check) {
@ -4825,6 +4835,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
bounds_ptr[0] = 0; /* relocated */
bounds_ptr[1] = size;
}
#endif
}
if (has_init) {
decl_initializer(type, sec, addr, 1, 0);