04 December 2014

zygote fork

Q. how does zygote exactly fork Dalvik VM?
Short Answer: Zygote process basically cold boots a VM on system start up. Once done, it listens to a socket for incoming commands. Other processes (e.g. ActivityManagerService) writes commands to this socket, whenever it needs a new process for an application. This command is read by the Zygote process and calls fork() - so the child process now gets a pre-warmed up VM in which to run. This is how zygote forks the Dalvik VM.
Long answer: (this could be really long) After kernel is loaded, init.rc is parsed and native services are started. With this, the /system/bin/app_process (Source code:frameworks/base/cmds/app_process/app_main.cpp) is run. This eventually calls AndroidRuntime.start() function (Source code: frameworks/base/core/jni/AndroidRuntime.cpp), passing it the parameters com.android.internal.os.ZygoteInit and start-system-server.
The AndroidRuntime.start() starts the Java VM, then calls ZygoteInit.main() (Source code:frameworks/base/core/java/com/android/internal/os/ZygoteInit.java), passing it the parameter start-system-server.
ZygoteInit.main() first registers the zygote socket (the zygote process listens to a socket for incoming commands, and on receiving new command, spawns a new process as requested). Next thing that happens is, it preloads a lot of classes (which is listed in frameworks/base/preloaded-classes, last I checked, 2307 lines, in android 4.0.4) and all the system-wide resources like drawables, xmls, etc. Then it calls startSystemServer() which forks a new process for com.android.server.SystemServer(Source code: frameworks/base/services/java/com/android/server/SystemServer.java). Forking of system server is a special case, because in all other cases, zygote process listens to a socket and forks for new commands, as we will see soon.
After SystemServer is forked, a function runSelectLoopMode() is called. This is a while(true) loop which basically establishes a ZygoteConnection with the zygote socket and waits for commands on it. When a command is received, ZygoteConnection.runOnce() is called (Source code:frameworks/base/core/java/com/android/internal/os/ZygoteConnection.java)
ZygoteConnection.runOnce() calls Zygote.forkAndSpecialize() (Source code:libcore/dalvik/src/main/java/dalvik/system/Zygote.java) which simply calls a natvie function to do the fork. Thus, like in the case of SystemServer, a child process is created which has a pre-warmed up Dalvik for itself.
Q. why it is not possible to run multiple applications in the same Dalvik VM?
This is a design decision as far as I know. Android guys just decided to fork a new VM per process, for security via sandboxing.

ref: http://stackoverflow.com/questions/9153166/understanding-android-zygote-and-dalvikvm

03 December 2014

git: lokasi asal (remote)

git branch -a
git remote show
git remote show origin


cat manifests.git/config 
        repositoryformatversion = 0
        filemode = true
[remote "origin"]
        url = /usr/local/aosp/mirror/platform/manifest.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "default"]
        remote = origin
        merge = android-4.4.2_r1
        email = siperdana@gmail.com

masalah compile android

  1. semak version java* dan jar* dalam:
    • /etc/alternatives/jar*
    • /etc/alternatives/java*
    • pastikan semua guna version sama (on ubuntu12.04):
    • /etc/alternatives/jar -> /usr/lib/jvm/java-6-oracle/bin/jar*
    • /etc/alternatives/jarsigner -> /usr/lib/jvm/java-6-oracle/bin/jarsigner*
  2. package com.sun.javadoc does not exist 
    • export PATH=/home/rev/BIN/jdk-6u34/jdk1.6.0_34/bin/:$PATH
    • buang / lepas bin
    • export PATH=/home/rev/BIN/jdk-6u34/jdk1.6.0_34/bin:$PATH 

01 December 2014

root dengan odin


vnc on ubuntu server

ref: http://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on-ubuntu-server-12-04/

ubuntu 14.04

21 November 2014

tambah syscall sendiri

Cara nak tambah syscall sendiri ke dalam linux kernel. Melibatkan recompile kernel

// 1)  source_path/arch/x86/syscalls/syscall_32.tbl
# The format is:
356     i386    memfd_create            sys_memfd_create
357     i386     mhsyscall            sys_mhsyscall  ( new line)

// 2)  source_path/include/linux/syscalls.h

// last line
asmlinkage long sys_opsyscall(const char *test);

// 3)   source_path/mhsyscall/mhfzsyscall.c   ( nama c file suka hati)


//The system call
asmlinkage long sys_mhsyscall(const char *test)
   printk(KERN_ALERT "Called with string: %s\n", test);
   // 0 for success
   return 0;

// 4)   source_path/mhsyscall/Makefile

// Include the object in the kernel core
obj-y := mhfzsyscall.o

// 5)    source_path/Makefile

# Objects we will link into vmlinux / subdirs we need to visit
init-y          := init/
drivers-y       := drivers/ sound/ firmware/
net-y           := net/
libs-y          := lib/
core-y          := usr/ mhsyscall/   ( edit line )

// 6)  compile
# make

//  7) userspace binary to call mhsyscall (pemanggil.c)


int main(){
   syscall(357, "Mesage from user space program");
   return 0;
//  gcc -o pemanggil pemanggil.c

ref https://www.youtube.com/watch?v=5rr_VoQCOgE&feature=youtu.be

20 November 2014

aosp mirror

These instructions assume that the mirror is created in /usr/local/aosp/mirror. The first step is to create and sync the mirror itself, which uses close to 13GB of network bandwidth and a similar amount of disk space. Notice the --mirror flag, which can only be specified when creating a new client:
$ mkdir -p /usr/local/aosp/mirror
$ cd /usr/local/aosp/mirror
$ repo init -u https://android.googlesource.com/mirror/manifest --mirror
$ repo sync
Once the mirror is synced, new clients can be created from it. Note that it's important to specify an absolute path:
$ mkdir -p /usr/local/aosp/kitkat
$ cd /usr/local/aosp/kitkat
$ repo init -u /usr/local/aosp/mirror/platform/manifest.git -b android-4.4.4
$ repo sync
Finally, to sync a client against the server, the mirror needs to be synced against the server, then the client against the mirror:
$ cd /usr/local/aosp/mirror
$ repo sync
$ cd /usr/local/aosp/kitkat
$ repo sync

ref:  http://stackoverflow.com/questions/15870217/android-source-code-and-repo-what-exactly-is-happening-when-getting-code