1 //===-- msan_dl.cpp -------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of MemorySanitizer.
11 // Helper functions for unpoisoning results of dladdr and dladdr1.
12 //===----------------------------------------------------------------------===//
20 #include "msan_poisoning.h"
24 void UnpoisonDllAddrInfo(void *info
) {
25 Dl_info
*ptr
= (Dl_info
*)(info
);
26 __msan_unpoison(ptr
, sizeof(*ptr
));
28 __msan_unpoison(ptr
->dli_fname
, internal_strlen(ptr
->dli_fname
) + 1);
30 __msan_unpoison(ptr
->dli_sname
, internal_strlen(ptr
->dli_sname
) + 1);
34 void UnpoisonDllAddr1ExtraInfo(void **extra_info
, int flags
) {
35 if (flags
== RTLD_DL_SYMENT
) {
36 __msan_unpoison(extra_info
, sizeof(void *));
38 ElfW(Sym
) *s
= *((ElfW(Sym
) **)(extra_info
));
39 __msan_unpoison(s
, sizeof(ElfW(Sym
)));
40 } else if (flags
== RTLD_DL_LINKMAP
) {
41 __msan_unpoison(extra_info
, sizeof(void *));
43 struct link_map
*map
= *((struct link_map
**)(extra_info
));
46 for (auto *ptr
= map
; ptr
; ptr
= ptr
->l_next
) {
47 __msan_unpoison(ptr
, sizeof(struct link_map
));
49 __msan_unpoison(ptr
->l_name
, internal_strlen(ptr
->l_name
) + 1);
56 for (auto *ptr
= map
->l_prev
; ptr
; ptr
= ptr
->l_prev
) {
57 __msan_unpoison(ptr
, sizeof(struct link_map
));
59 __msan_unpoison(ptr
->l_name
, internal_strlen(ptr
->l_name
) + 1);