1/* libunwind - a platform-independent unwind library
2   Copyright (C) 2001-2002, 2005 Hewlett-Packard Co
3	Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5This file is part of libunwind.
6
7Permission is hereby granted, free of charge, to any person obtaining
8a copy of this software and associated documentation files (the
9"Software"), to deal in the Software without restriction, including
10without limitation the rights to use, copy, modify, merge, publish,
11distribute, sublicense, and/or sell copies of the Software, and to
12permit persons to whom the Software is furnished to do so, subject to
13the following conditions:
14
15The above copyright notice and this permission notice shall be
16included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
25
26#include "libunwind_i.h"
27
28#ifdef UNW_REMOTE_ONLY
29
30static inline int
31local_find_proc_info (unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
32		      int need_unwind_info, void *arg)
33{
34  return -UNW_ENOINFO;
35}
36
37#else /* !UNW_REMOTE_ONLY */
38
39static inline int
40local_find_proc_info (unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
41		      int need_unwind_info, void *arg)
42{
43  unw_dyn_info_list_t *list;
44  unw_dyn_info_t *di;
45
46#ifndef UNW_LOCAL_ONLY
47# pragma weak _U_dyn_info_list_addr
48  if (!_U_dyn_info_list_addr)
49    return -UNW_ENOINFO;
50#endif
51
52  list = (unw_dyn_info_list_t *) (uintptr_t) _U_dyn_info_list_addr ();
53  for (di = list->first; di; di = di->next)
54    if (ip >= di->start_ip && ip < di->end_ip)
55      return unwi_extract_dynamic_proc_info (as, ip, pi, di, need_unwind_info,
56					     arg);
57  return -UNW_ENOINFO;
58}
59
60#endif /* !UNW_REMOTE_ONLY */
61
62#ifdef UNW_LOCAL_ONLY
63
64static inline int
65remote_find_proc_info (unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
66		       int need_unwind_info, void *arg)
67{
68  return -UNW_ENOINFO;
69}
70
71#else /* !UNW_LOCAL_ONLY */
72
73static inline int
74remote_find_proc_info (unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
75		       int need_unwind_info, void *arg)
76{
77  return unwi_dyn_remote_find_proc_info (as, ip, pi, need_unwind_info, arg);
78}
79
80#endif /* !UNW_LOCAL_ONLY */
81
82HIDDEN int
83unwi_find_dynamic_proc_info (unw_addr_space_t as, unw_word_t ip,
84			     unw_proc_info_t *pi, int need_unwind_info,
85			     void *arg)
86{
87  if (as == unw_local_addr_space)
88    return local_find_proc_info (as, ip, pi, need_unwind_info, arg);
89  else
90    return remote_find_proc_info (as, ip, pi, need_unwind_info, arg);
91}
92