aboutsummaryrefslogtreecommitdiff
path: root/elf/dl-error.c
diff options
context:
space:
mode:
Diffstat (limited to 'elf/dl-error.c')
-rw-r--r--elf/dl-error.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/elf/dl-error.c b/elf/dl-error.c
index 0ef76c8..79ebaaf 100644
--- a/elf/dl-error.c
+++ b/elf/dl-error.c
@@ -1,5 +1,5 @@
/* Error handling for runtime dynamic linker.
- Copyright (C) 1995-2002,2004 Free Software Foundation, Inc.
+ Copyright (C) 1995-2002,2004,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -19,6 +19,7 @@
#include <libintl.h>
#include <setjmp.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -30,6 +31,8 @@ struct catch
{
const char *objname; /* Object/File name. */
const char *errstring; /* Error detail filled in here. */
+ bool malloced; /* Nonzero if the string is malloced
+ by the libc malloc. */
jmp_buf env; /* longjmp here on error. */
};
@@ -44,8 +47,7 @@ struct catch
/* This message we return as a last resort. We define the string in a
variable since we have to avoid freeing it and so have to enable
a pointer comparison. See below and in dlfcn/dlerror.c. */
-const char _dl_out_of_memory[] = "out of memory";
-INTVARDEF(_dl_out_of_memory)
+static const char _dl_out_of_memory[] = "out of memory";
/* This points to a function which is called when an continuable error is
@@ -87,17 +89,31 @@ _dl_signal_error (int errcode, const char *objname, const char *occation,
lcatch->errstring = (char *) malloc (len_objname + len_errstring);
if (lcatch->errstring != NULL)
- /* Make a copy of the object file name and the error string. */
- lcatch->objname = memcpy (__mempcpy ((char *) lcatch->errstring,
- errstring, len_errstring),
- objname, len_objname);
+ {
+ /* Make a copy of the object file name and the error string. */
+ lcatch->objname = memcpy (__mempcpy ((char *) lcatch->errstring,
+ errstring, len_errstring),
+ objname, len_objname);
+
+ /* If the main executable is relocated it means the libc's malloc
+ is used. */
+#ifdef SHARED
+ lcatch->malloced = (GL(dl_ns)[LM_ID_BASE]._ns_loaded != NULL
+ && (GL(dl_ns)[LM_ID_BASE]._ns_loaded->l_relocated
+ != 0));
+#else
+ lcatch->malloced = true;
+#endif
+ }
else
{
/* This is better than nothing. */
lcatch->objname = "";
- lcatch->errstring = INTUSE(_dl_out_of_memory);
+ lcatch->errstring = _dl_out_of_memory;
+ lcatch->malloced = false;
}
- longjmp (lcatch->env, errcode ?: -1);
+ /* We do not restore the signal mask because none was saved. */
+ __longjmp (lcatch->env[0].__jmpbuf, errcode ?: -1);
}
else
{
@@ -140,7 +156,7 @@ _dl_signal_cerror (int errcode, const char *objname, const char *occation,
int
internal_function
_dl_catch_error (const char **objname, const char **errstring,
- void (*operate) (void *), void *args)
+ bool *mallocedp, void (*operate) (void *), void *args)
{
int errcode;
struct catch *volatile old;
@@ -154,7 +170,8 @@ _dl_catch_error (const char **objname, const char **errstring,
struct catch **const catchp = &CATCH_HOOK;
old = *catchp;
- errcode = setjmp (c.env);
+ /* Do not save the signal mask. */
+ errcode = __sigsetjmp (c.env, 0);
if (__builtin_expect (errcode, 0) == 0)
{
*catchp = &c;
@@ -162,6 +179,7 @@ _dl_catch_error (const char **objname, const char **errstring,
*catchp = old;
*objname = NULL;
*errstring = NULL;
+ *mallocedp = false;
return 0;
}
@@ -169,6 +187,7 @@ _dl_catch_error (const char **objname, const char **errstring,
*catchp = old;
*objname = c.objname;
*errstring = c.errstring;
+ *mallocedp = c.malloced;
return errcode == -1 ? 0 : errcode;
}