Colin Cross | bcb4ed3 | 2016-01-14 15:35:40 -0800 | [diff] [blame] | 1 | /* |
| 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 Cross | a9939e9 | 2017-06-21 13:13:00 -0700 | [diff] [blame] | 24 | namespace android { |
| 25 | |
Colin Cross | bcb4ed3 | 2016-01-14 15:35:40 -0800 | [diff] [blame] | 26 | struct ThreadInfo { |
| 27 | pid_t tid; |
| 28 | allocator::vector<uintptr_t> regs; |
| 29 | std::pair<uintptr_t, uintptr_t> stack; |
| 30 | }; |
| 31 | |
| 32 | using TidList = allocator::vector<pid_t>; |
| 33 | using ThreadInfoList = allocator::vector<ThreadInfo>; |
| 34 | |
| 35 | class ThreadCaptureImpl; |
| 36 | |
| 37 | class ThreadCapture { |
Colin Cross | a83881e | 2017-06-22 10:50:05 -0700 | [diff] [blame] | 38 | public: |
Colin Cross | bcb4ed3 | 2016-01-14 15:35:40 -0800 | [diff] [blame] | 39 | 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 Cross | a83881e | 2017-06-22 10:50:05 -0700 | [diff] [blame] | 49 | private: |
Colin Cross | bcb4ed3 | 2016-01-14 15:35:40 -0800 | [diff] [blame] | 50 | ThreadCapture(const ThreadCapture&) = delete; |
| 51 | void operator=(const ThreadCapture&) = delete; |
| 52 | |
| 53 | Allocator<ThreadCaptureImpl>::unique_ptr impl_; |
| 54 | }; |
| 55 | |
Colin Cross | a9939e9 | 2017-06-21 13:13:00 -0700 | [diff] [blame] | 56 | } // namespace android |
| 57 | |
Colin Cross | bcb4ed3 | 2016-01-14 15:35:40 -0800 | [diff] [blame] | 58 | #endif |