| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: dlfcn_elf.c,v 1.16 2018/07/13 19:49:47 joerg Exp $ */ | | 1 | /* $NetBSD: dlfcn_elf.c,v 1.16.10.1 2023/07/05 16:11:51 martin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2000 Takuya SHIOZAKI | | 4 | * Copyright (c) 2000 Takuya SHIOZAKI |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | #include <sys/cdefs.h> | | 28 | #include <sys/cdefs.h> |
29 | #if defined(LIBC_SCCS) && !defined(lint) | | 29 | #if defined(LIBC_SCCS) && !defined(lint) |
30 | __RCSID("$NetBSD: dlfcn_elf.c,v 1.16 2018/07/13 19:49:47 joerg Exp $"); | | 30 | __RCSID("$NetBSD: dlfcn_elf.c,v 1.16.10.1 2023/07/05 16:11:51 martin Exp $"); |
31 | #endif /* LIBC_SCCS and not lint */ | | 31 | #endif /* LIBC_SCCS and not lint */ |
32 | | | 32 | |
33 | #include "namespace.h" | | 33 | #include "namespace.h" |
34 | #include <sys/atomic.h> | | 34 | #include <sys/atomic.h> |
35 | #include <assert.h> | | 35 | #include <assert.h> |
36 | #include <elf.h> | | 36 | #include <elf.h> |
37 | #include <errno.h> | | 37 | #include <errno.h> |
38 | #include <string.h> | | 38 | #include <string.h> |
39 | #include <stdbool.h> | | 39 | #include <stdbool.h> |
40 | | | 40 | |
41 | #undef dl_iterate_phdr | | 41 | #undef dl_iterate_phdr |
42 | #undef dlopen | | 42 | #undef dlopen |
43 | #undef dlclose | | 43 | #undef dlclose |
| @@ -197,26 +197,27 @@ dl_iterate_phdr(int (*callback)(struct d | | | @@ -197,26 +197,27 @@ dl_iterate_phdr(int (*callback)(struct d |
197 | static bool setup_done; | | 197 | static bool setup_done; |
198 | struct dl_phdr_info phdr_info; | | 198 | struct dl_phdr_info phdr_info; |
199 | | | 199 | |
200 | if (!setup_done) { | | 200 | if (!setup_done) { |
201 | /* | | 201 | /* |
202 | * This can race on the first call to dl_iterate_phdr. | | 202 | * This can race on the first call to dl_iterate_phdr. |
203 | * dl_iterate_phdr_setup only touches field of pointer size | | 203 | * dl_iterate_phdr_setup only touches field of pointer size |
204 | * and smaller and such stores are atomic. | | 204 | * and smaller and such stores are atomic. |
205 | */ | | 205 | */ |
206 | dl_iterate_phdr_setup(); | | 206 | dl_iterate_phdr_setup(); |
207 | membar_producer(); | | 207 | membar_producer(); |
208 | setup_done = true; | | 208 | setup_done = true; |
209 | } | | 209 | } |
| | | 210 | membar_consumer(); |
210 | | | 211 | |
211 | memset(&phdr_info, 0, sizeof(phdr_info)); | | 212 | memset(&phdr_info, 0, sizeof(phdr_info)); |
212 | phdr_info.dlpi_addr = dlpi_addr; | | 213 | phdr_info.dlpi_addr = dlpi_addr; |
213 | phdr_info.dlpi_phdr = dlpi_phdr; | | 214 | phdr_info.dlpi_phdr = dlpi_phdr; |
214 | phdr_info.dlpi_phnum = dlpi_phnum; | | 215 | phdr_info.dlpi_phnum = dlpi_phnum; |
215 | phdr_info.dlpi_name = dlpi_name; | | 216 | phdr_info.dlpi_name = dlpi_name; |
216 | | | 217 | |
217 | return callback(&phdr_info, sizeof(phdr_info), data); | | 218 | return callback(&phdr_info, sizeof(phdr_info), data); |
218 | } | | 219 | } |
219 | | | 220 | |
220 | void ___dl_cxa_refcount(void *, ssize_t); | | 221 | void ___dl_cxa_refcount(void *, ssize_t); |
221 | | | 222 | |
222 | /*ARGSUSED*/ | | 223 | /*ARGSUSED*/ |