diff options
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/src/alloc.c b/src/alloc.c index 89fe96a2349..77d5d2839a2 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -655,24 +655,22 @@ buffer_memory_full (ptrdiff_t nbytes) | |||
| 655 | #define COMMON_MULTIPLE(a, b) \ | 655 | #define COMMON_MULTIPLE(a, b) \ |
| 656 | ((a) % (b) == 0 ? (a) : (b) % (a) == 0 ? (b) : (a) * (b)) | 656 | ((a) % (b) == 0 ? (a) : (b) % (a) == 0 ? (b) : (a) * (b)) |
| 657 | 657 | ||
| 658 | /* A lower bound on the alignment of malloc. Although this bound is | 658 | /* Alignment needed for memory blocks that are allocated via malloc |
| 659 | incorrect for some buggy malloc implementations (e.g., MinGW circa | 659 | and that contain Lisp objects. On typical hosts malloc already |
| 660 | 2020), the bugs should not matter for the way this bound is used | 660 | aligns sufficiently, but extra work is needed on oddball hosts |
| 661 | since the correct bound is also a multiple of LISP_ALIGNMENT on the | 661 | where Emacs would crash if malloc returned a non-GCALIGNED pointer. */ |
| 662 | buggy platforms. */ | 662 | enum { LISP_ALIGNMENT = alignof (union { union emacs_align_type x; |
| 663 | enum { MALLOC_ALIGNMENT_BOUND = alignof (max_align_t) }; | 663 | GCALIGNED_UNION_MEMBER }) }; |
| 664 | 664 | verify (LISP_ALIGNMENT % GCALIGNMENT == 0); | |
| 665 | /* A lower bound on the alignment of Lisp objects allocated on the heap. | ||
| 666 | All such objects must have an address that is a multiple of LISP_ALIGNMENT; | ||
| 667 | otherwise maybe_lisp_pointer can issue false negatives, causing crashes. | ||
| 668 | On all practical Emacs targets, sizeof (struct Lisp_Float) == 8 and | ||
| 669 | since GCALIGNMENT also equals 8 there's little point to optimizing | ||
| 670 | for impractical targets. */ | ||
| 671 | enum { LISP_ALIGNMENT = GCALIGNMENT }; | ||
| 672 | 665 | ||
| 673 | /* True if malloc (N) is known to return storage suitably aligned for | 666 | /* True if malloc (N) is known to return storage suitably aligned for |
| 674 | Lisp objects whenever N is a multiple of LISP_ALIGNMENT. */ | 667 | Lisp objects whenever N is a multiple of LISP_ALIGNMENT. In |
| 675 | enum { MALLOC_IS_LISP_ALIGNED = MALLOC_ALIGNMENT_BOUND % LISP_ALIGNMENT == 0 }; | 668 | practice this is true whenever alignof (max_align_t) is also a |
| 669 | multiple of LISP_ALIGNMENT. This works even for buggy platforms | ||
| 670 | like MinGW circa 2020, where alignof (max_align_t) is 16 even though | ||
| 671 | the malloc alignment is only 8, and where Emacs still works because | ||
| 672 | it never does anything that requires an alignment of 16. */ | ||
| 673 | enum { MALLOC_IS_LISP_ALIGNED = alignof (max_align_t) % LISP_ALIGNMENT == 0 }; | ||
| 676 | 674 | ||
| 677 | /* If compiled with XMALLOC_BLOCK_INPUT_CHECK, define a symbol | 675 | /* If compiled with XMALLOC_BLOCK_INPUT_CHECK, define a symbol |
| 678 | BLOCK_INPUT_IN_MEMORY_ALLOCATORS that is visible to the debugger. | 676 | BLOCK_INPUT_IN_MEMORY_ALLOCATORS that is visible to the debugger. |
| @@ -4653,12 +4651,12 @@ mark_maybe_objects (Lisp_Object const *array, ptrdiff_t nelts) | |||
| 4653 | collected, and false otherwise (i.e., false if it is easy to see | 4651 | collected, and false otherwise (i.e., false if it is easy to see |
| 4654 | that P cannot point to Lisp data that can be garbage collected). | 4652 | that P cannot point to Lisp data that can be garbage collected). |
| 4655 | Symbols are implemented via offsets not pointers, but the offsets | 4653 | Symbols are implemented via offsets not pointers, but the offsets |
| 4656 | are also multiples of LISP_ALIGNMENT. */ | 4654 | are also multiples of GCALIGNMENT. */ |
| 4657 | 4655 | ||
| 4658 | static bool | 4656 | static bool |
| 4659 | maybe_lisp_pointer (void *p) | 4657 | maybe_lisp_pointer (void *p) |
| 4660 | { | 4658 | { |
| 4661 | return (uintptr_t) p % LISP_ALIGNMENT == 0; | 4659 | return (uintptr_t) p % GCALIGNMENT == 0; |
| 4662 | } | 4660 | } |
| 4663 | 4661 | ||
| 4664 | /* If P points to Lisp data, mark that as live if it isn't already | 4662 | /* If P points to Lisp data, mark that as live if it isn't already |