blob: 961cb60fa0246594ebfdedceddc33b0ee3e68878 [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
Colin Crossa9939e92017-06-21 13:13:00 -070024namespace android {
25
Colin Crossbcb4ed32016-01-14 15:35:40 -080026struct ThreadInfo {
27 pid_t tid;
28 allocator::vector<uintptr_t> regs;
29 std::pair<uintptr_t, uintptr_t> stack;
30};
31
32using TidList = allocator::vector<pid_t>;
33using ThreadInfoList = allocator::vector<ThreadInfo>;
34
35class ThreadCaptureImpl;
36
37class ThreadCapture {
Colin Crossa83881e2017-06-22 10:50:05 -070038 public:
Colin Crossbcb4ed32016-01-14 15:35:40 -080039 ThreadCapture(pid_t pid, Allocator<ThreadCapture> allocator);
40 ~ThreadCapture();
41
42 bool ListThreads(TidList& tids);
43 bool CaptureThreads();
44 bool ReleaseThreads();
45 bool ReleaseThread(pid_t tid);
46 bool CapturedThreadInfo(ThreadInfoList& threads);
47 void InjectTestFunc(std::function<void(pid_t)>&& f);
48
Colin Crossa83881e2017-06-22 10:50:05 -070049 private:
Colin Crossbcb4ed32016-01-14 15:35:40 -080050 ThreadCapture(const ThreadCapture&) = delete;
51 void operator=(const ThreadCapture&) = delete;
52
53 Allocator<ThreadCaptureImpl>::unique_ptr impl_;
54};
55
Colin Crossa9939e92017-06-21 13:13:00 -070056} // namespace android
57
Colin Crossbcb4ed32016-01-14 15:35:40 -080058#endif