File: sanitizer_procmaps_haiku.cpp

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,236,320 kB
  • sloc: cpp: 7,619,338; ansic: 1,433,952; asm: 1,058,735; python: 252,125; f90: 94,671; objc: 70,753; lisp: 42,813; pascal: 18,401; sh: 10,094; ml: 5,111; perl: 4,720; awk: 3,523; makefile: 3,397; javascript: 2,272; xml: 892; fortran: 770
file content (94 lines) | stat: -rw-r--r-- 3,284 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//===-- sanitizer_procmaps_haiku.cpp --------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Information about the process mappings
// (Haiku-specific parts).
//===----------------------------------------------------------------------===//

#include "sanitizer_platform.h"
#if SANITIZER_HAIKU
#  include "sanitizer_common.h"
#  include "sanitizer_procmaps.h"

#  include <kernel/OS.h>

namespace __sanitizer {

void MemoryMappedSegment::AddAddressRanges(LoadedModule *module) {
  // data_ should be unused on this platform
  CHECK(!data_);
  module->addAddressRange(start, end, IsExecutable(), IsWritable());
}

MemoryMappingLayout::MemoryMappingLayout(bool) { Reset(); }

void MemoryMappingLayout::Reset() { data_.cookie = 0; }

MemoryMappingLayout::~MemoryMappingLayout() {}

// static
void MemoryMappingLayout::CacheMemoryMappings() {}

bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
  area_info info;
  if (get_next_area_info(B_CURRENT_TEAM, &data_.cookie, &info) != B_OK)
    return false;

  segment->start = (uptr)info.address;
  segment->end = (uptr)info.address + info.size;
  segment->offset = 0;
  segment->protection = 0;
  if (info.protection & B_READ_AREA)
    segment->protection |= kProtectionRead;
  if (info.protection & B_WRITE_AREA)
    segment->protection |= kProtectionWrite;
  if (info.protection & B_EXECUTE_AREA)
    segment->protection |= kProtectionExecute;
  if (segment->filename) {
    uptr len = Min((uptr)B_OS_NAME_LENGTH, segment->filename_size - 1);
    internal_strncpy(segment->filename, info.name, len);
    segment->filename[len] = 0;
  }
  return true;
}

bool MemoryMappingLayout::Error() const { return false; }

void MemoryMappingLayout::DumpListOfModules(
    InternalMmapVectorNoCtor<LoadedModule> *modules) {
  Reset();
  InternalMmapVector<char> module_name(kMaxPathLength);
  MemoryMappedSegment segment(module_name.data(), module_name.size());
  for (uptr i = 0; Next(&segment); i++) {
    const char *cur_name = segment.filename;
    if (cur_name[0] == '\0')
      continue;
    // Don't subtract 'cur_beg' from the first entry:
    // * If a binary is compiled w/o -pie, then the first entry in
    //   process maps is likely the binary itself (all dynamic libs
    //   are mapped higher in address space). For such a binary,
    //   instruction offset in binary coincides with the actual
    //   instruction address in virtual memory (as code section
    //   is mapped to a fixed memory range).
    // * If a binary is compiled with -pie, all the modules are
    //   mapped high at address space (in particular, higher than
    //   shadow memory of the tool), so the module can't be the
    //   first entry.
    uptr base_address = (i ? segment.start : 0) - segment.offset;
    LoadedModule cur_module;
    cur_module.set(cur_name, base_address);
    segment.AddAddressRanges(&cur_module);
    modules->push_back(cur_module);
  }
}

void GetMemoryProfile(fill_profile_f cb, uptr *stats) {}

}  // namespace __sanitizer

#endif