Home | History | Annotate | Download | only in libmemunreachable
      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 
     24 struct ThreadInfo {
     25   pid_t tid;
     26   allocator::vector<uintptr_t> regs;
     27   std::pair<uintptr_t, uintptr_t> stack;
     28 };
     29 
     30 using TidList = allocator::vector<pid_t>;
     31 using ThreadInfoList = allocator::vector<ThreadInfo>;
     32 
     33 class ThreadCaptureImpl;
     34 
     35 class ThreadCapture {
     36 public:
     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 
     47 private:
     48   ThreadCapture(const ThreadCapture&) = delete;
     49   void operator=(const ThreadCapture&) = delete;
     50 
     51   Allocator<ThreadCaptureImpl>::unique_ptr impl_;
     52 };
     53 
     54 #endif
     55