当前位置:网站首页>Systemserver process
Systemserver process
2022-07-02 13:57:00 【xhBruce】
SystemServer process
android12-release
Android The system starts
Zygote process
Zygote process fork And come
init process -> Zygote process -> system_server process
frameworks/base/core/java/com/android/internal/os/ZygoteInit.java
frameworks/base/core/java/com/android/internal/os/Zygote.java
frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
art/runtime/native/dalvik_system_ZygoteHooks.cc
forkSystemServer().run() -> pid = Zygote.forkSystemServer() -> nativeForkSystemServer() -> com_android_internal_os_Zygote_nativeForkSystemServer -> pid = zygote::ForkCommon() -> pid = fork() -> SpecializeCommon()
/* Hardcoded command line to start the system server */
String[] args = {
"--setuid=1000",
"--setgid=1000",
"--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1018,1021,1023,"
+ "1024,1032,1065,3001,3002,3003,3006,3007,3009,3010,3011",
"--capabilities=" + capabilities + "," + capabilities,
"--nice-name=system_server",
"--runtime-args",
"--target-sdk-version=" + VMRuntime.SDK_VERSION_CUR_DEVELOPMENT,
"com.android.server.SystemServer",
};
ZygoteArguments parsedArgs;
SystemServer The process parameter information is uid=1000,gid=1000, The process name is
sytem_serverZygote.forkSystemServer()fork Outsystem_server process
com_android_internal_os_Zygote_nativeForkSystemServerJNIzygote::ForkCommon()Call tofork()Create a new process , use copy on write The way , This is a linux Standard method for creating processes , There will be two return. The return value is 3 Types : In parent process ,fork Returns the... Of the newly created child process pid; In subprocess ,fork return 0; When an error occurs ,fork Return negative .
When system_server After the process dies , restart zygote process .New creation system_server The process is complete ,
pid == 0Then enterhandleSystemServerProcess() Method
handleSystemServerProcess
fork() Here we are system_server The process has completed all the work created , Here we go system_server The real work of the process
handleSystemServerProcess(parsedArgs)complete system_server Process remaining work , Running on thesystem_server processProcess.setArgV0(parsedArgs.mNiceName)Current process name "system_server"performSystemServerDexOpt()perform dex Optimize operation , frominstalldTo complete- system_server perform
ZygoteInit.zygoteInit()
/** * Finish remaining work for the newly forked system server process. */
private static Runnable handleSystemServerProcess(ZygoteArguments parsedArgs) {
// set umask to 0077 so new files and directories will default to owner-only permissions.
Os.umask(S_IRWXG | S_IRWXO);
if (parsedArgs.mNiceName != null) {
Process.setArgV0(parsedArgs.mNiceName);
}
final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH");
if (systemServerClasspath != null) {
performSystemServerDexOpt(systemServerClasspath);
// Capturing profiles is only supported for debug or eng builds since selinux normally
// prevents it.
if (shouldProfileSystemServer() && (Build.IS_USERDEBUG || Build.IS_ENG)) {
try {
Log.d(TAG, "Preparing system server profile");
prepareSystemServerProfile(systemServerClasspath);
} catch (Exception e) {
Log.wtf(TAG, "Failed to set up system server profile", e);
}
}
}
if (parsedArgs.mInvokeWith != null) {
String[] args = parsedArgs.mRemainingArgs;
// If we have a non-null system server class path, we'll have to duplicate the
// existing arguments and append the classpath to it. ART will handle the classpath
// correctly when we exec a new process.
if (systemServerClasspath != null) {
String[] amendedArgs = new String[args.length + 2];
amendedArgs[0] = "-cp";
amendedArgs[1] = systemServerClasspath;
System.arraycopy(args, 0, amendedArgs, 2, args.length);
args = amendedArgs;
}
WrapperInit.execApplication(parsedArgs.mInvokeWith,
parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion,
VMRuntime.getCurrentInstructionSet(), null, args);
throw new IllegalStateException("Unexpected return from WrapperInit.execApplication");
} else {
ClassLoader cl = getOrCreateSystemServerClassLoader();
if (cl != null) {
Thread.currentThread().setContextClassLoader(cl);
}
/* * Pass the remaining arguments to SystemServer. */
return ZygoteInit.zygoteInit(parsedArgs.mTargetSdkVersion,
parsedArgs.mDisabledCompatChanges,
parsedArgs.mRemainingArgs, cl);
}
/* should never reach here */
}
ZygoteInit.zygoteInit()
ZygoteInit.nativeZygoteInit()stay AndroidRuntime.cpp in , the jni mappingRuntimeInit.applicationInit()Meso endomorph MethodAndArgsCaller.run functionmMethod.invoke()start-up SystemServer.main()
SystemServer.main
4.2 system service : from SystemServer.java Be responsible for starting and managing the whole Java framework In the service startBootstrapServices、startCoreServices、startOtherServices
Sequence diagram

边栏推荐
- Launcher启动过程
- D how to check null
- Add sequence number column to query results in MySQL
- P3807 [template] Lucas theorem /lucas theorem
- 2022 zero code / low code development white paper [produced by partner cloud] with download
- 自定义事件,全局事件总线,消息订阅与发布,$nextTick
- [技术发展-22]:网络与通信技术的应用与发展快速概览-2- 通信技术
- Characteristics of selenium
- Selenium installing selenium in pycharm
- Solve "sub number integer", "jump happily", "turn on the light"
猜你喜欢

The global special paper revenue in 2021 was about $27 million, and it is expected to reach $35 million in 2028. From 2022 to 2028, the CAGR was 3.8%

Launcher启动过程

A better database client management tool than Navicat

Codeforces Round #803 (Div. 2)(A~D)

Code implementation MNLM

无主灯设计:如何让智能照明更加「智能」?

Solve "sub number integer", "jump happily", "turn on the light"

Selenium, element operation and browser operation methods

混沌工程平台 ChaosBlade-Box 新版重磅发布

c# 水晶报表打印
随机推荐
无主灯设计:如何让智能照明更加「智能」?
Use bloc to build a page instance of shutter
Everyone believes that the one-stop credit platform makes the credit scenario "useful"
Error: eacces: permission denied, access to "/usr/lib/node_modules"
Bridge of undirected graph
[cloud native database] what to do when encountering slow SQL (Part 1)?
P3008 [USACO11JAN]Roads and Planes G (SPFA + SLF优化)
Daily practice of C language --- monkeys divide peaches
混沌工程平台 ChaosBlade-Box 新版重磅发布
Word frequency statistics & sorting
题解:《压缩技术》(原版、续集版)
693. Travel sequencing (map + topology)
Codeforces Round #803 (Div. 2)(A~D)
Node. JS accessing PostgreSQL database through ODBC
P1908 逆序对
I did it with two lines of code. As a result, my sister had a more ingenious way
浏览器驱动的下载
[Blue Bridge Cup] children's worship circle
Quantum three body problem: Landau fall
Find love for speed in F1 delta time Grand Prix