History

x86_64 bound checking failure

The code: void mul(double *p) { *p *= 2.0; } failed on x86_64 because register was not loaded after bound checking call. Also printed size when pointer indir failes.

herman ten brugge committed 1 year ago

Commit 087cf2e1 parent fa979545 files · +15 −3Browse files

Unified · Split

5 files
  1. lib/bcheck.c +3 −2
  2. tests/tests2/126_bound_global.expect +1 −1
  3. tests/tests2/132_bound_test.c +8 −0
  4. tests/tests2/132_bound_test.expect +1 −0
  5. x86_64-gen.c +2 −0
lib/bcheck.c+3−2
@@ -588,8 +588,9 @@ void * __bound_ptr_indir ## dsize (void *p, size_t offset) \ · 587 unmodified lines
588 if (addr <= tree->size) { \588 if (addr <= tree->size) { \
589 if (tree->is_invalid || addr + offset + dsize > tree->size) { \589 if (tree->is_invalid || addr + offset + dsize > tree->size) { \
590 POST_SEM (); \590 POST_SEM (); \
591 bound_warning("%p is outside of the region (0x%lx..0x%lx)", \591 bound_warning("%p (size %d) is outside of the region " \
592 p + offset, (long)tree->start, \592 "(0x%lx..0x%lx)", \
593 p + offset, dsize, (long)tree->start, \
593 (long)(tree->start + tree->size - 1)); \594 (long)(tree->start + tree->size - 1)); \
594 if (never_fatal <= 0) \595 if (never_fatal <= 0) \
595 return INVALID_POINTER; /* return an invalid pointer */ \596 return INVALID_POINTER; /* return an invalid pointer */ \
tests/tests2/126_bound_global.expect+1−1
@@ -1,2 +1,2 @@
1126_bound_global.c:11: at main: BCHECK: ........ is outside of the region (..................)1126_bound_global.c:11: at main: BCHECK: ........ (size 4) is outside of the region (..................)
2126_bound_global.c:11: at main: RUNTIME ERROR: invalid memory access2126_bound_global.c:11: at main: RUNTIME ERROR: invalid memory access
tests/tests2/132_bound_test.c+8−0
@@ -21,9 +21,17 @@ double scale(double d) · 20 unmodified lines
21 return x.d;21 return x.d;
22}22}
23 23
24void mul(double *p)
25{
26 *p *= 2.0;
27}
28
24int29int
25main(void)30main(void)
26{31{
32 double d = 4.0;
27 printf("%g\n", scale(42));33 printf("%g\n", scale(42));
34 mul(&d);
35 printf("%g\n", d);
28 return 0;36 return 0;
29}37}
tests/tests2/132_bound_test.expect+1−0
@@ -1 +1,2 @@
142000142000
28
x86_64-gen.c+2−0
@@ -120,6 +120,7 @@ ST_FUNC void gen_struct_copy(int size); · 119 unmodified lines
120 120
121ST_DATA const char * const target_machine_defs =121ST_DATA const char * const target_machine_defs =
122 "__x86_64__\0"122 "__x86_64__\0"
123 "__x86_64\0"
123 "__amd64__\0"124 "__amd64__\0"
124 ;125 ;
125 126
@@ -2020,6 +2021,7 @@ void gen_opf(int op) · 1894 unmodified lines
2020 gv(RC_FLOAT);2021 gv(RC_FLOAT);
2021 vswap();2022 vswap();
2022 fc = vtop->c.i; /* bcheck may have saved previous vtop[-1] */2023 fc = vtop->c.i; /* bcheck may have saved previous vtop[-1] */
2024 r = vtop->r;
2023 }2025 }
2024 2026
2025 if ((ft & VT_BTYPE) == VT_DOUBLE) {2027 if ((ft & VT_BTYPE) == VT_DOUBLE) {

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