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
588588 if (addr <= tree->size) { \
589589 if (tree->is_invalid || addr + offset + dsize > tree->size) { \
590590 POST_SEM (); \
591− bound_warning("%p is outside of the region (0x%lx..0x%lx)", \
592− p + offset, (long)tree->start, \
591+ bound_warning("%p (size %d) is outside of the region " \
592+ "(0x%lx..0x%lx)", \
593+ p + offset, dsize, (long)tree->start, \
593594 (long)(tree->start + tree->size - 1)); \
594595 if (never_fatal <= 0) \
595596 return INVALID_POINTER; /* return an invalid pointer */ \
tests/tests2/126_bound_global.expect+1−1
@@ -1,2 +1,2 @@
1−126_bound_global.c:11: at main: BCHECK: ........ is outside of the region (..................)
1+126_bound_global.c:11: at main: BCHECK: ........ (size 4) is outside of the region (..................)
22 126_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
2121 return x.d;
2222 }
2323
24+void mul(double *p)
25+{
26+ *p *= 2.0;
27+}
28+
2429 int
2530 main(void)
2631 {
32+ double d = 4.0;
2733 printf("%g\n", scale(42));
34+ mul(&d);
35+ printf("%g\n", d);
2836 return 0;
2937 }
tests/tests2/132_bound_test.expect+1−0
@@ -1 +1,2 @@
11 42000
2+8
x86_64-gen.c+2−0
@@ -120,6 +120,7 @@ ST_FUNC void gen_struct_copy(int size); · 119 unmodified lines
120120
121121 ST_DATA const char * const target_machine_defs =
122122 "__x86_64__\0"
123+ "__x86_64\0"
123124 "__amd64__\0"
124125 ;
125126
@@ -2020,6 +2021,7 @@ void gen_opf(int op) · 1894 unmodified lines
20202021 gv(RC_FLOAT);
20212022 vswap();
20222023 fc = vtop->c.i; /* bcheck may have saved previous vtop[-1] */
2024+ r = vtop->r;
20232025 }
20242026
20252027 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