Loading core/java/com/android/internal/os/ZygoteInit.java +25 −4 Original line number Diff line number Diff line Loading @@ -127,6 +127,12 @@ public class ZygoteInit { private static boolean sPreloadComplete; /** * Cached classloader to use for the system server. Will only be populated in the system * server process. */ private static ClassLoader sCachedSystemServerClassLoader = null; static void preload(TimingsTraceLog bootTimingsTraceLog) { Log.d(TAG, "begin preload"); bootTimingsTraceLog.traceBegin("BeginPreload"); Loading Loading @@ -540,10 +546,8 @@ public class ZygoteInit { throw new IllegalStateException("Unexpected return from WrapperInit.execApplication"); } else { ClassLoader cl = null; if (systemServerClasspath != null) { cl = createPathClassLoader(systemServerClasspath, parsedArgs.mTargetSdkVersion); ClassLoader cl = getOrCreateSystemServerClassLoader(); if (cl != null) { Thread.currentThread().setContextClassLoader(cl); } Loading @@ -558,6 +562,23 @@ public class ZygoteInit { /* should never reach here */ } /** * Create the classloader for the system server and store it in * {@link sCachedSystemServerClassLoader}. This function may be called through JNI in * system server startup, when the runtime is in a critically low state. Do not do * extended computation etc here. */ private static ClassLoader getOrCreateSystemServerClassLoader() { if (sCachedSystemServerClassLoader == null) { final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH"); if (systemServerClasspath != null) { sCachedSystemServerClassLoader = createPathClassLoader(systemServerClasspath, VMRuntime.SDK_VERSION_CUR_DEVELOPMENT); } } return sCachedSystemServerClassLoader; } /** * Note that preparing the profiles for system server does not require special selinux * permissions. From the installer perspective the system server is a regular package which can Loading core/jni/com_android_internal_os_Zygote.cpp +23 −1 Original line number Diff line number Diff line Loading @@ -122,6 +122,10 @@ static jclass gZygoteClass; static jmethodID gCallPostForkSystemServerHooks; static jmethodID gCallPostForkChildHooks; static constexpr const char* kZygoteInitClassName = "com/android/internal/os/ZygoteInit"; static jclass gZygoteInitClass; static jmethodID gGetOrCreateSystemServerClassLoader; static bool gIsSecurityEnforced = true; /** Loading Loading @@ -1613,6 +1617,17 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, instruction_set.value().c_str()); } if (is_system_server) { // Prefetch the classloader for the system server. This is done early to // allow a tie-down of the proper system server selinux domain. env->CallStaticVoidMethod(gZygoteInitClass, gGetOrCreateSystemServerClassLoader); if (env->ExceptionCheck()) { // Be robust here. The Java code will attempt to create the classloader // at a later point (but may not have rights to use AoT artifacts). env->ExceptionClear(); } } if (setresgid(gid, gid, gid) == -1) { fail_fn(CREATE_ERROR("setresgid(%d) failed: %s", gid, strerror(errno))); } Loading Loading @@ -2676,6 +2691,13 @@ int register_com_android_internal_os_Zygote(JNIEnv* env) { gCallPostForkChildHooks = GetStaticMethodIDOrDie(env, gZygoteClass, "callPostForkChildHooks", "(IZZLjava/lang/String;)V"); return RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods)); gZygoteInitClass = MakeGlobalRefOrDie(env, FindClassOrDie(env, kZygoteInitClassName)); gGetOrCreateSystemServerClassLoader = GetStaticMethodIDOrDie(env, gZygoteInitClass, "getOrCreateSystemServerClassLoader", "()Ljava/lang/ClassLoader;"); RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods)); return JNI_OK; } } // namespace android Loading
core/java/com/android/internal/os/ZygoteInit.java +25 −4 Original line number Diff line number Diff line Loading @@ -127,6 +127,12 @@ public class ZygoteInit { private static boolean sPreloadComplete; /** * Cached classloader to use for the system server. Will only be populated in the system * server process. */ private static ClassLoader sCachedSystemServerClassLoader = null; static void preload(TimingsTraceLog bootTimingsTraceLog) { Log.d(TAG, "begin preload"); bootTimingsTraceLog.traceBegin("BeginPreload"); Loading Loading @@ -540,10 +546,8 @@ public class ZygoteInit { throw new IllegalStateException("Unexpected return from WrapperInit.execApplication"); } else { ClassLoader cl = null; if (systemServerClasspath != null) { cl = createPathClassLoader(systemServerClasspath, parsedArgs.mTargetSdkVersion); ClassLoader cl = getOrCreateSystemServerClassLoader(); if (cl != null) { Thread.currentThread().setContextClassLoader(cl); } Loading @@ -558,6 +562,23 @@ public class ZygoteInit { /* should never reach here */ } /** * Create the classloader for the system server and store it in * {@link sCachedSystemServerClassLoader}. This function may be called through JNI in * system server startup, when the runtime is in a critically low state. Do not do * extended computation etc here. */ private static ClassLoader getOrCreateSystemServerClassLoader() { if (sCachedSystemServerClassLoader == null) { final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH"); if (systemServerClasspath != null) { sCachedSystemServerClassLoader = createPathClassLoader(systemServerClasspath, VMRuntime.SDK_VERSION_CUR_DEVELOPMENT); } } return sCachedSystemServerClassLoader; } /** * Note that preparing the profiles for system server does not require special selinux * permissions. From the installer perspective the system server is a regular package which can Loading
core/jni/com_android_internal_os_Zygote.cpp +23 −1 Original line number Diff line number Diff line Loading @@ -122,6 +122,10 @@ static jclass gZygoteClass; static jmethodID gCallPostForkSystemServerHooks; static jmethodID gCallPostForkChildHooks; static constexpr const char* kZygoteInitClassName = "com/android/internal/os/ZygoteInit"; static jclass gZygoteInitClass; static jmethodID gGetOrCreateSystemServerClassLoader; static bool gIsSecurityEnforced = true; /** Loading Loading @@ -1613,6 +1617,17 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, instruction_set.value().c_str()); } if (is_system_server) { // Prefetch the classloader for the system server. This is done early to // allow a tie-down of the proper system server selinux domain. env->CallStaticVoidMethod(gZygoteInitClass, gGetOrCreateSystemServerClassLoader); if (env->ExceptionCheck()) { // Be robust here. The Java code will attempt to create the classloader // at a later point (but may not have rights to use AoT artifacts). env->ExceptionClear(); } } if (setresgid(gid, gid, gid) == -1) { fail_fn(CREATE_ERROR("setresgid(%d) failed: %s", gid, strerror(errno))); } Loading Loading @@ -2676,6 +2691,13 @@ int register_com_android_internal_os_Zygote(JNIEnv* env) { gCallPostForkChildHooks = GetStaticMethodIDOrDie(env, gZygoteClass, "callPostForkChildHooks", "(IZZLjava/lang/String;)V"); return RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods)); gZygoteInitClass = MakeGlobalRefOrDie(env, FindClassOrDie(env, kZygoteInitClassName)); gGetOrCreateSystemServerClassLoader = GetStaticMethodIDOrDie(env, gZygoteInitClass, "getOrCreateSystemServerClassLoader", "()Ljava/lang/ClassLoader;"); RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods)); return JNI_OK; } } // namespace android