1

As far as I know Zygote is started by app_process64 and app_process32 where 64 is for primary zygote that starts system services because of start-system-server flag.

As we can see below in static void main method of frameworks/base/core/java/com/android/internal/os/ZygoteInit.java, it checks for start-system-server flag, run the forked System Server and exits due to return; statement below it, and never running the runSelectLoop that actually goes into infinite loop listening to connections that request to launch new applications. Only app_process32 without start-system-server flag will not enter the control statement to run the forked System Server, and instead, runs the runSelectLoop. Does it mean that all system services are inherently 64-bit while all Android apps are inherently 32-bit?

This code is from AOSP branch: Android-14.0.0_r21:

// redacted above code

zygoteServer = new ZygoteServer(isPrimaryZygote);

if (startSystemServer) {
    Runnable r = forkSystemServer(abiList, zygoteSocketName, zygoteServer);

    // {@code r == null} in the parent (zygote) process, and {@code r != null} in the
    // child (system_server) process.
    if (r != null) {
        r.run();
        return;
    }
}

Log.i(TAG, "Accepting command socket connections");

// The select loop returns early in the child process after a fork and
// loops forever in the zygote.
caller = zygoteServer.runSelectLoop(abiList);

// redacted code below
1
  • 1
    Are you sure this is not a misinterpretation? May be 64 and 32 means can execute only 64 but and can execute 32 (and 64) bit software. This would make sense as system services are defined by the manufacturer so on a 64 bit device I would assume all system services are 64 bit. But user apps can be 32 or 64 bit so the run in app_process32 (assuming the used CPU and the platform still has the 32 but capability which is not true for Google's recent Pixel phones).
    – Robert
    Commented Jan 21 at 21:50

2 Answers 2

1

The runSelectLoop will actually be run by app_process64 as well and not simply exit.

Let's take a look at this excerpt of the forkSystemServer method, called in your code snippet when startSystemServer is true, to see why:

private static Runnable forkSystemServer(String abiList, String socketName,
        ZygoteServer zygoteServer) {
    // ...

    int pid;

    try {
        // ...

        pid = Zygote.forkSystemServer(
                parsedArgs.mUid, parsedArgs.mGid,
                parsedArgs.mGids,
                parsedArgs.mRuntimeFlags,
                null,
                parsedArgs.mPermittedCapabilities,
                parsedArgs.mEffectiveCapabilities);
    } catch (IllegalArgumentException ex) {
        throw new RuntimeException(ex);
    }

    /* For child process */
    if (pid == 0) {
        // ...

        return handleSystemServerProcess(parsedArgs);
    }

    /* For parent process */
    return null;
}

I removed most of the code and kept only the relevant part for clarity. As you can see, the method will fork the current process and return some data in the child process, while it will return null in the parent process.

This means that both the child process (system_server) and the main process (zygote64) process will continue execution in the code snippet you included in the question:

Runnable r = forkSystemServer(abiList, zygoteSocketName, zygoteServer);

// {@code r == null} in the parent (zygote) process, and {@code r != null} in the
// child (system_server) process.
if (r != null) {
    r.run();
    return;
}

Now, in the forked system_server process, the call to forkSystemServer returned some object. The process will therefore enter the if and execute r.run() before returning. zygoteServer.runSelectLoop(abiList) will therefore never be executed in the child process (system_server).

However, in the parent process, the call to forkSystemServer returned null. The process will therefore not enter the if and continue, executing zygoteServer.runSelectLoop(abiList).

This is also what is mentioned in comment in your code snippet.

In case you are not yet convinced, listing the running processes on your device will clearly show you that both zygote64 and system_server are running alongside the 32-bit version of zygote:

# ps -e | grep -E "zygote|system_server"
root           979     1 6102692  65188 do_sys_poll         0 S zygote64
root           980     1 1754948  18020 do_sys_poll         0 S zygote
system        2164   979 14310660 308548 do_epoll_wait      0 S system_server

So to finally answer the question: No, Android applications are not inherently 32-bit. zygote64 will be used to run 64-bit applications.

0

You are correct. In modern Android versions, starting with Android 8.0 (Oreo), the system_server process is started by the zygote64 process. This change was introduced to support 64-bit architectures while maintaining backward compatibility with 32-bit architectures.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Jan 31 at 7:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .