blob: ced2252d09084128030c48001dc18a216ecace00 [file] [log] [blame]
Alex Lightfbf96702017-12-14 13:27:13 -08001/*
2 * Copyright (C) 2017 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#include <array>
Alex Light75d21892020-03-25 14:18:56 -070018#include <cstddef>
Josh Gaobd396c02020-01-22 18:02:19 -080019#include <iterator>
Alex Lightfbf96702017-12-14 13:27:13 -080020
21#include "adbconnection.h"
22
Josh Gaobd396c02020-01-22 18:02:19 -080023#include "adbconnection/client.h"
Alex Lightfbf96702017-12-14 13:27:13 -080024#include "android-base/endian.h"
25#include "android-base/stringprintf.h"
Andreas Gampedfcd82c2018-10-16 20:22:37 -070026#include "base/file_utils.h"
Alex Lightfbf96702017-12-14 13:27:13 -080027#include "base/logging.h"
28#include "base/macros.h"
29#include "base/mutex.h"
Alex Lightfc588092020-01-23 15:39:08 -080030#include "base/socket_peer_is_trusted.h"
31#include "debugger.h"
Vladimir Markoa3ad0cd2018-05-04 10:06:38 +010032#include "jni/java_vm_ext.h"
33#include "jni/jni_env_ext.h"
Alex Lightfbf96702017-12-14 13:27:13 -080034#include "mirror/throwable.h"
Orion Hodsond41c7592019-01-27 09:25:47 +000035#include "nativehelper/scoped_local_ref.h"
Alex Lightfbf96702017-12-14 13:27:13 -080036#include "runtime-inl.h"
37#include "runtime_callbacks.h"
38#include "scoped_thread_state_change-inl.h"
39#include "well_known_classes.h"
40
Alex Lightfbf96702017-12-14 13:27:13 -080041#include "fd_transport.h"
42
43#include "poll.h"
44
Alex Light15b81132018-01-24 13:29:07 -080045#include <sys/ioctl.h>
Alex Lightfbf96702017-12-14 13:27:13 -080046#include <sys/socket.h>
Alex Lightfc588092020-01-23 15:39:08 -080047#include <sys/uio.h>
Alex Lightfbf96702017-12-14 13:27:13 -080048#include <sys/un.h>
49#include <sys/eventfd.h>
50#include <jni.h>
51
52namespace adbconnection {
53
Alex Lightfc588092020-01-23 15:39:08 -080054static constexpr size_t kJdwpHeaderLen = 11U;
55/* DDM support */
56static constexpr uint8_t kJdwpDdmCmdSet = 199U; // 0xc7, or 'G'+128
57static constexpr uint8_t kJdwpDdmCmd = 1U;
58
Alex Light15b81132018-01-24 13:29:07 -080059// Messages sent from the transport
Alex Lightfbf96702017-12-14 13:27:13 -080060using dt_fd_forward::kListenStartMessage;
61using dt_fd_forward::kListenEndMessage;
62using dt_fd_forward::kAcceptMessage;
63using dt_fd_forward::kCloseMessage;
64
Alex Light15b81132018-01-24 13:29:07 -080065// Messages sent to the transport
66using dt_fd_forward::kPerformHandshakeMessage;
67using dt_fd_forward::kSkipHandshakeMessage;
68
Alex Lightfbf96702017-12-14 13:27:13 -080069using android::base::StringPrintf;
70
Alex Light15b81132018-01-24 13:29:07 -080071static constexpr const char kJdwpHandshake[14] = {
72 'J', 'D', 'W', 'P', '-', 'H', 'a', 'n', 'd', 's', 'h', 'a', 'k', 'e'
73};
74
Alex Lightfbf96702017-12-14 13:27:13 -080075static constexpr int kEventfdLocked = 0;
76static constexpr int kEventfdUnlocked = 1;
Alex Lightfbf96702017-12-14 13:27:13 -080077
Alex Light15b81132018-01-24 13:29:07 -080078static constexpr size_t kPacketHeaderLen = 11;
79static constexpr off_t kPacketSizeOff = 0;
80static constexpr off_t kPacketIdOff = 4;
81static constexpr off_t kPacketCommandSetOff = 9;
82static constexpr off_t kPacketCommandOff = 10;
83
84static constexpr uint8_t kDdmCommandSet = 199;
85static constexpr uint8_t kDdmChunkCommand = 1;
86
Flash Liu013e2082019-10-31 11:18:55 +080087static std::optional<AdbConnectionState> gState;
Alex Light75d21892020-03-25 14:18:56 -070088static std::optional<pthread_t> gPthread;
Alex Lightfbf96702017-12-14 13:27:13 -080089
90static bool IsDebuggingPossible() {
Alex Light2ce6fc82017-12-18 16:42:36 -080091 return art::Dbg::IsJdwpAllowed();
Alex Lightfbf96702017-12-14 13:27:13 -080092}
93
94// Begin running the debugger.
95void AdbConnectionDebuggerController::StartDebugger() {
Shukang Zhou670ea842020-02-06 14:53:14 -080096 // The debugger thread is started for a debuggable or profileable-from-shell process.
97 // The pid will be send to adbd for adb's "track-jdwp" and "track-app" services.
98 // The thread will also set up the jdwp tunnel if the process is debuggable.
99 if (IsDebuggingPossible() || art::Runtime::Current()->IsProfileableFromShell()) {
Alex Lightfbf96702017-12-14 13:27:13 -0800100 connection_->StartDebuggerThreads();
101 } else {
102 LOG(ERROR) << "Not starting debugger since process cannot load the jdwp agent.";
103 }
104}
105
Alex Light75d21892020-03-25 14:18:56 -0700106// The debugger should have already shut down since the runtime is ending. As far
107// as the agent is concerned shutdown already happened when we went to kDeath
108// state. We need to clean up our threads still though and this is a good time
109// to do it since the runtime is still able to handle all the normal state
110// transitions.
111void AdbConnectionDebuggerController::StopDebugger() {
112 // Stop our threads.
113 gState->StopDebuggerThreads();
114 // Wait for our threads to actually return and cleanup the pthread.
115 if (gPthread.has_value()) {
116 void* ret_unused;
117 if (TEMP_FAILURE_RETRY(pthread_join(gPthread.value(), &ret_unused)) != 0) {
118 PLOG(ERROR) << "Failed to join debugger threads!";
119 }
120 gPthread.reset();
121 }
122}
Alex Lightfbf96702017-12-14 13:27:13 -0800123
124bool AdbConnectionDebuggerController::IsDebuggerConfigured() {
125 return IsDebuggingPossible() && !art::Runtime::Current()->GetJdwpOptions().empty();
126}
127
128void AdbConnectionDdmCallback::DdmPublishChunk(uint32_t type,
129 const art::ArrayRef<const uint8_t>& data) {
130 connection_->PublishDdmData(type, data);
131}
132
133class ScopedEventFdLock {
134 public:
135 explicit ScopedEventFdLock(int fd) : fd_(fd), data_(0) {
136 TEMP_FAILURE_RETRY(read(fd_, &data_, sizeof(data_)));
137 }
138
139 ~ScopedEventFdLock() {
140 TEMP_FAILURE_RETRY(write(fd_, &data_, sizeof(data_)));
141 }
142
143 private:
144 int fd_;
145 uint64_t data_;
146};
147
148AdbConnectionState::AdbConnectionState(const std::string& agent_name)
149 : agent_name_(agent_name),
150 controller_(this),
151 ddm_callback_(this),
152 sleep_event_fd_(-1),
Josh Gaobd396c02020-01-22 18:02:19 -0800153 control_ctx_(nullptr, adbconnection_client_destroy),
Alex Lightfbf96702017-12-14 13:27:13 -0800154 local_agent_control_sock_(-1),
155 remote_agent_control_sock_(-1),
156 adb_connection_socket_(-1),
157 adb_write_event_fd_(-1),
158 shutting_down_(false),
159 agent_loaded_(false),
160 agent_listening_(false),
Alex Light15b81132018-01-24 13:29:07 -0800161 agent_has_socket_(false),
162 sent_agent_fds_(false),
163 performed_handshake_(false),
164 notified_ddm_active_(false),
Alex Lightd6f9d852018-01-25 11:26:28 -0800165 next_ddm_id_(1),
166 started_debugger_threads_(false) {
Alex Lightfbf96702017-12-14 13:27:13 -0800167 // Add the startup callback.
168 art::ScopedObjectAccess soa(art::Thread::Current());
169 art::Runtime::Current()->GetRuntimeCallbacks()->AddDebuggerControlCallback(&controller_);
170}
171
Flash Liu013e2082019-10-31 11:18:55 +0800172AdbConnectionState::~AdbConnectionState() {
173 // Remove the startup callback.
174 art::Thread* self = art::Thread::Current();
175 if (self != nullptr) {
176 art::ScopedObjectAccess soa(self);
177 art::Runtime::Current()->GetRuntimeCallbacks()->RemoveDebuggerControlCallback(&controller_);
178 }
179}
180
Alex Lightfbf96702017-12-14 13:27:13 -0800181static jobject CreateAdbConnectionThread(art::Thread* thr) {
182 JNIEnv* env = thr->GetJniEnv();
183 // Move to native state to talk with the jnienv api.
184 art::ScopedThreadStateChange stsc(thr, art::kNative);
185 ScopedLocalRef<jstring> thr_name(env, env->NewStringUTF(kAdbConnectionThreadName));
186 ScopedLocalRef<jobject> thr_group(
187 env,
188 env->GetStaticObjectField(art::WellKnownClasses::java_lang_ThreadGroup,
189 art::WellKnownClasses::java_lang_ThreadGroup_systemThreadGroup));
190 return env->NewObject(art::WellKnownClasses::java_lang_Thread,
191 art::WellKnownClasses::java_lang_Thread_init,
192 thr_group.get(),
193 thr_name.get(),
Andreas Gampe9b031f72018-10-04 11:03:34 -0700194 /*Priority=*/ 0,
195 /*Daemon=*/ true);
Alex Lightfbf96702017-12-14 13:27:13 -0800196}
197
198struct CallbackData {
199 AdbConnectionState* this_;
200 jobject thr_;
201};
202
203static void* CallbackFunction(void* vdata) {
204 std::unique_ptr<CallbackData> data(reinterpret_cast<CallbackData*>(vdata));
205 art::Thread* self = art::Thread::Attach(kAdbConnectionThreadName,
206 true,
207 data->thr_);
208 CHECK(self != nullptr) << "threads_being_born_ should have ensured thread could be attached.";
209 // The name in Attach() is only for logging. Set the thread name. This is important so
210 // that the thread is no longer seen as starting up.
211 {
212 art::ScopedObjectAccess soa(self);
213 self->SetThreadName(kAdbConnectionThreadName);
214 }
215
216 // Release the peer.
217 JNIEnv* env = self->GetJniEnv();
218 env->DeleteGlobalRef(data->thr_);
219 data->thr_ = nullptr;
220 {
221 // The StartThreadBirth was called in the parent thread. We let the runtime know we are up
222 // before going into the provided code.
223 art::MutexLock mu(self, *art::Locks::runtime_shutdown_lock_);
224 art::Runtime::Current()->EndThreadBirth();
225 }
226 data->this_->RunPollLoop(self);
227 int detach_result = art::Runtime::Current()->GetJavaVM()->DetachCurrentThread();
228 CHECK_EQ(detach_result, 0);
229
230 return nullptr;
231}
232
233void AdbConnectionState::StartDebuggerThreads() {
234 // First do all the final setup we need.
235 CHECK_EQ(adb_write_event_fd_.get(), -1);
236 CHECK_EQ(sleep_event_fd_.get(), -1);
237 CHECK_EQ(local_agent_control_sock_.get(), -1);
238 CHECK_EQ(remote_agent_control_sock_.get(), -1);
239
240 sleep_event_fd_.reset(eventfd(kEventfdLocked, EFD_CLOEXEC));
241 CHECK_NE(sleep_event_fd_.get(), -1) << "Unable to create wakeup eventfd.";
242 adb_write_event_fd_.reset(eventfd(kEventfdUnlocked, EFD_CLOEXEC));
243 CHECK_NE(adb_write_event_fd_.get(), -1) << "Unable to create write-lock eventfd.";
244
245 {
246 art::ScopedObjectAccess soa(art::Thread::Current());
247 art::Runtime::Current()->GetRuntimeCallbacks()->AddDdmCallback(&ddm_callback_);
248 }
249 // Setup the socketpair we use to talk to the agent.
250 bool has_sockets;
251 do {
252 has_sockets = android::base::Socketpair(AF_UNIX,
253 SOCK_SEQPACKET | SOCK_CLOEXEC,
254 0,
255 &local_agent_control_sock_,
256 &remote_agent_control_sock_);
257 } while (!has_sockets && errno == EINTR);
258 if (!has_sockets) {
259 PLOG(FATAL) << "Unable to create socketpair for agent control!";
260 }
261
262 // Next start the threads.
263 art::Thread* self = art::Thread::Current();
264 art::ScopedObjectAccess soa(self);
265 {
266 art::Runtime* runtime = art::Runtime::Current();
267 art::MutexLock mu(self, *art::Locks::runtime_shutdown_lock_);
268 if (runtime->IsShuttingDownLocked()) {
269 // The runtime is shutting down so we cannot create new threads. This shouldn't really happen.
270 LOG(ERROR) << "The runtime is shutting down when we are trying to start up the debugger!";
271 return;
272 }
273 runtime->StartThreadBirth();
274 }
275 ScopedLocalRef<jobject> thr(soa.Env(), CreateAdbConnectionThread(soa.Self()));
Andreas Gampeafaf7f82018-10-16 11:32:38 -0700276 // Note: Using pthreads instead of std::thread to not abort when the thread cannot be
277 // created (exception support required).
Alex Lightfbf96702017-12-14 13:27:13 -0800278 std::unique_ptr<CallbackData> data(new CallbackData { this, soa.Env()->NewGlobalRef(thr.get()) });
Alex Lightd6f9d852018-01-25 11:26:28 -0800279 started_debugger_threads_ = true;
Alex Light75d21892020-03-25 14:18:56 -0700280 gPthread.emplace();
281 int pthread_create_result = pthread_create(&gPthread.value(),
Alex Lightfbf96702017-12-14 13:27:13 -0800282 nullptr,
283 &CallbackFunction,
284 data.get());
285 if (pthread_create_result != 0) {
Alex Light75d21892020-03-25 14:18:56 -0700286 gPthread.reset();
Alex Lightd6f9d852018-01-25 11:26:28 -0800287 started_debugger_threads_ = false;
Alex Lightfbf96702017-12-14 13:27:13 -0800288 // If the create succeeded the other thread will call EndThreadBirth.
289 art::Runtime* runtime = art::Runtime::Current();
290 soa.Env()->DeleteGlobalRef(data->thr_);
291 LOG(ERROR) << "Failed to create thread for adb-jdwp connection manager!";
292 art::MutexLock mu(art::Thread::Current(), *art::Locks::runtime_shutdown_lock_);
293 runtime->EndThreadBirth();
294 return;
295 }
Andreas Gampeafaf7f82018-10-16 11:32:38 -0700296 data.release(); // NOLINT pthreads API.
Alex Lightfbf96702017-12-14 13:27:13 -0800297}
298
299static bool FlagsSet(int16_t data, int16_t flags) {
300 return (data & flags) == flags;
301}
302
303void AdbConnectionState::CloseFds() {
Alex Light15b81132018-01-24 13:29:07 -0800304 {
305 // Lock the write_event_fd so that concurrent PublishDdms will see that the connection is
306 // closed.
307 ScopedEventFdLock lk(adb_write_event_fd_);
308 // shutdown(adb_connection_socket_, SHUT_RDWR);
309 adb_connection_socket_.reset();
310 }
311
312 // If we didn't load anything we will need to do the handshake again.
313 performed_handshake_ = false;
314
315 // If the agent isn't loaded we might need to tell ddms code the connection is closed.
316 if (!agent_loaded_ && notified_ddm_active_) {
Andreas Gampe9b031f72018-10-04 11:03:34 -0700317 NotifyDdms(/*active=*/false);
Alex Light15b81132018-01-24 13:29:07 -0800318 }
319}
320
321void AdbConnectionState::NotifyDdms(bool active) {
322 art::ScopedObjectAccess soa(art::Thread::Current());
323 DCHECK_NE(notified_ddm_active_, active);
324 notified_ddm_active_ = active;
325 if (active) {
326 art::Dbg::DdmConnected();
327 } else {
328 art::Dbg::DdmDisconnected();
329 }
Alex Lightfbf96702017-12-14 13:27:13 -0800330}
331
332uint32_t AdbConnectionState::NextDdmId() {
333 // Just have a normal counter but always set the sign bit.
334 return (next_ddm_id_++) | 0x80000000;
335}
336
337void AdbConnectionState::PublishDdmData(uint32_t type, const art::ArrayRef<const uint8_t>& data) {
Alex Light15b81132018-01-24 13:29:07 -0800338 SendDdmPacket(NextDdmId(), DdmPacketType::kCmd, type, data);
339}
340
341void AdbConnectionState::SendDdmPacket(uint32_t id,
342 DdmPacketType packet_type,
343 uint32_t type,
344 art::ArrayRef<const uint8_t> data) {
Alex Lightfbf96702017-12-14 13:27:13 -0800345 // Get the write_event early to fail fast.
346 ScopedEventFdLock lk(adb_write_event_fd_);
347 if (adb_connection_socket_ == -1) {
Alex Lighta17cc2e2018-02-02 13:56:14 -0800348 VLOG(jdwp) << "Not sending ddms data of type "
349 << StringPrintf("%c%c%c%c",
350 static_cast<char>(type >> 24),
351 static_cast<char>(type >> 16),
352 static_cast<char>(type >> 8),
353 static_cast<char>(type)) << " due to no connection!";
Alex Lightfbf96702017-12-14 13:27:13 -0800354 // Adb is not connected.
355 return;
356 }
357
358 // the adb_write_event_fd_ will ensure that the adb_connection_socket_ will not go away until
359 // after we have sent our data.
360 static constexpr uint32_t kDdmPacketHeaderSize =
Alex Lightfc588092020-01-23 15:39:08 -0800361 kJdwpHeaderLen // jdwp command packet size
Alex Lightfbf96702017-12-14 13:27:13 -0800362 + sizeof(uint32_t) // Type
363 + sizeof(uint32_t); // length
Alex Light15b81132018-01-24 13:29:07 -0800364 alignas(sizeof(uint32_t)) std::array<uint8_t, kDdmPacketHeaderSize> pkt;
Alex Lightfbf96702017-12-14 13:27:13 -0800365 uint8_t* pkt_data = pkt.data();
366
367 // Write the length first.
368 *reinterpret_cast<uint32_t*>(pkt_data) = htonl(kDdmPacketHeaderSize + data.size());
369 pkt_data += sizeof(uint32_t);
370
371 // Write the id next;
Alex Light15b81132018-01-24 13:29:07 -0800372 *reinterpret_cast<uint32_t*>(pkt_data) = htonl(id);
Alex Lightfbf96702017-12-14 13:27:13 -0800373 pkt_data += sizeof(uint32_t);
374
375 // next the flags. (0 for cmd packet because DDMS).
Alex Light15b81132018-01-24 13:29:07 -0800376 *(pkt_data++) = static_cast<uint8_t>(packet_type);
377 switch (packet_type) {
378 case DdmPacketType::kCmd: {
379 // Now the cmd-set
Alex Lightfc588092020-01-23 15:39:08 -0800380 *(pkt_data++) = kJdwpDdmCmdSet;
Alex Light15b81132018-01-24 13:29:07 -0800381 // Now the command
Alex Lightfc588092020-01-23 15:39:08 -0800382 *(pkt_data++) = kJdwpDdmCmd;
Alex Light15b81132018-01-24 13:29:07 -0800383 break;
384 }
385 case DdmPacketType::kReply: {
386 // This is the error code bytes which are all 0
387 *(pkt_data++) = 0;
388 *(pkt_data++) = 0;
389 }
390 }
Alex Lightfbf96702017-12-14 13:27:13 -0800391
Alex Light15b81132018-01-24 13:29:07 -0800392 // These are at unaligned addresses so we need to do them manually.
Alex Lightfbf96702017-12-14 13:27:13 -0800393 // now the type.
Alex Light15b81132018-01-24 13:29:07 -0800394 uint32_t net_type = htonl(type);
395 memcpy(pkt_data, &net_type, sizeof(net_type));
Alex Lightfbf96702017-12-14 13:27:13 -0800396 pkt_data += sizeof(uint32_t);
397
398 // Now the data.size()
Alex Light15b81132018-01-24 13:29:07 -0800399 uint32_t net_len = htonl(data.size());
400 memcpy(pkt_data, &net_len, sizeof(net_len));
Alex Lightfbf96702017-12-14 13:27:13 -0800401 pkt_data += sizeof(uint32_t);
402
403 static uint32_t constexpr kIovSize = 2;
404 struct iovec iovs[kIovSize] = {
405 { pkt.data(), pkt.size() },
406 { const_cast<uint8_t*>(data.data()), data.size() },
407 };
408 // now pkt_header has the header.
409 // use writev to send the actual data.
410 ssize_t res = TEMP_FAILURE_RETRY(writev(adb_connection_socket_, iovs, kIovSize));
411 if (static_cast<size_t>(res) != (kDdmPacketHeaderSize + data.size())) {
412 PLOG(ERROR) << StringPrintf("Failed to send DDMS packet %c%c%c%c to debugger (%zd of %zu)",
413 static_cast<char>(type >> 24),
414 static_cast<char>(type >> 16),
415 static_cast<char>(type >> 8),
416 static_cast<char>(type),
417 res, data.size() + kDdmPacketHeaderSize);
418 } else {
419 VLOG(jdwp) << StringPrintf("sent DDMS packet %c%c%c%c to debugger %zu",
420 static_cast<char>(type >> 24),
421 static_cast<char>(type >> 16),
422 static_cast<char>(type >> 8),
423 static_cast<char>(type),
424 data.size() + kDdmPacketHeaderSize);
425 }
426}
427
Alex Light15b81132018-01-24 13:29:07 -0800428void AdbConnectionState::SendAgentFds(bool require_handshake) {
Alex Lightfbf96702017-12-14 13:27:13 -0800429 DCHECK(!sent_agent_fds_);
Alex Light15b81132018-01-24 13:29:07 -0800430 const char* message = require_handshake ? kPerformHandshakeMessage : kSkipHandshakeMessage;
Alex Lightfbf96702017-12-14 13:27:13 -0800431 union {
432 cmsghdr cm;
433 char buffer[CMSG_SPACE(dt_fd_forward::FdSet::kDataLength)];
434 } cm_un;
435 iovec iov;
Alex Light15b81132018-01-24 13:29:07 -0800436 iov.iov_base = const_cast<char*>(message);
437 iov.iov_len = strlen(message) + 1;
Alex Lightfbf96702017-12-14 13:27:13 -0800438
439 msghdr msg;
440 msg.msg_name = nullptr;
441 msg.msg_namelen = 0;
442 msg.msg_iov = &iov;
443 msg.msg_iovlen = 1;
444 msg.msg_flags = 0;
445 msg.msg_control = cm_un.buffer;
446 msg.msg_controllen = sizeof(cm_un.buffer);
447
448 cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
449 cmsg->cmsg_len = CMSG_LEN(dt_fd_forward::FdSet::kDataLength);
450 cmsg->cmsg_level = SOL_SOCKET;
451 cmsg->cmsg_type = SCM_RIGHTS;
452
453 // Duplicate the fds before sending them.
Andreas Gampedfcd82c2018-10-16 20:22:37 -0700454 android::base::unique_fd read_fd(art::DupCloexec(adb_connection_socket_));
Alex Lightfbf96702017-12-14 13:27:13 -0800455 CHECK_NE(read_fd.get(), -1) << "Failed to dup read_fd_: " << strerror(errno);
Andreas Gampedfcd82c2018-10-16 20:22:37 -0700456 android::base::unique_fd write_fd(art::DupCloexec(adb_connection_socket_));
Alex Lightfbf96702017-12-14 13:27:13 -0800457 CHECK_NE(write_fd.get(), -1) << "Failed to dup write_fd: " << strerror(errno);
Andreas Gampedfcd82c2018-10-16 20:22:37 -0700458 android::base::unique_fd write_lock_fd(art::DupCloexec(adb_write_event_fd_));
Alex Lightfbf96702017-12-14 13:27:13 -0800459 CHECK_NE(write_lock_fd.get(), -1) << "Failed to dup write_lock_fd: " << strerror(errno);
460
461 dt_fd_forward::FdSet {
462 read_fd.get(), write_fd.get(), write_lock_fd.get()
463 }.WriteData(CMSG_DATA(cmsg));
464
465 int res = TEMP_FAILURE_RETRY(sendmsg(local_agent_control_sock_, &msg, MSG_EOR));
466 if (res < 0) {
467 PLOG(ERROR) << "Failed to send agent adb connection fds.";
468 } else {
469 sent_agent_fds_ = true;
470 VLOG(jdwp) << "Fds have been sent to jdwp agent!";
471 }
472}
473
474android::base::unique_fd AdbConnectionState::ReadFdFromAdb() {
Josh Gaobd396c02020-01-22 18:02:19 -0800475 return android::base::unique_fd(adbconnection_client_receive_jdwp_fd(control_ctx_.get()));
Alex Lightfbf96702017-12-14 13:27:13 -0800476}
477
478bool AdbConnectionState::SetupAdbConnection() {
Josh Gaobd396c02020-01-22 18:02:19 -0800479 int sleep_ms = 500;
480 const int sleep_max_ms = 2 * 1000;
Alex Lightfbf96702017-12-14 13:27:13 -0800481
Shukang Zhou670ea842020-02-06 14:53:14 -0800482 const char* isa = GetInstructionSetString(art::Runtime::Current()->GetInstructionSet());
Josh Gaobd396c02020-01-22 18:02:19 -0800483 const AdbConnectionClientInfo infos[] = {
Shukang Zhou670ea842020-02-06 14:53:14 -0800484 {.type = AdbConnectionClientInfoType::pid,
485 .data.pid = static_cast<uint64_t>(getpid())},
486 {.type = AdbConnectionClientInfoType::debuggable,
487 .data.debuggable = IsDebuggingPossible()},
488 {.type = AdbConnectionClientInfoType::profileable,
489 .data.profileable = art::Runtime::Current()->IsProfileableFromShell()},
490 {.type = AdbConnectionClientInfoType::architecture,
491 // GetInstructionSetString() returns a null-terminating C-style string.
492 .data.architecture.name = isa,
493 .data.architecture.size = strlen(isa)},
Josh Gaobd396c02020-01-22 18:02:19 -0800494 };
Shukang Zhou670ea842020-02-06 14:53:14 -0800495 const AdbConnectionClientInfo *info_ptrs[] = {&infos[0], &infos[1], &infos[2], &infos[3]};
Alex Lightfbf96702017-12-14 13:27:13 -0800496
497 while (!shutting_down_) {
498 // If adbd isn't running, because USB debugging was disabled or
499 // perhaps the system is restarting it for "adb root", the
500 // connect() will fail. We loop here forever waiting for it
501 // to come back.
502 //
503 // Waking up and polling every couple of seconds is generally a
504 // bad thing to do, but we only do this if the application is
505 // debuggable *and* adbd isn't running. Still, for the sake
506 // of battery life, we should consider timing out and giving
507 // up after a few minutes in case somebody ships an app with
508 // the debuggable flag set.
Josh Gaobd396c02020-01-22 18:02:19 -0800509 control_ctx_.reset(adbconnection_client_new(info_ptrs, std::size(infos)));
510 if (control_ctx_) {
511 return true;
512 }
Alex Lightfbf96702017-12-14 13:27:13 -0800513
Josh Gaobd396c02020-01-22 18:02:19 -0800514 // We failed to connect.
515 usleep(sleep_ms * 1000);
Alex Lightfbf96702017-12-14 13:27:13 -0800516
Josh Gaobd396c02020-01-22 18:02:19 -0800517 sleep_ms += (sleep_ms >> 1);
518 if (sleep_ms > sleep_max_ms) {
519 sleep_ms = sleep_max_ms;
Alex Lightfbf96702017-12-14 13:27:13 -0800520 }
521 }
Josh Gaobd396c02020-01-22 18:02:19 -0800522
Alex Lightfbf96702017-12-14 13:27:13 -0800523 return false;
524}
525
526void AdbConnectionState::RunPollLoop(art::Thread* self) {
Shukang Zhou670ea842020-02-06 14:53:14 -0800527 DCHECK(IsDebuggingPossible() || art::Runtime::Current()->IsProfileableFromShell());
Alex Lightd6f9d852018-01-25 11:26:28 -0800528 CHECK_NE(agent_name_, "");
Alex Lightfbf96702017-12-14 13:27:13 -0800529 CHECK_EQ(self->GetState(), art::kNative);
Ziang Wan92db59b2019-07-22 21:19:24 +0000530 art::Locks::mutator_lock_->AssertNotHeld(self);
Alex Lightfbf96702017-12-14 13:27:13 -0800531 self->SetState(art::kWaitingInMainDebuggerLoop);
532 // shutting_down_ set by StopDebuggerThreads
533 while (!shutting_down_) {
Josh Gaobd396c02020-01-22 18:02:19 -0800534 // First, connect to adbd if we haven't already.
535 if (!control_ctx_ && !SetupAdbConnection()) {
Alex Lightfbf96702017-12-14 13:27:13 -0800536 LOG(ERROR) << "Failed to setup adb connection.";
537 return;
538 }
Josh Gaobd396c02020-01-22 18:02:19 -0800539 while (!shutting_down_ && control_ctx_) {
Alex Light15b81132018-01-24 13:29:07 -0800540 bool should_listen_on_connection = !agent_has_socket_ && !sent_agent_fds_;
Alex Lightfbf96702017-12-14 13:27:13 -0800541 struct pollfd pollfds[4] = {
542 { sleep_event_fd_, POLLIN, 0 },
543 // -1 as an fd causes it to be ignored by poll
544 { (agent_loaded_ ? local_agent_control_sock_ : -1), POLLIN, 0 },
545 // Check for the control_sock_ actually going away. Only do this if we don't have an active
546 // connection.
Josh Gaobd396c02020-01-22 18:02:19 -0800547 { (adb_connection_socket_ == -1 ? adbconnection_client_pollfd(control_ctx_.get()) : -1),
548 POLLIN | POLLRDHUP, 0 },
Alex Lightfbf96702017-12-14 13:27:13 -0800549 // if we have not loaded the agent either the adb_connection_socket_ is -1 meaning we don't
550 // have a real connection yet or the socket through adb needs to be listened to for incoming
Alex Light15b81132018-01-24 13:29:07 -0800551 // data that the agent or this plugin can handle.
552 { should_listen_on_connection ? adb_connection_socket_ : -1, POLLIN | POLLRDHUP, 0 }
Alex Lightfbf96702017-12-14 13:27:13 -0800553 };
554 int res = TEMP_FAILURE_RETRY(poll(pollfds, 4, -1));
555 if (res < 0) {
556 PLOG(ERROR) << "Failed to poll!";
557 return;
558 }
559 // We don't actually care about doing this we just use it to wake us up.
560 // const struct pollfd& sleep_event_poll = pollfds[0];
561 const struct pollfd& agent_control_sock_poll = pollfds[1];
562 const struct pollfd& control_sock_poll = pollfds[2];
563 const struct pollfd& adb_socket_poll = pollfds[3];
564 if (FlagsSet(agent_control_sock_poll.revents, POLLIN)) {
Shukang Zhou670ea842020-02-06 14:53:14 -0800565 CHECK(IsDebuggingPossible()); // This path is unexpected for a profileable process.
Alex Lightfbf96702017-12-14 13:27:13 -0800566 DCHECK(agent_loaded_);
567 char buf[257];
568 res = TEMP_FAILURE_RETRY(recv(local_agent_control_sock_, buf, sizeof(buf) - 1, 0));
569 if (res < 0) {
570 PLOG(ERROR) << "Failed to read message from agent control socket! Retrying";
571 continue;
572 } else {
573 buf[res + 1] = '\0';
574 VLOG(jdwp) << "Local agent control sock has data: " << static_cast<const char*>(buf);
575 }
576 if (memcmp(kListenStartMessage, buf, sizeof(kListenStartMessage)) == 0) {
577 agent_listening_ = true;
578 if (adb_connection_socket_ != -1) {
Andreas Gampe9b031f72018-10-04 11:03:34 -0700579 SendAgentFds(/*require_handshake=*/ !performed_handshake_);
Alex Lightfbf96702017-12-14 13:27:13 -0800580 }
581 } else if (memcmp(kListenEndMessage, buf, sizeof(kListenEndMessage)) == 0) {
582 agent_listening_ = false;
583 } else if (memcmp(kCloseMessage, buf, sizeof(kCloseMessage)) == 0) {
584 CloseFds();
585 agent_has_socket_ = false;
586 } else if (memcmp(kAcceptMessage, buf, sizeof(kAcceptMessage)) == 0) {
587 agent_has_socket_ = true;
588 sent_agent_fds_ = false;
Alex Light15b81132018-01-24 13:29:07 -0800589 // We will only ever do the handshake once so reset this.
590 performed_handshake_ = false;
Alex Lightfbf96702017-12-14 13:27:13 -0800591 } else {
592 LOG(ERROR) << "Unknown message received from debugger! '" << std::string(buf) << "'";
593 }
594 } else if (FlagsSet(control_sock_poll.revents, POLLIN)) {
Shukang Zhou670ea842020-02-06 14:53:14 -0800595 if (!IsDebuggingPossible()) {
596 // For a profielable process, this path can execute when the adbd restarts.
597 control_ctx_.reset();
598 break;
599 }
Alex Lightfbf96702017-12-14 13:27:13 -0800600 bool maybe_send_fds = false;
601 {
602 // Hold onto this lock so that concurrent ddm publishes don't try to use an illegal fd.
603 ScopedEventFdLock sefdl(adb_write_event_fd_);
Josh Gaobd396c02020-01-22 18:02:19 -0800604 android::base::unique_fd new_fd(adbconnection_client_receive_jdwp_fd(control_ctx_.get()));
Alex Lightfbf96702017-12-14 13:27:13 -0800605 if (new_fd == -1) {
606 // Something went wrong. We need to retry getting the control socket.
Josh Gaobd396c02020-01-22 18:02:19 -0800607 control_ctx_.reset();
Alex Lightfbf96702017-12-14 13:27:13 -0800608 break;
609 } else if (adb_connection_socket_ != -1) {
610 // We already have a connection.
611 VLOG(jdwp) << "Ignoring second debugger. Accept then drop!";
612 if (new_fd >= 0) {
613 new_fd.reset();
614 }
615 } else {
616 VLOG(jdwp) << "Adb connection established with fd " << new_fd;
617 adb_connection_socket_ = std::move(new_fd);
618 maybe_send_fds = true;
619 }
620 }
621 if (maybe_send_fds && agent_loaded_ && agent_listening_) {
622 VLOG(jdwp) << "Sending fds as soon as we received them.";
Alex Light15b81132018-01-24 13:29:07 -0800623 // The agent was already loaded so this must be after a disconnection. Therefore have the
624 // transport perform the handshake.
Andreas Gampe9b031f72018-10-04 11:03:34 -0700625 SendAgentFds(/*require_handshake=*/ true);
Alex Lightfbf96702017-12-14 13:27:13 -0800626 }
627 } else if (FlagsSet(control_sock_poll.revents, POLLRDHUP)) {
628 // The other end of the adb connection just dropped it.
629 // Reset the connection since we don't have an active socket through the adb server.
Shukang Zhou670ea842020-02-06 14:53:14 -0800630 // Note this path is expected for either debuggable or profileable processes.
Alex Lightfbf96702017-12-14 13:27:13 -0800631 DCHECK(!agent_has_socket_) << "We shouldn't be doing anything if there is already a "
632 << "connection active";
Josh Gaobd396c02020-01-22 18:02:19 -0800633 control_ctx_.reset();
Alex Lightfbf96702017-12-14 13:27:13 -0800634 break;
635 } else if (FlagsSet(adb_socket_poll.revents, POLLIN)) {
Shukang Zhou670ea842020-02-06 14:53:14 -0800636 CHECK(IsDebuggingPossible()); // This path is unexpected for a profileable process.
Alex Lightfbf96702017-12-14 13:27:13 -0800637 DCHECK(!agent_has_socket_);
638 if (!agent_loaded_) {
Alex Light15b81132018-01-24 13:29:07 -0800639 HandleDataWithoutAgent(self);
Alex Lightfbf96702017-12-14 13:27:13 -0800640 } else if (agent_listening_ && !sent_agent_fds_) {
641 VLOG(jdwp) << "Sending agent fds again on data.";
Alex Light15b81132018-01-24 13:29:07 -0800642 // Agent was already loaded so it can deal with the handshake.
Andreas Gampe9b031f72018-10-04 11:03:34 -0700643 SendAgentFds(/*require_handshake=*/ true);
Alex Lightfbf96702017-12-14 13:27:13 -0800644 }
Alex Light15b81132018-01-24 13:29:07 -0800645 } else if (FlagsSet(adb_socket_poll.revents, POLLRDHUP)) {
Shukang Zhou670ea842020-02-06 14:53:14 -0800646 CHECK(IsDebuggingPossible()); // This path is unexpected for a profileable process.
Alex Light15b81132018-01-24 13:29:07 -0800647 DCHECK(!agent_has_socket_);
648 CloseFds();
Alex Lightfbf96702017-12-14 13:27:13 -0800649 } else {
650 VLOG(jdwp) << "Woke up poll without anything to do!";
651 }
652 }
653 }
654}
655
Alex Light15b81132018-01-24 13:29:07 -0800656static uint32_t ReadUint32AndAdvance(/*in-out*/uint8_t** in) {
657 uint32_t res;
658 memcpy(&res, *in, sizeof(uint32_t));
659 *in = (*in) + sizeof(uint32_t);
660 return ntohl(res);
661}
662
663void AdbConnectionState::HandleDataWithoutAgent(art::Thread* self) {
664 DCHECK(!agent_loaded_);
665 DCHECK(!agent_listening_);
666 // TODO Should we check in some other way if we are userdebug/eng?
667 CHECK(art::Dbg::IsJdwpAllowed());
668 // We try to avoid loading the agent which is expensive. First lets just perform the handshake.
669 if (!performed_handshake_) {
670 PerformHandshake();
671 return;
672 }
673 // Read the packet header to figure out if it is one we can handle. We only 'peek' into the stream
674 // to see if it's one we can handle. This doesn't change the state of the socket.
675 alignas(sizeof(uint32_t)) uint8_t packet_header[kPacketHeaderLen];
676 ssize_t res = TEMP_FAILURE_RETRY(recv(adb_connection_socket_.get(),
677 packet_header,
678 sizeof(packet_header),
679 MSG_PEEK));
680 // We want to be very careful not to change the socket state until we know we succeeded. This will
681 // let us fall-back to just loading the agent and letting it deal with everything.
682 if (res <= 0) {
683 // Close the socket. We either hit EOF or an error.
684 if (res < 0) {
685 PLOG(ERROR) << "Unable to peek into adb socket due to error. Closing socket.";
686 }
687 CloseFds();
688 return;
689 } else if (res < static_cast<int>(kPacketHeaderLen)) {
690 LOG(ERROR) << "Unable to peek into adb socket. Loading agent to handle this. Only read " << res;
691 AttachJdwpAgent(self);
692 return;
693 }
694 uint32_t full_len = ntohl(*reinterpret_cast<uint32_t*>(packet_header + kPacketSizeOff));
695 uint32_t pkt_id = ntohl(*reinterpret_cast<uint32_t*>(packet_header + kPacketIdOff));
696 uint8_t pkt_cmd_set = packet_header[kPacketCommandSetOff];
697 uint8_t pkt_cmd = packet_header[kPacketCommandOff];
698 if (pkt_cmd_set != kDdmCommandSet ||
699 pkt_cmd != kDdmChunkCommand ||
700 full_len < kPacketHeaderLen) {
701 VLOG(jdwp) << "Loading agent due to jdwp packet that cannot be handled by adbconnection.";
702 AttachJdwpAgent(self);
703 return;
704 }
705 uint32_t avail = -1;
706 res = TEMP_FAILURE_RETRY(ioctl(adb_connection_socket_.get(), FIONREAD, &avail));
707 if (res < 0) {
708 PLOG(ERROR) << "Failed to determine amount of readable data in socket! Closing connection";
709 CloseFds();
710 return;
711 } else if (avail < full_len) {
712 LOG(WARNING) << "Unable to handle ddm command in adbconnection due to insufficent data. "
713 << "Expected " << full_len << " bytes but only " << avail << " are readable. "
714 << "Loading jdwp agent to deal with this.";
715 AttachJdwpAgent(self);
716 return;
717 }
718 // Actually read the data.
719 std::vector<uint8_t> full_pkt;
720 full_pkt.resize(full_len);
721 res = TEMP_FAILURE_RETRY(recv(adb_connection_socket_.get(), full_pkt.data(), full_len, 0));
722 if (res < 0) {
723 PLOG(ERROR) << "Failed to recv data from adb connection. Closing connection";
724 CloseFds();
725 return;
726 }
727 DCHECK_EQ(memcmp(full_pkt.data(), packet_header, sizeof(packet_header)), 0);
728 size_t data_size = full_len - kPacketHeaderLen;
729 if (data_size < (sizeof(uint32_t) * 2)) {
730 // This is an error (the data isn't long enough) but to match historical behavior we need to
731 // ignore it.
732 return;
733 }
734 uint8_t* ddm_data = full_pkt.data() + kPacketHeaderLen;
735 uint32_t ddm_type = ReadUint32AndAdvance(&ddm_data);
736 uint32_t ddm_len = ReadUint32AndAdvance(&ddm_data);
737 if (ddm_len > data_size - (2 * sizeof(uint32_t))) {
738 // This is an error (the data isn't long enough) but to match historical behavior we need to
739 // ignore it.
740 return;
741 }
742
743 if (!notified_ddm_active_) {
Andreas Gampe9b031f72018-10-04 11:03:34 -0700744 NotifyDdms(/*active=*/ true);
Alex Light15b81132018-01-24 13:29:07 -0800745 }
746 uint32_t reply_type;
747 std::vector<uint8_t> reply;
748 if (!art::Dbg::DdmHandleChunk(self->GetJniEnv(),
749 ddm_type,
750 art::ArrayRef<const jbyte>(reinterpret_cast<const jbyte*>(ddm_data),
751 ddm_len),
752 /*out*/&reply_type,
753 /*out*/&reply)) {
754 // To match historical behavior we don't send any response when there is no data to reply with.
755 return;
756 }
757 SendDdmPacket(pkt_id,
758 DdmPacketType::kReply,
759 reply_type,
760 art::ArrayRef<const uint8_t>(reply));
761}
762
763void AdbConnectionState::PerformHandshake() {
764 CHECK(!performed_handshake_);
765 // Check to make sure we are able to read the whole handshake.
766 uint32_t avail = -1;
767 int res = TEMP_FAILURE_RETRY(ioctl(adb_connection_socket_.get(), FIONREAD, &avail));
768 if (res < 0 || avail < sizeof(kJdwpHandshake)) {
769 if (res < 0) {
770 PLOG(ERROR) << "Failed to determine amount of readable data for handshake!";
771 }
772 LOG(WARNING) << "Closing connection to broken client.";
773 CloseFds();
774 return;
775 }
776 // Perform the handshake.
777 char handshake_msg[sizeof(kJdwpHandshake)];
778 res = TEMP_FAILURE_RETRY(recv(adb_connection_socket_.get(),
779 handshake_msg,
780 sizeof(handshake_msg),
781 MSG_DONTWAIT));
782 if (res < static_cast<int>(sizeof(kJdwpHandshake)) ||
783 strncmp(handshake_msg, kJdwpHandshake, sizeof(kJdwpHandshake)) != 0) {
784 if (res < 0) {
785 PLOG(ERROR) << "Failed to read handshake!";
786 }
787 LOG(WARNING) << "Handshake failed!";
788 CloseFds();
789 return;
790 }
791 // Send the handshake back.
792 res = TEMP_FAILURE_RETRY(send(adb_connection_socket_.get(),
793 kJdwpHandshake,
794 sizeof(kJdwpHandshake),
795 0));
796 if (res < static_cast<int>(sizeof(kJdwpHandshake))) {
797 PLOG(ERROR) << "Failed to send jdwp-handshake response.";
798 CloseFds();
799 return;
800 }
801 performed_handshake_ = true;
802}
803
804void AdbConnectionState::AttachJdwpAgent(art::Thread* self) {
Alex Lightbd2a4e22018-04-17 09:07:37 -0700805 art::Runtime* runtime = art::Runtime::Current();
Alex Light15b81132018-01-24 13:29:07 -0800806 self->AssertNoPendingException();
Andreas Gampe9b031f72018-10-04 11:03:34 -0700807 runtime->AttachAgent(/* env= */ nullptr,
Alex Lightbd2a4e22018-04-17 09:07:37 -0700808 MakeAgentArg(),
Andreas Gampe9b031f72018-10-04 11:03:34 -0700809 /* class_loader= */ nullptr);
Alex Light15b81132018-01-24 13:29:07 -0800810 if (self->IsExceptionPending()) {
811 LOG(ERROR) << "Failed to load agent " << agent_name_;
812 art::ScopedObjectAccess soa(self);
813 self->GetException()->Dump();
814 self->ClearException();
815 return;
816 }
817 agent_loaded_ = true;
818}
819
Alex Light81f75c32018-01-26 09:46:32 -0800820bool ContainsArgument(const std::string& opts, const char* arg) {
821 return opts.find(arg) != std::string::npos;
822}
823
824bool ValidateJdwpOptions(const std::string& opts) {
825 bool res = true;
826 // The adbconnection plugin requires that the jdwp agent be configured as a 'server' because that
827 // is what adb expects and otherwise we will hit a deadlock as the poll loop thread stops waiting
828 // for the fd's to be passed down.
829 if (ContainsArgument(opts, "server=n")) {
830 res = false;
831 LOG(ERROR) << "Cannot start jdwp debugging with server=n from adbconnection.";
832 }
833 // We don't start the jdwp agent until threads are already running. It is far too late to suspend
834 // everything.
835 if (ContainsArgument(opts, "suspend=y")) {
836 res = false;
837 LOG(ERROR) << "Cannot use suspend=y with late-init jdwp.";
838 }
839 return res;
840}
841
Alex Lightfbf96702017-12-14 13:27:13 -0800842std::string AdbConnectionState::MakeAgentArg() {
Alex Lightfbf96702017-12-14 13:27:13 -0800843 const std::string& opts = art::Runtime::Current()->GetJdwpOptions();
Alex Light81f75c32018-01-26 09:46:32 -0800844 DCHECK(ValidateJdwpOptions(opts));
845 // TODO Get agent_name_ from something user settable?
846 return agent_name_ + "=" + opts + (opts.empty() ? "" : ",") +
847 "ddm_already_active=" + (notified_ddm_active_ ? "y" : "n") + "," +
848 // See the comment above for why we need to be server=y. Since the agent defaults to server=n
849 // we will add it if it wasn't already present for the convenience of the user.
850 (ContainsArgument(opts, "server=y") ? "" : "server=y,") +
851 // See the comment above for why we need to be suspend=n. Since the agent defaults to
852 // suspend=y we will add it if it wasn't already present.
Alex Light5ebdc882018-06-04 16:42:30 -0700853 (ContainsArgument(opts, "suspend=n") ? "" : "suspend=n,") +
Alex Light81f75c32018-01-26 09:46:32 -0800854 "transport=dt_fd_forward,address=" + std::to_string(remote_agent_control_sock_);
Alex Lightfbf96702017-12-14 13:27:13 -0800855}
856
857void AdbConnectionState::StopDebuggerThreads() {
858 // The regular agent system will take care of unloading the agent (if needed).
859 shutting_down_ = true;
860 // Wakeup the poll loop.
861 uint64_t data = 1;
Alex Lightd6f9d852018-01-25 11:26:28 -0800862 if (sleep_event_fd_ != -1) {
863 TEMP_FAILURE_RETRY(write(sleep_event_fd_, &data, sizeof(data)));
864 }
Alex Lightfbf96702017-12-14 13:27:13 -0800865}
866
867// The plugin initialization function.
Alex Light3b08bcc2019-09-11 09:48:51 -0700868extern "C" bool ArtPlugin_Initialize() {
Alex Lightfbf96702017-12-14 13:27:13 -0800869 DCHECK(art::Runtime::Current()->GetJdwpProvider() == art::JdwpProvider::kAdbConnection);
870 // TODO Provide some way for apps to set this maybe?
Flash Liu013e2082019-10-31 11:18:55 +0800871 gState.emplace(kDefaultJdwpAgentName);
Alex Light81f75c32018-01-26 09:46:32 -0800872 return ValidateJdwpOptions(art::Runtime::Current()->GetJdwpOptions());
Alex Lightfbf96702017-12-14 13:27:13 -0800873}
874
875extern "C" bool ArtPlugin_Deinitialize() {
Alex Light75d21892020-03-25 14:18:56 -0700876 // We don't actually have to do anything here. The debugger (if one was
877 // attached) was shutdown by the move to the kDeath runtime phase and the
878 // adbconnection threads were shutdown by StopDebugger.
Alex Lightfbf96702017-12-14 13:27:13 -0800879 return true;
880}
881
882} // namespace adbconnection