* sysdeps/unix/sysv/linux/m68k/register-dump.h: Use
[glibc.git] / elf / dl-caller.c
blobddabbd0f2dd30fc3e6c0e583545e66483d5f3e74
1 /* Check whether caller comes from the right place.
2 Copyright (C) 2004 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 Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <assert.h>
21 #include <ldsodefs.h>
22 #include <stddef.h>
23 #include <caller.h>
24 #include <gnu/lib-names.h>
27 int
28 attribute_hidden
29 _dl_check_caller (const void *caller, enum allowmask mask)
31 static const char expected1[] = LIBC_SO;
32 static const char expected2[] = LIBDL_SO;
33 #ifdef LIBPTHREAD_SO
34 static const char expected3[] = LIBPTHREAD_SO;
35 #endif
36 static const char expected4[] = LD_SO;
38 for (struct link_map *l = GL(dl_loaded); l != NULL; l = l->l_next)
39 if (caller >= (const void *) l->l_map_start
40 && caller < (const void *) l->l_text_end)
42 /* The address falls into this DSO's address range. Check the
43 name. */
44 if ((mask & allow_libc) && strcmp (expected1, l->l_name) == 0)
45 return 0;
46 if ((mask & allow_libdl) && strcmp (expected2, l->l_name) == 0)
47 return 0;
48 #ifdef LIBPTHREAD_SO
49 if ((mask & allow_libpthread) && strcmp (expected3, l->l_name) == 0)
50 return 0;
51 #endif
52 if ((mask & allow_ldso) && strcmp (expected4, l->l_name) == 0)
53 return 0;
55 struct libname_list *runp = l->l_libname;
57 while (runp != NULL)
59 if ((mask & allow_libc) && strcmp (expected1, runp->name) == 0)
60 return 0;
61 if ((mask & allow_libdl) && strcmp (expected2, runp->name) == 0)
62 return 0;
63 #ifdef LIBPTHREAD_SO
64 if ((mask & allow_libpthread)
65 && strcmp (expected3, runp->name) == 0)
66 return 0;
67 #endif
68 if ((mask & allow_ldso) && strcmp (expected4, runp->name) == 0)
69 return 0;
71 runp = runp->next;
74 break;
77 /* Maybe the dynamic linker is not yet on the list. */
78 if ((mask & allow_ldso) != 0
79 && caller >= (const void *) GL(dl_rtld_map).l_map_start
80 && caller < (const void *) GL(dl_rtld_map).l_text_end)
81 return 0;
83 /* No valid caller. */
84 return 1;