diff options
| author | Paul Eggert | 2017-12-09 13:57:38 -0800 |
|---|---|---|
| committer | Paul Eggert | 2017-12-12 15:17:12 -0800 |
| commit | 881abfc7fb55db2d00adf352100cc58a6a86c176 (patch) | |
| tree | 4bb07ccaf020ea861ce95ff4fd57bb6d2c562810 /src/alloc.c | |
| parent | 244346c744a6700d320a0a0fe8c796be3b3ff023 (diff) | |
| download | emacs-881abfc7fb55db2d00adf352100cc58a6a86c176.tar.gz emacs-881abfc7fb55db2d00adf352100cc58a6a86c176.zip | |
Port to gcc -fcheck-pointer-bounds
This is a minimal port, just to get Emacs running;
it does not attempt to make the pointer bounds at all tight.
* src/ptr-bounds.h: New file.
* src/alloc.c, src/gmalloc.c: Include it.
* src/alloc.c (live_string_holding, live_cons_holding)
(live_symbol_holding, live_misc_holding, garbage_collect_1)
(sweep_conses, sweep_floats):
* src/gmalloc.c (malloc_initialize_1, _free_internal_nolock)
(_realloc_internal_nolock):
Widen pointer bounds as necessary.
We're in a memory allocator so this is OK.
* src/lisp.h (lisp_h_XSYMBOL, make_lisp_symbol) [__CHKP__]:
Do not convert from pointer to integer and back again, so
that GCC does not lose track of pointer bounds.
(XSYMBOL) [__CHKP__ && !USE_LSB_TAG]: Now a compile-time error.
Although it's possible to support both -fcheck-pointer-bounds and
--with-wide-int, it's more work; keep things simple for now.
(DEFINE_LISP_SYMBOL) [__CHKP__]: Now a no-op, to avoid
trouble with unbounded pointers.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/alloc.c b/src/alloc.c index 38daee065ae..96b9aaa0d2d 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -33,6 +33,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 33 | #include "lisp.h" | 33 | #include "lisp.h" |
| 34 | #include "dispextern.h" | 34 | #include "dispextern.h" |
| 35 | #include "intervals.h" | 35 | #include "intervals.h" |
| 36 | #include "ptr-bounds.h" | ||
| 36 | #include "puresize.h" | 37 | #include "puresize.h" |
| 37 | #include "sheap.h" | 38 | #include "sheap.h" |
| 38 | #include "systime.h" | 39 | #include "systime.h" |
| @@ -4564,6 +4565,7 @@ live_string_holding (struct mem_node *m, void *p) | |||
| 4564 | must not be on the free-list. */ | 4565 | must not be on the free-list. */ |
| 4565 | if (0 <= offset && offset < STRING_BLOCK_SIZE * sizeof b->strings[0]) | 4566 | if (0 <= offset && offset < STRING_BLOCK_SIZE * sizeof b->strings[0]) |
| 4566 | { | 4567 | { |
| 4568 | cp = ptr_bounds_copy (cp, b); | ||
| 4567 | struct Lisp_String *s = p = cp -= offset % sizeof b->strings[0]; | 4569 | struct Lisp_String *s = p = cp -= offset % sizeof b->strings[0]; |
| 4568 | if (s->u.s.data) | 4570 | if (s->u.s.data) |
| 4569 | return make_lisp_ptr (s, Lisp_String); | 4571 | return make_lisp_ptr (s, Lisp_String); |
| @@ -4598,6 +4600,7 @@ live_cons_holding (struct mem_node *m, void *p) | |||
| 4598 | && (b != cons_block | 4600 | && (b != cons_block |
| 4599 | || offset / sizeof b->conses[0] < cons_block_index)) | 4601 | || offset / sizeof b->conses[0] < cons_block_index)) |
| 4600 | { | 4602 | { |
| 4603 | cp = ptr_bounds_copy (cp, b); | ||
| 4601 | struct Lisp_Cons *s = p = cp -= offset % sizeof b->conses[0]; | 4604 | struct Lisp_Cons *s = p = cp -= offset % sizeof b->conses[0]; |
| 4602 | if (!EQ (s->u.s.car, Vdead)) | 4605 | if (!EQ (s->u.s.car, Vdead)) |
| 4603 | return make_lisp_ptr (s, Lisp_Cons); | 4606 | return make_lisp_ptr (s, Lisp_Cons); |
| @@ -4633,6 +4636,7 @@ live_symbol_holding (struct mem_node *m, void *p) | |||
| 4633 | && (b != symbol_block | 4636 | && (b != symbol_block |
| 4634 | || offset / sizeof b->symbols[0] < symbol_block_index)) | 4637 | || offset / sizeof b->symbols[0] < symbol_block_index)) |
| 4635 | { | 4638 | { |
| 4639 | cp = ptr_bounds_copy (cp, b); | ||
| 4636 | struct Lisp_Symbol *s = p = cp -= offset % sizeof b->symbols[0]; | 4640 | struct Lisp_Symbol *s = p = cp -= offset % sizeof b->symbols[0]; |
| 4637 | if (!EQ (s->u.s.function, Vdead)) | 4641 | if (!EQ (s->u.s.function, Vdead)) |
| 4638 | return make_lisp_symbol (s); | 4642 | return make_lisp_symbol (s); |
| @@ -4692,6 +4696,7 @@ live_misc_holding (struct mem_node *m, void *p) | |||
| 4692 | && (b != marker_block | 4696 | && (b != marker_block |
| 4693 | || offset / sizeof b->markers[0] < marker_block_index)) | 4697 | || offset / sizeof b->markers[0] < marker_block_index)) |
| 4694 | { | 4698 | { |
| 4699 | cp = ptr_bounds_copy (cp, b); | ||
| 4695 | union Lisp_Misc *s = p = cp -= offset % sizeof b->markers[0]; | 4700 | union Lisp_Misc *s = p = cp -= offset % sizeof b->markers[0]; |
| 4696 | if (s->u_any.type != Lisp_Misc_Free) | 4701 | if (s->u_any.type != Lisp_Misc_Free) |
| 4697 | return make_lisp_ptr (s, Lisp_Misc); | 4702 | return make_lisp_ptr (s, Lisp_Misc); |
| @@ -5955,6 +5960,7 @@ garbage_collect_1 (void *end) | |||
| 5955 | stack_copy = xrealloc (stack_copy, stack_size); | 5960 | stack_copy = xrealloc (stack_copy, stack_size); |
| 5956 | stack_copy_size = stack_size; | 5961 | stack_copy_size = stack_size; |
| 5957 | } | 5962 | } |
| 5963 | stack = ptr_bounds_set (stack, stack_size); | ||
| 5958 | no_sanitize_memcpy (stack_copy, stack, stack_size); | 5964 | no_sanitize_memcpy (stack_copy, stack, stack_size); |
| 5959 | } | 5965 | } |
| 5960 | } | 5966 | } |
| @@ -6848,7 +6854,9 @@ sweep_conses (void) | |||
| 6848 | 6854 | ||
| 6849 | for (pos = start; pos < stop; pos++) | 6855 | for (pos = start; pos < stop; pos++) |
| 6850 | { | 6856 | { |
| 6851 | if (!CONS_MARKED_P (&cblk->conses[pos])) | 6857 | struct Lisp_Cons *acons |
| 6858 | = ptr_bounds_copy (&cblk->conses[pos], cblk); | ||
| 6859 | if (!CONS_MARKED_P (acons)) | ||
| 6852 | { | 6860 | { |
| 6853 | this_free++; | 6861 | this_free++; |
| 6854 | cblk->conses[pos].u.s.u.chain = cons_free_list; | 6862 | cblk->conses[pos].u.s.u.chain = cons_free_list; |
| @@ -6858,7 +6866,7 @@ sweep_conses (void) | |||
| 6858 | else | 6866 | else |
| 6859 | { | 6867 | { |
| 6860 | num_used++; | 6868 | num_used++; |
| 6861 | CONS_UNMARK (&cblk->conses[pos]); | 6869 | CONS_UNMARK (acons); |
| 6862 | } | 6870 | } |
| 6863 | } | 6871 | } |
| 6864 | } | 6872 | } |
| @@ -6901,17 +6909,20 @@ sweep_floats (void) | |||
| 6901 | register int i; | 6909 | register int i; |
| 6902 | int this_free = 0; | 6910 | int this_free = 0; |
| 6903 | for (i = 0; i < lim; i++) | 6911 | for (i = 0; i < lim; i++) |
| 6904 | if (!FLOAT_MARKED_P (&fblk->floats[i])) | 6912 | { |
| 6905 | { | 6913 | struct Lisp_Float *afloat = ptr_bounds_copy (&fblk->floats[i], fblk); |
| 6906 | this_free++; | 6914 | if (!FLOAT_MARKED_P (afloat)) |
| 6907 | fblk->floats[i].u.chain = float_free_list; | 6915 | { |
| 6908 | float_free_list = &fblk->floats[i]; | 6916 | this_free++; |
| 6909 | } | 6917 | fblk->floats[i].u.chain = float_free_list; |
| 6910 | else | 6918 | float_free_list = &fblk->floats[i]; |
| 6911 | { | 6919 | } |
| 6912 | num_used++; | 6920 | else |
| 6913 | FLOAT_UNMARK (&fblk->floats[i]); | 6921 | { |
| 6914 | } | 6922 | num_used++; |
| 6923 | FLOAT_UNMARK (afloat); | ||
| 6924 | } | ||
| 6925 | } | ||
| 6915 | lim = FLOAT_BLOCK_SIZE; | 6926 | lim = FLOAT_BLOCK_SIZE; |
| 6916 | /* If this block contains only free floats and we have already | 6927 | /* If this block contains only free floats and we have already |
| 6917 | seen more than two blocks worth of free floats then deallocate | 6928 | seen more than two blocks worth of free floats then deallocate |