blob: 1022cad1f57c704a06aa596c654334b3c9ef169c [file] [log] [blame]
Colin Crossbcb4ed32016-01-14 15:35:40 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#ifndef LIBMEMUNREACHABLE_THREAD_CAPTURE_H_
18#define LIBMEMUNREACHABLE_THREAD_CAPTURE_H_
19
20#include <utility>
21
22#include "Allocator.h"
23
24struct ThreadInfo {
25 pid_t tid;
26 allocator::vector<uintptr_t> regs;
27 std::pair<uintptr_t, uintptr_t> stack;
28};
29
30using TidList = allocator::vector<pid_t>;
31using ThreadInfoList = allocator::vector<ThreadInfo>;
32
33class ThreadCaptureImpl;
34
35class ThreadCapture {
36public:
37 ThreadCapture(pid_t pid, Allocator<ThreadCapture> allocator);
38 ~ThreadCapture();
39
40 bool ListThreads(TidList& tids);
41 bool CaptureThreads();
42 bool ReleaseThreads();
43 bool ReleaseThread(pid_t tid);
44 bool CapturedThreadInfo(ThreadInfoList& threads);
45 void InjectTestFunc(std::function<void(pid_t)>&& f);
46
47private:
48 ThreadCapture(const ThreadCapture&) = delete;
49 void operator=(const ThreadCapture&) = delete;
50
51 Allocator<ThreadCaptureImpl>::unique_ptr impl_;
52};
53
54#endif