2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "createdump.h"
21 #include "dnetmemoryenumlib.h"
23 bool g_diagnostics = false;
25 std::vector<SimpleMemoryRegion> sm_regions;
27 static std::vector<SimpleMemoryRegion>
28 get_regions(CrashInfo *crashInfo)
30 std::vector<SimpleMemoryRegion> reg_vec;
31 for (const MemoryRegion& memoryRegion : crashInfo->MemoryRegions()) {
32 if (memoryRegion.IsBackedByMemory()) {
33 reg_vec.push_back({memoryRegion.StartAddress(), memoryRegion.Size()});
41 DotNetMemoryEnumInit()
43 int exitCode = PAL_InitializeDLL();
48 DotNetMemoryEnumFinish()
54 DotNetMemoryEnumRegions(pid_t pid, elf_prstatus **statuses, int statuses_count,
55 DUMP_TYPE minidump_type, SimpleMemoryRegion **regions)
59 std::vector<elf_prstatus*> stats;
60 for (int i = 0; i < statuses_count; i++) {
61 stats.push_back(statuses[i]);
64 MINIDUMP_TYPE minidumpType;
66 switch (minidump_type) {
69 minidumpType = MiniDumpNormal;
71 case DT_WITH_PRIV_AND_SHARED_MEM:
72 minidumpType = MiniDumpWithPrivateReadWriteMemory;
75 minidumpType = MiniDumpWithFullMemory;
79 int exitCode = REGERR_OK;
83 ReleaseHolder<DumpDataTarget> dataTarget = new DumpDataTarget(pid);
84 ReleaseHolder<CrashInfo> crashInfo = new CrashInfo(pid, dataTarget, true);
86 if (dataTarget->Initialize(crashInfo))
88 if (!crashInfo->EnumerateAndSuspendThreads(false))
90 return REGERR_ENUMERATION_ERROR;
92 crashInfo->SetThreadsRegisters(stats);
93 crashInfo->GatherCrashInfo(minidumpType, false);
94 sm_regions = get_regions(crashInfo);
95 *regions = sm_regions.data();
96 exitCode = sm_regions.size();
100 exitCode = REGERR_INITIALIZATION_ERROR;
105 exitCode = REGERR_WRONG_PID;