1 /* 2 * Copyright 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 #pragma once 18 19 #include <sys/types.h> 20 21 #include <unordered_map> 22 23 #include <event2/event.h> 24 #include <event2/listener.h> 25 26 #include <android-base/unique_fd.h> 27 28 #include "dump_type.h" 29 30 struct InterceptManager; 31 32 struct Intercept { ~InterceptIntercept33 ~Intercept() { 34 event_free(intercept_event); 35 } 36 37 InterceptManager* intercept_manager = nullptr; 38 event* intercept_event = nullptr; 39 android::base::unique_fd sockfd; 40 41 pid_t intercept_pid = -1; 42 android::base::unique_fd output_fd; 43 bool registered = false; 44 DebuggerdDumpType dump_type = kDebuggerdNativeBacktrace; 45 }; 46 47 struct InterceptManager { 48 event_base* base; 49 std::unordered_map<pid_t, std::unique_ptr<Intercept>> intercepts; 50 evconnlistener* listener = nullptr; 51 52 InterceptManager(event_base* _Nonnull base, int intercept_socket); 53 InterceptManager(InterceptManager& copy) = delete; 54 InterceptManager(InterceptManager&& move) = delete; 55 56 bool GetIntercept(pid_t pid, DebuggerdDumpType dump_type, android::base::unique_fd* out_fd); 57 }; 58