1//===-- sanitizer_procmaps_haiku.cpp --------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// Information about the process mappings
10// (Haiku-specific parts).
11//===----------------------------------------------------------------------===//
12
13#include "sanitizer_platform.h"
14#if SANITIZER_HAIKU
15# include "sanitizer_common.h"
16# include "sanitizer_procmaps.h"
17
18# include <kernel/OS.h>
19
20namespace __sanitizer {
21
22void MemoryMappedSegment::AddAddressRanges(LoadedModule *module) {
23 // data_ should be unused on this platform
24 CHECK(!data_);
25 module->addAddressRange(start, end, IsExecutable(), IsWritable());
26}
27
28MemoryMappingLayout::MemoryMappingLayout(bool) { Reset(); }
29
30void MemoryMappingLayout::Reset() { data_.cookie = 0; }
31
32MemoryMappingLayout::~MemoryMappingLayout() {}
33
34// static
35void MemoryMappingLayout::CacheMemoryMappings() {}
36
37bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
38 area_info info;
39 if (get_next_area_info(B_CURRENT_TEAM, &data_.cookie, &info) != B_OK)
40 return false;
41
42 segment->start = (uptr)info.address;
43 segment->end = (uptr)info.address + info.size;
44 segment->offset = 0;
45 segment->protection = 0;
46 if (info.protection & B_READ_AREA)
47 segment->protection |= kProtectionRead;
48 if (info.protection & B_WRITE_AREA)
49 segment->protection |= kProtectionWrite;
50 if (info.protection & B_EXECUTE_AREA)
51 segment->protection |= kProtectionExecute;
52 if (segment->filename) {
53 uptr len = Min((uptr)B_OS_NAME_LENGTH, segment->filename_size - 1);
54 internal_strncpy(segment->filename, info.name, len);
55 segment->filename[len] = 0;
56 }
57 return true;
58}
59
60bool MemoryMappingLayout::Error() const { return false; }
61
62void MemoryMappingLayout::DumpListOfModules(
63 InternalMmapVectorNoCtor<LoadedModule> *modules) {
64 Reset();
65 InternalMmapVector<char> module_name(kMaxPathLength);
66 MemoryMappedSegment segment(module_name.data(), module_name.size());
67 for (uptr i = 0; Next(&segment); i++) {
68 const char *cur_name = segment.filename;
69 if (cur_name[0] == '\0')
70 continue;
71 // Don't subtract 'cur_beg' from the first entry:
72 // * If a binary is compiled w/o -pie, then the first entry in
73 // process maps is likely the binary itself (all dynamic libs
74 // are mapped higher in address space). For such a binary,
75 // instruction offset in binary coincides with the actual
76 // instruction address in virtual memory (as code section
77 // is mapped to a fixed memory range).
78 // * If a binary is compiled with -pie, all the modules are
79 // mapped high at address space (in particular, higher than
80 // shadow memory of the tool), so the module can't be the
81 // first entry.
82 uptr base_address = (i ? segment.start : 0) - segment.offset;
83 LoadedModule cur_module;
84 cur_module.set(cur_name, base_address);
85 segment.AddAddressRanges(&cur_module);
86 modules->push_back(cur_module);
87 }
88}
89
90void GetMemoryProfile(fill_profile_f cb, uptr *stats) {}
91
92} // namespace __sanitizer
93
94#endif
95