enum { MALLOC_IS_LISP_ALIGNED = alignof (max_align_t) % LISP_ALIGNMENT == 0 };
static_assert (MALLOC_IS_LISP_ALIGNED);
-/* If compiled with XMALLOC_BLOCK_INPUT_CHECK, define a symbol
- BLOCK_INPUT_IN_MEMORY_ALLOCATORS that is visible to the debugger.
- If that variable is set, block input while in one of Emacs's memory
- allocation functions. There should be no need for this debugging
- option, since signal handlers do not allocate memory, but Emacs
- formerly allocated memory in signal handlers and this compile-time
- option remains as a way to help debug the issue should it rear its
- ugly head again. */
-#ifdef XMALLOC_BLOCK_INPUT_CHECK
-bool block_input_in_memory_allocators EXTERNALLY_VISIBLE;
-static void
-malloc_block_input (void)
-{
- if (block_input_in_memory_allocators)
- block_input ();
-}
-static void
-malloc_unblock_input (void)
-{
- if (block_input_in_memory_allocators)
- {
- int err = errno;
- unblock_input ();
- errno = err;
- }
-}
-# define MALLOC_BLOCK_INPUT malloc_block_input ()
-# define MALLOC_UNBLOCK_INPUT malloc_unblock_input ()
-#else
-# define MALLOC_BLOCK_INPUT ((void) 0)
-# define MALLOC_UNBLOCK_INPUT ((void) 0)
-#endif
-
#define MALLOC_PROBE(size) \
do { \
if (profiler_memory_running) \
void *
xmalloc (size_t size)
{
- void *val;
-
- MALLOC_BLOCK_INPUT;
- val = malloc (size);
- MALLOC_UNBLOCK_INPUT;
-
+ void *val = malloc (size);
if (!val)
memory_full (size);
MALLOC_PROBE (size);
void *
xzalloc (size_t size)
{
- void *val;
-
- MALLOC_BLOCK_INPUT;
- val = calloc (1, size);
- MALLOC_UNBLOCK_INPUT;
-
+ void *val = calloc (1, size);
if (!val)
memory_full (size);
MALLOC_PROBE (size);
void *
xrealloc (void *block, size_t size)
{
- void *val;
-
- MALLOC_BLOCK_INPUT;
- val = realloc (block, size);
- MALLOC_UNBLOCK_INPUT;
-
+ void *val = realloc (block, size);
if (!val)
memory_full (size);
MALLOC_PROBE (size);
return;
if (pdumper_object_p (block))
return;
- MALLOC_BLOCK_INPUT;
free (block);
- MALLOC_UNBLOCK_INPUT;
/* We don't call refill_memory_reserve here
because in practice the call in r_alloc_free seems to suffice. */
}
static void *
lisp_malloc (size_t nbytes, bool clearit, enum mem_type type)
{
- register void *val;
-
- MALLOC_BLOCK_INPUT;
-
#ifdef GC_MALLOC_CHECK
allocated_mem_type = type;
#endif
- val = clearit ? calloc (1, nbytes) : malloc (nbytes);
+ void *val = clearit ? calloc (1, nbytes) : malloc (nbytes);
#if ! USE_LSB_TAG
/* If the memory just allocated cannot be addressed thru a Lisp
mem_insert (val, (char *) val + nbytes, type);
#endif
- MALLOC_UNBLOCK_INPUT;
if (!val)
memory_full (nbytes);
MALLOC_PROBE (nbytes);
if (pdumper_object_p (block))
return;
- MALLOC_BLOCK_INPUT;
#ifndef GC_MALLOC_CHECK
struct mem_node *m = mem_find (block);
#endif
#ifndef GC_MALLOC_CHECK
mem_delete (m);
#endif
- MALLOC_UNBLOCK_INPUT;
}
/***** Allocation of aligned blocks of memory to store Lisp data. *****/
eassert (nbytes <= BLOCK_BYTES);
- MALLOC_BLOCK_INPUT;
-
#ifdef GC_MALLOC_CHECK
allocated_mem_type = type;
#endif
#endif
if (base == 0)
- {
- MALLOC_UNBLOCK_INPUT;
- memory_full (ABLOCKS_BYTES);
- }
+ memory_full (ABLOCKS_BYTES);
aligned = (base == abase);
if (!aligned)
{
lisp_malloc_loser = base;
free (base);
- MALLOC_UNBLOCK_INPUT;
memory_full (SIZE_MAX);
}
}
mem_insert (val, (char *) val + nbytes, type);
#endif
- MALLOC_UNBLOCK_INPUT;
-
MALLOC_PROBE (nbytes);
eassert (0 == ((uintptr_t) val) % BLOCK_ALIGN);
struct ablock *ablock = block;
struct ablocks *abase = ABLOCK_ABASE (ablock);
- MALLOC_BLOCK_INPUT;
#ifndef GC_MALLOC_CHECK
mem_delete (mem_find (block));
#endif
#endif
free (ABLOCKS_BASE (abase));
}
- MALLOC_UNBLOCK_INPUT;
}
\f
{
INTERVAL val;
- MALLOC_BLOCK_INPUT;
-
if (interval_free_list)
{
val = interval_free_list;
ASAN_UNPOISON_INTERVAL (val);
}
- MALLOC_UNBLOCK_INPUT;
-
tally_consing (sizeof (struct interval));
intervals_consed++;
RESET_INTERVAL (val);
{
struct Lisp_String *s;
- MALLOC_BLOCK_INPUT;
-
/* If the free-list is empty, allocate a new string_block, and
add all the Lisp_Strings in it to the free-list. */
if (string_free_list == NULL)
ASAN_UNPOISON_STRING (s);
string_free_list = NEXT_FREE_LISP_STRING (s);
- MALLOC_UNBLOCK_INPUT;
-
++strings_consed;
tally_consing (sizeof *s);
of string data. */
ptrdiff_t needed = sdata_size (nbytes);
- MALLOC_BLOCK_INPUT;
-
if (nbytes > LARGE_STRING_BYTES || immovable)
{
size_t size = FLEXSIZEOF (struct sblock, data, needed);
b->next_free = (sdata *) ((char *) data + needed + GC_STRING_EXTRA);
eassert ((uintptr_t) b->next_free % alignof (sdata) == 0);
- MALLOC_UNBLOCK_INPUT;
-
s->u.s.data = SDATA_DATA (data);
#ifdef GC_CHECK_STRING_BYTES
SDATA_NBYTES (data) = nbytes;
{
register Lisp_Object val;
- MALLOC_BLOCK_INPUT;
-
if (float_free_list)
{
XSETFLOAT (val, float_free_list);
float_block_index++;
}
- MALLOC_UNBLOCK_INPUT;
-
XFLOAT_INIT (val, float_value);
eassert (!XFLOAT_MARKED_P (XFLOAT (val)));
tally_consing (sizeof (struct Lisp_Float));
{
register Lisp_Object val;
- MALLOC_BLOCK_INPUT;
-
if (cons_free_list)
{
ASAN_UNPOISON_CONS (cons_free_list);
cons_block_index++;
}
- MALLOC_UNBLOCK_INPUT;
-
XSETCAR (val, car);
XSETCDR (val, cdr);
eassert (!XCONS_MARKED_P (XCONS (val)));
ptrdiff_t nbytes = header_size + len * word_size;
struct Lisp_Vector *p;
- MALLOC_BLOCK_INPUT;
-
#ifdef DOUG_LEA_MALLOC
if (!mmap_lisp_allowed_p ())
mallopt (M_MMAP_MAX, 0);
tally_consing (nbytes);
vector_cells_consed += len;
- MALLOC_UNBLOCK_INPUT;
-
return p;
}
CHECK_STRING (name);
- MALLOC_BLOCK_INPUT;
-
if (symbol_free_list)
{
ASAN_UNPOISON_SYMBOL (symbol_free_list);
symbol_block_index++;
}
- MALLOC_UNBLOCK_INPUT;
-
init_symbol (val, name);
tally_consing (sizeof (struct Lisp_Symbol));
symbols_consed++;
bool enough_free_memory = false;
if (SPARE_MEMORY < nbytes)
{
- void *p;
-
- MALLOC_BLOCK_INPUT;
- p = malloc (SPARE_MEMORY);
+ void *p = malloc (SPARE_MEMORY);
if (p)
{
free (p);
enough_free_memory = true;
}
- MALLOC_UNBLOCK_INPUT;
}
if (! enough_free_memory)