summaryrefslogtreecommitdiff
path: root/nasmlib
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2019-08-28 18:32:46 -0700
committerH. Peter Anvin <hpa@zytor.com>2019-08-28 18:32:46 -0700
commit6a4353c4c29274fb2df6ca712fad70b8701c9187 (patch)
tree81456594614ae6120f6b1f0746d3c146ee890539 /nasmlib
parentf8a15a8ea3cc3484f4250fd878569f15412434ab (diff)
downloadnasm-6a4353c4c29274fb2df6ca712fad70b8701c9187.tar.gz
errors: be more robust in handling unexpected fatal errors
Introduce a new error level, ERR_CRITICAL, beyond which we will minimize the amount of code that will be executed before we die; in particular don't execute any memory allocations, and if we somehow end up recursing, abort() immediately. Basically, "less than panic, more than fatal." At this point this level is used by nasm_alloc_failed(). Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'nasmlib')
-rw-r--r--nasmlib/alloc.c20
-rw-r--r--nasmlib/alloc.h2
2 files changed, 3 insertions, 19 deletions
diff --git a/nasmlib/alloc.c b/nasmlib/alloc.c
index b0d623a2..e25e0e0a 100644
--- a/nasmlib/alloc.c
+++ b/nasmlib/alloc.c
@@ -42,25 +42,9 @@
size_t _nasm_last_string_size;
-no_return nasm_alloc_failed(void)
+fatal_func nasm_alloc_failed(void)
{
- /* If nasm_fatal() gets us back here, then croak hard */
- static bool already_here = false;
- FILE *errfile;
-
- if (likely(!already_here)) {
- already_here = true;
- nasm_fatal("out of memory!");
- }
-
- errfile = error_file;
- if (!errfile)
- error_file = stderr;
-
- fprintf(error_file, "nasm: out of memory!\n");
- fflush(error_file);
- fflush(NULL);
- abort();
+ nasm_critical("out of memory!");
}
void *nasm_malloc(size_t size)
diff --git a/nasmlib/alloc.h b/nasmlib/alloc.h
index 1b896585..9b8ad192 100644
--- a/nasmlib/alloc.h
+++ b/nasmlib/alloc.h
@@ -36,7 +36,7 @@
#include "compiler.h"
-no_return nasm_alloc_failed(void);
+fatal_func nasm_alloc_failed(void);
static inline void *validate_ptr(void *p)
{