Sun Jul 21 06:48:38 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc.git] / elf / dl-error.c
blob737bba7421d521a6b66673dc886da6b65ea4bc03
1 /* Error handling for runtime dynamic linker.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
20 #include <stddef.h>
21 #include <link.h>
22 #include <setjmp.h>
23 #include <string.h>
25 /* This structure communicates state between _dl_catch_error and
26 _dl_signal_error. */
27 struct catch
29 const char *errstring, *objname; /* Error detail filled in here. */
30 jmp_buf env; /* longjmp here on error. */
33 /* This points to such a structure during a call to _dl_catch_error.
34 During implicit startup and run-time work for needed shared libraries,
35 this is null. */
36 static struct catch *catch;
39 void
40 _dl_signal_error (int errcode,
41 const char *objname,
42 const char *errstring)
44 if (! errstring)
45 errstring = "DYNAMIC LINKER BUG!!!";
47 if (catch)
49 /* We are inside _dl_catch_error. Return to it. */
50 catch->errstring = errstring;
51 catch->objname = objname;
52 longjmp (catch->env, errcode ?: -1);
54 else
56 /* Lossage while resolving the program's own symbols is always fatal. */
57 extern char **_dl_argv; /* Set in rtld.c at startup. */
58 _dl_sysdep_fatal (_dl_argv[0] ?: "<program name unknown>",
59 ": error in loading shared libraries\n",
60 objname ?: "", objname ? ": " : "",
61 errstring, errcode ? ": " : "",
62 errcode ? strerror (errcode) : "", "\n", NULL);
66 int
67 _dl_catch_error (const char **errstring,
68 const char **objname,
69 void (*operate) (void))
71 int errcode;
72 struct catch c = { errstring: NULL, objname: NULL };
74 errcode = setjmp (c.env);
75 if (errcode == 0)
77 catch = &c;
78 (*operate) ();
79 catch = NULL;
80 *errstring = *objname = NULL;
81 return 0;
84 /* We get here only if we longjmp'd out of OPERATE. */
85 *errstring = c.errstring;
86 *objname = c.objname;
87 return errcode == -1 ? 0 : errcode;