aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c52
1 files changed, 18 insertions, 34 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 12f53bdd6d8..738a35ce715 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -34,7 +34,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
34#include "bignum.h" 34#include "bignum.h"
35#include "dispextern.h" 35#include "dispextern.h"
36#include "intervals.h" 36#include "intervals.h"
37#include "ptr-bounds.h"
38#include "puresize.h" 37#include "puresize.h"
39#include "sheap.h" 38#include "sheap.h"
40#include "sysstdio.h" 39#include "sysstdio.h"
@@ -1624,8 +1623,7 @@ static struct Lisp_String *string_free_list;
1624 a pointer to the `u.data' member of its sdata structure; the 1623 a pointer to the `u.data' member of its sdata structure; the
1625 structure starts at a constant offset in front of that. */ 1624 structure starts at a constant offset in front of that. */
1626 1625
1627#define SDATA_OF_STRING(S) ((sdata *) ptr_bounds_init ((S)->u.s.data \ 1626#define SDATA_OF_STRING(S) ((sdata *) ((S)->u.s.data - SDATA_DATA_OFFSET))
1628 - SDATA_DATA_OFFSET))
1629 1627
1630 1628
1631#ifdef GC_CHECK_STRING_OVERRUN 1629#ifdef GC_CHECK_STRING_OVERRUN
@@ -1799,7 +1797,7 @@ allocate_string (void)
1799 /* Every string on a free list should have NULL data pointer. */ 1797 /* Every string on a free list should have NULL data pointer. */
1800 s->u.s.data = NULL; 1798 s->u.s.data = NULL;
1801 NEXT_FREE_LISP_STRING (s) = string_free_list; 1799 NEXT_FREE_LISP_STRING (s) = string_free_list;
1802 string_free_list = ptr_bounds_clip (s, sizeof *s); 1800 string_free_list = s;
1803 } 1801 }
1804 } 1802 }
1805 1803
@@ -1908,7 +1906,7 @@ allocate_string_data (struct Lisp_String *s,
1908 1906
1909 MALLOC_UNBLOCK_INPUT; 1907 MALLOC_UNBLOCK_INPUT;
1910 1908
1911 s->u.s.data = ptr_bounds_clip (SDATA_DATA (data), nbytes + 1); 1909 s->u.s.data = SDATA_DATA (data);
1912#ifdef GC_CHECK_STRING_BYTES 1910#ifdef GC_CHECK_STRING_BYTES
1913 SDATA_NBYTES (data) = nbytes; 1911 SDATA_NBYTES (data) = nbytes;
1914#endif 1912#endif
@@ -2036,7 +2034,7 @@ sweep_strings (void)
2036 2034
2037 /* Put the string on the free-list. */ 2035 /* Put the string on the free-list. */
2038 NEXT_FREE_LISP_STRING (s) = string_free_list; 2036 NEXT_FREE_LISP_STRING (s) = string_free_list;
2039 string_free_list = ptr_bounds_clip (s, sizeof *s); 2037 string_free_list = s;
2040 ++nfree; 2038 ++nfree;
2041 } 2039 }
2042 } 2040 }
@@ -2044,7 +2042,7 @@ sweep_strings (void)
2044 { 2042 {
2045 /* S was on the free-list before. Put it there again. */ 2043 /* S was on the free-list before. Put it there again. */
2046 NEXT_FREE_LISP_STRING (s) = string_free_list; 2044 NEXT_FREE_LISP_STRING (s) = string_free_list;
2047 string_free_list = ptr_bounds_clip (s, sizeof *s); 2045 string_free_list = s;
2048 ++nfree; 2046 ++nfree;
2049 } 2047 }
2050 } 2048 }
@@ -2171,8 +2169,7 @@ compact_small_strings (void)
2171 { 2169 {
2172 eassert (tb != b || to < from); 2170 eassert (tb != b || to < from);
2173 memmove (to, from, size + GC_STRING_EXTRA); 2171 memmove (to, from, size + GC_STRING_EXTRA);
2174 to->string->u.s.data 2172 to->string->u.s.data = SDATA_DATA (to);
2175 = ptr_bounds_clip (SDATA_DATA (to), nbytes + 1);
2176 } 2173 }
2177 2174
2178 /* Advance past the sdata we copied to. */ 2175 /* Advance past the sdata we copied to. */
@@ -2959,7 +2956,6 @@ Lisp_Object zero_vector;
2959static void 2956static void
2960setup_on_free_list (struct Lisp_Vector *v, ptrdiff_t nbytes) 2957setup_on_free_list (struct Lisp_Vector *v, ptrdiff_t nbytes)
2961{ 2958{
2962 v = ptr_bounds_clip (v, nbytes);
2963 eassume (header_size <= nbytes); 2959 eassume (header_size <= nbytes);
2964 ptrdiff_t nwords = (nbytes - header_size) / word_size; 2960 ptrdiff_t nwords = (nbytes - header_size) / word_size;
2965 XSETPVECTYPESIZE (v, PVEC_FREE, 0, nwords); 2961 XSETPVECTYPESIZE (v, PVEC_FREE, 0, nwords);
@@ -3327,7 +3323,7 @@ allocate_vectorlike (ptrdiff_t len, bool clearit)
3327 3323
3328 MALLOC_UNBLOCK_INPUT; 3324 MALLOC_UNBLOCK_INPUT;
3329 3325
3330 return ptr_bounds_clip (p, nbytes); 3326 return p;
3331} 3327}
3332 3328
3333 3329
@@ -4481,7 +4477,6 @@ live_string_holding (struct mem_node *m, void *p)
4481 must not be on the free-list. */ 4477 must not be on the free-list. */
4482 if (0 <= offset && offset < sizeof b->strings) 4478 if (0 <= offset && offset < sizeof b->strings)
4483 { 4479 {
4484 cp = ptr_bounds_copy (cp, b);
4485 struct Lisp_String *s = p = cp -= offset % sizeof b->strings[0]; 4480 struct Lisp_String *s = p = cp -= offset % sizeof b->strings[0];
4486 if (s->u.s.data) 4481 if (s->u.s.data)
4487 return s; 4482 return s;
@@ -4514,7 +4509,6 @@ live_cons_holding (struct mem_node *m, void *p)
4514 && (b != cons_block 4509 && (b != cons_block
4515 || offset / sizeof b->conses[0] < cons_block_index)) 4510 || offset / sizeof b->conses[0] < cons_block_index))
4516 { 4511 {
4517 cp = ptr_bounds_copy (cp, b);
4518 struct Lisp_Cons *s = p = cp -= offset % sizeof b->conses[0]; 4512 struct Lisp_Cons *s = p = cp -= offset % sizeof b->conses[0];
4519 if (!deadp (s->u.s.car)) 4513 if (!deadp (s->u.s.car))
4520 return s; 4514 return s;
@@ -4548,7 +4542,6 @@ live_symbol_holding (struct mem_node *m, void *p)
4548 && (b != symbol_block 4542 && (b != symbol_block
4549 || offset / sizeof b->symbols[0] < symbol_block_index)) 4543 || offset / sizeof b->symbols[0] < symbol_block_index))
4550 { 4544 {
4551 cp = ptr_bounds_copy (cp, b);
4552 struct Lisp_Symbol *s = p = cp -= offset % sizeof b->symbols[0]; 4545 struct Lisp_Symbol *s = p = cp -= offset % sizeof b->symbols[0];
4553 if (!deadp (s->u.s.function)) 4546 if (!deadp (s->u.s.function))
4554 return s; 4547 return s;
@@ -4645,7 +4638,7 @@ mark_maybe_object (Lisp_Object obj)
4645#endif 4638#endif
4646 4639
4647 int type_tag = XTYPE (obj); 4640 int type_tag = XTYPE (obj);
4648 intptr_t offset; 4641 intptr_t pointer_word_tag = LISP_WORD_TAG (type_tag), offset, ipo;
4649 4642
4650 switch (type_tag) 4643 switch (type_tag)
4651 { 4644 {
@@ -4661,16 +4654,8 @@ mark_maybe_object (Lisp_Object obj)
4661 break; 4654 break;
4662 } 4655 }
4663 4656
4664 bool overflow 4657 INT_ADD_WRAPV ((intptr_t) XLP (obj), offset - pointer_word_tag, &ipo);
4665 = INT_SUBTRACT_WRAPV (offset, LISP_WORD_TAG (type_tag), &offset); 4658 void *po = (void *) ipo;
4666#if !defined WIDE_EMACS_INT || USE_LSB_TAG
4667 /* If we don't use wide integers, then `intptr_t' should always be
4668 large enough to not overflow. Furthermore, when using the least
4669 significant bits as tag bits, the tag is small enough to not
4670 overflow either. */
4671 eassert (!overflow);
4672#endif
4673 void *po = (char *) ((intptr_t) (char *) XLP (obj) + offset);
4674 4659
4675 /* If the pointer is in the dump image and the dump has a record 4660 /* If the pointer is in the dump image and the dump has a record
4676 of the object starting at the place where the pointer points, we 4661 of the object starting at the place where the pointer points, we
@@ -4873,7 +4858,7 @@ mark_memory (void const *start, void const *end)
4873 4858
4874 for (pp = start; (void const *) pp < end; pp += GC_POINTER_ALIGNMENT) 4859 for (pp = start; (void const *) pp < end; pp += GC_POINTER_ALIGNMENT)
4875 { 4860 {
4876 char *p = *(char *const *) pp; 4861 void *p = *(void *const *) pp;
4877 mark_maybe_pointer (p); 4862 mark_maybe_pointer (p);
4878 4863
4879 /* Unmask any struct Lisp_Symbol pointer that make_lisp_symbol 4864 /* Unmask any struct Lisp_Symbol pointer that make_lisp_symbol
@@ -4881,8 +4866,9 @@ mark_memory (void const *start, void const *end)
4881 On a host with 32-bit pointers and 64-bit Lisp_Objects, 4866 On a host with 32-bit pointers and 64-bit Lisp_Objects,
4882 a Lisp_Object might be split into registers saved into 4867 a Lisp_Object might be split into registers saved into
4883 non-adjacent words and P might be the low-order word's value. */ 4868 non-adjacent words and P might be the low-order word's value. */
4884 p = (char *) ((uintptr_t) p + (uintptr_t) lispsym); 4869 intptr_t ip;
4885 mark_maybe_pointer (p); 4870 INT_ADD_WRAPV ((intptr_t) p, (intptr_t) lispsym, &ip);
4871 mark_maybe_pointer ((void *) ip);
4886 4872
4887 verify (alignof (Lisp_Object) % GC_POINTER_ALIGNMENT == 0); 4873 verify (alignof (Lisp_Object) % GC_POINTER_ALIGNMENT == 0);
4888 if (alignof (Lisp_Object) == GC_POINTER_ALIGNMENT 4874 if (alignof (Lisp_Object) == GC_POINTER_ALIGNMENT
@@ -5261,7 +5247,7 @@ pure_alloc (size_t size, int type)
5261 pure_bytes_used = pure_bytes_used_lisp + pure_bytes_used_non_lisp; 5247 pure_bytes_used = pure_bytes_used_lisp + pure_bytes_used_non_lisp;
5262 5248
5263 if (pure_bytes_used <= pure_size) 5249 if (pure_bytes_used <= pure_size)
5264 return ptr_bounds_clip (result, size); 5250 return result;
5265 5251
5266 /* Don't allocate a large amount here, 5252 /* Don't allocate a large amount here,
5267 because it might get mmap'd and then its address 5253 because it might get mmap'd and then its address
@@ -5352,7 +5338,7 @@ find_string_data_in_pure (const char *data, ptrdiff_t nbytes)
5352 /* Check the remaining characters. */ 5338 /* Check the remaining characters. */
5353 if (memcmp (data, non_lisp_beg + start, nbytes) == 0) 5339 if (memcmp (data, non_lisp_beg + start, nbytes) == 0)
5354 /* Found. */ 5340 /* Found. */
5355 return ptr_bounds_clip (non_lisp_beg + start, nbytes + 1); 5341 return non_lisp_beg + start;
5356 5342
5357 start += last_char_skip; 5343 start += last_char_skip;
5358 } 5344 }
@@ -6076,7 +6062,6 @@ garbage_collect (void)
6076 stack_copy = xrealloc (stack_copy, stack_size); 6062 stack_copy = xrealloc (stack_copy, stack_size);
6077 stack_copy_size = stack_size; 6063 stack_copy_size = stack_size;
6078 } 6064 }
6079 stack = ptr_bounds_set (stack, stack_size);
6080 no_sanitize_memcpy (stack_copy, stack, stack_size); 6065 no_sanitize_memcpy (stack_copy, stack, stack_size);
6081 } 6066 }
6082 } 6067 }
@@ -6922,8 +6907,7 @@ sweep_conses (void)
6922 6907
6923 for (pos = start; pos < stop; pos++) 6908 for (pos = start; pos < stop; pos++)
6924 { 6909 {
6925 struct Lisp_Cons *acons 6910 struct Lisp_Cons *acons = &cblk->conses[pos];
6926 = ptr_bounds_copy (&cblk->conses[pos], cblk);
6927 if (!XCONS_MARKED_P (acons)) 6911 if (!XCONS_MARKED_P (acons))
6928 { 6912 {
6929 this_free++; 6913 this_free++;
@@ -6976,7 +6960,7 @@ sweep_floats (void)
6976 int this_free = 0; 6960 int this_free = 0;
6977 for (int i = 0; i < lim; i++) 6961 for (int i = 0; i < lim; i++)
6978 { 6962 {
6979 struct Lisp_Float *afloat = ptr_bounds_copy (&fblk->floats[i], fblk); 6963 struct Lisp_Float *afloat = &fblk->floats[i];
6980 if (!XFLOAT_MARKED_P (afloat)) 6964 if (!XFLOAT_MARKED_P (afloat))
6981 { 6965 {
6982 this_free++; 6966 this_free++;