1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup rtl |
---|
7 | * |
---|
8 | * @brief RTEMS Module Loading Debugger Interface. |
---|
9 | * |
---|
10 | * Inspection of run-time linkers in NetBSD and Android show a common type of |
---|
11 | * structure that is used to interface to GDB. The NetBSD definition of this |
---|
12 | * interface is being used and is defined in <link.h>. It defines a protocol |
---|
13 | * that is used by GDB to inspect the state of dynamic libraries. I have not |
---|
14 | * checked GDB code at when writing this comment but I suspect GDB sets a break |
---|
15 | * point on the r_brk field of _rtld_debug and it has code that detects this |
---|
16 | * break point being hit. When this happens it reads the state and performs the |
---|
17 | * operation based on the r_state field. |
---|
18 | */ |
---|
19 | |
---|
20 | /* |
---|
21 | * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org> |
---|
22 | * |
---|
23 | * Redistribution and use in source and binary forms, with or without |
---|
24 | * modification, are permitted provided that the following conditions |
---|
25 | * are met: |
---|
26 | * 1. Redistributions of source code must retain the above copyright |
---|
27 | * notice, this list of conditions and the following disclaimer. |
---|
28 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
29 | * notice, this list of conditions and the following disclaimer in the |
---|
30 | * documentation and/or other materials provided with the distribution. |
---|
31 | * |
---|
32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
33 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
34 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
35 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
36 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
37 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
38 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
39 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
40 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
41 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
42 | * POSSIBILITY OF SUCH DAMAGE. |
---|
43 | */ |
---|
44 | |
---|
45 | #ifdef HAVE_CONFIG_H |
---|
46 | #include "config.h" |
---|
47 | #endif |
---|
48 | |
---|
49 | #include <stdio.h> |
---|
50 | #include <link.h> |
---|
51 | #include <rtems/rtl/rtl.h> |
---|
52 | #include <rtems/rtl/rtl-trace.h> |
---|
53 | #include <rtems/rtl/rtl-obj-fwd.h> |
---|
54 | |
---|
55 | struct r_debug _rtld_debug; |
---|
56 | |
---|
57 | void |
---|
58 | _rtld_debug_state (void) |
---|
59 | { |
---|
60 | /* |
---|
61 | * Empty. GDB only needs to hit this location. |
---|
62 | */ |
---|
63 | } |
---|
64 | |
---|
65 | int |
---|
66 | _rtld_linkmap_add (rtems_rtl_obj* obj) |
---|
67 | { |
---|
68 | struct link_map* l = obj->linkmap; |
---|
69 | struct link_map* prev; |
---|
70 | uint32_t obj_num = obj->obj_num; |
---|
71 | int i; |
---|
72 | |
---|
73 | if (rtems_rtl_trace (RTEMS_RTL_TRACE_DETAIL)) |
---|
74 | printf ("rtl: linkmap_add\n"); |
---|
75 | |
---|
76 | for (i = 0; i < obj_num; ++i) |
---|
77 | { |
---|
78 | l[i].sec_addr[rap_text] = obj->text_base; |
---|
79 | l[i].sec_addr[rap_const] = obj->const_base; |
---|
80 | l[i].sec_addr[rap_data] = obj->data_base; |
---|
81 | l[i].sec_addr[rap_bss] = obj->bss_base; |
---|
82 | } |
---|
83 | |
---|
84 | if (_rtld_debug.r_map == NULL) |
---|
85 | { |
---|
86 | _rtld_debug.r_map = l; |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | for (prev = _rtld_debug.r_map; prev->l_next != NULL; prev = prev->l_next); |
---|
91 | l->l_prev = prev; |
---|
92 | prev->l_next = l; |
---|
93 | } |
---|
94 | |
---|
95 | return true; |
---|
96 | } |
---|
97 | |
---|
98 | void |
---|
99 | _rtld_linkmap_delete (rtems_rtl_obj* obj) |
---|
100 | { |
---|
101 | struct link_map* l = obj->linkmap; |
---|
102 | |
---|
103 | /* |
---|
104 | * link_maps are allocated together if not 1 |
---|
105 | */ |
---|
106 | struct link_map* e = l + obj->obj_num - 1; |
---|
107 | |
---|
108 | if (l->l_prev == NULL) |
---|
109 | { |
---|
110 | if ((_rtld_debug.r_map = e->l_next) != NULL) |
---|
111 | _rtld_debug.r_map->l_prev = NULL; |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | if ((l->l_prev->l_next = e->l_next) != NULL) |
---|
116 | e->l_next->l_prev = l->l_prev; |
---|
117 | } |
---|
118 | } |
---|