blob: bdbb80bd587f39eb5d0a04e7fb8232c982569ca2 [file] [log] [blame]
Narayan Kamath8b2c8b92014-03-31 16:44:54 +01001/*
2 * Copyright (C) 2008 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
Andreas Gampe277ccbd2014-11-03 21:36:10 -080017#include "dalvik_system_ZygoteHooks.h"
18
Narayan Kamath8b2c8b92014-03-31 16:44:54 +010019#include <stdlib.h>
20
Andreas Gampe57943812017-12-06 21:39:13 -080021#include <android-base/logging.h>
22#include <android-base/stringprintf.h>
Andreas Gampe46ee31b2016-12-14 10:11:49 -080023
Ian Rogersd582fa42014-11-05 23:46:43 -080024#include "arch/instruction_set.h"
Andreas Gampec6ea7d02017-02-01 16:46:28 -080025#include "art_method-inl.h"
Andreas Gampe57943812017-12-06 21:39:13 -080026#include "base/macros.h"
27#include "base/mutex.h"
Narayan Kamath8b2c8b92014-03-31 16:44:54 +010028#include "debugger.h"
Ian Rogers68d8b422014-07-17 11:09:10 -070029#include "java_vm_ext.h"
Mathieu Chartier455f67c2015-03-17 13:48:29 -070030#include "jit/jit.h"
Narayan Kamath8b2c8b92014-03-31 16:44:54 +010031#include "jni_internal.h"
Andreas Gampe87583b32017-05-25 11:22:18 -070032#include "native_util.h"
Steven Morelande431e272017-07-18 16:53:49 -070033#include "nativehelper/jni_macros.h"
Andreas Gampe373a9b52017-10-18 09:01:57 -070034#include "nativehelper/scoped_utf_chars.h"
Alex Lighte77b48b2017-02-22 11:08:06 -080035#include "non_debuggable_classes.h"
Nicolas Geoffray68bf3902017-09-07 14:40:48 +010036#include "oat_file.h"
37#include "oat_file_manager.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070038#include "scoped_thread_state_change-inl.h"
Andreas Gampe513061a2017-06-01 09:17:34 -070039#include "stack.h"
Andreas Gampeb486a982017-06-01 13:45:54 -070040#include "thread-current-inl.h"
Alex Lighte77b48b2017-02-22 11:08:06 -080041#include "thread_list.h"
Andreas Gampe40da2862015-02-27 12:49:04 -080042#include "trace.h"
Narayan Kamath8b2c8b92014-03-31 16:44:54 +010043
Elliott Hughes0a18df82015-01-09 15:16:16 -080044#if defined(__linux__)
Narayan Kamath8b2c8b92014-03-31 16:44:54 +010045#include <sys/prctl.h>
46#endif
47
Narayan Kamathad4b0d22014-04-02 12:06:02 +010048#include <sys/resource.h>
49
Narayan Kamath8b2c8b92014-03-31 16:44:54 +010050namespace art {
51
Alex Lighte77b48b2017-02-22 11:08:06 -080052// Set to true to always determine the non-debuggable classes even if we would not allow a debugger
53// to actually attach.
Andreas Gampedbe54912017-10-19 13:02:03 -070054static bool kAlwaysCollectNonDebuggableClasses =
55 RegisterRuntimeDebugFlag(&kAlwaysCollectNonDebuggableClasses);
Alex Lighte77b48b2017-02-22 11:08:06 -080056
Andreas Gampe46ee31b2016-12-14 10:11:49 -080057using android::base::StringPrintf;
58
Narayan Kamath8b2c8b92014-03-31 16:44:54 +010059static void EnableDebugger() {
Elliott Hughes0a18df82015-01-09 15:16:16 -080060#if defined(__linux__)
Narayan Kamath8b2c8b92014-03-31 16:44:54 +010061 // To let a non-privileged gdbserver attach to this
62 // process, we must set our dumpable flag.
63 if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
64 PLOG(ERROR) << "prctl(PR_SET_DUMPABLE) failed for pid " << getpid();
65 }
Oleksiy Vyalovde9007f2016-06-21 16:21:37 -070066
67 // Even if Yama is on a non-privileged native debugger should
68 // be able to attach to the debuggable app.
69 if (prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0) == -1) {
70 // if Yama is off prctl(PR_SET_PTRACER) returns EINVAL - don't log in this
71 // case since it's expected behaviour.
72 if (errno != EINVAL) {
73 PLOG(ERROR) << "prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY) failed for pid " << getpid();
74 }
75 }
Ian Rogersc5f17732014-06-05 20:48:42 -070076#endif
Narayan Kamath8b2c8b92014-03-31 16:44:54 +010077 // We don't want core dumps, though, so set the core dump size to 0.
78 rlimit rl;
79 rl.rlim_cur = 0;
80 rl.rlim_max = RLIM_INFINITY;
81 if (setrlimit(RLIMIT_CORE, &rl) == -1) {
82 PLOG(ERROR) << "setrlimit(RLIMIT_CORE) failed for pid " << getpid();
83 }
84}
85
Alex Light861af892017-02-28 12:45:36 -080086class ClassSet {
87 public:
Alex Light84740262017-03-01 09:00:28 -080088 // The number of classes we reasonably expect to have to look at. Realistically the number is more
89 // ~10 but there is little harm in having some extra.
90 static constexpr int kClassSetCapacity = 100;
Alex Light861af892017-02-28 12:45:36 -080091
Alex Light84740262017-03-01 09:00:28 -080092 explicit ClassSet(Thread* const self) : self_(self) {
93 self_->GetJniEnv()->PushFrame(kClassSetCapacity);
Alex Light861af892017-02-28 12:45:36 -080094 }
95
Alex Light84740262017-03-01 09:00:28 -080096 ~ClassSet() {
97 self_->GetJniEnv()->PopFrame();
98 }
99
100 void AddClass(ObjPtr<mirror::Class> klass) REQUIRES(Locks::mutator_lock_) {
101 class_set_.insert(self_->GetJniEnv()->AddLocalReference<jclass>(klass.Ptr()));
102 }
103
104 const std::unordered_set<jclass>& GetClasses() const {
Alex Light861af892017-02-28 12:45:36 -0800105 return class_set_;
106 }
107
108 private:
Alex Light84740262017-03-01 09:00:28 -0800109 Thread* const self_;
110 std::unordered_set<jclass> class_set_;
Alex Light861af892017-02-28 12:45:36 -0800111};
112
113static void DoCollectNonDebuggableCallback(Thread* thread, void* data)
Alex Lighte77b48b2017-02-22 11:08:06 -0800114 REQUIRES(Locks::mutator_lock_) {
115 class NonDebuggableStacksVisitor : public StackVisitor {
116 public:
Alex Light861af892017-02-28 12:45:36 -0800117 NonDebuggableStacksVisitor(Thread* t, ClassSet* class_set)
118 : StackVisitor(t, nullptr, StackVisitor::StackWalkKind::kIncludeInlinedFrames),
119 class_set_(class_set) {}
Alex Lighte77b48b2017-02-22 11:08:06 -0800120
121 ~NonDebuggableStacksVisitor() OVERRIDE {}
122
123 bool VisitFrame() OVERRIDE REQUIRES(Locks::mutator_lock_) {
124 if (GetMethod()->IsRuntimeMethod()) {
125 return true;
126 }
Alex Light861af892017-02-28 12:45:36 -0800127 class_set_->AddClass(GetMethod()->GetDeclaringClass());
Alex Lighte77b48b2017-02-22 11:08:06 -0800128 if (kIsDebugBuild) {
129 LOG(INFO) << GetMethod()->GetDeclaringClass()->PrettyClass()
130 << " might not be fully debuggable/deoptimizable due to "
131 << GetMethod()->PrettyMethod() << " appearing on the stack during zygote fork.";
132 }
133 return true;
134 }
Alex Light861af892017-02-28 12:45:36 -0800135
136 private:
137 ClassSet* class_set_;
Alex Lighte77b48b2017-02-22 11:08:06 -0800138 };
Alex Light861af892017-02-28 12:45:36 -0800139 NonDebuggableStacksVisitor visitor(thread, reinterpret_cast<ClassSet*>(data));
Alex Lighte77b48b2017-02-22 11:08:06 -0800140 visitor.WalkStack();
141}
142
Alex Light861af892017-02-28 12:45:36 -0800143static void CollectNonDebuggableClasses() REQUIRES(!Locks::mutator_lock_) {
Alex Lighte77b48b2017-02-22 11:08:06 -0800144 Runtime* const runtime = Runtime::Current();
Alex Light861af892017-02-28 12:45:36 -0800145 Thread* const self = Thread::Current();
146 // Get the mutator lock.
147 ScopedObjectAccess soa(self);
148 ClassSet classes(self);
149 {
Alex Light84740262017-03-01 09:00:28 -0800150 // Drop the shared mutator lock.
151 ScopedThreadSuspension sts(self, art::ThreadState::kNative);
152 // Get exclusive mutator lock with suspend all.
153 ScopedSuspendAll suspend("Checking stacks for non-obsoletable methods!", /*long_suspend*/false);
154 MutexLock mu(Thread::Current(), *Locks::thread_list_lock_);
155 runtime->GetThreadList()->ForEach(DoCollectNonDebuggableCallback, &classes);
Alex Light861af892017-02-28 12:45:36 -0800156 }
Alex Light84740262017-03-01 09:00:28 -0800157 for (jclass klass : classes.GetClasses()) {
158 NonDebuggableClasses::AddNonDebuggableClass(klass);
Alex Light861af892017-02-28 12:45:36 -0800159 }
Alex Lighte77b48b2017-02-22 11:08:06 -0800160}
161
Nicolas Geoffray68bf3902017-09-07 14:40:48 +0100162// Must match values in com.android.internal.os.Zygote.
163enum {
164 DEBUG_ENABLE_JDWP = 1,
165 DEBUG_ENABLE_CHECKJNI = 1 << 1,
166 DEBUG_ENABLE_ASSERT = 1 << 2,
167 DEBUG_ENABLE_SAFEMODE = 1 << 3,
168 DEBUG_ENABLE_JNI_LOGGING = 1 << 4,
169 DEBUG_GENERATE_DEBUG_INFO = 1 << 5,
170 DEBUG_ALWAYS_JIT = 1 << 6,
171 DEBUG_NATIVE_DEBUGGABLE = 1 << 7,
172 DEBUG_JAVA_DEBUGGABLE = 1 << 8,
173 DISABLE_VERIFIER = 1 << 9,
174 ONLY_USE_SYSTEM_OAT_FILES = 1 << 10,
175};
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100176
Nicolas Geoffray68bf3902017-09-07 14:40:48 +0100177static uint32_t EnableDebugFeatures(uint32_t runtime_flags) {
Mathieu Chartier6eff38d2015-03-17 09:52:22 -0700178 Runtime* const runtime = Runtime::Current();
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100179 if ((runtime_flags & DEBUG_ENABLE_CHECKJNI) != 0) {
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100180 JavaVMExt* vm = runtime->GetJavaVM();
Ian Rogers68d8b422014-07-17 11:09:10 -0700181 if (!vm->IsCheckJniEnabled()) {
Brian Carlstrom966ce112014-05-12 17:30:36 -0700182 LOG(INFO) << "Late-enabling -Xcheck:jni";
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100183 vm->SetCheckJniEnabled(true);
184 // There's only one thread running at this point, so only one JNIEnv to fix up.
185 Thread::Current()->GetJniEnv()->SetCheckJniEnabled(true);
186 } else {
Brian Carlstrom966ce112014-05-12 17:30:36 -0700187 LOG(INFO) << "Not late-enabling -Xcheck:jni (already on)";
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100188 }
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100189 runtime_flags &= ~DEBUG_ENABLE_CHECKJNI;
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100190 }
191
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100192 if ((runtime_flags & DEBUG_ENABLE_JNI_LOGGING) != 0) {
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100193 gLogVerbosity.third_party_jni = true;
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100194 runtime_flags &= ~DEBUG_ENABLE_JNI_LOGGING;
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100195 }
196
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100197 Dbg::SetJdwpAllowed((runtime_flags & DEBUG_ENABLE_JDWP) != 0);
198 if ((runtime_flags & DEBUG_ENABLE_JDWP) != 0) {
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100199 EnableDebugger();
200 }
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100201 runtime_flags &= ~DEBUG_ENABLE_JDWP;
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100202
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100203 const bool safe_mode = (runtime_flags & DEBUG_ENABLE_SAFEMODE) != 0;
Mathieu Chartier6eff38d2015-03-17 09:52:22 -0700204 if (safe_mode) {
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100205 // Only quicken oat files.
206 runtime->AddCompilerOption("--compiler-filter=quicken");
Nicolas Geoffray0f042e02015-11-05 11:32:24 +0000207 runtime->SetSafeMode(true);
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100208 runtime_flags &= ~DEBUG_ENABLE_SAFEMODE;
Andreas Gamped2abbc92014-12-19 09:53:27 -0800209 }
210
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100211 const bool generate_debug_info = (runtime_flags & DEBUG_GENERATE_DEBUG_INFO) != 0;
David Srbecky8363c772015-05-28 16:12:43 +0100212 if (generate_debug_info) {
213 runtime->AddCompilerOption("--generate-debug-info");
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100214 runtime_flags &= ~DEBUG_GENERATE_DEBUG_INFO;
Andreas Gampe00bb8782015-04-24 16:33:43 -0700215 }
216
Andreas Gamped2abbc92014-12-19 09:53:27 -0800217 // This is for backwards compatibility with Dalvik.
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100218 runtime_flags &= ~DEBUG_ENABLE_ASSERT;
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100219
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100220 if ((runtime_flags & DEBUG_ALWAYS_JIT) != 0) {
Siva Chandra05d24152016-01-05 17:43:17 -0800221 jit::JitOptions* jit_options = runtime->GetJITOptions();
222 CHECK(jit_options != nullptr);
223 jit_options->SetJitAtFirstUse();
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100224 runtime_flags &= ~DEBUG_ALWAYS_JIT;
Siva Chandra05d24152016-01-05 17:43:17 -0800225 }
226
Alex Lighte77b48b2017-02-22 11:08:06 -0800227 bool needs_non_debuggable_classes = false;
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100228 if ((runtime_flags & DEBUG_JAVA_DEBUGGABLE) != 0) {
Nicolas Geoffray433b79a2017-01-30 20:54:45 +0000229 runtime->AddCompilerOption("--debuggable");
230 runtime->SetJavaDebuggable(true);
231 // Deoptimize the boot image as it may be non-debuggable.
232 runtime->DeoptimizeBootImage();
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100233 runtime_flags &= ~DEBUG_JAVA_DEBUGGABLE;
Alex Lighte77b48b2017-02-22 11:08:06 -0800234 needs_non_debuggable_classes = true;
235 }
236 if (needs_non_debuggable_classes || kAlwaysCollectNonDebuggableClasses) {
237 CollectNonDebuggableClasses();
Nicolas Geoffray433b79a2017-01-30 20:54:45 +0000238 }
239
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100240 if ((runtime_flags & DEBUG_NATIVE_DEBUGGABLE) != 0) {
David Srbecky346dc992016-03-13 22:00:07 +0000241 runtime->AddCompilerOption("--debuggable");
242 runtime->AddCompilerOption("--generate-debug-info");
David Srbeckyf4480162016-03-16 00:06:24 +0000243 runtime->SetNativeDebuggable(true);
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100244 runtime_flags &= ~DEBUG_NATIVE_DEBUGGABLE;
Tamas Berghammerdd5e5e92016-02-12 16:29:00 +0000245 }
246
Nicolas Geoffray68bf3902017-09-07 14:40:48 +0100247 return runtime_flags;
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100248}
249
250static jlong ZygoteHooks_nativePreFork(JNIEnv* env, jclass) {
251 Runtime* runtime = Runtime::Current();
252 CHECK(runtime->IsZygote()) << "runtime instance not started with -Xzygote";
Narayan Kamath3de95a72014-04-02 12:54:23 +0100253
254 runtime->PreZygoteFork();
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100255
Andreas Gampe40da2862015-02-27 12:49:04 -0800256 if (Trace::GetMethodTracingMode() != TracingMode::kTracingInactive) {
257 // Tracing active, pause it.
258 Trace::Pause();
259 }
260
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100261 // Grab thread before fork potentially makes Thread::pthread_key_self_ unusable.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700262 return reinterpret_cast<jlong>(ThreadForEnv(env));
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100263}
264
Nicolas Geoffrayd66c8622015-12-11 14:59:16 +0000265static void ZygoteHooks_nativePostForkChild(JNIEnv* env,
266 jclass,
267 jlong token,
Nicolas Geoffray5510c0a2017-09-12 15:11:37 +0100268 jint runtime_flags,
Nicolas Geoffrayd66c8622015-12-11 14:59:16 +0000269 jboolean is_system_server,
Andreas Gampe6be67ee2014-09-02 21:22:18 -0700270 jstring instruction_set) {
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100271 Thread* thread = reinterpret_cast<Thread*>(token);
272 // Our system thread ID, etc, has changed so reset Thread state.
273 thread->InitAfterFork();
Nicolas Geoffray68bf3902017-09-07 14:40:48 +0100274 runtime_flags = EnableDebugFeatures(runtime_flags);
275
276 if ((runtime_flags & DISABLE_VERIFIER) != 0) {
277 Runtime::Current()->DisableVerifier();
278 runtime_flags &= ~DISABLE_VERIFIER;
279 }
280
281 if ((runtime_flags & ONLY_USE_SYSTEM_OAT_FILES) != 0) {
282 Runtime::Current()->GetOatFileManager().SetOnlyUseSystemOatFiles();
283 runtime_flags &= ~ONLY_USE_SYSTEM_OAT_FILES;
284 }
285
286 if (runtime_flags != 0) {
287 LOG(ERROR) << StringPrintf("Unknown bits set in runtime_flags: %#x", runtime_flags);
288 }
Andreas Gampe6be67ee2014-09-02 21:22:18 -0700289
Andreas Gampe40da2862015-02-27 12:49:04 -0800290 // Update tracing.
291 if (Trace::GetMethodTracingMode() != TracingMode::kTracingInactive) {
292 Trace::TraceOutputMode output_mode = Trace::GetOutputMode();
293 Trace::TraceMode trace_mode = Trace::GetMode();
Andreas Gampee34a42c2015-04-25 14:44:29 -0700294 size_t buffer_size = Trace::GetBufferSize();
Andreas Gampe40da2862015-02-27 12:49:04 -0800295
296 // Just drop it.
297 Trace::Abort();
298
299 // Only restart if it was streaming mode.
300 // TODO: Expose buffer size, so we can also do file mode.
301 if (output_mode == Trace::TraceOutputMode::kStreaming) {
Dmitriy Filchenko03c01342016-07-11 17:41:28 -0700302 static constexpr size_t kMaxProcessNameLength = 100;
303 char name_buf[kMaxProcessNameLength] = {};
304 int rc = pthread_getname_np(pthread_self(), name_buf, kMaxProcessNameLength);
Andreas Gampe40da2862015-02-27 12:49:04 -0800305 std::string proc_name;
Dmitriy Filchenko03c01342016-07-11 17:41:28 -0700306
307 if (rc == 0) {
308 // On success use the pthread name.
309 proc_name = name_buf;
Andreas Gampe40da2862015-02-27 12:49:04 -0800310 }
Dmitriy Filchenko03c01342016-07-11 17:41:28 -0700311
312 if (proc_name.empty() || proc_name == "zygote" || proc_name == "zygote64") {
Andreas Gampe40da2862015-02-27 12:49:04 -0800313 // Either no process name, or the name hasn't been changed, yet. Just use pid.
314 pid_t pid = getpid();
315 proc_name = StringPrintf("%u", static_cast<uint32_t>(pid));
316 }
317
Calin Juravlef83e7332015-11-04 16:16:47 +0000318 std::string trace_file = StringPrintf("/data/misc/trace/%s.trace.bin", proc_name.c_str());
319 Trace::Start(trace_file.c_str(),
320 -1,
321 buffer_size,
322 0, // TODO: Expose flags.
323 output_mode,
324 trace_mode,
325 0); // TODO: Expose interval.
326 if (thread->IsExceptionPending()) {
327 ScopedObjectAccess soa(env);
328 thread->ClearException();
Andreas Gampe40da2862015-02-27 12:49:04 -0800329 }
330 }
331 }
332
Nicolas Geoffrayd66c8622015-12-11 14:59:16 +0000333 if (instruction_set != nullptr && !is_system_server) {
Andreas Gampe6be67ee2014-09-02 21:22:18 -0700334 ScopedUtfChars isa_string(env, instruction_set);
335 InstructionSet isa = GetInstructionSetFromString(isa_string.c_str());
jgu21a6da74e2014-09-10 06:57:17 -0400336 Runtime::NativeBridgeAction action = Runtime::NativeBridgeAction::kUnload;
Vladimir Marko33bff252017-11-01 14:35:42 +0000337 if (isa != InstructionSet::kNone && isa != kRuntimeISA) {
Andreas Gampe6be67ee2014-09-02 21:22:18 -0700338 action = Runtime::NativeBridgeAction::kInitialize;
339 }
Nicolas Geoffrayd66c8622015-12-11 14:59:16 +0000340 Runtime::Current()->InitNonZygoteOrPostFork(
341 env, is_system_server, action, isa_string.c_str());
jgu21a6da74e2014-09-10 06:57:17 -0400342 } else {
Nicolas Geoffrayd66c8622015-12-11 14:59:16 +0000343 Runtime::Current()->InitNonZygoteOrPostFork(
344 env, is_system_server, Runtime::NativeBridgeAction::kUnload, nullptr);
Andreas Gampe6be67ee2014-09-02 21:22:18 -0700345 }
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100346}
347
Andreas Gampef38a6612016-04-11 08:42:26 -0700348static void ZygoteHooks_startZygoteNoThreadCreation(JNIEnv* env ATTRIBUTE_UNUSED,
349 jclass klass ATTRIBUTE_UNUSED) {
350 Runtime::Current()->SetZygoteNoThreadSection(true);
351}
352
353static void ZygoteHooks_stopZygoteNoThreadCreation(JNIEnv* env ATTRIBUTE_UNUSED,
354 jclass klass ATTRIBUTE_UNUSED) {
355 Runtime::Current()->SetZygoteNoThreadSection(false);
356}
357
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100358static JNINativeMethod gMethods[] = {
359 NATIVE_METHOD(ZygoteHooks, nativePreFork, "()J"),
Nicolas Geoffrayd66c8622015-12-11 14:59:16 +0000360 NATIVE_METHOD(ZygoteHooks, nativePostForkChild, "(JIZLjava/lang/String;)V"),
Andreas Gampef38a6612016-04-11 08:42:26 -0700361 NATIVE_METHOD(ZygoteHooks, startZygoteNoThreadCreation, "()V"),
362 NATIVE_METHOD(ZygoteHooks, stopZygoteNoThreadCreation, "()V"),
Narayan Kamath8b2c8b92014-03-31 16:44:54 +0100363};
364
365void register_dalvik_system_ZygoteHooks(JNIEnv* env) {
366 REGISTER_NATIVE_METHODS("dalvik/system/ZygoteHooks");
367}
368
369} // namespace art